mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Fix calculations for offseted addresses
Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
798256ed61
commit
b32b5784c2
@@ -55,13 +55,13 @@ NEO::GraphicsAllocation *CommandList::getAllocationFromHostPtrMap(const void *bu
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *CommandList::getHostPtrAlloc(const void *buffer, uint64_t bufferSize, size_t *offset) {
|
||||
NEO::GraphicsAllocation *CommandList::getHostPtrAlloc(const void *buffer, uint64_t bufferSize) {
|
||||
NEO::GraphicsAllocation *alloc = getAllocationFromHostPtrMap(buffer, bufferSize);
|
||||
if (alloc) {
|
||||
*offset += ptrDiff(buffer, alloc->getUnderlyingBuffer());
|
||||
return alloc;
|
||||
}
|
||||
alloc = device->allocateMemoryFromHostPtr(buffer, bufferSize);
|
||||
UNRECOVERABLE_IF(alloc == nullptr);
|
||||
hostPtrMap.insert(std::make_pair(buffer, alloc));
|
||||
return alloc;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ struct CommandList : _ze_command_list_handle_t {
|
||||
bool indirectAllocationsAllowed = false;
|
||||
bool internalUsage = false;
|
||||
NEO::GraphicsAllocation *getAllocationFromHostPtrMap(const void *buffer, uint64_t bufferSize);
|
||||
NEO::GraphicsAllocation *getHostPtrAlloc(const void *buffer, uint64_t bufferSize, size_t *offset);
|
||||
NEO::GraphicsAllocation *getHostPtrAlloc(const void *buffer, uint64_t bufferSize);
|
||||
bool containsStatelessUncachedResource = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ struct CommandListCoreFamily : CommandListImp {
|
||||
void programThreadArbitrationPolicy(Device *device);
|
||||
|
||||
uint64_t getInputBufferSize(NEO::ImageType imageType, uint64_t bytesPerPixel, const ze_image_region_t *region);
|
||||
virtual AlignedAllocationData getAlignedAllocation(Device *device, const void *buffer, uint64_t bufferSize);
|
||||
MOCKABLE_VIRTUAL AlignedAllocationData getAlignedAllocation(Device *device, const void *buffer, uint64_t bufferSize);
|
||||
ze_result_t addEventsToCmdList(ze_event_handle_t hEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents);
|
||||
};
|
||||
|
||||
|
||||
@@ -1216,7 +1216,8 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendBlitFill(void *ptr,
|
||||
appendEventForProfiling(hEvent, true);
|
||||
NEO::GraphicsAllocation *gpuAllocation = device->getDriverHandle()->getDriverSystemMemoryAllocation(ptr,
|
||||
size,
|
||||
neoDevice->getRootDeviceIndex());
|
||||
neoDevice->getRootDeviceIndex(),
|
||||
nullptr);
|
||||
if (gpuAllocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -1301,17 +1302,15 @@ inline AlignedAllocationData CommandListCoreFamily<gfxCoreFamily>::getAlignedAll
|
||||
|
||||
if (srcAllocFound == false) {
|
||||
alloc = device->getDriverHandle()->findHostPointerAllocation(ptr, static_cast<size_t>(bufferSize), device->getRootDeviceIndex());
|
||||
if (alloc != nullptr) {
|
||||
offset += ptrDiff(buffer, alloc->getUnderlyingBuffer());
|
||||
} else {
|
||||
alloc = getHostPtrAlloc(buffer, bufferSize, &offset);
|
||||
if (alloc == nullptr) {
|
||||
alloc = getHostPtrAlloc(buffer, bufferSize);
|
||||
}
|
||||
alignedPtr = static_cast<uintptr_t>(alignDown(alloc->getGpuAddress(), NEO::EncodeSurfaceState<GfxFamily>::getSurfaceBaseAddressAlignment()));
|
||||
|
||||
hostPointerNeedsFlush = true;
|
||||
} else {
|
||||
alloc = allocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
|
||||
alignedPtr = reinterpret_cast<uintptr_t>(ptr) - offset;
|
||||
alignedPtr = sourcePtr;
|
||||
|
||||
if (allocData->memoryType == InternalMemoryType::HOST_UNIFIED_MEMORY ||
|
||||
allocData->memoryType == InternalMemoryType::SHARED_UNIFIED_MEMORY) {
|
||||
|
||||
@@ -88,7 +88,11 @@ ze_result_t ContextImp::freeMem(const void *ptr) {
|
||||
ze_result_t ContextImp::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());
|
||||
auto allocation = device->getDriverHandle()->getDriverSystemMemoryAllocation(
|
||||
ptr,
|
||||
size,
|
||||
neoDevice->getRootDeviceIndex(),
|
||||
nullptr);
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -112,7 +116,11 @@ ze_result_t ContextImp::makeMemoryResident(ze_device_handle_t hDevice, void *ptr
|
||||
ze_result_t ContextImp::evictMemory(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());
|
||||
auto allocation = device->getDriverHandle()->getDriverSystemMemoryAllocation(
|
||||
ptr,
|
||||
size,
|
||||
neoDevice->getRootDeviceIndex(),
|
||||
nullptr);
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,10 @@ struct DriverHandle : _ze_driver_handle_t {
|
||||
virtual ze_result_t getHostPointerBaseAddress(void *ptr, void **baseAddress) = 0;
|
||||
|
||||
virtual NEO::GraphicsAllocation *findHostPointerAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) = 0;
|
||||
virtual NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) = 0;
|
||||
virtual NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr,
|
||||
size_t size,
|
||||
uint32_t rootDeviceIndex,
|
||||
uintptr_t *gpuAddress) = 0;
|
||||
|
||||
static DriverHandle *fromHandle(ze_driver_handle_t handle) { return static_cast<DriverHandle *>(handle); }
|
||||
inline ze_driver_handle_t toHandle() { return this; }
|
||||
|
||||
@@ -453,13 +453,27 @@ NEO::GraphicsAllocation *DriverHandleImp::findHostPointerAllocation(void *ptr, s
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *DriverHandleImp::getDriverSystemMemoryAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) {
|
||||
NEO::GraphicsAllocation *DriverHandleImp::getDriverSystemMemoryAllocation(void *ptr,
|
||||
size_t size,
|
||||
uint32_t rootDeviceIndex,
|
||||
uintptr_t *gpuAddress) {
|
||||
NEO::SvmAllocationData *allocData = nullptr;
|
||||
bool allocFound = findAllocationDataForRange(ptr, size, &allocData);
|
||||
if (allocFound) {
|
||||
if (gpuAddress != nullptr) {
|
||||
*gpuAddress = reinterpret_cast<uintptr_t>(ptr);
|
||||
}
|
||||
return allocData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
|
||||
}
|
||||
return findHostPointerAllocation(ptr, size, rootDeviceIndex);
|
||||
auto allocation = findHostPointerAllocation(ptr, size, rootDeviceIndex);
|
||||
if (allocation != nullptr) {
|
||||
if (gpuAddress != nullptr) {
|
||||
uintptr_t offset = reinterpret_cast<uintptr_t>(ptr) -
|
||||
reinterpret_cast<uintptr_t>(allocation->getUnderlyingBuffer());
|
||||
*gpuAddress = static_cast<uintptr_t>(allocation->getGpuAddress()) + offset;
|
||||
}
|
||||
}
|
||||
return allocation;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -76,7 +76,10 @@ struct DriverHandleImp : public DriverHandle {
|
||||
ze_result_t getHostPointerBaseAddress(void *ptr, void **baseAddress) override;
|
||||
|
||||
virtual NEO::GraphicsAllocation *findHostPointerAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) override;
|
||||
virtual NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) override;
|
||||
virtual NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr,
|
||||
size_t size,
|
||||
uint32_t rootDeviceIndex,
|
||||
uintptr_t *gpuAddress) override;
|
||||
uint32_t parseAffinityMask(std::vector<std::unique_ptr<NEO::Device>> &neoDevices);
|
||||
void createHostPointerManager();
|
||||
|
||||
|
||||
@@ -524,11 +524,11 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi
|
||||
uintptr_t gpuAddress = 0u;
|
||||
NEO::GraphicsAllocation *alloc = module->getDevice()->getDriverHandle()->getDriverSystemMemoryAllocation(requestedAddress,
|
||||
1u,
|
||||
module->getDevice()->getRootDeviceIndex());
|
||||
module->getDevice()->getRootDeviceIndex(),
|
||||
&gpuAddress);
|
||||
if (nullptr == alloc) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
gpuAddress = static_cast<uintptr_t>(alloc->getGpuAddress());
|
||||
return setArgBufferWithAlloc(argIndex, gpuAddress, alloc);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user