Move reading env vars to DriverImp

- add requirePerContextMemorySpace flag to ExecEnv

Related-To: NEO-4637

Change-Id: I3968bedd9cfd1b1e41e79b63939b7a9bf25e7ff5
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2020-07-13 15:14:16 +02:00
committed by sys_ocldev
parent 74ac02e1f3
commit 073a40c14c
12 changed files with 112 additions and 20 deletions

View File

@@ -9,6 +9,7 @@
#include "shared/source/device/device.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/os_interface/debug_env_reader.h"
#include "shared/source/os_interface/device_factory.h"
#include "level_zero/core/source/device/device.h"
@@ -26,14 +27,25 @@ uint32_t driverCount = 1;
void DriverImp::initialize(bool *result) {
*result = false;
NEO::EnvironmentVariableReader envReader;
L0EnvVariables envVariables = {};
envVariables.affinityMask =
envReader.getSetting("ZE_AFFINITY_MASK", std::string(""));
envVariables.programDebugging =
envReader.getSetting("ZET_ENABLE_PROGRAM_DEBUGGING", false);
auto executionEnvironment = new NEO::ExecutionEnvironment();
UNRECOVERABLE_IF(nullptr == executionEnvironment);
if (envVariables.programDebugging) {
executionEnvironment->setPerContextMemorySpace();
}
executionEnvironment->incRefInternal();
auto neoDevices = NEO::DeviceFactory::createDevices(*executionEnvironment);
executionEnvironment->decRefInternal();
if (!neoDevices.empty()) {
GlobalDriverHandle = DriverHandle::create(std::move(neoDevices));
GlobalDriverHandle = DriverHandle::create(std::move(neoDevices), envVariables);
if (GlobalDriverHandle != nullptr) {
*result = true;
}

View File

@@ -18,6 +18,7 @@ struct _ze_driver_handle_t {
namespace L0 {
struct Device;
struct L0EnvVariables;
struct DriverHandle : _ze_driver_handle_t {
virtual ze_result_t getDevice(uint32_t *pCount, ze_device_handle_t *phDevices) = 0;
@@ -65,7 +66,7 @@ struct DriverHandle : _ze_driver_handle_t {
DriverHandle &operator=(const DriverHandle &) = delete;
DriverHandle &operator=(DriverHandle &&) = delete;
static DriverHandle *create(std::vector<std::unique_ptr<NEO::Device>> devices);
static DriverHandle *create(std::vector<std::unique_ptr<NEO::Device>> devices, const L0EnvVariables &envVariables);
};
} // namespace L0

View File

@@ -10,11 +10,11 @@
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/device/device.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/os_interface/debug_env_reader.h"
#include "shared/source/os_interface/os_library.h"
#include "level_zero/core/source/debugger/debugger_l0.h"
#include "level_zero/core/source/device/device_imp.h"
#include "level_zero/core/source/driver/driver_imp.h"
#include "driver_version_l0.h"
@@ -176,15 +176,12 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
return ZE_RESULT_SUCCESS;
}
DriverHandle *DriverHandle::create(std::vector<std::unique_ptr<NEO::Device>> devices) {
DriverHandle *DriverHandle::create(std::vector<std::unique_ptr<NEO::Device>> devices, const L0EnvVariables &envVariables) {
DriverHandleImp *driverHandle = new DriverHandleImp;
UNRECOVERABLE_IF(nullptr == driverHandle);
NEO::EnvironmentVariableReader envReader;
driverHandle->affinityMaskString =
envReader.getSetting("ZE_AFFINITY_MASK", driverHandle->affinityMaskString);
driverHandle->enableProgramDebugging =
envReader.getSetting("ZET_ENABLE_PROGRAM_DEBUGGING", driverHandle->enableProgramDebugging);
driverHandle->affinityMaskString = envVariables.affinityMask;
driverHandle->enableProgramDebugging = envVariables.programDebugging;
ze_result_t res = driverHandle->initialize(std::move(devices));
if (res != ZE_RESULT_SUCCESS) {

View File

@@ -10,6 +10,7 @@
#include "level_zero/core/source/driver/driver.h"
#include <mutex>
#include <string>
namespace L0 {
@@ -23,4 +24,10 @@ class DriverImp : public Driver {
std::once_flag initDriverOnce;
static bool initStatus;
};
struct L0EnvVariables {
std::string affinityMask;
bool programDebugging;
};
} // namespace L0

View File

@@ -12,6 +12,7 @@
#include "opencl/source/helpers/hardware_commands_helper.h"
#include "test.h"
#include "level_zero/core/source/driver/driver_imp.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
@@ -32,7 +33,7 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
std::vector<std::unique_ptr<NEO::Device>> devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices)));
auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices), L0EnvVariables{}));
driverHandle.reset(driverHandleUlt);
ASSERT_NE(nullptr, driverHandle);

View File

@@ -12,6 +12,7 @@
#include "opencl/source/helpers/hardware_commands_helper.h"
#include "test.h"
#include "level_zero/core/source/driver/driver_imp.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
@@ -32,7 +33,7 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
std::vector<std::unique_ptr<NEO::Device>> devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices)));
auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices), L0EnvVariables{}));
driverHandle.reset(driverHandleUlt);
ASSERT_NE(nullptr, driverHandle);

View File

