10#if defined(TRITON_CPP_ENABLE_CUDA_SHM)
11#include <cuda_runtime_api.h>
16#if defined(TRITON_CPP_ENABLE_CUDA_SHM)
25 if (status == cudaSuccess) {
28 throw std::runtime_error(std::string(operation) +
" failed: " + cudaGetErrorString(status));
38 const auto status = cudaGetDeviceCount(&device_count);
39 if (status != cudaSuccess) {
40 if (reason !=
nullptr) {
41 *reason = cudaGetErrorString(status);
46 if (device_count <= 0) {
47 if (reason !=
nullptr) {
48 *reason =
"no CUDA-capable device is visible to the client";
71 throw_on_cuda_error(cudaMalloc(
reinterpret_cast<void**
>(&device_ptr_),
static_cast<std::size_t
>(size_)),
"cudaMalloc");
77 if (device_ptr_ !=
nullptr) {
78 cudaFree(device_ptr_);
90 const cudaIpcMemHandle_t&
getIpcHandle()
const {
return ipc_handle_; }
92 std::size_t
getDeviceId()
const {
return static_cast<std::size_t
>(device_id_); }
94 std::int64_t
getSize()
const {
return size_; }
96 const std::string&
getName()
const {
return name_; }
100 std::int64_t size_ = 0;
102 uint8_t* device_ptr_ =
nullptr;
103 cudaIpcMemHandle_t ipc_handle_{};
Own a CUDA device allocation exportable through a CUDA IPC handle.
const std::string & getName() const
CudaSharedMemoryRegion(const CudaSharedMemoryRegion &)=delete
~CudaSharedMemoryRegion()
Release the owned CUDA device allocation.
CudaSharedMemoryRegion & operator=(const CudaSharedMemoryRegion &)=delete
CudaSharedMemoryRegion(CudaSharedMemoryRegion &&)=delete
std::int64_t getSize() const
uint8_t * getDeviceAddress() const
std::size_t getDeviceId() const
const cudaIpcMemHandle_t & getIpcHandle() const
CudaSharedMemoryRegion & operator=(CudaSharedMemoryRegion &&)=delete
CudaSharedMemoryRegion(const std::string &name, std::int64_t size)
Allocate a CUDA shared-memory region on the current device.
void throw_on_cuda_error(cudaError_t status, const char *operation)
Throw a descriptive exception when a CUDA Runtime API call fails.
bool LocalCudaSharedMemorySupported(std::string *reason=nullptr)
Check whether this process can allocate CUDA IPC shared memory.