finish numeric.cu

This commit is contained in:
amdsc21 2023-03-10 05:16:23 +01:00
parent bb6adda8a3
commit 8fd2af1c8b
3 changed files with 17 additions and 2 deletions

View File

@ -3,7 +3,12 @@
*/
#include <thrust/execution_policy.h>
#if defined(XGBOOST_USE_CUDA)
#include "device_helpers.cuh" // dh::Reduce, dh::XGBCachingDeviceAllocator
#elif defined(XGBOOST_USE_HIP)
#include "device_helpers.hip.h" // dh::Reduce, dh::XGBCachingDeviceAllocator
#endif
#include "numeric.h"
#include "xgboost/context.h" // Context
#include "xgboost/host_device_vector.h" // HostDeviceVector
@ -15,8 +20,14 @@ double Reduce(Context const* ctx, HostDeviceVector<float> const& values) {
values.SetDevice(ctx->gpu_id);
auto const d_values = values.ConstDeviceSpan();
dh::XGBCachingDeviceAllocator<char> alloc;
#if defined(XGBOOST_USE_CUDA)
return dh::Reduce(thrust::cuda::par(alloc), dh::tcbegin(d_values), dh::tcend(d_values), 0.0,
thrust::plus<float>{});
#elif defined(XGBOOST_USE_HIP)
return dh::Reduce(thrust::hip::par(alloc), dh::tcbegin(d_values), dh::tcend(d_values), 0.0,
thrust::plus<float>{});
#endif
}
} // namespace cuda_impl
} // namespace common

View File

@ -97,12 +97,12 @@ void PartialSum(int32_t n_threads, InIt begin, InIt end, T init, OutIt out_it) {
namespace cuda_impl {
double Reduce(Context const* ctx, HostDeviceVector<float> const& values);
#if !defined(XGBOOST_USE_CUDA)
#if !defined(XGBOOST_USE_CUDA) && !defined(XGBOOST_USE_HIP)
inline double Reduce(Context const*, HostDeviceVector<float> const&) {
AssertGPUSupport();
return 0;
}
#endif // !defined(XGBOOST_USE_CUDA)
#endif // !defined(XGBOOST_USE_CUDA) && !defined(XGBOOST_USE_HIP)
} // namespace cuda_impl
/**

View File

@ -0,0 +1,4 @@
#if defined(XGBOOST_USE_HIP)
#include "numeric.cu"
#endif