mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Map/unmap enqueue fixes [2/n]: CPU operations on limited range
- Curently each non-zerocopy CPU operation on map/unmap make a full copy using hostPtr - This commit adds functionality to select specific range of copy - Multiple mapping with different size is not supported yet, so copy will be made on full range for now. This is for future usage. Change-Id: I7652e85482ba6fffb2474169447baf9b080dcd1e
This commit is contained in:

committed by
sys_ocldev

parent
ff44e9922d
commit
4f2a05ac88
@ -165,6 +165,30 @@ TEST_F(clCreateImageTest, NotNullHostPtrAndRowPitchIsNotMultipleOfElementSizeRet
|
||||
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
||||
}
|
||||
|
||||
TEST_F(clCreateImageTest, givenNullHostPtrWhenCopyHostPtrFlagPassedThenReturnError) {
|
||||
auto image = clCreateImage(
|
||||
pContext,
|
||||
CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
|
||||
&imageFormat,
|
||||
&imageDesc,
|
||||
nullptr,
|
||||
&retVal);
|
||||
ASSERT_EQ(CL_INVALID_HOST_PTR, retVal);
|
||||
EXPECT_EQ(nullptr, image);
|
||||
}
|
||||
|
||||
TEST_F(clCreateImageTest, givenNullHostPtrWhenUseHostPtrFlagPassedThenReturnError) {
|
||||
auto image = clCreateImage(
|
||||
pContext,
|
||||
CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
|
||||
&imageFormat,
|
||||
&imageDesc,
|
||||
nullptr,
|
||||
&retVal);
|
||||
ASSERT_EQ(CL_INVALID_HOST_PTR, retVal);
|
||||
EXPECT_EQ(nullptr, image);
|
||||
}
|
||||
|
||||
TEST_F(clCreateImageTest, NullHostPtrAndRowPitchIsNotZeroReturnsError) {
|
||||
imageDesc.image_row_pitch = 4;
|
||||
auto image = clCreateImage(
|
||||
|
@ -29,7 +29,7 @@ set(IGDRCL_SRCS_tests_mem_obj
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/destructor_callback_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/get_mem_object_info_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/get_mem_object_info_subbufer_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/image_copy_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/image_transfer_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/image_format_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/image_redescribe_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/image_release_mapped_ptr_tests.cpp"
|
||||
|
@ -856,3 +856,50 @@ HWTEST_F(BufferUnmapTest, givenBufferWithoutSharingHandlerWhenUnmappingThenDontU
|
||||
|
||||
EXPECT_EQ(0u, cmdQ.EnqueueWriteBufferCounter);
|
||||
}
|
||||
|
||||
using BufferTransferTests = BufferUnmapTest;
|
||||
|
||||
TEST_F(BufferTransferTests, givenBufferWhenTransferToHostPtrCalledThenCopyRequestedSizeAndOffsetOnly) {
|
||||
MockContext context(pDevice);
|
||||
auto retVal = CL_SUCCESS;
|
||||
const size_t bufferSize = 100;
|
||||
size_t copyOffset = 20;
|
||||
size_t copySize = 10;
|
||||
size_t ignoredParam = 123;
|
||||
|
||||
uint8_t hostPtr[bufferSize] = {};
|
||||
uint8_t expectedHostPtr[bufferSize] = {};
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(&context, CL_MEM_USE_HOST_PTR, bufferSize, hostPtr, retVal));
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
auto srcPtr = buffer->getCpuAddress();
|
||||
EXPECT_NE(srcPtr, hostPtr);
|
||||
memset(srcPtr, 123, bufferSize);
|
||||
memset(ptrOffset(expectedHostPtr, copyOffset), 123, copySize);
|
||||
|
||||
buffer->transferDataToHostPtr({{copySize, ignoredParam, ignoredParam}}, {{copyOffset, ignoredParam, ignoredParam}});
|
||||
|
||||
EXPECT_TRUE(memcmp(hostPtr, expectedHostPtr, copySize) == 0);
|
||||
}
|
||||
|
||||
TEST_F(BufferTransferTests, givenBufferWhenTransferFromHostPtrCalledThenCopyRequestedSizeAndOffsetOnly) {
|
||||
MockContext context(pDevice);
|
||||
auto retVal = CL_SUCCESS;
|
||||
const size_t bufferSize = 100;
|
||||
size_t copyOffset = 20;
|
||||
size_t copySize = 10;
|
||||
size_t ignoredParam = 123;
|
||||
|
||||
uint8_t hostPtr[bufferSize] = {};
|
||||
uint8_t expectedBufferMemory[bufferSize] = {};
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(&context, CL_MEM_USE_HOST_PTR, bufferSize, hostPtr, retVal));
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_NE(buffer->getCpuAddress(), hostPtr);
|
||||
memset(hostPtr, 123, bufferSize);
|
||||
memset(ptrOffset(expectedBufferMemory, copyOffset), 123, copySize);
|
||||
|
||||
buffer->transferDataFromHostPtr({{copySize, ignoredParam, ignoredParam}}, {{copyOffset, ignoredParam, ignoredParam}});
|
||||
|
||||
EXPECT_TRUE(memcmp(expectedBufferMemory, buffer->getCpuAddress(), copySize) == 0);
|
||||
}
|
||||
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "runtime/mem_obj/image.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
const char valueOfEmptyPixel = 0;
|
||||
const char valueOfCopiedPixel = 1;
|
||||
const char garbageValue = 2;
|
||||
|
||||
const int imageCount = 2;
|
||||
const int imageDimension = 25;
|
||||
auto const elementSize = 4;
|
||||
|
||||
class CopyImageTest : public testing::WithParamInterface<std::tuple<size_t, size_t> /*srcPitch, destPitch*/>,
|
||||
public testing::Test {
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
std::tie(srcRowPitch, destRowPitch) = GetParam();
|
||||
// clang-format off
|
||||
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
imageDesc.image_width = imageDimension;
|
||||
imageDesc.image_height = imageDimension;
|
||||
imageDesc.image_depth = 0;
|
||||
imageDesc.image_array_size = imageCount;
|
||||
imageDesc.image_row_pitch = 0;
|
||||
imageDesc.image_slice_pitch = 0;
|
||||
imageDesc.num_mip_levels = 0;
|
||||
imageDesc.num_samples = 0;
|
||||
imageDesc.mem_object = NULL;
|
||||
// clang-format on
|
||||
lineWidth = imageDesc.image_width * elementSize;
|
||||
srcSlicePitch = srcRowPitch * imageDimension;
|
||||
destSlicePitch = destRowPitch * imageDimension;
|
||||
srcPtrSize = srcSlicePitch * imageCount;
|
||||
destPtrSize = destSlicePitch * imageCount;
|
||||
srcPtr.reset(new char[srcPtrSize]);
|
||||
destPtr.reset(new char[destPtrSize * 2]);
|
||||
}
|
||||
|
||||
cl_image_desc imageDesc;
|
||||
size_t srcRowPitch;
|
||||
size_t srcSlicePitch;
|
||||
size_t destRowPitch;
|
||||
size_t destSlicePitch;
|
||||
size_t srcPtrSize;
|
||||
size_t destPtrSize;
|
||||
size_t lineWidth;
|
||||
std::unique_ptr<char> srcPtr;
|
||||
std::unique_ptr<char> destPtr;
|
||||
};
|
||||
|
||||
TEST_P(CopyImageTest, givenSrcAndDestPitchesWhenTransferDataIsCalledThenSpecificValuesAreCopied) {
|
||||
memset(destPtr.get(), valueOfEmptyPixel, 2 * destPtrSize);
|
||||
memset(srcPtr.get(), garbageValue, srcPtrSize);
|
||||
for (size_t i = 0; i < imageCount; ++i) {
|
||||
for (size_t j = 0; j < imageDimension; ++j) {
|
||||
memset(srcPtr.get() + i * srcSlicePitch + j * srcRowPitch, valueOfCopiedPixel, lineWidth);
|
||||
}
|
||||
}
|
||||
Image::transferData(srcPtr.get(), srcRowPitch, srcSlicePitch, destPtr.get(), destRowPitch, destSlicePitch, &imageDesc, elementSize, imageCount);
|
||||
size_t unconfirmedCopies = 0;
|
||||
//expect no garbage copied
|
||||
for (size_t i = 0; i < 2 * destPtrSize; ++i) {
|
||||
if (destPtr.get()[i] == valueOfCopiedPixel) {
|
||||
unconfirmedCopies++;
|
||||
}
|
||||
EXPECT_NE(garbageValue, destPtr.get()[i]);
|
||||
}
|
||||
//expect copied to right locations
|
||||
for (size_t i = 0; i < imageCount; ++i) {
|
||||
for (size_t j = 0; j < imageDimension; ++j) {
|
||||
for (size_t k = 0; k < lineWidth; ++k) {
|
||||
EXPECT_EQ(valueOfCopiedPixel, destPtr.get()[i * destSlicePitch + j * destRowPitch + k]);
|
||||
unconfirmedCopies--;
|
||||
}
|
||||
}
|
||||
}
|
||||
//expect copied only to destPtr
|
||||
for (size_t i = 0; i < destPtrSize; ++i) {
|
||||
EXPECT_EQ(valueOfEmptyPixel, destPtr.get()[destPtrSize + i]);
|
||||
}
|
||||
EXPECT_EQ(0u, unconfirmedCopies);
|
||||
}
|
||||
size_t valuesOfPitchesInCopyTests[] = {100, 101, 102};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
CopyImageTests,
|
||||
CopyImageTest,
|
||||
testing::Combine(
|
||||
testing::ValuesIn(valuesOfPitchesInCopyTests),
|
||||
testing::ValuesIn(valuesOfPitchesInCopyTests)));
|
@ -472,22 +472,6 @@ TEST_P(CreateImageNoHostPtr, completionStamp) {
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_P(CreateImageNoHostPtr, withUseHostPtrReturnsError) {
|
||||
auto image = createImageWithFlags(flags | CL_MEM_USE_HOST_PTR);
|
||||
|
||||
EXPECT_EQ(CL_INVALID_HOST_PTR, retVal);
|
||||
EXPECT_EQ(nullptr, image);
|
||||
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_P(CreateImageNoHostPtr, withCopyHostPtrReturnsError) {
|
||||
auto image = createImageWithFlags(flags | CL_MEM_COPY_HOST_PTR);
|
||||
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
EXPECT_EQ(nullptr, image);
|
||||
}
|
||||
|
||||
TEST_P(CreateImageNoHostPtr, withImageGraphicsAllocationReportsImageType) {
|
||||
auto image = createImageWithFlags(flags);
|
||||
|
||||
@ -785,7 +769,9 @@ TEST_F(ImageTransfer, GivenNonZeroCopyImageWhenDataTransferedFromHostPtrToMemSto
|
||||
memset(memoryStorage, 0, memoryStorageSize);
|
||||
memset((char *)unalignedHostPtr + imageSize, 2, 100 - 4);
|
||||
|
||||
imageNonZeroCopy->transferDataFromHostPtrToMemoryStorage();
|
||||
auto &imgDesc = imageNonZeroCopy->getImageDesc();
|
||||
imageNonZeroCopy->transferDataFromHostPtr({{imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth}},
|
||||
{{0, 0, 0}});
|
||||
|
||||
void *foundData = memchr(memoryStorage, 2, memoryStorageSize);
|
||||
EXPECT_EQ(0, foundData);
|
||||
@ -818,7 +804,9 @@ TEST_F(ImageTransfer, GivenNonZeroCopyNonZeroRowPitchImageWhenDataIsTransferedFr
|
||||
memset(memoryStorage, 0, memoryStorageSize);
|
||||
memset((char *)unalignedHostPtr + imageSize, 2, 100 - 4);
|
||||
|
||||
imageNonZeroCopy->transferDataFromHostPtrToMemoryStorage();
|
||||
auto &imgDesc = imageNonZeroCopy->getImageDesc();
|
||||
imageNonZeroCopy->transferDataFromHostPtr({{imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth}},
|
||||
{{0, 0, 0}});
|
||||
|
||||
void *foundData = memchr(memoryStorage, 2, memoryStorageSize);
|
||||
EXPECT_EQ(0, foundData);
|
||||
@ -874,7 +862,9 @@ TEST_F(ImageTransfer, GivenNonZeroCopyNonZeroRowPitchWithExtraBytes1DArrayImageW
|
||||
unsigned char *internalRow = static_cast<unsigned char *>(memoryStorage);
|
||||
|
||||
if (run == 1) {
|
||||
imageNonZeroCopy->transferDataFromHostPtrToMemoryStorage();
|
||||
auto &imgDesc = imageNonZeroCopy->getImageDesc();
|
||||
imageNonZeroCopy->transferDataFromHostPtr({{imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth}},
|
||||
{{0, 0, 0}});
|
||||
}
|
||||
|
||||
for (size_t arrayIndex = 0; arrayIndex < imageCount; ++arrayIndex) {
|
||||
@ -893,7 +883,9 @@ TEST_F(ImageTransfer, GivenNonZeroCopyNonZeroRowPitchWithExtraBytes1DArrayImageW
|
||||
}
|
||||
}
|
||||
|
||||
imageNonZeroCopy->transferDataToHostPtr();
|
||||
auto &imgDesc = imageNonZeroCopy->getImageDesc();
|
||||
imageNonZeroCopy->transferDataToHostPtr({{imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth}},
|
||||
{{0, 0, 0}});
|
||||
|
||||
row = static_cast<uint32_t *>(unalignedHostPtr);
|
||||
|
||||
|
144
unit_tests/mem_obj/image_transfer_tests.cpp
Normal file
144
unit_tests/mem_obj/image_transfer_tests.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "unit_tests/fixtures/image_fixture.h"
|
||||
#include "unit_tests/mocks/mock_device.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
class ImageHostPtrTransferTests : public testing::Test {
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
device.reset(Device::create<MockDevice>(*platformDevices));
|
||||
context.reset(new MockContext(device.get()));
|
||||
}
|
||||
|
||||
template <typename ImageTraits>
|
||||
void createImageAndSetTestParams() {
|
||||
image.reset(ImageHelper<ImageUseHostPtr<ImageTraits>>::create(context.get()));
|
||||
|
||||
imgDesc = &image->getImageDesc();
|
||||
copyOrigin = {{imgDesc->image_width / 2, imgDesc->image_height / 2, imgDesc->image_depth / 2}};
|
||||
copyRegion = copyOrigin;
|
||||
|
||||
hostPtrSlicePitch = image->getHostPtrSlicePitch();
|
||||
hostPtrRowPitch = image->getHostPtrRowPitch();
|
||||
imageSlicePitch = image->getImageDesc().image_slice_pitch;
|
||||
imageRowPitch = image->getImageDesc().image_row_pitch;
|
||||
pixelSize = image->getSurfaceFormatInfo().ImageElementSizeInBytes;
|
||||
}
|
||||
|
||||
void setExpectedData(uint8_t *dstPtr, size_t slicePitch, size_t rowPitch) {
|
||||
for (size_t slice = copyOrigin[2]; slice < (copyOrigin[2] + copyRegion[2]); slice++) {
|
||||
auto sliceOffset = ptrOffset(dstPtr, slicePitch * slice);
|
||||
for (size_t height = copyOrigin[1]; height < (copyOrigin[1] + copyRegion[1]); height++) {
|
||||
auto rowOffset = ptrOffset(sliceOffset, rowPitch * height);
|
||||
memset(ptrOffset(rowOffset, copyOrigin[0] * pixelSize), 123, copyRegion[0] * pixelSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<MockDevice> device;
|
||||
std::unique_ptr<MockContext> context;
|
||||
std::unique_ptr<Image> image;
|
||||
|
||||
std::array<size_t, 3> copyRegion;
|
||||
std::array<size_t, 3> copyOrigin;
|
||||
|
||||
const cl_image_desc *imgDesc = nullptr;
|
||||
size_t hostPtrSlicePitch, hostPtrRowPitch, imageSlicePitch, imageRowPitch, pixelSize;
|
||||
};
|
||||
|
||||
TEST_F(ImageHostPtrTransferTests, given3dImageWhenTransferToHostPtrCalledThenCopyRequestedRegionAndOriginOnly) {
|
||||
createImageAndSetTestParams<Image3dDefaults>();
|
||||
EXPECT_NE(hostPtrSlicePitch, imageSlicePitch);
|
||||
EXPECT_NE(hostPtrRowPitch, imageRowPitch);
|
||||
EXPECT_NE(image->getCpuAddress(), image->getHostPtr());
|
||||
|
||||
std::unique_ptr<uint8_t> expectedHostPtr(new uint8_t[hostPtrSlicePitch * imgDesc->image_depth]);
|
||||
memset(image->getHostPtr(), 0, hostPtrSlicePitch * imgDesc->image_depth);
|
||||
memset(expectedHostPtr.get(), 0, hostPtrSlicePitch * imgDesc->image_depth);
|
||||
memset(image->getCpuAddress(), 123, imageSlicePitch * imgDesc->image_depth);
|
||||
|
||||
setExpectedData(expectedHostPtr.get(), hostPtrSlicePitch, hostPtrRowPitch);
|
||||
|
||||
image->transferDataToHostPtr(copyRegion, copyOrigin);
|
||||
|
||||
EXPECT_TRUE(memcmp(image->getHostPtr(), expectedHostPtr.get(), hostPtrSlicePitch * imgDesc->image_depth) == 0);
|
||||
}
|
||||
|
||||
TEST_F(ImageHostPtrTransferTests, given3dImageWhenTransferFromHostPtrCalledThenCopyRequestedRegionAndOriginOnly) {
|
||||
createImageAndSetTestParams<Image3dDefaults>();
|
||||
EXPECT_NE(hostPtrSlicePitch, imageSlicePitch);
|
||||
EXPECT_NE(hostPtrRowPitch, imageRowPitch);
|
||||
EXPECT_NE(image->getCpuAddress(), image->getHostPtr());
|
||||
|
||||
std::unique_ptr<uint8_t> expectedImageData(new uint8_t[imageSlicePitch * imgDesc->image_depth]);
|
||||
memset(image->getHostPtr(), 123, hostPtrSlicePitch * imgDesc->image_depth);
|
||||
memset(expectedImageData.get(), 0, imageSlicePitch * imgDesc->image_depth);
|
||||
memset(image->getCpuAddress(), 0, imageSlicePitch * imgDesc->image_depth);
|
||||
|
||||
setExpectedData(expectedImageData.get(), imageSlicePitch, imageRowPitch);
|
||||
|
||||
image->transferDataFromHostPtr(copyRegion, copyOrigin);
|
||||
|
||||
EXPECT_TRUE(memcmp(image->getCpuAddress(), expectedImageData.get(), imageSlicePitch * imgDesc->image_depth) == 0);
|
||||
}
|
||||
|
||||
TEST_F(ImageHostPtrTransferTests, given2dArrayImageWhenTransferToHostPtrCalledThenCopyRequestedRegionAndOriginOnly) {
|
||||
createImageAndSetTestParams<Image2dArrayDefaults>();
|
||||
EXPECT_NE(hostPtrSlicePitch, imageSlicePitch);
|
||||
EXPECT_NE(hostPtrRowPitch, imageRowPitch);
|
||||
EXPECT_NE(image->getCpuAddress(), image->getHostPtr());
|
||||
|
||||
std::unique_ptr<uint8_t> expectedHostPtr(new uint8_t[hostPtrSlicePitch * imgDesc->image_depth]);
|
||||
memset(image->getHostPtr(), 0, hostPtrSlicePitch * imgDesc->image_depth);
|
||||
memset(expectedHostPtr.get(), 0, hostPtrSlicePitch * imgDesc->image_depth);
|
||||
memset(image->getCpuAddress(), 123, imageSlicePitch * imgDesc->image_depth);
|
||||
|
||||
setExpectedData(expectedHostPtr.get(), hostPtrSlicePitch, hostPtrRowPitch);
|
||||
|
||||
image->transferDataToHostPtr(copyRegion, copyOrigin);
|
||||
|
||||
EXPECT_TRUE(memcmp(image->getHostPtr(), expectedHostPtr.get(), hostPtrSlicePitch * imgDesc->image_depth) == 0);
|
||||
}
|
||||
|
||||
TEST_F(ImageHostPtrTransferTests, given2dArrayImageWhenTransferFromHostPtrCalledThenCopyRequestedRegionAndOriginOnly) {
|
||||
createImageAndSetTestParams<Image2dArrayDefaults>();
|
||||
EXPECT_NE(hostPtrSlicePitch, imageSlicePitch);
|
||||
EXPECT_NE(hostPtrRowPitch, imageRowPitch);
|
||||
EXPECT_NE(image->getCpuAddress(), image->getHostPtr());
|
||||
|
||||
std::unique_ptr<uint8_t> expectedImageData(new uint8_t[imageSlicePitch * imgDesc->image_depth]);
|
||||
memset(image->getHostPtr(), 123, hostPtrSlicePitch * imgDesc->image_depth);
|
||||
memset(expectedImageData.get(), 0, imageSlicePitch * imgDesc->image_depth);
|
||||
memset(image->getCpuAddress(), 0, imageSlicePitch * imgDesc->image_depth);
|
||||
|
||||
setExpectedData(expectedImageData.get(), imageSlicePitch, imageRowPitch);
|
||||
|
||||
image->transferDataFromHostPtr(copyRegion, copyOrigin);
|
||||
|
||||
EXPECT_TRUE(memcmp(image->getCpuAddress(), expectedImageData.get(), imageSlicePitch * imgDesc->image_depth) == 0);
|
||||
}
|
@ -63,15 +63,38 @@ TEST(MemObj, GivenMemObjWhenInititalizedFromHostPtrThenInitializeFields) {
|
||||
EXPECT_EQ(0u, memObj.getMappedOffset());
|
||||
}
|
||||
|
||||
TEST(MemObj, GivenMemObjectWhenAskedForTransferDataThenNullPtrIsReturned) {
|
||||
char buffer[64];
|
||||
TEST(MemObj, givenMemObjectWhenAskedForTransferToHostPtrThenDoNothing) {
|
||||
const size_t size = 64;
|
||||
uint8_t hostPtr[size] = {};
|
||||
uint8_t expectedHostPtr[size] = {};
|
||||
MockContext context;
|
||||
MockGraphicsAllocation *mockAllocation = new MockGraphicsAllocation(buffer, sizeof(buffer));
|
||||
MockGraphicsAllocation *mockAllocation = new MockGraphicsAllocation(hostPtr, sizeof(hostPtr));
|
||||
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_USE_HOST_PTR,
|
||||
sizeof(buffer), buffer, buffer, mockAllocation, true, false, false);
|
||||
size, hostPtr, hostPtr, mockAllocation, true, false, false);
|
||||
|
||||
auto ptr = memObj.transferDataToHostPtr();
|
||||
EXPECT_EQ(nullptr, ptr);
|
||||
memset(memObj.getCpuAddress(), 123, size);
|
||||
memset(hostPtr, 0, size);
|
||||
|
||||
EXPECT_THROW(memObj.transferDataToHostPtr({{size, 0, 0}}, {{0, 0, 0}}), std::exception);
|
||||
|
||||
EXPECT_TRUE(memcmp(hostPtr, expectedHostPtr, size) == 0);
|
||||
}
|
||||
|
||||
TEST(MemObj, givenMemObjectWhenAskedForTransferFromHostPtrThenDoNothing) {
|
||||
const size_t size = 64;
|
||||
uint8_t hostPtr[size] = {};
|
||||
uint8_t expectedBufferPtr[size] = {};
|
||||
MockContext context;
|
||||
MockGraphicsAllocation *mockAllocation = new MockGraphicsAllocation(hostPtr, sizeof(hostPtr));
|
||||
MemObj memObj(&context, CL_MEM_OBJECT_PIPE, CL_MEM_USE_HOST_PTR,
|
||||
size, hostPtr, hostPtr, mockAllocation, true, false, false);
|
||||
|
||||
memset(memObj.getCpuAddress(), 123, size);
|
||||
memset(expectedBufferPtr, 123, size);
|
||||
|
||||
EXPECT_THROW(memObj.transferDataFromHostPtr({{size, 0, 0}}, {{0, 0, 0}}), std::exception);
|
||||
|
||||
EXPECT_TRUE(memcmp(memObj.getCpuAddress(), expectedBufferPtr, size) == 0);
|
||||
}
|
||||
|
||||
TEST(MemObj, givenMemObjWhenAllocatedMappedPtrIsSetThenGetMappedPtrIsDifferentThanAllocatedMappedPtr) {
|
||||
|
@ -67,6 +67,9 @@ void MockGmmResourceInfo::setupDefaultActions() {
|
||||
reqOffsetInfo.Render.XOffset = 32;
|
||||
reqOffsetInfo.Render.Offset = 64;
|
||||
}
|
||||
if (reqOffsetInfo.Slice == 1) {
|
||||
reqOffsetInfo.Render.YOffset = mockResourceCreateParams.BaseHeight;
|
||||
}
|
||||
|
||||
return GMM_SUCCESS;
|
||||
}));
|
||||
|
Reference in New Issue
Block a user