Power Saving Hint Support for Level Zero in Windows

- Added Functionality to pass ze_power_saving_hint_type_t to zeContextCreate
included in the pNext extensions in ze_context_desc_t.
- Enables handling a hint value 0-100 with 0 being no power savings
and 100 being maximum power savings.
- ZE_RESULT_ERROR_INVALID_ENUMERATION is returned given an invalid hint.

Related-To: LOCI-2567

Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
This commit is contained in:
Spruit, Neil R 2021-12-16 02:13:00 +00:00 committed by Compute-Runtime-Automation
parent 635c02e1ff
commit 02f075c541
33 changed files with 386 additions and 59 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -161,6 +161,11 @@ CommandQueue *CommandQueue::create(uint32_t productFamily, Device *device, NEO::
}
auto &osContext = csr->getOsContext();
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(device->getDriverHandle());
if (driverHandleImp->powerHint && driverHandleImp->powerHint != osContext.getUmdPowerHintValue()) {
osContext.setUmdPowerHintValue(driverHandleImp->powerHint);
osContext.reInitializeContext();
}
osContext.ensureContextInitialized();
csr->initDirectSubmission(*device->getNEODevice(), osContext);
return commandQueue;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -41,6 +41,20 @@ ze_result_t DriverHandleImp::createContext(const ze_context_desc_t *desc,
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
if (desc->pNext) {
const ze_base_desc_t *expDesc = reinterpret_cast<const ze_base_desc_t *>(desc->pNext);
if (expDesc->stype == ZE_STRUCTURE_TYPE_POWER_SAVING_HINT_EXP_DESC) {
const ze_context_power_saving_hint_exp_desc_t *powerHintExpDesc =
reinterpret_cast<const ze_context_power_saving_hint_exp_desc_t *>(expDesc);
if (powerHintExpDesc->hint == ZE_POWER_SAVING_HINT_TYPE_MIN || powerHintExpDesc->hint <= ZE_POWER_SAVING_HINT_TYPE_MAX) {
powerHint = static_cast<uint8_t>(powerHintExpDesc->hint);
} else {
delete context;
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
}
}
}
*phContext = context->toHandle();
if (numDevices == 0) {

View File

@ -108,6 +108,7 @@ struct DriverHandleImp : public DriverHandle {
bool enableProgramDebugging = false;
bool enableSysman = false;
bool enablePciIdDeviceOrder = false;
uint8_t powerHint = 0;
};
extern struct DriverHandleImp *GlobalDriver;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -70,7 +70,7 @@ void AUBFixtureL0::SetUp(const NEO::HardwareInfo *hardwareInfo) {
device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -194,8 +194,7 @@ std::vector<ze_device_handle_t> zelloInitContextAndGetDevices(ze_context_handle_
}
SUCCESS_OR_TERMINATE(zeDriverGet(&driverCount, &driverHandle));
ze_context_desc_t context_desc = {};
context_desc.stype = ZE_STRUCTURE_TYPE_CONTEXT_DESC;
ze_context_desc_t context_desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
SUCCESS_OR_TERMINATE(zeContextCreate(driverHandle, &context_desc, &context));
uint32_t deviceCount = 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -33,7 +33,7 @@ void DeviceFixture::setupWithExecutionEnvironment(NEO::ExecutionEnvironment &exe
device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
@ -54,7 +54,7 @@ void PageFaultDeviceFixture::SetUp() { // NOLINT(readability-identifier-naming)
device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
@ -80,7 +80,7 @@ void MultiDeviceFixture::SetUp() { // NOLINT(readability-identifier-naming)
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -45,7 +45,7 @@ struct HostPointerManagerFixure {
heapPointer = hostDriverHandle->getMemoryManager()->allocateSystemMemory(heapSize, MemoryConstants::pageSize);
ASSERT_NE(nullptr, heapPointer);
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t ret = hostDriverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
context = L0::Context::fromHandle(hContext);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -251,7 +251,7 @@ HWTEST2_F(DeviceQueueGroupTest,
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
L0::Context *context = Context::fromHandle(hContext);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -66,7 +66,7 @@ HWTEST2_F(DeviceQueueGroupTest, givenQueueGroupsReturnedThenCommandListIsCreated
EXPECT_EQ(properties.maxMemoryFillPatternSize, std::numeric_limits<size_t>::max());
ze_context_handle_t hContext;
ze_context_desc_t contextDesc;
ze_context_desc_t contextDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
res = driverHandle->createContext(&contextDesc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
L0::Context *context = Context::fromHandle(hContext);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -959,6 +959,8 @@ TEST_F(CommandListCreate, givenRootDeviceAndImplicitScalingDisabledWhenCreatingC
queueDesc.ordinal = ordinal;
queueDesc.index = 0;
l0RootDevice.driverHandle = driverHandle.get();
l0RootDevice.implicitScalingCapable = true;
auto returnValue = l0RootDevice.createCommandList(&cmdDesc, &commandList);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, returnValue);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -1151,7 +1151,7 @@ struct MultiTileCommandListAppendLaunchFunctionXeHpCoreFixture : MultiDeviceModu
device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = device->getDriverHandle()->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
contextImp = static_cast<ContextImp *>(Context::fromHandle(hContext));

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -86,6 +86,8 @@ HWTEST_F(ContextCreateCommandQueueTest, givenRootDeviceAndImplicitScalingDisable
auto ordinal = static_cast<uint32_t>(subDevice0.getRegularEngineGroups().size() - 1);
Mock<L0::DeviceImp> l0RootDevice(&rootDevice, rootDevice.getExecutionEnvironment());
l0RootDevice.driverHandle = driverHandle.get();
ze_command_queue_handle_t commandQueue = nullptr;
ze_command_queue_desc_t desc = {ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC};
desc.ordinal = ordinal;
@ -378,6 +380,51 @@ HWTEST_F(CommandQueueSynchronizeTest, givenSinglePartitionCountWhenWaitFunctionF
commandQueue->destroy();
}
using CommandQueuePowerHintTest = Test<ContextFixture>;
HWTEST_F(CommandQueuePowerHintTest, givenDriverHandleWithPowerHintAndOsContextPowerHintUnsetThenSuccessIsReturned) {
auto csr = std::unique_ptr<TestCmdQueueCsr<FamilyType>>(new TestCmdQueueCsr<FamilyType>(*device->getNEODevice()->getExecutionEnvironment(),
device->getNEODevice()->getDeviceBitfield()));
csr->setupContext(*device->getNEODevice()->getDefaultEngine().osContext);
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(device->getDriverHandle());
driverHandleImp->powerHint = 1;
const ze_command_queue_desc_t desc{};
ze_result_t returnValue;
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily,
device,
csr.get(),
&desc,
false,
false,
returnValue));
EXPECT_EQ(returnValue, ZE_RESULT_SUCCESS);
ASSERT_NE(nullptr, commandQueue);
commandQueue->destroy();
}
HWTEST_F(CommandQueuePowerHintTest, givenDriverHandleWithPowerHintAndOsContextPowerHintAlreadySetThenSuccessIsReturned) {
auto csr = std::unique_ptr<TestCmdQueueCsr<FamilyType>>(new TestCmdQueueCsr<FamilyType>(*device->getNEODevice()->getExecutionEnvironment(),
device->getNEODevice()->getDeviceBitfield()));
csr->setupContext(*device->getNEODevice()->getDefaultEngine().osContext);
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(device->getDriverHandle());
driverHandleImp->powerHint = 1;
auto &osContext = csr->getOsContext();
osContext.setUmdPowerHintValue(1);
const ze_command_queue_desc_t desc{};
ze_result_t returnValue;
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily,
device,
csr.get(),
&desc,
false,
false,
returnValue));
EXPECT_EQ(returnValue, ZE_RESULT_SUCCESS);
ASSERT_NE(nullptr, commandQueue);
commandQueue->destroy();
}
struct MemoryManagerCommandQueueCreateNegativeTest : public NEO::MockMemoryManager {
MemoryManagerCommandQueueCreateNegativeTest(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -30,7 +30,7 @@ using MultiDeviceContextTests = Test<MultiDeviceFixture>;
TEST_F(MultiDeviceContextTests,
whenCreatingContextWithZeroNumDevicesThenAllDevicesAreAssociatedWithTheContext) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@ -48,7 +48,7 @@ TEST_F(MultiDeviceContextTests,
TEST_F(MultiDeviceContextTests,
whenCreatingContextWithNonZeroNumDevicesThenOnlySpecifiedDeviceAndItsSubDevicesAreAssociatedWithTheContext) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_device_handle_t device0 = driverHandle->devices[0]->toHandle();
DeviceImp *deviceImp0 = static_cast<DeviceImp *>(device0);
@ -104,7 +104,7 @@ TEST_F(MultiDeviceContextTests,
TEST_F(MultiDeviceContextTests,
whenAllocatingDeviceMemoryWithDeviceNotDefinedForContextThenDeviceLostIsReturned) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_device_handle_t device = driverHandle->devices[1]->toHandle();
@ -126,7 +126,7 @@ TEST_F(MultiDeviceContextTests,
TEST_F(MultiDeviceContextTests,
whenAllocatingSharedMemoryWithDeviceNotDefinedForContextThenDeviceLostIsReturned) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_device_handle_t device = driverHandle->devices[1]->toHandle();
@ -201,7 +201,7 @@ TEST_F(ContextHostAllocTests,
whenAllocatingHostMemoryOnlyIndexesOfDevicesWithinTheContextAreUsed) {
L0::ContextImp *context = nullptr;
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc,
numberOfDevicesInContext,
zeDevices.data(),
@ -225,7 +225,7 @@ TEST_F(ContextHostAllocTests,
using ContextGetStatusTest = Test<DeviceFixture>;
TEST_F(ContextGetStatusTest, givenCallToContextGetStatusThenCorrectErrorCodeIsReturnedWhenResourcesHaveBeenReleased) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@ -245,11 +245,78 @@ TEST_F(ContextGetStatusTest, givenCallToContextGetStatusThenCorrectErrorCodeIsRe
context->destroy();
}
using ContextPowerSavingHintTest = Test<DeviceFixture>;
TEST_F(ContextPowerSavingHintTest, givenCallToContextCreateWithPowerHintDescThenPowerHintSetInDriverHandle) {
ze_context_handle_t hContext;
ze_context_desc_t ctxtDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC};
ze_context_power_saving_hint_exp_desc_t powerHintContext = {};
powerHintContext.stype = ZE_STRUCTURE_TYPE_POWER_SAVING_HINT_EXP_DESC;
powerHintContext.hint = 1;
ctxtDesc.pNext = &powerHintContext;
ze_result_t res = driverHandle->createContext(&ctxtDesc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_EQ(powerHintContext.hint, driverHandle->powerHint);
L0::Context *context = L0::Context::fromHandle(hContext);
context->destroy();
}
TEST_F(ContextPowerSavingHintTest, givenCallToContextCreateWithPowerHintMinimumThenPowerHintSetInDriverHandle) {
ze_context_handle_t hContext;
ze_context_desc_t ctxtDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC};
ze_context_power_saving_hint_exp_desc_t powerHintContext = {};
powerHintContext.stype = ZE_STRUCTURE_TYPE_POWER_SAVING_HINT_EXP_DESC;
powerHintContext.hint = ZE_POWER_SAVING_HINT_TYPE_MIN;
ctxtDesc.pNext = &powerHintContext;
ze_result_t res = driverHandle->createContext(&ctxtDesc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_EQ(powerHintContext.hint, driverHandle->powerHint);
L0::Context *context = L0::Context::fromHandle(hContext);
context->destroy();
}
TEST_F(ContextPowerSavingHintTest, givenCallToContextCreateWithPowerHintMaximumThenPowerHintSetInDriverHandle) {
ze_context_handle_t hContext;
ze_context_desc_t ctxtDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC};
ze_context_power_saving_hint_exp_desc_t powerHintContext = {};
powerHintContext.stype = ZE_STRUCTURE_TYPE_POWER_SAVING_HINT_EXP_DESC;
powerHintContext.hint = ZE_POWER_SAVING_HINT_TYPE_MAX;
ctxtDesc.pNext = &powerHintContext;
ze_result_t res = driverHandle->createContext(&ctxtDesc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_EQ(powerHintContext.hint, driverHandle->powerHint);
L0::Context *context = L0::Context::fromHandle(hContext);
context->destroy();
}
TEST_F(ContextPowerSavingHintTest, givenCallToContextCreateWithPowerHintGreaterThanMaxHintThenErrorIsReturned) {
ze_context_handle_t hContext;
ze_context_desc_t ctxtDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_context_power_saving_hint_exp_desc_t powerHintContext = {};
powerHintContext.stype = ZE_STRUCTURE_TYPE_POWER_SAVING_HINT_EXP_DESC;
powerHintContext.hint = ZE_POWER_SAVING_HINT_TYPE_MAX + 1;
ctxtDesc.pNext = &powerHintContext;
ze_result_t res = driverHandle->createContext(&ctxtDesc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ENUMERATION, res);
}
TEST_F(ContextPowerSavingHintTest, givenCallToContextCreateWithoutPowerHintDescThenPowerHintIsNotSetInDriverHandle) {
ze_context_handle_t hContext;
ze_context_desc_t ctxtDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_scheduling_hint_exp_desc_t invalidExpContext = {};
invalidExpContext.stype = ZE_STRUCTURE_TYPE_SCHEDULING_HINT_EXP_DESC;
ctxtDesc.pNext = &invalidExpContext;
ze_result_t res = driverHandle->createContext(&ctxtDesc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_EQ(0, driverHandle->powerHint);
L0::Context *context = L0::Context::fromHandle(hContext);
context->destroy();
}
using ContextTest = Test<DeviceFixture>;
TEST_F(ContextTest, whenCreatingAndDestroyingContextThenSuccessIsReturned) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@ -660,7 +727,7 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests,
TEST_F(ContextTest, whenGettingDriverThenDriverIsRetrievedSuccessfully) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@ -675,7 +742,7 @@ TEST_F(ContextTest, whenGettingDriverThenDriverIsRetrievedSuccessfully) {
TEST_F(ContextTest, whenCallingVirtualMemInterfacesThenUnsupportedIsReturned) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@ -701,7 +768,7 @@ TEST_F(ContextTest, whenCallingVirtualMemInterfacesThenUnsupportedIsReturned) {
TEST_F(ContextTest, whenCallingPhysicalMemInterfacesThenUnsupportedIsReturned) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@ -722,7 +789,7 @@ TEST_F(ContextTest, whenCallingPhysicalMemInterfacesThenUnsupportedIsReturned) {
TEST_F(ContextTest, whenCallingMappingVirtualInterfacesThenUnsupportedIsReturned) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@ -763,7 +830,7 @@ using IsAtMostProductDG1 = IsAtMostProduct<IGFX_DG1>;
HWTEST2_F(ContextTest, WhenCreatingImageThenSuccessIsReturned, IsAtMostProductDG1) {
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -1177,7 +1177,7 @@ struct EventPoolCreateNegativeTest : public ::testing::Test {
device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -2967,7 +2967,7 @@ struct AllocHostMemoryTest : public ::testing::Test {
driverHandle->initialize(std::move(devices));
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -142,7 +142,7 @@ HWTEST2_F(CommandQueueCommandsPvc, givenLinkedCopyEngineOrdinalWhenCreatingThenS
auto testL0Device = std::unique_ptr<L0::Device>(L0::Device::create(driverHandle.get(), testNeoDevice, false, &returnValue));
ze_context_handle_t hContext;
ze_context_desc_t desc = {};
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t result = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -396,7 +396,7 @@ struct Sample {
}
// Obtain context.
ze_context_desc_t contextDesc = {};
ze_context_desc_t contextDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
VALIDATECALL(zeContextCreate(driverHandle, &contextDesc, &contextHandle));
// Obtain all devices.

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -65,6 +65,22 @@ TEST(OSContext, givenCooperativeEngineWhenIsCooperativeEngineIsCalledThenReturnT
delete pOsContext;
}
TEST(OSContext, givenReinitializeContextWhenContextIsInitThenContextIsStillIinitializedAfter) {
auto engineDescriptor = EngineDescriptorHelper::getDefaultDescriptor();
auto pOsContext = OsContext::create(nullptr, 0, engineDescriptor);
EXPECT_NO_THROW(pOsContext->reInitializeContext());
EXPECT_NO_THROW(pOsContext->ensureContextInitialized());
delete pOsContext;
}
TEST(OSContext, givenSetPowerHintThenGetPowerHintShowsTheSameValue) {
auto engineDescriptor = EngineDescriptorHelper::getDefaultDescriptor();
auto pOsContext = OsContext::create(nullptr, 0, engineDescriptor);
pOsContext->setUmdPowerHintValue(1);
EXPECT_EQ(1, pOsContext->getUmdPowerHintValue());
delete pOsContext;
}
struct DeferredOsContextCreationTests : ::testing::Test {
void SetUp() override {
device = std::unique_ptr<MockDevice>{MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get())};

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -56,3 +56,34 @@ TEST_F(OsContextWinTest, givenWddm20WhenRegisterTrimCallbackIsDisabledThenOsCont
osContext = std::make_unique<OsContextWin>(*osInterface->getDriverModel()->as<Wddm>(), 0u, EngineDescriptorHelper::getDefaultDescriptor(engineTypeUsage, preemptionMode));
EXPECT_NO_THROW(osContext->ensureContextInitialized());
}
TEST_F(OsContextWinTest, givenReinitializeContextWhenContextIsInitThenContextIsDestroyedAndRecreated) {
osContext = std::make_unique<OsContextWin>(*osInterface->getDriverModel()->as<Wddm>(), 0u, EngineDescriptorHelper::getDefaultDescriptor(engineTypeUsage, preemptionMode));
EXPECT_NO_THROW(osContext->reInitializeContext());
EXPECT_NO_THROW(osContext->ensureContextInitialized());
}
TEST_F(OsContextWinTest, givenReinitializeContextWhenContextIsNotInitThenContextIsCreated) {
EXPECT_NO_THROW(osContext->reInitializeContext());
EXPECT_NO_THROW(osContext->ensureContextInitialized());
}
struct OsContextWinTestNoCleanup : public WddmTestWithMockGdiDllNoCleanup {
void SetUp() override {
WddmTestWithMockGdiDllNoCleanup::SetUp();
preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo);
engineTypeUsage = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0];
init();
}
PreemptionMode preemptionMode;
EngineTypeUsage engineTypeUsage;
};
TEST_F(OsContextWinTestNoCleanup, givenReinitializeContextWhenContextIsInitThenContextIsNotDestroyed) {
osContext = std::make_unique<OsContextWin>(*osInterface->getDriverModel()->as<Wddm>(), 0u, EngineDescriptorHelper::getDefaultDescriptor(engineTypeUsage, preemptionMode));
EXPECT_TRUE(this->wddm->skipResourceCleanup());
EXPECT_NO_THROW(osContext->reInitializeContext());
EXPECT_NO_THROW(osContext->ensureContextInitialized());
}

View File

@ -226,6 +226,23 @@ TEST_F(Wddm20Tests, whenInitializeWddmThenContextIsCreated) {
EXPECT_TRUE(context != static_cast<D3DKMT_HANDLE>(0));
}
TEST_F(Wddm20Tests, whenCreatingContextWithPowerHintSuccessIsReturned) {
auto newContext = osContext.get();
newContext->setUmdPowerHintValue(1);
EXPECT_EQ(1, newContext->getUmdPowerHintValue());
wddm->createContext(*newContext);
EXPECT_TRUE(wddm->createContext(*newContext));
}
TEST_F(Wddm20Tests, whenInitPrivateDataThenDefaultValuesAreSet) {
auto newContext = osContext.get();
CREATECONTEXT_PVTDATA PrivateData = initPrivateData(*newContext);
EXPECT_FALSE(PrivateData.IsProtectedProcess);
EXPECT_FALSE(PrivateData.IsDwm);
EXPECT_TRUE(PrivateData.GpuVAContext);
EXPECT_FALSE(PrivateData.IsMediaUsage);
}
TEST_F(Wddm20Tests, WhenCreatingAllocationAndDestroyingAllocationThenCorrectResultReturned) {
OsAgnosticMemoryManager mm(*executionEnvironment);
WddmAllocation allocation(0, GraphicsAllocation::AllocationType::UNKNOWN, mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull, 0u, 1u);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -96,6 +96,8 @@ void OsContextLinux::waitForPagingFence() {
}
}
void OsContextLinux::reInitializeContext() {}
OsContextLinux::~OsContextLinux() {
if (contextInitialized) {
for (auto drmContextId : drmContextIds) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -29,6 +29,7 @@ class OsContextLinux : public OsContext {
Drm &getDrm() const;
void waitForPagingFence();
static OsContext *create(OSInterface *osInterface, uint32_t contextId, const EngineDescriptor &engineDescriptor);
void reInitializeContext() override;
protected:
void initializeContext() override;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -54,6 +54,9 @@ class OsContext : public ReferenceTrackedObject<OsContext> {
aub_stream::EngineType contextEngineType,
bool &startOnInit,
bool &startInContext);
virtual void reInitializeContext() {}
uint8_t getUmdPowerHintValue() { return powerHintValue; }
void setUmdPowerHintValue(uint8_t powerHintValue) { this->powerHintValue = powerHintValue; }
protected:
virtual void initializeContext() {}
@ -71,5 +74,6 @@ class OsContext : public ReferenceTrackedObject<OsContext> {
std::once_flag contextInitializedFlag = {};
bool contextInitialized = false;
bool engineInstancedDevice = false;
uint8_t powerHintValue = 0;
};
} // namespace NEO

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2019-2021 Intel Corporation
# Copyright (C) 2019-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@ -111,6 +111,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM
${CMAKE_CURRENT_SOURCE_DIR}/windows_defs.h
${CMAKE_CURRENT_SOURCE_DIR}/windows_wrapper.h
${CMAKE_CURRENT_SOURCE_DIR}/sys_calls_wrapper.h
${CMAKE_CURRENT_SOURCE_DIR}/wddm${BRANCH_DIR_SUFFIX}/init_context_private_data.cpp
)
if(NOT WIN32 AND NOT DISABLE_WDDM_LINUX)

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -38,6 +38,13 @@ void OsContextWin::initializeContext() {
UNRECOVERABLE_IF(!residencyController.isInitialized());
};
void OsContextWin::reInitializeContext() {
if (contextInitialized && (false == this->wddm.skipResourceCleanup())) {
wddm.destroyContext(wddmContextHandle);
}
UNRECOVERABLE_IF(!wddm.createContext(*this));
};
OsContextWin::~OsContextWin() {
if (contextInitialized && (false == this->wddm.skipResourceCleanup())) {
wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -34,6 +34,7 @@ class OsContextWin : public OsContext {
Wddm *getWddm() const { return &wddm; }
MOCKABLE_VIRTUAL WddmResidencyController &getResidencyController() { return residencyController; }
static OsContext *create(OSInterface *osInterface, uint32_t contextId, const EngineDescriptor &engineDescriptor);
void reInitializeContext() override;
protected:
void initializeContext() override;

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/windows/os_context_win.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
namespace NEO {
CREATECONTEXT_PVTDATA initPrivateData(OsContextWin &osContext) {
CREATECONTEXT_PVTDATA PrivateData = {};
PrivateData.IsProtectedProcess = FALSE;
PrivateData.IsDwm = FALSE;
PrivateData.GpuVAContext = TRUE;
PrivateData.IsMediaUsage = false;
return PrivateData;
}
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -792,15 +792,13 @@ void Wddm::kmDafLock(D3DKMT_HANDLE handle) {
bool Wddm::createContext(OsContextWin &osContext) {
NTSTATUS status = STATUS_UNSUCCESSFUL;
D3DKMT_CREATECONTEXTVIRTUAL CreateContext = {};
CREATECONTEXT_PVTDATA PrivateData = {};
PrivateData.IsProtectedProcess = FALSE;
PrivateData.IsDwm = FALSE;
CREATECONTEXT_PVTDATA PrivateData = initPrivateData(osContext);
PrivateData.ProcessID = NEO::getPid();
PrivateData.GpuVAContext = TRUE;
PrivateData.pHwContextId = &hwContextId;
PrivateData.IsMediaUsage = false;
PrivateData.NoRingFlushes = DebugManager.flags.UseNoRingFlushesKmdMode.get();
auto &rootDeviceEnvironment = this->getRootDeviceEnvironment();
applyAdditionalContextFlags(PrivateData, osContext, *rootDeviceEnvironment.getHardwareInfo());

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -52,6 +52,7 @@ enum class HeapIndex : uint32_t;
unsigned int readEnablePreemptionRegKey();
unsigned int getPid();
bool isShutdownInProgress();
CREATECONTEXT_PVTDATA initPrivateData(OsContextWin &osContext);
class Wddm : public DriverModel {
public:

View File

@ -98,6 +98,49 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture, public MockExecutionEnv
RootDeviceEnvironment *rootDeviceEnvironment = nullptr;
};
struct NoCleanupWddmMock : WddmMock {
bool skipResourceCleanup() {
return true;
}
};
struct WddmFixtureWithMockGdiDllWddmNoCleanup : public GdiDllFixture, public MockExecutionEnvironmentGmmFixture {
void SetUp() override {
MockExecutionEnvironmentGmmFixture::SetUp();
GdiDllFixture::SetUp();
rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get();
wddm = static_cast<NoCleanupWddmMock *>(Wddm::createWddm(nullptr, *rootDeviceEnvironment));
wddmMockInterface = new WddmMockInterface20(*wddm);
wddm->wddmInterface.reset(wddmMockInterface);
rootDeviceEnvironment->osInterface = std::make_unique<OSInterface>();
rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr<DriverModel>(wddm));
rootDeviceEnvironment->memoryOperationsInterface = std::make_unique<WddmMemoryOperationsHandler>(wddm);
osInterface = rootDeviceEnvironment->osInterface.get();
}
void init() {
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo);
wddmMockInterface = static_cast<WddmMockInterface20 *>(wddm->wddmInterface.release());
wddm->init();
wddm->wddmInterface.reset(wddmMockInterface);
auto hwInfo = rootDeviceEnvironment->getHardwareInfo();
auto engine = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0];
osContext = std::make_unique<OsContextWin>(*osInterface->getDriverModel()->as<Wddm>(), 0u, EngineDescriptorHelper::getDefaultDescriptor(engine, preemptionMode));
osContext->ensureContextInitialized();
}
void TearDown() override {
GdiDllFixture::TearDown();
}
NoCleanupWddmMock *wddm = nullptr;
OSInterface *osInterface;
std::unique_ptr<OsContextWin> osContext;
WddmMockInterface20 *wddmMockInterface = nullptr;
RootDeviceEnvironment *rootDeviceEnvironment = nullptr;
};
struct WddmInstrumentationGmmFixture : DeviceFixture {
void SetUp() {
DeviceFixture::SetUp();
@ -120,6 +163,7 @@ struct WddmInstrumentationGmmFixture : DeviceFixture {
using WddmTest = WddmFixture;
using WddmTestWithMockGdiDll = Test<WddmFixtureWithMockGdiDll>;
using WddmTestWithMockGdiDllNoCleanup = Test<WddmFixtureWithMockGdiDllWddmNoCleanup>;
using WddmInstrumentationTest = Test<WddmInstrumentationGmmFixture>;
using WddmTestSingle = ::testing::Test;
} // namespace NEO

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2021 Intel Corporation
# Copyright (C) 2020-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@ -9,6 +9,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_query_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_special_heap_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_uuid_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_context_linux_tests.cpp
)
set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_TESTS_LINUX ${NEO_CORE_OS_INTERFACE_TESTS_LINUX})

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/drm_buffer_object.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h"
#include "shared/source/os_interface/linux/os_context_linux.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_gmm_helper.h"
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
#include "shared/test/common/test_macros/test.h"
#include "drm/i915_drm.h"
#include "gtest/gtest.h"
#include <memory>
using namespace NEO;
TEST(OSContextLinux, givenReinitializeContextWhenContextIsInitThenContextIsStillIinitializedAfter) {
MockExecutionEnvironment executionEnvironment;
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock.get(), 0u);
OsContextLinux osContext(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
EXPECT_NO_THROW(osContext.reInitializeContext());
EXPECT_NO_THROW(osContext.ensureContextInitialized());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -74,4 +74,13 @@ TEST_F(WddmTests, whenCheckedIfResourcesCleanupCanBeSkippedThenReturnsFalse) {
EXPECT_FALSE(wddm->skipResourceCleanup());
}
TEST_F(WddmTests, whenCreatingContextWithPowerHintSuccessIsReturned) {
init();
auto newContext = osContext.get();
newContext->setUmdPowerHintValue(1);
EXPECT_EQ(1, newContext->getUmdPowerHintValue());
wddm->createContext(*newContext);
EXPECT_TRUE(wddm->createContext(*newContext));
}
} // namespace NEO