-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Small cleanup for the jvm interface.
Fix create jni. serialization. lint. cleanup. [wip][jvm-packages] Add java class for `ExtMemQdm`. cleanup. cleanup. Debug build. Fix CPU build. Cleanup.
- Loading branch information
1 parent
2e1626c
commit 73c95c7
Showing
11 changed files
with
215 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...kages/xgboost4j-spark-gpu/src/main/java/ml/dmlc/xgboost4j/java/ExtMemQuantileDMatrix.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2025, XGBoost Contributors | ||
*/ | ||
package ml.dmlc.xgboost4j.java; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
|
||
|
||
public class ExtMemQuantileDMatrix extends QuantileDMatrix { | ||
// on_host is set to true by default as we only support GPU at the moment | ||
// cache_prefix is not used yet since we have on_host=true. | ||
public ExtMemQuantileDMatrix(Iterator<ColumnBatch> iter, | ||
float missing, | ||
int maxBin, | ||
DMatrix ref, | ||
int nthread, | ||
int max_num_device_pages, | ||
int max_quantile_batches, | ||
int min_cache_page_bytes) throws XGBoostError { | ||
long[] out = new long[1]; | ||
long[] ref_handle = null; | ||
if (ref != null) { | ||
ref_handle = new long[1]; | ||
ref_handle[0] = ref.getHandle(); | ||
} | ||
String conf = this.getConfig(missing, maxBin, nthread, max_num_device_pages, | ||
max_quantile_batches, min_cache_page_bytes); | ||
XGBoostJNI.checkCall(XGBoostJNI.XGExtMemQuantileDMatrixCreateFromCallback( | ||
iter, ref_handle, conf, out)); | ||
handle = out[0]; | ||
} | ||
|
||
private String getConfig(float missing, int maxBin, int nthread, int max_num_device_pages, | ||
int max_quantile_batches, | ||
int min_cache_page_bytes) { | ||
Map<String, Object> conf = new java.util.HashMap<>(); | ||
conf.put("missing", missing); | ||
conf.put("max_bin", maxBin); | ||
conf.put("nthread", nthread); | ||
conf.put("max_num_device_pages", max_num_device_pages); | ||
conf.put("max_quantile_batches", max_quantile_batches); | ||
conf.put("min_cache_page_bytes", min_cache_page_bytes); | ||
conf.put("on_host", true); | ||
conf.put("cache_prefix", "."); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
|
||
// Handle NaN values. Jackson by default serializes NaN values into strings. | ||
SimpleModule module = new SimpleModule(); | ||
module.addSerializer(Double.class, new F64NaNSerializer()); | ||
module.addSerializer(Float.class, new F32NaNSerializer()); | ||
mapper.registerModule(module); | ||
|
||
try { | ||
String config = mapper.writeValueAsString(conf); | ||
return config; | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException("Failed to serialize configuration", e); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,5 +198,4 @@ private float[] convertFloatTofloat(Float[]... datas) { | |
} | ||
return floatArray; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.