@@ -64,10 +64,15 @@ void clear_last_error() noexcept;
6464// function pointers extracted from cuda.bindings.cydriver.__pyx_capi__.
6565// ============================================================================
6666
67+ extern decltype (&cuGetErrorName) p_cuGetErrorName;
68+ extern decltype (&cuGetErrorString) p_cuGetErrorString;
69+
6770extern decltype (&cuDevicePrimaryCtxRetain) p_cuDevicePrimaryCtxRetain;
6871extern decltype (&cuDevicePrimaryCtxRelease) p_cuDevicePrimaryCtxRelease;
6972extern decltype (&cuCtxGetCurrent) p_cuCtxGetCurrent;
7073extern decltype (&cuCtxSetCurrent) p_cuCtxSetCurrent;
74+ extern decltype (&cuCtxSynchronize) p_cuCtxSynchronize;
75+ extern decltype (&cuCtxGetStreamPriorityRange) p_cuCtxGetStreamPriorityRange;
7176extern decltype (&cuGreenCtxCreate) p_cuGreenCtxCreate;
7277extern decltype (&cuGreenCtxDestroy) p_cuGreenCtxDestroy;
7378extern decltype (&cuCtxFromGreenCtx) p_cuCtxFromGreenCtx;
@@ -77,6 +82,7 @@ extern decltype(&cuGreenCtxStreamCreate) p_cuGreenCtxStreamCreate;
7782
7883extern decltype (&cuStreamCreateWithPriority) p_cuStreamCreateWithPriority;
7984extern decltype (&cuStreamDestroy) p_cuStreamDestroy;
85+ extern decltype (&cuStreamSynchronize) p_cuStreamSynchronize;
8086
8187extern decltype (&cuEventCreate) p_cuEventCreate;
8288extern decltype (&cuEventDestroy) p_cuEventDestroy;
@@ -128,6 +134,7 @@ extern decltype(&cuGraphicsUnregisterResource) p_cuGraphicsUnregisterResource;
128134
129135// Texture / surface / array (PR #467)
130136extern decltype (&cuArray3DCreate) p_cuArray3DCreate;
137+ extern decltype (&cuArray3DGetDescriptor) p_cuArray3DGetDescriptor;
131138extern decltype (&cuArrayDestroy) p_cuArrayDestroy;
132139extern decltype (&cuMipmappedArrayCreate) p_cuMipmappedArrayCreate;
133140extern decltype (&cuMipmappedArrayDestroy) p_cuMipmappedArrayDestroy;
@@ -246,6 +253,17 @@ ContextHandle get_primary_context(int device_id);
246253// Returns empty handle if no context is current (caller must check)
247254ContextHandle get_current_context ();
248255
256+ // Synchronize the provided context.
257+ // Returns CUDA_ERROR_INVALID_CONTEXT for an empty handle.
258+ CUresult context_synchronize (const ContextHandle& h_context) noexcept ;
259+
260+ // Query the stream priority range for the provided context.
261+ // Returns CUDA_ERROR_INVALID_CONTEXT for an empty handle.
262+ CUresult context_get_stream_priority_range (
263+ const ContextHandle& h_context,
264+ int * least_priority,
265+ int * greatest_priority) noexcept ;
266+
249267// ============================================================================
250268// Stream handle functions
251269// ============================================================================
@@ -371,10 +389,15 @@ DevicePtrHandle deviceptr_alloc_from_pool(
371389// Returns empty handle on error (caller must check).
372390DevicePtrHandle deviceptr_alloc_async (size_t size, const StreamHandle& h_stream);
373391
374- // Allocate device memory synchronously via cuMemAlloc.
375- // When the last reference is released, cuMemFree is called.
376- // Returns empty handle on error (caller must check).
377- DevicePtrHandle deviceptr_alloc (size_t size);
392+ // Allocate device memory synchronously via cuMemAlloc with the provided
393+ // context current. The caller owns the pointer; release it with deviceptr_free.
394+ // Returns CUDA_ERROR_INVALID_CONTEXT for an empty handle.
395+ CUresult deviceptr_alloc_raw (CUdeviceptr* ptr, size_t size,
396+ const ContextHandle& h_context) noexcept ;
397+
398+ // Synchronize the provided stream, if any, then release a synchronous
399+ // allocation via cuMemFree.
400+ CUresult deviceptr_free (CUdeviceptr ptr, const StreamHandle& h_stream) noexcept ;
378401
379402// Allocate pinned host memory via cuMemAllocHost.
380403// When the last reference is released, cuMemFreeHost is called.
@@ -739,7 +762,7 @@ FileDescriptorHandle create_fd_handle_ref(int fd);
739762// Create an owning CUDA array via cuArray3DCreate.
740763// When the last reference is released, cuArrayDestroy is called automatically.
741764// Returns empty handle on error (caller must check).
742- OpaqueArrayHandle create_array_handle (const CUDA_ARRAY3D_DESCRIPTOR & desc);
765+ OpaqueArrayHandle create_array_handle (const ContextHandle& h_context, const CUDA_ARRAY3D_DESCRIPTOR & desc);
743766
744767// Create a non-owning array handle (references an existing CUarray).
745768// Use for arrays owned elsewhere (e.g. graphics interop). Never destroyed here.
@@ -749,6 +772,12 @@ OpaqueArrayHandle create_array_handle_ref(CUarray arr);
749772// When the last reference is released, cuArrayDestroy is called automatically.
750773OpaqueArrayHandle create_array_handle_owning (CUarray arr);
751774
775+ // Return the context dependency associated with an array, if known.
776+ ContextHandle get_array_context (const OpaqueArrayHandle& h) noexcept ;
777+
778+ // Query an array descriptor.
779+ CUresult get_array_descriptor (const OpaqueArrayHandle& h, CUDA_ARRAY3D_DESCRIPTOR * desc) noexcept ;
780+
752781// Create a non-owning handle to a mipmap level via cuMipmappedArrayGetLevel.
753782// The level CUarray is owned by the mipmap; the parent MipmappedArrayHandle is
754783// embedded in the box so it outlives the level view. No destroy in the deleter.
@@ -758,27 +787,35 @@ OpaqueArrayHandle create_array_level_handle(const MipmappedArrayHandle& h_mip, u
758787// Create an owning mipmapped array via cuMipmappedArrayCreate.
759788// When the last reference is released, cuMipmappedArrayDestroy is called.
760789// Returns empty handle on error (caller must check).
761- MipmappedArrayHandle create_mipmapped_array_handle (const CUDA_ARRAY3D_DESCRIPTOR & desc,
790+ MipmappedArrayHandle create_mipmapped_array_handle (const ContextHandle& h_context,
791+ const CUDA_ARRAY3D_DESCRIPTOR & desc,
762792 unsigned int num_levels);
763793
794+ // Return the context dependency associated with a mipmapped array, if known.
795+ ContextHandle get_mipmapped_array_context (const MipmappedArrayHandle& h) noexcept ;
796+
764797// Create an owning texture object via cuTexObjectCreate, embedding the backing
765798// resource handle (array / mipmapped array / linear-or-pitch2d device pointer)
766799// so the backing always outlives the texture. cuTexObjectDestroy runs in the
767800// deleter. Returns empty handle on error (caller must check).
768- TexObjectHandle create_tex_object_handle_array (const CUDA_RESOURCE_DESC & res,
801+ TexObjectHandle create_tex_object_handle_array (const ContextHandle& h_context,
802+ const CUDA_RESOURCE_DESC & res,
769803 const CUDA_TEXTURE_DESC & tex,
770804 const OpaqueArrayHandle& h_backing);
771- TexObjectHandle create_tex_object_handle_mipmap (const CUDA_RESOURCE_DESC & res,
805+ TexObjectHandle create_tex_object_handle_mipmap (const ContextHandle& h_context,
806+ const CUDA_RESOURCE_DESC & res,
772807 const CUDA_TEXTURE_DESC & tex,
773808 const MipmappedArrayHandle& h_backing);
774- TexObjectHandle create_tex_object_handle_linear (const CUDA_RESOURCE_DESC & res,
809+ TexObjectHandle create_tex_object_handle_linear (const ContextHandle& h_context,
810+ const CUDA_RESOURCE_DESC & res,
775811 const CUDA_TEXTURE_DESC & tex,
776812 const DevicePtrHandle& h_backing);
777813
778814// Create an owning surface object via cuSurfObjectCreate, embedding the backing
779815// array handle so it outlives the surface. cuSurfObjectDestroy runs in the
780816// deleter. Returns empty handle on error (caller must check).
781- SurfObjectHandle create_surf_object_handle (const CUDA_RESOURCE_DESC & res,
817+ SurfObjectHandle create_surf_object_handle (const ContextHandle& h_context,
818+ const CUDA_RESOURCE_DESC & res,
782819 const OpaqueArrayHandle& h_backing);
783820
784821// ============================================================================
0 commit comments