disallowing zero sized tensors
This commit is contained in:
parent
acc3e96227
commit
a995cbf9ec
2 changed files with 23 additions and 1 deletions
|
|
@ -268,10 +268,14 @@ Tensor::createBuffer()
|
||||||
throw std::runtime_error("Kompute Tensor device is null");
|
throw std::runtime_error("Kompute Tensor device is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->mFreeBuffer = true;
|
|
||||||
|
|
||||||
vk::BufferUsageFlags usageFlags = this->getBufferUsageFlags();
|
vk::BufferUsageFlags usageFlags = this->getBufferUsageFlags();
|
||||||
vk::DeviceSize bufferSize = this->memorySize();
|
vk::DeviceSize bufferSize = this->memorySize();
|
||||||
|
if(bufferSize<1){
|
||||||
|
throw std::runtime_error("Kompute Tensor attempted to create a zero-sized buffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
this->mFreeBuffer = true;
|
||||||
|
|
||||||
SPDLOG_DEBUG("Kompute Tensor creating buffer with memory size: {}, and "
|
SPDLOG_DEBUG("Kompute Tensor creating buffer with memory size: {}, and "
|
||||||
"usage flags: {}",
|
"usage flags: {}",
|
||||||
|
|
|
||||||
|
|
@ -113,3 +113,21 @@ TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore)
|
||||||
EXPECT_FALSE(tensorA->isInit());
|
EXPECT_FALSE(tensorA->isInit());
|
||||||
EXPECT_FALSE(tensorB->isInit());
|
EXPECT_FALSE(tensorB->isInit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(TestOpTensorCreate, ExceptionOnZeroSizeTensor)
|
||||||
|
{
|
||||||
|
std::vector<float> testVecA;
|
||||||
|
|
||||||
|
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
|
||||||
|
|
||||||
|
kp::Manager mgr;
|
||||||
|
|
||||||
|
try{
|
||||||
|
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA });
|
||||||
|
} catch( const std::runtime_error& err ) {
|
||||||
|
// check exception
|
||||||
|
ASSERT_STREQ("Kompute Tensor attempted to create a zero-sized buffer", err.what() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue