Fix L0 SubDevice creation

Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski
2021-10-12 17:11:20 +00:00
committed by Compute-Runtime-Automation
parent cd4df42616
commit 8605f06435
9 changed files with 41 additions and 38 deletions

View File

@ -108,8 +108,8 @@ struct Device : _ze_device_handle_t {
inline ze_device_handle_t toHandle() { return this; }
static Device *create(DriverHandle *driverHandle, NEO::Device *neoDevice, uint32_t currentDeviceMask, bool isSubDevice, ze_result_t *returnValue);
static Device *create(DriverHandle *driverHandle, NEO::Device *neoDevice, uint32_t currentDeviceMask, bool isSubDevice, ze_result_t *returnValue, L0::Device *deviceL0);
static Device *create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool isSubDevice, ze_result_t *returnValue);
static Device *create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool isSubDevice, ze_result_t *returnValue, L0::Device *deviceL0);
static Device *deviceReinit(DriverHandle *driverHandle, L0::Device *device, std::unique_ptr<NEO::Device> &neoDevice, ze_result_t *returnValue);
virtual NEO::PreemptionMode getDevicePreemptionMode() const = 0;

View File

@ -757,19 +757,16 @@ const NEO::HardwareInfo &DeviceImp::getHwInfo() const { return neoDevice->getHar
// Use this method to reinitialize L0::Device *device, that was created during zeInit, with the help of Device::create
Device *Device::deviceReinit(DriverHandle *driverHandle, L0::Device *device, std::unique_ptr<NEO::Device> &neoDevice, ze_result_t *returnValue) {
const auto rootDeviceIndex = neoDevice->getRootDeviceIndex();
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get();
auto pNeoDevice = neoDevice.release();
auto subDevicesMask = static_cast<uint32_t>(rootDeviceEnvironment->deviceAffinityMask.getGenericSubDevicesMask().to_ulong());
return Device::create(driverHandle, pNeoDevice, subDevicesMask, false, returnValue, device);
return Device::create(driverHandle, pNeoDevice, false, returnValue, device);
}
Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, uint32_t currentDeviceMask, bool isSubDevice, ze_result_t *returnValue) {
return Device::create(driverHandle, neoDevice, currentDeviceMask, isSubDevice, returnValue, nullptr);
Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool isSubDevice, ze_result_t *returnValue) {
return Device::create(driverHandle, neoDevice, isSubDevice, returnValue, nullptr);
}
Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, uint32_t currentDeviceMask, bool isSubDevice, ze_result_t *returnValue, L0::Device *deviceL0) {
Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool isSubDevice, ze_result_t *returnValue, L0::Device *deviceL0) {
L0::DeviceImp *device = nullptr;
if (deviceL0 == nullptr) {
device = new DeviceImp;
@ -807,13 +804,12 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, uint3
}
for (uint32_t i = 0; i < device->neoDevice->getNumSubDevices(); i++) {
if (!((1UL << i) & currentDeviceMask)) {
if (!device->neoDevice->getSubDevice(i)) {
continue;
}
ze_device_handle_t subDevice = Device::create(driverHandle,
device->neoDevice->getSubDevice(i),
0,
true, returnValue, nullptr);
if (subDevice == nullptr) {
return nullptr;

View File

@ -175,7 +175,6 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
}
const auto rootDeviceIndex = neoDevice->getRootDeviceIndex();
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get();
enableRootDeviceDebugger(neoDevice);
@ -184,8 +183,7 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
auto pNeoDevice = neoDevice.release();
auto subDevicesMask = static_cast<uint32_t>(rootDeviceEnvironment->deviceAffinityMask.getGenericSubDevicesMask().to_ulong());
auto device = Device::create(this, pNeoDevice, subDevicesMask, false, &returnValue);
auto device = Device::create(this, pNeoDevice, false, &returnValue);
this->devices.push_back(device);
multiOsContextDriver |= device->isMultiDeviceCapable();

View File

@ -76,7 +76,7 @@ void Mock<DriverHandle>::setupDevices(std::vector<std::unique_ptr<NEO::Device>>
ze_result_t returnValue = ZE_RESULT_SUCCESS;
this->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
this->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
auto device = Device::create(this, neoDevice.release(), std::numeric_limits<uint32_t>::max(), false, &returnValue);
auto device = Device::create(this, neoDevice.release(), false, &returnValue);
this->devices.push_back(device);
}
}

View File

@ -173,7 +173,7 @@ HWTEST_F(TestBuiltinFunctionsLibImplStateless, givenCallToStatelessBuiltinFuncti
HWTEST_F(TestBuiltinFunctionsLibImplDefault, givenCompilerInterfaceWhenCreateDeviceAndImageSupportedThenBuiltinsImageFunctionsAreLoaded) {
ze_result_t returnValue = ZE_RESULT_SUCCESS;
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->compilerInterface.reset(new NEO::MockCompilerInterfaceSpirv());
std::unique_ptr<L0::Device> testDevice(Device::create(device->getDriverHandle(), neoDevice, std::numeric_limits<uint32_t>::max(), false, &returnValue));
std::unique_ptr<L0::Device> testDevice(Device::create(device->getDriverHandle(), neoDevice, false, &returnValue));
if (device->getHwInfo().capabilityTable.supportsImages) {
for (uint32_t builtId = 0; builtId < static_cast<uint32_t>(ImageBuiltin::COUNT); builtId++) {
@ -185,7 +185,7 @@ HWTEST_F(TestBuiltinFunctionsLibImplDefault, givenCompilerInterfaceWhenCreateDev
HWTEST_F(TestBuiltinFunctionsLibImplDefault, givenCompilerInterfaceWhenCreateDeviceThenBuiltinsFunctionsAreLoaded) {
ze_result_t returnValue = ZE_RESULT_SUCCESS;
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->compilerInterface.reset(new NEO::MockCompilerInterfaceSpirv());
std::unique_ptr<L0::Device> testDevice(Device::create(device->getDriverHandle(), neoDevice, std::numeric_limits<uint32_t>::max(), false, &returnValue));
std::unique_ptr<L0::Device> testDevice(Device::create(device->getDriverHandle(), neoDevice, false, &returnValue));
for (uint32_t builtId = 0; builtId < static_cast<uint32_t>(Builtin::COUNT); builtId++) {
EXPECT_NE(nullptr, testDevice->getBuiltinFunctionsLib()->getFunction(static_cast<L0::Builtin>(builtId)));

View File

@ -71,12 +71,16 @@ TEST_F(MultiDeviceContextTests,
res = deviceImp1->getSubDevices(&subDeviceCount1, subDevices1.data());
EXPECT_EQ(res, ZE_RESULT_SUCCESS);
uint32_t subSubDeviceCount1 = 0;
res = static_cast<DeviceImp *>(subDevices1[0])->getSubDevices(&subSubDeviceCount1, nullptr);
EXPECT_EQ(res, ZE_RESULT_SUCCESS);
res = driverHandle->createContext(&desc, 1u, &device1, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
ContextImp *contextImp = static_cast<ContextImp *>(Context::fromHandle(hContext));
uint32_t expectedDeviceCountInContext = 1 + subDeviceCount1;
uint32_t expectedDeviceCountInContext = 1 + subDeviceCount1 + (subDeviceCount1 * subSubDeviceCount1);
EXPECT_EQ(contextImp->getDevices().size(), expectedDeviceCountInContext);
EXPECT_FALSE(contextImp->isDeviceDefinedForThisContext(L0::Device::fromHandle(device0)));
@ -86,7 +90,12 @@ TEST_F(MultiDeviceContextTests,
EXPECT_TRUE(contextImp->isDeviceDefinedForThisContext(L0::Device::fromHandle(device1)));
for (auto subDevice : subDevices1) {
EXPECT_TRUE(contextImp->isDeviceDefinedForThisContext(L0::Device::fromHandle(subDevice)));
auto l0SubDevice = static_cast<DeviceImp *>(subDevice);
EXPECT_TRUE(contextImp->isDeviceDefinedForThisContext(l0SubDevice));
for (auto &subSubDevice : l0SubDevice->subDevices) {
EXPECT_TRUE(contextImp->isDeviceDefinedForThisContext(L0::Device::fromHandle(subSubDevice)));
}
}
res = L0::Context::fromHandle(hContext)->destroy();

View File

@ -48,7 +48,7 @@ TEST(L0DeviceTest, GivenCreatedDeviceHandleWhenCallingdeviceReinitThenNewDeviceH
std::unique_ptr<DriverHandleImp> driverHandle(new DriverHandleImp);
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = Device::create(driverHandle.get(), neoDevice.release(), 1, false, &returnValue);
auto device = Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue);
ASSERT_NE(nullptr, device);
static_cast<DeviceImp *>(device)->releaseResources();
@ -67,7 +67,7 @@ TEST(L0DeviceTest, GivenDualStorageSharedMemorySupportedWhenCreatingDeviceThenPa
hwInfo.featureTable.ftrLocalMemory = true;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, &returnValue));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
auto deviceImp = static_cast<DeviceImp *>(device.get());
ASSERT_NE(nullptr, deviceImp->pageFaultCommandList);
@ -93,7 +93,7 @@ TEST(L0DeviceTest, givenMidThreadPreemptionWhenCreatingDeviceThenSipKernelIsInit
EXPECT_EQ(NEO::SipKernelType::COUNT, NEO::MockSipData::calledType);
EXPECT_FALSE(NEO::MockSipData::called);
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, &returnValue));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
EXPECT_EQ(NEO::SipKernelType::Csr, NEO::MockSipData::calledType);
@ -140,7 +140,7 @@ TEST(L0DeviceTest, givenDisabledPreemptionWhenCreatingDeviceThenSipKernelIsNotIn
EXPECT_EQ(NEO::SipKernelType::COUNT, NEO::MockSipData::calledType);
EXPECT_FALSE(NEO::MockSipData::called);
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, &returnValue));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
EXPECT_EQ(NEO::SipKernelType::COUNT, NEO::MockSipData::calledType);
@ -158,7 +158,7 @@ TEST(L0DeviceTest, givenDeviceWithoutFCLCompilerLibraryThenInvalidDependencyRetu
auto oldFclDllName = Os::frontEndDllName;
Os::frontEndDllName = "invalidFCL";
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, &returnValue));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
EXPECT_EQ(returnValue, ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
@ -176,7 +176,7 @@ TEST(L0DeviceTest, givenDeviceWithoutIGCCompilerLibraryThenInvalidDependencyRetu
auto oldIgcDllName = Os::igcDllName;
Os::igcDllName = "invalidIGC";
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, &returnValue));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
EXPECT_EQ(returnValue, ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
@ -196,7 +196,7 @@ TEST(L0DeviceTest, givenDeviceWithoutAnyCompilerLibraryThenInvalidDependencyRetu
Os::frontEndDllName = "invalidFCL";
Os::igcDllName = "invalidIGC";
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, &returnValue));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
EXPECT_EQ(returnValue, ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
@ -210,7 +210,7 @@ TEST(L0DeviceTest, givenFilledTopologyWhenGettingApiSliceThenCorrectSliceIdIsRet
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, nullptr));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, nullptr));
ASSERT_NE(nullptr, device);
auto deviceImp = static_cast<DeviceImp *>(device.get());
@ -248,7 +248,7 @@ TEST(L0DeviceTest, givenFilledTopologyForZeroSubDeviceWhenGettingApiSliceForHigh
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, nullptr));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, nullptr));
ASSERT_NE(nullptr, device);
auto deviceImp = static_cast<DeviceImp *>(device.get());
@ -274,7 +274,7 @@ TEST(L0DeviceTest, givenInvalidPhysicalSliceIdWhenGettingApiSliceIdThenFalseIsRe
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, nullptr));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, nullptr));
ASSERT_NE(nullptr, device);
auto deviceImp = static_cast<DeviceImp *>(device.get());
@ -300,7 +300,7 @@ TEST(L0DeviceTest, givenInvalidApiSliceIdWhenGettingPhysicalSliceIdThenFalseIsRe
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, nullptr));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, nullptr));
ASSERT_NE(nullptr, device);
auto deviceImp = static_cast<DeviceImp *>(device.get());
@ -327,7 +327,7 @@ TEST(L0DeviceTest, givenEmptyTopologyWhenGettingApiSliceIdThenFalseIsReturned) {
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, nullptr));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, nullptr));
ASSERT_NE(nullptr, device);
auto deviceImp = static_cast<DeviceImp *>(device.get());
@ -345,7 +345,7 @@ TEST(L0DeviceTest, givenDeviceWithoutSubDevicesWhenGettingPhysicalSliceIdThenCor
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, nullptr));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, nullptr));
ASSERT_NE(nullptr, device);
auto deviceImp = static_cast<DeviceImp *>(device.get());
@ -374,7 +374,7 @@ TEST(L0DeviceTest, givenTopologyNotAvaialbleWhenGettingPhysicalSliceIdThenFalseI
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), 1, false, nullptr));
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, nullptr));
ASSERT_NE(nullptr, device);
auto deviceImp = static_cast<DeviceImp *>(device.get());
@ -2184,7 +2184,7 @@ TEST(zeDevice, givenImagesSupportedWhenGettingImagePropertiesThenValidValuesAreR
NEO::MockCompilerEnableGuard mock(true);
DriverHandleImp driverHandle{};
NEO::MockDevice *neoDevice = (NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), 0));
auto device = std::unique_ptr<L0::Device>(Device::create(&driverHandle, neoDevice, 1, false, &errorValue));
auto device = std::unique_ptr<L0::Device>(Device::create(&driverHandle, neoDevice, false, &errorValue));
DeviceInfo &deviceInfo = neoDevice->deviceInfo;
deviceInfo.imageSupport = true;
@ -2215,7 +2215,7 @@ TEST(zeDevice, givenNoImagesSupportedWhenGettingImagePropertiesThenZeroValuesAre
NEO::MockCompilerEnableGuard mock(true);
DriverHandleImp driverHandle{};
NEO::MockDevice *neoDevice = (NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), 0));
auto device = std::unique_ptr<L0::Device>(Device::create(&driverHandle, neoDevice, 1, false, &errorValue));
auto device = std::unique_ptr<L0::Device>(Device::create(&driverHandle, neoDevice, false, &errorValue));
DeviceInfo &deviceInfo = neoDevice->deviceInfo;
neoDevice->deviceInfo.imageSupport = false;

