From 7e3884e22dd7ebbf5270163797ed4f94ad6da3cc Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Wed, 28 Nov 2018 15:32:13 +0100 Subject: [PATCH] Add clEnqueueVerifyMemory API Change-Id: I15a514b14b9efdaeb182c7abd98b8e236932d50f Signed-off-by: Filip Hazubski --- public/cl_ext_private.h | 6 +- runtime/api/api.cpp | 36 ++++- runtime/api/api.h | 9 +- .../aub_command_stream_receiver_hw.h | 4 +- .../aub_command_stream_receiver_hw.inl | 8 +- .../command_stream_receiver.cpp | 7 +- .../command_stream/command_stream_receiver.h | 4 +- unit_tests/api/CMakeLists.txt | 3 +- unit_tests/api/api_tests_wrapper2.cpp | 3 +- unit_tests/api/cl_enqueue_verify_memory.inl | 80 ++++++++++ .../aub_tests/command_queue/CMakeLists.txt | 6 +- ...enqueue_verify_memory_buffer_aub_tests.cpp | 145 ++++++++++++++++++ .../enqueue_verify_memory_image_aub_tests.cpp | 141 +++++++++++++++++ .../command_stream/aub_mem_dump_tests.cpp | 14 +- unit_tests/aub_tests/fixtures/aub_fixture.h | 9 +- unit_tests/aub_tests/gen10/CMakeLists.txt | 3 +- unit_tests/aub_tests/gen8/CMakeLists.txt | 3 +- unit_tests/aub_tests/gen9/CMakeLists.txt | 3 +- .../aub_command_stream_receiver_2_tests.cpp | 5 +- unit_tests/helpers/unit_test_helper.h | 4 +- unit_tests/helpers/unit_test_helper.inl | 7 +- 21 files changed, 470 insertions(+), 30 deletions(-) create mode 100644 unit_tests/api/cl_enqueue_verify_memory.inl create mode 100644 unit_tests/aub_tests/command_queue/enqueue_verify_memory_buffer_aub_tests.cpp create mode 100644 unit_tests/aub_tests/command_queue/enqueue_verify_memory_image_aub_tests.cpp diff --git a/public/cl_ext_private.h b/public/cl_ext_private.h index 24b3901135..ff594b092c 100644 --- a/public/cl_ext_private.h +++ b/public/cl_ext_private.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -48,3 +48,7 @@ using cl_mem_flags_intel = cl_mem_flags; ******************************/ #define CL_MEM_FLAGS_INTEL 0x10001 + +// Used with clEnqueueVerifyMemory +#define CL_MEM_COMPARE_EQUAL 0u +#define CL_MEM_COMPARE_NOT_EQUAL 1u diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index 4ff2ae1bbc..f69357fdc7 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -3325,8 +3325,8 @@ void *CL_API_CALL clGetExtensionFunctionAddress(const char *func_name) { RETURN_FUNC_PTR_IF_EXIST(clGetAcceleratorInfoINTEL); RETURN_FUNC_PTR_IF_EXIST(clRetainAcceleratorINTEL); RETURN_FUNC_PTR_IF_EXIST(clReleaseAcceleratorINTEL); - RETURN_FUNC_PTR_IF_EXIST(clCreateBufferWithPropertiesINTEL); + RETURN_FUNC_PTR_IF_EXIST(clEnqueueVerifyMemory); void *ret = sharingFactory.getExtensionFunctionAddress(func_name); if (ret != nullptr) @@ -4247,3 +4247,37 @@ cl_kernel CL_API_CALL clCloneKernel(cl_kernel sourceKernel, return pClonedKernel; } + +CL_API_ENTRY cl_int CL_API_CALL clEnqueueVerifyMemory(cl_command_queue commandQueue, + const void *allocationPtr, + const void *expectedData, + size_t sizeOfComparison, + cl_uint comparisonMode) { + cl_int retVal = CL_SUCCESS; + API_ENTER(&retVal); + DBG_LOG_INPUTS("commandQueue", commandQueue, + "allocationPtr", allocationPtr, + "expectedData", expectedData, + "sizeOfComparison", sizeOfComparison, + "comparisonMode", comparisonMode); + + if (sizeOfComparison == 0 || expectedData == nullptr || allocationPtr == nullptr) { + retVal = CL_INVALID_VALUE; + return retVal; + } + + CommandQueue *pCommandQueue = nullptr; + retVal = validateObjects(WithCastToInternal(commandQueue, &pCommandQueue)); + if (retVal != CL_SUCCESS) { + return retVal; + } + + auto &csr = pCommandQueue->getCommandStreamReceiver(); + if (csr.expectMemory(allocationPtr, expectedData, sizeOfComparison, comparisonMode)) { + retVal = CL_SUCCESS; + return retVal; + } + + retVal = CL_INVALID_VALUE; + return retVal; +} diff --git a/runtime/api/api.h b/runtime/api/api.h index 2f7332512c..6f5871ef9b 100644 --- a/runtime/api/api.h +++ b/runtime/api/api.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -840,6 +840,13 @@ cl_sampler CL_API_CALL clCreateSamplerWithProperties( const cl_sampler_properties *samplerProperties, cl_int *errcodeRet); +cl_int CL_API_CALL clEnqueueVerifyMemory( + cl_command_queue commandQueue, + const void *allocationPtr, + const void *expectedData, + size_t sizeOfComparison, + cl_uint comparisonMode); + // OpenCL 2.1 cl_int CL_API_CALL clGetDeviceAndHostTimer(cl_device_id device, diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 33abd62a71..ea72931d7d 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -54,6 +54,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::expectMemoryNotEqual(void *gfxAddres } template -void AUBCommandStreamReceiverHw::expectMemory(void *gfxAddress, const void *srcAddress, +bool AUBCommandStreamReceiverHw::expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation) { if (hardwareContext) { hardwareContext->expectMemory(reinterpret_cast(gfxAddress), srcAddress, length, compareOperation); - return; + return true; } PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) { @@ -708,6 +708,8 @@ void AUBCommandStreamReceiverHw::expectMemory(void *gfxAddress, const }; this->ppgtt->pageWalk(reinterpret_cast(gfxAddress), length, 0, PageTableEntry::nonValidBits, walker, MemoryBanks::BankNotSpecified); + + return true; } template diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 48e0ac300f..d87428c14e 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -392,4 +392,9 @@ TagAllocator *CommandStreamReceiver::getTimestampPacketAllocato return timestampPacketAllocator.get(); } +bool CommandStreamReceiver::expectMemory(const void *gfxAddress, const void *srcAddress, + size_t length, uint32_t compareOperation) { + return false; +} + } // namespace OCLRT diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index 467f39930d..a4f045caf6 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -168,6 +168,8 @@ class CommandStreamReceiver { TagAllocator *getEventPerfCountAllocator(); TagAllocator *getTimestampPacketAllocator(); + virtual bool expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation); + protected: void cleanupResources(); void setDisableL3Cache(bool val) { diff --git a/unit_tests/api/CMakeLists.txt b/unit_tests/api/CMakeLists.txt index db0d3fc09c..93507c4490 100644 --- a/unit_tests/api/CMakeLists.txt +++ b/unit_tests/api/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2017-2018 Intel Corporation +# Copyright (C) 2017-2019 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -59,6 +59,7 @@ set(IGDRCL_SRCS_tests_api ${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_svm_unmap_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_task_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_unmap_mem_object_tests.inl + ${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_verify_memory.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_wait_for_events_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_write_buffer_rect_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_write_buffer_tests.inl diff --git a/unit_tests/api/api_tests_wrapper2.cpp b/unit_tests/api/api_tests_wrapper2.cpp index 64834bac11..56c8fad7f4 100644 --- a/unit_tests/api/api_tests_wrapper2.cpp +++ b/unit_tests/api/api_tests_wrapper2.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,6 +18,7 @@ #include "unit_tests/api/cl_enqueue_svm_unmap_tests.inl" #include "unit_tests/api/cl_enqueue_task_tests.inl" #include "unit_tests/api/cl_enqueue_unmap_mem_object_tests.inl" +#include "unit_tests/api/cl_enqueue_verify_memory.inl" #include "unit_tests/api/cl_enqueue_wait_for_events_tests.inl" #include "unit_tests/api/cl_enqueue_write_buffer_rect_tests.inl" #include "unit_tests/api/cl_enqueue_write_buffer_tests.inl" diff --git a/unit_tests/api/cl_enqueue_verify_memory.inl b/unit_tests/api/cl_enqueue_verify_memory.inl new file mode 100644 index 0000000000..806ed34a88 --- /dev/null +++ b/unit_tests/api/cl_enqueue_verify_memory.inl @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2017-2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "public/cl_ext_private.h" +#include "runtime/aub_mem_dump/aub_services.h" +#include "unit_tests/api/cl_api_tests.h" +#include "unit_tests/mocks/mock_csr.h" +#include "test.h" + +using namespace OCLRT; + +TEST(CheckVerifyMemoryRelatedApiConstants, givenVerifyMemoryRelatedApiConstantsWhenVerifyingTheirValueThenCorrectValuesAreReturned) { + EXPECT_EQ(CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual, CL_MEM_COMPARE_EQUAL); + EXPECT_EQ(CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareNotEqual, CL_MEM_COMPARE_NOT_EQUAL); +} + +struct clEnqueueVerifyMemorySettings { + const cl_uint comparisonMode = CL_MEM_COMPARE_EQUAL; + const size_t bufferSize = 1; + static constexpr size_t expectedSize = 1; + int expected[expectedSize]; + // Use any valid pointer as gpu address because non aub tests will not actually validate the memory + void *gpuAddress = expected; +}; + +class clEnqueueVerifyMemoryTests : public api_tests, + public clEnqueueVerifyMemorySettings { +}; + +TEST_F(clEnqueueVerifyMemoryTests, givenSizeOfComparisonEqualZeroWhenCallingVerifyMemoryThenErrorIsReturned) { + cl_int retval = clEnqueueVerifyMemory(nullptr, nullptr, nullptr, 0, comparisonMode); + EXPECT_EQ(CL_INVALID_VALUE, retval); +} + +TEST_F(clEnqueueVerifyMemoryTests, givenNullExpectedDataWhenCallingVerifyMemoryThenErrorIsReturned) { + cl_int retval = clEnqueueVerifyMemory(nullptr, nullptr, nullptr, expectedSize, comparisonMode); + EXPECT_EQ(CL_INVALID_VALUE, retval); +} + +TEST_F(clEnqueueVerifyMemoryTests, givenInvalidAllocationPointerWhenCallingVerifyMemoryThenErrorIsReturned) { + cl_int retval = clEnqueueVerifyMemory(nullptr, nullptr, expected, expectedSize, comparisonMode); + EXPECT_EQ(CL_INVALID_VALUE, retval); +} + +TEST_F(clEnqueueVerifyMemoryTests, givenInvalidCommandQueueWhenCallingVerifyMemoryThenErrorIsReturned) { + cl_int retval = clEnqueueVerifyMemory(nullptr, gpuAddress, expected, expectedSize, comparisonMode); + EXPECT_EQ(CL_INVALID_COMMAND_QUEUE, retval); +} + +TEST_F(clEnqueueVerifyMemoryTests, givenCommandQueueWithoutAubCsrWhenCallingVerifyMemoryThenErrorIsReturned) { + cl_int retval = clEnqueueVerifyMemory(pCommandQueue, gpuAddress, expected, expectedSize, comparisonMode); + EXPECT_EQ(CL_INVALID_VALUE, retval); +} + +template +struct MockCsrWithExpectMemory : MockCsr { + MockCsrWithExpectMemory() = delete; + MockCsrWithExpectMemory(const HardwareInfo &hwInfoIn) = delete; + MockCsrWithExpectMemory(int32_t &execStamp, ExecutionEnvironment &executionEnvironment) + : MockCsr(execStamp, executionEnvironment) { + } + bool expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation) override { + return true; + } +}; + +HWTEST_F(clEnqueueVerifyMemoryTests, givenCommandQueueWithMockAubCsrWhenCallingVerifyMemoryThenSuccessIsReturned) { + std::unique_ptr mockDevice(MockDevice::createWithNewExecutionEnvironment(platformDevices[0])); + int32_t executionStamp = 0; + auto *mockCsr = new MockCsrWithExpectMemory(executionStamp, *mockDevice.get()->executionEnvironment); + mockDevice.get()->resetCommandStreamReceiver(mockCsr); + CommandQueue cmdQ(nullptr, mockDevice.get(), 0); + + cl_int retval = clEnqueueVerifyMemory(&cmdQ, gpuAddress, expected, expectedSize, comparisonMode); + EXPECT_EQ(CL_SUCCESS, retval); +} diff --git a/unit_tests/aub_tests/command_queue/CMakeLists.txt b/unit_tests/aub_tests/command_queue/CMakeLists.txt index 009ea2868a..8ef0ff5fcf 100644 --- a/unit_tests/aub_tests/command_queue/CMakeLists.txt +++ b/unit_tests/aub_tests/command_queue/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2017-2018 Intel Corporation +# Copyright (C) 2017-2019 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -18,6 +18,8 @@ target_sources(igdrcl_aub_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_read_buffer_aub_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_read_buffer_rect_aub_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_read_image_aub_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_verify_memory_buffer_aub_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_verify_memory_image_aub_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_with_timestamp_packet_aub_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_write_buffer_aub_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_write_buffer_rect_aub_tests.cpp @@ -25,3 +27,5 @@ target_sources(igdrcl_aub_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_write_copy_read_buffer_aub_tests.h ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_write_image_aub_tests.cpp ) + +add_subdirectories() diff --git a/unit_tests/aub_tests/command_queue/enqueue_verify_memory_buffer_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_verify_memory_buffer_aub_tests.cpp new file mode 100644 index 0000000000..e3b0e8ff5b --- /dev/null +++ b/unit_tests/aub_tests/command_queue/enqueue_verify_memory_buffer_aub_tests.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2018-2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/api/api.h" +#include "runtime/command_stream/command_stream_receiver.h" +#include "runtime/mem_obj/buffer.h" +#include "unit_tests/aub_tests/command_queue/command_enqueue_fixture.h" +#include "unit_tests/mocks/mock_context.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/helpers/unit_test_helper.h" + +#include "test.h" + +using namespace OCLRT; + +struct TestDataItem { + uint8_t *item; + uint8_t *itemWrongSmaller; + uint8_t *itemWrongGreater; + size_t size; +}; + +struct VerifyMemoryBufferHw + : public CommandEnqueueAUBFixture, + public ::testing::TestWithParam> { + + void SetUp() override { + CommandEnqueueAUBFixture::SetUp(); + } + + void TearDown() override { + CommandEnqueueAUBFixture::TearDown(); + } +}; + +cl_int testClInt = 5; +cl_int testClIntSmaller = 4; +cl_int testClIntGreater = 6; +cl_float testClFloat = 20.0; +cl_float testClFloatSmaller = 19.5; +cl_float testClFloatGreater = 20.5; + +TestDataItem testDataItemTable[] = { + {reinterpret_cast(&testClInt), + reinterpret_cast(&testClIntSmaller), + reinterpret_cast(&testClIntGreater), + sizeof(testClInt)}, + {reinterpret_cast(&testClFloat), + reinterpret_cast(&testClFloatSmaller), + reinterpret_cast(&testClFloatGreater), + sizeof(testClFloat)}}; + +size_t testDataSizeTable[] = { + 16, + MemoryConstants::cacheLineSize}; + +cl_mem_flags testFlagsTable[] = { + 0, + CL_MEM_COPY_HOST_PTR}; + +HWTEST_P(VerifyMemoryBufferHw, givenDifferentBuffersWhenValidatingMemoryThenSuccessIsReturned) { + const auto &testDataItem = std::get<0>(GetParam()); + const auto &testDataSize = std::get<1>(GetParam()); + EXPECT_FALSE(testDataSize < testDataItem.size); + const auto &flags = std::get<2>(GetParam()); + const auto usesHostPointer = ((flags & CL_MEM_USE_HOST_PTR) || + (flags & CL_MEM_COPY_HOST_PTR)); + + DebugManagerStateRestore restore; + DebugManager.flags.DisableZeroCopyForBuffers.set(true); + + // for each buffer size check also one object smaller and one object greater + for (auto dataSize = testDataSize - testDataItem.size; + dataSize <= testDataSize + testDataItem.size; + dataSize += testDataItem.size) { + + std::unique_ptr bufferContent(new uint8_t[dataSize]); + std::unique_ptr validContent(new uint8_t[dataSize]); + std::unique_ptr invalidContent1(new uint8_t[dataSize]); + std::unique_ptr invalidContent2(new uint8_t[dataSize]); + + for (size_t offset = 0; offset < dataSize; offset += testDataItem.size) { + for (size_t itemOffset = 0; itemOffset < testDataItem.size; itemOffset++) { + bufferContent.get()[offset + itemOffset] = testDataItem.item[itemOffset]; + validContent.get()[offset + itemOffset] = testDataItem.item[itemOffset]; + invalidContent1.get()[offset + itemOffset] = testDataItem.item[itemOffset]; + invalidContent2.get()[offset + itemOffset] = testDataItem.item[itemOffset]; + } + } + + // set last item for invalid contents + size_t offset = dataSize - testDataItem.size; + for (size_t itemOffset = 0; itemOffset < testDataItem.size; itemOffset++) { + invalidContent1.get()[offset + itemOffset] = testDataItem.itemWrongSmaller[itemOffset]; + invalidContent2.get()[offset + itemOffset] = testDataItem.itemWrongGreater[itemOffset]; + } + + MockContext context(&this->pCmdQ->getDevice()); + cl_int retVal = CL_INVALID_VALUE; + + std::unique_ptr buffer(Buffer::create( + &context, + flags, + dataSize, + (usesHostPointer ? bufferContent.get() : nullptr), + retVal)); + EXPECT_NE(nullptr, buffer); + + if (!usesHostPointer) { + retVal = pCmdQ->enqueueFillBuffer( + buffer.get(), + testDataItem.item, + testDataItem.size, + 0, + dataSize, + 0, + nullptr, + nullptr); + EXPECT_EQ(CL_SUCCESS, retVal); + } + + auto mappedAddress = clEnqueueMapBuffer(pCmdQ, buffer.get(), CL_TRUE, CL_MAP_READ, 0, dataSize, 0, nullptr, nullptr, nullptr); + + retVal = clEnqueueVerifyMemory(pCmdQ, mappedAddress, validContent.get(), dataSize, CL_MEM_COMPARE_EQUAL); + EXPECT_EQ(CL_SUCCESS, retVal); + + if (UnitTestHelper::isExpectMemoryNotEqualSupported()) { + retVal = clEnqueueVerifyMemory(pCmdQ, mappedAddress, invalidContent1.get(), dataSize, CL_MEM_COMPARE_NOT_EQUAL); + EXPECT_EQ(CL_SUCCESS, retVal); + retVal = clEnqueueVerifyMemory(pCmdQ, mappedAddress, invalidContent2.get(), dataSize, CL_MEM_COMPARE_NOT_EQUAL); + EXPECT_EQ(CL_SUCCESS, retVal); + } + } +} + +INSTANTIATE_TEST_CASE_P(VerifyMemoryBuffer, + VerifyMemoryBufferHw, + ::testing::Combine( + ::testing::ValuesIn(testDataItemTable), + ::testing::ValuesIn(testDataSizeTable), + ::testing::ValuesIn(testFlagsTable))); diff --git a/unit_tests/aub_tests/command_queue/enqueue_verify_memory_image_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_verify_memory_image_aub_tests.cpp new file mode 100644 index 0000000000..dbd5618965 --- /dev/null +++ b/unit_tests/aub_tests/command_queue/enqueue_verify_memory_image_aub_tests.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2018-2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/api/api.h" +#include "runtime/command_stream/command_stream_receiver.h" +#include "runtime/helpers/aligned_memory.h" +#include "runtime/helpers/ptr_math.h" +#include "runtime/mem_obj/image.h" +#include "runtime/memory_manager/os_agnostic_memory_manager.h" +#include "unit_tests/aub_tests/command_queue/command_enqueue_fixture.h" +#include "unit_tests/helpers/unit_test_helper.h" +#include "unit_tests/mocks/mock_context.h" +#include "test.h" + +using namespace OCLRT; + +struct TestOffset { + size_t offset[3]; +}; + +struct VerifyMemoryImageHw + : public CommandEnqueueAUBFixture, + public ::testing::TestWithParam { + + void SetUp() override { + CommandEnqueueAUBFixture::SetUp(); + } + + void TearDown() override { + CommandEnqueueAUBFixture::TearDown(); + } +}; + +TestOffset testInput[] = { + {{0, 0, 0}}, + {{1, 2, 3}}, + {{3, 2, 1}}, + {{5, 5, 5}}}; + +HWTEST_P(VerifyMemoryImageHw, givenDifferentImagesWhenValidatingMemoryThenSuccessIsReturned) { + cl_image_format imageFormat; + cl_image_desc imageDesc; + + // clang-format off + imageFormat.image_channel_data_type = CL_UNSIGNED_INT32; + imageFormat.image_channel_order = CL_RGBA; + + imageDesc.image_type = CL_MEM_OBJECT_IMAGE3D; + imageDesc.image_width = 10; + imageDesc.image_height = 19; + imageDesc.image_depth = 7; + 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 + + // data per channel multplied by number of channels + size_t elementSize = 16; + + cl_mem_flags flags = CL_MEM_READ_ONLY; + auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat); + auto retVal = CL_INVALID_VALUE; + std::unique_ptr image(Image::create( + context, + flags, + surfaceFormat, + &imageDesc, + nullptr, + retVal)); + EXPECT_NE(nullptr, image); + + auto sizeMemory = image->getSize(); + EXPECT_GT(sizeMemory, 0u); + + std::unique_ptr srcMemory(new uint8_t[elementSize]); + memset(srcMemory.get(), 0xAB, elementSize); + memset(image->getCpuAddress(), 0xAB, sizeMemory); + + const size_t *origin = GetParam().offset; + + const size_t region[] = { + imageDesc.image_width - origin[0], + imageDesc.image_height - origin[1], + imageDesc.image_depth - origin[2]}; + + uint32_t fillValues[] = {0x3f800000, 0x00000000, 0x3f555555, 0x3f2aaaaa}; + retVal = pCmdQ->enqueueFillImage( + image.get(), + fillValues, + origin, + region, + 0, + nullptr, + nullptr); + EXPECT_EQ(CL_SUCCESS, retVal); + + size_t imgOrigin[] = {0, 0, 0}; + size_t imgRegion[] = {imageDesc.image_width, imageDesc.image_height, imageDesc.image_depth}; + + size_t mappedRowPitch; + size_t mappedSlicePitch; + auto mappedAddress = clEnqueueMapImage(pCmdQ, image.get(), CL_TRUE, CL_MAP_READ, imgOrigin, imgRegion, + &mappedRowPitch, &mappedSlicePitch, 0, nullptr, nullptr, &retVal); + auto pImageData = reinterpret_cast(mappedAddress); + for (size_t z = 0; z < imageDesc.image_depth; ++z) { + for (size_t y = 0; y < imageDesc.image_height; ++y) { + for (size_t x = 0; x < imageDesc.image_width; ++x) { + void *validData = srcMemory.get(); + void *invalidData = fillValues; + + if (z >= origin[2] && z < (origin[2] + region[2]) && + y >= origin[1] && y < (origin[1] + region[1]) && + x >= origin[0] && x < (origin[0] + region[0])) { + std::swap(validData, invalidData); + } + + retVal = clEnqueueVerifyMemory(pCmdQ, &pImageData[x * elementSize], validData, elementSize, CL_MEM_COMPARE_EQUAL); + EXPECT_EQ(CL_SUCCESS, retVal); + + if (UnitTestHelper::isExpectMemoryNotEqualSupported()) { + retVal = clEnqueueVerifyMemory(pCmdQ, &pImageData[x * elementSize], invalidData, elementSize, + CL_MEM_COMPARE_NOT_EQUAL); + EXPECT_EQ(CL_SUCCESS, retVal); + } + } + pImageData = ptrOffset(pImageData, mappedRowPitch); + } + pImageData = ptrOffset(pImageData, mappedSlicePitch - (mappedRowPitch * imageDesc.image_height)); + } +} + +INSTANTIATE_TEST_CASE_P(VerifyMemoryImage, + VerifyMemoryImageHw, + ::testing::ValuesIn(testInput)); diff --git a/unit_tests/aub_tests/command_stream/aub_mem_dump_tests.cpp b/unit_tests/aub_tests/command_stream/aub_mem_dump_tests.cpp index abea9691c0..717b8eb4a5 100644 --- a/unit_tests/aub_tests/command_stream/aub_mem_dump_tests.cpp +++ b/unit_tests/aub_tests/command_stream/aub_mem_dump_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -108,7 +108,8 @@ HWTEST_F(AubMemDumpTests, writeVerifyOneBytePPGTT) { OCLRT::AubHelperHw aubHelperHw(false); AUB::reserveAddressPPGTT(aubFile, gAddress, sizeof(byte), physAddress, 7, aubHelperHw); AUB::addMemoryWrite(aubFile, physAddress, &byte, sizeof(byte), AubMemDump::AddressSpaceValues::TraceNonlocal); - aubFile.expectMemory(physAddress, &byte, sizeof(byte), AubMemDump::AddressSpaceValues::TraceNonlocal, 0); + aubFile.expectMemory(physAddress, &byte, sizeof(byte), AubMemDump::AddressSpaceValues::TraceNonlocal, + AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual); aubFile.fileHandle.close(); } @@ -130,7 +131,8 @@ HWTEST_F(AubMemDumpTests, writeVerifyOneByteGGTT) { AubGTTData data = {true, false}; AUB::reserveAddressGGTT(aubFile, &byte, sizeof(byte), physAddress, data); AUB::addMemoryWrite(aubFile, physAddress, &byte, sizeof(byte), AubMemDump::AddressSpaceValues::TraceNonlocal); - aubFile.expectMemory(physAddress, &byte, sizeof(byte), AubMemDump::AddressSpaceValues::TraceNonlocal, 0); + aubFile.expectMemory(physAddress, &byte, sizeof(byte), AubMemDump::AddressSpaceValues::TraceNonlocal, + AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual); aubFile.fileHandle.close(); } @@ -154,7 +156,8 @@ HWTEST_F(AubMemDumpTests, writeVerifySevenBytesPPGTT) { OCLRT::AubHelperHw aubHelperHw(false); AUB::reserveAddressPPGTT(aubFile, gAddress, sizeof(bytes), physAddress, 7, aubHelperHw); AUB::addMemoryWrite(aubFile, physAddress, bytes, sizeof(bytes), AubMemDump::AddressSpaceValues::TraceNonlocal); - aubFile.expectMemory(physAddress, bytes, sizeof(bytes), AubMemDump::AddressSpaceValues::TraceNonlocal, 0); + aubFile.expectMemory(physAddress, bytes, sizeof(bytes), AubMemDump::AddressSpaceValues::TraceNonlocal, + AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual); aubFile.fileHandle.close(); } @@ -176,7 +179,8 @@ HWTEST_F(AubMemDumpTests, writeVerifySevenBytesGGTT) { AubGTTData data = {true, false}; AUB::reserveAddressGGTT(aubFile, bytes, sizeof(bytes), physAddress, data); AUB::addMemoryWrite(aubFile, physAddress, bytes, sizeof(bytes), AubMemDump::AddressSpaceValues::TraceNonlocal); - aubFile.expectMemory(physAddress, bytes, sizeof(bytes), AubMemDump::AddressSpaceValues::TraceNonlocal, 0); + aubFile.expectMemory(physAddress, bytes, sizeof(bytes), AubMemDump::AddressSpaceValues::TraceNonlocal, + AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual); aubFile.fileHandle.close(); } diff --git a/unit_tests/aub_tests/fixtures/aub_fixture.h b/unit_tests/aub_tests/fixtures/aub_fixture.h index 045e4ea9b2..3e41592e58 100644 --- a/unit_tests/aub_tests/fixtures/aub_fixture.h +++ b/unit_tests/aub_tests/fixtures/aub_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -36,11 +36,10 @@ class AUBFixture : public CommandQueueHwFixture { strfilename << testInfo->test_case_name() << "_" << testInfo->name() << "_" << hwHelper.getCsTraits(engineType).name; executionEnvironment = new ExecutionEnvironment; - - if (testMode == TestMode::AubTests) { - this->csr = AUBCommandStreamReceiver::create(hwInfo, strfilename.str(), true, *executionEnvironment); - } else if (testMode == TestMode::AubTestsWithTbx) { + if (testMode == TestMode::AubTestsWithTbx) { this->csr = TbxCommandStreamReceiver::create(hwInfo, true, *executionEnvironment); + } else { + this->csr = AUBCommandStreamReceiver::create(hwInfo, strfilename.str(), true, *executionEnvironment); } executionEnvironment->commandStreamReceivers.resize(deviceIndex + 1); diff --git a/unit_tests/aub_tests/gen10/CMakeLists.txt b/unit_tests/aub_tests/gen10/CMakeLists.txt index d6f61bb9e4..f5b6b37ecf 100644 --- a/unit_tests/aub_tests/gen10/CMakeLists.txt +++ b/unit_tests/aub_tests/gen10/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2017-2018 Intel Corporation +# Copyright (C) 2017-2019 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -8,6 +8,7 @@ if(TESTS_GEN10) target_sources(igdrcl_aub_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/aub_tests_configuration_gen10.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/gen10/unit_test_helper_gen10.cpp ) add_subdirectories() endif() diff --git a/unit_tests/aub_tests/gen8/CMakeLists.txt b/unit_tests/aub_tests/gen8/CMakeLists.txt index 753d080a94..af2b42c508 100644 --- a/unit_tests/aub_tests/gen8/CMakeLists.txt +++ b/unit_tests/aub_tests/gen8/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2018 Intel Corporation +# Copyright (C) 2018-2019 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -8,6 +8,7 @@ if(TESTS_GEN8) target_sources(igdrcl_aub_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/aub_tests_configuration_gen8.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/gen8/unit_test_helper_gen8.cpp ) add_subdirectories() endif() diff --git a/unit_tests/aub_tests/gen9/CMakeLists.txt b/unit_tests/aub_tests/gen9/CMakeLists.txt index c26c8f3dda..deb55d6c83 100644 --- a/unit_tests/aub_tests/gen9/CMakeLists.txt +++ b/unit_tests/aub_tests/gen9/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2018 Intel Corporation +# Copyright (C) 2018-2019 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -7,6 +7,7 @@ if(TESTS_GEN9) target_sources(igdrcl_aub_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/aub_tests_configuration_gen9.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/gen9/unit_test_helper_gen9.cpp ) add_subdirectories() endif() diff --git a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp index 7fd61b5de5..6e893fb8b6 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -813,9 +813,10 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenAskedForMemoryExpectation public: using AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw; - void expectMemory(void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation) override { + bool expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation) override { inputCompareOperation = compareOperation; AUBCommandStreamReceiverHw::expectMemory(gfxAddress, srcAddress, length, compareOperation); + return true; } uint32_t inputCompareOperation = 0; }; diff --git a/unit_tests/helpers/unit_test_helper.h b/unit_tests/helpers/unit_test_helper.h index b5aa7ba66d..77c3aedf46 100644 --- a/unit_tests/helpers/unit_test_helper.h +++ b/unit_tests/helpers/unit_test_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,5 +21,7 @@ struct UnitTestHelper { static bool isPageTableManagerSupported(const HardwareInfo &hwInfo); static bool isTimestampPacketWriteSupported(); + + static bool isExpectMemoryNotEqualSupported(); }; } // namespace OCLRT diff --git a/unit_tests/helpers/unit_test_helper.inl b/unit_tests/helpers/unit_test_helper.inl index f4d13f85c5..aa7c3dbaae 100644 --- a/unit_tests/helpers/unit_test_helper.inl +++ b/unit_tests/helpers/unit_test_helper.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,4 +29,9 @@ template bool UnitTestHelper::isTimestampPacketWriteSupported() { return false; } + +template +bool UnitTestHelper::isExpectMemoryNotEqualSupported() { + return false; +} } // namespace OCLRT