diff --git a/opencl/test/unit_test/aub_tests/command_queue/enqueue_read_image_aub_tests.cpp b/opencl/test/unit_test/aub_tests/command_queue/enqueue_read_image_aub_tests.cpp index dd8681224b..7e6704633f 100644 --- a/opencl/test/unit_test/aub_tests/command_queue/enqueue_read_image_aub_tests.cpp +++ b/opencl/test/unit_test/aub_tests/command_queue/enqueue_read_image_aub_tests.cpp @@ -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 pixelSizes = {1, 2, 4}; - const std::vector offsets = {0, 1, 2, 3}; + const std::vector offsets = {0, 4, 8, 12}; const std::vector sizes = {3, 2, 1}; for (auto pixelSize : pixelSizes) { diff --git a/opencl/test/unit_test/aub_tests/command_queue/enqueue_read_write_image_aub_fixture.h b/opencl/test/unit_test/aub_tests/command_queue/enqueue_read_write_image_aub_fixture.h index e2208d710c..fe15014a86 100644 --- a/opencl/test/unit_test/aub_tests/command_queue/enqueue_read_write_image_aub_fixture.h +++ b/opencl/test/unit_test/aub_tests/command_queue/enqueue_read_write_image_aub_fixture.h @@ -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()); - 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(ptrOffset(srcMemoryAligned, 4)); + for (auto i = 0u; i < pixelSize * numPixels; ++i) { + srcMemoryUnaligned[i] = static_cast(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::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(graphicsAllocation->getGpuAddress()); + auto graphicsAllocation = createResidentAllocationAndStoreItInCsr(dstMemoryAligned, pixelSize * numPixels); + auto dstMemoryGPUPtr = reinterpret_cast(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(dstMemoryGPUPtr, referenceMemory, offset); - AUBCommandStreamFixture::expectMemory(ptrOffset(dstMemoryGPUPtr, offset), &imageMemory[inputRowPitch * origin[1] * pixelSize], size * pixelSize); - AUBCommandStreamFixture::expectMemory(ptrOffset(dstMemoryGPUPtr, size * pixelSize + offset), referenceMemory, bufferSize - offset - size * pixelSize); pCmdQ->finish(); - alignedFree(dstMemory); + + std::vector referenceMemory(pixelSize * numPixels, 0x0); + + AUBCommandStreamFixture::expectMemory(dstMemoryGPUPtr, referenceMemory.data(), offset); + AUBCommandStreamFixture::expectMemory(ptrOffset(dstMemoryGPUPtr, offset), &srcMemoryUnaligned[inputRowPitch * origin[1]], size * pixelSize); + AUBCommandStreamFixture::expectMemory(ptrOffset(dstMemoryGPUPtr, offset + size * pixelSize), referenceMemory.data(), pixelSize * numPixels - offset - size * pixelSize); + + alignedFree(dstMemoryAligned); + alignedFree(srcMemoryAligned); } template @@ -132,19 +131,13 @@ struct AUBImageUnaligned DebugManager.flags.ForceLinearImages.set(true); MockContext context(pCmdQ->getDevice().getSpecializedDevice()); - 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(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(image->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getGpuAddress()); + for (auto i = 0u; i < pixelSize * numPixels; ++i) { + srcMemoryUnaligned[i] = static_cast(i); + } + + auto dstMemoryGPUPtr = reinterpret_cast(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 referenceMemory(inputRowPitch * pixelSize, 0x0); - AUBCommandStreamFixture::expectMemory(dstMemoryGPUPtr, referenceMemory, inputRowPitch * pixelSize); // validate zero row is not written - AUBCommandStreamFixture::expectMemory(ptrOffset(dstMemoryGPUPtr, imageRowPitch), &srcMemory[offset], size * pixelSize); // validate first row is written, - AUBCommandStreamFixture::expectMemory(ptrOffset(dstMemoryGPUPtr, imageRowPitch + size * pixelSize), referenceMemory, (inputRowPitch - size) * pixelSize); // only size number of pixels, with correct data + AUBCommandStreamFixture::expectMemory(dstMemoryGPUPtr, referenceMemory.data(), inputRowPitch); // validate zero row is not written + AUBCommandStreamFixture::expectMemory(ptrOffset(dstMemoryGPUPtr, imageRowPitch), &srcMemoryUnaligned[offset], size * pixelSize); // validate first row is written with correct data + AUBCommandStreamFixture::expectMemory(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(ptrOffset(dstMemoryGPUPtr, row * imageRowPitch), referenceMemory, inputRowPitch * pixelSize); // next image rows shouldn;t be modified + AUBCommandStreamFixture::expectMemory(ptrOffset(dstMemoryGPUPtr, row * imageRowPitch), referenceMemory.data(), inputRowPitch); // validate the remaining rows are not written } + + alignedFree(srcMemoryAligned); } }; diff --git a/opencl/test/unit_test/aub_tests/command_queue/enqueue_write_image_aub_tests.cpp b/opencl/test/unit_test/aub_tests/command_queue/enqueue_write_image_aub_tests.cpp index 03e518256e..95b0bb7d4e 100644 --- a/opencl/test/unit_test/aub_tests/command_queue/enqueue_write_image_aub_tests.cpp +++ b/opencl/test/unit_test/aub_tests/command_queue/enqueue_write_image_aub_tests.cpp @@ -219,7 +219,7 @@ using AUBWriteImageUnaligned = AUBImageUnaligned; HWTEST_F(AUBWriteImageUnaligned, GivenMisalignedHostPtrWhenWritingImageThenExpectationsAreMet) { const std::vector pixelSizes = {1, 2, 4}; - const std::vector offsets = {0, 1, 2, 3}; + const std::vector offsets = {0, 4, 8, 12}; const std::vector sizes = {3, 2, 1}; for (auto pixelSize : pixelSizes) {