[sycl] Reorder if-else statements to allow using of cpu branches for sycl-devices (#10543)
* reoder if-else statements for sycl compatibility * trigger check --------- Co-authored-by: Dmitry Razdoburdin <>
This commit is contained in:
committed by
GitHub
parent
620b2b155a
commit
513d7a7d84
@@ -45,17 +45,17 @@ struct EllpackDeviceAccessor {
|
||||
n_rows(n_rows),
|
||||
gidx_iter(gidx_iter),
|
||||
feature_types{feature_types} {
|
||||
if (device.IsCPU()) {
|
||||
gidx_fvalue_map = cuts->cut_values_.ConstHostSpan();
|
||||
feature_segments = cuts->cut_ptrs_.ConstHostSpan();
|
||||
min_fvalue = cuts->min_vals_.ConstHostSpan();
|
||||
} else {
|
||||
if (device.IsCUDA()) {
|
||||
cuts->cut_values_.SetDevice(device);
|
||||
cuts->cut_ptrs_.SetDevice(device);
|
||||
cuts->min_vals_.SetDevice(device);
|
||||
gidx_fvalue_map = cuts->cut_values_.ConstDeviceSpan();
|
||||
feature_segments = cuts->cut_ptrs_.ConstDeviceSpan();
|
||||
min_fvalue = cuts->min_vals_.ConstDeviceSpan();
|
||||
} else {
|
||||
gidx_fvalue_map = cuts->cut_values_.ConstHostSpan();
|
||||
feature_segments = cuts->cut_ptrs_.ConstHostSpan();
|
||||
min_fvalue = cuts->min_vals_.ConstHostSpan();
|
||||
}
|
||||
}
|
||||
// Get a matrix element, uses binary search for look up Return NaN if missing
|
||||
|
||||
@@ -41,10 +41,10 @@ IterativeDMatrix::IterativeDMatrix(DataIterHandle iter_handle, DMatrixHandle pro
|
||||
// hardcoded parameter.
|
||||
BatchParam p{max_bin, tree::TrainParam::DftSparseThreshold()};
|
||||
|
||||
if (ctx.IsCPU()) {
|
||||
this->InitFromCPU(&ctx, p, iter_handle, missing, ref);
|
||||
} else {
|
||||
if (ctx.IsCUDA()) {
|
||||
this->InitFromCUDA(&ctx, p, iter_handle, missing, ref);
|
||||
} else {
|
||||
this->InitFromCPU(&ctx, p, iter_handle, missing, ref);
|
||||
}
|
||||
|
||||
this->fmat_ctx_ = ctx;
|
||||
@@ -73,10 +73,10 @@ void GetCutsFromRef(Context const* ctx, std::shared_ptr<DMatrix> ref, bst_featur
|
||||
|
||||
if (ref->PageExists<GHistIndexMatrix>() && ref->PageExists<EllpackPage>()) {
|
||||
// Both exists
|
||||
if (ctx->IsCPU()) {
|
||||
csr();
|
||||
} else {
|
||||
if (ctx->IsCUDA()) {
|
||||
ellpack();
|
||||
} else {
|
||||
csr();
|
||||
}
|
||||
} else if (ref->PageExists<GHistIndexMatrix>()) {
|
||||
csr();
|
||||
@@ -84,10 +84,10 @@ void GetCutsFromRef(Context const* ctx, std::shared_ptr<DMatrix> ref, bst_featur
|
||||
ellpack();
|
||||
} else {
|
||||
// None exist
|
||||
if (ctx->IsCPU()) {
|
||||
csr();
|
||||
} else {
|
||||
if (ctx->IsCUDA()) {
|
||||
ellpack();
|
||||
} else {
|
||||
csr();
|
||||
}
|
||||
}
|
||||
CHECK_EQ(ref->Info().num_col_, n_features)
|
||||
@@ -297,9 +297,9 @@ BatchSet<GHistIndexMatrix> IterativeDMatrix::GetGradientIndex(Context const* ctx
|
||||
}
|
||||
|
||||
if (!ghist_) {
|
||||
if (ctx->IsCPU()) {
|
||||
if (!ctx->IsCUDA()) {
|
||||
ghist_ = std::make_shared<GHistIndexMatrix>(ctx, Info(), *ellpack_, param);
|
||||
} else if (fmat_ctx_.IsCPU()) {
|
||||
} else if (!fmat_ctx_.IsCUDA()) {
|
||||
ghist_ = std::make_shared<GHistIndexMatrix>(&fmat_ctx_, Info(), *ellpack_, param);
|
||||
} else {
|
||||
// Can happen when QDM is initialized on GPU, but a CPU version is queried by a different QDM
|
||||
|
||||
@@ -46,7 +46,7 @@ void IterativeDMatrix::InitFromCUDA(Context const* ctx, BatchParam const& p,
|
||||
int32_t current_device;
|
||||
dh::safe_cuda(cudaGetDevice(¤t_device));
|
||||
auto get_device = [&]() {
|
||||
auto d = (ctx->IsCPU()) ? DeviceOrd::CUDA(current_device) : ctx->Device();
|
||||
auto d = (ctx->IsCUDA()) ? ctx->Device() : DeviceOrd::CUDA(current_device);
|
||||
CHECK(!d.IsCPU());
|
||||
return d;
|
||||
};
|
||||
|
||||
@@ -56,7 +56,9 @@ std::shared_ptr<DMatrix> CreateDMatrixFromProxy(Context const *ctx,
|
||||
float missing) {
|
||||
bool type_error{false};
|
||||
std::shared_ptr<DMatrix> p_fmat{nullptr};
|
||||
if (proxy->Ctx()->IsCPU()) {
|
||||
if (proxy->Ctx()->IsCUDA()) {
|
||||
p_fmat = cuda_impl::CreateDMatrixFromProxy(ctx, proxy, missing);
|
||||
} else {
|
||||
p_fmat = data::HostAdapterDispatch<false>(
|
||||
proxy.get(),
|
||||
[&](auto const &adapter) {
|
||||
@@ -65,8 +67,6 @@ std::shared_ptr<DMatrix> CreateDMatrixFromProxy(Context const *ctx,
|
||||
return p_fmat;
|
||||
},
|
||||
&type_error);
|
||||
} else {
|
||||
p_fmat = cuda_impl::CreateDMatrixFromProxy(ctx, proxy, missing);
|
||||
}
|
||||
|
||||
CHECK(p_fmat) << "Failed to fallback.";
|
||||
|
||||
@@ -11,7 +11,7 @@ void DMatrixProxy::FromCudaColumnar(StringView interface_str) {
|
||||
this->batch_ = adapter;
|
||||
this->Info().num_col_ = adapter->NumColumns();
|
||||
this->Info().num_row_ = adapter->NumRows();
|
||||
if (adapter->Device().IsCPU()) {
|
||||
if (!adapter->Device().IsCUDA()) {
|
||||
// empty data
|
||||
CHECK_EQ(this->Info().num_row_, 0);
|
||||
ctx_ = ctx_.MakeCUDA(dh::CurrentDevice());
|
||||
@@ -25,7 +25,7 @@ void DMatrixProxy::FromCudaArray(StringView interface_str) {
|
||||
this->batch_ = adapter;
|
||||
this->Info().num_col_ = adapter->NumColumns();
|
||||
this->Info().num_row_ = adapter->NumRows();
|
||||
if (adapter->Device().IsCPU()) {
|
||||
if (!adapter->Device().IsCUDA()) {
|
||||
// empty data
|
||||
CHECK_EQ(this->Info().num_row_, 0);
|
||||
ctx_ = ctx_.MakeCUDA(dh::CurrentDevice());
|
||||
|
||||
@@ -185,12 +185,12 @@ BatchSet<GHistIndexMatrix> SimpleDMatrix::GetGradientIndex(Context const* ctx,
|
||||
CHECK_GE(param.max_bin, 2);
|
||||
// Used only by approx.
|
||||
auto sorted_sketch = param.regen;
|
||||
if (ctx->IsCPU()) {
|
||||
if (!ctx->IsCUDA()) {
|
||||
// The context passed in is on CPU, we pick it first since we prioritize the context
|
||||
// in Booster.
|
||||
gradient_index_.reset(new GHistIndexMatrix{ctx, this, param.max_bin, param.sparse_thresh,
|
||||
sorted_sketch, param.hess});
|
||||
} else if (fmat_ctx_.IsCPU()) {
|
||||
} else if (!fmat_ctx_.IsCUDA()) {
|
||||
// DMatrix was initialized on CPU, we use the context from initialization.
|
||||
gradient_index_.reset(new GHistIndexMatrix{&fmat_ctx_, this, param.max_bin,
|
||||
param.sparse_thresh, sorted_sketch, param.hess});
|
||||
|
||||
@@ -19,7 +19,7 @@ SimpleDMatrix::SimpleDMatrix(AdapterT* adapter, float missing, std::int32_t nthr
|
||||
DataSplitMode data_split_mode) {
|
||||
CHECK(data_split_mode != DataSplitMode::kCol)
|
||||
<< "Column-wise data split is currently not supported on the GPU.";
|
||||
auto device = (adapter->Device().IsCPU() || adapter->NumRows() == 0)
|
||||
auto device = (!adapter->Device().IsCUDA() || adapter->NumRows() == 0)
|
||||
? DeviceOrd::CUDA(dh::CurrentDevice())
|
||||
: adapter->Device();
|
||||
CHECK(device.IsCUDA());
|
||||
|
||||
@@ -20,7 +20,7 @@ std::size_t NFeaturesDevice(DMatrixProxy *proxy) {
|
||||
|
||||
void DevicePush(DMatrixProxy *proxy, float missing, SparsePage *page) {
|
||||
auto device = proxy->Device();
|
||||
if (device.IsCPU()) {
|
||||
if (!device.IsCUDA()) {
|
||||
device = DeviceOrd::CUDA(dh::CurrentDevice());
|
||||
}
|
||||
CHECK(device.IsCUDA());
|
||||
|
||||
Reference in New Issue
Block a user