2019-08-27 15:34:20 +08:00
|
|
|
/*
|
2020-12-30 21:36:22 +08:00
|
|
|
* Copyright (C) 2019-2021 Intel Corporation
|
2019-08-27 15:34:20 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/root_device.h"
|
2019-08-27 15:34:20 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
|
|
|
#include "shared/source/device/sub_device.h"
|
2020-10-19 16:02:28 +08:00
|
|
|
#include "shared/source/helpers/api_specific_config.h"
|
|
|
|
#include "shared/source/helpers/bindless_heaps_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2021-01-26 19:22:10 +08:00
|
|
|
#include "shared/source/utilities/software_tags_manager.h"
|
2019-08-27 15:34:20 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
2020-10-29 22:33:35 +08:00
|
|
|
extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment,
|
|
|
|
uint32_t rootDeviceIndex,
|
|
|
|
const DeviceBitfield deviceBitfield);
|
2020-01-20 14:02:07 +08:00
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
RootDevice::RootDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) : Device(executionEnvironment), rootDeviceIndex(rootDeviceIndex) {}
|
2019-08-27 15:34:20 +08:00
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
RootDevice::~RootDevice() {
|
2021-01-26 19:22:10 +08:00
|
|
|
if (getRootDeviceEnvironment().tagsManager) {
|
|
|
|
getRootDeviceEnvironment().tagsManager->shutdown();
|
|
|
|
}
|
2020-01-14 21:32:11 +08:00
|
|
|
}
|
2019-08-28 19:12:44 +08:00
|
|
|
|
2019-10-21 19:41:35 +08:00
|
|
|
uint32_t RootDevice::getRootDeviceIndex() const {
|
2019-10-24 19:34:25 +08:00
|
|
|
return rootDeviceIndex;
|
2019-10-21 19:41:35 +08:00
|
|
|
}
|
|
|
|
|
2021-04-08 01:00:33 +08:00
|
|
|
Device *RootDevice::getRootDevice() const {
|
|
|
|
return const_cast<RootDevice *>(this);
|
2020-07-15 18:38:34 +08:00
|
|
|
}
|
2019-10-10 21:56:10 +08:00
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
SubDevice *RootDevice::createSubDevice(uint32_t subDeviceIndex) {
|
|
|
|
return Device::create<SubDevice>(executionEnvironment, subDeviceIndex, *this);
|
|
|
|
}
|
|
|
|
|
2019-08-28 19:12:44 +08:00
|
|
|
bool RootDevice::createDeviceImpl() {
|
2021-01-25 17:24:00 +08:00
|
|
|
auto deviceMask = executionEnvironment->rootDeviceEnvironments[this->rootDeviceIndex]->deviceAffinityMask;
|
2021-04-10 01:52:17 +08:00
|
|
|
uint32_t subDeviceCount = HwHelper::getSubDevicesCount(&getHardwareInfo());
|
|
|
|
deviceBitfield = maxNBitValue(subDeviceCount);
|
2021-01-25 17:24:00 +08:00
|
|
|
deviceBitfield &= deviceMask;
|
|
|
|
numSubDevices = static_cast<uint32_t>(deviceBitfield.count());
|
2019-10-07 18:42:28 +08:00
|
|
|
if (numSubDevices == 1) {
|
|
|
|
numSubDevices = 0;
|
2019-08-28 19:12:44 +08:00
|
|
|
}
|
2020-01-14 21:32:11 +08:00
|
|
|
UNRECOVERABLE_IF(!subdevices.empty());
|
2021-01-25 17:24:00 +08:00
|
|
|
if (numSubDevices) {
|
2021-04-10 01:52:17 +08:00
|
|
|
subdevices.resize(subDeviceCount, nullptr);
|
|
|
|
for (auto i = 0u; i < subDeviceCount; i++) {
|
2021-01-25 17:24:00 +08:00
|
|
|
if (!deviceBitfield.test(i)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto subDevice = createSubDevice(i);
|
|
|
|
if (!subDevice) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
subdevices[i] = subDevice;
|
2019-08-28 19:12:44 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-07 18:42:28 +08:00
|
|
|
auto status = Device::createDeviceImpl();
|
|
|
|
if (!status) {
|
|
|
|
return status;
|
|
|
|
}
|
2020-10-19 16:02:28 +08:00
|
|
|
if (ApiSpecificConfig::getBindlessConfiguration()) {
|
2021-01-27 21:31:29 +08:00
|
|
|
this->executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->createBindlessHeapsHelper(getMemoryManager(), getNumAvailableDevices() > 1, rootDeviceIndex);
|
2020-10-19 16:02:28 +08:00
|
|
|
}
|
2021-01-26 19:22:10 +08:00
|
|
|
|
2019-08-28 19:12:44 +08:00
|
|
|
return true;
|
|
|
|
}
|
2021-01-25 17:24:00 +08:00
|
|
|
|
2019-10-07 18:42:28 +08:00
|
|
|
bool RootDevice::createEngines() {
|
2020-01-20 14:02:07 +08:00
|
|
|
if (getNumSubDevices() < 2) {
|
2019-10-07 18:42:28 +08:00
|
|
|
return Device::createEngines();
|
2020-01-20 14:02:07 +08:00
|
|
|
} else {
|
2020-12-30 21:36:22 +08:00
|
|
|
this->engineGroups.resize(static_cast<uint32_t>(EngineGroupType::MaxEngineGroups));
|
2020-01-20 14:02:07 +08:00
|
|
|
initializeRootCommandStreamReceiver();
|
2019-10-07 18:42:28 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-20 14:02:07 +08:00
|
|
|
|
|
|
|
void RootDevice::initializeRootCommandStreamReceiver() {
|
2020-10-28 23:08:37 +08:00
|
|
|
std::unique_ptr<CommandStreamReceiver> rootCommandStreamReceiver(createCommandStream(*executionEnvironment, rootDeviceIndex, getDeviceBitfield()));
|
2020-01-20 14:02:07 +08:00
|
|
|
|
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
auto defaultEngineType = getChosenEngineType(hwInfo);
|
|
|
|
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo);
|
|
|
|
|
2021-03-09 02:50:32 +08:00
|
|
|
auto osContext = getMemoryManager()->createAndRegisterOsContext(rootCommandStreamReceiver.get(),
|
|
|
|
EngineTypeUsage{defaultEngineType, EngineUsage::Regular},
|
|
|
|
getDeviceBitfield(),
|
|
|
|
preemptionMode,
|
|
|
|
true);
|
2020-01-20 14:02:07 +08:00
|
|
|
|
2021-04-20 22:42:58 +08:00
|
|
|
osContext->ensureContextInitialized();
|
2020-01-20 14:02:07 +08:00
|
|
|
rootCommandStreamReceiver->setupContext(*osContext);
|
|
|
|
rootCommandStreamReceiver->initializeTagAllocation();
|
2020-02-06 03:00:08 +08:00
|
|
|
rootCommandStreamReceiver->createGlobalFenceAllocation();
|
2021-02-17 01:04:00 +08:00
|
|
|
rootCommandStreamReceiver->createWorkPartitionAllocation(*this);
|
2020-01-20 14:02:07 +08:00
|
|
|
commandStreamReceivers.push_back(std::move(rootCommandStreamReceiver));
|
2020-12-30 21:36:22 +08:00
|
|
|
|
|
|
|
EngineControl engine{commandStreamReceivers.back().get(), osContext};
|
|
|
|
engines.push_back(engine);
|
|
|
|
addEngineToEngineGroup(engine);
|
2020-01-20 14:02:07 +08:00
|
|
|
}
|
|
|
|
|
2019-08-27 15:34:20 +08:00
|
|
|
} // namespace NEO
|