From a580869abd0d763054cebe89e16de6ef3f3edda5 Mon Sep 17 00:00:00 2001 From: Philip Yang Date: Mon, 5 Feb 2024 19:34:14 -0500 Subject: [PATCH] libhsakmt: Support contiguous VRAM allocation flag Add HsaMemFlags Contiguous bit for hsaKmtAllocMemory to allocate contiguous VRAM, to support RDMA device with limited scatter-gather ability. Check KFD ioctl minor version >= 17. Change-Id: I0db00dad125b2b7be523f343082641f59b850423 Signed-off-by: Philip Yang [ROCm/ROCR-Runtime commit: 97497c7efcc8be1c84eec50b6edf295f50805735] --- projects/rocr-runtime/include/hsakmt/hsakmttypes.h | 3 ++- projects/rocr-runtime/include/hsakmt/linux/kfd_ioctl.h | 1 + projects/rocr-runtime/src/fmm.c | 3 +++ projects/rocr-runtime/src/memory.c | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/projects/rocr-runtime/include/hsakmt/hsakmttypes.h b/projects/rocr-runtime/include/hsakmt/hsakmttypes.h index f94efa11c3..eebc14bf3d 100644 --- a/projects/rocr-runtime/include/hsakmt/hsakmttypes.h +++ b/projects/rocr-runtime/include/hsakmt/hsakmttypes.h @@ -569,7 +569,8 @@ typedef struct _HsaMemFlags unsigned int ExtendedCoherent: 1; // system-scope coherence on atomic instructions unsigned int GTTAccess: 1; // default = 0; If 1: The caller indicates this memory will be mapped to GART for MES // KFD will allocate GTT memory with the Preferred_node set as gpu_id for GART mapping - unsigned int Reserved: 10; + unsigned int Contiguous: 1; // Allocate contiguous VRAM + unsigned int Reserved: 9; } ui32; HSAuint32 Value; diff --git a/projects/rocr-runtime/include/hsakmt/linux/kfd_ioctl.h b/projects/rocr-runtime/include/hsakmt/linux/kfd_ioctl.h index f1fd54bfa4..fe0a09a34f 100644 --- a/projects/rocr-runtime/include/hsakmt/linux/kfd_ioctl.h +++ b/projects/rocr-runtime/include/hsakmt/linux/kfd_ioctl.h @@ -1029,6 +1029,7 @@ struct kfd_ioctl_acquire_vm_args { #define KFD_IOC_ALLOC_MEM_FLAGS_COHERENT (1 << 26) #define KFD_IOC_ALLOC_MEM_FLAGS_UNCACHED (1 << 25) #define KFD_IOC_ALLOC_MEM_FLAGS_EXT_COHERENT (1 << 24) +#define KFD_IOC_ALLOC_MEM_FLAGS_CONTIGUOUS_BEST_EFFORT (1 << 23) /* Allocate memory for later SVM (shared virtual memory) mapping. * diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index bad29e9ea6..ef9e3f628c 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -1579,6 +1579,9 @@ void *fmm_allocate_device(uint32_t gpu_id, uint32_t node_id, void *address, if (mflags.ui32.ExtendedCoherent) ioc_flags |= KFD_IOC_ALLOC_MEM_FLAGS_EXT_COHERENT; + if (mflags.ui32.Contiguous) + ioc_flags |= KFD_IOC_ALLOC_MEM_FLAGS_CONTIGUOUS_BEST_EFFORT; + mem = __fmm_allocate_device(gpu_id, address, size, aperture, &mmap_offset, ioc_flags, &vm_obj); diff --git a/projects/rocr-runtime/src/memory.c b/projects/rocr-runtime/src/memory.c index 8e2b49b1d4..b239b1a076 100644 --- a/projects/rocr-runtime/src/memory.c +++ b/projects/rocr-runtime/src/memory.c @@ -115,6 +115,9 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemory(HSAuint32 PreferredNode, CHECK_KFD_OPEN(); + if (MemFlags.ui32.Contiguous) + CHECK_KFD_MINOR_VERSION(17); + pr_debug("[%s] node %d\n", __func__, PreferredNode); result = validate_nodeid(PreferredNode, &gpu_id);