Skip to content

Commit 463fc8c

Browse files
committed
CUEW: Add external memory API functions
Pull Request: https://projects.blender.org/blender/blender/pulls/137363
1 parent b8b7f71 commit 463fc8c

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

extern/cuew/include/cuew.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ typedef struct CUstream_st* CUstream;
155155
typedef struct CUgraphicsResource_st* CUgraphicsResource;
156156
typedef unsigned long long CUtexObject;
157157
typedef unsigned long long CUsurfObject;
158+
typedef struct CUextMemory_st *CUexternalMemory;
158159

159160
typedef struct CUuuid_st {
160161
char bytes[16];
@@ -887,6 +888,49 @@ typedef enum {
887888

888889
typedef struct _nvrtcProgram* nvrtcProgram;
889890

891+
typedef enum CUexternalMemoryHandleType_enum {
892+
CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD = 1,
893+
CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32 = 2,
894+
CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT = 3,
895+
CU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP = 4,
896+
CU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE = 5,
897+
CU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE = 6,
898+
CU_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_RESOURCE_KMT = 7,
899+
CU_EXTERNAL_MEMORY_HANDLE_TYPE_NVSCIBUF = 8,
900+
} CUexternalMemoryHandleType;
901+
902+
typedef struct CUDA_EXTERNAL_MEMORY_HANDLE_DESC_st {
903+
CUexternalMemoryHandleType type;
904+
union {
905+
int fd;
906+
struct {
907+
void *handle;
908+
const void *name;
909+
} win32;
910+
const void *nvSciBufObject;
911+
} handle;
912+
unsigned long long size;
913+
unsigned int flags;
914+
unsigned int reserved[16];
915+
} CUDA_EXTERNAL_MEMORY_HANDLE_DESC_v1;
916+
typedef CUDA_EXTERNAL_MEMORY_HANDLE_DESC_v1 CUDA_EXTERNAL_MEMORY_HANDLE_DESC;
917+
918+
typedef struct CUDA_EXTERNAL_MEMORY_BUFFER_DESC_st {
919+
unsigned long long offset;
920+
unsigned long long size;
921+
unsigned int flags;
922+
unsigned int reserved[16];
923+
} CUDA_EXTERNAL_MEMORY_BUFFER_DESC_v1;
924+
typedef CUDA_EXTERNAL_MEMORY_BUFFER_DESC_v1 CUDA_EXTERNAL_MEMORY_BUFFER_DESC;
925+
926+
typedef struct CUDA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC_st {
927+
unsigned long long offset;
928+
CUDA_ARRAY3D_DESCRIPTOR arrayDesc;
929+
unsigned int numLevels;
930+
unsigned int reserved[16];
931+
} CUDA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC_v1;
932+
typedef CUDA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC_v1 CUDA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC;
933+
890934

891935
/* Function types. */
892936
typedef CUresult CUDAAPI tcuGetErrorString(CUresult error, const char** pStr);
@@ -1116,6 +1160,11 @@ typedef CUresult CUDAAPI tcuGLSetBufferObjectMapFlags(GLuint buffer, unsigned in
11161160
typedef CUresult CUDAAPI tcuGLMapBufferObjectAsync_v2(CUdeviceptr* dptr, size_t* size, GLuint buffer, CUstream hStream);
11171161
typedef CUresult CUDAAPI tcuGLUnmapBufferObjectAsync(GLuint buffer, CUstream hStream);
11181162

1163+
typedef CUresult CUDAAPI tcuImportExternalMemory(CUexternalMemory *extMem_out, const CUDA_EXTERNAL_MEMORY_HANDLE_DESC *memHandleDesc);
1164+
typedef CUresult CUDAAPI tcuExternalMemoryGetMappedBuffer(CUdeviceptr *devPtr, CUexternalMemory extMem, const CUDA_EXTERNAL_MEMORY_BUFFER_DESC *bufferDesc);
1165+
typedef CUresult CUDAAPI tcuExternalMemoryGetMappedMipmappedArray(CUmipmappedArray *mipmap, CUexternalMemory extMem, const CUDA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC *mipmapDesc);
1166+
typedef CUresult CUDAAPI tcuDestroyExternalMemory(CUexternalMemory extMem);
1167+
11191168
typedef const char* CUDAAPI tnvrtcGetErrorString(nvrtcResult result);
11201169
typedef nvrtcResult CUDAAPI tnvrtcVersion(int* major, int* minor);
11211170
typedef nvrtcResult CUDAAPI tnvrtcCreateProgram(nvrtcProgram* prog, const char* src, const char* name, int numHeaders, const char** headers, const char** includeNames);
@@ -1357,6 +1406,11 @@ extern tcuGLSetBufferObjectMapFlags *cuGLSetBufferObjectMapFlags;
13571406
extern tcuGLMapBufferObjectAsync_v2 *cuGLMapBufferObjectAsync_v2;
13581407
extern tcuGLUnmapBufferObjectAsync *cuGLUnmapBufferObjectAsync;
13591408

1409+
extern tcuImportExternalMemory *cuImportExternalMemory;
1410+
extern tcuExternalMemoryGetMappedBuffer *cuExternalMemoryGetMappedBuffer;
1411+
extern tcuExternalMemoryGetMappedMipmappedArray *cuExternalMemoryGetMappedMipmappedArray;
1412+
extern tcuDestroyExternalMemory *cuDestroyExternalMemory;
1413+
13601414
extern tnvrtcGetErrorString *nvrtcGetErrorString;
13611415
extern tnvrtcVersion *nvrtcVersion;
13621416
extern tnvrtcCreateProgram *nvrtcCreateProgram;

extern/cuew/src/cuew.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ tcuGLSetBufferObjectMapFlags *cuGLSetBufferObjectMapFlags;
297297
tcuGLMapBufferObjectAsync_v2 *cuGLMapBufferObjectAsync_v2;
298298
tcuGLUnmapBufferObjectAsync *cuGLUnmapBufferObjectAsync;
299299

300+
tcuImportExternalMemory *cuImportExternalMemory;
301+
tcuExternalMemoryGetMappedBuffer *cuExternalMemoryGetMappedBuffer;
302+
tcuExternalMemoryGetMappedMipmappedArray *cuExternalMemoryGetMappedMipmappedArray;
303+
tcuDestroyExternalMemory *cuDestroyExternalMemory;
304+
300305
tnvrtcGetErrorString *nvrtcGetErrorString;
301306
tnvrtcVersion *nvrtcVersion;
302307
tnvrtcCreateProgram *nvrtcCreateProgram;
@@ -607,6 +612,11 @@ static int cuewCudaInit(void) {
607612
CUDA_LIBRARY_FIND(cuGLMapBufferObjectAsync_v2);
608613
CUDA_LIBRARY_FIND(cuGLUnmapBufferObjectAsync);
609614

615+
CUDA_LIBRARY_FIND(cuImportExternalMemory);
616+
CUDA_LIBRARY_FIND(cuExternalMemoryGetMappedBuffer);
617+
CUDA_LIBRARY_FIND(cuExternalMemoryGetMappedMipmappedArray);
618+
CUDA_LIBRARY_FIND(cuDestroyExternalMemory);
619+
610620
result = CUEW_SUCCESS;
611621
return result;
612622
}

0 commit comments

Comments
 (0)