From 7c05c5240ff085ae8b7d48df5ab0c577651dd07f Mon Sep 17 00:00:00 2001 From: Harish Kasiviswanathan Date: Wed, 30 Dec 2020 18:47:48 -0500 Subject: [PATCH] libhsakmt: A+A: Mark buffers accessed by CP as UC This change is for the A+A bring-up branch as it needs to made more generic to handle all ASICs. For A+A all the system buffers are mapped as NC (non coherent) unless explicitly marked as UC (uncached). The coherency is then expected to be handled by shader by explicitly using acquire/release instructions. However, CP doesn't have same feature. The buffers used by CP thus have to UC. For now queue buffer and Signal handler memory is marked as UC. This change shouldn't affect other ASICs since Uncached flag is not used in those. However, this change still need to be made more generic. Signed-off-by: Harish Kasiviswanathan Change-Id: I56c37a809913f7f08c94d01b0572d0f4864939aa --- src/events.c | 2 +- src/libhsakmt.h | 2 +- src/queues.c | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/events.c b/src/events.c index 23fb710523..d4c751c0cc 100644 --- a/src/events.c +++ b/src/events.c @@ -76,7 +76,7 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtCreateEvent(HsaEventDescriptor *EventDesc, if (is_dgpu && !events_page) { events_page = allocate_exec_aligned_memory_gpu( - KFD_SIGNAL_EVENT_LIMIT * 8, PAGE_SIZE, 0, true, false); + KFD_SIGNAL_EVENT_LIMIT * 8, PAGE_SIZE, 0, true, false, true); if (!events_page) { pthread_mutex_unlock(&hsakmt_mutex); return HSAKMT_STATUS_ERROR; diff --git a/src/libhsakmt.h b/src/libhsakmt.h index 86ec0cb9c0..dee5929614 100644 --- a/src/libhsakmt.h +++ b/src/libhsakmt.h @@ -169,7 +169,7 @@ HSAuint32 PageSizeFromFlags(unsigned int pageSizeFlags); void* allocate_exec_aligned_memory_gpu(uint32_t size, uint32_t align, uint32_t NodeId, bool NonPaged, - bool DeviceLocal); + bool DeviceLocal, bool Uncached); void free_exec_aligned_memory_gpu(void *addr, uint32_t size, uint32_t align); HSAKMT_STATUS init_process_doorbells(unsigned int NumNodes); void destroy_process_doorbells(void); diff --git a/src/queues.c b/src/queues.c index 8d3bd02a4e..b8572b6458 100644 --- a/src/queues.c +++ b/src/queues.c @@ -455,7 +455,8 @@ static bool update_ctx_save_restore_size(uint32_t nodeid, struct queue *q) void *allocate_exec_aligned_memory_gpu(uint32_t size, uint32_t align, uint32_t NodeId, bool nonPaged, - bool DeviceLocal) + bool DeviceLocal, + bool Uncached) { void *mem; HSAuint64 gpu_va; @@ -469,6 +470,7 @@ void *allocate_exec_aligned_memory_gpu(uint32_t size, uint32_t align, flags.ui32.NonPaged = nonPaged; flags.ui32.PageSize = HSA_PAGE_SIZE_4KB; flags.ui32.CoarseGrain = DeviceLocal; + flags.ui32.Uncached = Uncached; /* Get the closest cpu_id to GPU NodeId for system memory allocation * nonPaged=1 system memory allocation uses GTT path @@ -518,11 +520,13 @@ void free_exec_aligned_memory_gpu(void *addr, uint32_t size, uint32_t align) static void *allocate_exec_aligned_memory(uint32_t size, bool use_ats, uint32_t NodeId, - bool DeviceLocal) + bool DeviceLocal, + bool Uncached) { if (!use_ats) return allocate_exec_aligned_memory_gpu(size, PAGE_SIZE, NodeId, - DeviceLocal, DeviceLocal); + DeviceLocal, DeviceLocal, + Uncached); return allocate_exec_aligned_memory_cpu(size); } @@ -564,7 +568,7 @@ static int handle_concrete_asic(struct queue *q, q->eop_buffer = allocate_exec_aligned_memory(q->dev_info->eop_buffer_size, q->use_ats, - NodeId, true); + NodeId, true, /* Unused for VRAM */false); if (!q->eop_buffer) return HSAKMT_STATUS_NO_MEMORY; @@ -582,7 +586,7 @@ static int handle_concrete_asic(struct queue *q, q->ctx_save_restore = allocate_exec_aligned_memory(q->ctx_save_restore_size, q->use_ats, - NodeId, false); + NodeId, false, false); if (!q->ctx_save_restore) return HSAKMT_STATUS_NO_MEMORY; @@ -639,7 +643,7 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtCreateQueue(HSAuint32 NodeId, struct queue *q = allocate_exec_aligned_memory(sizeof(*q), use_ats, - NodeId, false); + NodeId, false, true); if (!q) return HSAKMT_STATUS_NO_MEMORY;