mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Refactoring preemption fixture
Change-Id: I7f520a591a251d68fb3443d221ab8b628a450398
This commit is contained in:

committed by
sys_ocldev

parent
4e9c1178a3
commit
c838a7dfc6
@ -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"
|
||||
|
114
unit_tests/fixtures/preemption_fixture.cpp
Normal file
114
unit_tests/fixtures/preemption_fixture.cpp
Normal file
@ -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<OCLRT::MockDevice>(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<size_t>(1, 1, 1), Vec3<size_t>(1, 1, 1), Vec3<size_t>(0, 0, 0)));
|
||||
|
||||
ASSERT_NE(nullptr, device);
|
||||
ASSERT_NE(nullptr, context);
|
||||
ASSERT_NE(nullptr, cmdQ);
|
||||
forceWhitelistedRegs(true);
|
||||
waTable = const_cast<WorkaroundTable *>(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<HardwareInfo *>(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<HardwareInfo *>(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();
|
||||
}
|
92
unit_tests/fixtures/preemption_fixture.h
Normal file
92
unit_tests/fixtures/preemption_fixture.h
Normal file
@ -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 <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
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<HelloWorldFixtureFactory>;
|
||||
using PreemptionEnqueueKernelTest = Test<PreemptionEnqueueKernelFixture>;
|
||||
}
|
||||
|
||||
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<OCLRT::DispatchInfo> dispatchInfo;
|
||||
std::unique_ptr<OCLRT::MockKernel> kernel;
|
||||
std::unique_ptr<OCLRT::MockCommandQueue> cmdQ;
|
||||
std::unique_ptr<OCLRT::MockDevice> device;
|
||||
std::unique_ptr<OCLRT::MockContext> context;
|
||||
std::unique_ptr<DebugManagerStateRestore> dbgRestore;
|
||||
std::unique_ptr<iOpenCL::SPatchExecutionEnvironment> executionEnvironment;
|
||||
std::unique_ptr<OCLRT::MockProgram> program;
|
||||
std::unique_ptr<OCLRT::KernelInfo> 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;
|
||||
};
|
@ -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<FamilyType>(&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<FamilyType>(&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<FamilyType>(&cmdStream, preemptionMode, nullptr, nullptr);
|
||||
EXPECT_EQ(requiredSize, cmdStream.getUsed());
|
||||
|
@ -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<FamilyType>(&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<FamilyType>(&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<FamilyType>(&cmdStream, preemptionMode, &csrSurface, nullptr);
|
||||
EXPECT_EQ(requiredSize, cmdStream.getUsed());
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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<int32_t>(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<int32_t>(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<size_t>(1, 1, 1), Vec3<size_t>(1, 1, 1), Vec3<size_t>(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);
|
||||
}
|
||||
|
||||
|
@ -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<OCLRT::MockDevice>(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<size_t>(1, 1, 1), Vec3<size_t>(1, 1, 1), Vec3<size_t>(0, 0, 0));
|
||||
|
||||
ASSERT_NE(nullptr, device);
|
||||
ASSERT_NE(nullptr, context);
|
||||
ASSERT_NE(nullptr, cmdQ);
|
||||
forceWhitelistedRegs(true);
|
||||
waTable = const_cast<WorkaroundTable *>(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<HelloWorldFixtureFactory> PreemptionEnqueueKernelFixture;
|
||||
typedef Test<PreemptionEnqueueKernelFixture> PreemptionEnqueueKernelTest;
|
||||
|
||||
struct ThreadGroupPreemptionEnqueueKernelTest : PreemptionEnqueueKernelTest {
|
||||
void SetUp() override {
|
||||
globalHwInfo = const_cast<HardwareInfo *>(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<HardwareInfo *>(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
|
Reference in New Issue
Block a user