opensubdiv/osd/cudaEvaluator.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List

cudaEvaluator.h
Go to the documentation of this file.
1 //
2 // Copyright 2015 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24
25 #ifndef OPENSUBDIV3_OSD_CUDA_EVALUATOR_H
26 #define OPENSUBDIV3_OSD_CUDA_EVALUATOR_H
27
28 #include "../version.h"
29
30 #include <vector>
31 #include "../osd/bufferDescriptor.h"
32 #include "../osd/types.h"
33
34 namespace OpenSubdiv {
35 namespace OPENSUBDIV_VERSION {
36
37 namespace Far {
38 class PatchTable;
39 class StencilTable;
40 class LimitStencilTable;
41 }
42
43 namespace Osd {
44
52 class CudaStencilTable {
53 public:
54 static CudaStencilTable *Create(Far::StencilTable const *stencilTable,
55 void *deviceContext = NULL) {
56 (void)deviceContext; // unused
57 return new CudaStencilTable(stencilTable);
58 }
59 static CudaStencilTable *Create(Far::LimitStencilTable const *limitStencilTable,
60 void *deviceContext = NULL) {
61 (void)deviceContext; // unused
62 return new CudaStencilTable(limitStencilTable);
63 }
64
65 explicit CudaStencilTable(Far::StencilTable const *stencilTable);
66 explicit CudaStencilTable(Far::LimitStencilTable const *limitStencilTable);
67 ~CudaStencilTable();
68
69 // interfaces needed for CudaCompute
70 void *GetSizesBuffer() const { return _sizes; }
71 void *GetOffsetsBuffer() const { return _offsets; }
72 void *GetIndicesBuffer() const { return _indices; }
73 void *GetWeightsBuffer() const { return _weights; }
74 void *GetDuWeightsBuffer() const { return _duWeights; }
75 void *GetDvWeightsBuffer() const { return _dvWeights; }
76 int GetNumStencils() const { return _numStencils; }
77
78 private:
79 void * _sizes,
80 * _offsets,
81 * _indices,
82 * _weights,
83 * _duWeights,
84 * _dvWeights;
85 int _numStencils;
86 };
87
88 class CudaEvaluator {
89 public:
95
119 template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
120 static bool EvalStencils(
121 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
122 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
123 STENCIL_TABLE const *stencilTable,
124 const void *instance = NULL,
125 void * deviceContext = NULL) {
126
127 (void)instance; // unused
128 (void)deviceContext; // unused
129 return EvalStencils(srcBuffer->BindCudaBuffer(), srcDesc,
130 dstBuffer->BindCudaBuffer(), dstDesc,
131 (int const *)stencilTable->GetSizesBuffer(),
132 (int const *)stencilTable->GetOffsetsBuffer(),
133 (int const *)stencilTable->GetIndicesBuffer(),
134 (float const *)stencilTable->GetWeightsBuffer(),
135 /*start = */ 0,
136 /*end = */ stencilTable->GetNumStencils());
137 }
138
165 static bool EvalStencils(
166 const float *src, BufferDescriptor const &srcDesc,
167 float *dst, BufferDescriptor const &dstDesc,
168 const int * sizes,
169 const int * offsets,
170 const int * indices,
171 const float * weights,
172 int start, int end);
173
211 template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
212 static bool EvalStencils(
213 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
214 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
215 DST_BUFFER *duBuffer, BufferDescriptor const &duDesc,
216 DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc,
217 STENCIL_TABLE const *stencilTable,
218 const CudaEvaluator *instance = NULL,
219 void * deviceContext = NULL) {
220
221 (void)instance; // unused
222 (void)deviceContext; // unused
223
224 return EvalStencils(srcBuffer->BindCudaBuffer(), srcDesc,
225 dstBuffer->BindCudaBuffer(), dstDesc,
226 duBuffer->BindCudaBuffer(), duDesc,
227 dvBuffer->BindCudaBuffer(), dvDesc,
228 (int const *)stencilTable->GetSizesBuffer(),
229 (int const *)stencilTable->GetOffsetsBuffer(),
230 (int const *)stencilTable->GetIndicesBuffer(),
231 (float const *)stencilTable->GetWeightsBuffer(),
232 (float const *)stencilTable->GetDuWeightsBuffer(),
233 (float const *)stencilTable->GetDvWeightsBuffer(),
234 /*start = */ 0,
235 /*end = */ stencilTable->GetNumStencils());
236 }
237
278 static bool EvalStencils(
279 const float *src, BufferDescriptor const &srcDesc,
280 float *dst, BufferDescriptor const &dstDesc,
281 float *du, BufferDescriptor const &duDesc,
282 float *dv, BufferDescriptor const &dvDesc,
283 const int * sizes,
284 const int * offsets,
285 const int * indices,
286 const float * weights,
287 const float * duWeights,
288 const float * dvWeights,
289 int start, int end);
290
296
325 template <typename SRC_BUFFER, typename DST_BUFFER,
326 typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
327 static bool EvalPatches(
328 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
329 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
330 int numPatchCoords,
331 PATCHCOORD_BUFFER *patchCoords,
332 PATCH_TABLE *patchTable,
333 CudaEvaluator const *instance,
334 void * deviceContext = NULL) {
335
336 (void)instance; // unused
337 (void)deviceContext; // unused
338
339 return EvalPatches(srcBuffer->BindCudaBuffer(), srcDesc,
340 dstBuffer->BindCudaBuffer(), dstDesc,
341 numPatchCoords,
342 (const PatchCoord *)patchCoords->BindCudaBuffer(),
343 (const PatchArray *)patchTable->GetPatchArrayBuffer(),
344 (const int *)patchTable->GetPatchIndexBuffer(),
345 (const PatchParam *)patchTable->GetPatchParamBuffer());
346 }
347
386 template <typename SRC_BUFFER, typename DST_BUFFER,
387 typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
388 static bool EvalPatches(
389 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
390 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
391 DST_BUFFER *duBuffer, BufferDescriptor const &duDesc,
392 DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc,
393 int numPatchCoords,
394 PATCHCOORD_BUFFER *patchCoords,
395 PATCH_TABLE *patchTable,
396 CudaEvaluator const *instance,
397 void * deviceContext = NULL) {
398
399 (void)instance; // unused
400 (void)deviceContext; // unused
401
402 return EvalPatches(srcBuffer->BindCudaBuffer(), srcDesc,
403 dstBuffer->BindCudaBuffer(), dstDesc,
404 duBuffer->BindCudaBuffer(), duDesc,
405 dvBuffer->BindCudaBuffer(), dvDesc,
406 numPatchCoords,
407 (const PatchCoord *)patchCoords->BindCudaBuffer(),
408 (const PatchArray *)patchTable->GetPatchArrayBuffer(),
409 (const int *)patchTable->GetPatchIndexBuffer(),
410 (const PatchParam *)patchTable->GetPatchParamBuffer());
411 }
412
440 static bool EvalPatches(
441 const float *src, BufferDescriptor const &srcDesc,
442 float *dst, BufferDescriptor const &dstDesc,
443 int numPatchCoords,
444 const PatchCoord *patchCoords,
445 const PatchArray *patchArrays,
446 const int *patchIndices,
447 const PatchParam *patchParams);
448
486 static bool EvalPatches(
487 const float *src, BufferDescriptor const &srcDesc,
488 float *dst, BufferDescriptor const &dstDesc,
489 float *du, BufferDescriptor const &duDesc,
490 float *dv, BufferDescriptor const &dvDesc,
491 int numPatchCoords,
492 const PatchCoord *patchCoords,
493 const PatchArray *patchArrays,
494 const int *patchIndices,
495 const PatchParam *patchParams);
496
502 static void Synchronize(void *deviceContext = NULL);
503 };
504
505
506 } // end namespace Osd
507
508 } // end namespace OPENSUBDIV_VERSION
509 using namespace OPENSUBDIV_VERSION;
510
511 } // end namespace OpenSubdiv
512
513
514 #endif // OPENSUBDIV3_OSD_CUDA_EVALUATOR_H
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::Create
static CudaStencilTable * Create(Far::LimitStencilTable const *limitStencilTable, void *deviceContext=NULL)
Definition: cudaEvaluator.h:59
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::GetDuWeightsBuffer
void * GetDuWeightsBuffer() const
Definition: cudaEvaluator.h:74
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaEvaluator::EvalPatches
static bool EvalPatches(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, int numPatchCoords, PATCHCOORD_BUFFER *patchCoords, PATCH_TABLE *patchTable, CudaEvaluator const *instance, void *deviceContext=NULL)
Generic limit eval function. This function has a same signature as other device kernels have so that ...
Definition: cudaEvaluator.h:327
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor
BufferDescriptor is a struct which describes buffer elements in interleaved data buffers. Almost all Osd Evaluator APIs take BufferDescriptors along with device-specific buffer objects.
Definition: bufferDescriptor.h:61
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::GetDvWeightsBuffer
void * GetDvWeightsBuffer() const
Definition: cudaEvaluator.h:75
OpenSubdiv
Definition: error.h:30
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::GetIndicesBuffer
void * GetIndicesBuffer() const
Definition: cudaEvaluator.h:72
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaEvaluator::Synchronize
static void Synchronize(void *deviceContext=NULL)
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaEvaluator::EvalStencils
static bool EvalStencils(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, STENCIL_TABLE const *stencilTable, const void *instance=NULL, void *deviceContext=NULL)
Generic static compute function. This function has a same signature as other device kernels have so t...
Definition: cudaEvaluator.h:120
OpenSubdiv::OPENSUBDIV_VERSION::Osd::PatchCoord
Coordinates set on a patch table.
Definition: types.h:40
OpenSubdiv::OPENSUBDIV_VERSION::Osd::PatchParam
Definition: types.h:93
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::CudaStencilTable
CudaStencilTable(Far::StencilTable const *stencilTable)
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::GetSizesBuffer
void * GetSizesBuffer() const
Definition: cudaEvaluator.h:70
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaEvaluator
Definition: cudaEvaluator.h:88
OpenSubdiv::OPENSUBDIV_VERSION::Osd::PatchArray
Definition: types.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTable
Table of subdivision stencils.
Definition: stencilTable.h:125
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::Create
static CudaStencilTable * Create(Far::StencilTable const *stencilTable, void *deviceContext=NULL)
Definition: cudaEvaluator.h:54
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable
CUDA stencil table.
Definition: cudaEvaluator.h:52
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaEvaluator::EvalPatches
static bool EvalPatches(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, DST_BUFFER *duBuffer, BufferDescriptor const &duDesc, DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc, int numPatchCoords, PATCHCOORD_BUFFER *patchCoords, PATCH_TABLE *patchTable, CudaEvaluator const *instance, void *deviceContext=NULL)
Generic limit eval function with derivatives. This function has a same signature as other device kern...
Definition: cudaEvaluator.h:388
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::GetOffsetsBuffer
void * GetOffsetsBuffer() const
Definition: cudaEvaluator.h:71
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::GetWeightsBuffer
void * GetWeightsBuffer() const
Definition: cudaEvaluator.h:73
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::GetNumStencils
int GetNumStencils() const
Definition: cudaEvaluator.h:76
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaEvaluator::EvalStencils
static bool EvalStencils(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, DST_BUFFER *duBuffer, BufferDescriptor const &duDesc, DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc, STENCIL_TABLE const *stencilTable, const CudaEvaluator *instance=NULL, void *deviceContext=NULL)
Generic static eval stencils function with derivatives. This function has a same signature as other d...
Definition: cudaEvaluator.h:212
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CudaStencilTable::~CudaStencilTable
~CudaStencilTable()
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTable
Table of limit subdivision stencils.
Definition: stencilTable.h:287