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);
81 inline status_t unmap_nothrow(
void* ipc_mapped_ptr) noexcept
91 inline void unmap(
void* ipc_mapped_ptr)
93 auto status = unmap_nothrow(ipc_mapped_ptr);
94 throw_if_error_lazy(status,
"Failed unmapping IPC memory mapped to " + cuda::detail_::ptr_as_hex(ipc_mapped_ptr));
116 + cuda::detail_::ptr_as_hex(device_ptr));
130 imported_ptr_t(
void* ptr,
bool owning) : ptr_(ptr), owning_(owning)
132 if (ptr_ ==
nullptr) {
133 throw ::std::logic_error(
"IPC memory handle yielded a null pointer");
142 if (not owning_) {
return; }
143 #if THROW_IN_DESTRUCTORS 144 detail_::unmap(ptr_);
146 detail_::unmap_nothrow(ptr_);
156 ::std::swap(ptr_, other.ptr_);
157 ::std::swap(owning_, other.owning_);
165 template <
typename T =
void>
166 T*
get()
const noexcept
170 return static_cast<T*
>(
const_cast<void*
>(ptr_));
191 return wrap(raw_ptr, do_take_ownership);
196 #if CUDA_VERSION >= 11020 203 template <shared_handle_kind_t Kind>
204 shared_handle_t<Kind>
export_(
const pool_t& pool);
208 template <shared_handle_kind_t Kind>
209 pool::handle_t import(
const shared_handle_t<Kind>& shared_pool_handle)
212 static constexpr
const unsigned long long flags { 0 };
213 void * ptr_to_handle =
static_cast<void*
>(
const_cast<shared_handle_t<Kind>*
>(&shared_pool_handle));
214 auto status = cuMemPoolImportFromShareableHandle(
215 &result, ptr_to_handle, static_cast<CUmemAllocationHandleType>(Kind), flags);
222 template <shared_handle_kind_t Kind>
223 pool_t
import(
const device_t& device,
const shared_handle_t<Kind>& shared_pool_handle);
227 auto status = cuMemPoolExportPointer(&handle,
device::address(pool_allocated));
229 "Failed producing an IPC handle for memory-pool-allocated pointer " 230 + cuda::detail_::ptr_as_hex(pool_allocated));
238 CUdeviceptr imported;
239 auto status = cuMemPoolImportPointer(&imported, pool_handle, const_cast<ptr_handle_t*>(&handle));
265 #endif // CUDA_VERSION >= 11020 283 auto status = cuIpcGetEventHandle(&ipc_handle, event_handle);
285 event::detail_::identify(event_handle));
292 auto status = cuIpcOpenEventHandle(&event_handle, handle);
338 #endif // CUDA_API_WRAPPERS_IPC_HPP_ Proxy class for a CUDA stream.
Definition: stream.hpp:258
Wrapper class for a CUDA context.
Definition: context.hpp:249
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:147
Contains a proxy class for CUDA execution contexts.
CUevent handle_t
The CUDA driver's raw handle for events.
Definition: types.hpp:214
CUipcEventHandle handle_t
The concrete value passed between processes, used to tell the CUDA Runtime API which event is desired...
Definition: ipc.hpp:276
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:327
bool is_owning() const noexcept
Definition: ipc.hpp:174
A smart-pointer-like class for memory obtained via inter-process communication.
Definition: ipc.hpp:128
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:684
void * as_pointer(device::address_t address) noexcept
Definition: types.hpp:702
Wrapper class for a CUDA device.
Definition: device.hpp:135
Fundamental CUDA-related type definitions.
CUresult status_t
Indicates either the result (success or error index) of a CUDA Runtime or Driver API call...
Definition: types.hpp:74