Reformatted
This commit is contained in:
parent
c5df89c17b
commit
fdc1d3b91a
23 changed files with 455 additions and 418 deletions
2
Makefile
2
Makefile
|
|
@ -147,7 +147,7 @@ build_single_header:
|
|||
"single_include/kompute/Kompute.hpp"
|
||||
|
||||
format:
|
||||
$(CLANG_FORMAT_BIN) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/include/kompute/*.hpp
|
||||
$(CLANG_FORMAT_BIN) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/include/kompute/*.hpp test/*cpp
|
||||
|
||||
clean:
|
||||
find src -name "*gch" -exec rm {} \; || "No ghc files"
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ Algorithm::~Algorithm()
|
|||
if (this->mFreePipeline) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying pipeline");
|
||||
if (!this->mPipeline) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy pipeline but it is null");
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"pipeline but it is null");
|
||||
}
|
||||
this->mDevice->destroy(*this->mPipeline);
|
||||
}
|
||||
|
|
@ -39,7 +40,8 @@ Algorithm::~Algorithm()
|
|||
if (this->mFreePipelineCache) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying pipeline cache");
|
||||
if (!this->mPipelineCache) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy pipeline cache but it is null");
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"pipeline cache but it is null");
|
||||
}
|
||||
this->mDevice->destroy(*this->mPipelineCache);
|
||||
}
|
||||
|
|
@ -47,7 +49,8 @@ Algorithm::~Algorithm()
|
|||
if (this->mFreePipelineLayout) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying pipeline layout");
|
||||
if (!this->mPipelineLayout) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy pipeline layout but it is null");
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"pipeline layout but it is null");
|
||||
}
|
||||
this->mDevice->destroy(*this->mPipelineLayout);
|
||||
}
|
||||
|
|
@ -55,7 +58,8 @@ Algorithm::~Algorithm()
|
|||
if (this->mFreeShaderModule) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying shader module");
|
||||
if (!this->mShaderModule) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy shader module but it is null");
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy shader "
|
||||
"module but it is null");
|
||||
}
|
||||
this->mDevice->destroy(*this->mShaderModule);
|
||||
}
|
||||
|
|
@ -63,15 +67,18 @@ Algorithm::~Algorithm()
|
|||
if (this->mFreeDescriptorSet) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Freeing Descriptor Set");
|
||||
if (!this->mDescriptorSet) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to free descriptor set");
|
||||
SPDLOG_ERROR(
|
||||
"Kompute Algorithm Error requested to free descriptor set");
|
||||
}
|
||||
this->mDevice->freeDescriptorSets(*this->mDescriptorPool, 1, this->mDescriptorSet.get());
|
||||
this->mDevice->freeDescriptorSets(
|
||||
*this->mDescriptorPool, 1, this->mDescriptorSet.get());
|
||||
}
|
||||
|
||||
if (this->mFreeDescriptorSetLayout) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying Descriptor Set Layout");
|
||||
if (!this->mDescriptorSetLayout) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy descriptor set layout but it is null");
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"descriptor set layout but it is null");
|
||||
}
|
||||
this->mDevice->destroy(*this->mDescriptorSetLayout);
|
||||
}
|
||||
|
|
@ -79,7 +86,8 @@ Algorithm::~Algorithm()
|
|||
if (this->mFreeDescriptorPool) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying Descriptor Pool");
|
||||
if (!this->mDescriptorPool) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy descriptor pool but it is null");
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"descriptor pool but it is null");
|
||||
}
|
||||
this->mDevice->destroy(*this->mDescriptorPool);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,8 +215,8 @@ Manager::createDevice()
|
|||
physicalDevice.getProperties();
|
||||
|
||||
SPDLOG_INFO("Using physical device index {} found {}",
|
||||
this->mPhysicalDeviceIndex,
|
||||
physicalDeviceProperties.deviceName);
|
||||
this->mPhysicalDeviceIndex,
|
||||
physicalDeviceProperties.deviceName);
|
||||
|
||||
// Find compute queue
|
||||
std::vector<vk::QueueFamilyProperties> allQueueFamilyProperties =
|
||||
|
|
|
|||
|
|
@ -8,11 +8,10 @@ OpTensorCopy::OpTensorCopy()
|
|||
SPDLOG_DEBUG("Kompute OpTensorCopy constructor base");
|
||||
}
|
||||
|
||||
OpTensorCopy::OpTensorCopy(
|
||||
std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
std::shared_ptr<vk::Device> device,
|
||||
std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
std::vector<std::shared_ptr<Tensor>> tensors)
|
||||
OpTensorCopy::OpTensorCopy(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
std::shared_ptr<vk::Device> device,
|
||||
std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
std::vector<std::shared_ptr<Tensor>> tensors)
|
||||
: OpBase(physicalDevice, device, commandBuffer, tensors, false)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorCopy constructor with params");
|
||||
|
|
@ -33,12 +32,15 @@ OpTensorCopy::init()
|
|||
"Kompute OpTensorCopy called with less than 2 tensor");
|
||||
}
|
||||
|
||||
for (std::shared_ptr<Tensor> tensor: this->mTensors) {
|
||||
for (std::shared_ptr<Tensor> tensor : this->mTensors) {
|
||||
if (!tensor->isInit()) {
|
||||
throw std::runtime_error("Kompute OpTensorCopy tensor parameter has not been initialized");
|
||||
throw std::runtime_error(
|
||||
"Kompute OpTensorCopy tensor parameter has not been initialized");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eStorage) {
|
||||
throw std::runtime_error("Kompute OpTensorCopy tensor parameter is of TensorTypes::eStorage and hence cannot be used to receive or pass data.");
|
||||
throw std::runtime_error("Kompute OpTensorCopy tensor parameter is "
|
||||
"of TensorTypes::eStorage and hence "
|
||||
"cannot be used to receive or pass data.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +52,8 @@ OpTensorCopy::record()
|
|||
|
||||
// We iterate from the second tensor onwards and record a copy to all
|
||||
for (size_t i = 1; i < this->mTensors.size(); i++) {
|
||||
this->mTensors[i]->recordCopyFrom(this->mCommandBuffer, this->mTensors[0], false);
|
||||
this->mTensors[i]->recordCopyFrom(
|
||||
this->mCommandBuffer, this->mTensors[0], false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,4 +75,3 @@ OpTensorCopy::postEval()
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,19 +35,18 @@ OpTensorCreate::init()
|
|||
"Kompute OpTensorCreate called with less than 1 tensor");
|
||||
}
|
||||
|
||||
for (std::shared_ptr<Tensor> tensor: this->mTensors) {
|
||||
for (std::shared_ptr<Tensor> tensor : this->mTensors) {
|
||||
if (tensor->isInit()) {
|
||||
throw std::runtime_error("Kompute OpTensorCreate: Tensor has already been initialized");
|
||||
throw std::runtime_error(
|
||||
"Kompute OpTensorCreate: Tensor has already been initialized");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
tensor->init(
|
||||
this->mPhysicalDevice, this->mDevice);
|
||||
tensor->init(this->mPhysicalDevice, this->mDevice);
|
||||
|
||||
std::shared_ptr<Tensor> stagingTensor = std::make_shared<Tensor>(
|
||||
tensor->data(), Tensor::TensorTypes::eStaging);
|
||||
|
||||
stagingTensor->init(
|
||||
this->mPhysicalDevice, this->mDevice);
|
||||
stagingTensor->init(this->mPhysicalDevice, this->mDevice);
|
||||
|
||||
stagingTensor->mapDataIntoHostMemory();
|
||||
|
||||
|
|
@ -55,12 +54,11 @@ OpTensorCreate::init()
|
|||
|
||||
} else {
|
||||
|
||||
tensor->init(
|
||||
this->mPhysicalDevice, this->mDevice);
|
||||
tensor->init(this->mPhysicalDevice, this->mDevice);
|
||||
|
||||
tensor->mapDataIntoHostMemory();
|
||||
|
||||
// We push a nullptr when no staging tensor is needed to match
|
||||
// We push a nullptr when no staging tensor is needed to match
|
||||
// index number in array to have one to one mapping with tensors
|
||||
this->mStagingTensors.push_back(nullptr);
|
||||
}
|
||||
|
|
@ -74,8 +72,9 @@ OpTensorCreate::record()
|
|||
|
||||
for (size_t i = 0; i < this->mTensors.size(); i++) {
|
||||
if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
this->mTensors[i]->recordCopyFrom(this->mCommandBuffer, this->mStagingTensors[i], false);
|
||||
}
|
||||
this->mTensors[i]->recordCopyFrom(
|
||||
this->mCommandBuffer, this->mStagingTensors[i], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,25 +35,28 @@ OpTensorSyncDevice::init()
|
|||
"Kompute OpTensorSyncDevice called with less than 1 tensor");
|
||||
}
|
||||
|
||||
for (std::shared_ptr<Tensor> tensor: this->mTensors) {
|
||||
for (std::shared_ptr<Tensor> tensor : this->mTensors) {
|
||||
if (!tensor->isInit()) {
|
||||
throw std::runtime_error("Kompute OpTensorSyncDevice: Tensor param has not been initialized");
|
||||
throw std::runtime_error("Kompute OpTensorSyncDevice: Tensor param "
|
||||
"has not been initialized");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eStorage) {
|
||||
throw std::runtime_error("Kompute OpTensorSyncLocal tensor parameter is of type TensorTypes::eStorage and hence cannot be used to receive or pass data.");
|
||||
throw std::runtime_error(
|
||||
"Kompute OpTensorSyncLocal tensor parameter is of type "
|
||||
"TensorTypes::eStorage and hence cannot be used to receive or "
|
||||
"pass data.");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
|
||||
std::shared_ptr<Tensor> stagingTensor = std::make_shared<Tensor>(
|
||||
tensor->data(), Tensor::TensorTypes::eStaging);
|
||||
|
||||
stagingTensor->init(
|
||||
this->mPhysicalDevice, this->mDevice);
|
||||
stagingTensor->init(this->mPhysicalDevice, this->mDevice);
|
||||
|
||||
this->mStagingTensors.push_back(stagingTensor);
|
||||
|
||||
} else {
|
||||
// We push a nullptr when no staging tensor is needed to match
|
||||
// We push a nullptr when no staging tensor is needed to match
|
||||
// index number in array to have one to one mapping with tensors
|
||||
this->mStagingTensors.push_back(nullptr);
|
||||
}
|
||||
|
|
@ -67,7 +70,8 @@ OpTensorSyncDevice::record()
|
|||
|
||||
for (size_t i = 0; i < this->mTensors.size(); i++) {
|
||||
if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
this->mTensors[i]->recordCopyFrom(this->mCommandBuffer, this->mStagingTensors[i], false);
|
||||
this->mTensors[i]->recordCopyFrom(
|
||||
this->mCommandBuffer, this->mStagingTensors[i], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,26 +35,29 @@ OpTensorSyncLocal::init()
|
|||
"Kompute OpTensorSyncLocal called with less than 1 tensor");
|
||||
}
|
||||
|
||||
for (std::shared_ptr<Tensor> tensor: this->mTensors) {
|
||||
for (std::shared_ptr<Tensor> tensor : this->mTensors) {
|
||||
if (!tensor->isInit()) {
|
||||
throw std::runtime_error("Kompute OpTensorSyncLocal: Tensor has not been initialized");
|
||||
throw std::runtime_error(
|
||||
"Kompute OpTensorSyncLocal: Tensor has not been initialized");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eStorage) {
|
||||
throw std::runtime_error("Kompute OpTensorSyncLocal tensor parameter is of type TensorTypes::eStorage and hence cannot be used to receive or pass data.");
|
||||
throw std::runtime_error(
|
||||
"Kompute OpTensorSyncLocal tensor parameter is of type "
|
||||
"TensorTypes::eStorage and hence cannot be used to receive or "
|
||||
"pass data.");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
|
||||
std::shared_ptr<Tensor> stagingTensor = std::make_shared<Tensor>(
|
||||
tensor->data(), Tensor::TensorTypes::eStaging);
|
||||
|
||||
stagingTensor->init(
|
||||
this->mPhysicalDevice, this->mDevice);
|
||||
stagingTensor->init(this->mPhysicalDevice, this->mDevice);
|
||||
|
||||
this->mStagingTensors.push_back(stagingTensor);
|
||||
|
||||
} else {
|
||||
|
||||
// We push a nullptr when no staging tensor is needed to match
|
||||
// We push a nullptr when no staging tensor is needed to match
|
||||
// index number in array to have one to one mapping with tensors
|
||||
this->mStagingTensors.push_back(nullptr);
|
||||
}
|
||||
|
|
@ -68,7 +71,8 @@ OpTensorSyncLocal::record()
|
|||
|
||||
for (size_t i = 0; i < this->mTensors.size(); i++) {
|
||||
if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
this->mStagingTensors[i]->recordCopyFrom(this->mCommandBuffer, this->mTensors[i], true);
|
||||
this->mStagingTensors[i]->recordCopyFrom(
|
||||
this->mCommandBuffer, this->mTensors[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -96,4 +100,3 @@ OpTensorSyncLocal::postEval()
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ Sequence::~Sequence()
|
|||
SPDLOG_INFO("Freeing CommandBuffer");
|
||||
if (!this->mCommandBuffer) {
|
||||
SPDLOG_ERROR("Kompute Sequence destructor reached with null "
|
||||
"CommandPool pointer");
|
||||
"CommandPool pointer");
|
||||
return;
|
||||
}
|
||||
this->mDevice->freeCommandBuffers(
|
||||
|
|
@ -49,7 +49,7 @@ Sequence::~Sequence()
|
|||
SPDLOG_INFO("Destroying CommandPool");
|
||||
if (this->mCommandPool == nullptr) {
|
||||
SPDLOG_ERROR("Kompute Sequence destructor reached with null "
|
||||
"CommandPool pointer");
|
||||
"CommandPool pointer");
|
||||
return;
|
||||
}
|
||||
this->mDevice->destroy(*this->mCommandPool);
|
||||
|
|
@ -85,7 +85,7 @@ Sequence::begin()
|
|||
this->mRecording = true;
|
||||
} else {
|
||||
SPDLOG_WARN("Kompute Sequence attempted to start command recording "
|
||||
"but recording already started");
|
||||
"but recording already started");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ Sequence::end()
|
|||
this->mRecording = false;
|
||||
} else {
|
||||
SPDLOG_WARN("Kompute Sequence attempted to end command recording but "
|
||||
"recording not started");
|
||||
"recording not started");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ Tensor::Tensor(const std::vector<float>& data, TensorTypes tensorType)
|
|||
|
||||
Tensor::~Tensor()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor destructor started. Type: {}", this->tensorType());
|
||||
SPDLOG_DEBUG("Kompute Tensor destructor started. Type: {}",
|
||||
this->tensorType());
|
||||
|
||||
if (this->isInit()) {
|
||||
this->freeMemoryDestroyGPUResources();
|
||||
|
|
@ -62,7 +63,7 @@ Tensor::data()
|
|||
}
|
||||
|
||||
float&
|
||||
Tensor::operator[] (int index)
|
||||
Tensor::operator[](int index)
|
||||
{
|
||||
return this->mData[index];
|
||||
}
|
||||
|
|
@ -101,16 +102,16 @@ void
|
|||
Tensor::setData(const std::vector<float>& data)
|
||||
{
|
||||
if (data.size() != this->mData.size()) {
|
||||
throw std::runtime_error("Kompute Tensor Cannot set data of different sizes");
|
||||
throw std::runtime_error(
|
||||
"Kompute Tensor Cannot set data of different sizes");
|
||||
}
|
||||
this->mData = data;
|
||||
}
|
||||
|
||||
void
|
||||
Tensor::recordCopyFrom(
|
||||
std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
std::shared_ptr<Tensor> copyFromTensor,
|
||||
bool createBarrier)
|
||||
Tensor::recordCopyFrom(std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
std::shared_ptr<Tensor> copyFromTensor,
|
||||
bool createBarrier)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor recordCopyFrom called");
|
||||
|
||||
|
|
@ -138,11 +139,12 @@ Tensor::recordCopyFrom(
|
|||
}
|
||||
|
||||
void
|
||||
Tensor::recordBufferMemoryBarrier(std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
vk::AccessFlagBits srcAccessMask,
|
||||
vk::AccessFlagBits dstAccessMask,
|
||||
vk::PipelineStageFlagBits srcStageMask,
|
||||
vk::PipelineStageFlagBits dstStageMask)
|
||||
Tensor::recordBufferMemoryBarrier(
|
||||
std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
vk::AccessFlagBits srcAccessMask,
|
||||
vk::AccessFlagBits dstAccessMask,
|
||||
vk::PipelineStageFlagBits srcStageMask,
|
||||
vk::PipelineStageFlagBits dstStageMask)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor recording buffer memory barrier");
|
||||
|
||||
|
|
@ -157,11 +159,11 @@ Tensor::recordBufferMemoryBarrier(std::shared_ptr<vk::CommandBuffer> commandBuff
|
|||
bufferMemoryBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
|
||||
commandBuffer->pipelineBarrier(srcStageMask,
|
||||
dstStageMask,
|
||||
vk::DependencyFlags(),
|
||||
nullptr,
|
||||
bufferMemoryBarrier,
|
||||
nullptr);
|
||||
dstStageMask,
|
||||
vk::DependencyFlags(),
|
||||
nullptr,
|
||||
bufferMemoryBarrier,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
vk::DescriptorBufferInfo
|
||||
|
|
@ -201,9 +203,8 @@ Tensor::mapDataIntoHostMemory()
|
|||
SPDLOG_DEBUG("Kompute Tensor local mapping tensor data to host buffer");
|
||||
|
||||
if (this->mTensorType != TensorTypes::eStaging) {
|
||||
SPDLOG_ERROR(
|
||||
"Mapping tensor data manually to DEVICE memory instead of "
|
||||
"using record GPU command with staging buffer");
|
||||
SPDLOG_ERROR("Mapping tensor data manually to DEVICE memory instead of "
|
||||
"using record GPU command with staging buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#else
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef KOMPUTE_LOG_OVERRIDE
|
||||
#if KOMPUTE_ENABLE_SPDLOG
|
||||
|
|
@ -19,7 +19,8 @@
|
|||
#if SPDLOG_ACTIVE_LEVEL > 1
|
||||
#define SPDLOG_DEBUG(message, ...)
|
||||
#else
|
||||
#define SPDLOG_DEBUG(message, ...) std::cout << "DEBUG: " << message << std::endl
|
||||
#define SPDLOG_DEBUG(message, ...) \
|
||||
std::cout << "DEBUG: " << message << std::endl
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 1
|
||||
#if SPDLOG_ACTIVE_LEVEL > 2
|
||||
#define SPDLOG_INFO(message, ...)
|
||||
|
|
@ -29,13 +30,14 @@
|
|||
#if SPDLOG_ACTIVE_LEVEL > 3
|
||||
#define SPDLOG_WARN(message, ...)
|
||||
#else
|
||||
#define SPDLOG_WARN(message, ...) std::cout << "WARNING: " << message << std::endl
|
||||
#define SPDLOG_WARN(message, ...) \
|
||||
std::cout << "WARNING: " << message << std::endl
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 3
|
||||
#if SPDLOG_ACTIVE_LEVEL > 4
|
||||
#define SPDLOG_ERROR(message, ...)
|
||||
#else
|
||||
#define SPDLOG_ERROR(message, ...) std::cout << "ERROR: " << message << std::endl
|
||||
#define SPDLOG_ERROR(message, ...) \
|
||||
std::cout << "ERROR: " << message << std::endl
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 4
|
||||
#endif //KOMPUTE_SPDLOG_ENABLED
|
||||
#endif // KOMPUTE_SPDLOG_ENABLED
|
||||
#endif // KOMPUTE_LOG_OVERRIDE
|
||||
|
||||
|
|
|
|||
|
|
@ -107,17 +107,17 @@ class Manager
|
|||
*/
|
||||
template<typename T, typename... TArgs>
|
||||
void evalOpDefault(std::vector<std::shared_ptr<Tensor>> tensors,
|
||||
TArgs&&... params)
|
||||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp Default triggered");
|
||||
this->evalOp<T>(tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
this->evalOp<T>(
|
||||
tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function that simplifies the common workflow of tensor creation and
|
||||
* initialization. It will take the constructor parameters for a Tensor
|
||||
* and will will us it to create a new Tensor and then create it using
|
||||
* and will will us it to create a new Tensor and then create it using
|
||||
* the OpCreateTensor command.
|
||||
*
|
||||
* @param data The data to initialize the tensor with
|
||||
|
|
@ -125,15 +125,16 @@ class Manager
|
|||
* @returns Initialized Tensor with memory Syncd to GPU device
|
||||
*/
|
||||
std::shared_ptr<Tensor> buildTensor(
|
||||
const std::vector<float>& data,
|
||||
Tensor::TensorTypes tensorType = Tensor::TensorTypes::eDevice)
|
||||
const std::vector<float>& data,
|
||||
Tensor::TensorTypes tensorType = Tensor::TensorTypes::eDevice)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager createInitTensor triggered");
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager creating new tensor shared ptr");
|
||||
std::shared_ptr<Tensor> tensor = std::make_shared<Tensor>(kp::Tensor(data, tensorType));
|
||||
std::shared_ptr<Tensor> tensor =
|
||||
std::make_shared<Tensor>(kp::Tensor(data, tensorType));
|
||||
|
||||
this->evalOpDefault<OpTensorCreate>({tensor});
|
||||
this->evalOpDefault<OpTensorCreate>({ tensor });
|
||||
|
||||
return tensor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Tensor
|
|||
*/
|
||||
enum class TensorTypes
|
||||
{
|
||||
eDevice = 0, ///< Type is device memory, source and destination
|
||||
eDevice = 0, ///< Type is device memory, source and destination
|
||||
eStaging = 1, ///< Type is host memory, source and destination
|
||||
eStorage = 2, ///< Type is Device memory (only)
|
||||
};
|
||||
|
|
@ -52,7 +52,10 @@ class Tensor
|
|||
~Tensor();
|
||||
|
||||
/**
|
||||
* Initialiser which calls the initialisation for all the respective tensors as well as creates the respective staging tensors. The staging tensors woudl only be created for the tensors of type TensorType::eDevice as otherwise there is no need to copy from host memory.
|
||||
* Initialiser which calls the initialisation for all the respective tensors
|
||||
* as well as creates the respective staging tensors. The staging tensors
|
||||
* woudl only be created for the tensors of type TensorType::eDevice as
|
||||
* otherwise there is no need to copy from host memory.
|
||||
*/
|
||||
void init(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
std::shared_ptr<vk::Device> device);
|
||||
|
|
@ -67,7 +70,8 @@ class Tensor
|
|||
* important to ensure that there is no out-of-sync data with the GPU
|
||||
* memory.
|
||||
*
|
||||
* @return Reference to vector of elements representing the data in the tensor.
|
||||
* @return Reference to vector of elements representing the data in the
|
||||
* tensor.
|
||||
*/
|
||||
std::vector<float>& data();
|
||||
/**
|
||||
|
|
@ -78,7 +82,7 @@ class Tensor
|
|||
* @param i The index where the element will be returned from.
|
||||
* @return Returns the element in the position requested.
|
||||
*/
|
||||
float& operator[] (int index);
|
||||
float& operator[](int index);
|
||||
/**
|
||||
* Returns the size/magnitude of the Tensor, which will be the total number
|
||||
* of elements across all dimensions
|
||||
|
|
@ -137,11 +141,12 @@ class Tensor
|
|||
* @param scrStageMask Pipeline stage flags for source stage mask
|
||||
* @param dstStageMask Pipeline stage flags for destination stage mask
|
||||
*/
|
||||
void recordBufferMemoryBarrier(std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
vk::AccessFlagBits srcAccessMask,
|
||||
vk::AccessFlagBits dstAccessMask,
|
||||
vk::PipelineStageFlagBits srcStageMask,
|
||||
vk::PipelineStageFlagBits dstStageMask);
|
||||
void recordBufferMemoryBarrier(
|
||||
std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
vk::AccessFlagBits srcAccessMask,
|
||||
vk::AccessFlagBits dstAccessMask,
|
||||
vk::PipelineStageFlagBits srcStageMask,
|
||||
vk::PipelineStageFlagBits dstStageMask);
|
||||
|
||||
/**
|
||||
* Constructs a vulkan descriptor buffer info which can be used to specify
|
||||
|
|
|
|||
|
|
@ -4,33 +4,35 @@
|
|||
#include "fmt/ranges.h"
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression) {
|
||||
TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression)
|
||||
{
|
||||
|
||||
uint32_t ITERATIONS = 100;
|
||||
float learningRate = 0.1;
|
||||
|
||||
std::shared_ptr<kp::Tensor> xI{ new kp::Tensor({ 0, 1, 1, 1, 1 })};
|
||||
std::shared_ptr<kp::Tensor> xJ{ new kp::Tensor({ 0, 0, 0, 1, 1 })};
|
||||
std::shared_ptr<kp::Tensor> xI{ new kp::Tensor({ 0, 1, 1, 1, 1 }) };
|
||||
std::shared_ptr<kp::Tensor> xJ{ new kp::Tensor({ 0, 0, 0, 1, 1 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> y{ new kp::Tensor({ 0, 0, 0, 1, 1 })};
|
||||
std::shared_ptr<kp::Tensor> y{ new kp::Tensor({ 0, 0, 0, 1, 1 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> wIn{ new kp::Tensor({ 0.001, 0.001 })};
|
||||
std::shared_ptr<kp::Tensor> wOutI{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> wOutJ{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> wIn{ new kp::Tensor({ 0.001, 0.001 }) };
|
||||
std::shared_ptr<kp::Tensor> wOutI{ new kp::Tensor({ 0, 0, 0, 0, 0 }) };
|
||||
std::shared_ptr<kp::Tensor> wOutJ{ new kp::Tensor({ 0, 0, 0, 0, 0 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> bIn{ new kp::Tensor({ 0 })};
|
||||
std::shared_ptr<kp::Tensor> bOut{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> bIn{ new kp::Tensor({ 0 }) };
|
||||
std::shared_ptr<kp::Tensor> bOut{ new kp::Tensor({ 0, 0, 0, 0, 0 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> lOut{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> lOut{ new kp::Tensor({ 0, 0, 0, 0, 0 }) };
|
||||
|
||||
std::vector<std::shared_ptr<kp::Tensor>> params =
|
||||
{xI, xJ, y, wIn, wOutI, wOutJ, bIn, bOut, lOut};
|
||||
std::vector<std::shared_ptr<kp::Tensor>> params = { xI, xJ, y,
|
||||
wIn, wOutI, wOutJ,
|
||||
bIn, bOut, lOut };
|
||||
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.getOrCreateManagedSequence("createTensors").lock()) {
|
||||
if (std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.getOrCreateManagedSequence("createTensors").lock()) {
|
||||
|
||||
sq->begin();
|
||||
|
||||
|
|
@ -42,13 +44,12 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression) {
|
|||
// Record op algo base
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorSyncDevice>({wIn, bIn});
|
||||
sq->record<kp::OpTensorSyncDevice>({ wIn, bIn });
|
||||
|
||||
sq->record<kp::OpAlgoBase<>>(
|
||||
params,
|
||||
"test/shaders/glsl/test_logistic_regression.comp");
|
||||
params, "test/shaders/glsl/test_logistic_regression.comp");
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({wOutI, wOutJ, bOut, lOut});
|
||||
sq->record<kp::OpTensorSyncLocal>({ wOutI, wOutJ, bOut, lOut });
|
||||
|
||||
sq->end();
|
||||
|
||||
|
|
@ -57,7 +58,7 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression) {
|
|||
|
||||
sq->eval();
|
||||
|
||||
for(size_t j = 0; j < bOut->size(); j++) {
|
||||
for (size_t j = 0; j < bOut->size(); j++) {
|
||||
wIn->data()[0] -= learningRate * wOutI->data()[j];
|
||||
wIn->data()[1] -= learningRate * wOutJ->data()[j];
|
||||
bIn->data()[0] -= learningRate * bOut->data()[j];
|
||||
|
|
@ -66,7 +67,6 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Based on the inputs the outputs should be at least:
|
||||
// * wi < 0.01
|
||||
// * wj > 1.0
|
||||
|
|
@ -77,11 +77,14 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression) {
|
|||
EXPECT_LT(bIn->data()[0], 0.0);
|
||||
EXPECT_LT(bIn->data()[0], 0.0);
|
||||
|
||||
SPDLOG_WARN("Result wIn: {}, bIn: {}, loss: {}",
|
||||
wIn->data(), bIn->data(), lOut->data());
|
||||
SPDLOG_WARN("Result wIn: {}, bIn: {}, loss: {}",
|
||||
wIn->data(),
|
||||
bIn->data(),
|
||||
lOut->data());
|
||||
}
|
||||
|
||||
TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy) {
|
||||
TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy)
|
||||
{
|
||||
|
||||
uint32_t ITERATIONS = 100;
|
||||
float learningRate = 0.1;
|
||||
|
|
@ -89,30 +92,31 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy) {
|
|||
std::vector<float> wInVec = { 0.001, 0.001 };
|
||||
std::vector<float> bInVec = { 0 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> xI{ new kp::Tensor({ 0, 1, 1, 1, 1 })};
|
||||
std::shared_ptr<kp::Tensor> xJ{ new kp::Tensor({ 0, 0, 0, 1, 1 })};
|
||||
std::shared_ptr<kp::Tensor> xI{ new kp::Tensor({ 0, 1, 1, 1, 1 }) };
|
||||
std::shared_ptr<kp::Tensor> xJ{ new kp::Tensor({ 0, 0, 0, 1, 1 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> y{ new kp::Tensor({ 0, 0, 0, 1, 1 })};
|
||||
std::shared_ptr<kp::Tensor> y{ new kp::Tensor({ 0, 0, 0, 1, 1 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> wIn{
|
||||
new kp::Tensor(wInVec, kp::Tensor::TensorTypes::eStaging)};
|
||||
std::shared_ptr<kp::Tensor> wOutI{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> wOutJ{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> wIn{ new kp::Tensor(
|
||||
wInVec, kp::Tensor::TensorTypes::eStaging) };
|
||||
std::shared_ptr<kp::Tensor> wOutI{ new kp::Tensor({ 0, 0, 0, 0, 0 }) };
|
||||
std::shared_ptr<kp::Tensor> wOutJ{ new kp::Tensor({ 0, 0, 0, 0, 0 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> bIn{
|
||||
new kp::Tensor(bInVec, kp::Tensor::TensorTypes::eStaging)};
|
||||
std::shared_ptr<kp::Tensor> bOut{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> bIn{ new kp::Tensor(
|
||||
bInVec, kp::Tensor::TensorTypes::eStaging) };
|
||||
std::shared_ptr<kp::Tensor> bOut{ new kp::Tensor({ 0, 0, 0, 0, 0 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> lOut{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> lOut{ new kp::Tensor({ 0, 0, 0, 0, 0 }) };
|
||||
|
||||
std::vector<std::shared_ptr<kp::Tensor>> params =
|
||||
{xI, xJ, y, wIn, wOutI, wOutJ, bIn, bOut, lOut};
|
||||
std::vector<std::shared_ptr<kp::Tensor>> params = { xI, xJ, y,
|
||||
wIn, wOutI, wOutJ,
|
||||
bIn, bOut, lOut };
|
||||
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.getOrCreateManagedSequence("createTensors").lock()) {
|
||||
if (std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.getOrCreateManagedSequence("createTensors").lock()) {
|
||||
|
||||
sq->begin();
|
||||
|
||||
|
|
@ -125,10 +129,9 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy) {
|
|||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<>>(
|
||||
params,
|
||||
"test/shaders/glsl/test_logistic_regression.comp");
|
||||
params, "test/shaders/glsl/test_logistic_regression.comp");
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({wOutI, wOutJ, bOut, lOut});
|
||||
sq->record<kp::OpTensorSyncLocal>({ wOutI, wOutJ, bOut, lOut });
|
||||
|
||||
sq->end();
|
||||
|
||||
|
|
@ -137,7 +140,7 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy) {
|
|||
|
||||
sq->eval();
|
||||
|
||||
for(size_t j = 0; j < bOut->size(); j++) {
|
||||
for (size_t j = 0; j < bOut->size(); j++) {
|
||||
wIn->data()[0] -= learningRate * wOutI->data()[j];
|
||||
wIn->data()[1] -= learningRate * wOutJ->data()[j];
|
||||
bIn->data()[0] -= learningRate * bOut->data()[j];
|
||||
|
|
@ -148,7 +151,6 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Based on the inputs the outputs should be at least:
|
||||
// * wi < 0.01
|
||||
// * wj > 1.0
|
||||
|
|
@ -158,6 +160,8 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy) {
|
|||
EXPECT_GT(wIn->data()[1], 1.0);
|
||||
EXPECT_LT(bIn->data()[0], 0.0);
|
||||
|
||||
SPDLOG_WARN("Result wIn: {}, bIn: {}, loss: {}",
|
||||
wIn->data(), bIn->data(), lOut->data());
|
||||
SPDLOG_WARN("Result wIn: {}, bIn: {}, loss: {}",
|
||||
wIn->data(),
|
||||
bIn->data(),
|
||||
lOut->data());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,15 @@
|
|||
|
||||
#include <kompute/Kompute.hpp>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
#if KOMPUTE_ENABLE_SPDLOG
|
||||
spdlog::set_level(static_cast<spdlog::level::level_enum>(SPDLOG_ACTIVE_LEVEL));
|
||||
spdlog::set_level(
|
||||
static_cast<spdlog::level::level_enum>(SPDLOG_ACTIVE_LEVEL));
|
||||
#endif
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
|
|
|
|||
80
test/TestManager.cpp
Executable file → Normal file
80
test/TestManager.cpp
Executable file → Normal file
|
|
@ -10,10 +10,10 @@ TEST(TestManager, EndToEndOpMultFlow)
|
|||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor({ 0, 1, 2 }) };
|
||||
mgr.evalOp<kp::OpTensorCreate>({ tensorLHS });
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor( { 2, 4, 6 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor({ 2, 4, 6 }) };
|
||||
mgr.evalOp<kp::OpTensorCreate>({ tensorRHS });
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor( { 0, 0, 0 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
mgr.evalOp<kp::OpTensorCreate>({ tensorOutput });
|
||||
|
||||
|
|
@ -21,23 +21,22 @@ TEST(TestManager, EndToEndOpMultFlow)
|
|||
|
||||
mgr.evalOp<kp::OpTensorSyncLocal>({ tensorOutput });
|
||||
|
||||
EXPECT_EQ(tensorOutput->data(), std::vector<float>({0, 4, 12}));
|
||||
EXPECT_EQ(tensorOutput->data(), std::vector<float>({ 0, 4, 12 }));
|
||||
}
|
||||
|
||||
TEST(TestManager, OpMultSequenceFlow) {
|
||||
TEST(TestManager, OpMultSequenceFlow)
|
||||
{
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor(
|
||||
{ 0, 1, 2 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor({ 0, 1, 2 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor(
|
||||
{ 2, 4, 6 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor({ 2, 4, 6 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor(
|
||||
{ 0, 0, 0 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr = mgr.getOrCreateManagedSequence("newSequence");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
sq->begin();
|
||||
|
||||
|
|
@ -54,23 +53,24 @@ TEST(TestManager, OpMultSequenceFlow) {
|
|||
}
|
||||
sqWeakPtr.reset();
|
||||
|
||||
EXPECT_EQ(tensorOutput->data(), std::vector<float>({0, 4, 12}));
|
||||
EXPECT_EQ(tensorOutput->data(), std::vector<float>({ 0, 4, 12 }));
|
||||
}
|
||||
|
||||
TEST(TestManager, TestMultipleSequences) {
|
||||
TEST(TestManager, TestMultipleSequences)
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtrOne =
|
||||
mgr.getOrCreateManagedSequence("sqOne");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtrOne =
|
||||
mgr.getOrCreateManagedSequence("sqOne");
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtrTwo =
|
||||
mgr.getOrCreateManagedSequence("sqTwo");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtrTwo =
|
||||
mgr.getOrCreateManagedSequence("sqTwo");
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtrOneRef =
|
||||
mgr.getOrCreateManagedSequence("sqOne");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtrOneRef =
|
||||
mgr.getOrCreateManagedSequence("sqOne");
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtrTwoRef =
|
||||
mgr.getOrCreateManagedSequence("sqTwo");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtrTwoRef =
|
||||
mgr.getOrCreateManagedSequence("sqTwo");
|
||||
|
||||
EXPECT_EQ(sqWeakPtrOne.lock(), sqWeakPtrOneRef.lock());
|
||||
EXPECT_NE(sqWeakPtrTwo.lock(), sqWeakPtrOneRef.lock());
|
||||
|
|
@ -78,20 +78,19 @@ TEST(TestManager, TestMultipleSequences) {
|
|||
EXPECT_NE(sqWeakPtrOneRef.lock(), sqWeakPtrTwoRef.lock());
|
||||
}
|
||||
|
||||
TEST(TestManager, TestMultipleTensorsAtOnce) {
|
||||
TEST(TestManager, TestMultipleTensorsAtOnce)
|
||||
{
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor(
|
||||
{ 0, 1, 2 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor({ 0, 1, 2 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor(
|
||||
{ 2, 4, 6 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor({ 2, 4, 6 }) };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor(
|
||||
{ 0, 0, 0 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr = mgr.getOrCreateManagedSequence("newSequence");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
sq->begin();
|
||||
|
||||
|
|
@ -110,25 +109,26 @@ TEST(TestManager, TestMultipleTensorsAtOnce) {
|
|||
}
|
||||
sqWeakPtr.reset();
|
||||
|
||||
EXPECT_EQ(tensorOutput->data(), std::vector<float>({0, 4, 12}));
|
||||
EXPECT_EQ(tensorOutput->data(), std::vector<float>({ 0, 4, 12 }));
|
||||
}
|
||||
|
||||
TEST(TestManager, TestCreateInitTensor) {
|
||||
TEST(TestManager, TestCreateInitTensor)
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA = mgr.buildTensor({0,1,2});
|
||||
std::shared_ptr<kp::Tensor> tensorB = mgr.buildTensor({0,0,0});
|
||||
std::shared_ptr<kp::Tensor> tensorA = mgr.buildTensor({ 0, 1, 2 });
|
||||
std::shared_ptr<kp::Tensor> tensorB = mgr.buildTensor({ 0, 0, 0 });
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB });
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorB });
|
||||
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({0,1,2}));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({ 0, 1, 2 }));
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorC = mgr.buildTensor({0,0,0}, kp::Tensor::TensorTypes::eStaging);
|
||||
std::shared_ptr<kp::Tensor> tensorC =
|
||||
mgr.buildTensor({ 0, 0, 0 }, kp::Tensor::TensorTypes::eStaging);
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({tensorA, tensorC});
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorC });
|
||||
|
||||
EXPECT_EQ(tensorC->data(), std::vector<float>({0,1,2}));
|
||||
EXPECT_EQ(tensorC->data(), std::vector<float>({ 0, 1, 2 }));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,37 +3,35 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST(TestMultipleAlgoExecutions, SingleSequenceRecord) {
|
||||
TEST(TestMultipleAlgoExecutions, SingleSequenceRecord)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
std::string shader(
|
||||
"#version 450\n"
|
||||
"layout (local_size_x = 1) in;\n"
|
||||
"layout(set = 0, binding = 0) buffer a { float pa[]; };\n"
|
||||
"void main() {\n"
|
||||
" uint index = gl_GlobalInvocationID.x;\n"
|
||||
" pa[index] = pa[index] + 1;\n"
|
||||
"}\n"
|
||||
);
|
||||
"#version 450\n"
|
||||
"layout (local_size_x = 1) in;\n"
|
||||
"layout(set = 0, binding = 0) buffer a { float pa[]; };\n"
|
||||
"void main() {\n"
|
||||
" uint index = gl_GlobalInvocationID.x;\n"
|
||||
" pa[index] = pa[index] + 1;\n"
|
||||
"}\n");
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr = mgr.getOrCreateManagedSequence("newSequence");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorCreate>({ tensorA });
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({ tensorA });
|
||||
|
||||
|
|
@ -42,34 +40,34 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord) {
|
|||
}
|
||||
sqWeakPtr.reset();
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({3, 3, 3}));
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 3, 3, 3 }));
|
||||
}
|
||||
|
||||
TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords) {
|
||||
TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
std::string shader(
|
||||
"#version 450\n"
|
||||
"layout (local_size_x = 1) in;\n"
|
||||
"layout(set = 0, binding = 0) buffer a { float pa[]; };\n"
|
||||
"void main() {\n"
|
||||
" uint index = gl_GlobalInvocationID.x;\n"
|
||||
" pa[index] = pa[index] + 1;\n"
|
||||
"}\n"
|
||||
);
|
||||
"#version 450\n"
|
||||
"layout (local_size_x = 1) in;\n"
|
||||
"layout(set = 0, binding = 0) buffer a { float pa[]; };\n"
|
||||
"void main() {\n"
|
||||
" uint index = gl_GlobalInvocationID.x;\n"
|
||||
" pa[index] = pa[index] + 1;\n"
|
||||
"}\n");
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr = mgr.getOrCreateManagedSequence("newSequence");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorCreate>({ tensorA });
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
|
@ -77,8 +75,7 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords) {
|
|||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
|
@ -86,112 +83,109 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords) {
|
|||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>(
|
||||
{ tensorA });
|
||||
sq->record<kp::OpTensorSyncLocal>({ tensorA });
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
}
|
||||
sqWeakPtr.reset();
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({3, 3, 3}));
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 3, 3, 3 }));
|
||||
}
|
||||
|
||||
TEST(TestMultipleAlgoExecutions, MultipleSequences) {
|
||||
TEST(TestMultipleAlgoExecutions, MultipleSequences)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
std::string shader(
|
||||
"#version 450\n"
|
||||
"layout (local_size_x = 1) in;\n"
|
||||
"layout(set = 0, binding = 0) buffer a { float pa[]; };\n"
|
||||
"void main() {\n"
|
||||
" uint index = gl_GlobalInvocationID.x;\n"
|
||||
" pa[index] = pa[index] + 1;\n"
|
||||
"}\n"
|
||||
);
|
||||
"#version 450\n"
|
||||
"layout (local_size_x = 1) in;\n"
|
||||
"layout(set = 0, binding = 0) buffer a { float pa[]; };\n"
|
||||
"void main() {\n"
|
||||
" uint index = gl_GlobalInvocationID.x;\n"
|
||||
" pa[index] = pa[index] + 1;\n"
|
||||
"}\n");
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr = mgr.getOrCreateManagedSequence("newSequence");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorCreate>({ tensorA });
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
}
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr2 = mgr.getOrCreateManagedSequence("newSequence2");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr2 =
|
||||
mgr.getOrCreateManagedSequence("newSequence2");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr2.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
}
|
||||
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr3 = mgr.getOrCreateManagedSequence("newSequence3");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr3 =
|
||||
mgr.getOrCreateManagedSequence("newSequence3");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr3.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
}
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr4 = mgr.getOrCreateManagedSequence("newSequence5");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr4 =
|
||||
mgr.getOrCreateManagedSequence("newSequence5");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr4.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>(
|
||||
{ tensorA });
|
||||
sq->record<kp::OpTensorSyncLocal>({ tensorA });
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
}
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({3, 3, 3}));
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 3, 3, 3 }));
|
||||
}
|
||||
|
||||
TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval) {
|
||||
TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
std::string shader(
|
||||
"#version 450\n"
|
||||
"layout (local_size_x = 1) in;\n"
|
||||
"layout(set = 0, binding = 0) buffer a { float pa[]; };\n"
|
||||
"void main() {\n"
|
||||
" uint index = gl_GlobalInvocationID.x;\n"
|
||||
" pa[index] = pa[index] + 1;\n"
|
||||
"}\n"
|
||||
);
|
||||
"#version 450\n"
|
||||
"layout (local_size_x = 1) in;\n"
|
||||
"layout(set = 0, binding = 0) buffer a { float pa[]; };\n"
|
||||
"void main() {\n"
|
||||
" uint index = gl_GlobalInvocationID.x;\n"
|
||||
" pa[index] = pa[index] + 1;\n"
|
||||
"}\n");
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr = mgr.getOrCreateManagedSequence("newSequence");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
sq->begin();
|
||||
|
||||
|
|
@ -201,13 +195,13 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval) {
|
|||
sq->eval();
|
||||
}
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr2 = mgr.getOrCreateManagedSequence("newSequence2");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr2 =
|
||||
mgr.getOrCreateManagedSequence("newSequence2");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr2.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->end();
|
||||
|
||||
|
|
@ -216,12 +210,12 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval) {
|
|||
sq->eval();
|
||||
}
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr3 = mgr.getOrCreateManagedSequence("newSequence3");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr3 =
|
||||
mgr.getOrCreateManagedSequence("newSequence3");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr2.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>(
|
||||
{ tensorA });
|
||||
sq->record<kp::OpTensorSyncLocal>({ tensorA });
|
||||
|
||||
sq->end();
|
||||
|
||||
|
|
@ -230,6 +224,5 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval) {
|
|||
sq->eval();
|
||||
}
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({3, 3, 3}));
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 3, 3, 3 }));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,15 +3,18 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST(TestProcessingIterations, IterateThroughMultipleSumAndCopies) {
|
||||
TEST(TestProcessingIterations, IterateThroughMultipleSumAndCopies)
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
float TOTAL_ITER = 10;
|
||||
|
||||
std::vector<float> testExpectedOutVec = {TOTAL_ITER, TOTAL_ITER, TOTAL_ITER};
|
||||
std::vector<float> testExpectedOutVec = { TOTAL_ITER,
|
||||
TOTAL_ITER,
|
||||
TOTAL_ITER };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
std::string shader(R"(
|
||||
#version 450
|
||||
|
|
@ -27,11 +30,10 @@ TEST(TestProcessingIterations, IterateThroughMultipleSumAndCopies) {
|
|||
}
|
||||
)");
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("default");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("default");
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock())
|
||||
{
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
|
@ -41,18 +43,17 @@ TEST(TestProcessingIterations, IterateThroughMultipleSumAndCopies) {
|
|||
sq->eval();
|
||||
}
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr2 =
|
||||
mgr.getOrCreateManagedSequence("run");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr2 =
|
||||
mgr.getOrCreateManagedSequence("run");
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr2.lock())
|
||||
{
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr2.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<>>(
|
||||
{ tensorA, tensorB },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA, tensorB },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->record<kp::OpTensorCopy>({tensorB, tensorA});
|
||||
sq->record<kp::OpTensorCopy>({ tensorB, tensorA });
|
||||
sq->end();
|
||||
|
||||
for (size_t i = 0; i < TOTAL_ITER; i++) {
|
||||
|
|
@ -60,14 +61,13 @@ TEST(TestProcessingIterations, IterateThroughMultipleSumAndCopies) {
|
|||
}
|
||||
}
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr3 =
|
||||
mgr.getOrCreateManagedSequence("export");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr3 =
|
||||
mgr.getOrCreateManagedSequence("export");
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr3.lock())
|
||||
{
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr3.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({tensorA, tensorB});
|
||||
sq->record<kp::OpTensorSyncLocal>({ tensorA, tensorB });
|
||||
|
||||
sq->end();
|
||||
|
||||
|
|
@ -76,4 +76,3 @@ TEST(TestProcessingIterations, IterateThroughMultipleSumAndCopies) {
|
|||
|
||||
EXPECT_EQ(tensorA->data(), testExpectedOutVec);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,12 @@
|
|||
|
||||
#include "kompute_test/shaders/shadertest_op_custom_shader.hpp"
|
||||
|
||||
TEST(TestOpAlgoBase, ShaderRawDataFromConstructor) {
|
||||
TEST(TestOpAlgoBase, ShaderRawDataFromConstructor)
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
std::string shader(R"(
|
||||
|
|
@ -28,65 +29,66 @@ TEST(TestOpAlgoBase, ShaderRawDataFromConstructor) {
|
|||
)");
|
||||
|
||||
mgr.evalOpDefault<kp::OpAlgoBase<>>(
|
||||
{ tensorA, tensorB },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
{ tensorA, tensorB }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({0, 1, 2}));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({3, 4, 5}));
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 0, 1, 2 }));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({ 3, 4, 5 }));
|
||||
}
|
||||
|
||||
TEST(TestOpAlgoBase, ShaderCompiledDataFromConstructor) {
|
||||
TEST(TestOpAlgoBase, ShaderCompiledDataFromConstructor)
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
mgr.evalOpDefault<kp::OpAlgoBase<>>(
|
||||
{ tensorA, tensorB },
|
||||
std::vector<char>(
|
||||
kp::shader_data::test_shaders_glsl_test_op_custom_shader_comp_spv,
|
||||
kp::shader_data::test_shaders_glsl_test_op_custom_shader_comp_spv +
|
||||
kp::shader_data::test_shaders_glsl_test_op_custom_shader_comp_spv_len));
|
||||
{ tensorA, tensorB },
|
||||
std::vector<char>(
|
||||
kp::shader_data::test_shaders_glsl_test_op_custom_shader_comp_spv,
|
||||
kp::shader_data::test_shaders_glsl_test_op_custom_shader_comp_spv +
|
||||
kp::shader_data::
|
||||
test_shaders_glsl_test_op_custom_shader_comp_spv_len));
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({0, 1, 2}));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({3, 4, 5}));
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 0, 1, 2 }));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({ 3, 4, 5 }));
|
||||
}
|
||||
|
||||
TEST(TestOpAlgoBase, ShaderRawDataFromFile) {
|
||||
TEST(TestOpAlgoBase, ShaderRawDataFromFile)
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
mgr.evalOpDefault<kp::OpAlgoBase<>>(
|
||||
{ tensorA, tensorB },
|
||||
"test/shaders/glsl/test_op_custom_shader.comp");
|
||||
{ tensorA, tensorB }, "test/shaders/glsl/test_op_custom_shader.comp");
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({0, 1, 2}));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({3, 4, 5}));
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 0, 1, 2 }));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({ 3, 4, 5 }));
|
||||
}
|
||||
|
||||
TEST(TestOpAlgoBase, ShaderCompiledDataFromFile) {
|
||||
TEST(TestOpAlgoBase, ShaderCompiledDataFromFile)
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
mgr.evalOpDefault<kp::OpAlgoBase<>>(
|
||||
{ tensorA, tensorB },
|
||||
"test/shaders/glsl/test_op_custom_shader.comp.spv");
|
||||
{ tensorA, tensorB }, "test/shaders/glsl/test_op_custom_shader.comp.spv");
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({0, 1, 2}));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({3, 4, 5}));
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 0, 1, 2 }));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({ 3, 4, 5 }));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,31 +3,33 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor) {
|
||||
TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 0, 0, 0 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
|
||||
// Making sure the GPU holds the same data
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorB });
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
}
|
||||
|
||||
TEST(TestOpTensorCopy, CopyDeviceToDeviceTensorMulti) {
|
||||
TEST(TestOpTensorCopy, CopyDeviceToDeviceTensorMulti)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
|
|
@ -35,113 +37,120 @@ TEST(TestOpTensorCopy, CopyDeviceToDeviceTensorMulti) {
|
|||
std::vector<float> testVecB{ 0, 0, 0 };
|
||||
std::vector<float> testVecC{ 0, 0, 0 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
|
||||
std::shared_ptr<kp::Tensor> tensorC{new kp::Tensor(testVecC)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
|
||||
std::shared_ptr<kp::Tensor> tensorC{ new kp::Tensor(testVecC) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA, tensorB, tensorC});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB, tensorC });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
EXPECT_TRUE(tensorC->isInit());
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({tensorA, tensorB, tensorC});
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB, tensorC });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
EXPECT_EQ(tensorA->data(), tensorC->data());
|
||||
|
||||
// Making sure the GPU holds the same data
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorB, tensorC});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorB, tensorC });
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
EXPECT_EQ(tensorA->data(), tensorC->data());
|
||||
}
|
||||
|
||||
TEST(TestOpTensorCopy, CopyDeviceToStagingTensor) {
|
||||
TEST(TestOpTensorCopy, CopyDeviceToStagingTensor)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 0, 0, 0 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB, kp::Tensor::TensorTypes::eStaging)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(
|
||||
testVecB, kp::Tensor::TensorTypes::eStaging) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
|
||||
// Making sure the GPU holds the same data
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorB });
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
}
|
||||
|
||||
TEST(TestOpTensorCopy, CopyStagingToDeviceTensor) {
|
||||
TEST(TestOpTensorCopy, CopyStagingToDeviceTensor)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 0, 0, 0 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA, kp::Tensor::TensorTypes::eStaging)};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(
|
||||
testVecA, kp::Tensor::TensorTypes::eStaging) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
|
||||
// Making sure the GPU holds the same data
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorB });
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
}
|
||||
|
||||
TEST(TestOpTensorCopy, CopyStagingToStagingTensor) {
|
||||
TEST(TestOpTensorCopy, CopyStagingToStagingTensor)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 0, 0, 0 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA, kp::Tensor::TensorTypes::eStaging)};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB, kp::Tensor::TensorTypes::eStaging)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(
|
||||
testVecA, kp::Tensor::TensorTypes::eStaging) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(
|
||||
testVecB, kp::Tensor::TensorTypes::eStaging) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
|
||||
// Making sure the GPU holds the same data
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorB });
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
}
|
||||
|
||||
TEST(TestOpTensorCopy, SingleTensorShouldFail) {
|
||||
TEST(TestOpTensorCopy, SingleTensorShouldFail)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA, kp::Tensor::TensorTypes::eStaging)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(
|
||||
testVecA, kp::Tensor::TensorTypes::eStaging) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
|
||||
EXPECT_THROW(
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({tensorA}),
|
||||
std::runtime_error);
|
||||
EXPECT_THROW(mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA }),
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,15 +3,16 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST(TestOpTensorCreate, CreateSingleTensorSingleOp) {
|
||||
TEST(TestOpTensorCreate, CreateSingleTensorSingleOp)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
|
||||
|
|
@ -21,17 +22,18 @@ TEST(TestOpTensorCreate, CreateSingleTensorSingleOp) {
|
|||
EXPECT_FALSE(tensorA->isInit());
|
||||
}
|
||||
|
||||
TEST(TestOpTensorCreate, CreateMultipleTensorSingleOp) {
|
||||
TEST(TestOpTensorCreate, CreateMultipleTensorSingleOp)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 6, 5, 4 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA, tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
|
@ -40,18 +42,19 @@ TEST(TestOpTensorCreate, CreateMultipleTensorSingleOp) {
|
|||
EXPECT_EQ(tensorB->data(), testVecB);
|
||||
}
|
||||
|
||||
TEST(TestOpTensorCreate, CreateMultipleTensorMultipleOp) {
|
||||
TEST(TestOpTensorCreate, CreateMultipleTensorMultipleOp)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 6, 5, 4 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA });
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorB });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
|
@ -60,18 +63,19 @@ TEST(TestOpTensorCreate, CreateMultipleTensorMultipleOp) {
|
|||
EXPECT_EQ(tensorB->data(), testVecB);
|
||||
}
|
||||
|
||||
TEST(TestOpTensorCreate, ManageTensorMemoryWhenOpTensorCreateDestroyed) {
|
||||
TEST(TestOpTensorCreate, ManageTensorMemoryWhenOpTensorCreateDestroyed)
|
||||
{
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 6, 5, 4 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
|
||||
|
||||
{
|
||||
kp::Manager mgr;
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA });
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorB });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
|
@ -84,18 +88,19 @@ TEST(TestOpTensorCreate, ManageTensorMemoryWhenOpTensorCreateDestroyed) {
|
|||
EXPECT_FALSE(tensorB->isInit());
|
||||
}
|
||||
|
||||
TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore) {
|
||||
TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore)
|
||||
{
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 6, 5, 4 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorB});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA });
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorB });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
|
@ -108,4 +113,3 @@ TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore) {
|
|||
EXPECT_FALSE(tensorA->isInit());
|
||||
EXPECT_FALSE(tensorB->isInit());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,39 +3,41 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST(TestOpTensorSync, SyncToDeviceMemorySingleTensor) {
|
||||
TEST(TestOpTensorSync, SyncToDeviceMemorySingleTensor)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVecPreA{ 0, 0, 0 };
|
||||
std::vector<float> testVecPostA{ 9, 8, 7 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecPreA)};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecPreA) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
|
||||
tensorA->setData(testVecPostA);
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncDevice>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA });
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorA });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), testVecPostA);
|
||||
}
|
||||
|
||||
TEST(TestOpTensorSync, SyncToDeviceMemoryMultiTensor) {
|
||||
TEST(TestOpTensorSync, SyncToDeviceMemoryMultiTensor)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<float> testVec{ 9, 8, 7 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor({0, 0, 0})};
|
||||
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor({0, 0, 0})};
|
||||
std::shared_ptr<kp::Tensor> tensorC{new kp::Tensor({0, 0, 0})};
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorC{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA, tensorB, tensorC});
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB, tensorC });
|
||||
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
|
@ -43,15 +45,13 @@ TEST(TestOpTensorSync, SyncToDeviceMemoryMultiTensor) {
|
|||
|
||||
tensorA->setData(testVec);
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncDevice>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA });
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({tensorA, tensorB, tensorC});
|
||||
mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB, tensorC });
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorA, tensorB, tensorC});
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorA, tensorB, tensorC });
|
||||
|
||||
EXPECT_EQ(tensorA->data(), testVec);
|
||||
EXPECT_EQ(tensorB->data(), testVec);
|
||||
EXPECT_EQ(tensorC->data(), testVec);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST(TestSequence, CmdBufSequenceBeginEnd) {
|
||||
TEST(TestSequence, CmdBufSequenceBeginEnd)
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
EXPECT_TRUE(sq->eval());
|
||||
|
|
@ -23,4 +24,3 @@ TEST(TestSequence, CmdBufSequenceBeginEnd) {
|
|||
EXPECT_TRUE(sq->eval());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,34 +3,33 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST(TestTensor, ConstructorData) {
|
||||
std::vector<float> vec{0,1,2};
|
||||
TEST(TestTensor, ConstructorData)
|
||||
{
|
||||
std::vector<float> vec{ 0, 1, 2 };
|
||||
kp::Tensor tensor(vec);
|
||||
EXPECT_EQ( tensor.size(), vec.size() );
|
||||
EXPECT_EQ( tensor.data(), vec );
|
||||
EXPECT_EQ(tensor.size(), vec.size());
|
||||
EXPECT_EQ(tensor.data(), vec);
|
||||
}
|
||||
|
||||
TEST(TestTensor, CopyFromHostData) {
|
||||
std::vector<float> vecA{0,1,2};
|
||||
std::vector<float> vecB{0,0,0};
|
||||
TEST(TestTensor, CopyFromHostData)
|
||||
{
|
||||
std::vector<float> vecA{ 0, 1, 2 };
|
||||
std::vector<float> vecB{ 0, 0, 0 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA = std::make_shared<kp::Tensor>(
|
||||
vecA,
|
||||
kp::Tensor::TensorTypes::eStaging);
|
||||
std::shared_ptr<kp::Tensor> tensorB = std::make_shared<kp::Tensor>(
|
||||
vecB,
|
||||
kp::Tensor::TensorTypes::eStaging);
|
||||
std::shared_ptr<kp::Tensor> tensorA =
|
||||
std::make_shared<kp::Tensor>(vecA, kp::Tensor::TensorTypes::eStaging);
|
||||
std::shared_ptr<kp::Tensor> tensorB =
|
||||
std::make_shared<kp::Tensor>(vecB, kp::Tensor::TensorTypes::eStaging);
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
if(std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.getOrCreateManagedSequence("new").lock())
|
||||
{
|
||||
if (std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.getOrCreateManagedSequence("new").lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorCreate>({tensorA, tensorB});
|
||||
sq->record<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
sq->record<kp::OpTensorCopy>({tensorA, tensorB});
|
||||
sq->record<kp::OpTensorCopy>({ tensorA, tensorB });
|
||||
|
||||
sq->end();
|
||||
|
||||
|
|
@ -39,4 +38,3 @@ TEST(TestTensor, CopyFromHostData) {
|
|||
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue