From dd76f98009eee63b54cbcdb73abdb3396bea5e5b Mon Sep 17 00:00:00 2001 From: Saleel Kudchadker Date: Tue, 9 Nov 2021 02:54:48 -0800 Subject: [PATCH] SWDEV-299893 - Set preferred node affinity Set affinity to the node nearest to default GPU at init. Afterthat set it to NUMA node thats nearest to whatever GPU is set with hipSetDevice Change-Id: I85749258ea7c25385096ffe4089a70c948f332c7 Change-Id: I99a92c922655e22955bee512073b6ac8e6ced3a2 [ROCm/clr commit: 0d5bc833c36da1fc5de7213e0b36381332b54054] --- projects/clr/hipamd/src/hip_context.cpp | 2 ++ projects/clr/hipamd/src/hip_internal.hpp | 26 ++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/projects/clr/hipamd/src/hip_context.cpp b/projects/clr/hipamd/src/hip_context.cpp index caf6b195c2..f01b41575f 100644 --- a/projects/clr/hipamd/src/hip_context.cpp +++ b/projects/clr/hipamd/src/hip_context.cpp @@ -84,6 +84,8 @@ Device* getCurrentDevice() { void setCurrentDevice(unsigned int index) { assert(indexdevices()[0]->getPreferredNumaNode(); + amd::Os::setPreferredNumaNode(preferredNumaNode); } amd::HostQueue* getQueue(hipStream_t stream) { diff --git a/projects/clr/hipamd/src/hip_internal.hpp b/projects/clr/hipamd/src/hip_internal.hpp index b82dc37260..e8819a7f7d 100644 --- a/projects/clr/hipamd/src/hip_internal.hpp +++ b/projects/clr/hipamd/src/hip_internal.hpp @@ -73,17 +73,19 @@ typedef struct ihipIpcEventHandle_st { #endif #define HIP_INIT() \ - std::call_once(hip::g_ihipInitialized, hip::init); \ - if (hip::g_device == nullptr && g_devices.size() > 0) { \ - hip::g_device = g_devices[0]; \ + std::call_once(hip::g_ihipInitialized, hip::init); \ + if (hip::g_device == nullptr && g_devices.size() > 0) { \ + hip::g_device = g_devices[0]; \ + amd::Os::setPreferredNumaNode(g_devices[0]->devices()[0]->getPreferredNumaNode()); \ } -#define HIP_API_PRINT(...) \ - uint64_t startTimeUs=0 ; HIPPrintDuration(amd::LOG_INFO, amd::LOG_API, &startTimeUs, "%s%s ( %s )%s", KGRN, \ +#define HIP_API_PRINT(...) \ + uint64_t startTimeUs=0 ; HIPPrintDuration(amd::LOG_INFO, amd::LOG_API, \ + &startTimeUs, "%s%s ( %s )%s", KGRN, \ __func__, ToString( __VA_ARGS__ ).c_str(),KNRM); -#define HIP_ERROR_PRINT(err, ...) \ - ClPrint(amd::LOG_INFO, amd::LOG_API, "%s: Returned %s : %s", \ +#define HIP_ERROR_PRINT(err, ...) \ + ClPrint(amd::LOG_INFO, amd::LOG_API, "%s: Returned %s : %s", \ __func__, hipGetErrorName(err), ToString( __VA_ARGS__ ).c_str()); // This macro should be called at the beginning of every HIP API. @@ -96,10 +98,12 @@ typedef struct ihipIpcEventHandle_st { HIP_INIT() \ HIP_CB_SPAWNER_OBJECT(cid); -#define HIP_RETURN_DURATION(ret, ...) \ - hip::g_lastError = ret; \ - HIPPrintDuration(amd::LOG_INFO, amd::LOG_API, &startTimeUs, "%s: Returned %s : %s", \ - __func__, hipGetErrorName(hip::g_lastError), ToString( __VA_ARGS__ ).c_str()); \ +#define HIP_RETURN_DURATION(ret, ...) \ + hip::g_lastError = ret; \ + HIPPrintDuration(amd::LOG_INFO, amd::LOG_API, &startTimeUs, \ + "%s: Returned %s : %s", \ + __func__, hipGetErrorName(hip::g_lastError), \ + ToString( __VA_ARGS__ ).c_str()); \ return hip::g_lastError; #define HIP_RETURN(ret, ...) \