mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Affinity mask helper
Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
171a614f18
commit
9458638718
@@ -10,6 +10,7 @@
|
||||
#include "shared/source/built_ins/built_ins.h"
|
||||
#include "shared/source/built_ins/sip.h"
|
||||
#include "shared/source/execution_environment/root_device_environment.h"
|
||||
#include "shared/source/helpers/affinity_mask.h"
|
||||
#include "shared/source/helpers/hw_helper.h"
|
||||
#include "shared/source/memory_manager/memory_manager.h"
|
||||
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
||||
@@ -91,11 +92,9 @@ void ExecutionEnvironment::parseAffinityMask() {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::vector<bool>> affinityMaskBitSet(rootDeviceEnvironments.size());
|
||||
for (uint32_t i = 0; i < affinityMaskBitSet.size(); i++) {
|
||||
auto hwInfo = rootDeviceEnvironments[i]->getHardwareInfo();
|
||||
affinityMaskBitSet[i].resize(HwHelper::getSubDevicesCount(hwInfo));
|
||||
}
|
||||
const uint32_t numRootDevices = static_cast<uint32_t>(rootDeviceEnvironments.size());
|
||||
|
||||
std::vector<AffinityMaskHelper> affinityMaskHelper(numRootDevices);
|
||||
|
||||
size_t pos = 0;
|
||||
while (pos < affinityMaskString.size()) {
|
||||
@@ -103,21 +102,21 @@ void ExecutionEnvironment::parseAffinityMask() {
|
||||
size_t posNextComma = affinityMaskString.find_first_of(",", pos);
|
||||
std::string rootDeviceString = affinityMaskString.substr(pos, std::min(posNextDot, posNextComma) - pos);
|
||||
uint32_t rootDeviceIndex = static_cast<uint32_t>(std::stoul(rootDeviceString, nullptr, 0));
|
||||
if (rootDeviceIndex < rootDeviceEnvironments.size()) {
|
||||
if (rootDeviceIndex < numRootDevices) {
|
||||
auto hwInfo = rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo();
|
||||
auto subDevicesCount = HwHelper::getSubDevicesCount(hwInfo);
|
||||
|
||||
pos += rootDeviceString.size();
|
||||
if (posNextDot != std::string::npos &&
|
||||
affinityMaskString.at(pos) == '.' && posNextDot < posNextComma) {
|
||||
pos++;
|
||||
std::string subDeviceString = affinityMaskString.substr(pos, posNextComma - pos);
|
||||
uint32_t subDeviceIndex = static_cast<uint32_t>(std::stoul(subDeviceString, nullptr, 0));
|
||||
auto hwInfo = rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo();
|
||||
if (subDeviceIndex < HwHelper::getSubDevicesCount(hwInfo)) {
|
||||
affinityMaskBitSet[rootDeviceIndex][subDeviceIndex] = true;
|
||||
if (subDeviceIndex < subDevicesCount) {
|
||||
affinityMaskHelper[rootDeviceIndex].enableGenericSubDevice(subDeviceIndex);
|
||||
}
|
||||
} else {
|
||||
std::fill(affinityMaskBitSet[rootDeviceIndex].begin(),
|
||||
affinityMaskBitSet[rootDeviceIndex].end(),
|
||||
true);
|
||||
affinityMaskHelper[rootDeviceIndex].enableAllGenericSubDevices(subDevicesCount);
|
||||
}
|
||||
}
|
||||
if (posNextComma == std::string::npos) {
|
||||
@@ -126,31 +125,13 @@ void ExecutionEnvironment::parseAffinityMask() {
|
||||
pos = posNextComma + 1;
|
||||
}
|
||||
|
||||
uint32_t offset = 0;
|
||||
uint32_t affinityMask = 0;
|
||||
for (uint32_t i = 0; i < affinityMaskBitSet.size(); i++) {
|
||||
for (uint32_t j = 0; j < affinityMaskBitSet[i].size(); j++) {
|
||||
if (affinityMaskBitSet[i][j] == true) {
|
||||
affinityMask |= (1UL << offset);
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t currentMaskOffset = 0;
|
||||
std::vector<std::unique_ptr<RootDeviceEnvironment>> filteredEnvironments;
|
||||
for (size_t i = 0u; i < this->rootDeviceEnvironments.size(); i++) {
|
||||
auto hwInfo = rootDeviceEnvironments[i]->getHardwareInfo();
|
||||
|
||||
uint32_t currentDeviceMask = (affinityMask >> currentMaskOffset) & ((1UL << HwHelper::getSubDevicesCount(hwInfo)) - 1);
|
||||
bool isDeviceExposed = currentDeviceMask > 0;
|
||||
|
||||
currentMaskOffset += HwHelper::getSubDevicesCount(hwInfo);
|
||||
if (!isDeviceExposed) {
|
||||
for (uint32_t i = 0u; i < numRootDevices; i++) {
|
||||
if (!affinityMaskHelper[i].isDeviceEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rootDeviceEnvironments[i]->deviceAffinityMask = currentDeviceMask;
|
||||
rootDeviceEnvironments[i]->deviceAffinityMask = affinityMaskHelper[i];
|
||||
filteredEnvironments.emplace_back(rootDeviceEnvironments[i].release());
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/built_ins/sip_kernel_type.h"
|
||||
#include "shared/source/helpers/affinity_mask.h"
|
||||
#include "shared/source/helpers/options.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -33,8 +34,6 @@ class SipKernel;
|
||||
class SWTagsManager;
|
||||
struct HardwareInfo;
|
||||
|
||||
constexpr uint32_t allSubDevicesActive = std::numeric_limits<uint32_t>::max();
|
||||
|
||||
struct RootDeviceEnvironment {
|
||||
protected:
|
||||
std::unique_ptr<HardwareInfo> hwInfo;
|
||||
@@ -74,7 +73,7 @@ struct RootDeviceEnvironment {
|
||||
std::unique_ptr<SWTagsManager> tagsManager;
|
||||
ExecutionEnvironment &executionEnvironment;
|
||||
|
||||
uint32_t deviceAffinityMask = allSubDevicesActive;
|
||||
AffinityMaskHelper deviceAffinityMask{true};
|
||||
|
||||
private:
|
||||
std::mutex mtx;
|
||||
|
||||
Reference in New Issue
Block a user