mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
Clean up context vector of devices
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
325db6a99c
commit
1670081df7
@@ -46,14 +46,6 @@ ContextImp::ContextImp(DriverHandle *driverHandle) {
|
||||
this->driverHandle = static_cast<DriverHandleImp *>(driverHandle);
|
||||
}
|
||||
|
||||
void ContextImp::addDeviceAndSubDevices(Device *device) {
|
||||
this->devices.insert(std::make_pair(device->toHandle(), device));
|
||||
DeviceImp *deviceImp = static_cast<DeviceImp *>(device);
|
||||
for (auto subDevice : deviceImp->subDevices) {
|
||||
this->addDeviceAndSubDevices(subDevice);
|
||||
}
|
||||
}
|
||||
|
||||
ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc,
|
||||
size_t size,
|
||||
size_t alignment,
|
||||
@@ -101,7 +93,8 @@ ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc,
|
||||
}
|
||||
|
||||
bool ContextImp::isDeviceDefinedForThisContext(Device *inDevice) {
|
||||
return (this->getDevices().find(inDevice->toHandle()) != this->getDevices().end());
|
||||
uint32_t deviceIndex = inDevice->getRootDeviceIndex();
|
||||
return (this->getDevices().find(deviceIndex) != this->getDevices().end());
|
||||
}
|
||||
|
||||
ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice,
|
||||
@@ -196,7 +189,7 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
|
||||
size += (MemoryConstants::pageSize * NEO::DebugManager.flags.ForceExtendedUSMBufferSize.get());
|
||||
}
|
||||
|
||||
auto device = this->devices.begin()->second;
|
||||
auto device = Device::fromHandle(this->devices.begin()->second);
|
||||
if (hDevice != nullptr) {
|
||||
device = Device::fromHandle(hDevice);
|
||||
}
|
||||
@@ -277,6 +270,25 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void ContextImp::freePeerAllocations(const void *ptr, bool blocking, Device *device) {
|
||||
DeviceImp *deviceImp = static_cast<DeviceImp *>(device);
|
||||
|
||||
std::unique_lock<NEO::SpinLock> lock(deviceImp->peerAllocationsMutex);
|
||||
|
||||
auto iter = deviceImp->peerAllocations.allocations.find(ptr);
|
||||
if (iter != deviceImp->peerAllocations.allocations.end()) {
|
||||
auto peerAllocData = &iter->second;
|
||||
auto peerAlloc = peerAllocData->gpuAllocations.getDefaultGraphicsAllocation();
|
||||
auto peerPtr = reinterpret_cast<void *>(peerAlloc->getGpuAddress());
|
||||
this->driverHandle->svmAllocsManager->freeSVMAlloc(peerPtr, blocking);
|
||||
deviceImp->peerAllocations.allocations.erase(iter);
|
||||
}
|
||||
|
||||
for (auto subDevice : deviceImp->subDevices) {
|
||||
this->freePeerAllocations(ptr, blocking, subDevice);
|
||||
}
|
||||
}
|
||||
|
||||
ze_result_t ContextImp::freeMem(const void *ptr) {
|
||||
return this->freeMem(ptr, false);
|
||||
}
|
||||
@@ -288,18 +300,7 @@ ze_result_t ContextImp::freeMem(const void *ptr, bool blocking) {
|
||||
}
|
||||
|
||||
for (auto pairDevice : this->devices) {
|
||||
DeviceImp *deviceImp = static_cast<DeviceImp *>(pairDevice.second);
|
||||
|
||||
std::unique_lock<NEO::SpinLock> lock(deviceImp->peerAllocationsMutex);
|
||||
|
||||
auto iter = deviceImp->peerAllocations.allocations.find(ptr);
|
||||
if (iter != deviceImp->peerAllocations.allocations.end()) {
|
||||
auto peerAllocData = &iter->second;
|
||||
auto peerAlloc = peerAllocData->gpuAllocations.getDefaultGraphicsAllocation();
|
||||
auto peerPtr = reinterpret_cast<void *>(peerAlloc->getGpuAddress());
|
||||
this->driverHandle->svmAllocsManager->freeSVMAlloc(peerPtr, blocking);
|
||||
deviceImp->peerAllocations.allocations.erase(iter);
|
||||
}
|
||||
this->freePeerAllocations(ptr, blocking, Device::fromHandle(pairDevice.second));
|
||||
}
|
||||
|
||||
this->driverHandle->svmAllocsManager->freeSVMAlloc(const_cast<void *>(ptr), blocking);
|
||||
@@ -534,7 +535,7 @@ ze_result_t ContextImp::openEventPoolIpcHandle(ze_ipc_event_pool_handle_t hIpc,
|
||||
memcpy_s(&rootDeviceIndex, sizeof(rootDeviceIndex),
|
||||
hIpc.data + sizeof(int) + sizeof(numEvents), sizeof(rootDeviceIndex));
|
||||
|
||||
Device *device = this->devices.begin()->second;
|
||||
auto device = Device::fromHandle(this->devices.begin()->second);
|
||||
auto neoDevice = device->getNEODevice();
|
||||
NEO::osHandle osHandle = static_cast<NEO::osHandle>(handle);
|
||||
auto &hwHelper = device->getHwHelper();
|
||||
|
||||
@@ -132,12 +132,12 @@ struct ContextImp : Context {
|
||||
const ze_image_desc_t *desc,
|
||||
ze_image_handle_t *phImage) override;
|
||||
|
||||
void addDeviceAndSubDevices(Device *device);
|
||||
|
||||
std::map<ze_device_handle_t, Device *> &getDevices() {
|
||||
std::map<uint32_t, ze_device_handle_t> &getDevices() {
|
||||
return devices;
|
||||
}
|
||||
|
||||
void freePeerAllocations(const void *ptr, bool blocking, Device *device);
|
||||
|
||||
RootDeviceIndicesContainer rootDeviceIndices;
|
||||
std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields;
|
||||
|
||||
@@ -148,7 +148,7 @@ struct ContextImp : Context {
|
||||
protected:
|
||||
bool isAllocationSuitableForCompression(const StructuresLookupTable &structuresLookupTable, Device &device, size_t allocSize);
|
||||
|
||||
std::map<ze_device_handle_t, Device *> devices;
|
||||
std::map<uint32_t, ze_device_handle_t> devices;
|
||||
DriverHandleImp *driverHandle = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -59,20 +59,22 @@ ze_result_t DriverHandleImp::createContext(const ze_context_desc_t *desc,
|
||||
|
||||
if (numDevices == 0) {
|
||||
for (auto device : this->devices) {
|
||||
context->addDeviceAndSubDevices(device);
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->getDevices().insert(std::make_pair(neoDevice->getRootDeviceIndex(), device->toHandle()));
|
||||
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(),
|
||||
neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
} else {
|
||||
for (uint32_t i = 0; i < numDevices; i++) {
|
||||
context->addDeviceAndSubDevices(Device::fromHandle(phDevices[i]));
|
||||
auto neoDevice = Device::fromHandle(phDevices[i])->getNEODevice();
|
||||
context->getDevices().insert(std::make_pair(neoDevice->getRootDeviceIndex(), phDevices[i]));
|
||||
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(),
|
||||
neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
}
|
||||
|
||||
for (auto devicePair : context->getDevices()) {
|
||||
auto neoDevice = devicePair.second->getNEODevice();
|
||||
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(),
|
||||
neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
context->rootDeviceIndices.remove_duplicates();
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user