mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-19 06:24:51 +08:00
Kernel Source Level debugger support 4/n
- adding DebugSurface allocation and setup
- unit tests refactors:
- mock kernel with kernel debug option
- separating fixtures to headers
- added helper for getting internal-options kernels
filenames
Change-Id: I7b6f4d46e2ab7cff0da8d5212483f44ae0d4be31
This commit is contained in:
committed by
sys_ocldev
parent
7b1fd38fe6
commit
7f32eb06d1
@@ -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<uintptr_t *>(kernel->getSurfaceStateHeap()),
|
||||
kernel->getKernelInfo().patchInfo.pAllocateSystemThreadSurface->Offset);
|
||||
void *addressToPatch = reinterpret_cast<void *>(debugSurface->getGpuAddress());
|
||||
size_t sizeToPatch = debugSurface->getUnderlyingBufferSize();
|
||||
Buffer::setSurfaceState(context, surfaceState, sizeToPatch, addressToPatch, debugSurface);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -216,6 +216,12 @@ void CommandQueueHw<GfxFamily>::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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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> osInterface;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<MockDebugKernel> kernel(MockKernel::create<MockDebugKernel>(*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<MockDebugKernel> kernel(MockKernel::create<MockDebugKernel>(*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());
|
||||
}
|
||||
|
||||
157
unit_tests/command_queue/enqueue_debug_kernel_tests.cpp
Normal file
157
unit_tests/command_queue/enqueue_debug_kernel_tests.cpp
Normal file
@@ -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<MockCommandQueueHw<FamilyType>> mockCmdQ(new MockCommandQueueHw<FamilyType>(&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<BINDING_TABLE_STATE *>(ptrOffset(surfaceStates, debugKernel->getBindingTableOffset()));
|
||||
uint32_t surfaceStateOffset = dstBtiTableBase[0].getSurfaceStatePointer();
|
||||
|
||||
auto debugSurfaceState = reinterpret_cast<RENDER_SURFACE_STATE *>(ptrOffset(ssh.getCpuBase(), surfaceStateOffset));
|
||||
|
||||
auto &commandStreamReceiver = pDevice->getCommandStreamReceiver();
|
||||
auto debugSurface = commandStreamReceiver.getDebugSurfaceAllocation();
|
||||
|
||||
EXPECT_EQ(debugSurface->getGpuAddress(), debugSurfaceState->getSurfaceBaseAddress());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename GfxFamily>
|
||||
class GMockCommandQueueHw : public CommandQueueHw<GfxFamily> {
|
||||
typedef CommandQueueHw<GfxFamily> 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<MockDebugKernel> kernel(MockKernel::create<MockDebugKernel>(*pDevice, &program));
|
||||
std::unique_ptr<GMockCommandQueueHw<FamilyType>> mockCmdQ(new GMockCommandQueueHw<FamilyType>(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<MockDebugKernel> kernel(MockKernel::create<MockDebugKernel>(*pDevice, &program));
|
||||
std::unique_ptr<NiceMock<GMockCommandQueueHw<FamilyType>>> mockCmdQ(new NiceMock<GMockCommandQueueHw<FamilyType>>(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);
|
||||
}
|
||||
@@ -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<FamilyType>(tag);
|
||||
|
||||
@@ -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<FamilyType>();
|
||||
EXPECT_EQ(CommandStreamReceiver::DispatchMode::ImmediateDispatch, csr.dispatchMode);
|
||||
|
||||
@@ -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
|
||||
|
||||
40
unit_tests/fixtures/enqueue_handler_fixture.h
Normal file
40
unit_tests/fixtures/enqueue_handler_fixture.h
Normal file
@@ -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;
|
||||
};
|
||||
@@ -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
|
||||
|
||||
36
unit_tests/helpers/kernel_filename_helper.h
Normal file
36
unit_tests/helpers/kernel_filename_helper.h
Normal file
@@ -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 <algorithm>
|
||||
#include <string>
|
||||
|
||||
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(), ' ', '_');
|
||||
}
|
||||
};
|
||||
@@ -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<MockDevice> device(new MockDevice(*platformDevices[0]));
|
||||
MockProgram program;
|
||||
|
||||
@@ -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<true>(void *reflectionSurface, uint32_t blockID,
|
||||
uint64_t defaultDeviceQueueCurbeOffset, uint32_t patchSizeDefaultQueue, uint64_t defaultDeviceQueueGpuAddress,
|
||||
|
||||
@@ -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<char> mockCrossThreadData;
|
||||
std::vector<char> 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
|
||||
|
||||
@@ -139,7 +139,7 @@ class WddmMemoryManagerFixtureWithGmockWddm {
|
||||
|
||||
void SetUp() {
|
||||
// wddm is deleted by memory manager
|
||||
wddm = new GmockWddm;
|
||||
wddm = new NiceMock<GmockWddm>;
|
||||
ASSERT_NE(nullptr, wddm);
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ class WddmMemoryManagerFixtureWithGmockWddm {
|
||||
wddm = nullptr;
|
||||
}
|
||||
|
||||
GmockWddm *wddm;
|
||||
NiceMock<GmockWddm> *wddm;
|
||||
};
|
||||
|
||||
typedef ::Test<WddmMemoryManagerFixtureWithGmockWddm> WddmMemoryManagerTest2;
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user