Skip to content

Commit

Permalink
Stopgap
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrimsontianyu committed Sep 10, 2024
1 parent 949f171 commit d167d6e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ add_dependencies(cudf jitify_preprocess_run)
# Specify the target module library dependencies
target_link_libraries(
cudf
PUBLIC CCCL::CCCL rmm::rmm $<BUILD_LOCAL_INTERFACE:BS::thread_pool>
PUBLIC CCCL::CCCL rmm::rmm $<BUILD_LOCAL_INTERFACE:BS::thread_pool> CUDA::cuda_driver
PRIVATE $<BUILD_LOCAL_INTERFACE:nvtx3::nvtx3-cpp> cuco::cuco ZLIB::ZLIB nvcomp::nvcomp
kvikio::kvikio $<TARGET_NAME_IF_EXISTS:cuFile_interface> nanoarrow
)
Expand Down
36 changes: 34 additions & 2 deletions cpp/src/utilities/stream_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,49 @@ rmm::cuda_device_id get_current_cuda_device()
return rmm::cuda_device_id{device_id};
}

class primary_context_checker {
public:
void initialize()
{
int device_id{};
cudaGetDevice(&device_id); // TODO: Handle runtime API error code
cuDeviceGet(&device_handle_, device_id); // TODO: Handle driver API error code
}

bool is_primary_context_active()
{
int active_state{};
// TODO: Handle driver API error code
cuDevicePrimaryCtxGetState(
device_handle_, nullptr /* do not query context flags */, &active_state);
return static_cast<bool>(active_state);
}

private:
CUdevice device_handle_{};
};

/**
* @brief RAII struct to wrap a cuda event and ensure its proper destruction.
*/
struct cuda_event {
cuda_event() { CUDF_CUDA_TRY(cudaEventCreateWithFlags(&e_, cudaEventDisableTiming)); }
virtual ~cuda_event() { CUDF_ASSERT_CUDA_SUCCESS(cudaEventDestroy(e_)); }
cuda_event()
{
CUDF_CUDA_TRY(cudaEventCreateWithFlags(&e_, cudaEventDisableTiming));
ctx_checker_.initialize();
}
virtual ~cuda_event()
{
if (ctx_checker_.is_primary_context_active()) {
CUDF_ASSERT_CUDA_SUCCESS(cudaEventDestroy(e_));
}
}

operator cudaEvent_t() { return e_; }

private:
cudaEvent_t e_;
primary_context_checker ctx_checker_;
};

/**
Expand Down

0 comments on commit d167d6e

Please sign in to comment.