@@ -42,7 +42,7 @@ struct ActiveDebuggerFixture {
std::vector<std::unique_ptr<NEO::Device>> devices;
devices.push_back(std::unique_ptr<NEO::Device>(device));
auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices)));
auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices), L0EnvVariables{}));
driverHandle.reset(driverHandleUlt);
ASSERT_NE(nullptr, driverHandle);

View File

@@ -13,6 +13,7 @@
#include "test.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/source/driver/driver_imp.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include <bitset>
@@ -44,7 +45,7 @@ TEST(DriverTestFamilySupport, whenInitializingDriverOnSupportedFamilyThenDriverI
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandle = DriverHandle::create(std::move(devices));
auto driverHandle = DriverHandle::create(std::move(devices), L0EnvVariables{});
EXPECT_NE(nullptr, driverHandle);
delete driverHandle;
L0::GlobalDriver = nullptr;
@@ -58,7 +59,7 @@ TEST(DriverTestFamilySupport, whenInitializingDriverOnNotSupportedFamilyThenDriv
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandle = DriverHandle::create(std::move(devices));
auto driverHandle = DriverHandle::create(std::move(devices), L0EnvVariables{});
EXPECT_EQ(nullptr, driverHandle);
}
@@ -69,8 +70,10 @@ TEST(DriverTest, givenNullEnvVariableWhenCreatingDriverThenEnableProgramDebuggin
NEO::MockDevice *neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
L0EnvVariables envVariables = {};
envVariables.programDebugging = false;
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices)));
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices), envVariables));
EXPECT_NE(nullptr, driverHandle);
EXPECT_FALSE(driverHandle->enableProgramDebugging);
@@ -79,17 +82,75 @@ TEST(DriverTest, givenNullEnvVariableWhenCreatingDriverThenEnableProgramDebuggin
L0::GlobalDriver = nullptr;
}
TEST(DriverTest, givenEnvVariableNonZeroWhenCreatingDriverThenEnableProgramDebuggingIsSetTrue) {
TEST(DriverImpTest, givenDriverImpWhenInitializedThenEnvVariablesAreRead) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
VariableBackup<bool> mockDeviceFlagBackup(&IoFunctions::returnMockEnvValue, true);
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
bool result = false;
DriverImp driverImp;
driverImp.initialize(&result);
EXPECT_TRUE(result);
EXPECT_LE(2u, IoFunctions::mockGetenvCalled);
delete L0::GlobalDriver;
L0::GlobalDriverHandle = nullptr;
L0::GlobalDriver = nullptr;
}
TEST(DriverImpTest, givenEnabledProgramDebuggingWhenCreatingExecutionEnvironmentThenPerContextMemorySpaceIsTrue) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
VariableBackup<bool> mockDeviceFlagBackup(&IoFunctions::returnMockEnvValue, true);
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
bool result = false;
DriverImp driverImp;
driverImp.initialize(&result);
ASSERT_NE(nullptr, L0::GlobalDriver);
ASSERT_NE(0u, L0::GlobalDriver->numDevices);
EXPECT_TRUE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isPerContextMemorySpaceRequired());
delete L0::GlobalDriver;
L0::GlobalDriverHandle = nullptr;
L0::GlobalDriver = nullptr;
}
TEST(DriverImpTest, givenNoProgramDebuggingEnvVarWhenCreatingExecutionEnvironmentThenPerContextMemorySpaceIsFalse) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
VariableBackup<bool> mockDeviceFlagBackup(&IoFunctions::returnMockEnvValue, false);
bool result = false;
DriverImp driverImp;
driverImp.initialize(&result);
ASSERT_NE(nullptr, L0::GlobalDriver);
ASSERT_NE(0u, L0::GlobalDriver->numDevices);
EXPECT_FALSE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isPerContextMemorySpaceRequired());
delete L0::GlobalDriver;
L0::GlobalDriverHandle = nullptr;
L0::GlobalDriver = nullptr;
}
TEST(DriverTest, givenProgramDebuggingEnvVarNonZeroWhenCreatingDriverThenEnableProgramDebuggingIsSetTrue) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
NEO::MockDevice *neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices)));
L0EnvVariables envVariables = {};
envVariables.programDebugging = true;
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices), envVariables));
EXPECT_NE(nullptr, driverHandle);
EXPECT_TRUE(driverHandle->enableProgramDebugging);
@@ -126,7 +187,7 @@ struct DriverTestMultipleFamilySupport : public ::testing::Test {
};
TEST_F(DriverTestMultipleFamilySupport, whenInitializingDriverWithArrayOfDevicesThenDriverIsInitializedOnlyWithThoseSupported) {
auto driverHandle = DriverHandle::create(std::move(devices));
auto driverHandle = DriverHandle::create(std::move(devices), L0EnvVariables{});
EXPECT_NE(nullptr, driverHandle);
L0::DriverHandleImp *driverHandleImp = reinterpret_cast<L0::DriverHandleImp *>(driverHandle);
@@ -163,7 +224,7 @@ struct DriverTestMultipleFamilyNoSupport : public ::testing::Test {
};
TEST_F(DriverTestMultipleFamilyNoSupport, whenInitializingDriverWithArrayOfNotSupportedDevicesThenDriverIsNull) {
auto driverHandle = DriverHandle::create(std::move(devices));
auto driverHandle = DriverHandle::create(std::move(devices), L0EnvVariables{});
EXPECT_EQ(nullptr, driverHandle);
}