@@ -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;
@@ -128,6 +133,7 @@ extern decltype(&cuGraphicsUnregisterResource) p_cuGraphicsUnregisterResource;
128133
129134// Texture / surface / array (PR #467)
130135extern decltype (&cuArray3DCreate) p_cuArray3DCreate;
136+ extern decltype (&cuArray3DGetDescriptor) p_cuArray3DGetDescriptor;
131137extern decltype (&cuArrayDestroy) p_cuArrayDestroy;
132138extern decltype (&cuMipmappedArrayCreate) p_cuMipmappedArrayCreate;
133139extern decltype (&cuMipmappedArrayDestroy) p_cuMipmappedArrayDestroy;
@@ -246,6 +252,17 @@ ContextHandle get_primary_context(int device_id);
246252// Returns empty handle if no context is current (caller must check)
247253ContextHandle get_current_context ();
248254
255+ // Synchronize the provided context.
256+ // Returns CUDA_ERROR_INVALID_CONTEXT for an empty handle.
257+ CUresult context_synchronize (const ContextHandle& h_context) noexcept ;
258+
259+ // Query the stream priority range for the provided context.
260+ // Returns CUDA_ERROR_INVALID_CONTEXT for an empty handle.
261+ CUresult context_get_stream_priority_range (
262+ const ContextHandle& h_context,
263+ int * least_priority,
264+ int * greatest_priority) noexcept ;
265+
249266// ============================================================================
250267// Stream handle functions
251268// ============================================================================
@@ -371,10 +388,11 @@ DevicePtrHandle deviceptr_alloc_from_pool(
371388// Returns empty handle on error (caller must check).
372389DevicePtrHandle deviceptr_alloc_async (size_t size, const StreamHandle& h_stream);
373390
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);
391+ // Allocate device memory synchronously via cuMemAlloc with the provided
392+ // context current. The caller owns the pointer and releases it with cuMemFree.
393+ // Returns CUDA_ERROR_INVALID_CONTEXT for an empty handle.
394+ CUresult deviceptr_alloc_raw (CUdeviceptr* ptr, size_t size,
395+ const ContextHandle& h_context) noexcept ;
378396
379397// Allocate pinned host memory via cuMemAllocHost.
380398// When the last reference is released, cuMemFreeHost is called.
@@ -739,7 +757,7 @@ FileDescriptorHandle create_fd_handle_ref(int fd);
739757// Create an owning CUDA array via cuArray3DCreate.
740758// When the last reference is released, cuArrayDestroy is called automatically.
741759// Returns empty handle on error (caller must check).
742- OpaqueArrayHandle create_array_handle (const CUDA_ARRAY3D_DESCRIPTOR & desc);
760+ OpaqueArrayHandle create_array_handle (const ContextHandle& h_context, const CUDA_ARRAY3D_DESCRIPTOR & desc);
743761
744762// Create a non-owning array handle (references an existing CUarray).
745763// Use for arrays owned elsewhere (e.g. graphics interop). Never destroyed here.
@@ -749,6 +767,12 @@ OpaqueArrayHandle create_array_handle_ref(CUarray arr);
749767// When the last reference is released, cuArrayDestroy is called automatically.
750768OpaqueArrayHandle create_array_handle_owning (CUarray arr);
751769
770+ // Return the context dependency associated with an array, if known.
771+ ContextHandle get_array_context (const OpaqueArrayHandle& h) noexcept ;
772+
773+ // Query an array descriptor.
774+ CUresult get_array_descriptor (const OpaqueArrayHandle& h, CUDA_ARRAY3D_DESCRIPTOR * desc) noexcept ;
775+
752776// Create a non-owning handle to a mipmap level via cuMipmappedArrayGetLevel.
753777// The level CUarray is owned by the mipmap; the parent MipmappedArrayHandle is
754778// embedded in the box so it outlives the level view. No destroy in the deleter.
@@ -758,27 +782,35 @@ OpaqueArrayHandle create_array_level_handle(const MipmappedArrayHandle& h_mip, u
758782// Create an owning mipmapped array via cuMipmappedArrayCreate.
759783// When the last reference is released, cuMipmappedArrayDestroy is called.
760784// Returns empty handle on error (caller must check).
761- MipmappedArrayHandle create_mipmapped_array_handle (const CUDA_ARRAY3D_DESCRIPTOR & desc,
785+ MipmappedArrayHandle create_mipmapped_array_handle (const ContextHandle& h_context,
786+ const CUDA_ARRAY3D_DESCRIPTOR & desc,
762787 unsigned int num_levels);
763788
789+ // Return the context dependency associated with a mipmapped array, if known.
790+ ContextHandle get_mipmapped_array_context (const MipmappedArrayHandle& h) noexcept ;
791+
764792// Create an owning texture object via cuTexObjectCreate, embedding the backing
765793// resource handle (array / mipmapped array / linear-or-pitch2d device pointer)
766794// so the backing always outlives the texture. cuTexObjectDestroy runs in the
767795// deleter. Returns empty handle on error (caller must check).
768- TexObjectHandle create_tex_object_handle_array (const CUDA_RESOURCE_DESC & res,
796+ TexObjectHandle create_tex_object_handle_array (const ContextHandle& h_context,
797+ const CUDA_RESOURCE_DESC & res,
769798 const CUDA_TEXTURE_DESC & tex,
770799 const OpaqueArrayHandle& h_backing);
771- TexObjectHandle create_tex_object_handle_mipmap (const CUDA_RESOURCE_DESC & res,
800+ TexObjectHandle create_tex_object_handle_mipmap (const ContextHandle& h_context,
801+ const CUDA_RESOURCE_DESC & res,
772802 const CUDA_TEXTURE_DESC & tex,
773803 const MipmappedArrayHandle& h_backing);
774- TexObjectHandle create_tex_object_handle_linear (const CUDA_RESOURCE_DESC & res,
804+ TexObjectHandle create_tex_object_handle_linear (const ContextHandle& h_context,
805+ const CUDA_RESOURCE_DESC & res,
775806 const CUDA_TEXTURE_DESC & tex,
776807 const DevicePtrHandle& h_backing);
777808
778809// Create an owning surface object via cuSurfObjectCreate, embedding the backing
779810// array handle so it outlives the surface. cuSurfObjectDestroy runs in the
780811// deleter. Returns empty handle on error (caller must check).
781- SurfObjectHandle create_surf_object_handle (const CUDA_RESOURCE_DESC & res,
812+ SurfObjectHandle create_surf_object_handle (const ContextHandle& h_context,
813+ const CUDA_RESOURCE_DESC & res,
782814 const OpaqueArrayHandle& h_backing);
783815
784816// ============================================================================
0 commit comments