Merge pull request #129 from alexander-g/no_zero_size_tensors
Disallowing zero sized tensors
This commit is contained in:
commit
4b8c1c49f0
3 changed files with 24 additions and 2 deletions
|
|
@ -268,10 +268,14 @@ Tensor::createBuffer()
|
|||
throw std::runtime_error("Kompute Tensor device is null");
|
||||
}
|
||||
|
||||
this->mFreeBuffer = true;
|
||||
|
||||
vk::BufferUsageFlags usageFlags = this->getBufferUsageFlags();
|
||||
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 "
|
||||
"usage flags: {}",
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Tensor
|
|||
* Default constructor with data provided which would be used to create the
|
||||
* respective vulkan buffer and memory.
|
||||
*
|
||||
* @param data Vector of data that will be used by the tensor
|
||||
* @param data Non-zero-sized vector of data that will be used by the tensor
|
||||
* @param tensorType Type for the tensor which is of type TensorTypes
|
||||
*/
|
||||
Tensor(const std::vector<float>& data,
|
||||
|
|
|
|||
|
|
@ -113,3 +113,21 @@ TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore)
|
|||
EXPECT_FALSE(tensorA->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_TRUE( std::string(err.what()).find("zero-sized") != std::string::npos );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue