Initial commit

Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
Brandon Fliflet
2017-12-21 00:45:38 +01:00
commit 7e9ad41290
1350 changed files with 233156 additions and 0 deletions

View File

@ -0,0 +1,26 @@
# 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.
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
)

View File

@ -0,0 +1,231 @@
/*
* 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.
*/
#include "unit_tests/preemption/preemption_tests.h"
using namespace OCLRT;
typedef DevicePreemptionTests ThreadGroupPreemptionTests;
typedef DevicePreemptionTests MidThreadPreemptionTests;
TEST_F(ThreadGroupPreemptionTests, disallowByKMD) {
waTable->waDisablePerCtxtPreemptionGranularityControl = 1;
EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable));
EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel));
}
TEST_F(ThreadGroupPreemptionTests, disallowByDevice) {
device->setPreemptionMode(PreemptionMode::MidThread);
EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable));
EXPECT_EQ(PreemptionMode::MidThread, PreemptionHelper::taskPreemptionMode(*device, kernel));
}
TEST_F(ThreadGroupPreemptionTests, disallowByReadWriteFencesWA) {
executionEnvironment.UsesFencesForReadWriteImages = 1u;
waTable->waDisableLSQCROPERFforOCL = 1;
EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable));
EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel));
}
TEST_F(ThreadGroupPreemptionTests, disallowBySchedulerKernel) {
delete kernel;
kernel = new MockKernel(&program, *kernelInfo, *device, true);
EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable));
EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel));
}
TEST_F(ThreadGroupPreemptionTests, disallowByVmeKernel) {
delete kernel;
kernelInfo->isVmeWorkload = true;
kernel = new MockKernel(&program, *kernelInfo, *device);
EXPECT_FALSE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable));
EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, kernel));
}
TEST_F(ThreadGroupPreemptionTests, simpleAllow) {
EXPECT_TRUE(PreemptionHelper::allowThreadGroupPreemption(kernel, waTable));
EXPECT_EQ(PreemptionMode::ThreadGroup, PreemptionHelper::taskPreemptionMode(*device, kernel));
}
TEST_F(ThreadGroupPreemptionTests, allowDefaultModeForNonKernelRequest) {
EXPECT_EQ(PreemptionMode::ThreadGroup, PreemptionHelper::taskPreemptionMode(*device, nullptr));
}
TEST_F(ThreadGroupPreemptionTests, allowMidBatch) {
device->setPreemptionMode(PreemptionMode::MidBatch);
EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, nullptr));
}
TEST_F(ThreadGroupPreemptionTests, disallowWhenAdjustedDisabled) {
device->setPreemptionMode(PreemptionMode::Disabled);
EXPECT_EQ(PreemptionMode::Disabled, PreemptionHelper::taskPreemptionMode(*device, nullptr));
}
TEST_F(ThreadGroupPreemptionTests, returnDefaultDeviceModeForZeroSizedMdi) {
MultiDispatchInfo multiDispatchInfo;
EXPECT_EQ(PreemptionMode::ThreadGroup, PreemptionHelper::taskPreemptionMode(*device, multiDispatchInfo));
}
TEST_F(ThreadGroupPreemptionTests, returnDefaultDeviceModeForValidKernelsInMdi) {
MultiDispatchInfo multiDispatchInfo;
multiDispatchInfo.push(*dispatchInfo);
multiDispatchInfo.push(*dispatchInfo);
EXPECT_EQ(PreemptionMode::ThreadGroup, PreemptionHelper::taskPreemptionMode(*device, multiDispatchInfo));
}
TEST_F(ThreadGroupPreemptionTests, disallowDefaultDeviceModeForValidKernelsInMdiAndDisabledPremption) {
device->setPreemptionMode(PreemptionMode::Disabled);
MultiDispatchInfo multiDispatchInfo;
multiDispatchInfo.push(*dispatchInfo);
multiDispatchInfo.push(*dispatchInfo);
EXPECT_EQ(PreemptionMode::Disabled, PreemptionHelper::taskPreemptionMode(*device, multiDispatchInfo));
}
TEST_F(ThreadGroupPreemptionTests, disallowDefaultDeviceModeWhenAtLeastOneInvalidKernelInMdi) {
MockKernel schedulerKernel(&program, *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));
MultiDispatchInfo multiDispatchInfo;
multiDispatchInfo.push(*dispatchInfo);
multiDispatchInfo.push(schedulerDispatchInfo);
multiDispatchInfo.push(*dispatchInfo);
EXPECT_EQ(PreemptionMode::MidBatch, PreemptionHelper::taskPreemptionMode(*device, multiDispatchInfo));
}
TEST_F(MidThreadPreemptionTests, allowMidThreadPreemption) {
device->setPreemptionMode(PreemptionMode::MidThread);
executionEnvironment.DisableMidThreadPreemption = 0;
EXPECT_TRUE(PreemptionHelper::allowMidThreadPreemption(kernel, *device));
}
TEST_F(MidThreadPreemptionTests, allowMidThreadPreemptionNullKernel) {
device->setPreemptionMode(PreemptionMode::MidThread);
EXPECT_TRUE(PreemptionHelper::allowMidThreadPreemption(nullptr, *device));
}
TEST_F(MidThreadPreemptionTests, disallowMidThreadPreemptionByDevice) {
device->setPreemptionMode(PreemptionMode::ThreadGroup);
executionEnvironment.DisableMidThreadPreemption = 0;
EXPECT_FALSE(PreemptionHelper::allowMidThreadPreemption(kernel, *device));
}
TEST_F(MidThreadPreemptionTests, disallowMidThreadPreemptionByKernel) {
device->setPreemptionMode(PreemptionMode::MidThread);
executionEnvironment.DisableMidThreadPreemption = 1;
EXPECT_FALSE(PreemptionHelper::allowMidThreadPreemption(kernel, *device));
}
TEST_F(MidThreadPreemptionTests, taskPreemptionDisallowMidThreadByDevice) {
executionEnvironment.DisableMidThreadPreemption = 0;
device->setPreemptionMode(PreemptionMode::ThreadGroup);
PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel);
EXPECT_EQ(PreemptionMode::ThreadGroup, outMode);
}
TEST_F(MidThreadPreemptionTests, taskPreemptionDisallowMidThreadByKernel) {
executionEnvironment.DisableMidThreadPreemption = 1;
device->setPreemptionMode(PreemptionMode::MidThread);
PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel);
EXPECT_EQ(PreemptionMode::ThreadGroup, outMode);
}
TEST_F(MidThreadPreemptionTests, taskPreemptionAllow) {
executionEnvironment.DisableMidThreadPreemption = 0;
device->setPreemptionMode(PreemptionMode::MidThread);
PreemptionMode outMode = PreemptionHelper::taskPreemptionMode(*device, kernel);
EXPECT_EQ(PreemptionMode::MidThread, outMode);
}
TEST_F(DevicePreemptionTests, setDefaultMidThreadPreemption) {
RuntimeCapabilityTable devCapabilities = {};
devCapabilities.defaultPreemptionMode = PreemptionMode::MidThread;
PreemptionHelper::adjustDefaultPreemptionMode(devCapabilities, true, true, true);
EXPECT_EQ(PreemptionMode::MidThread, devCapabilities.defaultPreemptionMode);
}
TEST_F(DevicePreemptionTests, setDefaultThreadGroupPreemptionNoMidThreadDefault) {
RuntimeCapabilityTable devCapabilities = {};
devCapabilities.defaultPreemptionMode = PreemptionMode::ThreadGroup;
PreemptionHelper::adjustDefaultPreemptionMode(devCapabilities, true, true, true);
EXPECT_EQ(PreemptionMode::ThreadGroup, devCapabilities.defaultPreemptionMode);
}
TEST_F(DevicePreemptionTests, setDefaultThreadGroupPreemptionNoMidThreadSupport) {
RuntimeCapabilityTable devCapabilities = {};
devCapabilities.defaultPreemptionMode = PreemptionMode::MidThread;
PreemptionHelper::adjustDefaultPreemptionMode(devCapabilities, false, true, true);
EXPECT_EQ(PreemptionMode::ThreadGroup, devCapabilities.defaultPreemptionMode);
}
TEST_F(DevicePreemptionTests, setDefaultMidBatchPreemptionNoThreadGroupDefault) {
RuntimeCapabilityTable devCapabilities = {};
devCapabilities.defaultPreemptionMode = PreemptionMode::MidBatch;
PreemptionHelper::adjustDefaultPreemptionMode(devCapabilities, true, true, true);
EXPECT_EQ(PreemptionMode::MidBatch, devCapabilities.defaultPreemptionMode);
}
TEST_F(DevicePreemptionTests, setDefaultMidBatchPreemptionNoThreadGroupSupport) {
RuntimeCapabilityTable devCapabilities = {};
devCapabilities.defaultPreemptionMode = PreemptionMode::MidThread;
PreemptionHelper::adjustDefaultPreemptionMode(devCapabilities, false, false, true);
EXPECT_EQ(PreemptionMode::MidBatch, devCapabilities.defaultPreemptionMode);
}
TEST_F(DevicePreemptionTests, setDefaultDisabledPreemptionNoMidBatchDefault) {
RuntimeCapabilityTable devCapabilities = {};
devCapabilities.defaultPreemptionMode = PreemptionMode::Disabled;
PreemptionHelper::adjustDefaultPreemptionMode(devCapabilities, true, true, true);
EXPECT_EQ(PreemptionMode::Disabled, devCapabilities.defaultPreemptionMode);
}
TEST_F(DevicePreemptionTests, setDefaultDisabledPreemptionNoMidBatchSupport) {
RuntimeCapabilityTable devCapabilities = {};
devCapabilities.defaultPreemptionMode = PreemptionMode::MidThread;
PreemptionHelper::adjustDefaultPreemptionMode(devCapabilities, false, false, false);
EXPECT_EQ(PreemptionMode::Disabled, devCapabilities.defaultPreemptionMode);
}
TEST(PreemptionTest, defaultMode) {
EXPECT_EQ(0, DebugManager.flags.ForcePreemptionMode.get());
}

View File

@ -0,0 +1,136 @@
/*
* 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 {
dbgRestore = new DebugManagerStateRestore();
DebugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::ThreadGroup));
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);
preemptionMode = PreemptionMode::ThreadGroup;
waTable = const_cast<WorkaroundTable *>(device->getWaTable());
}
void TearDown() override {
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;
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