HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_CEAttribute Class Reference

#include <GA_CEAttribute.h>

+ Inheritance diagram for GA_CEAttribute:

Public Member Functions

 GA_CEAttribute ()
 
 GA_CEAttribute (GA_Size entries, GA_StorageClass storage, GA_Precision precision, GA_Size tuplesize, bool isarray, cl::Buffer buffer, cl::Buffer indexbuffer, bool leave_on_gpu=false)
 Create an attribute from existing buffers. More...
 
 GA_CEAttribute (GA_Size entries, GA_StorageClass storage, GA_Precision precision, GA_Size tuplesize, bool isarray)
 Construct unallocated array of this size and type. More...
 
 GA_CEAttribute (const GA_CEAttribute &other)
 
 GA_CEAttribute (GA_CEAttribute &&other) noexcept
 
virtual ~GA_CEAttribute () override
 
EntryType poolTypeID () const override
 
void copy (const GA_CEAttribute &other)
 
GA_CEAttributeoperator= (const GA_CEAttribute &other)
 
void swap (GA_CEAttribute &other)
 
GA_CEAttributeoperator= (GA_CEAttribute &&other)
 
bool saveJSON (UT_JSONWriter &w) const
 Returns true for successful save. More...
 
bool rawData (UT_WorkBuffer &data) const
 
bool setRawData (const char *data, exint length)
 
void clearBuffers ()
 
bool isValid () const
 
bool isOnGPU () const
 
bool isOnCPU () const
 
void copyToCPU ()
 Ensures the CPU version of the attribute is valid. More...
 
int64 getDeviceMemoryUsage () const
 
int64 getMemoryUsage (bool inclusive=false) const
 
GA_Size entries () const
 
int tupleSize () const
 
GA_StorageClass storage () const
 
GA_Precision precision () const
 
bool isArray () const
 
bool attributeToOCL (const GA_Detail *gdp, GA_AttributeOwner owner, const char *aname, GA_StorageClass storage, int &tuplesize, bool isarray, bool docopy=true)
 
bool attributeToOCL (const GA_Detail *gdp, GA_AttributeOwner owner, const char *aname, GA_StorageClass storage, GA_Precision precision, int &tuplesize, bool isarray, bool docopy=true)
 
bool attributeToOCL (const GA_Attribute *attrib, GA_StorageClass storage, GA_Precision precision, int &tuplesize, bool isarray, bool docopy=true)
 
bool intToOCL (const UT_Array< int64 > &data, GA_StorageClass storage, GA_Precision precision, bool docopy=true)
 
bool intArrayToOCL (const UT_Array< UT_Array< int64 >> &data, GA_StorageClass storage, GA_Precision precision, bool docopy=true)
 
bool packedIntArrayToOCL (const UT_PackedArrayOfArrays< int64 > &data, GA_StorageClass storage, GA_Precision precision, bool docopy=true)
 
bool oclToAttribute (GA_Detail *gdp, GA_AttributeOwner owner, const char *aname)
 
bool oclToAttribute (GA_Attribute *attrib)
 
bool isWriteBackRequired () const
 
void setWriteBackRequired (bool isrequired)
 
- Public Member Functions inherited from CE_HotSwapPoolEntry
 CE_HotSwapPoolEntry ()
 Creates a new buffer. You must call setSize to make this buffer usable. More...
 
virtual ~CE_HotSwapPoolEntry ()
 
 CE_HotSwapPoolEntry (const CE_HotSwapPoolEntry &)=delete
 
CE_HotSwapPoolEntryoperator= (const CE_HotSwapPoolEntry &)=delete
 
bool isInUseGPU () const
 
void setInUseGPUFlag () const
 
void clearInUseGPUFlag () const
 

Static Public Member Functions

static GA_CEAttributeUPtr loadJSON (UT_JSONParser &p)
 
static GA_CEAttributeAccessorPtr makeAccessor (GA_CEAttributePtr attrib, bool read, bool write)
 
static GA_CEAttributeAccessorPtr makeAccessorR (GA_CEAttributeConstPtr attrib)
 
static GA_CEAttributeAccessorPtr makeAccessorRW (GA_CEAttributePtr attrib)
 
