rocr/driver: add scratch memory allocation into driver interface

Add AllocateScratchMemory interface to Driver base class and implement it
in both KFD and XDNA drivers. This change encapsulates the low-level
scratch memory allocation details within driver implementations, making
the code more maintainable and the interface cleaner.

The main changes include:
- Add AllocateScratchMemory virtual method to Driver interface
- Implement the interface in KfdDriver with existing allocation logic
- Add stub implementation in XdnaDriver
- Update GpuAgent to use the new interface instead of direct KMT calls

Signed-off-by: Honglei Huang <Honglei1.Huang@amd.com>


[ROCm/ROCR-Runtime commit: da8dd9e1e3]
Cette révision appartient à :
Honglei Huang
2025-07-15 10:47:50 +08:00
révisé par Huang, Honglei1
Parent a0ef6f6473
révision 1ad79f04d0
6 fichiers modifiés avec 31 ajouts et 9 suppressions
+15
Voir le fichier
@@ -574,6 +574,21 @@ hsa_status_t KfdDriver::SetTrapHandler(uint32_t node_id, const void* base, uint6
return HSA_STATUS_SUCCESS;
}
hsa_status_t KfdDriver::AllocateScratchMemory(uint32_t node_id, uint64_t size, void** mem) const {
assert(mem);
assert(size > 0);
HsaMemFlags flags = {};
flags.ui32.Scratch = 1;
flags.ui32.HostAccess = 1;
void* ptr = AllocateKfdMemory(flags, node_id, size);
if (ptr == nullptr) return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
*mem = ptr;
return HSA_STATUS_SUCCESS;
}
hsa_status_t KfdDriver::GetDeviceHandle(uint32_t node_id, void** device_handle) const {
assert(device_handle);
@@ -877,6 +877,10 @@ hsa_status_t XdnaDriver::SetTrapHandler(uint32_t node_id, const void* base, uint
return HSA_STATUS_ERROR;
}
hsa_status_t XdnaDriver::AllocateScratchMemory(uint32_t node_id, uint64_t size, void** mem) const {
return HSA_STATUS_ERROR;
}
hsa_status_t XdnaDriver::GetDeviceHandle(uint32_t node_id, void** device_handle) const {
return HSA_STATUS_ERROR;
}