Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions plugin/sycl/common/optional_weight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
#include "../device_manager.h"

namespace xgboost::common::sycl_impl {
double SumOptionalWeights(Context const* ctx, OptionalWeights const& weights) {
sycl::DeviceManager device_manager;
auto* qu = device_manager.GetQueue(ctx->Device());

template <typename T>
T ElementWiseSum(::sycl::queue* qu, OptionalWeights const& weights) {
const auto* data = weights.Data();
double result = 0;
T result = 0;
{
::sycl::buffer<double> buff(&result, 1);
::sycl::buffer<T> buff(&result, 1);
qu->submit([&](::sycl::handler& cgh) {
auto reduction = ::sycl::reduction(buff, cgh, ::sycl::plus<>());
cgh.parallel_for<>(::sycl::range<1>(weights.Size()), reduction,
Expand All @@ -28,4 +27,16 @@ double SumOptionalWeights(Context const* ctx, OptionalWeights const& weights) {

return result;
}

double SumOptionalWeights(Context const* ctx, OptionalWeights const& weights) {
sycl::DeviceManager device_manager;
auto* qu = device_manager.GetQueue(ctx->Device());

bool has_fp64_support = qu->get_device().has(::sycl::aspect::fp64);
if (has_fp64_support) {
return ElementWiseSum<double>(qu, weights);
} else {
return ElementWiseSum<float>(qu, weights);
}
}
} // namespace xgboost::common::sycl_impl
Loading