static GA_CEAttributeAccessorPtr makeAccessorW (GA_CEAttributePtr attrib)
 

Protected Member Functions

cl::Buffer bufferW ()
 
cl::Buffer bufferRW ()
 
cl::Buffer bufferR () const
 
cl::Buffer buffer (bool read, bool write)
 
cl::Buffer indexBufferR () const
 Index buffer is immutable, so no writable variant: More...
 
void poolResetGPUBuffer () override
 
void poolSetOnGPU (bool ongpu) override
 Update OnGPU. More...
 
bool poolIsGPUBufferEmpty () const override
 True if the gpu buffer is null. More...
 
bool poolIsGPUBufferValid () const override
 True if the gpu buffer is not null and valid. More...
 
bool poolSwapGPUBuffer (CE_HotSwapPoolEntry *otherbase) override
 True if the swap does something. More...
 
void poolShallowCopyGPUBuffer (const CE_HotSwapPoolEntry *srcbase) override
 Shallow copy. More...
 
void unloadFromGPU () override
 
template<typename OP >
void dispatchToArray (const OP &op)
 
template<typename OP >
void dispatchToArray (const OP &op) const
 
void loadToGPU (bool docopy)
 

Protected Attributes

UT_SharedPtr< CE_BufferDeviceBytemyBuffer
 
UT_SharedPtr< CE_BufferDeviceBytemyIndexBuffer
 
UT_SharedPtr< UT_Array< cl_int > > myIndexArray
 
UT_SharedPtr< UT_Array
< fpreal16 > > 
myFloat16Array
 
UT_SharedPtr< UT_Array
< cl_float > > 
myFloat32Array
 
UT_SharedPtr< UT_Array
< cl_double > > 
myFloat64Array
 
UT_SharedPtr< UT_Array< cl_char > > myInt8Array
 
UT_SharedPtr< UT_Array
< cl_short > > 
myInt16Array
 
UT_SharedPtr< UT_Array< cl_int > > myInt32Array
 
UT_SharedPtr< UT_Array< cl_long > > myInt64Array
 
GA_Size myEntries = 0
 
GA_Size myDataEntries = 0
 
GA_Size myTupleSize = 0
 
GA_StorageClass myStorage = GA_STORECLASS_INVALID
 
GA_Precision myPrecision = GA_PRECISION_INVALID
 
bool myIsArray = false
 
bool myOnCPU = false
 
bool myOnGPU = false
 
bool myWriteBackRequired = false
 

Friends

class GA_CEAttributeAccessor
 

Additional Inherited Members

- Public Types inherited from CE_HotSwapPoolEntry
enum  EntryType { EntryType::BUFFER = 0, EntryType::VDB, EntryType::ATTRIBUTE }
 To avoid the need for dynamic casts: More...
 

Detailed Description

Definition at line 32 of file GA_CEAttribute.h.

Constructor & Destructor Documentation

GA_CEAttribute::GA_CEAttribute ( )
GA_CEAttribute::GA_CEAttribute ( GA_Size  entries,
GA_StorageClass  storage,
GA_Precision  precision,
GA_Size  tuplesize,
bool  isarray,
cl::Buffer  buffer,
cl::Buffer  indexbuffer,
bool  leave_on_gpu = false 
)

Create an attribute from existing buffers.

GA_CEAttribute::GA_CEAttribute ( GA_Size  entries,
GA_StorageClass  storage,
GA_Precision  precision,
GA_Size  tuplesize,
bool  isarray 
)

Construct unallocated array of this size and type.

GA_CEAttribute::GA_CEAttribute ( const GA_CEAttribute other)
inline

Definition at line 47 of file GA_CEAttribute.h.

GA_CEAttribute::GA_CEAttribute ( GA_CEAttribute &&  other)
inlinenoexcept

Definition at line 48 of file GA_CEAttribute.h.

virtual GA_CEAttribute::~GA_CEAttribute ( )
overridevirtual

Member Function Documentation

bool GA_CEAttribute::attributeToOCL ( const GA_Detail gdp,
GA_AttributeOwner  owner,
const char *  aname,
GA_StorageClass  storage,
int tuplesize,
bool  isarray,
bool  docopy = true 
)
inline

