RavEngine
Loading...
Searching...
No Matches
PxCudaContext.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26
27#ifndef PX_CUDA_CONTEX_H
28#define PX_CUDA_CONTEX_H
29
30#include "foundation/PxPreprocessor.h"
31
32#if PX_SUPPORT_GPU_PHYSX
33
34#include "PxCudaTypes.h"
35
36#if !PX_DOXYGEN
37namespace physx
38{
39#endif
40 struct PxCudaKernelParam
41 {
42 void* data;
43 size_t size;
44 };
45
46 // workaround for not being able to forward declare enums in PxCudaTypes.h.
47 // provides different automatic casting depending on whether cuda.h was included beforehand or not.
48 template<typename CUenum>
49 struct PxCUenum
50 {
51 PxU32 value;
52
53 PxCUenum(CUenum e) { value = PxU32(e); }
54 operator CUenum() const { return CUenum(value); }
55 };
56
57#ifdef CUDA_VERSION
58 typedef PxCUenum<CUjit_option> PxCUjit_option;
59 typedef PxCUenum<CUresult> PxCUresult;
60#else
61 typedef PxCUenum<PxU32> PxCUjit_option;
62 typedef PxCUenum<PxU32> PxCUresult;
63#endif
64
65#define PX_CUDA_KERNEL_PARAM(X) { (void*)&X, sizeof(X) }
66#define PX_CUDA_KERNEL_PARAM2(X) (void*)&X
67
68 class PxDeviceAllocatorCallback;
72 class PxCudaContext
73 {
74 protected:
75 virtual ~PxCudaContext() {}
76
77 PxDeviceAllocatorCallback* mAllocatorCallback;
78
79 public:
80 virtual void release() = 0;
81
82 virtual PxCUresult memAlloc(CUdeviceptr *dptr, size_t bytesize) = 0;
83
84 virtual PxCUresult memFree(CUdeviceptr dptr) = 0;
85
86 virtual PxCUresult memHostAlloc(void **pp, size_t bytesize, unsigned int Flags) = 0;
87
88 virtual PxCUresult memFreeHost(void *p) = 0;
89
90 virtual PxCUresult memHostGetDevicePointer(CUdeviceptr *pdptr, void *p, unsigned int Flags) = 0;
91
92 virtual PxCUresult moduleLoadDataEx(CUmodule *module, const void *image, unsigned int numOptions, PxCUjit_option *options, void **optionValues) = 0;
93
94 virtual PxCUresult moduleGetFunction(CUfunction *hfunc, CUmodule hmod, const char *name) = 0;
95
96 virtual PxCUresult moduleUnload(CUmodule hmod) = 0;
97
98 virtual PxCUresult streamCreate(CUstream *phStream, unsigned int Flags) = 0;
99
100 virtual PxCUresult streamCreateWithPriority(CUstream *phStream, unsigned int flags, int priority) = 0;
101
102 virtual PxCUresult streamFlush(CUstream hStream) = 0;
103
104 virtual PxCUresult streamWaitEvent(CUstream hStream, CUevent hEvent, unsigned int Flags) = 0;
105
106 virtual PxCUresult streamDestroy(CUstream hStream) = 0;
107
108 virtual PxCUresult streamSynchronize(CUstream hStream) = 0;
109
110 virtual PxCUresult eventCreate(CUevent *phEvent, unsigned int Flags) = 0;
111
112 virtual PxCUresult eventRecord(CUevent hEvent, CUstream hStream) = 0;
113
114 virtual PxCUresult eventQuery(CUevent hEvent) = 0;
115
116 virtual PxCUresult eventSynchronize(CUevent hEvent) = 0;
117
118 virtual PxCUresult eventDestroy(CUevent hEvent) = 0;
119
120 virtual PxCUresult launchKernel(
121 CUfunction f,
122 unsigned int gridDimX,
123 unsigned int gridDimY,
124 unsigned int gridDimZ,
125 unsigned int blockDimX,
126 unsigned int blockDimY,
127 unsigned int blockDimZ,
128 unsigned int sharedMemBytes,
129 CUstream hStream,
130 PxCudaKernelParam* kernelParams,
131 size_t kernelParamsSizeInBytes,
132 void** extra = NULL
133 ) = 0;
134
135 // PT: same as above but without copying the kernel params to a local stack before the launch
136 // i.e. the kernelParams data is passed directly to the kernel.
137 virtual PxCUresult launchKernel(
138 CUfunction f,
139 PxU32 gridDimX, PxU32 gridDimY, PxU32 gridDimZ,
140 PxU32 blockDimX, PxU32 blockDimY, PxU32 blockDimZ,
141 PxU32 sharedMemBytes,
142 CUstream hStream,
143 void** kernelParams,
144 void** extra = NULL
145 ) = 0;
146
147 virtual PxCUresult memcpyDtoH(void *dstHost, CUdeviceptr srcDevice, size_t ByteCount) = 0;
148
149 virtual PxCUresult memcpyDtoHAsync(void *dstHost, CUdeviceptr srcDevice, size_t ByteCount, CUstream hStream) = 0;
150
151 virtual PxCUresult memcpyHtoD(CUdeviceptr dstDevice, const void *srcHost, size_t ByteCount) = 0;
152
153 virtual PxCUresult memcpyHtoDAsync(CUdeviceptr dstDevice, const void *srcHost, size_t ByteCount, CUstream hStream) = 0;
154
155 virtual PxCUresult memcpyDtoDAsync(CUdeviceptr dstDevice, CUdeviceptr srcDevice, size_t ByteCount, CUstream hStream) = 0;
156
157 virtual PxCUresult memcpyDtoD(CUdeviceptr dstDevice, CUdeviceptr srcDevice, size_t ByteCount) = 0;
158
159 virtual PxCUresult memcpyPeerAsync(CUdeviceptr dstDevice, CUcontext dstContext, CUdeviceptr srcDevice, CUcontext srcContext, size_t ByteCount, CUstream hStream) = 0;
160
161 virtual PxCUresult memsetD32Async(CUdeviceptr dstDevice, unsigned int ui, size_t N, CUstream hStream) = 0;
162
163 virtual PxCUresult memsetD8Async(CUdeviceptr dstDevice, unsigned char uc, size_t N, CUstream hStream) = 0;
164
165 virtual PxCUresult memsetD32(CUdeviceptr dstDevice, unsigned int ui, size_t N) = 0;
166
167 virtual PxCUresult memsetD16(CUdeviceptr dstDevice, unsigned short uh, size_t N) = 0;
168
169 virtual PxCUresult memsetD8(CUdeviceptr dstDevice, unsigned char uc, size_t N) = 0;
170
171 virtual PxCUresult getLastError() = 0;
172
173 PxDeviceAllocatorCallback* getAllocatorCallback() { return mAllocatorCallback; }
174 };
175
176#if !PX_DOXYGEN
177} // namespace physx
178#endif
179
180#endif // PX_SUPPORT_GPU_PHYSX
181#endif
182
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39