mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Fix thread safety violations within runtime allocators
Change-Id: I925d15429de314e3d3287f41a054732181911851 Signed-off-by: Vinod Tipparaju <vinod.tipparaju@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
ac62fce964
commit
c98949fd37
@@ -45,9 +45,9 @@ void CommandList::removeDeallocationContainerData() {
|
||||
for (auto deallocation : container) {
|
||||
DEBUG_BREAK_IF(deallocation == nullptr);
|
||||
UNRECOVERABLE_IF(memoryManager == nullptr);
|
||||
NEO::SvmAllocationData *allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(reinterpret_cast<void *>(deallocation->getGpuAddress()));
|
||||
NEO::SvmAllocationData *allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(reinterpret_cast<void *>(deallocation->getGpuAddress()));
|
||||
if (allocData) {
|
||||
device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->remove(*allocData);
|
||||
device->getDriverHandle()->getSvmAllocsManager()->removeSVMAlloc(*allocData);
|
||||
}
|
||||
if (!((deallocation->getAllocationType() == NEO::GraphicsAllocation::AllocationType::INTERNAL_HEAP) ||
|
||||
(deallocation->getAllocationType() == NEO::GraphicsAllocation::AllocationType::LINEAR_STREAM))) {
|
||||
|
||||
@@ -529,7 +529,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemAdvise(ze_device_hand
|
||||
const void *ptr, size_t size,
|
||||
ze_memory_advice_t advice) {
|
||||
|
||||
auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(ptr);
|
||||
auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
|
||||
if (allocData) {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
@@ -914,7 +914,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemoryCopyKernel2d(NEO::
|
||||
template <GFXCORE_FAMILY gfxCoreFamily>
|
||||
ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemoryPrefetch(const void *ptr,
|
||||
size_t count) {
|
||||
auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(ptr);
|
||||
auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
|
||||
if (allocData) {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
@@ -1249,7 +1249,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::reset() {
|
||||
template <GFXCORE_FAMILY gfxCoreFamily>
|
||||
ze_result_t CommandListCoreFamily<gfxCoreFamily>::prepareIndirectParams(const ze_group_count_t *pThreadGroupDimensions) {
|
||||
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
|
||||
auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(pThreadGroupDimensions);
|
||||
auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(pThreadGroupDimensions);
|
||||
if (allocData) {
|
||||
auto alloc = allocData->gpuAllocation;
|
||||
commandContainer.addToResidencyContainer(alloc);
|
||||
|
||||
@@ -179,7 +179,7 @@ ze_result_t DeviceImp::evictImage(ze_image_handle_t hImage) {
|
||||
}
|
||||
|
||||
ze_result_t DeviceImp::evictMemory(void *ptr, size_t size) {
|
||||
auto alloc = getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(ptr);
|
||||
auto alloc = getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
|
||||
if (alloc == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -390,7 +390,7 @@ ze_result_t DeviceImp::makeImageResident(ze_image_handle_t hImage) {
|
||||
}
|
||||
|
||||
ze_result_t DeviceImp::makeMemoryResident(void *ptr, size_t size) {
|
||||
auto alloc = getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(ptr);
|
||||
auto alloc = getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
|
||||
if (alloc == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -676,7 +676,7 @@ NEO::GraphicsAllocation *DeviceImp::allocateManagedMemoryFromHostPtr(void *buffe
|
||||
char *allocAddress = reinterpret_cast<char *>(allocation->getGpuAddress());
|
||||
size_t allocSize = allocData->size;
|
||||
|
||||
driverHandle->getSvmAllocsManager()->getSVMAllocs()->remove(*allocData);
|
||||
driverHandle->getSvmAllocsManager()->removeSVMAlloc(*allocData);
|
||||
neoDevice->getMemoryManager()->freeGraphicsMemory(allocation);
|
||||
commandList->eraseDeallocationContainerEntry(allocation);
|
||||
commandList->eraseResidencyContainerEntry(allocation);
|
||||
@@ -713,7 +713,7 @@ NEO::GraphicsAllocation *DeviceImp::allocateManagedMemoryFromHostPtr(void *buffe
|
||||
allocData.size = size;
|
||||
allocData.memoryType = InternalMemoryType::NOT_SPECIFIED;
|
||||
allocData.device = nullptr;
|
||||
driverHandle->getSvmAllocsManager()->getSVMAllocs()->insert(allocData);
|
||||
driverHandle->getSvmAllocsManager()->insertSVMAlloc(allocData);
|
||||
|
||||
return allocation;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ ze_result_t DriverHandleImp::getExtensionFunctionAddress(const char *pFuncName,
|
||||
ze_result_t DriverHandleImp::getMemAllocProperties(const void *ptr,
|
||||
ze_memory_allocation_properties_t *pMemAllocProperties,
|
||||
ze_device_handle_t *phDevice) {
|
||||
auto alloc = svmAllocsManager->getSVMAllocs()->get(ptr);
|
||||
auto alloc = svmAllocsManager->getSVMAlloc(ptr);
|
||||
if (alloc) {
|
||||
pMemAllocProperties->type = parseUSMType(alloc->memoryType);
|
||||
pMemAllocProperties->id = alloc->gpuAllocation->getGpuAddress();
|
||||
@@ -181,8 +181,8 @@ bool DriverHandleImp::findAllocationDataForRange(const void *buffer,
|
||||
NEO::SvmAllocationData **allocData) {
|
||||
// Make sure the host buffer does not overlap any existing allocation
|
||||
const char *baseAddress = reinterpret_cast<const char *>(buffer);
|
||||
NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAllocs()->get(baseAddress);
|
||||
NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAllocs()->get(baseAddress + size - 1);
|
||||
NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAlloc(baseAddress);
|
||||
NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + size - 1);
|
||||
|
||||
if (allocData) {
|
||||
if (beginAllocData) {
|
||||
@@ -206,8 +206,8 @@ std::vector<NEO::SvmAllocationData *> DriverHandleImp::findAllocationsWithinRang
|
||||
std::vector<NEO::SvmAllocationData *> allocDataArray;
|
||||
const char *baseAddress = reinterpret_cast<const char *>(buffer);
|
||||
// Check if the host buffer overlaps any existing allocation
|
||||
NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAllocs()->get(baseAddress);
|
||||
NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAllocs()->get(baseAddress + size - 1);
|
||||
NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAlloc(baseAddress);
|
||||
NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + size - 1);
|
||||
|
||||
// Add the allocation that matches the beginning address
|
||||
if (beginAllocData) {
|
||||
|
||||
@@ -487,7 +487,7 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi
|
||||
|
||||
auto requestedAddress = *reinterpret_cast<void *const *>(argVal);
|
||||
auto svmAllocsManager = module->getDevice()->getDriverHandle()->getSvmAllocsManager();
|
||||
NEO::GraphicsAllocation *alloc = svmAllocsManager->getSVMAllocs()->get(requestedAddress)->gpuAllocation;
|
||||
NEO::GraphicsAllocation *alloc = svmAllocsManager->getSVMAlloc(requestedAddress)->gpuAllocation;
|
||||
auto gpuAddress = reinterpret_cast<uintptr_t>(requestedAddress);
|
||||
return setArgBufferWithAlloc(argIndex, gpuAddress, alloc);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
namespace L0 {
|
||||
|
||||
ze_result_t DriverHandleImp::getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) {
|
||||
NEO::SvmAllocationData *allocData = svmAllocsManager->getSVMAllocs()->get(ptr);
|
||||
NEO::SvmAllocationData *allocData = svmAllocsManager->getSVMAlloc(ptr);
|
||||
if (allocData) {
|
||||
uint64_t handle = allocData->gpuAllocation->peekInternalHandle(this->getMemoryManager());
|
||||
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
|
||||
@@ -49,7 +49,7 @@ ze_result_t DriverHandleImp::openIpcMemHandle(ze_device_handle_t hDevice, ze_ipc
|
||||
allocData.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
|
||||
allocData.device = Device::fromHandle(hDevice)->getNEODevice();
|
||||
|
||||
this->getSvmAllocsManager()->getSVMAllocs()->insert(allocData);
|
||||
this->getSvmAllocsManager()->insertSVMAlloc(allocData);
|
||||
|
||||
*ptr = reinterpret_cast<void *>(alloc->getGpuAddress());
|
||||
|
||||
@@ -61,7 +61,7 @@ ze_result_t DriverHandleImp::closeIpcMemHandle(const void *ptr) {
|
||||
}
|
||||
|
||||
ze_result_t DriverHandleImp::checkMemoryAccessFromDevice(Device *device, const void *ptr) {
|
||||
auto allocation = svmAllocsManager->getSVMAllocs()->get(ptr);
|
||||
auto allocation = svmAllocsManager->getSVMAlloc(ptr);
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ ze_result_t DriverHandleImp::checkMemoryAccessFromDevice(Device *device, const v
|
||||
}
|
||||
|
||||
ze_result_t DriverHandleImp::getMemAddressRange(const void *ptr, void **pBase, size_t *pSize) {
|
||||
NEO::SvmAllocationData *allocData = svmAllocsManager->getSVMAllocs()->get(ptr);
|
||||
NEO::SvmAllocationData *allocData = svmAllocsManager->getSVMAlloc(ptr);
|
||||
if (allocData) {
|
||||
NEO::GraphicsAllocation *alloc;
|
||||
alloc = allocData->gpuAllocation;
|
||||
@@ -166,7 +166,7 @@ ze_result_t DriverHandleImp::allocSharedMem(ze_device_handle_t hDevice, ze_devic
|
||||
}
|
||||
|
||||
ze_result_t DriverHandleImp::freeMem(const void *ptr) {
|
||||
auto allocation = svmAllocsManager->getSVMAllocs()->get(ptr);
|
||||
auto allocation = svmAllocsManager->getSVMAlloc(ptr);
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ ze_result_t Mock<DriverHandle>::doAllocDeviceMem(ze_device_handle_t hDevice, ze_
|
||||
}
|
||||
|
||||
ze_result_t Mock<DriverHandle>::doFreeMem(const void *ptr) {
|
||||
auto allocation = svmAllocsManager->getSVMAllocs()->get(ptr);
|
||||
auto allocation = svmAllocsManager->getSVMAlloc(ptr);
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user