attributeToOCL populates our own data from the attribute. It will be loaded onto the GPU. If it fails, returns false.

Definition at line 111 of file GA_CEAttribute.h.

bool GA_CEAttribute::attributeToOCL ( const GA_Detail gdp,
GA_AttributeOwner  owner,
const char *  aname,
GA_StorageClass  storage,
GA_Precision  precision,
int tuplesize,
bool  isarray,
bool  docopy = true 
)
inline

Definition at line 122 of file GA_CEAttribute.h.

bool GA_CEAttribute::attributeToOCL ( const GA_Attribute attrib,
GA_StorageClass  storage,
GA_Precision  precision,
int tuplesize,
bool  isarray,
bool  docopy = true 
)
cl::Buffer GA_CEAttribute::buffer ( bool  read,
bool  write 
)
protected
cl::Buffer GA_CEAttribute::bufferR ( ) const
inlineprotected

Definition at line 199 of file GA_CEAttribute.h.

cl::Buffer GA_CEAttribute::bufferRW ( )
inlineprotected

Definition at line 198 of file GA_CEAttribute.h.

cl::Buffer GA_CEAttribute::bufferW ( )
inlineprotected

bufferRW() will ensure COW is respected and create a new GPU buffer if this was shared. It also resets the OnCPU flag as it is assumed the data will be written to. bufferW() ensures the GPU buffer is unique, but does not copy the data when doing so. bufferR() will return a shared buffer without uniquing. Caution should be taken to ensure you don't get both a read & write buffer, as your read buffer may be then orphaned (If you hold onto the cl::Buffer object it is safe other than out of date data. NOTE: binding to a kernel does NOT preserve the cl::Buffer object)

Definition at line 197 of file GA_CEAttribute.h.

void GA_CEAttribute::clearBuffers ( )
void GA_CEAttribute::copy ( const GA_CEAttribute other)
void GA_CEAttribute::copyToCPU ( )
inline

Ensures the CPU version of the attribute is valid.

Definition at line 83 of file GA_CEAttribute.h.

template<typename OP >
void GA_CEAttribute::dispatchToArray ( const OP &  op)
inlineprotected

Definition at line 252 of file GA_CEAttribute.h.

template<typename OP >
void GA_CEAttribute::dispatchToArray ( const OP &  op) const
inlineprotected

Definition at line 281 of file GA_CEAttribute.h.

GA_Size GA_CEAttribute::entries ( ) const
inline

Definition at line 100 of file GA_CEAttribute.h.

int64 GA_CEAttribute::getDeviceMemoryUsage ( ) const
int64 GA_CEAttribute::getMemoryUsage ( bool  inclusive = false) const
cl::Buffer GA_CEAttribute::indexBufferR ( ) const
inlineprotected

Index buffer is immutable, so no writable variant:

Definition at line 203 of file GA_CEAttribute.h.

bool GA_CEAttribute::intArrayToOCL ( const UT_Array< UT_Array< int64 >> &  data,
GA_StorageClass  storage,
GA_Precision  precision,
bool  docopy = true 
)
bool GA_CEAttribute::intToOCL ( const UT_Array< int64 > &  data,
GA_StorageClass  storage,
GA_Precision  precision,
bool  docopy = true 
)

The int*ToOCL copy integer data into our own data. It will beloaded onto the GPU. If it fails, returns false.

bool GA_CEAttribute::isArray ( ) const
inline

Definition at line 104 of file GA_CEAttribute.h.

bool GA_CEAttribute::isOnCPU ( ) const
inline

Definition at line 79 of file GA_CEAttribute.h.

bool GA_CEAttribute::isOnGPU ( ) const
inline

Definition at line 77 of file GA_CEAttribute.h.

bool GA_CEAttribute::isValid ( ) const
inline

Definition at line 71 of file GA_CEAttribute.h.

bool GA_CEAttribute::isWriteBackRequired ( ) const
inline

Definition at line 183 of file GA_CEAttribute.h.

static GA_CEAttributeUPtr GA_CEAttribute::loadJSON ( UT_JSONParser p)
static

