Skip to content

Commit

Permalink
libhsakmt: Support contiguous VRAM allocation flag
Browse files Browse the repository at this point in the history
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 <Philip.Yang@amd.com>
  • Loading branch information
PhilipYangA committed Apr 23, 2024
1 parent 2e5ef66 commit f7b4a26
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/hsakmt/hsakmttypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/hsakmt/linux/kfd_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions src/fmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f7b4a26

Please sign in to comment.