HDK
|
#include <CE_Grid.h>
Public Member Functions | |
CE_Grid () | |
CE_Grid (const CE_Grid &src) | |
virtual | ~CE_Grid () |
const cl::Buffer & | buffer () const |
bool | hasBuffer () const |
If the current OpenCL buffer is valid. More... | |
void | size (int xres, int yres, int zres, int xghost=1, int yghost=1, int zghost=1, int xpad=1, int ypad=1, int zpad=1) |
int | getXRes () const |
int | getYRes () const |
int | getZRes () const |
int | getRes (int dim) const |
UT_Vector3I | getRes () const |
UT_Vector3I | getGhostRes () const |
int | getGhostRes (int dim) const |
UT_Vector3I | getPadding () const |
int | getPadding (int dim) const |
int | getOffset () const |
int | getGhostOffset () const |
void | setBorder (UT_VoxelBorderType type, fpreal32 t) |
UT_VoxelBorderType | getBorder () const |
fpreal32 | getBorderValue () const |
void | setBorderScale (fpreal32 scalex, fpreal32 scaley, fpreal32 scalez) |
fpreal32 | getBorderScale (int axis) const |
bool | indexToPos (int x, int y, int z, UT_Vector3F &pos) const |
void | updateBorderCells () const |
int64 | numVoxels () const |
Returns the number of data voxels in the grid. More... | |
int64 | numTotalVoxels () const |
int64 | totalVoxelMemory () const |
void | initFromVoxels (const UT_VoxelArrayF &src, int xghost=1, int yghost=1, int zghost=1, int xpad=1, int ypad=1, int zpad=1) |
void | matchAndCopyToVoxels (UT_VoxelArrayF &dest, bool includeGhostCells=false) const |
void | match (const CE_Grid &src) |
Match the src CE_Grid in terms of size and border conditions. More... | |
bool | isMatching (const CE_Grid &src) const |
bool | isCongruent (const CE_Grid &src) const |
Returns true if this CE_Grid matches src in terms of offset and strides. More... | |
int | getXStride () const |
int | getYStride () const |
int | getZStride () const |
int | getStride (int dim) const |
UT_Vector3I | getStrides () const |
int | getGhostStride (int axis) const |
Returns the stride along axis including ghost cells. More... | |
bool | isAxis2D (int axis) const |
Returns whether the specified axis is 2-dimensional. More... | |
int | getAxis2D () const |
Returns the 2-dimensional axis of this grid, or -1 if there is none. More... | |
int | getXStride2D (int axis2d) const |
2D strides. More... | |
int | getYStride2D (int axis2d) const |
int | getXStride2D3D () const |
int | getYStride2D3D () const |
int | getZStride2D3D () const |
Returns the true Z-stride if the grid is 3D, or 0 if 2D. More... | |
int | getXRes2D3D () const |
int | getYRes2D3D () const |
int | getZRes2D3D () const |
Returns the true z resolution if the grid is 3D, or 1 if 2D. More... | |
void | constant (fpreal32 v) |
void | zero () |
bool | isConstant (fpreal32 *cval=0, bool checkBorders=false) const |
void | copyData (const CE_Grid &src) |
CE_Grid & | operator= (const CE_Grid &src) |
Assign to this, equivalent to match(src), followed by copyData(src). More... | |
void | stealBuffer (CE_Grid &src) |
Steal the buffer from the other grid, leaving it unitialized. More... | |
CE_Grid & | operator+= (const CE_Grid &src) |
cl::NDRange | getGlobalRange () const |
cl::NDRange | getGlobalRange2D (int axis2d) const |
cl::NDRange | getGlobalRange2D3D () const |
cl::NDRange | getLocalRange2D3D () const |
cl::KernelFunctor | bind (cl::Kernel k, const cl::NDRange *lrange=nullptr, int n=1) const |
cl::KernelFunctor | bind (cl::Program prog, const char *kernelname) const |
cl::KernelFunctor | bind2D (int axis, cl::Kernel k) const |
cl::KernelFunctor | bind2D (int axis, cl::Program prog, const char *kernelname) const |
cl::KernelFunctor | bind2D3D (cl::Kernel k) const |
cl::KernelFunctor | bind2D3D (cl::Program prog, const char *kernelname) const |
void | scaledAddCornerFromCenter (fpreal32 c1, const CE_Grid &g1) |
void | linearCombination (fpreal32 c0, const CE_Grid &g0, fpreal32 d) |
void | linearCombination (fpreal32 c0, const CE_Grid &g0, fpreal32 c1, const CE_Grid &g1, fpreal32 d) |
void | linearCombination (fpreal32 c0, const CE_Grid &g0, fpreal32 c1, const CE_Grid &g1, fpreal32 c2, const CE_Grid &g2, fpreal32 d) |
void | divergence (const CE_Grid &x, const CE_Grid &y, const CE_Grid &z, fpreal32 scale, UT_Vector3 voxelSize) |
void | divergenceCenterToCorner (const CE_Grid &x, const CE_Grid &y, const CE_Grid &z, fpreal32 scale, UT_Vector3 voxelSize) |
void | applyGradient (const CE_Grid &p, fpreal32 scale, fpreal32 voxelSize, int axis) |
void | applyGradientCornerToCenter (const CE_Grid &p, fpreal32 scale, fpreal32 voxelsize, int axis) |
fpreal64 | sum () const |
Reductions of the grid to a single value. More... | |
fpreal64 | sumAbs () const |
fpreal64 | sumSqr () const |
fpreal64 | min () const |
fpreal64 | minAbs () const |
fpreal64 | max () const |
fpreal64 | maxAbs () const |
fpreal64 | average () const |
fpreal64 | localAverage (UT_Vector3I &radius) |
fpreal64 | localSum (UT_Vector3I &radius) |
fpreal64 | localSumSqr (UT_Vector3I &radius) |
fpreal64 | localSumAbs (UT_Vector3I &radius) |
fpreal64 | localMin (UT_Vector3I &radius) |
fpreal64 | localMinAbs (UT_Vector3I &radius) |
fpreal64 | localMax (UT_Vector3I &radius) |
fpreal64 | localMaxAbs (UT_Vector3I &radius) |
void | boxBlur (int passes, UT_Vector3 radius) |
void | computeNorms (fpreal64 &norminf, fpreal64 &norm2) const |
Compute the infinity-norm and 2-norm of the grid. More... | |
Static Public Member Functions | |
static int | getXAxis2D (int axis2d) |
static int | getYAxis2D (int axis2d) |
static cl::NDRange | getLocalRange (const cl::NDRange &g) |
Create a local work item range for the supplied global range. More... | |
Protected Member Functions | |
const cl::Buffer & | allocBuffer () const |
void | releaseBuffer () |
void | setValue (fpreal32 cval) const |
void | getReductionRanges (const cl::Kernel &k, cl::NDRange &globalRange, cl::NDRange &localRange, uint &groupsize, uint &ngroups, size_t &accumsize) const |
fpreal64 | reduceFlat (cl::Buffer outgrid, uint groupsize, uint ngroups, size_t accumsize, const char *reduceFlags) const |
fpreal64 | doReduce (const char *reduceFlags) const |
bool | doLocalReduce (const char *options, UT_Vector3I &radius) |
This class represents a 3-dimensional array of float values stored on an OpenCL device. It is roughly analagous to UT_VoxelArray, although it does not support tiling. There are various convenience functions for simplifying invocations of OpenCL kernels that operate on grids of values.
CE_Grid supports an arbitrary number of "ghost" cells, which are cells at the boundary edges of the grid that can be set according to different UT_VoxelBorderType values, as well as arbitrary number of "padding" cells. The padding cells can be used to ensure that several grids with slightly different resolutions can nonetheless have indentical x, y, and z stride values. This makes writing kernels that operate on grids that represent face-sampled (MAC) vector array much simpler, since the index into the different grids need only be calculated once.
Invoking an OpenCL kernel typically involves one of the bind() functions to bind the kernel to the range of work items in the grid, assuming one OpenCL work item per voxel. There are three different variants of bind(), the default assumes the grid is always 3-dimensional; bind2D() which assumes the grid has a 2-dimensional axis, and bind2D3D(), which will treat a 3-dimensional grid normally, but flatten a 2-d grid for optimal performance on OpenCL devices that prefer a large number of work items in the first dimension. This last function is the preferred method to call if the grid might represent 2D or 3D data.
A simple OpenCL kernel that doubles every value in a CE_Grid might look like:
Because this kernel takes x, y, and z strides, it can be used for 2D and 3D data: in the 2D case zstride will always be 0. Invoking this kernel then typically looks like:
CE_Grid::CE_Grid | ( | ) |
CE_Grid::CE_Grid | ( | const CE_Grid & | src | ) |
|
virtual |
|
protected |
Add scale * gradient of the supplied field along the supplied axis and voxelsize.
void CE_Grid::applyGradientCornerToCenter | ( | const CE_Grid & | p, |
fpreal32 | scale, | ||
fpreal32 | voxelsize, | ||
int | axis | ||
) |
Add scale * gradient of the supplied field along the supplied axis and voxelsize. Assumes this grid is center-sampled, and p is sampled at its corners.
cl::KernelFunctor CE_Grid::bind | ( | cl::Kernel | k, |
const cl::NDRange * | lrange = nullptr , |
||
int | n = 1 |
||
) | const |
Bind a 3D kernel, with one work item per voxel. If a local range is provided, the global range will be padded to ensure compliance; in this case, the kernel must manually perform bound checks! lrange can point at an array, in which case n specifies its size.
cl::KernelFunctor CE_Grid::bind | ( | cl::Program | prog, |
const char * | kernelname | ||
) | const |
cl::KernelFunctor CE_Grid::bind2D | ( | int | axis, |
cl::Kernel | k | ||
) | const |
Bind a 2D kernel, treating the provided axis as the flat one, with one work item per voxel. This also allows calling 2d kernels along slices of a 3D grid.
cl::KernelFunctor CE_Grid::bind2D | ( | int | axis, |
cl::Program | prog, | ||
const char * | kernelname | ||
) | const |
cl::KernelFunctor CE_Grid::bind2D3D | ( | cl::Kernel | k | ) | const |
Bind a 2D-3D kernel, which should take x-, y-, and z-strides as as parameters, automatically flattening a 2D grid if necessary.
cl::KernelFunctor CE_Grid::bind2D3D | ( | cl::Program | prog, |
const char * | kernelname | ||
) | const |
void CE_Grid::boxBlur | ( | int | passes, |
UT_Vector3 | radius | ||
) |
|
inline |
Compute the infinity-norm and 2-norm of the grid.
Set this grid to the specified constant value. This will release the underlying OpenCL buffer and store the constant value in the CE_Grid object.
Copy data from the source grid. This requires that the grids have the same data resolution, but ghost cells, padding, borders, etc. can differ.
void CE_Grid::divergence | ( | const CE_Grid & | x, |
const CE_Grid & | y, | ||
const CE_Grid & | z, | ||
fpreal32 | scale, | ||
UT_Vector3 | voxelSize | ||
) |
Compute scale * divergence of the vector field represented by the supplied grids and voxelsize.
void CE_Grid::divergenceCenterToCorner | ( | const CE_Grid & | x, |
const CE_Grid & | y, | ||
const CE_Grid & | z, | ||
fpreal32 | scale, | ||
UT_Vector3 | voxelSize | ||
) |
Compute scale * divergence of the vector field represented by the supplied grids and voxelsize; divergence is calculated at corners of the center-sampled vector field.
|
protected |
|
protected |
|
inline |
|
inline |
int CE_Grid::getGhostOffset | ( | ) | const |
Returns the offset from the beginning of the buffer to the beginning of the data including ghost cells.
|
inline |
|
inline |
|
inline |
|
inline |
|
static |
Create a local work item range for the supplied global range.
|
inline |
|
inline |
|
inline |
|
protected |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
bool CE_Grid::indexToPos | ( | int | x, |
int | y, | ||
int | z, | ||
UT_Vector3F & | pos | ||
) | const |
Converts the given voxel coordinates to the normalized [0..1]^3 space, similar to the function of the same name on UT_VoxelArray.
void CE_Grid::initFromVoxels | ( | const UT_VoxelArrayF & | src, |
int | xghost = 1 , |
||
int | yghost = 1 , |
||
int | zghost = 1 , |
||
int | xpad = 1 , |
||
int | ypad = 1 , |
||
int | zpad = 1 |
||
) |
Initialize the CE_Grid from the supplied UT_VoxelArray. Note that in the case that UT_VoxelArray::isConstant(), this will be very fast and avoid allocating any actual GPU memory.
|
inline |
bool CE_Grid::isCongruent | ( | const CE_Grid & | src | ) | const |
Returns true if this CE_Grid matches src in terms of offset and strides.
bool CE_Grid::isConstant | ( | fpreal32 * | cval = 0 , |
bool | checkBorders = false |
||
) | const |
Returns whether the grid is set to a constant value. If checkBorders is true, checks that the border type and value are equal as well.
bool CE_Grid::isMatching | ( | const CE_Grid & | src | ) | const |
Returns true if this CE_Grid matches src in terms of size and border conditions.
Enqueue kernel that stores the linear combination c0 * g0 + d. Requires isCongruent(g0).
void CE_Grid::linearCombination | ( | fpreal32 | c0, |
const CE_Grid & | g0, | ||
fpreal32 | c1, | ||
const CE_Grid & | g1, | ||
fpreal32 | d | ||
) |
Enqueue kernel that stores the linear combination c0 * g0 + c1 * g1 + d. Requires isCongruent(g0) && isCongruent(g1).
void CE_Grid::linearCombination | ( | fpreal32 | c0, |
const CE_Grid & | g0, | ||
fpreal32 | c1, | ||
const CE_Grid & | g1, | ||
fpreal32 | c2, | ||
const CE_Grid & | g2, | ||
fpreal32 | d | ||
) |
Enqueue kernel that stores the linear combination c0 * g0 + c1 * g1 + c2 * g2 + d Requires isCongruent(g0) && isCongruent(g1) && isCongruent(g2)
fpreal64 CE_Grid::localAverage | ( | UT_Vector3I & | radius | ) |
fpreal64 CE_Grid::localMax | ( | UT_Vector3I & | radius | ) |
fpreal64 CE_Grid::localMaxAbs | ( | UT_Vector3I & | radius | ) |
fpreal64 CE_Grid::localMin | ( | UT_Vector3I & | radius | ) |
fpreal64 CE_Grid::localMinAbs | ( | UT_Vector3I & | radius | ) |
fpreal64 CE_Grid::localSum | ( | UT_Vector3I & | radius | ) |
fpreal64 CE_Grid::localSumAbs | ( | UT_Vector3I & | radius | ) |
fpreal64 CE_Grid::localSumSqr | ( | UT_Vector3I & | radius | ) |
Match the src CE_Grid in terms of size and border conditions.
void CE_Grid::matchAndCopyToVoxels | ( | UT_VoxelArrayF & | dest, |
bool | includeGhostCells = false |
||
) | const |
Match destination UT_VoxelArray to this CE_Grid and copy data. Note if isConstant() is true, this is very fast. includeGhostCells can be set to include the ghost cell values in the sizing and copy operations.
fpreal64 CE_Grid::max | ( | ) | const |
fpreal64 CE_Grid::maxAbs | ( | ) | const |
fpreal64 CE_Grid::min | ( | ) | const |
fpreal64 CE_Grid::minAbs | ( | ) | const |
|
inline |
|
inline |
Add the source array values to this. Calls linearCombination() and requires isCongruent(src).
Assign to this, equivalent to match(src), followed by copyData(src).
|
protected |
|
protected |
Enqueue kernel that stores the linear combination g0 + c1 * g1 where this is g0. g1 is assumed to be center-sampled, and g0 is corner-sampled around g1. Thus, g1 is 8-way (4-way for 2D) averaged before the operation. Requires this grid to have one more voxel per live dimension.
void CE_Grid::setBorder | ( | UT_VoxelBorderType | type, |
fpreal32 | t | ||
) |
Like the identically-named function in UT_VoxelArray, set the values that determine grid border behaviour. Note that calling these functions does not actually set the ghost cell values; updateBorderCells() does that.
void CE_Grid::size | ( | int | xres, |
int | yres, | ||
int | zres, | ||
int | xghost = 1 , |
||
int | yghost = 1 , |
||
int | zghost = 1 , |
||
int | xpad = 1 , |
||
int | ypad = 1 , |
||
int | zpad = 1 |
||
) |
Size the grid as specified. Note this does not actually allocate memory on the OpenCL device.
Steal the buffer from the other grid, leaving it unitialized.
fpreal64 CE_Grid::sum | ( | ) | const |
Reductions of the grid to a single value.
fpreal64 CE_Grid::sumAbs | ( | ) | const |
fpreal64 CE_Grid::sumSqr | ( | ) | const |
|
inline |
void CE_Grid::updateBorderCells | ( | ) | const |
Invoke a series of kernels to fill the ghost cells along each axis with the proper values according to the border value and type.
|
protected |
|
protected |
|
mutableprotected |
|
protected |
|
protected |
|
protected |
|
protected |