View File

@ -187,7 +187,7 @@ HWTEST_F(ImportNTHandle, givenNTHandleWhenCreatingDeviceMemoryThenSuccessIsRetur
neoDevice->injectMemoryManager(currMemoryManager);
ze_result_t result = ZE_RESULT_SUCCESS;
auto device = L0::Device::create(driverHandle.get(), neoDevice, 0, false, &result);
auto device = L0::Device::create(driverHandle.get(), neoDevice, false, &result);
context->addDeviceAndSubDevices(device);

View File

@ -402,7 +402,7 @@ HWTEST2_F(ImageCreate, givenNTHandleWhenCreatingImageThenSuccessIsReturned, Imag
neoDevice->injectMemoryManager(currMemoryManager);
ze_result_t result = ZE_RESULT_SUCCESS;
auto device = L0::Device::create(driverHandle.get(), neoDevice, 0, false, &result);
auto device = L0::Device::create(driverHandle.get(), neoDevice, false, &result);
auto imageHW = std::make_unique<WhiteBox<::L0::ImageCoreFamily<gfxCoreFamily>>>();
auto ret = imageHW->initialize(device, &desc);
@ -453,7 +453,7 @@ HWTEST2_F(ImageCreate, givenImageDescWhenFailImageAllocationThenProperErrorIsRet
neoDevice->injectMemoryManager(currMemoryManager);
ze_result_t result = ZE_RESULT_SUCCESS;
auto device = L0::Device::create(driverHandle.get(), neoDevice, 0, false, &result);
auto device = L0::Device::create(driverHandle.get(), neoDevice, false, &result);
L0::Image *imageHandle;