Skip to content

Commit

Permalink
Use nullptr default initialization
Browse files Browse the repository at this point in the history
Don't need extra flag for IsInitialized if checking if cudaGraphExec is
no longer its initial value of nullptr.
  • Loading branch information
hdelan committed Nov 15, 2024
1 parent 7de661f commit afcee70
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions source/adapters/cuda/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions source/adapters/cuda/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/hip/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@ 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(
&hCommandBuffer->HIPGraphExec, hCommandBuffer->HIPGraph, flags));
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
hCommandBuffer->IsFinalized = true;
return UR_RESULT_SUCCESS;
}

Expand Down
4 changes: 1 addition & 3 deletions source/adapters/hip/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit afcee70

Please sign in to comment.