Kompute
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
kp::Tensor Class Reference

#include <Tensor.hpp>

Inheritance diagram for kp::Tensor:
Inheritance graph
[legend]
Collaboration diagram for kp::Tensor:
Collaboration graph
[legend]

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 DataTypes &dataType, const MemoryTypes &tensorType=MemoryTypes::eDevice)
 
 Tensor (std::shared_ptr< vk::PhysicalDevice > physicalDevice, std::shared_ptr< vk::Device > device, uint32_t elementTotalCount, uint32_t elementMemorySize, const DataTypes &dataType, const MemoryTypes &memoryType=MemoryTypes::eDevice)
 
 Tensor (const Tensor &)=delete
 Make Tensor uncopyable.
 
 Tensor (const Tensor &&)=delete
 
Tensoroperator= (const Tensor &)=delete
 
Tensoroperator= (const Tensor &&)=delete
 
virtual ~Tensor ()
 
void destroy () override
 
bool isInit () override
 
void recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Tensor > copyFromTensor) override
 
void recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Image > copyFromImage) override
 
void recordCopyFromStagingToDevice (const vk::CommandBuffer &commandBuffer) override
 
void recordCopyFromDeviceToStaging (const vk::CommandBuffer &commandBuffer) override
 
void recordPrimaryMemoryBarrier (const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) override
 
void recordStagingMemoryBarrier (const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) override
 
vk::WriteDescriptorSet constructDescriptorSet (vk::DescriptorSet descriptorSet, uint32_t binding) override
 
std::shared_ptr< vk::Buffer > getPrimaryBuffer ()
 
Type type () override
 
- Public Member Functions inherited from kp::Memory
 Memory (std::shared_ptr< vk::PhysicalDevice > physicalDevice, std::shared_ptr< vk::Device > device, const DataTypes &dataType, const MemoryTypes &memoryType, uint32_t x, uint32_t y)
 
 Memory (const Memory &)=delete
 Make Memory uncopyable.
 
 Memory (const Memory &&)=delete
 
Memoryoperator= (const Memory &)=delete
 
Memoryoperator= (const Memory &&)=delete
 
virtual ~Memory ()
 
MemoryTypes memoryType ()
 
DataTypes dataType ()
 
void recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Memory > copyFromMemory)
 
uint32_t size ()
 
uint32_t dataTypeMemorySize ()
 
uint32_t memorySize ()
 
vk::DescriptorType getDescriptorType ()
 
voidrawData ()
 
void setData (const void *data, size_t size)
 
template<typename T >
void setData (const std::vector< T > &data)
 
template<typename T >
Tdata ()
 
template<typename T >
std::vector< T > vector ()
 
uint32_t getX ()
 
uint32_t getY ()
 

Protected Attributes

vk::DescriptorBufferInfo mDescriptorBufferInfo
 
- Protected Attributes inherited from kp::Memory
MemoryTypes mMemoryType
 
DataTypes mDataType
 
uint32_t mSize
 
uint32_t mDataTypeMemorySize
 
voidmRawData = nullptr
 
vk::DescriptorType mDescriptorType
 
bool mUnmapMemory = false
 
uint32_t mX
 
uint32_t mY
 
std::shared_ptr< vk::PhysicalDevice > mPhysicalDevice
 
std::shared_ptr< vk::Device > mDevice
 
std::shared_ptr< vk::DeviceMemory > mPrimaryMemory
 
bool mFreePrimaryMemory = false
 
std::shared_ptr< vk::DeviceMemory > mStagingMemory
 
bool mFreeStagingMemory = false
 

Additional Inherited Members

- Public Types inherited from kp::Memory
enum class  MemoryTypes { eDevice = 0 , eHost = 1 , eStorage = 2 , eDeviceAndHost }
 
enum class  DataTypes {
  eBool = 0 , eInt = 1 , eUnsignedInt = 2 , eFloat = 3 ,
  eDouble = 4 , eCustom = 5 , eShort = 6 , eUnsignedShort = 7 ,
  eChar = 8 , eUnsignedChar = 9
}
 
enum class  Type { eTensor = 0 , eImage = 1 }
 
- Static Public Member Functions inherited from kp::Memory
static std::string toString (MemoryTypes dt)
 
static std::string toString (DataTypes dt)
 
template<typename T >
static constexpr DataTypes dataType ()
 
static uint32_t dataTypeMemorySize (DataTypes dataType)
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
- Protected Member Functions inherited from kp::Memory
void mapRawData ()
 
void unmapRawData ()
 
void updateRawData (void *data)
 
vk::MemoryPropertyFlags getPrimaryMemoryPropertyFlags ()
 
vk::MemoryPropertyFlags getStagingMemoryPropertyFlags ()
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Tensor() [1/2]

kp::Tensor::Tensor ( std::shared_ptr< vk::PhysicalDevice >  physicalDevice,
std::shared_ptr< vk::Device >  device,
void data,
uint32_t  elementTotalCount,
uint32_t  elementMemorySize,
const DataTypes &  dataType,
const MemoryTypes tensorType = MemoryTypes::eDevice 
)

Constructor with data provided which would be used to create the respective vulkan buffer and memory.

