Skip to content

Commit

Permalink
Add a check that the image sizes match when copying images
Browse files Browse the repository at this point in the history
Add a supporting test and remove an incorrect TODO.
(Size checking for copying from Tensor to Tensor, Tensor to Image and
Image to Tensor is covered by the total size check in
Memory::recordCopyFrom.

Signed-off-by: Robert Quill <[email protected]>
  • Loading branch information
robquill committed Aug 27, 2024
1 parent 97da31f commit b085445
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ Image::recordCopyFrom(const vk::CommandBuffer& commandBuffer,
layer.layerCount = 1;
vk::Offset3D offset = { 0, 0, 0 };

// FIXME: Check the size of the dest and source images match
if (this->getWidth() != copyFromImage->getWidth() ||
this->getHeight() != copyFromImage->getHeight())
{
throw std::runtime_error("Kompute Image recordCopyFrom image sizes do not match");
}

vk::Extent3D size = { this->mWidth, this->mHeight, 1 };

vk::ImageCopy copyRegion(layer, offset, layer, offset, size);
Expand Down Expand Up @@ -133,7 +138,6 @@ Image::recordCopyFrom(const vk::CommandBuffer& commandBuffer,
layer.layerCount = 1;
vk::Offset3D offset = { 0, 0, 0 };

// FIXME: Check the size of the dest and source images match
vk::Extent3D size = { this->mWidth, this->mHeight, 1 };

vk::BufferImageCopy copyRegion(0, 0, 0, layer, offset, size);
Expand Down
1 change: 0 additions & 1 deletion src/Tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ Tensor::recordCopyFrom(const vk::CommandBuffer& commandBuffer,
layer.layerCount = 1;
vk::Offset3D offset = { 0, 0, 0 };

// FIXME: Check the size of the dest and source images match
vk::Extent3D size = { copyFromImage->getWidth(),
copyFromImage->getHeight(),
1 };
Expand Down
21 changes: 21 additions & 0 deletions test/TestOpCopyImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,24 @@ TEST(TestOpCopyImage, CopyImageThroughStorageViaAlgorithmsUninitialisedOutput)
// Making sure the GPU holds the same vector
EXPECT_EQ(ImageIn->vector(), ImageOut->vector());
}

TEST(TestOpCopyImage, CopyDeviceToDeviceImage2DMismatchedSizes)
{
kp::Manager mgr;

std::vector<float> testVecA;
std::vector<float> testVecB;

for (int i = 0; i < 256; i++) {
testVecA.push_back(i);
testVecB.push_back(0);
}

std::shared_ptr<kp::ImageT<float>> imageA = mgr.image(testVecA, 16, 1, 1);
std::shared_ptr<kp::ImageT<float>> imageB = mgr.image(testVecB, 1, 16, 1);

EXPECT_TRUE(imageA->isInit());
EXPECT_TRUE(imageB->isInit());

EXPECT_THROW(mgr.sequence()->eval<kp::OpCopy>({ imageA, imageB }), std::runtime_error);
}

0 comments on commit b085445

Please sign in to comment.