Returns a newly created VDB loaded from the stream, or null if load failure.

void GA_CEAttribute::loadToGPU ( bool  docopy)
protected

Transfers this CPU data onto the GPU. Will set myOnGPu true on success, if docopy is false we only allocate the gpu buffer.

static GA_CEAttributeAccessorPtr GA_CEAttribute::makeAccessor ( GA_CEAttributePtr  attrib,
bool  read,
bool  write 
)
static

Acquire accessors to the GPU data. Extend the liftetime of these until any kernels they are bound to are dispatched. These handle pinning the GPU buffer from eviction from the hot swap pool, and also extending the cl::Buffer lifetime. You must test to see if these are null. If they are non-null, they will be isValid().

static GA_CEAttributeAccessorPtr GA_CEAttribute::makeAccessorR ( GA_CEAttributeConstPtr  attrib)
inlinestatic

Definition at line 96 of file GA_CEAttribute.h.

static GA_CEAttributeAccessorPtr GA_CEAttribute::makeAccessorRW ( GA_CEAttributePtr  attrib)
inlinestatic

Definition at line 97 of file GA_CEAttribute.h.

static GA_CEAttributeAccessorPtr GA_CEAttribute::makeAccessorW ( GA_CEAttributePtr  attrib)
inlinestatic

Definition at line 98 of file GA_CEAttribute.h.

bool GA_CEAttribute::oclToAttribute ( GA_Detail gdp,
GA_AttributeOwner  owner,
const char *  aname 
)
inline

oclToAttribute writes back our data to the specified attribute. If it is not compatible, returns false.

Definition at line 171 of file GA_CEAttribute.h.

bool GA_CEAttribute::oclToAttribute ( GA_Attribute attrib)
GA_CEAttribute& GA_CEAttribute::operator= ( const GA_CEAttribute other)
inline

Definition at line 55 of file GA_CEAttribute.h.

GA_CEAttribute& GA_CEAttribute::operator= ( GA_CEAttribute &&  other)
inline

Definition at line 58 of file GA_CEAttribute.h.

bool GA_CEAttribute::packedIntArrayToOCL ( const UT_PackedArrayOfArrays< int64 > &  data,
GA_StorageClass  storage,
GA_Precision  precision,
bool  docopy = true 
)
bool GA_CEAttribute::poolIsGPUBufferEmpty ( ) const
inlineoverrideprotectedvirtual

True if the gpu buffer is null.

Implements CE_HotSwapPoolEntry.

Definition at line 217 of file GA_CEAttribute.h.

bool GA_CEAttribute::poolIsGPUBufferValid ( ) const
inlineoverrideprotectedvirtual

True if the gpu buffer is not null and valid.

Implements CE_HotSwapPoolEntry.

Definition at line 222 of file GA_CEAttribute.h.

void GA_CEAttribute::poolResetGPUBuffer ( )
inlineoverrideprotectedvirtual

These implement methods required by the pool. Resets the GPU Buffer pointer.

Implements CE_HotSwapPoolEntry.

Definition at line 207 of file GA_CEAttribute.h.

void GA_CEAttribute::poolSetOnGPU ( bool  ongpu)
inlineoverrideprotectedvirtual

Update OnGPU.

Implements CE_HotSwapPoolEntry.

Definition at line 212 of file GA_CEAttribute.h.

void GA_CEAttribute::poolShallowCopyGPUBuffer ( const CE_HotSwapPoolEntry srcbase)
inlineoverrideprotectedvirtual

Shallow copy.

Implements CE_HotSwapPoolEntry.

Definition at line 238 of file GA_CEAttribute.h.

bool GA_CEAttribute::poolSwapGPUBuffer ( CE_HotSwapPoolEntry otherbase)
inlineoverrideprotectedvirtual

True if the swap does something.

Implements CE_HotSwapPoolEntry.

Definition at line 227 of file GA_CEAttribute.h.

EntryType GA_CEAttribute::poolTypeID ( ) const
inlineoverridevirtual

Implements CE_HotSwapPoolEntry.

Definition at line 52 of file GA_CEAttribute.h.

GA_Precision GA_CEAttribute::precision ( ) const
inline

Definition at line 103 of file GA_CEAttribute.h.

