From afcee70571ca7e1dbf63cc7dc8594d01f6ee2987 Mon Sep 17 00:00:00 2001 From: Hugh Delaney Date: Thu, 14 Nov 2024 17:16:20 +0000 Subject: [PATCH] Use nullptr default initialization Don't need extra flag for IsInitialized if checking if cudaGraphExec is no longer its initial value of nullptr. --- source/adapters/cuda/command_buffer.cpp | 4 ++-- source/adapters/cuda/command_buffer.hpp | 4 +--- source/adapters/hip/command_buffer.cpp | 4 ++-- source/adapters/hip/command_buffer.hpp | 4 +--- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/source/adapters/cuda/command_buffer.cpp b/source/adapters/cuda/command_buffer.cpp index 1ea823c255..b6aad34e21 100644 --- a/source/adapters/cuda/command_buffer.cpp +++ b/source/adapters/cuda/command_buffer.cpp @@ -401,7 +401,8 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t hCommandBuffer) { UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t hCommandBuffer) { - UR_ASSERT(!hCommandBuffer->IsFinalized, UR_RESULT_ERROR_INVALID_OPERATION); + UR_ASSERT(hCommandBuffer->CudaGraphExec == nullptr, + UR_RESULT_ERROR_INVALID_OPERATION); try { const unsigned long long flags = 0; #if CUDA_VERSION >= 12000 @@ -419,7 +420,6 @@ urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t hCommandBuffer) { } catch (...) { return UR_RESULT_ERROR_UNKNOWN; } - hCommandBuffer->IsFinalized = true; return UR_RESULT_SUCCESS; } diff --git a/source/adapters/cuda/command_buffer.hpp b/source/adapters/cuda/command_buffer.hpp index aa7968959b..2537aad11a 100644 --- a/source/adapters/cuda/command_buffer.hpp +++ b/source/adapters/cuda/command_buffer.hpp @@ -352,12 +352,10 @@ struct ur_exp_command_buffer_handle_t_ { ur_device_handle_t Device; // Whether commands in the command-buffer can be updated bool IsUpdatable; - // Keep track of whether command buffer is finalized - bool IsFinalized = false; // Cuda Graph handle CUgraph CudaGraph; // Cuda Graph Exec handle - CUgraphExec CudaGraphExec; + CUgraphExec CudaGraphExec = nullptr; // Atomic variable counting the number of reference to this command_buffer // using std::atomic prevents data race when incrementing/decrementing. std::atomic_uint32_t RefCountInternal; diff --git a/source/adapters/hip/command_buffer.cpp b/source/adapters/hip/command_buffer.cpp index c522f5324d..770b98c90f 100644 --- a/source/adapters/hip/command_buffer.cpp +++ b/source/adapters/hip/command_buffer.cpp @@ -306,7 +306,8 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t hCommandBuffer) { UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t hCommandBuffer) { - UR_ASSERT(!hCommandBuffer->IsFinalized, UR_RESULT_ERROR_INVALID_OPERATION); + UR_ASSERT(hCommandBuffer->HIPGraphExec == nullptr, + UR_RESULT_ERROR_INVALID_OPERATION); try { const unsigned long long flags = 0; UR_CHECK_ERROR(hipGraphInstantiateWithFlags( @@ -314,7 +315,6 @@ urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t hCommandBuffer) { } catch (...) { return UR_RESULT_ERROR_UNKNOWN; } - hCommandBuffer->IsFinalized = true; return UR_RESULT_SUCCESS; } diff --git a/source/adapters/hip/command_buffer.hpp b/source/adapters/hip/command_buffer.hpp index 27ad07b1cf..a236a32c24 100644 --- a/source/adapters/hip/command_buffer.hpp +++ b/source/adapters/hip/command_buffer.hpp @@ -172,12 +172,10 @@ struct ur_exp_command_buffer_handle_t_ { ur_device_handle_t Device; // Whether commands in the command-buffer can be updated bool IsUpdatable; - // Keep track of whether command buffer is finalized - bool IsFinalized = false; // HIP Graph handle hipGraph_t HIPGraph; // HIP Graph Exec handle - hipGraphExec_t HIPGraphExec; + hipGraphExec_t HIPGraphExec = nullptr; // Atomic variable counting the number of reference to this command_buffer // using std::atomic prevents data race when incrementing/decrementing. std::atomic_uint32_t RefCountInternal;