From: Honglei Huang <[email protected]>

Introduce new ioctl AMDKFD_IOC_ALLOC_MEMORY_OF_GPU_BATCH to support
allocating multiple non-contiguous CPU virtual address ranges that
map to a single contiguous GPU virtual address.

This allows userspace to efficiently manage scattered memory buffers
by presenting them as a unified GPU address space, useful for
applications dealing with fragmented host memory.

Signed-off-by: Honglei Huang <[email protected]>
---
 include/uapi/linux/kfd_ioctl.h | 37 +++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index 84aa24c02..c364aa971 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -442,6 +442,38 @@ struct kfd_ioctl_alloc_memory_of_gpu_args {
        __u32 flags;
 };
 
+/* Userptr range for batch allocation
+ *
+ * @start: start address of user virtual memory range
+ * @size:  size of this user virtual memory range in bytes
+ */
+struct kfd_ioctl_userptr_range {
+       __u64 start;            /* to KFD */
+       __u64 size;             /* to KFD */
+};
+
+/* Allocate memory for batch of non-contiguous userptr ranges
+ * that map to a contiguous GPU virtual address
+ *
+ * @va_addr:     contiguous GPU virtual address where all ranges will be mapped
+ * @total_size:  total size in bytes (sum of all range sizes)
+ * @handle:      buffer handle returned to user mode
+ * @ranges_ptr:  pointer to array of kfd_ioctl_userptr_range structures
+ * @num_ranges:  number of ranges in the array
+ * @gpu_id:      device identifier
+ * @flags:       memory type and attributes (must include 
KFD_IOC_ALLOC_MEM_FLAGS_USERPTR)
+ */
+struct kfd_ioctl_alloc_memory_of_gpu_batch_args {
+       __u64 va_addr;          /* to KFD */
+       __u64 total_size;       /* to KFD */
+       __u64 handle;           /* from KFD */
+       __u64 ranges_ptr;       /* to KFD */
+       __u32 num_ranges;       /* to KFD */
+       __u32 gpu_id;           /* to KFD */
+       __u32 flags;            /* to KFD */
+       __u32 pad;
+};
+
 /* Free memory allocated with kfd_ioctl_alloc_memory_of_gpu
  *
  * @handle: memory handle returned by alloc
@@ -1675,7 +1707,10 @@ struct kfd_ioctl_dbg_trap_args {
 #define AMDKFD_IOC_CREATE_PROCESS              \
                AMDKFD_IO(0x27)
 
+#define AMDKFD_IOC_ALLOC_MEMORY_OF_GPU_BATCH   \
+               AMDKFD_IOWR(0x28, struct 
kfd_ioctl_alloc_memory_of_gpu_batch_args)
+
 #define AMDKFD_COMMAND_START           0x01
-#define AMDKFD_COMMAND_END             0x28
+#define AMDKFD_COMMAND_END             0x29
 
 #endif
-- 
2.34.1

Reply via email to