Skip to content

Commit

Permalink
Expose copy region for tensor copy operations
Browse files Browse the repository at this point in the history
Signed-off-by: crydsch <crydsch@lph.zone>
  • Loading branch information
Crydsch committed Aug 26, 2023
1 parent 01ac6b5 commit 99cafa2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
37 changes: 34 additions & 3 deletions src/Tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,20 @@ Tensor::recordCopyFrom(const vk::CommandBuffer& commandBuffer,
vk::DeviceSize bufferSize(this->memorySize());
vk::BufferCopy copyRegion(0, 0, bufferSize);

KP_LOG_DEBUG("Kompute Tensor recordCopyFrom data size {}.", bufferSize);
this->recordCopyFrom(commandBuffer,
copyFromTensor,
copyRegion);
}

void
Tensor::recordCopyFrom(const vk::CommandBuffer& commandBuffer,
std::shared_ptr<Tensor> copyFromTensor,
const vk::BufferCopy copyRegion)
{

vk::DeviceSize bufferSize(this->memorySize());

KP_LOG_DEBUG("Kompute Tensor recordCopyFrom data size {}.", copyRegion.size);

this->recordCopyBuffer(commandBuffer,
copyFromTensor->mPrimaryBuffer,
Expand All @@ -217,7 +230,15 @@ Tensor::recordCopyFromStagingToDevice(const vk::CommandBuffer& commandBuffer)
vk::DeviceSize bufferSize(this->memorySize());
vk::BufferCopy copyRegion(0, 0, bufferSize);

KP_LOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize);
this->recordCopyFromStagingToDevice(commandBuffer, copyRegion);
}

void
Tensor::recordCopyFromStagingToDevice(const vk::CommandBuffer& commandBuffer, const vk::BufferCopy copyRegion)
{
vk::DeviceSize bufferSize(this->memorySize());

KP_LOG_DEBUG("Kompute Tensor copying data size {}.", copyRegion.size);

this->recordCopyBuffer(commandBuffer,
this->mStagingBuffer,
Expand All @@ -232,7 +253,17 @@ Tensor::recordCopyFromDeviceToStaging(const vk::CommandBuffer& commandBuffer)
vk::DeviceSize bufferSize(this->memorySize());
vk::BufferCopy copyRegion(0, 0, bufferSize);

KP_LOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize);
this->recordCopyFromDeviceToStaging(commandBuffer,
copyRegion);
}

void
Tensor::recordCopyFromDeviceToStaging(const vk::CommandBuffer& commandBuffer,
const vk::BufferCopy copyRegion)
{
vk::DeviceSize bufferSize(this->memorySize());

KP_LOG_DEBUG("Kompute Tensor copying data size {}.", copyRegion.size);

this->recordCopyBuffer(commandBuffer,
this->mPrimaryBuffer,
Expand Down
40 changes: 37 additions & 3 deletions src/include/kompute/Tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,66 @@ class Tensor

/**
* 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
* tensor. This is intended to pass memory into a processing, to perform
* a staging buffer transfer, or to gather output (between others).
* Copies the entire tensor.
*
* @param commandBuffer Vulkan Command Buffer to record the commands into
* @param copyFromTensor Tensor to copy the data from
*/
void recordCopyFrom(const vk::CommandBuffer& commandBuffer,
std::shared_ptr<Tensor> copyFromTensor);

/**
* 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).
*
* @param commandBuffer Vulkan Command Buffer to record the commands into
* @param copyFromTensor Tensor to copy the data from
* @param copyRegion The buffer region to copy
*/
void recordCopyFrom(const vk::CommandBuffer& commandBuffer,
std::shared_ptr<Tensor> copyFromTensor,
const vk::BufferCopy copyRegion);

/**
* 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.
* only be relevant for kp::Tensors of type eDevice. Copies the entire tensor.
*
* @param commandBuffer Vulkan Command Buffer to record the commands into
*/
void recordCopyFromStagingToDevice(const vk::CommandBuffer& commandBuffer);

/**
* Records a copy from the internal device memory to the staging memory
* 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.
*
* @param commandBuffer Vulkan Command Buffer to record the commands into
* @param copyRegion The buffer region to copy
*/
void recordCopyFromStagingToDevice(const vk::CommandBuffer& commandBuffer, const vk::BufferCopy copyRegion);

/**
* 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. Copies the entire tensor.
*
* @param commandBuffer Vulkan Command Buffer to record the commands into
*/
void 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.
*
* @param commandBuffer Vulkan Command Buffer to record the commands into
* @param copyRegion The buffer region to copy
*/
void recordCopyFromDeviceToStaging(const vk::CommandBuffer& commandBuffer, const vk::BufferCopy copyRegion);

/**
* Records the buffer memory barrier into the primary buffer and command
Expand Down

0 comments on commit 99cafa2

Please sign in to comment.