4 #include "kompute/Core.hpp"
5 #include "logger/Logger.hpp"
34 enum class TensorDataTypes
43 static std::string toString(TensorDataTypes dt);
56 Tensor(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
57 std::shared_ptr<vk::Device> device,
59 uint32_t elementTotalCount,
60 uint32_t elementMemorySize,
78 uint32_t elementTotalCount,
79 uint32_t elementMemorySize);
109 std::shared_ptr<Tensor> copyFromTensor);
141 const vk::CommandBuffer& commandBuffer,
142 vk::AccessFlagBits srcAccessMask,
143 vk::AccessFlagBits dstAccessMask,
144 vk::PipelineStageFlagBits srcStageMask,
145 vk::PipelineStageFlagBits dstStageMask);
158 const vk::CommandBuffer& commandBuffer,
159 vk::AccessFlagBits srcAccessMask,
160 vk::AccessFlagBits dstAccessMask,
161 vk::PipelineStageFlagBits srcStageMask,
162 vk::PipelineStageFlagBits dstStageMask);
231 return (T*)this->mRawData;
244 return { (T*)this->mRawData, ((T*)this->mRawData) + this->
size() };
250 TensorDataTypes mDataType;
252 uint32_t mDataTypeMemorySize;
257 std::shared_ptr<vk::PhysicalDevice> mPhysicalDevice;
258 std::shared_ptr<vk::Device> mDevice;
261 std::shared_ptr<vk::Buffer> mPrimaryBuffer;
262 bool mFreePrimaryBuffer =
false;
263 std::shared_ptr<vk::Buffer> mStagingBuffer;
264 bool mFreeStagingBuffer =
false;
265 std::shared_ptr<vk::DeviceMemory> mPrimaryMemory;
266 bool mFreePrimaryMemory =
false;
267 std::shared_ptr<vk::DeviceMemory> mStagingMemory;
268 bool mFreeStagingMemory =
false;
270 void allocateMemoryCreateGPUResources();
271 void createBuffer(std::shared_ptr<vk::Buffer> buffer,
272 vk::BufferUsageFlags bufferUsageFlags);
273 void allocateBindMemory(std::shared_ptr<vk::Buffer> buffer,
274 std::shared_ptr<vk::DeviceMemory> memory,
275 vk::MemoryPropertyFlags memoryPropertyFlags);
276 void recordCopyBuffer(
const vk::CommandBuffer& commandBuffer,
277 std::shared_ptr<vk::Buffer> bufferFrom,
278 std::shared_ptr<vk::Buffer> bufferTo,
279 vk::DeviceSize bufferSize,
280 vk::BufferCopy copyRegion);
281 void recordBufferMemoryBarrier(
const vk::CommandBuffer& commandBuffer,
282 const vk::Buffer& buffer,
283 vk::AccessFlagBits srcAccessMask,
284 vk::AccessFlagBits dstAccessMask,
285 vk::PipelineStageFlagBits srcStageMask,
286 vk::PipelineStageFlagBits dstStageMask);
289 vk::BufferUsageFlags getPrimaryBufferUsageFlags();
290 vk::MemoryPropertyFlags getPrimaryMemoryPropertyFlags();
291 vk::BufferUsageFlags getStagingBufferUsageFlags();
292 vk::MemoryPropertyFlags getStagingMemoryPropertyFlags();
303 TensorT(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
304 std::shared_ptr<vk::Device> device,
305 const std::vector<T>& data,
315 KP_LOG_DEBUG(
"Kompute TensorT constructor with data size {}",
319 ~
TensorT() { KP_LOG_DEBUG(
"Kompute TensorT destructor"); }
321 T* data() {
return (T*)this->mRawData; }
323 std::vector<T> vector()
325 return { (T*)this->mRawData, ((T*)this->mRawData) + this->
size() };
328 T& operator[](
int index) {
return *(((T*)this->mRawData) + index); }
330 void setData(
const std::vector<T>& data)
333 KP_LOG_DEBUG(
"Kompute TensorT setting data with data size {}",
336 if (data.size() != this->mSize) {
337 throw std::runtime_error(
338 "Kompute TensorT Cannot set data of different sizes");
344 TensorDataTypes dataType();
Definition: Tensor.hpp:300
Definition: Tensor.hpp:20
std::vector< T > vector()
Definition: Tensor.hpp:242
TensorTypes
Definition: Tensor.hpp:29
@ eDevice
Type is device memory, source and destination.
@ eHost
Type is host memory, source and destination.
@ eStorage
Type is Device memory (only)
void recordPrimaryBufferMemoryBarrier(const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask)
uint32_t dataTypeMemorySize()
TensorDataTypes dataType()
void setRawData(const void *data)
vk::DescriptorBufferInfo constructDescriptorBufferInfo()
void recordCopyFromDeviceToStaging(const vk::CommandBuffer &commandBuffer)
void recordCopyFromStagingToDevice(const vk::CommandBuffer &commandBuffer)
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)
void recordStagingBufferMemoryBarrier(const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask)
void rebuild(void *data, uint32_t elementTotalCount, uint32_t elementMemorySize)
T * data()
Definition: Tensor.hpp:229
void recordCopyFrom(const vk::CommandBuffer &commandBuffer, std::shared_ptr< Tensor > copyFromTensor)