Added initial base for opcreatetensor
This commit is contained in:
parent
93041b4519
commit
014f15d552
14 changed files with 422 additions and 61 deletions
|
|
@ -1,13 +1,74 @@
|
|||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
|
||||
#if DEBUG
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
||||
#endif
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#define KP_MAX_DIM_SIZE 1
|
||||
|
||||
namespace kp {
|
||||
|
||||
class Tensor
|
||||
{
|
||||
private:
|
||||
public:
|
||||
|
||||
enum class TensorTypes
|
||||
{
|
||||
eDevice = 0,
|
||||
eStaging = 1,
|
||||
eStorage = 2,
|
||||
};
|
||||
|
||||
Tensor();
|
||||
virtual ~Tensor();
|
||||
|
||||
Tensor(std::vector<uint32_t> shape, TensorTypes tensorType = TensorTypes::eDevice);
|
||||
|
||||
~Tensor();
|
||||
|
||||
void init(std::shared_ptr<vk::PhysicalDevice> physicalDevice, std::shared_ptr<vk::Device> device, std::shared_ptr<vk::CommandBuffer> commandBuffer, std::vector<uint32_t> data = std::vector<uint32_t>());
|
||||
|
||||
// Create functions
|
||||
void createBuffer(void* data = nullptr);
|
||||
|
||||
// Getter functions
|
||||
std::vector<uint32_t> data();
|
||||
uint32_t size();
|
||||
std::array<uint32_t, KP_MAX_DIM_SIZE> shape();
|
||||
TensorTypes tensorType();
|
||||
bool isInit();
|
||||
|
||||
// Record functions
|
||||
void recordCopyFrom(std::shared_ptr<Tensor> copyFromTensor);
|
||||
|
||||
private:
|
||||
std::shared_ptr<vk::PhysicalDevice> mPhysicalDevice;
|
||||
std::shared_ptr<vk::Device> mDevice;
|
||||
std::shared_ptr<vk::CommandBuffer> mCommandBuffer;
|
||||
|
||||
std::shared_ptr<vk::Buffer> mBuffer;
|
||||
bool mFreeBuffer;
|
||||
std::shared_ptr<vk::DeviceMemory> mMemory;
|
||||
bool mFreeMemory;
|
||||
|
||||
std::vector<uint32_t> mData;
|
||||
|
||||
TensorTypes mTensorType = TensorTypes::eDevice;
|
||||
|
||||
std::array<uint32_t, KP_MAX_DIM_SIZE> mShape; // TODO: Only 1D supported
|
||||
bool mIsInit = false;
|
||||
// uint32_t mDataType;
|
||||
|
||||
|
||||
// Private util functions
|
||||
vk::BufferUsageFlags getBufferUsageFlags();
|
||||
vk::MemoryPropertyFlags getMemoryPropertyFlags();
|
||||
uint64_t memorySize();
|
||||
};
|
||||
|
||||
} // End namespace kp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue