-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCudaFunctionNV.cpp
More file actions
79 lines (64 loc) · 2.42 KB
/
Copy pathCudaFunctionNV.cpp
File metadata and controls
79 lines (64 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#if defined(VK_CUDA_MODULE)
#include "CudaFunctionNV.h"
#include <new>
#include "Device.h"
#include "Internal/Error.h"
extern "C"
{
GPU_API VkResult GPU_CALL gpuCudaFunctionNVCreate(
GPUDevice device,
const VkCudaFunctionCreateInfoNV *createInfo,
const VkAllocationCallbacks *allocator,
GPUCudaFunctionNV *function)
{
gpu::internal::clearLastError();
if (device == nullptr || createInfo == nullptr || function == nullptr)
{
gpu::internal::setLastError("Device, create info, and CUDA function output must not be null.");
return VK_ERROR_INITIALIZATION_FAILED;
}
if (device->destroyRequested)
{
gpu::internal::setLastError("Device is being destroyed.");
return VK_ERROR_INITIALIZATION_FAILED;
}
*function = nullptr;
VkCudaFunctionNV handle = VK_NULL_HANDLE;
const VkResult result = gpuCreateCudaFunctionNV(device->handle, createInfo, allocator, &handle);
if (result != VK_SUCCESS)
{
gpu::internal::setLastError("Failed to create CUDA function NV.");
return result;
}
GPUCudaFunctionNV wrapper = new (std::nothrow) GPUCudaFunctionNV_T{device, handle, allocator, false};
if (wrapper == nullptr)
{
gpuDestroyCudaFunctionNV(device->handle, handle, allocator);
gpu::internal::setLastError("Failed to allocate CudaFunctionNV.");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
gpuDeviceRetain(device);
*function = wrapper;
return VK_SUCCESS;
}
GPU_API void GPU_CALL gpuCudaFunctionNVDestroy(GPUCudaFunctionNV function)
{
if (function == nullptr || function->destroyRequested)
{
return;
}
function->destroyRequested = true;
gpuDestroyCudaFunctionNV(function->device->handle, function->handle, function->allocator);
gpuDeviceDrop(function->device);
delete function;
}
GPU_API VkCudaFunctionNV GPU_CALL gpuCudaFunctionNVGetVkHandle(GPUCudaFunctionNV function)
{
return function != nullptr && !function->destroyRequested ? function->handle : VK_NULL_HANDLE;
}
GPU_API GPUDevice GPU_CALL gpuCudaFunctionNVGetDevice(GPUCudaFunctionNV function)
{
return function != nullptr && !function->destroyRequested ? function->device : nullptr;
}
} // extern "C"
#endif