From db66fad9e96dffd1088656f853d1ca65230aa16f Mon Sep 17 00:00:00 2001 From: Hendrik Groove Date: Sun, 20 Oct 2024 23:27:50 +0200 Subject: [PATCH] SumReduction logging --- src/common/device_helpers.hip.h | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/common/device_helpers.hip.h b/src/common/device_helpers.hip.h index 92b6c281f..d54be2c16 100644 --- a/src/common/device_helpers.hip.h +++ b/src/common/device_helpers.hip.h @@ -665,21 +665,31 @@ struct PinnedMemory { */ template typename std::iterator_traits::value_type SumReduction(T in, int nVals) { + std::cerr << "Entering SumReduction, nVals: " << nVals << std::endl; using ValueT = typename std::iterator_traits::value_type; + size_t tmpSize {0}; ValueT *dummy_out = nullptr; - dh::safe_cuda(hipcub::DeviceReduce::Sum(nullptr, tmpSize, in, dummy_out, nVals)); + + try { + dh::safe_cuda(hipcub::DeviceReduce::Sum(nullptr, tmpSize, in, dummy_out, nVals)); + std::cerr << "Temporary storage size: " << tmpSize << std::endl; - TemporaryArray temp(tmpSize + sizeof(ValueT)); - auto ptr = reinterpret_cast(temp.data().get()) + 1; - dh::safe_cuda(hipcub::DeviceReduce::Sum( - reinterpret_cast(ptr), tmpSize, in, - reinterpret_cast(temp.data().get()), - nVals)); - ValueT sum; - dh::safe_cuda(hipMemcpy(&sum, temp.data().get(), sizeof(ValueT), - hipMemcpyDeviceToHost)); - return sum; + TemporaryArray temp(tmpSize + sizeof(ValueT)); + auto ptr = reinterpret_cast(temp.data().get()) + 1; + + dh::safe_cuda(hipcub::DeviceReduce::Sum( + reinterpret_cast(ptr), tmpSize, in, reinterpret_cast(temp.data().get()), nVals)); + + ValueT sum; + dh::safe_cuda(hipMemcpy(&sum, temp.data().get(), sizeof(ValueT), hipMemcpyDeviceToHost)); + + std::cerr << "SumReduction completed successfully" << std::endl; + return sum; + } catch (const std::exception& e) { + std::cerr << "Exception in SumReduction: " << e.what() << std::endl; + throw; + } } constexpr std::pair CUDAVersion() {