diff --git a/runtime/device/device_caps.cpp b/runtime/device/device_caps.cpp index ad3efd59e9..da1fa82783 100644 --- a/runtime/device/device_caps.cpp +++ b/runtime/device/device_caps.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * 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"), @@ -64,8 +64,8 @@ const char *builtInKernels = ""; // the "always available" (extension-independen void Device::checkPriorityHints() { #ifdef SUPPORT_PRIORITY_HINTS - if (DebugManager.flags.ForcePreemptionMode.get() > PreemptionMode::Disabled || - (preemptionMode >= ThreadGroup)) { + if (static_cast(DebugManager.flags.ForcePreemptionMode.get()) > PreemptionMode::Disabled || + (preemptionMode >= PreemptionMode::ThreadGroup)) { deviceExtensions += "cl_khr_priority_hints "; deviceInfo.priorityHintsSupported = true; } diff --git a/runtime/helpers/hw_info.h b/runtime/helpers/hw_info.h index b214533366..5048a580e3 100644 --- a/runtime/helpers/hw_info.h +++ b/runtime/helpers/hw_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * 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"), @@ -26,7 +26,7 @@ namespace OCLRT { -enum PreemptionMode { +enum class PreemptionMode : uint32_t { // Keep in sync with ForcePreemptionMode debug variable Disabled = 1, MidBatch, diff --git a/runtime/os_interface/windows/wddm.cpp b/runtime/os_interface/windows/wddm.cpp index cb0f479d99..df347c9138 100644 --- a/runtime/os_interface/windows/wddm.cpp +++ b/runtime/os_interface/windows/wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * 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"), @@ -265,7 +265,7 @@ bool Wddm::createDevice() { if (adapter) { CreateDevice.hAdapter = adapter; CreateDevice.Flags.LegacyMode = FALSE; - if (DebugManager.flags.ForcePreemptionMode.get() != PreemptionMode::Disabled) { + if (static_cast(DebugManager.flags.ForcePreemptionMode.get()) != PreemptionMode::Disabled) { CreateDevice.Flags.DisableGpuTimeout = readEnablePreemptionRegKey(); } diff --git a/unit_tests/fixtures/CMakeLists.txt b/unit_tests/fixtures/CMakeLists.txt index b6d0e9a525..84362dc159 100644 --- a/unit_tests/fixtures/CMakeLists.txt +++ b/unit_tests/fixtures/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017, Intel Corporation +# 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"), @@ -48,6 +48,8 @@ set(IGDRCL_SRCS_tests_fixtures "${CMAKE_CURRENT_SOURCE_DIR}/memory_management_fixture.h" "${CMAKE_CURRENT_SOURCE_DIR}/platform_fixture.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/platform_fixture.h" + "${CMAKE_CURRENT_SOURCE_DIR}/preemption_fixture.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/preemption_fixture.h" "${CMAKE_CURRENT_SOURCE_DIR}/program_fixture.h" "${CMAKE_CURRENT_SOURCE_DIR}/program_fixture.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/run_kernel_fixture.h" diff --git a/unit_tests/fixtures/preemption_fixture.cpp b/unit_tests/fixtures/preemption_fixture.cpp new file mode 100644 index 0000000000..c7ef548294 --- /dev/null +++ b/unit_tests/fixtures/preemption_fixture.cpp @@ -0,0 +1,114 @@ +/* + * 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 "unit_tests/fixtures/preemption_fixture.h" + +#include "runtime/command_stream/preemption.h" +#include "runtime/command_queue/enqueue_common.h" +#include "runtime/command_queue/enqueue_kernel.h" +#include "runtime/command_queue/enqueue_marker.h" +#include "runtime/helpers/dispatch_info.h" +#include "runtime/helpers/hw_info.h" +#include "runtime/scheduler/scheduler_kernel.h" +#include "unit_tests/fixtures/hello_world_fixture.h" +#include "unit_tests/helpers/hw_parse.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/mocks/mock_kernel.h" +#include "unit_tests/mocks/mock_command_queue.h" +#include "unit_tests/mocks/mock_context.h" +#include "unit_tests/mocks/mock_device.h" + +#include "gtest/gtest.h" +#include "test.h" + +using namespace OCLRT; + +DevicePreemptionTests::DevicePreemptionTests() = default; +DevicePreemptionTests::~DevicePreemptionTests() = default; + +void DevicePreemptionTests::SetUp() { + if (dbgRestore == nullptr) { + dbgRestore.reset(new DebugManagerStateRestore()); + } + const cl_queue_properties properties[3] = {CL_QUEUE_PROPERTIES, 0, 0}; + kernelInfo.reset(KernelInfo::create()); + device.reset(MockDevice::create(nullptr, false)); + context.reset(new MockContext(device.get())); + cmdQ.reset(new MockCommandQueue(context.get(), device.get(), properties)); + executionEnvironment.reset(new SPatchExecutionEnvironment); + memset(executionEnvironment.get(), 0, sizeof(SPatchExecutionEnvironment)); + kernelInfo->patchInfo.executionEnvironment = executionEnvironment.get(); + program.reset(new MockProgram); + kernel.reset(new MockKernel(program.get(), *kernelInfo, *device)); + dispatchInfo.reset(new DispatchInfo(kernel.get(), 1, Vec3(1, 1, 1), Vec3(1, 1, 1), Vec3(0, 0, 0))); + + ASSERT_NE(nullptr, device); + ASSERT_NE(nullptr, context); + ASSERT_NE(nullptr, cmdQ); + forceWhitelistedRegs(true); + waTable = const_cast(device->getWaTable()); +} + +void DevicePreemptionTests::TearDown() { + dbgRestore.reset(); + kernel.reset(); + kernelInfo.reset(); + dispatchInfo.reset(); + cmdQ.reset(); + context.reset(); + device.reset(); +} + +void DevicePreemptionTests::forceWhitelistedRegs(bool whitelisted) { + WhitelistedRegisters forceRegs = {whitelisted}; + device->setForceWhitelistedRegs(true, &forceRegs); +} + +void ThreadGroupPreemptionEnqueueKernelTest::SetUp() { + globalHwInfo = const_cast(platformDevices[0]); + originalPreemptionMode = globalHwInfo->capabilityTable.defaultPreemptionMode; + globalHwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::ThreadGroup; + + HelloWorldFixture::SetUp(); + pDevice->setPreemptionMode(PreemptionMode::ThreadGroup); +} + +void ThreadGroupPreemptionEnqueueKernelTest::TearDown() { + globalHwInfo->capabilityTable.defaultPreemptionMode = originalPreemptionMode; + + HelloWorldFixture::TearDown(); +} + +void MidThreadPreemptionEnqueueKernelTest::SetUp() { + globalHwInfo = const_cast(platformDevices[0]); + originalPreemptionMode = globalHwInfo->capabilityTable.defaultPreemptionMode; + globalHwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; + + HelloWorldFixture::SetUp(); + pDevice->setPreemptionMode(PreemptionMode::MidThread); +} + +void MidThreadPreemptionEnqueueKernelTest::TearDown() { + globalHwInfo->capabilityTable.defaultPreemptionMode = originalPreemptionMode; + + HelloWorldFixture::TearDown(); +} diff --git a/unit_tests/fixtures/preemption_fixture.h b/unit_tests/fixtures/preemption_fixture.h new file mode 100644 index 0000000000..ad4ff0dc20 --- /dev/null +++ b/unit_tests/fixtures/preemption_fixture.h @@ -0,0 +1,92 @@ +/* + * 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/hello_world_fixture.h" +#include "unit_tests/gen_common/test.h" + +#include "gtest/gtest.h" + +#include +#include + +namespace iOpenCL { +struct SPatchExecutionEnvironment; +} + +namespace OCLRT { +enum class PreemptionMode : uint32_t; +class DispatchInfo; +class MockCommandQueue; +class MockContext; +class MockDevice; +class MockKernel; +class MockProgram; +struct KernelInfo; +struct WorkaroundTable; + +using PreemptionEnqueueKernelFixture = HelloWorldFixture; +using PreemptionEnqueueKernelTest = Test; +} + +class DebugManagerStateRestore; + +class DevicePreemptionTests : public ::testing::Test { + public: + void SetUp() override; + void TearDown() override; + void forceWhitelistedRegs(bool whitelisted); + + DevicePreemptionTests(); + ~DevicePreemptionTests() override; + + OCLRT::PreemptionMode preemptionMode; + OCLRT::WorkaroundTable *waTable = nullptr; + std::unique_ptr dispatchInfo; + std::unique_ptr kernel; + std::unique_ptr cmdQ; + std::unique_ptr device; + std::unique_ptr context; + std::unique_ptr dbgRestore; + std::unique_ptr executionEnvironment; + std::unique_ptr program; + std::unique_ptr kernelInfo; +}; + +struct ThreadGroupPreemptionEnqueueKernelTest : OCLRT::PreemptionEnqueueKernelTest { + void SetUp() override; + + void TearDown() override; + + OCLRT::HardwareInfo *globalHwInfo; + OCLRT::PreemptionMode originalPreemptionMode; +}; + +struct MidThreadPreemptionEnqueueKernelTest : OCLRT::PreemptionEnqueueKernelTest { + void SetUp() override; + + void TearDown() override; + + OCLRT::HardwareInfo *globalHwInfo; + OCLRT::PreemptionMode originalPreemptionMode; +}; diff --git a/unit_tests/gen8/test_preemption.cpp b/unit_tests/gen8/test_preemption.cpp index b502b9af4b..76d33f01fd 100644 --- a/unit_tests/gen8/test_preemption.cpp +++ b/unit_tests/gen8/test_preemption.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * 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"), @@ -20,13 +20,15 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/command_stream/preemption.h" #include "unit_tests/command_queue/enqueue_fixture.h" #include "unit_tests/helpers/hw_parse.h" #include "unit_tests/fixtures/hello_world_fixture.h" +#include "unit_tests/fixtures/preemption_fixture.h" +#include "unit_tests/mocks/mock_command_queue.h" #include "unit_tests/mocks/mock_csr.h" #include "unit_tests/mocks/mock_buffer.h" #include "unit_tests/mocks/mock_submissions_aggregator.h" -#include "unit_tests/preemption/preemption_tests.h" using namespace OCLRT; @@ -41,7 +43,7 @@ GEN8TEST_F(Gen8PreemptionTests, programThreadGroupPreemptionLri) { EXPECT_EQ(expectedSize, requiredSize); auto &cmdStream = cmdQ->getCS(requiredSize); - EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); + EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); PreemptionHelper::programPreemptionMode(&cmdStream, preemptionMode, nullptr, nullptr); EXPECT_EQ(sizeof(MI_LOAD_REGISTER_IMM), cmdStream.getUsed()); @@ -61,7 +63,7 @@ GEN8TEST_F(Gen8PreemptionTests, programMidBatchPreemptionLri) { auto &cmdStream = cmdQ->getCS(requiredSize); - EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); + EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); PreemptionHelper::programPreemptionMode(&cmdStream, preemptionMode, nullptr, nullptr); EXPECT_EQ(requiredSize, cmdStream.getUsed()); @@ -81,7 +83,7 @@ GEN8TEST_F(Gen8PreemptionTests, programPreemptionLri) { auto &cmdStream = cmdQ->getCS(requiredSize); device->setPreemptionMode(preemptionMode); - EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); + EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); PreemptionHelper::programPreemptionMode(&cmdStream, preemptionMode, nullptr, nullptr); EXPECT_EQ(requiredSize, cmdStream.getUsed()); diff --git a/unit_tests/gen9/test_preemption.cpp b/unit_tests/gen9/test_preemption.cpp index b22badf9ec..39c87e493c 100644 --- a/unit_tests/gen9/test_preemption.cpp +++ b/unit_tests/gen9/test_preemption.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * 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"), @@ -20,12 +20,14 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/command_stream/preemption.h" #include "unit_tests/command_queue/enqueue_fixture.h" +#include "unit_tests/fixtures/preemption_fixture.h" #include "unit_tests/helpers/hw_parse.h" +#include "unit_tests/mocks/mock_command_queue.h" #include "unit_tests/mocks/mock_csr.h" #include "unit_tests/mocks/mock_buffer.h" #include "unit_tests/mocks/mock_submissions_aggregator.h" -#include "unit_tests/preemption/preemption_tests.h" namespace OCLRT { @@ -55,7 +57,7 @@ GEN9TEST_F(Gen9PreemptionTests, programThreadGroupPreemptionLri) { auto &cmdStream = cmdQ->getCS(requiredSize); - EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); + EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); PreemptionHelper::programPreemptionMode(&cmdStream, preemptionMode, nullptr, nullptr); EXPECT_EQ(requiredSize, cmdStream.getUsed()); @@ -72,7 +74,7 @@ GEN9TEST_F(Gen9PreemptionTests, programMidBatchPreemptionLri) { size_t expectedSize = sizeof(MI_LOAD_REGISTER_IMM); EXPECT_EQ(expectedSize, requiredSize); auto &cmdStream = cmdQ->getCS(requiredSize); - EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); + EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); PreemptionHelper::programPreemptionMode(&cmdStream, preemptionMode, nullptr, nullptr); EXPECT_EQ(requiredSize, cmdStream.getUsed()); @@ -94,10 +96,10 @@ GEN9TEST_F(Gen9PreemptionTests, programMidThreadPreemptionLri) { size_t minSize = device->getHardwareInfo().pSysInfo->CsrSizeInMb * MemoryConstants::megaByte; uint64_t minAlignment = 2 * 256 * MemoryConstants::kiloByte; MockGraphicsAllocation csrSurface((void *)minAlignment, minSize); - executionEnvironment.DisableMidThreadPreemption = 0; + executionEnvironment->DisableMidThreadPreemption = 0; device->setPreemptionMode(preemptionMode); - EXPECT_TRUE(PreemptionHelper::allowMidThreadPreemption(kernel, *device)); + EXPECT_TRUE(PreemptionHelper::allowMidThreadPreemption(kernel.get(), *device)); PreemptionHelper::programPreemptionMode(&cmdStream, preemptionMode, &csrSurface, nullptr); EXPECT_EQ(requiredSize, cmdStream.getUsed()); diff --git a/unit_tests/preemption/CMakeLists.txt b/unit_tests/preemption/CMakeLists.txt index adee56070a..7915071c3a 100644 --- a/unit_tests/preemption/CMakeLists.txt +++ b/unit_tests/preemption/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017, Intel Corporation +# 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"), @@ -21,6 +21,5 @@ set(IGDRCL_SRCS_tests_preemption "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt" "${CMAKE_CURRENT_SOURCE_DIR}/preemption_tests.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/preemption_tests.h" PARENT_SCOPE ) diff --git a/unit_tests/preemption/preemption_tests.cpp b/unit_tests/preemption/preemption_tests.cpp index 97a4b8ffdd..4dbef9aef5 100644 --- a/unit_tests/preemption/preemption_tests.cpp +++ b/unit_tests/preemption/preemption_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * 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"), @@ -20,14 +20,19 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include "unit_tests/preemption/preemption_tests.h" +#include "runtime/command_stream/preemption.h" #include "runtime/helpers/options.h" +#include "unit_tests/fixtures/preemption_fixture.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/helpers/hw_parse.h" +#include "unit_tests/mocks/mock_device.h" +#include "unit_tests/mocks/mock_kernel.h" using namespace OCLRT; class ThreadGroupPreemptionTests : public DevicePreemptionTests { void SetUp() override { - dbgRestore = new DebugManagerStateRestore(); + dbgRestore.reset(new DebugManagerStateRestore()); DebugManager.flags.ForcePreemptionMode.set(static_cast(PreemptionMode::ThreadGroup)); preemptionMode = PreemptionMode::ThreadGroup; DevicePreemptionTests::SetUp(); @@ -36,7 +41,7 @@ class ThreadGroupPreemptionTests : public DevicePreemptionTests { class MidThreadPreemptionTests : public DevicePreemptionTests { void SetUp() override { - dbgRestore = new DebugManagerStateRestore(); + dbgRestore.reset(new DebugManagerStateRestore()); DebugManager.flags.ForcePreemptionMode.set(static_cast(PreemptionMode::MidThread)); preemptionMode = PreemptionMode::MidThread; DevicePreemptionTests::SetUp(); @@ -46,45 +51,43 @@ class MidThreadPreemptionTests : public DevicePreemptionTests { TEST_F(ThreadGroupPreemptionTests, disallowByKMD) { waTable->waDisablePerCtxtPreemptionGranularityControl = 1; - EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); - EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel)); + EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); + EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel.get())); } TEST_F(ThreadGroupPreemptionTests, disallowByDevice) { device->setPreemptionMode(PreemptionMode::MidThread); - EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); - EXPECT_EQ(PreemptionMode::MidThread, PreemptionHelper::taskPreemptionMode(*device, kernel)); + EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); + EXPECT_EQ(PreemptionMode::MidThread, PreemptionHelper::taskPreemptionMode(*device, kernel.get())); } TEST_F(ThreadGroupPreemptionTests, disallowByReadWriteFencesWA) { - executionEnvironment.UsesFencesForReadWriteImages = 1u; + executionEnvironment->UsesFencesForReadWriteImages = 1u; waTable->waDisableLSQCROPERFforOCL = 1; - EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); - EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel)); + EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); + EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel.get())); } TEST_F(ThreadGroupPreemptionTests, disallowBySchedulerKernel) { - delete kernel; - kernel = new MockKernel(&program, *kernelInfo, *device, true); + kernel.reset(new MockKernel(program.get(), *kernelInfo, *device, true)); - EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); - EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel)); + EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); + EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel.get())); } TEST_F(ThreadGroupPreemptionTests, disallowByVmeKernel) { - delete kernel; kernelInfo->isVmeWorkload = true; - kernel = new MockKernel(&program, *kernelInfo, *device); + kernel.reset(new MockKernel(program.get(), *kernelInfo, *device)); - EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); - EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel)); + EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); + EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel.get())); } TEST_F(ThreadGroupPreemptionTests, simpleAllow) { - EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable)); - EXPECT_EQ(PreemptionMode::ThreadGroup, PreemptionHelper::taskPreemptionMode(*device, kernel)); + EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel.get(), waTable)); + EXPECT_EQ(PreemptionMode::ThreadGroup, PreemptionHelper::taskPreemptionMode(*device, kernel.get())); } TEST_F(ThreadGroupPreemptionTests, allowDefaultModeForNonKernelRequest) { @@ -122,7 +125,7 @@ TEST_F(ThreadGroupPreemptionTests, disallowDefaultDeviceModeForValidKernelsInMdi } TEST_F(ThreadGroupPreemptionTests, disallowDefaultDeviceModeWhenAtLeastOneInvalidKernelInMdi) { - MockKernel schedulerKernel(&program, *kernelInfo, *device, true); + MockKernel schedulerKernel(program.get(), *kernelInfo, *device, true); DispatchInfo schedulerDispatchInfo(&schedulerKernel, 1, Vec3(1, 1, 1), Vec3(1, 1, 1), Vec3(0, 0, 0)); EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, &schedulerKernel)); @@ -137,8 +140,8 @@ TEST_F(ThreadGroupPreemptionTests, disallowDefaultDeviceModeWhenAtLeastOneInvali TEST_F(MidThreadPreemptionTests, allowMidThreadPreemption) { device->setPreemptionMode(PreemptionMode::MidThread); - executionEnvironment.DisableMidThreadPreemption = 0; - EXPECT_TRUE(PreemptionHelper::allowMidThreadPreemption(kernel, *device)); + executionEnvironment->DisableMidThreadPreemption = 0; + EXPECT_TRUE(PreemptionHelper::allowMidThreadPreemption(kernel.get(), *device)); } TEST_F(MidThreadPreemptionTests, allowMidThreadPreemptionNullKernel) { @@ -149,73 +152,69 @@ TEST_F(MidThreadPreemptionTests, allowMidThreadPreemptionNullKernel) { TEST_F(MidThreadPreemptionTests, allowMidThreadPreemptionDeviceSupportPreemptionOnVmeKernel) { device->setPreemptionMode(PreemptionMode::MidThread); device->getMutableDeviceInfo()->vmeAvcSupportsPreemption = true; - delete kernel; kernelInfo->isVmeWorkload = true; - kernel = new MockKernel(&program, *kernelInfo, *device); - EXPECT_TRUE(PreemptionHelper::allowMidThreadPreemption(kernel, *device)); + kernel.reset(new MockKernel(program.get(), *kernelInfo, *device)); + EXPECT_TRUE(PreemptionHelper::allowMidThreadPreemption(kernel.get(), *device)); } TEST_F(MidThreadPreemptionTests, disallowMidThreadPreemptionByDevice) { device->setPreemptionMode(PreemptionMode::ThreadGroup); - executionEnvironment.DisableMidThreadPreemption = 0; - EXPECT_FALSE(PreemptionHelper::allowMidThreadPreemption(kernel, *device)); + executionEnvironment->DisableMidThreadPreemption = 0; + EXPECT_FALSE(PreemptionHelper::allowMidThreadPreemption(kernel.get(), *device)); } TEST_F(MidThreadPreemptionTests, disallowMidThreadPreemptionByKernel) { device->setPreemptionMode(PreemptionMode::MidThread); - executionEnvironment.DisableMidThreadPreemption = 1; - EXPECT_FALSE(PreemptionHelper::allowMidThreadPreemption(kernel, *device)); + executionEnvironment->DisableMidThreadPreemption = 1; + EXPECT_FALSE(PreemptionHelper::allowMidThreadPreemption(kernel.get(), *device)); } TEST_F(MidThreadPreemptionTests, disallowMidThreadPreemptionByVmeKernel) { device->setPreemptionMode(PreemptionMode::MidThread); device->getMutableDeviceInfo()->vmeAvcSupportsPreemption = false; - delete kernel; kernelInfo->isVmeWorkload = true; - kernel = new MockKernel(&program, *kernelInfo, *device); - EXPECT_FALSE(PreemptionHelper::allowMidThreadPreemption(kernel, *device)); + kernel.reset(new MockKernel(program.get(), *kernelInfo, *device)); + EXPECT_FALSE(PreemptionHelper::allowMidThreadPreemption(kernel.get(), *device)); } TEST_F(MidThreadPreemptionTests, taskPreemptionDisallowMidThreadByDevice) { - executionEnvironment.DisableMidThreadPreemption = 0; + executionEnvironment->DisableMidThreadPreemption = 0; device->setPreemptionMode(PreemptionMode::ThreadGroup); - PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel); + PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel.get()); EXPECT_EQ(PreemptionMode::ThreadGroup, outMode); } TEST_F(MidThreadPreemptionTests, taskPreemptionDisallowMidThreadByKernel) { - executionEnvironment.DisableMidThreadPreemption = 1; + executionEnvironment->DisableMidThreadPreemption = 1; device->setPreemptionMode(PreemptionMode::MidThread); - PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel); + PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel.get()); EXPECT_EQ(PreemptionMode::ThreadGroup, outMode); } TEST_F(MidThreadPreemptionTests, taskPreemptionDisallowMidThreadByVmeKernel) { - delete kernel; kernelInfo->isVmeWorkload = true; device->getMutableDeviceInfo()->vmeAvcSupportsPreemption = false; - kernel = new MockKernel(&program, *kernelInfo, *device); + kernel.reset(new MockKernel(program.get(), *kernelInfo, *device)); device->setPreemptionMode(PreemptionMode::MidThread); - PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel); + PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel.get()); //VME disables mid thread and thread group when device does not support it EXPECT_EQ(PreemptionMode::MidBatch, outMode); } TEST_F(MidThreadPreemptionTests, taskPreemptionAllow) { - executionEnvironment.DisableMidThreadPreemption = 0; + executionEnvironment->DisableMidThreadPreemption = 0; device->setPreemptionMode(PreemptionMode::MidThread); - PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel); + PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel.get()); EXPECT_EQ(PreemptionMode::MidThread, outMode); } TEST_F(MidThreadPreemptionTests, taskPreemptionAllowDeviceSupportsPreemptionOnVmeKernel) { - executionEnvironment.DisableMidThreadPreemption = 0; - delete kernel; + executionEnvironment->DisableMidThreadPreemption = 0; kernelInfo->isVmeWorkload = true; - kernel = new MockKernel(&program, *kernelInfo, *device); + kernel.reset(new MockKernel(program.get(), *kernelInfo, *device)); device->getMutableDeviceInfo()->vmeAvcSupportsPreemption = true; device->setPreemptionMode(PreemptionMode::MidThread); - PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel); + PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel.get()); EXPECT_EQ(PreemptionMode::MidThread, outMode); } diff --git a/unit_tests/preemption/preemption_tests.h b/unit_tests/preemption/preemption_tests.h deleted file mode 100644 index ce2c679bab..0000000000 --- a/unit_tests/preemption/preemption_tests.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2017, 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 "gtest/gtest.h" -#include "test.h" -#include "runtime/command_stream/preemption.h" -#include "runtime/helpers/dispatch_info.h" -#include "runtime/helpers/hw_info.h" -#include "runtime/scheduler/scheduler_kernel.h" -#include "runtime/command_queue/enqueue_common.h" -#include "runtime/command_queue/enqueue_kernel.h" -#include "runtime/command_queue/enqueue_marker.h" - -#include "unit_tests/mocks/mock_kernel.h" -#include "unit_tests/mocks/mock_command_queue.h" -#include "unit_tests/mocks/mock_context.h" -#include "unit_tests/mocks/mock_device.h" -#include "unit_tests/helpers/hw_parse.h" -#include "unit_tests/helpers/debug_manager_state_restore.h" -#include "unit_tests/fixtures/hello_world_fixture.h" - -namespace OCLRT { -class DevicePreemptionTests : public ::testing::Test { - public: - void SetUp() override { - const cl_queue_properties properties[3] = {CL_QUEUE_PROPERTIES, 0, 0}; - kernelInfo = KernelInfo::create(); - device = MockDevice::create(nullptr, false); - context = new MockContext(device); - cmdQ = new MockCommandQueue(context, device, properties); - memset(&executionEnvironment, 0, sizeof(SPatchExecutionEnvironment)); - kernelInfo->patchInfo.executionEnvironment = &executionEnvironment; - kernel = new MockKernel(&program, *kernelInfo, *device); - dispatchInfo = new DispatchInfo(kernel, 1, Vec3(1, 1, 1), Vec3(1, 1, 1), Vec3(0, 0, 0)); - - ASSERT_NE(nullptr, device); - ASSERT_NE(nullptr, context); - ASSERT_NE(nullptr, cmdQ); - forceWhitelistedRegs(true); - waTable = const_cast(device->getWaTable()); - } - void TearDown() override { - if (dbgRestore) { - delete dbgRestore; - } - delete kernel; - delete kernelInfo; - delete dispatchInfo; - delete cmdQ; - delete context; - delete device; - } - void forceWhitelistedRegs(bool whitelisted) { - WhitelistedRegisters forceRegs = {whitelisted}; - device->setForceWhitelistedRegs(true, &forceRegs); - } - - PreemptionMode preemptionMode; - DispatchInfo *dispatchInfo; - MockKernel *kernel; - MockCommandQueue *cmdQ; - MockDevice *device; - MockContext *context; - DebugManagerStateRestore *dbgRestore = nullptr; - WorkaroundTable *waTable = nullptr; - SPatchExecutionEnvironment executionEnvironment; - MockProgram program; - KernelInfo *kernelInfo; -}; - -typedef HelloWorldFixture PreemptionEnqueueKernelFixture; -typedef Test PreemptionEnqueueKernelTest; - -struct ThreadGroupPreemptionEnqueueKernelTest : PreemptionEnqueueKernelTest { - void SetUp() override { - globalHwInfo = const_cast(platformDevices[0]); - originalPreemptionMode = globalHwInfo->capabilityTable.defaultPreemptionMode; - globalHwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::ThreadGroup; - - HelloWorldFixture::SetUp(); - pDevice->setPreemptionMode(PreemptionMode::ThreadGroup); - } - - void TearDown() override { - globalHwInfo->capabilityTable.defaultPreemptionMode = originalPreemptionMode; - - HelloWorldFixture::TearDown(); - } - - HardwareInfo *globalHwInfo; - PreemptionMode originalPreemptionMode; -}; - -struct MidThreadPreemptionEnqueueKernelTest : PreemptionEnqueueKernelTest { - void SetUp() override { - globalHwInfo = const_cast(platformDevices[0]); - originalPreemptionMode = globalHwInfo->capabilityTable.defaultPreemptionMode; - globalHwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; - - HelloWorldFixture::SetUp(); - pDevice->setPreemptionMode(PreemptionMode::MidThread); - } - - void TearDown() override { - globalHwInfo->capabilityTable.defaultPreemptionMode = originalPreemptionMode; - - HelloWorldFixture::TearDown(); - } - - HardwareInfo *globalHwInfo; - PreemptionMode originalPreemptionMode; -}; - -} // namespace OCLRT