mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Remove csrsContainer from root device environment
improve mocking: - add method to create RootDevice in Platform - add method to create SubDevice in RootDevice - add method to create CommandStreamReceiver in Device Related-To: NEO-3691 Change-Id: Ie9fe3de260492604333c8ca93796bfbffae518c4 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
4102b9cf3d
commit
5a8f455a84
@@ -16,6 +16,7 @@ set(RUNTIME_SRCS_DEVICE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/driver_info.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/root_device.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/root_device.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/root_device_initialize.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sub_device.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sub_device.h
|
||||
)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
namespace NEO {
|
||||
|
||||
decltype(&PerformanceCounters::create) Device::createPerformanceCountersFunc = PerformanceCounters::create;
|
||||
extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex);
|
||||
|
||||
DeviceVector::DeviceVector(const cl_device_id *devices,
|
||||
cl_uint numDevices) {
|
||||
@@ -41,8 +42,8 @@ void DeviceVector::toDeviceIDs(std::vector<cl_device_id> &devIDs) {
|
||||
}
|
||||
}
|
||||
|
||||
Device::Device(ExecutionEnvironment *executionEnvironment, uint32_t internalDeviceIndex)
|
||||
: executionEnvironment(executionEnvironment), internalDeviceIndex(internalDeviceIndex) {
|
||||
Device::Device(ExecutionEnvironment *executionEnvironment)
|
||||
: executionEnvironment(executionEnvironment) {
|
||||
memset(&deviceInfo, 0, sizeof(deviceInfo));
|
||||
deviceExtensions.reserve(1000);
|
||||
name.reserve(100);
|
||||
@@ -70,7 +71,7 @@ Device::~Device() {
|
||||
if (deviceInfo.sourceLevelDebuggerActive && executionEnvironment->sourceLevelDebugger) {
|
||||
executionEnvironment->sourceLevelDebugger->notifyDeviceDestruction();
|
||||
}
|
||||
|
||||
commandStreamReceivers.clear();
|
||||
executionEnvironment->memoryManager->waitForDeletions();
|
||||
executionEnvironment->decRefInternal();
|
||||
}
|
||||
@@ -132,18 +133,24 @@ bool Device::createEngines() {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandStreamReceiver> Device::createCommandStreamReceiver() const {
|
||||
return std::unique_ptr<CommandStreamReceiver>(createCommandStream(*executionEnvironment, getRootDeviceIndex()));
|
||||
}
|
||||
|
||||
bool Device::createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engineType) {
|
||||
auto &hwInfo = getHardwareInfo();
|
||||
auto defaultEngineType = getChosenEngineType(hwInfo);
|
||||
|
||||
if (!executionEnvironment->initializeCommandStreamReceiver(getRootDeviceIndex(), internalDeviceIndex, deviceCsrIndex)) {
|
||||
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver = createCommandStreamReceiver();
|
||||
if (!commandStreamReceiver) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto commandStreamReceiver = executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()].commandStreamReceivers[internalDeviceIndex][deviceCsrIndex].get();
|
||||
if (HwHelper::get(hwInfo.platform.eRenderCoreFamily).isPageTableManagerSupported(hwInfo)) {
|
||||
commandStreamReceiver->createPageTableManager();
|
||||
}
|
||||
|
||||
bool lowPriority = (deviceCsrIndex == HwHelper::lowPriorityGpgpuEngineIndex);
|
||||
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver, engineType,
|
||||
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(), engineType,
|
||||
getDeviceBitfieldForOsContext(), preemptionMode, lowPriority);
|
||||
commandStreamReceiver->setupContext(*osContext);
|
||||
|
||||
@@ -158,7 +165,8 @@ bool Device::createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engine
|
||||
return false;
|
||||
}
|
||||
|
||||
engines.push_back({commandStreamReceiver, osContext});
|
||||
engines.push_back({commandStreamReceiver.get(), osContext});
|
||||
commandStreamReceivers.push_back(std::move(commandStreamReceiver));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -219,4 +227,5 @@ EngineControl &Device::getEngine(aub_stream::EngineType engineType, bool lowPrio
|
||||
}
|
||||
UNRECOVERABLE_IF(true);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -99,13 +99,10 @@ class Device : public BaseObject<_cl_device_id> {
|
||||
}
|
||||
virtual uint32_t getNumAvailableDevices() const = 0;
|
||||
virtual Device *getDeviceById(uint32_t deviceId) const = 0;
|
||||
uint32_t getInternalDeviceIndex() const {
|
||||
return internalDeviceIndex;
|
||||
}
|
||||
|
||||
protected:
|
||||
Device() = delete;
|
||||
Device(ExecutionEnvironment *executionEnvironment, uint32_t internalDeviceIndex);
|
||||
Device(ExecutionEnvironment *executionEnvironment);
|
||||
|
||||
template <typename T>
|
||||
static T *createDeviceInternals(T *device) {
|
||||
@@ -121,6 +118,7 @@ class Device : public BaseObject<_cl_device_id> {
|
||||
virtual bool createEngines();
|
||||
bool createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engineType);
|
||||
|
||||
MOCKABLE_VIRTUAL std::unique_ptr<CommandStreamReceiver> createCommandStreamReceiver() const;
|
||||
MOCKABLE_VIRTUAL void initializeCaps();
|
||||
void setupFp64Flags();
|
||||
void appendOSExtensions(std::string &deviceExtensions);
|
||||
@@ -132,13 +130,13 @@ class Device : public BaseObject<_cl_device_id> {
|
||||
std::unique_ptr<DriverInfo> driverInfo;
|
||||
std::unique_ptr<PerformanceCounters> performanceCounters;
|
||||
|
||||
std::vector<std::unique_ptr<CommandStreamReceiver>> commandStreamReceivers;
|
||||
std::vector<EngineControl> engines;
|
||||
|
||||
std::string exposedBuiltinKernels = "";
|
||||
|
||||
PreemptionMode preemptionMode;
|
||||
ExecutionEnvironment *executionEnvironment = nullptr;
|
||||
const uint32_t internalDeviceIndex;
|
||||
uint32_t defaultEngineIndex = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "runtime/os_interface/debug_settings_manager.h"
|
||||
|
||||
namespace NEO {
|
||||
RootDevice::RootDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) : Device(executionEnvironment), rootDeviceIndex(rootDeviceIndex) {}
|
||||
|
||||
RootDevice::~RootDevice() = default;
|
||||
|
||||
@@ -38,7 +39,10 @@ Device *RootDevice::getDeviceById(uint32_t deviceId) const {
|
||||
return subdevices[deviceId].get();
|
||||
};
|
||||
|
||||
RootDevice::RootDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) : Device(executionEnvironment, 0u), rootDeviceIndex(rootDeviceIndex) {}
|
||||
SubDevice *RootDevice::createSubDevice(uint32_t subDeviceIndex) {
|
||||
return Device::create<SubDevice>(executionEnvironment, subDeviceIndex, *this);
|
||||
}
|
||||
|
||||
bool RootDevice::createDeviceImpl() {
|
||||
auto numSubDevices = DeviceHelper::getSubDevicesCount(&getHardwareInfo());
|
||||
if (numSubDevices == 1) {
|
||||
@@ -47,7 +51,7 @@ bool RootDevice::createDeviceImpl() {
|
||||
subdevices.resize(numSubDevices);
|
||||
for (auto i = 0u; i < numSubDevices; i++) {
|
||||
|
||||
auto subDevice = Device::create<SubDevice>(executionEnvironment, i + 1, i, *this);
|
||||
auto subDevice = createSubDevice(i);
|
||||
if (!subDevice) {
|
||||
return false;
|
||||
}
|
||||
@@ -71,22 +75,14 @@ unique_ptr_if_unused<Device> RootDevice::release() {
|
||||
}
|
||||
DeviceBitfield RootDevice::getDeviceBitfieldForOsContext() const {
|
||||
DeviceBitfield deviceBitfield;
|
||||
deviceBitfield.set(internalDeviceIndex);
|
||||
deviceBitfield.set(0);
|
||||
return deviceBitfield;
|
||||
}
|
||||
|
||||
bool RootDevice::createEngines() {
|
||||
if (!executionEnvironment->initializeRootCommandStreamReceiver(*this)) {
|
||||
if (!initializeRootCommandStreamReceiver()) {
|
||||
return Device::createEngines();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RootDevice::setupRootEngine(EngineControl engine) {
|
||||
if (engines.size() > 0u) {
|
||||
return;
|
||||
}
|
||||
defaultEngineIndex = 0;
|
||||
engines.emplace_back(engine);
|
||||
}
|
||||
} // namespace NEO
|
||||
|
||||
@@ -18,17 +18,21 @@ class RootDevice : public Device {
|
||||
~RootDevice() override;
|
||||
bool createDeviceImpl() override;
|
||||
uint32_t getNumAvailableDevices() const override;
|
||||
uint32_t getNumSubDevices() const;
|
||||
uint32_t getRootDeviceIndex() const override;
|
||||
Device *getDeviceById(uint32_t deviceId) const override;
|
||||
/* We hide the retain and release function of BaseObject. */
|
||||
void retain() override;
|
||||
unique_ptr_if_unused<Device> release() override;
|
||||
void setupRootEngine(EngineControl engineControl);
|
||||
|
||||
uint32_t getNumSubDevices() const;
|
||||
|
||||
protected:
|
||||
DeviceBitfield getDeviceBitfieldForOsContext() const override;
|
||||
bool createEngines() override;
|
||||
|
||||
MOCKABLE_VIRTUAL bool initializeRootCommandStreamReceiver();
|
||||
MOCKABLE_VIRTUAL SubDevice *createSubDevice(uint32_t subDeviceIndex);
|
||||
|
||||
std::vector<std::unique_ptr<SubDevice>> subdevices;
|
||||
const uint32_t rootDeviceIndex;
|
||||
};
|
||||
|
||||
15
runtime/device/root_device_initialize.cpp
Normal file
15
runtime/device/root_device_initialize.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/device/root_device.h"
|
||||
|
||||
namespace NEO {
|
||||
bool RootDevice::initializeRootCommandStreamReceiver() {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
SubDevice::SubDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex, uint32_t subDeviceIndex, RootDevice &rootDevice) : Device(executionEnvironment, deviceIndex), subDeviceIndex(subDeviceIndex), rootDevice(rootDevice) {}
|
||||
SubDevice::SubDevice(ExecutionEnvironment *executionEnvironment, uint32_t subDeviceIndex, RootDevice &rootDevice) : Device(executionEnvironment), subDeviceIndex(subDeviceIndex), rootDevice(rootDevice) {}
|
||||
void SubDevice::retain() {
|
||||
rootDevice.incRefInternal();
|
||||
Device::retain();
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace NEO {
|
||||
class RootDevice;
|
||||
class SubDevice : public Device {
|
||||
public:
|
||||
SubDevice(ExecutionEnvironment *executionEnvironment, uint32_t internalDeviceIndex, uint32_t subDeviceIndex, RootDevice &rootDevice);
|
||||
SubDevice(ExecutionEnvironment *executionEnvironment, uint32_t subDeviceIndex, RootDevice &rootDevice);
|
||||
void retain() override;
|
||||
unique_ptr_if_unused<Device> release() override;
|
||||
void retainInternal();
|
||||
|
||||
Reference in New Issue
Block a user