Parameters
physicalDeviceThe physical device to use to fetch properties
deviceThe device to use to create the buffer and memory from
dataNon-zero-sized vector of data that will be used by the tensor
tensorTypesType for the tensor which is of type MemoryTypes

◆ Tensor() [2/2]

kp::Tensor::Tensor ( std::shared_ptr< vk::PhysicalDevice >  physicalDevice,
std::shared_ptr< vk::Device >  device,
uint32_t  elementTotalCount,
uint32_t  elementMemorySize,
const DataTypes &  dataType,
const MemoryTypes memoryType = MemoryTypes::eDevice 
)

Constructor with size provided which would be used to create the respective vulkan buffer and memory. Data is not copied.

Parameters
physicalDeviceThe physical device to use to fetch properties
deviceThe device to use to create the buffer and memory from
elmentTotalCountthe number of elements of the array
elementMemorySizethe size of the element
tensorTypesType for the tensor which is of type TensorTypes

◆ ~Tensor()

virtual kp::Tensor::~Tensor ( )
virtual

Destructor which is in charge of freeing vulkan resources unless they have been provided externally.

Member Function Documentation

◆ constructDescriptorSet()

vk::WriteDescriptorSet kp::Tensor::constructDescriptorSet ( vk::DescriptorSet  descriptorSet,
uint32_t  binding 
)
overridevirtual

Adds this object to a Vulkan descriptor set at binding.

Parameters
descriptorSetThe descriptor set to add to.
bindingThe binding number to use.
Returns
Add this object to a descriptor set at binding.

Implements kp::Memory.

◆ destroy()

void kp::Tensor::destroy ( )
overridevirtual

Destroys and frees the GPU resources which include the buffer and memory.

Reimplemented from kp::Memory.

◆ isInit()

bool kp::Tensor::isInit ( )
overridevirtual

Check whether tensor is initialized based on the created gpu resources.

Returns
Boolean stating whether tensor is initialized

Implements kp::Memory.

◆ recordCopyFrom() [1/2]

void kp::Tensor::recordCopyFrom ( const vk::CommandBuffer &  commandBuffer,
std::shared_ptr< Image copyFromImage 
)
overridevirtual

Records a copy from the memory of the image provided to the current tensor. This is intended to pass memory into a processing, to perform a staging buffer transfer, or to gather output (between others).

Parameters
commandBufferVulkan Command Buffer to record the commands into
copyFromImageImage to copy the data from

Implements kp::Memory.

◆ recordCopyFrom() [2/2]

void kp::Tensor::recordCopyFrom ( const vk::CommandBuffer &  commandBuffer,
std::shared_ptr< Tensor copyFromTensor 
)
overridevirtual

Records a copy from the memory of the tensor provided to the current tensor. This is intended to pass memory into a processing, to perform a staging buffer transfer, or to gather output (between others).

Parameters
commandBufferVulkan Command Buffer to record the commands into
copyFromTensorTensor to copy the data from

Implements kp::Memory.

◆ recordCopyFromDeviceToStaging()

void kp::Tensor::recordCopyFromDeviceToStaging ( const vk::CommandBuffer &  commandBuffer)
overridevirtual

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.

Parameters
commandBufferVulkan Command Buffer to record the commands into

Implements kp::Memory.

◆ recordCopyFromStagingToDevice()

void kp::Tensor::recordCopyFromStagingToDevice ( const vk::CommandBuffer &  commandBuffer)
overridevirtual

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.

Parameters
commandBufferVulkan Command Buffer to record the commands into

Implements kp::Memory.

◆ recordPrimaryMemoryBarrier()

void kp::Tensor::recordPrimaryMemoryBarrier ( const vk::CommandBuffer &  commandBuffer,
vk::AccessFlagBits  srcAccessMask,
vk::AccessFlagBits  dstAccessMask,
vk::PipelineStageFlagBits  srcStageMask,
vk::PipelineStageFlagBits  dstStageMask 
)
overridevirtual

Records the memory barrier into the primary buffer and command buffer which ensures that relevant data transfers are carried out correctly.

Parameters
commandBufferVulkan Command Buffer to record the commands into
srcAccessMaskAccess flags for source access mask
dstAccessMaskAccess flags for destination access mask
scrStageMaskPipeline stage flags for source stage mask
dstStageMaskPipeline stage flags for destination stage mask

Implements kp::Memory.

◆ recordStagingMemoryBarrier()

void kp::Tensor::recordStagingMemoryBarrier ( const vk::CommandBuffer &  commandBuffer,
vk::AccessFlagBits  srcAccessMask,
vk::AccessFlagBits  dstAccessMask,
vk::PipelineStageFlagBits  srcStageMask,
vk::PipelineStageFlagBits  dstStageMask 
)
overridevirtual

Records the memory barrier into the staging buffer and command buffer which ensures that relevant data transfers are carried out correctly.

Parameters
commandBufferVulkan Command Buffer to record the commands into
srcAccessMaskAccess flags for source access mask
dstAccessMaskAccess flags for destination access mask
scrStageMaskPipeline stage flags for source stage mask
dstStageMaskPipeline stage flags for destination stage mask

Implements kp::Memory.

◆ type()

Type kp::Tensor::type ( )
inlineoverridevirtual

Return the object type of this Memory object.

Returns
The object type of the Memory object.

Implements kp::Memory.


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