Ensure shared allocations made resident across multiple devices

Signed-off-by: Raiyan Latif <raiyan.latif@intel.com>
This commit is contained in:
Raiyan Latif
2022-07-12 16:43:14 +00:00
committed by Compute-Runtime-Automation
parent 8a6d6dd449
commit 1ed273dab8
6 changed files with 95 additions and 6 deletions

View File

@@ -65,6 +65,9 @@ struct DriverHandle : _ze_driver_handle_t {
size_t size,
uint32_t rootDeviceIndex,
uintptr_t *gpuAddress) = 0;
virtual ze_result_t makeMemoryResident(ze_device_handle_t hDevice,
void *ptr,
size_t size) = 0;
static DriverHandle *fromHandle(ze_driver_handle_t handle) { return static_cast<DriverHandle *>(handle); }
inline ze_driver_handle_t toHandle() { return this; }

View File

@@ -578,6 +578,28 @@ NEO::GraphicsAllocation *DriverHandleImp::getPeerAllocation(Device *device,
return alloc;
}
ze_result_t DriverHandleImp::makeMemoryResident(ze_device_handle_t hDevice, void *ptr, size_t size) {
Device *device = L0::Device::fromHandle(hDevice);
NEO::Device *neoDevice = device->getNEODevice();
auto allocation = device->getDriverHandle()->getDriverSystemMemoryAllocation(
ptr,
size,
neoDevice->getRootDeviceIndex(),
nullptr);
if (allocation == nullptr) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
if (allocData && allocData->memoryType == InternalMemoryType::SHARED_UNIFIED_MEMORY) {
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(device->getDriverHandle());
std::lock_guard<std::mutex> lock(driverHandleImp->sharedMakeResidentAllocationsLock);
driverHandleImp->sharedMakeResidentAllocations.insert({ptr, allocation});
}
return ZE_RESULT_SUCCESS;
}
void *DriverHandleImp::importNTHandle(ze_device_handle_t hDevice, void *handle) {
auto neoDevice = Device::fromHandle(hDevice)->getNEODevice();

View File

@@ -83,6 +83,10 @@ struct DriverHandleImp : public DriverHandle {
std::mutex sharedMakeResidentAllocationsLock;
std::map<void *, NEO::GraphicsAllocation *> sharedMakeResidentAllocations;
ze_result_t makeMemoryResident(ze_device_handle_t hDevice,
void *ptr,
size_t size) override;
std::vector<Device *> devices;
// Spec extensions
const std::vector<std::pair<std::string, uint32_t>> extensionsSupported = {