Kompute
|
#include <Tensor.hpp>
Public Types | |
enum class | TensorTypes { eDevice = 0 , eHost = 1 , eStorage = 2 } |
enum class | TensorDataTypes { eBool = 0 , eInt = 1 , eUnsignedInt = 2 , eFloat = 3 , eDouble = 4 } |
Public Member Functions | |
Tensor (std::shared_ptr< vk::PhysicalDevice > physicalDevice, std::shared_ptr< vk::Device > device, void *data, uint32_t elementTotalCount, uint32_t elementMemorySize, const TensorDataTypes &dataType, const TensorTypes &tensorType=TensorTypes::eDevice) | |
virtual | ~Tensor () |
void | rebuild (void *data, uint32_t elementTotalCount, uint32_t elementMemorySize) |
void | destroy () |
bool | isInit () |
TensorTypes | tensorType () |
void | recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Tensor > copyFromTensor) |
void | recordCopyFromStagingToDevice (const vk::CommandBuffer &commandBuffer) |
void | recordCopyFromDeviceToStaging (const vk::CommandBuffer &commandBuffer) |
void | recordPrimaryBufferMemoryBarrier (const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) |
void | recordStagingBufferMemoryBarrier (const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) |
vk::DescriptorBufferInfo | constructDescriptorBufferInfo () |
uint32_t | size () |
uint32_t | dataTypeMemorySize () |
uint32_t | memorySize () |
TensorDataTypes | dataType () |
void * | rawData () |
void | setRawData (const void *data) |
template<typename T > | |
T * | data () |
template<typename T > | |
std::vector< T > | vector () |
Static Public Member Functions | |
static std::string | toString (TensorDataTypes dt) |
static std::string | toString (TensorTypes dt) |
Protected Attributes | |
TensorTypes | mTensorType |
TensorDataTypes | mDataType |
uint32_t | mSize |
uint32_t | mDataTypeMemorySize |
void * | mRawData |
Structured data used in GPU operations.
Tensors are the base building block in Kompute to perform operations across GPUs. Each tensor would have a respective Vulkan memory and buffer, which would be used to store their respective data. The tensors can be used for GPU data storage or transfer.
|
strong |
Type for tensors created: Device allows memory to be transferred from staging buffers. Staging are host memory visible. Storage are device visible but are not set up to transfer or receive data (only for shader storage).
Enumerator | |
---|---|
eDevice | Type is device memory, source and destination. |
eHost | Type is host memory, source and destination. |
eStorage | Type is Device memory (only) |
kp::Tensor::Tensor | ( | std::shared_ptr< vk::PhysicalDevice > | physicalDevice, |
std::shared_ptr< vk::Device > | device, | ||
void * | data, | ||
uint32_t | elementTotalCount, | ||
uint32_t | elementMemorySize, | ||
const TensorDataTypes & | dataType, | ||
const TensorTypes & | tensorType = TensorTypes::eDevice |
||
) |
Constructor with data provided which would be used to create the respective vulkan buffer and memory.
physicalDevice | The physical device to use to fetch properties |
device | The device to use to create the buffer and memory from |
data | Non-zero-sized vector of data that will be used by the tensor |
tensorTypes | Type for the tensor which is of type TensorTypes |
|
virtual |
Destructor which is in charge of freeing vulkan resources unless they have been provided externally.
vk::DescriptorBufferInfo kp::Tensor::constructDescriptorBufferInfo | ( | ) |
Constructs a vulkan descriptor buffer info which can be used to specify and reference the underlying buffer component of the tensor without exposing it.
|
inline |
Template to return the pointer data converted by specific type, which would be any of the supported types including float, double, int32, uint32 and bool.
TensorDataTypes kp::Tensor::dataType | ( | ) |
Retrieve the data type of the tensor (host, device, storage)
uint32_t kp::Tensor::dataTypeMemorySize | ( | ) |
Returns the total size of a single element of the respective data type that this tensor holds.
void kp::Tensor::destroy | ( | ) |
Destroys and frees the GPU resources which include the buffer and memory.
bool kp::Tensor::isInit | ( | ) |
Check whether tensor is initialized based on the created gpu resources.
uint32_t kp::Tensor::memorySize | ( | ) |
Returns the total memory size of the data contained by the Tensor object which would equate to (this->size() * this->dataTypeMemorySize())
void* kp::Tensor::rawData | ( | ) |
void kp::Tensor::rebuild | ( | void * | data, |
uint32_t | elementTotalCount, | ||
uint32_t | elementMemorySize | ||
) |
Function to trigger reinitialisation of the tensor buffer and memory with new data as well as new potential device type.
data | Vector of data to use to initialise vector from |
tensorType | The type to use for the tensor |
void kp::Tensor::recordCopyFrom | ( | const vk::CommandBuffer & | commandBuffer, |
std::shared_ptr< Tensor > | copyFromTensor | ||
) |
Records a copy from the memory of the tensor provided to the current thensor. This is intended to pass memory into a processing, to perform a staging buffer transfer, or to gather output (between others).
commandBuffer | Vulkan Command Buffer to record the commands into |
copyFromTensor | Tensor to copy the data from |
void kp::Tensor::recordCopyFromDeviceToStaging | ( | const vk::CommandBuffer & | commandBuffer | ) |
Records a copy from the internal device memory to the staging memory using an optional barrier to wait for the operation. This function would only be relevant for kp::Tensors of type eDevice.
commandBuffer | Vulkan Command Buffer to record the commands into |
void kp::Tensor::recordCopyFromStagingToDevice | ( | const vk::CommandBuffer & | commandBuffer | ) |
Records a copy from the internal staging memory to the device memory using an optional barrier to wait for the operation. This function would only be relevant for kp::Tensors of type eDevice.
commandBuffer | Vulkan Command Buffer to record the commands into |
void kp::Tensor::recordPrimaryBufferMemoryBarrier | ( | const vk::CommandBuffer & | commandBuffer, |
vk::AccessFlagBits | srcAccessMask, | ||
vk::AccessFlagBits | dstAccessMask, | ||
vk::PipelineStageFlagBits | srcStageMask, | ||
vk::PipelineStageFlagBits | dstStageMask | ||
) |
Records the buffer memory barrier into the primary buffer and command buffer which ensures that relevant data transfers are carried out correctly.
commandBuffer | Vulkan Command Buffer to record the commands into |
srcAccessMask | Access flags for source access mask |
dstAccessMask | Access flags for destination access mask |
scrStageMask | Pipeline stage flags for source stage mask |
dstStageMask | Pipeline stage flags for destination stage mask |
void kp::Tensor::recordStagingBufferMemoryBarrier | ( | const vk::CommandBuffer & | commandBuffer, |
vk::AccessFlagBits | srcAccessMask, | ||
vk::AccessFlagBits | dstAccessMask, | ||
vk::PipelineStageFlagBits | srcStageMask, | ||
vk::PipelineStageFlagBits | dstStageMask | ||
) |
Records the buffer memory barrier into the staging buffer and command buffer which ensures that relevant data transfers are carried out correctly.
commandBuffer | Vulkan Command Buffer to record the commands into |
srcAccessMask | Access flags for source access mask |
dstAccessMask | Access flags for destination access mask |
scrStageMask | Pipeline stage flags for source stage mask |
dstStageMask | Pipeline stage flags for destination stage mask |
void kp::Tensor::setRawData | ( | const void * | data | ) |
Sets / resets the data of the tensor which is directly done on the GPU host visible memory available by the tensor.
uint32_t kp::Tensor::size | ( | ) |
Returns the size/magnitude of the Tensor, which will be the total number of elements across all dimensions
TensorTypes kp::Tensor::tensorType | ( | ) |
|
inline |
Template to get the data of the current tensor as a vector of specific type, which would be any of the supported types including float, double, int32, uint32 and bool.