mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 21:09:46 +08:00
Correct aub tests for image enqueue operations 3/n
Signed-off-by: Rafal Maziejuk <rafal.maziejuk@intel.com> Related-To: NEO-6135
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
85de06649d
commit
7931fb8f9a
@@ -72,19 +72,19 @@ HWTEST_P(AUBReadImage, GivenUnalignedMemoryWhenReadingImageThenExpectationsAreMe
|
||||
cl_image_format imageFormat;
|
||||
cl_image_desc imageDesc;
|
||||
// clang-format off
|
||||
imageFormat.image_channel_data_type = std::get<0>(GetParam());
|
||||
imageFormat.image_channel_order = std::get<1>(GetParam());
|
||||
imageFormat.image_channel_data_type = std::get<0>(GetParam());
|
||||
imageFormat.image_channel_order = std::get<1>(GetParam());
|
||||
|
||||
imageDesc.image_type = std::get<2>(GetParam()).imageType;
|
||||
imageDesc.image_width = testWidth;
|
||||
imageDesc.image_height = testHeight;
|
||||
imageDesc.image_depth = testDepth;
|
||||
imageDesc.image_array_size = 1;
|
||||
imageDesc.image_row_pitch = 0;
|
||||
imageDesc.image_slice_pitch = 0;
|
||||
imageDesc.num_mip_levels = 0;
|
||||
imageDesc.num_samples = 0;
|
||||
imageDesc.mem_object = NULL;
|
||||
imageDesc.image_type = std::get<2>(GetParam()).imageType;
|
||||
imageDesc.image_width = testWidth;
|
||||
imageDesc.image_height = testHeight;
|
||||
imageDesc.image_depth = testDepth;
|
||||
imageDesc.image_array_size = 1;
|
||||
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
|
||||
|
||||
auto perChannelDataSize = 0u;
|
||||
@@ -223,7 +223,7 @@ using AUBReadImageUnaligned = AUBImageUnaligned;
|
||||
|
||||
HWTEST_F(AUBReadImageUnaligned, GivenMisalignedHostPtrWhenReadingImageThenExpectationsAreMet) {
|
||||
const std::vector<size_t> pixelSizes = {1, 2, 4};
|
||||
const std::vector<size_t> offsets = {0, 1, 2, 3};
|
||||
const std::vector<size_t> offsets = {0, 4, 8, 12};
|
||||
const std::vector<size_t> sizes = {3, 2, 1};
|
||||
|
||||
for (auto pixelSize : pixelSizes) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2021 Intel Corporation
|
||||
* Copyright (C) 2019-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -35,20 +35,13 @@ struct AUBImageUnaligned
|
||||
void testReadImageUnaligned(size_t offset, size_t size, size_t pixelSize) {
|
||||
MockContext context(pCmdQ->getDevice().getSpecializedDevice<ClDevice>());
|
||||
|
||||
char srcMemory[] = "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnoprstuwxyz";
|
||||
const auto bufferSize = sizeof(srcMemory) - 1;
|
||||
char *imageMemory = &srcMemory[1]; //ensure non cacheline-aligned hostPtr to create non-zerocopy image
|
||||
void *dstMemory = alignedMalloc(bufferSize, MemoryConstants::pageSize);
|
||||
memset(dstMemory, 0, bufferSize);
|
||||
char referenceMemory[bufferSize] = {0};
|
||||
|
||||
const size_t testWidth = bufferSize / 4 / pixelSize;
|
||||
const size_t testWidth = 14 / pixelSize;
|
||||
const size_t testHeight = 4;
|
||||
const size_t testDepth = 1;
|
||||
auto numPixels = testWidth * testHeight * testDepth;
|
||||
|
||||
cl_image_format imageFormat;
|
||||
cl_image_desc imageDesc;
|
||||
|
||||
imageFormat.image_channel_data_type = CL_UNSIGNED_INT8;
|
||||
switch (pixelSize) {
|
||||
case 1:
|
||||
@@ -64,7 +57,6 @@ struct AUBImageUnaligned
|
||||
imageFormat.image_channel_order = CL_RGBA;
|
||||
break;
|
||||
}
|
||||
|
||||
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
imageDesc.image_width = testWidth;
|
||||
imageDesc.image_height = testHeight;
|
||||
@@ -76,11 +68,18 @@ struct AUBImageUnaligned
|
||||
imageDesc.num_samples = 0;
|
||||
imageDesc.mem_object = NULL;
|
||||
|
||||
cl_mem_flags flags = CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE;
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(
|
||||
flags, &imageFormat, pClDevice->getHardwareInfo().capabilityTable.supportsOcl21Features);
|
||||
auto retVal = CL_INVALID_VALUE;
|
||||
auto dstMemoryAligned = alignedMalloc(pixelSize * numPixels, MemoryConstants::cacheLineSize);
|
||||
memset(dstMemoryAligned, 0x0, pixelSize * numPixels);
|
||||
|
||||
auto srcMemoryAligned = alignedMalloc(4 + pixelSize * numPixels, 4);
|
||||
auto srcMemoryUnaligned = reinterpret_cast<uint8_t *>(ptrOffset(srcMemoryAligned, 4));
|
||||
for (auto i = 0u; i < pixelSize * numPixels; ++i) {
|
||||
srcMemoryUnaligned[i] = static_cast<uint8_t>(i);
|
||||
}
|
||||
|
||||
cl_mem_flags flags = CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE;
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, pClDevice->getHardwareInfo().capabilityTable.supportsOcl21Features);
|
||||
auto retVal = CL_INVALID_VALUE;
|
||||
auto image = std::unique_ptr<Image>(Image::create(
|
||||
&context,
|
||||
ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),
|
||||
@@ -88,20 +87,18 @@ struct AUBImageUnaligned
|
||||
0,
|
||||
surfaceFormat,
|
||||
&imageDesc,
|
||||
imageMemory,
|
||||
srcMemoryUnaligned,
|
||||
retVal));
|
||||
ASSERT_NE(nullptr, image);
|
||||
EXPECT_FALSE(image->isMemObjZeroCopy());
|
||||
|
||||
auto graphicsAllocation = createResidentAllocationAndStoreItInCsr(dstMemory, bufferSize);
|
||||
auto dstMemoryGPUPtr = reinterpret_cast<char *>(graphicsAllocation->getGpuAddress());
|
||||
auto graphicsAllocation = createResidentAllocationAndStoreItInCsr(dstMemoryAligned, pixelSize * numPixels);
|
||||
auto dstMemoryGPUPtr = reinterpret_cast<uint8_t *>(graphicsAllocation->getGpuAddress());
|
||||
|
||||
const size_t origin[3] = {0, 1, 0};
|
||||
const size_t region[3] = {size, 1, 1};
|
||||
|
||||
size_t inputRowPitch = testWidth;
|
||||
size_t inputRowPitch = testWidth * pixelSize;
|
||||
size_t inputSlicePitch = inputRowPitch * testHeight;
|
||||
|
||||
retVal = pCmdQ->enqueueReadImage(
|
||||
image.get(),
|
||||
CL_FALSE,
|
||||
@@ -109,21 +106,23 @@ struct AUBImageUnaligned
|
||||
region,
|
||||
inputRowPitch,
|
||||
inputSlicePitch,
|
||||
ptrOffset(dstMemory, offset),
|
||||
ptrOffset(dstMemoryAligned, offset),
|
||||
nullptr,
|
||||
0,
|
||||
nullptr,
|
||||
nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = pCmdQ->flush();
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(dstMemoryGPUPtr, referenceMemory, offset);
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, offset), &imageMemory[inputRowPitch * origin[1] * pixelSize], size * pixelSize);
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, size * pixelSize + offset), referenceMemory, bufferSize - offset - size * pixelSize);
|
||||
pCmdQ->finish();
|
||||
alignedFree(dstMemory);
|
||||
|
||||
std::vector<uint8_t> referenceMemory(pixelSize * numPixels, 0x0);
|
||||
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(dstMemoryGPUPtr, referenceMemory.data(), offset);
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, offset), &srcMemoryUnaligned[inputRowPitch * origin[1]], size * pixelSize);
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, offset + size * pixelSize), referenceMemory.data(), pixelSize * numPixels - offset - size * pixelSize);
|
||||
|
||||
alignedFree(dstMemoryAligned);
|
||||
alignedFree(srcMemoryAligned);
|
||||
}
|
||||
|
||||
template <typename FamilyType>
|
||||
@@ -132,19 +131,13 @@ struct AUBImageUnaligned
|
||||
DebugManager.flags.ForceLinearImages.set(true);
|
||||
MockContext context(pCmdQ->getDevice().getSpecializedDevice<ClDevice>());
|
||||
|
||||
char srcMemory[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnoprstuwxyz";
|
||||
const auto bufferSize = sizeof(srcMemory);
|
||||
char dstMemory[bufferSize + 1] = {0};
|
||||
char *imageMemory = &dstMemory[1]; //ensure non cacheline-aligned hostPtr to create non-zerocopy image
|
||||
char referenceMemory[bufferSize] = {0};
|
||||
|
||||
const size_t testWidth = bufferSize / 4 / pixelSize;
|
||||
const size_t testWidth = 14 / pixelSize;
|
||||
const size_t testHeight = 4;
|
||||
const size_t testDepth = 1;
|
||||
auto numPixels = testWidth * testHeight * testDepth;
|
||||
|
||||
cl_image_format imageFormat;
|
||||
cl_image_desc imageDesc;
|
||||
|
||||
imageFormat.image_channel_data_type = CL_UNSIGNED_INT8;
|
||||
switch (pixelSize) {
|
||||
case 1:
|
||||
@@ -160,7 +153,6 @@ struct AUBImageUnaligned
|
||||
imageFormat.image_channel_order = CL_RGBA;
|
||||
break;
|
||||
}
|
||||
|
||||
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
imageDesc.image_width = testWidth;
|
||||
imageDesc.image_height = testHeight;
|
||||
@@ -172,6 +164,10 @@ struct AUBImageUnaligned
|
||||
imageDesc.num_samples = 0;
|
||||
imageDesc.mem_object = NULL;
|
||||
|
||||
auto srcMemoryAligned = alignedMalloc(4 + pixelSize * numPixels, MemoryConstants::cacheLineSize);
|
||||
memset(srcMemoryAligned, 0x0, 4 + pixelSize * numPixels);
|
||||
auto srcMemoryUnaligned = ptrOffset(reinterpret_cast<uint8_t *>(srcMemoryAligned), 4); //ensure non cacheline-aligned (but aligned to 4) hostPtr to create non-zerocopy image
|
||||
|
||||
cl_mem_flags flags = CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE;
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, pClDevice->getHardwareInfo().capabilityTable.supportsOcl21Features);
|
||||
auto retVal = CL_INVALID_VALUE;
|
||||
@@ -183,19 +179,21 @@ struct AUBImageUnaligned
|
||||
0,
|
||||
surfaceFormat,
|
||||
&imageDesc,
|
||||
imageMemory,
|
||||
srcMemoryUnaligned,
|
||||
retVal));
|
||||
ASSERT_NE(nullptr, image);
|
||||
EXPECT_FALSE(image->isMemObjZeroCopy());
|
||||
|
||||
auto dstMemoryGPUPtr = reinterpret_cast<char *>(image->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getGpuAddress());
|
||||
for (auto i = 0u; i < pixelSize * numPixels; ++i) {
|
||||
srcMemoryUnaligned[i] = static_cast<uint8_t>(i);
|
||||
}
|
||||
|
||||
auto dstMemoryGPUPtr = reinterpret_cast<uint8_t *>(image->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getGpuAddress());
|
||||
|
||||
const size_t origin[3] = {0, 1, 0}; // write first row
|
||||
const size_t region[3] = {size, 1, 1}; // write only "size" number of pixels
|
||||
|
||||
size_t inputRowPitch = testWidth;
|
||||
size_t inputRowPitch = testWidth * pixelSize;
|
||||
size_t inputSlicePitch = inputRowPitch * testHeight;
|
||||
|
||||
retVal = pCmdQ->enqueueWriteImage(
|
||||
image.get(),
|
||||
CL_TRUE,
|
||||
@@ -203,7 +201,7 @@ struct AUBImageUnaligned
|
||||
region,
|
||||
inputRowPitch,
|
||||
inputSlicePitch,
|
||||
ptrOffset(srcMemory, offset),
|
||||
ptrOffset(srcMemoryUnaligned, offset),
|
||||
nullptr,
|
||||
0,
|
||||
nullptr,
|
||||
@@ -211,14 +209,18 @@ struct AUBImageUnaligned
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
pCmdQ->finish();
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
auto imageRowPitch = image->getImageDesc().image_row_pitch;
|
||||
std::vector<uint8_t> referenceMemory(inputRowPitch * pixelSize, 0x0);
|
||||
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(dstMemoryGPUPtr, referenceMemory, inputRowPitch * pixelSize); // validate zero row is not written
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, imageRowPitch), &srcMemory[offset], size * pixelSize); // validate first row is written,
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, imageRowPitch + size * pixelSize), referenceMemory, (inputRowPitch - size) * pixelSize); // only size number of pixels, with correct data
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(dstMemoryGPUPtr, referenceMemory.data(), inputRowPitch); // validate zero row is not written
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, imageRowPitch), &srcMemoryUnaligned[offset], size * pixelSize); // validate first row is written with correct data
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, imageRowPitch + size * pixelSize), referenceMemory.data(), inputRowPitch - size * pixelSize); // validate the remaining bytes of first row are not written
|
||||
for (uint32_t row = 2; row < testHeight; row++) {
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, row * imageRowPitch), referenceMemory, inputRowPitch * pixelSize); // next image rows shouldn;t be modified
|
||||
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, row * imageRowPitch), referenceMemory.data(), inputRowPitch); // validate the remaining rows are not written
|
||||
}
|
||||
|
||||
alignedFree(srcMemoryAligned);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -219,7 +219,7 @@ using AUBWriteImageUnaligned = AUBImageUnaligned;
|
||||
|
||||
HWTEST_F(AUBWriteImageUnaligned, GivenMisalignedHostPtrWhenWritingImageThenExpectationsAreMet) {
|
||||
const std::vector<size_t> pixelSizes = {1, 2, 4};
|
||||
const std::vector<size_t> offsets = {0, 1, 2, 3};
|
||||
const std::vector<size_t> offsets = {0, 4, 8, 12};
|
||||
const std::vector<size_t> sizes = {3, 2, 1};
|
||||
|
||||
for (auto pixelSize : pixelSizes) {
|
||||
|
||||
Reference in New Issue
Block a user