From 26f9deabf352553ed3bd6017a38b0fe00abbbc29 Mon Sep 17 00:00:00 2001 From: Dmitry Razdoburdin <> Date: Fri, 27 Oct 2023 04:05:39 -0700 Subject: [PATCH] allow build with cmake; fix test; fix bug with mingw --- CMakeLists.txt | 13 +- plugin/CMakeLists.txt | 4 +- .../updater_oneapi/device_manager_oneapi.cc | 32 ++-- plugin/updater_oneapi/predictor_oneapi.cc | 18 ++- src/context.cc | 15 +- tests/cpp/plugin/test_predictor_oneapi.cc | 142 ++++++------------ .../cpp/plugin/test_regression_obj_oneapi.cc | 88 ++++++----- 7 files changed, 149 insertions(+), 163 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 561d327568a8..4f7bc5f2fd6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,10 +170,6 @@ if (USE_CUDA) find_package(CUDAToolkit REQUIRED) endif (USE_CUDA) -if (PLUGIN_UPDATER_ONEAPI) - target_compile_definitions(xgboost PRIVATE -DXGBOOST_USE_ONEAPI=1) -endif (PLUGIN_UPDATER_ONEAPI) - if (FORCE_COLORED_OUTPUT AND (CMAKE_GENERATOR STREQUAL "Ninja") AND ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))) @@ -268,6 +264,15 @@ if (PLUGIN_RMM) get_target_property(rmm_link_libs rmm::rmm INTERFACE_LINK_LIBRARIES) endif (PLUGIN_RMM) +if (PLUGIN_UPDATER_ONEAPI) + set(CMAKE_CXX_LINK_EXECUTABLE + "icpx -qopenmp -o ") + set(CMAKE_CXX_CREATE_SHARED_LIBRARY + "icpx -qopenmp \ + , \ + -o ") +endif (PLUGIN_UPDATER_ONEAPI) + #-- library if (BUILD_STATIC_LIB) add_library(xgboost STATIC) diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt index def1d8b4f0cd..d2df479c80d7 100644 --- a/plugin/CMakeLists.txt +++ b/plugin/CMakeLists.txt @@ -3,6 +3,7 @@ if (PLUGIN_DENSE_PARSER) endif (PLUGIN_DENSE_PARSER) if (PLUGIN_UPDATER_ONEAPI) + set(CMAKE_CXX_COMPILER "icpx") add_library(oneapi_plugin OBJECT ${xgboost_SOURCE_DIR}/plugin/updater_oneapi/hist_util_oneapi.cc ${xgboost_SOURCE_DIR}/plugin/updater_oneapi/regression_obj_oneapi.cc @@ -24,7 +25,8 @@ if (PLUGIN_UPDATER_ONEAPI) POSITION_INDEPENDENT_CODE ON) if (USE_OPENMP) find_package(OpenMP REQUIRED) - target_link_libraries(oneapi_plugin PUBLIC OpenMP::OpenMP_CXX) + set_target_properties(oneapi_plugin PROPERTIES + COMPILE_FLAGS "-fsycl -qopenmp") endif (USE_OPENMP) # Get compilation and link flags of oneapi_plugin and propagate to objxgboost target_link_libraries(objxgboost PUBLIC oneapi_plugin) diff --git a/plugin/updater_oneapi/device_manager_oneapi.cc b/plugin/updater_oneapi/device_manager_oneapi.cc index 703db82d199b..72e7f1235d48 100644 --- a/plugin/updater_oneapi/device_manager_oneapi.cc +++ b/plugin/updater_oneapi/device_manager_oneapi.cc @@ -9,6 +9,11 @@ namespace xgboost { sycl::device DeviceManagerOneAPI::GetDevice(const DeviceOrd& device_spec) const { + if (!device_spec.IsSycl()) { + LOG(WARNING) << "Sycl kernel is executed with non-sycl context. " + << "Default sycl device_selector will be used."; + } + bool not_use_default_selector = (device_spec.ordinal != kDefaultOrdinal) || (rabit::IsDistributed()); if (not_use_default_selector) { @@ -28,22 +33,27 @@ sycl::device DeviceManagerOneAPI::GetDevice(const DeviceOrd& device_spec) const return gpu_devices[device_idx]; } } else { - if (device_spec.IsSyclDefault()) { - return sycl::device(sycl::default_selector_v); - } else if(device_spec.IsSyclCPU()) { - return sycl::device(sycl::cpu_selector_v); - } else { - return sycl::device(sycl::gpu_selector_v); - } + if(device_spec.IsSyclCPU()) { + return sycl::device(sycl::cpu_selector_v); + } else if(device_spec.IsSyclGPU()) { + return sycl::device(sycl::gpu_selector_v); + } else { + return sycl::device(sycl::default_selector_v); + } } } sycl::queue DeviceManagerOneAPI::GetQueue(const DeviceOrd& device_spec) const { + if (!device_spec.IsSycl()) { + LOG(WARNING) << "Sycl kernel is executed with non-sycl context. " + << "Default sycl device_selector will be used."; + } + QueueRegister_t& queue_register = GetQueueRegister(); if (queue_register.count(device_spec.Name()) > 0) { return queue_register.at(device_spec.Name()); } - + bool not_use_default_selector = (device_spec.ordinal != kDefaultOrdinal) || (rabit::IsDistributed()); std::lock_guard guard(queue_registering_mutex); @@ -64,12 +74,12 @@ sycl::queue DeviceManagerOneAPI::GetQueue(const DeviceOrd& device_spec) const { queue_register[device_spec.Name()] = sycl::queue(gpu_devices[device_idx]); } } else { - if (device_spec.IsSyclDefault()) { - queue_register[device_spec.Name()] = sycl::queue(sycl::default_selector_v); - } else if (device_spec.IsSyclCPU()) { + if (device_spec.IsSyclCPU()) { queue_register[device_spec.Name()] = sycl::queue(sycl::cpu_selector_v); } else if (device_spec.IsSyclGPU()) { queue_register[device_spec.Name()] = sycl::queue(sycl::gpu_selector_v); + } else { + queue_register[device_spec.Name()] = sycl::queue(sycl::default_selector_v); } } return queue_register.at(device_spec.Name()); diff --git a/plugin/updater_oneapi/predictor_oneapi.cc b/plugin/updater_oneapi/predictor_oneapi.cc index 86f1877b84c4..97409dfd1d39 100755 --- a/plugin/updater_oneapi/predictor_oneapi.cc +++ b/plugin/updater_oneapi/predictor_oneapi.cc @@ -28,11 +28,7 @@ namespace predictor { DMLC_REGISTRY_FILE_TAG(predictor_oneapi); class PredictorOneAPI : public Predictor { - public: - explicit PredictorOneAPI(Context const* context) : - Predictor::Predictor{context} {} - - void Configure(const std::vector>& args) override { + void SetupBackend() { const DeviceOrd device_spec = ctx_->Device(); bool is_cpu; @@ -42,14 +38,22 @@ class PredictorOneAPI : public Predictor { } else { is_cpu = true; } - LOG(INFO) << "device = " << device_spec.Name() << ", is_cpu = " << int(is_cpu); - if (is_cpu) { predictor_backend_.reset(Predictor::Create("cpu_predictor", ctx_)); } else{ predictor_backend_.reset(Predictor::Create("oneapi_predictor_backend", ctx_)); } + } + + public: + explicit PredictorOneAPI(Context const* context) : + Predictor::Predictor{context} { + SetupBackend(); + } + + void Configure(const std::vector>& args) override { + SetupBackend(); predictor_backend_->Configure(args); } diff --git a/src/context.cc b/src/context.cc index ff8fcb9b084b..a11264707c19 100644 --- a/src/context.cc +++ b/src/context.cc @@ -120,12 +120,23 @@ DeviceOrd CUDAOrdinal(DeviceOrd device, bool) { #endif // defined(__MINGW32__) // handle alias +#if defined(__MINGW32__) + // mingw hangs on regex using rtools 430. Basic checks only. + bool is_sycl = (substr == "syc"); +#else + bool is_sycl = std::regex_match(input, std::regex("sycl(:cpu|:gpu)?(:-1|:[0-9]+)?")); +#endif // defined(__MINGW32__) + std::string s_device = input; - if (!std::regex_match(s_device, std::regex("sycl(:cpu|:gpu)?(:-1|:[0-9]+)?"))) + if (!is_sycl) { s_device = std::regex_replace(s_device, std::regex{"gpu"}, DeviceSym::CUDA()); auto split_it = std::find(s_device.cbegin(), s_device.cend(), ':'); - if (std::regex_match(s_device, std::regex("sycl:(cpu|gpu)?"))) split_it = s_device.cend(); + // For these cases we need to move iterator to the end, not to look for a ordinal. + if ((s_device == "sycl:cpu") || + (s_device == "sycl:gpu")) { + split_it = s_device.cend(); + } // For s_device like "sycl:gpu:1" if (split_it != s_device.cend()) { diff --git a/tests/cpp/plugin/test_predictor_oneapi.cc b/tests/cpp/plugin/test_predictor_oneapi.cc index 52edd4a12dd5..2b9c9fce9630 100755 --- a/tests/cpp/plugin/test_predictor_oneapi.cc +++ b/tests/cpp/plugin/test_predictor_oneapi.cc @@ -5,33 +5,31 @@ #include #include "../../../src/data/adapter.h" +#include "../../../src/data/proxy_dmatrix.h" #include "../../../src/gbm/gbtree_model.h" #include "../filesystem.h" // dmlc::TemporaryDirectory #include "../helpers.h" #include "../predictor/test_predictor.h" namespace xgboost { -TEST(Plugin, OneAPIPredictorBasic) { - auto lparam = MakeCUDACtx(0); +namespace { +void TestBasic(DMatrix* dmat) { + Context ctx; + ctx.UpdateAllowUnknown(Args{{"device", "sycl"}}); std::unique_ptr oneapi_predictor = - std::unique_ptr(Predictor::Create("oneapi_predictor", &lparam)); + std::unique_ptr(Predictor::Create("oneapi_predictor", &ctx)); - int kRows = 5; - int kCols = 5; + size_t const kRows = dmat->Info().num_row_; + size_t const kCols = dmat->Info().num_col_; - LearnerModelParam param; - param.num_feature = kCols; - param.base_score = 0.0; - param.num_output_group = 1; - - gbm::GBTreeModel model = CreateTestModel(¶m); - - auto dmat = RandomDataGenerator(kRows, kCols, 0).GenerateDMatrix(); + LearnerModelParam param(MakeMP(kCols, .0, 1)); + gbm::GBTreeModel model = CreateTestModel(¶m, &ctx); // Test predict batch PredictionCacheEntry out_predictions; - oneapi_predictor->PredictBatch(dmat.get(), &out_predictions, model, 0); - ASSERT_EQ(model.trees.size(), out_predictions.version); + oneapi_predictor->InitOutPredictions(dmat->Info(), &out_predictions.predictions, model); + oneapi_predictor->PredictBatch(dmat, &out_predictions, model, 0); + std::vector& out_predictions_h = out_predictions.predictions.HostVector(); for (size_t i = 0; i < out_predictions.predictions.Size(); i++) { ASSERT_EQ(out_predictions_h[i], 1.5); @@ -39,22 +37,25 @@ TEST(Plugin, OneAPIPredictorBasic) { // Test predict instance auto const &batch = *dmat->GetBatches().begin(); + auto page = batch.GetView(); for (size_t i = 0; i < batch.Size(); i++) { std::vector instance_out_predictions; - oneapi_predictor->PredictInstance(batch[i], &instance_out_predictions, model); + oneapi_predictor->PredictInstance(page[i], &instance_out_predictions, model); ASSERT_EQ(instance_out_predictions[0], 1.5); } // Test predict leaf - std::vector leaf_out_predictions; - oneapi_predictor->PredictLeaf(dmat.get(), &leaf_out_predictions, model); - for (auto v : leaf_out_predictions) { + HostDeviceVector leaf_out_predictions; + oneapi_predictor->PredictLeaf(dmat, &leaf_out_predictions, model); + auto const& h_leaf_out_predictions = leaf_out_predictions.ConstHostVector(); + for (auto v : h_leaf_out_predictions) { ASSERT_EQ(v, 0); } // Test predict contribution - std::vector out_contribution; - oneapi_predictor->PredictContribution(dmat.get(), &out_contribution, model); + HostDeviceVector out_contribution_hdv; + auto& out_contribution = out_contribution_hdv.HostVector(); + oneapi_predictor->PredictContribution(dmat, &out_contribution_hdv, model); ASSERT_EQ(out_contribution.size(), kRows * (kCols + 1)); for (size_t i = 0; i < out_contribution.size(); ++i) { auto const& contri = out_contribution[i]; @@ -65,8 +66,9 @@ TEST(Plugin, OneAPIPredictorBasic) { ASSERT_EQ(contri, 0); } } + // Test predict contribution (approximate method) - oneapi_predictor->PredictContribution(dmat.get(), &out_contribution, model, 0, nullptr, true); + oneapi_predictor->PredictContribution(dmat, &out_contribution_hdv, model, 0, nullptr, true); for (size_t i = 0; i < out_contribution.size(); ++i) { auto const& contri = out_contribution[i]; // shift 1 for bias, as test tree is a decision dump, only global bias is filled with LeafValue(). @@ -77,71 +79,23 @@ TEST(Plugin, OneAPIPredictorBasic) { } } } +} // anonymous namespace -TEST(Plugin, OneAPIPredictorExternalMemory) { - dmlc::TemporaryDirectory tmpdir; - std::string filename = tmpdir.path + "/big.libsvm"; - std::unique_ptr dmat = CreateSparsePageDMatrix(12, 64, filename); - auto lparam = MakeCUDACtx(0); - - std::unique_ptr oneapi_predictor = - std::unique_ptr(Predictor::Create("oneapi_predictor", &lparam)); - - LearnerModelParam param; - param.base_score = 0; - param.num_feature = dmat->Info().num_col_; - param.num_output_group = 1; - - gbm::GBTreeModel model = CreateTestModel(¶m); - - // Test predict batch - PredictionCacheEntry out_predictions; - oneapi_predictor->PredictBatch(dmat.get(), &out_predictions, model, 0); - std::vector &out_predictions_h = out_predictions.predictions.HostVector(); - ASSERT_EQ(out_predictions.predictions.Size(), dmat->Info().num_row_); - for (const auto& v : out_predictions_h) { - ASSERT_EQ(v, 1.5); - } - - // Test predict leaf - std::vector leaf_out_predictions; - oneapi_predictor->PredictLeaf(dmat.get(), &leaf_out_predictions, model); - ASSERT_EQ(leaf_out_predictions.size(), dmat->Info().num_row_); - for (const auto& v : leaf_out_predictions) { - ASSERT_EQ(v, 0); - } - - // Test predict contribution - std::vector out_contribution; - oneapi_predictor->PredictContribution(dmat.get(), &out_contribution, model); - ASSERT_EQ(out_contribution.size(), dmat->Info().num_row_ * (dmat->Info().num_col_ + 1)); - for (size_t i = 0; i < out_contribution.size(); ++i) { - auto const& contri = out_contribution[i]; - // shift 1 for bias, as test tree is a decision dump, only global bias is filled with LeafValue(). - if ((i + 1) % (dmat->Info().num_col_ + 1) == 0) { - ASSERT_EQ(out_contribution.back(), 1.5f); - } else { - ASSERT_EQ(contri, 0); - } - } +TEST(SyclPredictor, Basic) { + size_t constexpr kRows = 5; + size_t constexpr kCols = 5; + auto dmat = RandomDataGenerator(kRows, kCols, 0).GenerateDMatrix(); + TestBasic(dmat.get()); +} - // Test predict contribution (approximate method) - std::vector out_contribution_approximate; - oneapi_predictor->PredictContribution(dmat.get(), &out_contribution_approximate, model, 0, nullptr, true); - ASSERT_EQ(out_contribution_approximate.size(), - dmat->Info().num_row_ * (dmat->Info().num_col_ + 1)); - for (size_t i = 0; i < out_contribution.size(); ++i) { - auto const& contri = out_contribution[i]; - // shift 1 for bias, as test tree is a decision dump, only global bias is filled with LeafValue(). - if ((i + 1) % (dmat->Info().num_col_ + 1) == 0) { - ASSERT_EQ(out_contribution.back(), 1.5f); - } else { - ASSERT_EQ(contri, 0); - } - } +TEST(SyclPredictor, ExternalMemory) { + size_t constexpr kPageSize = 64, kEntriesPerCol = 3; + size_t constexpr kEntries = kPageSize * kEntriesPerCol * 2; + std::unique_ptr dmat = CreateSparsePageDMatrix(kEntries); + TestBasic(dmat.get()); } -TEST(Plugin, OneAPIPredictorInplacePredict) { +TEST(SyclPredictor, InplacePredict) { bst_row_t constexpr kRows{128}; bst_feature_t constexpr kCols{64}; auto gen = RandomDataGenerator{kRows, kCols, 0.5}.Device(-1); @@ -149,20 +103,14 @@ TEST(Plugin, OneAPIPredictorInplacePredict) { HostDeviceVector data; gen.GenerateDense(&data); ASSERT_EQ(data.Size(), kRows * kCols); - std::shared_ptr x{ - new data::DenseAdapter(data.HostPointer(), kRows, kCols)}; - TestInplacePrediction(x, "oneapi_predictor", kRows, kCols, -1); - } - - { - HostDeviceVector data; - HostDeviceVector rptrs; - HostDeviceVector columns; - gen.GenerateCSR(&data, &rptrs, &columns); - std::shared_ptr x{new data::CSRAdapter( - rptrs.HostPointer(), columns.HostPointer(), data.HostPointer(), kRows, - data.Size(), kCols)}; - TestInplacePrediction(x, "oneapi_predictor", kRows, kCols, -1); + Context ctx; + ctx.UpdateAllowUnknown(Args{{"device", "sycl"}}); + std::shared_ptr x{new data::DMatrixProxy{}}; + auto array_interface = GetArrayInterface(&data, kRows, kCols); + std::string arr_str; + Json::Dump(array_interface, &arr_str); + x->SetArrayData(arr_str.data()); + TestInplacePrediction(&ctx, x, kRows, kCols); } } } // namespace xgboost diff --git a/tests/cpp/plugin/test_regression_obj_oneapi.cc b/tests/cpp/plugin/test_regression_obj_oneapi.cc index c01d9d9511e2..0b5b6bf20776 100755 --- a/tests/cpp/plugin/test_regression_obj_oneapi.cc +++ b/tests/cpp/plugin/test_regression_obj_oneapi.cc @@ -8,35 +8,37 @@ #include "../helpers.h" namespace xgboost { -TEST(Plugin, LinearRegressionGPairOneAPI) { - Context tparam = MakeCUDACtx(0); +TEST(SyclObjective, LinearRegressionGPair) { + Context ctx; + ctx.UpdateAllowUnknown(Args{{"device", "sycl"}}); std::vector> args; std::unique_ptr obj { - ObjFunction::Create("reg:squarederror_oneapi", &tparam) + ObjFunction::Create("reg:squarederror_oneapi", &ctx) }; obj->Configure(args); CheckObjFunction(obj, - {0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, - {0, 0, 0, 0, 1, 1, 1, 1}, - {1, 1, 1, 1, 1, 1, 1, 1}, - {0, 0.1f, 0.9f, 1.0f, -1.0f, -0.9f, -0.1f, 0}, - {1, 1, 1, 1, 1, 1, 1, 1}); + {0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, + {0, 0, 0, 0, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 1}, + {0, 0.1f, 0.9f, 1.0f, -1.0f, -0.9f, -0.1f, 0}, + {1, 1, 1, 1, 1, 1, 1, 1}); CheckObjFunction(obj, - {0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, - {0, 0, 0, 0, 1, 1, 1, 1}, + {0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, + {0, 0, 0, 0, 1, 1, 1, 1}, {}, // empty weight - {0, 0.1f, 0.9f, 1.0f, -1.0f, -0.9f, -0.1f, 0}, - {1, 1, 1, 1, 1, 1, 1, 1}); + {0, 0.1f, 0.9f, 1.0f, -1.0f, -0.9f, -0.1f, 0}, + {1, 1, 1, 1, 1, 1, 1, 1}); ASSERT_NO_THROW(obj->DefaultEvalMetric()); } -TEST(Plugin, SquaredLogOneAPI) { - Context tparam = MakeCUDACtx(0); +TEST(SyclObjective, SquaredLog) { + Context ctx; + ctx.UpdateAllowUnknown(Args{{"device", "sycl"}}); std::vector> args; - std::unique_ptr obj { ObjFunction::Create("reg:squaredlogerror_oneapi", &tparam) }; + std::unique_ptr obj { ObjFunction::Create("reg:squaredlogerror_oneapi", &ctx) }; obj->Configure(args); CheckConfigReload(obj, "reg:squaredlogerror_oneapi"); @@ -55,27 +57,29 @@ TEST(Plugin, SquaredLogOneAPI) { ASSERT_EQ(obj->DefaultEvalMetric(), std::string{"rmsle"}); } -TEST(Plugin, LogisticRegressionGPairOneAPI) { - Context tparam = MakeCUDACtx(0); +TEST(SyclObjective, LogisticRegressionGPair) { + Context ctx; + ctx.UpdateAllowUnknown(Args{{"device", "sycl"}}); std::vector> args; - std::unique_ptr obj { ObjFunction::Create("reg:logistic_oneapi", &tparam) }; + std::unique_ptr obj { ObjFunction::Create("reg:logistic_oneapi", &ctx) }; obj->Configure(args); CheckConfigReload(obj, "reg:logistic_oneapi"); CheckObjFunction(obj, - { 0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, // preds - { 0, 0, 0, 0, 1, 1, 1, 1}, // labels - { 1, 1, 1, 1, 1, 1, 1, 1}, // weights - { 0.5f, 0.52f, 0.71f, 0.73f, -0.5f, -0.47f, -0.28f, -0.26f}, // out_grad + { 0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, // preds + { 0, 0 , 0, 0, 1, 1, 1, 1}, // labels + { 1, 1, 1, 1, 1, 1, 1, 1}, // weights + { 0.5f, 0.52f, 0.71f, 0.73f, -0.5f, -0.47f, -0.28f, -0.26f}, // out_grad {0.25f, 0.24f, 0.20f, 0.19f, 0.25f, 0.24f, 0.20f, 0.19f}); // out_hess } -TEST(Plugin, LogisticRegressionBasicOneAPI) { - Context lparam = MakeCUDACtx(0); +TEST(SyclObjective, LogisticRegressionBasic) { + Context ctx; + ctx.UpdateAllowUnknown(Args{{"device", "sycl"}}); std::vector> args; std::unique_ptr obj { - ObjFunction::Create("reg:logistic_oneapi", &lparam) + ObjFunction::Create("reg:logistic_oneapi", &ctx) }; obj->Configure(args); @@ -102,11 +106,12 @@ TEST(Plugin, LogisticRegressionBasicOneAPI) { } } -TEST(Plugin, LogisticRawGPairOneAPI) { - Context lparam = MakeCUDACtx(0); +TEST(SyclObjective, LogisticRawGPair) { + Context ctx; + ctx.UpdateAllowUnknown(Args{{"device", "sycl"}}); std::vector> args; std::unique_ptr obj { - ObjFunction::Create("binary:logitraw_oneapi", &lparam) + ObjFunction::Create("binary:logitraw_oneapi", &ctx) }; obj->Configure(args); @@ -119,15 +124,18 @@ TEST(Plugin, LogisticRawGPairOneAPI) { {0.25f, 0.24f, 0.20f, 0.19f, 0.25f, 0.24f, 0.20f, 0.19f}); } -TEST(Plugin, CPUvsOneAPI) { - Context ctx = MakeCUDACtx(0); +TEST(SyclObjective, CPUvsSycl) { + Context ctx; + ctx.UpdateAllowUnknown(Args{{"device", "sycl"}}); + ObjFunction * obj_sycl = + ObjFunction::Create("reg:squarederror_oneapi", &ctx); + ctx = ctx.MakeCPU(); ObjFunction * obj_cpu = ObjFunction::Create("reg:squarederror", &ctx); - ObjFunction * obj_oneapi = - ObjFunction::Create("reg:squarederror_oneapi", &ctx); + HostDeviceVector cpu_out_preds; - HostDeviceVector oneapi_out_preds; + HostDeviceVector sycl_out_preds; constexpr size_t kRows = 400; constexpr size_t kCols = 100; @@ -148,29 +156,27 @@ TEST(Plugin, CPUvsOneAPI) { { // CPU - ctx = ctx.MakeCPU(); obj_cpu->GetGradient(preds, info, 0, &cpu_out_preds); } { - // oneapi - ctx.gpu_id = 0; - obj_oneapi->GetGradient(preds, info, 0, &oneapi_out_preds); + // sycl + obj_sycl->GetGradient(preds, info, 0, &sycl_out_preds); } auto& h_cpu_out = cpu_out_preds.HostVector(); - auto& h_oneapi_out = oneapi_out_preds.HostVector(); + auto& h_sycl_out = sycl_out_preds.HostVector(); float sgrad = 0; float shess = 0; for (size_t i = 0; i < kRows; ++i) { - sgrad += std::pow(h_cpu_out[i].GetGrad() - h_oneapi_out[i].GetGrad(), 2); - shess += std::pow(h_cpu_out[i].GetHess() - h_oneapi_out[i].GetHess(), 2); + sgrad += std::pow(h_cpu_out[i].GetGrad() - h_sycl_out[i].GetGrad(), 2); + shess += std::pow(h_cpu_out[i].GetHess() - h_sycl_out[i].GetHess(), 2); } ASSERT_NEAR(sgrad, 0.0f, kRtEps); ASSERT_NEAR(shess, 0.0f, kRtEps); delete obj_cpu; - delete obj_oneapi; + delete obj_sycl; } } // namespace xgboost