Kompute
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
kp::Memory Class Referenceabstract
Inheritance diagram for kp::Memory:
Inheritance graph
[legend]

Public Types

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 }
 

Public Member Functions

 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 ()
 
virtual void destroy ()
 
MemoryTypes memoryType ()
 
DataTypes dataType ()
 
virtual bool isInit ()=0
 
virtual void recordCopyFromStagingToDevice (const vk::CommandBuffer &commandBuffer)=0
 
virtual void recordCopyFromDeviceToStaging (const vk::CommandBuffer &commandBuffer)=0
 
virtual void recordPrimaryMemoryBarrier (const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask)=0
 
virtual void recordStagingMemoryBarrier (const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask)=0
 
void recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Memory > copyFromMemory)
 
virtual vk::WriteDescriptorSet constructDescriptorSet (vk::DescriptorSet descriptorSet, uint32_t binding)=0
 
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 ()
 
virtual Type type ()=0
 

Static Public Member Functions

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

void mapRawData ()
 
void unmapRawData ()
 
void updateRawData (void *data)
 
vk::MemoryPropertyFlags getPrimaryMemoryPropertyFlags ()
 
vk::MemoryPropertyFlags getStagingMemoryPropertyFlags ()
 
virtual void recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Tensor > copyFromMemory)=0
 
virtual void recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Image > copyFromMemory)=0
 

Protected Attributes

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
 

Member Enumeration Documentation

◆ MemoryTypes

Type for memory created: Device allows memory to be transferred from staging memory. 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)

eDeviceAndHost 

Type is host-visible and host-coherent device memory.

Constructor & Destructor Documentation

◆ ~Memory()

virtual kp::Memory::~Memory ( )
inlinevirtual

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

Member Function Documentation

◆ constructDescriptorSet()

virtual vk::WriteDescriptorSet kp::Memory::constructDescriptorSet ( vk::DescriptorSet  descriptorSet,
uint32_t  binding 
)
pure virtual

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.

Implemented in kp::Image, and kp::Tensor.

◆ data()

template<typename T >
T * kp::Memory::data ( )
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.

Returns
Pointer to raw memory containing raw bytes data of Tensor/Image.

◆ dataType() [1/2]

template<typename T >
static constexpr DataTypes kp::Memory::dataType ( )
staticconstexpr

Retrieve the data type for T

Returns
Data type of T of type kp::Memory::DataTypes

◆ dataType() [2/2]

DataTypes kp::Memory::dataType ( )

Retrieve the data type of the tensor (int, float, unsigned short etc.)

Returns
Data type of memory of type kp::Memory::DataTypes

◆ dataTypeMemorySize() [1/2]

uint32_t kp::Memory::dataTypeMemorySize ( )

Returns the total size of a single element of the respective data type that this memory object holds.

Returns
Unsigned integer representing the memory of a single element of the respective data type.

◆ dataTypeMemorySize() [2/2]

static uint32_t kp::Memory::dataTypeMemorySize ( DataTypes  dataType)
static

Returns the total size of a single element of the respective data type

Returns
Unsigned integer representing the memory of a single element of the respective data type.

◆ destroy()

virtual void kp::Memory::destroy ( )
virtual

Destroys and frees the GPU resources which includes the memory.

Reimplemented in kp::Image, and kp::Tensor.

◆ isInit()

virtual bool kp::Memory::isInit ( )
pure virtual

Check whether memory object is initialized based on the created gpu resources.

Returns
Boolean stating whether memory object is initialized

Implemented in kp::Image, and kp::Tensor.

◆ memorySize()

uint32_t kp::Memory::memorySize ( )

Returns the total memory size of the data contained by the memory object which would equate to (this->size() * this->dataTypeMemorySize())

Returns
Unsigned integer representing the total memory size of the data contained by the image object.

◆ memoryType()

MemoryTypes kp::Memory::memoryType ( )

Retrieve the memory type of the memory

Returns
memory type of memory

◆ rawData()

void * kp::Memory::rawData ( )

Retrieve the raw data via the pointer to the memory that contains the raw memory of this current tensor. This tensor gets changed to a nullptr when the Tensor is removed.

Returns
Pointer to raw memory containing raw bytes data of Tensor/Image.

◆ recordCopyFrom() [1/3]

virtual void kp::Memory::recordCopyFrom ( const vk::CommandBuffer &  commandBuffer,
std::shared_ptr< Image copyFromMemory 
)
protectedpure virtual

Implemented in kp::Image, and kp::Tensor.

◆ recordCopyFrom() [2/3]

void kp::Memory::recordCopyFrom ( const vk::CommandBuffer &  commandBuffer,
std::shared_ptr< Memory copyFromMemory 
)

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

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

◆ recordCopyFrom() [3/3]

virtual void kp::Memory::recordCopyFrom ( const vk::CommandBuffer &  commandBuffer,
std::shared_ptr< Tensor copyFromMemory 
)
protectedpure virtual

Implemented in kp::Image, and kp::Tensor.

◆ recordCopyFromDeviceToStaging()

virtual void kp::Memory::recordCopyFromDeviceToStaging ( const vk::CommandBuffer &  commandBuffer)
pure virtual

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

Implemented in kp::Image, and kp::Tensor.

◆ recordCopyFromStagingToDevice()

virtual void kp::Memory::recordCopyFromStagingToDevice ( const vk::CommandBuffer &  commandBuffer)
pure virtual

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

Implemented in kp::Image, and kp::Tensor.

◆ recordPrimaryMemoryBarrier()

virtual void kp::Memory::recordPrimaryMemoryBarrier ( const vk::CommandBuffer &  commandBuffer,
vk::AccessFlagBits  srcAccessMask,
vk::AccessFlagBits  dstAccessMask,
vk::PipelineStageFlagBits  srcStageMask,
vk::PipelineStageFlagBits  dstStageMask 
)
pure virtual

Records the buffer 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

Implemented in kp::Image, and kp::Tensor.

◆ recordStagingMemoryBarrier()

virtual void kp::Memory::recordStagingMemoryBarrier ( const vk::CommandBuffer &  commandBuffer,
vk::AccessFlagBits  srcAccessMask,
vk::AccessFlagBits  dstAccessMask,
vk::PipelineStageFlagBits  srcStageMask,
vk::PipelineStageFlagBits  dstStageMask 
)
pure virtual

Records the buffer 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

Implemented in kp::Image, and kp::Tensor.

◆ setData() [1/2]

template<typename T >
void kp::Memory::setData ( const std::vector< T > &  data)
inline

Sets / resets the data of the tensor/image which is directly done on the GPU host visible memory available by the tensor/image.

◆ setData() [2/2]

void kp::Memory::setData ( const void data,
size_t  size 
)

Sets / resets the data of the tensor/image which is directly done on the GPU host visible memory available by the tensor/image.

◆ size()

uint32_t kp::Memory::size ( )

Returns the size/magnitude of the Tensor/Image, which will be the total number of elements across all dimensions

Returns
Unsigned integer representing the total number of elements

◆ type()

virtual Type kp::Memory::type ( )
pure virtual

Return the object type of this Memory object.

Returns
The object type of the Memory object.

Implemented in kp::Image, and kp::Tensor.

◆ vector()

template<typename T >
std::vector< T > kp::Memory::vector ( )
inline

Template to get the data of the current tensor/image as a vector of specific type, which would be any of the supported types including float, double, int32, uint32 and bool.

Returns
Vector of type provided by template.

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