From c8a5c6aa00d44a246935b88b394695060c6c5464 Mon Sep 17 00:00:00 2001 From: Berenger Bramas Date: Sun, 8 Sep 2024 14:26:16 +0200 Subject: [PATCH] update stream to debug --- Src/Cuda/SpCudaUtils.hpp | 9 +++++++++ Src/Cuda/SpCudaWorkerData.hpp | 2 +- Src/Hip/SpHipUtils.hpp | 9 +++++++++ Src/Hip/SpHipWorkerData.hpp | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Src/Cuda/SpCudaUtils.hpp b/Src/Cuda/SpCudaUtils.hpp index c9e407b0..52bf68bb 100644 --- a/Src/Cuda/SpCudaUtils.hpp +++ b/Src/Cuda/SpCudaUtils.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "Config/SpConfig.hpp" @@ -64,6 +65,12 @@ class SpCudaUtils{ return free_byte; } + static int getUsingDevice() { + int currentDevice; + CUDA_ASSERT(cudaGetDevice(¤tDevice)); + return currentDevice; + } + static void UseDevice(const int deviceId){ if(deviceId >= GetNbDevices()){ std::cerr << "[SPECX] Ask to use gpu " << deviceId @@ -77,6 +84,8 @@ class SpCudaUtils{ } static void SynchronizeStream(cudaStream_t& stream){ + assert(stream != nullptr); + assert(getUsingDevice() != -1); CUDA_ASSERT(cudaStreamSynchronize(stream)); } diff --git a/Src/Cuda/SpCudaWorkerData.hpp b/Src/Cuda/SpCudaWorkerData.hpp index 43658d3c..1d198273 100644 --- a/Src/Cuda/SpCudaWorkerData.hpp +++ b/Src/Cuda/SpCudaWorkerData.hpp @@ -14,7 +14,7 @@ struct SpCudaWorkerData { int cudaId = -1; - cudaStream_t stream; + cudaStream_t stream = nullptr; void init(int deviceId){ cudaId = deviceId; diff --git a/Src/Hip/SpHipUtils.hpp b/Src/Hip/SpHipUtils.hpp index be4e3231..48ec9d26 100644 --- a/Src/Hip/SpHipUtils.hpp +++ b/Src/Hip/SpHipUtils.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "Config/SpConfig.hpp" @@ -64,6 +65,12 @@ class SpHipUtils{ return free_byte; } + static int getUsingDevice() { + int currentDevice; + HIP_ASSERT(hipGetDevice(¤tDevice)); + return currentDevice; + } + static void UseDevice(const int deviceId){ if(deviceId >= GetNbDevices()){ std::cerr << "[SPECX] Ask to use gpu " << deviceId @@ -77,6 +84,8 @@ class SpHipUtils{ } static void SynchronizeStream(hipStream_t& stream){ + assert(stream != nullptr); + assert(getUsingDevice() != -1); HIP_ASSERT(hipStreamSynchronize(stream)); } diff --git a/Src/Hip/SpHipWorkerData.hpp b/Src/Hip/SpHipWorkerData.hpp index 493b4337..49506a87 100644 --- a/Src/Hip/SpHipWorkerData.hpp +++ b/Src/Hip/SpHipWorkerData.hpp @@ -14,7 +14,7 @@ struct SpHipWorkerData { int hipId = -1; - hipStream_t stream; + hipStream_t stream = nullptr; void init(int deviceId){ hipId = deviceId;