diff --git a/runtime/command_queue/command_queue.cpp b/runtime/command_queue/command_queue.cpp index 2c47c51ba0..9d91739022 100644 --- a/runtime/command_queue/command_queue.cpp +++ b/runtime/command_queue/command_queue.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/built_ins/sip.h" #include "runtime/command_queue/command_queue.h" #include "runtime/command_queue/command_queue_hw.h" #include "runtime/command_stream/command_stream_receiver.h" @@ -629,4 +630,22 @@ void CommandQueue::enqueueBlockedMapUnmapOperation(const cl_event *eventWaitList this->virtualEvent = eventBuilder->getEvent(); } +bool CommandQueue::setupDebugSurface(Kernel *kernel) { + auto &commandStreamReceiver = device->getCommandStreamReceiver(); + auto debugSurface = commandStreamReceiver.getDebugSurfaceAllocation(); + + if (!debugSurface) { + debugSurface = commandStreamReceiver.allocateDebugSurface(SipKernel::maxDbgSurfaceSize); + } + + DEBUG_BREAK_IF(!kernel->requiresSshForBuffers()); + + auto surfaceState = ptrOffset(reinterpret_cast(kernel->getSurfaceStateHeap()), + kernel->getKernelInfo().patchInfo.pAllocateSystemThreadSurface->Offset); + void *addressToPatch = reinterpret_cast(debugSurface->getGpuAddress()); + size_t sizeToPatch = debugSurface->getUnderlyingBufferSize(); + Buffer::setSurfaceState(context, surfaceState, sizeToPatch, addressToPatch, debugSurface); + return true; +} + } // namespace OCLRT diff --git a/runtime/command_queue/command_queue.h b/runtime/command_queue/command_queue.h index d73d22b63d..3cc5424708 100644 --- a/runtime/command_queue/command_queue.h +++ b/runtime/command_queue/command_queue.h @@ -390,6 +390,8 @@ class CommandQueue : public BaseObject<_cl_command_queue> { bool readOnly, EventBuilder &externalEventBuilder); + MOCKABLE_VIRTUAL bool setupDebugSurface(Kernel *kernel); + // taskCount of last task uint32_t taskCount; diff --git a/runtime/command_queue/enqueue_common.h b/runtime/command_queue/enqueue_common.h index 32f810eb1e..ef582ba80f 100644 --- a/runtime/command_queue/enqueue_common.h +++ b/runtime/command_queue/enqueue_common.h @@ -216,6 +216,12 @@ void CommandQueueHw::enqueueHandler(Surface **surfacesForResidency, printfHandler.get()->prepareDispatch(multiDispatchInfo); } + if (commandType == CL_COMMAND_NDRANGE_KERNEL) { + if (multiDispatchInfo.begin()->getKernel()->getProgram()->isKernelDebugEnabled()) { + setupDebugSurface(multiDispatchInfo.begin()->getKernel()); + } + } + if ((this->isProfilingEnabled() && (eventBuilder.getEvent() != nullptr))) { // Get allocation for timestamps hwTimeStamps = eventBuilder.getEvent()->getHwTimeStamp(); diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 93f0a222b6..e0f8bae1f0 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -169,6 +169,11 @@ void CommandStreamReceiver::cleanupResources() { scratchAllocation = nullptr; } + if (debugSurface) { + memoryManager->freeGraphicsMemory(debugSurface); + debugSurface = nullptr; + } + if (commandStream.getCpuBase()) { memoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation()); commandStream.replaceGraphicsAllocation(nullptr); @@ -220,4 +225,10 @@ void CommandStreamReceiver::initializeInstructionHeapCmdStreamReceiverReservedBl return PreemptionHelper::initializeInstructionHeapSipKernelReservedBlock(ih, *memoryManager->device); } +GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) { + UNRECOVERABLE_IF(debugSurface != nullptr); + debugSurface = memoryManager->allocateGraphicsMemory(size); + return debugSurface; +} + } // namespace OCLRT diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index 81d73f3269..d5d5d3372f 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -105,6 +105,8 @@ class CommandStreamReceiver { void setRequiredScratchSize(uint32_t newRequiredScratchSize); GraphicsAllocation *getScratchAllocation() { return scratchAllocation; } + GraphicsAllocation *getDebugSurfaceAllocation() { return debugSurface; } + GraphicsAllocation *allocateDebugSurface(size_t size); void setPreemptionCsrAllocation(GraphicsAllocation *allocation) { preemptionCsrAllocation = allocation; } @@ -162,6 +164,7 @@ class CommandStreamReceiver { GraphicsAllocation *scratchAllocation = nullptr; GraphicsAllocation *preemptionCsrAllocation = nullptr; + GraphicsAllocation *debugSurface = nullptr; MemoryManager *memoryManager = nullptr; std::unique_ptr osInterface; diff --git a/runtime/program/program.h b/runtime/program/program.h index e4709bf315..b37ce1c8ae 100644 --- a/runtime/program/program.h +++ b/runtime/program/program.h @@ -241,6 +241,9 @@ class Program : public BaseObject<_cl_program> { static bool isValidLlvmBinary(const void *pBinary, size_t binarySize); static bool isValidSpirvBinary(const void *pBinary, size_t binarySize); + bool isKernelDebugEnabled() { + return kernelDebugEnabled; + } protected: Program(); @@ -280,10 +283,6 @@ class Program : public BaseObject<_cl_program> { void updateNonUniformFlag(); void updateNonUniformFlag(const Program **inputProgram, size_t numInputPrograms); - bool isKernelDebugEnabled() { - return kernelDebugEnabled; - } - static const std::string clOptNameClVer; static const std::string clOptNameUniformWgs; // clang-format off diff --git a/unit_tests/command_queue/CMakeLists.txt b/unit_tests/command_queue/CMakeLists.txt index 651bace66a..16b4ae7b91 100644 --- a/unit_tests/command_queue/CMakeLists.txt +++ b/unit_tests/command_queue/CMakeLists.txt @@ -40,6 +40,7 @@ set(IGDRCL_SRCS_tests_command_queue ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_copy_image_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_copy_image_to_buffer_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_copy_image_to_buffer_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_debug_kernel_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_fill_buffer_event_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_fill_buffer_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_fill_buffer_negative_tests.cpp diff --git a/unit_tests/command_queue/command_queue_tests.cpp b/unit_tests/command_queue/command_queue_tests.cpp index 363445ea95..fb62c531ec 100644 --- a/unit_tests/command_queue/command_queue_tests.cpp +++ b/unit_tests/command_queue/command_queue_tests.cpp @@ -39,6 +39,8 @@ #include "unit_tests/mocks/mock_command_queue.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_csr.h" +#include "unit_tests/mocks/mock_kernel.h" +#include "unit_tests/mocks/mock_program.h" #include "gtest/gtest.h" #include "gmock/gmock.h" @@ -844,3 +846,43 @@ TEST(CommandQueue, givenEnqueueReleaseSharedObjectsWhenIncorrectArgumentsThenRet result = cmdQ.enqueueReleaseSharedObjects(numObjects, memObjects, 0, nullptr, nullptr, 0); EXPECT_EQ(result, CL_INVALID_MEM_OBJECT); } + +HWTEST_F(CommandQueueCommandStreamTest, givenDebugKernelWhenSetupDebugSurfaceIsCalledThenSurfaceStateIsCorrectlySet) { + using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; + MockProgram program; + program.enableKernelDebug(); + std::unique_ptr kernel(MockKernel::create(*pDevice, &program)); + CommandQueue cmdQ(&context, pDevice, 0); + + kernel->setSshLocal(nullptr, sizeof(RENDER_SURFACE_STATE) + kernel->getAllocatedKernelInfo()->patchInfo.pAllocateSystemThreadSurface->Offset); + kernel->getAllocatedKernelInfo()->usesSsh = true; + auto &commandStreamReceiver = pDevice->getCommandStreamReceiver(); + + cmdQ.setupDebugSurface(kernel.get()); + + auto debugSurface = commandStreamReceiver.getDebugSurfaceAllocation(); + ASSERT_NE(nullptr, debugSurface); + RENDER_SURFACE_STATE *surfaceState = (RENDER_SURFACE_STATE *)kernel->getSurfaceStateHeap(); + EXPECT_EQ(debugSurface->getGpuAddress(), surfaceState->getSurfaceBaseAddress()); +} + +HWTEST_F(CommandQueueCommandStreamTest, givenCsrWithDebugSurfaceAllocatedWhenSetupDebugSurfaceIsCalledThenDebugSurfaceIsReused) { + using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; + MockProgram program; + program.enableKernelDebug(); + std::unique_ptr kernel(MockKernel::create(*pDevice, &program)); + CommandQueue cmdQ(&context, pDevice, 0); + + kernel->setSshLocal(nullptr, sizeof(RENDER_SURFACE_STATE) + kernel->getAllocatedKernelInfo()->patchInfo.pAllocateSystemThreadSurface->Offset); + kernel->getAllocatedKernelInfo()->usesSsh = true; + auto &commandStreamReceiver = pDevice->getCommandStreamReceiver(); + commandStreamReceiver.allocateDebugSurface(SipKernel::maxDbgSurfaceSize); + auto debugSurface = commandStreamReceiver.getDebugSurfaceAllocation(); + ASSERT_NE(nullptr, debugSurface); + + cmdQ.setupDebugSurface(kernel.get()); + + EXPECT_EQ(debugSurface, commandStreamReceiver.getDebugSurfaceAllocation()); + RENDER_SURFACE_STATE *surfaceState = (RENDER_SURFACE_STATE *)kernel->getSurfaceStateHeap(); + EXPECT_EQ(debugSurface->getGpuAddress(), surfaceState->getSurfaceBaseAddress()); +} diff --git a/unit_tests/command_queue/enqueue_debug_kernel_tests.cpp b/unit_tests/command_queue/enqueue_debug_kernel_tests.cpp new file mode 100644 index 0000000000..814e74c4c2 --- /dev/null +++ b/unit_tests/command_queue/enqueue_debug_kernel_tests.cpp @@ -0,0 +1,157 @@ +/* + * 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 "runtime/compiler_interface/compiler_options.h" +#include "runtime/command_queue/command_queue.h" +#include "runtime/program/program.h" +#include "unit_tests/fixtures/enqueue_handler_fixture.h" +#include "unit_tests/helpers/kernel_binary_helper.h" +#include "unit_tests/helpers/kernel_filename_helper.h" +#include "unit_tests/mocks/mock_buffer.h" +#include "unit_tests/mocks/mock_command_queue.h" +#include "unit_tests/mocks/mock_kernel.h" +#include "unit_tests/program/program_from_binary.h" +#include "test.h" +#include "gmock/gmock.h" + +using namespace OCLRT; +using namespace ::testing; + +typedef EnqueueHandlerTest EnqueueDebugKernelSimpleTest; + +class EnqueueDebugKernelTest : public ProgramSimpleFixture, + public ::testing::Test { + public: + void SetUp() override { + ProgramSimpleFixture::SetUp(); + device = pDevice; + if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) { + std::string filename; + std::string kernelOption(CompilerOptions::debugKernelEnable); + KernelFilenameHelper::getKernelFilenameFromInternalOption(kernelOption, filename); + + kbHelper = new KernelBinaryHelper(filename, false); + CreateProgramWithSource( + pContext, + &device, + "copybuffer.cl"); + pProgram->enableKernelDebug(); + + cl_int retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false); + ASSERT_EQ(CL_SUCCESS, retVal); + + // create a kernel + debugKernel = Kernel::create( + pProgram, + *pProgram->getKernelInfo("CopyBuffer"), + &retVal); + + ASSERT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, debugKernel); + + cl_mem src = &bufferSrc; + cl_mem dst = &bufferDst; + retVal = debugKernel->setArg( + 0, + sizeof(cl_mem), + &src); + retVal = debugKernel->setArg( + 1, + sizeof(cl_mem), + &dst); + } + } + + void TearDown() override { + if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) { + delete kbHelper; + debugKernel->release(); + } + ProgramSimpleFixture::TearDown(); + } + cl_device_id device; + Kernel *debugKernel = nullptr; + KernelBinaryHelper *kbHelper = nullptr; + MockContext context; + MockBuffer bufferSrc; + MockBuffer bufferDst; +}; + +HWTEST_F(EnqueueDebugKernelTest, givenDebugKernelWhenEnqueuedThenSSHAndBtiAreCorrectlySet) { + if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) { + using BINDING_TABLE_STATE = typename FamilyType::BINDING_TABLE_STATE; + using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; + std::unique_ptr> mockCmdQ(new MockCommandQueueHw(&context, pDevice, 0)); + + size_t gws[] = {1, 1, 1}; + auto &ssh = mockCmdQ->getIndirectHeap(IndirectHeap::SURFACE_STATE, 4096u); + void *surfaceStates = ssh.getSpace(0); + + mockCmdQ->enqueueKernel(debugKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); + + auto *dstBtiTableBase = reinterpret_cast(ptrOffset(surfaceStates, debugKernel->getBindingTableOffset())); + uint32_t surfaceStateOffset = dstBtiTableBase[0].getSurfaceStatePointer(); + + auto debugSurfaceState = reinterpret_cast(ptrOffset(ssh.getCpuBase(), surfaceStateOffset)); + + auto &commandStreamReceiver = pDevice->getCommandStreamReceiver(); + auto debugSurface = commandStreamReceiver.getDebugSurfaceAllocation(); + + EXPECT_EQ(debugSurface->getGpuAddress(), debugSurfaceState->getSurfaceBaseAddress()); + } +} + +template +class GMockCommandQueueHw : public CommandQueueHw { + typedef CommandQueueHw BaseClass; + + public: + GMockCommandQueueHw(Context *context, Device *device, cl_queue_properties *properties) : BaseClass(context, device, properties) { + } + + MOCK_METHOD1(setupDebugSurface, bool(Kernel *kernel)); +}; + +HWTEST_F(EnqueueDebugKernelSimpleTest, givenKernelFromProgramWithDebugEnabledWhenEnqueuedThenDebugSurfaceIsSetup) { + MockProgram program; + program.enableKernelDebug(); + std::unique_ptr kernel(MockKernel::create(*pDevice, &program)); + std::unique_ptr> mockCmdQ(new GMockCommandQueueHw(context, pDevice, 0)); + + EXPECT_CALL(*mockCmdQ.get(), setupDebugSurface(kernel.get())).Times(1).RetiresOnSaturation(); + + size_t gws[] = {1, 1, 1}; + mockCmdQ->enqueueKernel(kernel.get(), 1, nullptr, gws, nullptr, 0, nullptr, nullptr); + + ::testing::Mock::VerifyAndClearExpectations(mockCmdQ.get()); +} + +HWTEST_F(EnqueueDebugKernelSimpleTest, givenKernelFromProgramWithoutDebugEnabledWhenEnqueuedThenDebugSurfaceIsNotSetup) { + MockProgram program; + std::unique_ptr kernel(MockKernel::create(*pDevice, &program)); + std::unique_ptr>> mockCmdQ(new NiceMock>(context, pDevice, nullptr)); + + EXPECT_CALL(*mockCmdQ.get(), setupDebugSurface(kernel.get())).Times(0); + + size_t gws[] = {1, 1, 1}; + mockCmdQ->enqueueKernel(kernel.get(), 1, nullptr, gws, nullptr, 0, nullptr, nullptr); +} diff --git a/unit_tests/command_queue/enqueue_handler_tests.cpp b/unit_tests/command_queue/enqueue_handler_tests.cpp index d4f27a514b..dbbb15e774 100644 --- a/unit_tests/command_queue/enqueue_handler_tests.cpp +++ b/unit_tests/command_queue/enqueue_handler_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 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"), @@ -22,7 +22,7 @@ #include "runtime/event/event.h" #include "runtime/memory_manager/surface.h" -#include "unit_tests/fixtures/device_fixture.h" +#include "unit_tests/fixtures/enqueue_handler_fixture.h" #include "unit_tests/mocks/mock_command_queue.h" #include "unit_tests/mocks/mock_csr.h" #include "unit_tests/mocks/mock_context.h" @@ -34,21 +34,6 @@ using namespace OCLRT; -class EnqueueHandlerTest : public DeviceFixture, - public testing::Test { - public: - void SetUp() override { - context = new MockContext; - DeviceFixture::SetUp(); - } - - void TearDown() override { - DeviceFixture::TearDown(); - context->decRefInternal(); - } - MockContext *context; -}; - HWTEST_F(EnqueueHandlerTest, enqueueHandlerWithKernelCallsProcessEvictionOnCSR) { int32_t tag; auto csr = new MockCsrBase(tag); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index 350ff4a558..010e15e3c2 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -242,6 +242,13 @@ TEST_F(CommandStreamReceiverTest, makeResidentWithoutParametersDoesNothing) { EXPECT_EQ(0u, residencyAllocations.size()); } +TEST_F(CommandStreamReceiverTest, givenForced32BitAddressingWhenDebugSurfaceIsAllocatedThenRegularAllocationIsReturned) { + auto *memoryManager = commandStreamReceiver->getMemoryManager(); + memoryManager->setForce32BitAllocations(true); + auto allocation = commandStreamReceiver->allocateDebugSurface(1024); + EXPECT_FALSE(allocation->is32BitAllocation); +} + HWTEST_F(CommandStreamReceiverTest, givenDefaultCommandStreamReceiverThenDefaultDispatchingPolicyIsImmediateSubmission) { auto &csr = pDevice->getUltCommandStreamReceiver(); EXPECT_EQ(CommandStreamReceiver::DispatchMode::ImmediateDispatch, csr.dispatchMode); diff --git a/unit_tests/fixtures/CMakeLists.txt b/unit_tests/fixtures/CMakeLists.txt index 599226e122..3692a01418 100644 --- a/unit_tests/fixtures/CMakeLists.txt +++ b/unit_tests/fixtures/CMakeLists.txt @@ -24,6 +24,7 @@ set(IGDRCL_SRCS_tests_fixtures ${CMAKE_CURRENT_SOURCE_DIR}/context_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/device_host_queue_fixture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_host_queue_fixture.h + ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_handler_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/execution_model_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/execution_model_kernel_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/gmm_fixture.h diff --git a/unit_tests/fixtures/enqueue_handler_fixture.h b/unit_tests/fixtures/enqueue_handler_fixture.h new file mode 100644 index 0000000000..f04c947346 --- /dev/null +++ b/unit_tests/fixtures/enqueue_handler_fixture.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#pragma once +#include "unit_tests/fixtures/device_fixture.h" +#include "unit_tests/mocks/mock_context.h" + +class EnqueueHandlerTest : public DeviceFixture, + public testing::Test { + public: + void SetUp() override { + context = new OCLRT::MockContext; + DeviceFixture::SetUp(); + } + + void TearDown() override { + DeviceFixture::TearDown(); + context->decRefInternal(); + } + OCLRT::MockContext *context; +}; diff --git a/unit_tests/helpers/CMakeLists.txt b/unit_tests/helpers/CMakeLists.txt index c461befc5b..0d1901d4eb 100644 --- a/unit_tests/helpers/CMakeLists.txt +++ b/unit_tests/helpers/CMakeLists.txt @@ -39,6 +39,7 @@ set(IGDRCL_SRCS_tests_helpers ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.h ${CMAKE_CURRENT_SOURCE_DIR}/hw_parse.h ${CMAKE_CURRENT_SOURCE_DIR}/kernel_commands_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kernel_filename_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/kmd_notify_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/memory_management_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mipmap_tests.cpp diff --git a/unit_tests/helpers/kernel_filename_helper.h b/unit_tests/helpers/kernel_filename_helper.h new file mode 100644 index 0000000000..7ec28eccd0 --- /dev/null +++ b/unit_tests/helpers/kernel_filename_helper.h @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#pragma once +#include +#include + +class KernelFilenameHelper { + public: + static void getKernelFilenameFromInternalOption(std::string &option, std::string &filename) { + // remove leading spaces + size_t position = option.find_first_not_of(" "); + filename = option.substr(position); + // replace space with underscore + std::replace(filename.begin(), filename.end(), ' ', '_'); + } +}; diff --git a/unit_tests/kernel/debug_kernel_tests.cpp b/unit_tests/kernel/debug_kernel_tests.cpp index b6c0c1662d..aaddc150a9 100644 --- a/unit_tests/kernel/debug_kernel_tests.cpp +++ b/unit_tests/kernel/debug_kernel_tests.cpp @@ -30,35 +30,6 @@ using namespace OCLRT; -class MockDebugKernel : public MockKernel { - public: - MockDebugKernel(Program *program, KernelInfo &kernelInfo, const Device &device) : MockKernel(program, kernelInfo, device) { - if (!kernelInfo.patchInfo.pAllocateSystemThreadSurface) { - SPatchAllocateSystemThreadSurface *patchToken = new SPatchAllocateSystemThreadSurface; - - patchToken->BTI = 0; - patchToken->Offset = 0; - patchToken->PerThreadSystemThreadSurfaceSize = MockDebugKernel::perThreadSystemThreadSurfaceSize; - patchToken->Size = sizeof(SPatchAllocateSystemThreadSurface); - patchToken->Token = iOpenCL::PATCH_TOKEN_ALLOCATE_SIP_SURFACE; - - kernelInfo.patchInfo.pAllocateSystemThreadSurface = patchToken; - - systemThreadSurfaceAllocated = true; - } - } - - ~MockDebugKernel() override { - if (systemThreadSurfaceAllocated) { - delete kernelInfo.patchInfo.pAllocateSystemThreadSurface; - } - } - static const uint32_t perThreadSystemThreadSurfaceSize; - bool systemThreadSurfaceAllocated = false; -}; - -const uint32_t MockDebugKernel::perThreadSystemThreadSurfaceSize = 0x100; - TEST(DebugKernelTest, givenKernelCompiledForDebuggingWhenGetDebugSurfaceBtiIsCalledThenCorrectValueIsReturned) { std::unique_ptr device(new MockDevice(*platformDevices[0])); MockProgram program; diff --git a/unit_tests/mocks/mock_kernel.cpp b/unit_tests/mocks/mock_kernel.cpp index bea0468f27..527dfdb1f6 100644 --- a/unit_tests/mocks/mock_kernel.cpp +++ b/unit_tests/mocks/mock_kernel.cpp @@ -32,6 +32,8 @@ MockKernel::BlockPatchValues MockKernel::ReflectionSurfaceHelperPublic::defaultQ MockKernel::BlockPatchValues MockKernel::ReflectionSurfaceHelperPublic::eventPool; MockKernel::BlockPatchValues MockKernel::ReflectionSurfaceHelperPublic::printfBuffer; +const uint32_t MockDebugKernel::perThreadSystemThreadSurfaceSize = 0x100; + template <> void Kernel::ReflectionSurfaceHelper::patchBlocksCurbe(void *reflectionSurface, uint32_t blockID, uint64_t defaultDeviceQueueCurbeOffset, uint32_t patchSizeDefaultQueue, uint64_t defaultDeviceQueueGpuAddress, diff --git a/unit_tests/mocks/mock_kernel.h b/unit_tests/mocks/mock_kernel.h index 474422dbda..ce7453c27a 100644 --- a/unit_tests/mocks/mock_kernel.h +++ b/unit_tests/mocks/mock_kernel.h @@ -130,7 +130,8 @@ class MockKernel : public Kernel { info->patchInfo.threadPayload = threadPayload; SPatchExecutionEnvironment *executionEnvironment = new SPatchExecutionEnvironment; - executionEnvironment->HasDeviceEnqueue = 1; + memset(executionEnvironment, 0, sizeof(SPatchExecutionEnvironment)); + executionEnvironment->HasDeviceEnqueue = 0; info->patchInfo.executionEnvironment = executionEnvironment; info->crossThreadData = new char[crossThreadSize]; @@ -221,6 +222,10 @@ class MockKernel : public Kernel { return Kernel::patchBufferOffset(argInfo, svmPtr, svmAlloc); } + KernelInfo *getAllocatedKernelInfo() { + return kernelInfoAllocated; + } + std::vector mockCrossThreadData; std::vector mockSshLocal; @@ -541,4 +546,31 @@ class MockSchedulerKernel : public SchedulerKernel { MockSchedulerKernel(Program *programArg, const KernelInfo &kernelInfoArg, const Device &deviceArg) : SchedulerKernel(programArg, kernelInfoArg, deviceArg){}; }; +class MockDebugKernel : public MockKernel { + public: + MockDebugKernel(Program *program, KernelInfo &kernelInfo, const Device &device) : MockKernel(program, kernelInfo, device) { + if (!kernelInfo.patchInfo.pAllocateSystemThreadSurface) { + SPatchAllocateSystemThreadSurface *patchToken = new SPatchAllocateSystemThreadSurface; + + patchToken->BTI = 0; + patchToken->Offset = 0; + patchToken->PerThreadSystemThreadSurfaceSize = MockDebugKernel::perThreadSystemThreadSurfaceSize; + patchToken->Size = sizeof(SPatchAllocateSystemThreadSurface); + patchToken->Token = iOpenCL::PATCH_TOKEN_ALLOCATE_SIP_SURFACE; + + kernelInfo.patchInfo.pAllocateSystemThreadSurface = patchToken; + + systemThreadSurfaceAllocated = true; + } + } + + ~MockDebugKernel() override { + if (systemThreadSurfaceAllocated) { + delete kernelInfo.patchInfo.pAllocateSystemThreadSurface; + } + } + static const uint32_t perThreadSystemThreadSurfaceSize; + bool systemThreadSurfaceAllocated = false; +}; + } // namespace OCLRT diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h index a59fd456af..55e7571e58 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -139,7 +139,7 @@ class WddmMemoryManagerFixtureWithGmockWddm { void SetUp() { // wddm is deleted by memory manager - wddm = new GmockWddm; + wddm = new NiceMock; ASSERT_NE(nullptr, wddm); } @@ -157,7 +157,7 @@ class WddmMemoryManagerFixtureWithGmockWddm { wddm = nullptr; } - GmockWddm *wddm; + NiceMock *wddm; }; typedef ::Test WddmMemoryManagerTest2; diff --git a/unit_tests/program/program_with_kernel_debug_tests.cpp b/unit_tests/program/program_with_kernel_debug_tests.cpp index 297cf8e2ef..8ac108da47 100644 --- a/unit_tests/program/program_with_kernel_debug_tests.cpp +++ b/unit_tests/program/program_with_kernel_debug_tests.cpp @@ -24,6 +24,7 @@ #include "unit_tests/fixtures/program_fixture.h" #include "unit_tests/global_environment.h" #include "unit_tests/helpers/kernel_binary_helper.h" +#include "unit_tests/helpers/kernel_filename_helper.h" #include "unit_tests/mocks/mock_program.h" #include "unit_tests/program/program_tests.h" #include "unit_tests/program/program_from_binary.h" @@ -53,12 +54,9 @@ class ProgramWithKernelDebuggingTest : public ProgramSimpleFixture, ProgramSimpleFixture::SetUp(); device = pDevice; - std::string fullName(CompilerOptions::debugKernelEnable); - // remove leading spaces - size_t position = fullName.find_first_not_of(" "); - std::string filename(fullName, position); - // replace space with underscore - std::replace(filename.begin(), filename.end(), ' ', '_'); + std::string filename; + std::string kernelOption(CompilerOptions::debugKernelEnable); + KernelFilenameHelper::getKernelFilenameFromInternalOption(kernelOption, filename); kbHelper = new KernelBinaryHelper(filename, false); CreateProgramWithSource(