From a511b7c4f7ffc014e7be1b63c490818364025afb Mon Sep 17 00:00:00 2001 From: Ben Goz Date: Mon, 19 Oct 2015 15:27:36 +0300 Subject: [PATCH] Adding support for new AQL Queue Memory allocation Change-Id: If84fc4b961627dbdd0b77b1c509a3c9a4c709b9f Signed-off-by: Ben Goz [ROCm/ROCR-Runtime commit: e61500c46eb3a1fe2054bb1a3a7fb1596ebf63c2] --- projects/rocr-runtime/include/hsakmttypes.h | 8 ++++++-- projects/rocr-runtime/include/linux/kfd_ioctl.h | 2 ++ projects/rocr-runtime/src/fmm.c | 14 +++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/projects/rocr-runtime/include/hsakmttypes.h b/projects/rocr-runtime/include/hsakmttypes.h index 0ffe7663e2..5b4eeba1e1 100644 --- a/projects/rocr-runtime/include/hsakmttypes.h +++ b/projects/rocr-runtime/include/hsakmttypes.h @@ -182,7 +182,8 @@ typedef union unsigned int DoorbellType : 2; // 0: This node has pre-1.0 doorbell characteristic // 1: This node has 1.0 doorbell characteristic // 2,3: reserved for future use - unsigned int Reserved : 18; + unsigned int AQLQueueDoubleMap : 1; // The unit needs a VA “double map” + unsigned int Reserved : 17; } ui32; } HSA_CAPABILITY; @@ -458,7 +459,10 @@ typedef struct _HsaMemFlags // 1: memory consistency needs to be enforced at // synchronization points at dispatch or other software // enforced synchronization boundaries. - unsigned int Reserved : 18; + unsigned int AQLQueueMemory: 1; // default = 0; If 1: The caller indicates that the memory will be used as AQL queue memory. + // The KFD will ensure that the memory returned is allocated in the optimal memory location + // and optimal alignment requirements + unsigned int Reserved : 17; } ui32; HSAuint32 Value; diff --git a/projects/rocr-runtime/include/linux/kfd_ioctl.h b/projects/rocr-runtime/include/linux/kfd_ioctl.h index 4ee1317c1d..c08cea8810 100644 --- a/projects/rocr-runtime/include/linux/kfd_ioctl.h +++ b/projects/rocr-runtime/include/linux/kfd_ioctl.h @@ -296,6 +296,8 @@ struct kfd_ioctl_set_process_dgpu_aperture_args { #define KFD_IOC_ALLOC_MEM_FLAGS_APU_DEVICE (1 << 3) #define KFD_IOC_ALLOC_MEM_FLAGS_APU_SCRATCH (1 << 4) +#define KFD_IOC_ALLOC_MEM_FLAGS_DGPU_AQL_QUEUE_MEM (1 << 5) + struct kfd_ioctl_alloc_memory_of_gpu_new_args { uint64_t va_addr; /* to KFD */ uint64_t size; /* to KFD */ diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index fb5940259e..ce765d0abd 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -30,6 +30,7 @@ #include #include #include +#include #define NON_VALID_GPU_ID 0 #define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0])) @@ -657,23 +658,30 @@ static void* fmm_allocate_host_gpu(uint32_t gpu_id, manageble_aperture_t *aperture; int32_t gpu_mem_id; uint64_t mmap_offset; + uint32_t ioc_flags; + uint32_t size; /* Retrieve gpu_mem id according to gpu_id */ gpu_mem_id = gpu_mem_find_by_gpu_id(gpu_id); if (gpu_mem_id < 0) return NULL; + size = MemorySizeInBytes; + ioc_flags = KFD_IOC_ALLOC_MEM_FLAGS_DGPU_HOST; if (flags.ui32.CoarseGrain) aperture = &gpu_mem[gpu_mem_id].dgpu_aperture; else aperture = &gpu_mem[gpu_mem_id].dgpu_alt_aperture; /* coherent */ + if (flags.ui32.AQLQueueMemory) { + size = MemorySizeInBytes * 2; + ioc_flags = KFD_IOC_ALLOC_MEM_FLAGS_DGPU_AQL_QUEUE_MEM; + } - mem = __fmm_allocate_device(gpu_id, MemorySizeInBytes, + mem = __fmm_allocate_device(gpu_id, size, aperture, 0, &mmap_offset, - KFD_IOC_ALLOC_MEM_FLAGS_DGPU_HOST); + ioc_flags); /* FIXME: host memory allocated in this way should be mapped on all GPUs */ - void *ret = mmap(mem, MemorySizeInBytes, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_SHARED | MAP_FIXED, kfd_fd , mmap_offset);