bool GA_CEAttribute::rawData ( UT_WorkBuffer data) const
bool GA_CEAttribute::saveJSON ( UT_JSONWriter w) const

Returns true for successful save.

bool GA_CEAttribute::setRawData ( const char *  data,
exint  length 
)
void GA_CEAttribute::setWriteBackRequired ( bool  isrequired)
inline

Definition at line 184 of file GA_CEAttribute.h.

GA_StorageClass GA_CEAttribute::storage ( ) const
inline

Definition at line 102 of file GA_CEAttribute.h.

void GA_CEAttribute::swap ( GA_CEAttribute other)
int GA_CEAttribute::tupleSize ( ) const
inline

Definition at line 101 of file GA_CEAttribute.h.

void GA_CEAttribute::unloadFromGPU ( )
overrideprotectedvirtual

Queues up commands that transfer this buffer's GPU storage to main memory.

Implements CE_HotSwapPoolEntry.

Friends And Related Function Documentation

Definition at line 366 of file GA_CEAttribute.h.

Member Data Documentation

UT_SharedPtr<CE_BufferDeviceByte> GA_CEAttribute::myBuffer
protected

All changes to this member (the shared pointer) must be done by the memory pool!!!

Definition at line 317 of file GA_CEAttribute.h.

GA_Size GA_CEAttribute::myDataEntries = 0
protected

Definition at line 338 of file GA_CEAttribute.h.

GA_Size GA_CEAttribute::myEntries = 0
protected

Definition at line 337 of file GA_CEAttribute.h.

UT_SharedPtr<UT_Array<fpreal16> > GA_CEAttribute::myFloat16Array
protected

Definition at line 328 of file GA_CEAttribute.h.

UT_SharedPtr<UT_Array<cl_float> > GA_CEAttribute::myFloat32Array
protected

Definition at line 329 of file GA_CEAttribute.h.

UT_SharedPtr<UT_Array<cl_double> > GA_CEAttribute::myFloat64Array
protected

Definition at line 330 of file GA_CEAttribute.h.

UT_SharedPtr<UT_Array<cl_int> > GA_CEAttribute::myIndexArray
protected

Definition at line 324 of file GA_CEAttribute.h.

UT_SharedPtr<CE_BufferDeviceByte> GA_CEAttribute::myIndexBuffer
protected

Definition at line 319 of file GA_CEAttribute.h.

UT_SharedPtr<UT_Array<cl_short> > GA_CEAttribute::myInt16Array
protected

Definition at line 332 of file GA_CEAttribute.h.

UT_SharedPtr<UT_Array<cl_int> > GA_CEAttribute::myInt32Array
protected

Definition at line 333 of file GA_CEAttribute.h.

UT_SharedPtr<UT_Array<cl_long> > GA_CEAttribute::myInt64Array
protected

Definition at line 334 of file GA_CEAttribute.h.

UT_SharedPtr<UT_Array<cl_char> > GA_CEAttribute::myInt8Array
protected

Definition at line 331 of file GA_CEAttribute.h.

bool GA_CEAttribute::myIsArray = false
protected

Definition at line 342 of file GA_CEAttribute.h.

bool GA_CEAttribute::myOnCPU = false
protected

This pair stores whether correct data is on the CPU or GPU buffers or both.

Definition at line 359 of file GA_CEAttribute.h.

bool GA_CEAttribute::myOnGPU = false
protected

Definition at line 360 of file GA_CEAttribute.h.

GA_Precision GA_CEAttribute::myPrecision = GA_PRECISION_INVALID
protected

Definition at line 341 of file GA_CEAttribute.h.

GA_StorageClass GA_CEAttribute::myStorage = GA_STORECLASS_INVALID
protected

Definition at line 340 of file GA_CEAttribute.h.

GA_Size GA_CEAttribute::myTupleSize = 0
protected

Definition at line 339 of file GA_CEAttribute.h.

bool GA_CEAttribute::myWriteBackRequired = false
protected

Whether the buffer has been written to by CE. This implies GA_Attribute is out of date.

Definition at line 364 of file GA_CEAttribute.h.


The documentation for this class was generated from the following file: