Add hsa_amd_vmem_address_reserve_align API

New API to support alignment parameter when reserving virtual addresses.
If the alignment is 0, then the default size is used. Otherwise the
alignment needs to be a power of 2 and greater than or equal to page
size.

Existing hsa_amd_vmem_address_reserve marked for future deprecation.

Change-Id: I17cee75420183dea5842fc1ecc2514cdcd760bac
Signed-off-by: Chris Freehill <cfreehil@amd.com>
This commit is contained in:
David Yat Sin
2024-05-13 14:50:38 +00:00
committed by Chris Freehill
parent 81825df44d
commit 08c44fbda6
10 changed files with 65 additions and 8 deletions
+8 -3
View File
@@ -2962,18 +2962,23 @@ hsa_status_t Runtime::DmaBufClose(int dmabuf) {
}
hsa_status_t Runtime::VMemoryAddressReserve(void** va, size_t size, uint64_t address,
uint64_t flags) {
uint64_t alignment, uint64_t flags) {
void* addr = (void*)address;
HsaMemFlags memFlags = {};
if (!alignment)
alignment = sysconf(_SC_PAGE_SIZE);
ScopedAcquire<KernelSharedMutex> lock(&memory_lock_);
memFlags.ui32.OnlyAddress = 1;
memFlags.ui32.FixedAddress = 1;
/* Try to reserving the VA requested by user */
if (hsaKmtAllocMemory(0, size, memFlags, &addr) != HSAKMT_STATUS_SUCCESS) {
if (hsaKmtAllocMemoryAlign(0, size, alignment, memFlags, &addr) != HSAKMT_STATUS_SUCCESS) {
memFlags.ui32.FixedAddress = 0;
/* Could not reserved VA requested, allocate alternate VA */
if (hsaKmtAllocMemory(0, size, memFlags, &addr) != HSAKMT_STATUS_SUCCESS)
if (hsaKmtAllocMemoryAlign(0, size, alignment, memFlags, &addr) != HSAKMT_STATUS_SUCCESS)
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
}