From 7dde2f67108b3626c2fffb8422950add4cb5ebee Mon Sep 17 00:00:00 2001 From: Simone Date: Thu, 18 Dec 2025 19:28:53 +0100 Subject: [PATCH 1/2] Implement `get_queue` overload for native streams --- include/CLUEstering/utils/get_queue.hpp | 24 ++++++++++++--- tests/test_utilities.cpp | 40 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/include/CLUEstering/utils/get_queue.hpp b/include/CLUEstering/utils/get_queue.hpp index 02300332..5b71220d 100644 --- a/include/CLUEstering/utils/get_queue.hpp +++ b/include/CLUEstering/utils/get_queue.hpp @@ -17,9 +17,9 @@ namespace clue { /// @param device_id The index of the device /// @return An alpaka queue created from the device corresponding to the given index template - inline clue::Queue get_queue(TIdx device_id = TIdx{}) { + inline auto get_queue(TIdx device_id = TIdx{}) { auto device = alpaka::getDevByIdx(clue::Platform{}, device_id); - return clue::Queue{device}; + return clue::Queue(device); } /// @brief Get an alpaka queue created from a given device @@ -28,8 +28,24 @@ namespace clue { /// @param device The device to create the queue from /// @return An alpaka queue created from the given device template - inline clue::Queue get_queue(const TDevice& device) { - return clue::Queue{device}; + inline auto get_queue(const TDevice& device) { + return clue::Queue(device); } +#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED + /// @brief Get an alpaka queue wrapping a CUDA stream + /// + /// @param stream The CUDA stream to wrap inside the alpaka queue + /// @return An alpaka queue wrapping the given CUDA stream + inline auto get_queue(cudaStream_t& stream) { return clue::Queue(stream); } +#endif + +#ifdef ALPAKA_ACC_GPU_HIP_ENABLED + /// @brief Get an alpaka queue wrapping a HIP stream + /// + /// @param stream The HIP stream to wrap inside the alpaka queue + /// @return An alpaka queue wrapping the given HIP stream + inline auto get_queue(hipStream_t& stream) { return clue::Queue(stream); } +#endif + } // namespace clue diff --git a/tests/test_utilities.cpp b/tests/test_utilities.cpp index 328b5e6e..b4519edf 100644 --- a/tests/test_utilities.cpp +++ b/tests/test_utilities.cpp @@ -58,6 +58,46 @@ TEST_CASE("Test clue::get_queue utility") { auto d_points2 = clue::PointsDevice<2>(queue2, points2.size()); CHECK(1); } + +#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED + SUBCASE("Create queue using CUDA stream") { + cudaStream_t stream; + cudaStreamCreate(&stream); + + { + auto queue = clue::get_queue(stream); + static_assert(std::is_same_v, "Expected type clue::Queue"); + CHECK(alpaka::getDev(queue) == alpaka::getDevByIdx(clue::Platform{}, 0u)); + + // check if data allocation works + clue::PointsHost<2> points1(queue, 1000); + auto d_points1 = clue::PointsDevice<2>(queue, points1.size()); + CHECK(1); + } + + cudaStreamDestroy(stream); + } +#endif + +#ifdef ALPAKA_ACC_GPU_HIP_ENABLED + SUBCASE("Create queue using HIP stream") { + hipStream_t stream; + hipStreamCreate(&stream); + + { + auto queue = clue::get_queue(stream); + static_assert(std::is_same_v, "Expected type clue::Queue"); + CHECK(alpaka::getDev(queue) == alpaka::getDevByIdx(clue::Platform{}, 0u)); + + // check if data allocation works + clue::PointsHost<2> points1(queue, 1000); + auto d_points1 = clue::PointsDevice<2>(queue, points1.size()); + CHECK(1); + } + + hipStreamDestroy(stream); + } +#endif } TEST_CASE("Test get_clusters host function") { From bd5e70fa13db1b4d638b73a0000978cb767f372a Mon Sep 17 00:00:00 2001 From: Simone Date: Thu, 18 Dec 2025 19:29:59 +0100 Subject: [PATCH 2/2] Update native examples --- examples/cuda_native/main.cu | 2 +- examples/hip_native/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cuda_native/main.cu b/examples/cuda_native/main.cu index e7d04d24..bec2cb07 100644 --- a/examples/cuda_native/main.cu +++ b/examples/cuda_native/main.cu @@ -23,7 +23,7 @@ void compute_clusters(TQueue& queue, std::vector& cluster_indexes) { int main() { cudaStream_t stream; cudaStreamCreate(&stream); - clue::Queue queue(stream); + auto queue = clue::get_queue(stream); std::vector cluster_indexes; compute_clusters(queue, cluster_indexes); diff --git a/examples/hip_native/main.cpp b/examples/hip_native/main.cpp index 65aec4e0..0a214e98 100644 --- a/examples/hip_native/main.cpp +++ b/examples/hip_native/main.cpp @@ -23,7 +23,7 @@ void compute_clusters(TQueue& queue, std::vector& cluster_indexes) { int main() { hipStream_t stream; hipStreamCreate(&stream); - clue::Queue queue(stream); + auto queue = clue::get_queue(stream); std::vector cluster_indexes; compute_clusters(queue, cluster_indexes);