24 #ifndef CUDA_API_WRAPPERS_IPC_HPP_ 25 #define CUDA_API_WRAPPERS_IPC_HPP_ 69 CUdeviceptr device_ptr;
70 auto status = cuIpcOpenMemHandle(&device_ptr, handle, CU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS);
80 inline void unmap(
void* ipc_mapped_ptr)
83 throw_if_error_lazy(status,
"Failed unmapping IPC memory mapped to " + cuda::detail_::ptr_as_hex(ipc_mapped_ptr));
105 + cuda::detail_::ptr_as_hex(device_ptr));
119 imported_ptr_t(
void* ptr,
bool owning) : ptr_(ptr), owning_(owning)
121 if (ptr_ ==
nullptr) {
122 throw ::std::logic_error(
"IPC memory handle yielded a null pointer");
131 if (owning_) { detail_::unmap(ptr_); }
140 ::std::swap(ptr_, other.ptr_);
141 ::std::swap(owning_, other.owning_);
149 template <
typename T =
void>
150 T*
get()
const noexcept
154 return static_cast<T*
>(
const_cast<void*
>(ptr_));
175 return wrap(raw_ptr, do_take_ownership);
180 #if CUDA_VERSION >= 11020 187 template <shared_handle_kind_t Kind>
188 shared_handle_t<Kind>
export_(
const pool_t& pool);
192 template <shared_handle_kind_t Kind>
193 pool::handle_t import(
const shared_handle_t<Kind>& shared_pool_handle)
196 static constexpr
const unsigned long long flags { 0 };
197 void * ptr_to_handle =
static_cast<void*
>(
const_cast<shared_handle_t<Kind>*
>(&shared_pool_handle));
198 auto status = cuMemPoolImportFromShareableHandle(
199 &result, ptr_to_handle, static_cast<CUmemAllocationHandleType>(Kind), flags);
206 template <shared_handle_kind_t Kind>
207 pool_t
import(
const device_t& device,
const shared_handle_t<Kind>& shared_pool_handle);
211 auto status = cuMemPoolExportPointer(&handle,
device::address(pool_allocated));
213 "Failed producing an IPC handle for memory-pool-allocated pointer " 214 + cuda::detail_::ptr_as_hex(pool_allocated));
222 CUdeviceptr imported;
223 auto status = cuMemPoolImportPointer(&imported, pool_handle, const_cast<ptr_handle_t*>(&handle));
249 #endif // CUDA_VERSION >= 11020 267 auto status = cuIpcGetEventHandle(&ipc_handle, event_handle);
269 event::detail_::identify(event_handle));
276 auto status = cuIpcOpenEventHandle(&event_handle, handle);
322 #endif // CUDA_API_WRAPPERS_IPC_HPP_ Proxy class for a CUDA stream.
Definition: stream.hpp:246
Wrapper class for a CUDA context.
Definition: context.hpp:244
Definitions and functionality wrapping CUDA APIs.
Definition: array.hpp:22
handle_t export_(const event_t &event)
Enable use of an event which this process created by other processes.
Definition: event.hpp:71
event_t import(const context_t &context, const handle_t &event_ipc_handle)
Definition: event.hpp:76
Wrapper class for a CUDA event.
Definition: event.hpp:133
Contains a proxy class for CUDA execution contexts.
CUevent handle_t
The CUDA driver's raw handle for events.
Definition: types.hpp:217
CUipcEventHandle handle_t
The concrete value passed between processes, used to tell the CUDA Runtime API which event is desired...
Definition: ipc.hpp:260
CUipcMemHandle ptr_handle_t
The concrete value passed between processes, used to tell the CUDA Runtime API which memory area is d...
Definition: ipc.hpp:50
#define throw_if_error_lazy(status__,...)
A macro for only throwing an error if we've failed - which also ensures no string is constructed unle...
Definition: error.hpp:316
bool is_owning() const noexcept
Definition: ipc.hpp:158
A smart-pointer-like class for memory obtained via inter-process communication.
Definition: ipc.hpp:117
Facilities for exception-based handling of Runtime and Driver API errors, including a basic exception...
address_t address(const void *device_ptr) noexcept
Definition: types.hpp:682
void * as_pointer(device::address_t address) noexcept
Definition: types.hpp:700
Wrapper class for a CUDA device.
Definition: device.hpp:135
Fundamental CUDA-related type definitions.