From 45958c727d9cdc8a4ed7ed60770e115d8270bf00 Mon Sep 17 00:00:00 2001 From: Ramesh Errabolu Date: Thu, 5 Mar 2020 13:44:22 -0600 Subject: [PATCH] Extend ROCr to surface UUID of GPU devices that suppport Change-Id: I478db68d69a01578770403fa695f9e6391637573 --- .../core/runtime/amd_cpu_agent.cpp | 6 ++++++ .../core/runtime/amd_gpu_agent.cpp | 20 +++++++++++++++++++ .../hsa-runtime/core/runtime/amd_topology.cpp | 13 ++++++++---- runtime/hsa-runtime/core/util/flag.h | 3 +++ .../hsa-runtime/core/util/lnx/os_linux.cpp | 6 ++++++ runtime/hsa-runtime/core/util/os.h | 6 ++++++ runtime/hsa-runtime/inc/hsa_ext_amd.h | 12 ++++++++++- 7 files changed, 61 insertions(+), 5 deletions(-) diff --git a/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp index c5b33e4f20..b355ff01e7 100644 --- a/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp @@ -357,6 +357,12 @@ hsa_status_t CpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const { case HSA_AMD_AGENT_INFO_DOMAIN: *((uint32_t*)value) = static_cast(properties_.Domain); break; + case HSA_AMD_AGENT_INFO_UUID: { + // At this point CPU devices do not support UUID's. + char uuid_tmp[] = "CPU-XX"; + snprintf((char*)value, sizeof(uuid_tmp), "%s", uuid_tmp); + break; + } default: return HSA_STATUS_ERROR_INVALID_ARGUMENT; break; diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index 1dca41375b..b40049a394 100644 --- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include "core/inc/amd_aql_queue.h" #include "core/inc/amd_blit_kernel.h" @@ -900,6 +901,25 @@ hsa_status_t GpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const { case HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES: *((bool*)value) = properties_.NumGws != 0; break; + case HSA_AMD_AGENT_INFO_UUID: { + uint64_t uuid_value = static_cast(properties_.UniqueID); + + // Either device does not support UUID e.g. a Gfx8 device, + // or runtime is using an older thunk library that does not + // support UUID's + if (uuid_value == 0) { + char uuid_tmp[] = "GPU-XX"; + snprintf((char*)value, sizeof(uuid_tmp), "%s", uuid_tmp); + break; + } + + // Device supports UUID, build UUID string to return + std::stringstream ss; + ss << "GPU-" << std::setfill('0') << std::setw(sizeof(uint64_t) * 2) << std::hex + << uuid_value; + snprintf((char*)value, (ss.str().length() + 1), "%s", (char*)ss.str().c_str()); + break; + } default: return HSA_STATUS_ERROR_INVALID_ARGUMENT; break; diff --git a/runtime/hsa-runtime/core/runtime/amd_topology.cpp b/runtime/hsa-runtime/core/runtime/amd_topology.cpp index 1b1438fc18..3063d55fb2 100644 --- a/runtime/hsa-runtime/core/runtime/amd_topology.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_topology.cpp @@ -84,14 +84,19 @@ static bool PrintUsrGpuMap(std::map& gpu_usr_map) { * subset of Gpu's are desired to be surfaced. If defined the * set of Gpu's are captured into a map of Gpu index and * - * @return true if env is not blank, false otherwise. It is - * possible to have zero devices surfaced even when env is - * not blank. + * @return true if env is defined i.e. has some value including + * empty string, false otherwise. It is possible to have zero + * devices surfaced even when env is not blank. */ static bool MapUsrGpuList(int32_t numNodes, std::map& gpu_usr_map) { + bool filter = core::Runtime::runtime_singleton_->flag().filter_visible_gpus(); + if (filter == false) { + return false; + } + const std::string& env_value = core::Runtime::runtime_singleton_->flag().visible_gpus(); if (env_value.empty()) { - return false; + return true; } // Capture the env value string as a parsable stream diff --git a/runtime/hsa-runtime/core/util/flag.h b/runtime/hsa-runtime/core/util/flag.h index 272e5f1a4b..a5c0ad6031 100644 --- a/runtime/hsa-runtime/core/util/flag.h +++ b/runtime/hsa-runtime/core/util/flag.h @@ -72,6 +72,7 @@ class Flag { enable_sdma_ = os::GetEnvVar("HSA_ENABLE_SDMA"); visible_gpus_ = os::GetEnvVar("ROCR_VISIBLE_DEVICES"); + filter_visible_gpus_ = os::IsEnvVarSet("ROCR_VISIBLE_DEVICES"); var = os::GetEnvVar("HSA_RUNNING_UNDER_VALGRIND"); running_valgrind_ = (var == "1") ? true : false; @@ -143,6 +144,7 @@ class Flag { std::string enable_sdma() const { return enable_sdma_; } std::string visible_gpus() const { return visible_gpus_; } + bool filter_visible_gpus() const { return filter_visible_gpus_; } uint32_t max_queues() const { return max_queues_; } @@ -167,6 +169,7 @@ class Flag { std::string enable_sdma_; + bool filter_visible_gpus_; std::string visible_gpus_; uint32_t max_queues_; diff --git a/runtime/hsa-runtime/core/util/lnx/os_linux.cpp b/runtime/hsa-runtime/core/util/lnx/os_linux.cpp index 24974185ad..fdbe19a29f 100644 --- a/runtime/hsa-runtime/core/util/lnx/os_linux.cpp +++ b/runtime/hsa-runtime/core/util/lnx/os_linux.cpp @@ -237,6 +237,12 @@ bool WaitForAllThreads(Thread* threads, uint threadCount) { return true; } +bool IsEnvVarSet(std::string env_var_name) { + char* buff = NULL; + buff = getenv(env_var_name.c_str()); + return (buff != NULL); +} + void SetEnvVar(std::string env_var_name, std::string env_var_value) { setenv(env_var_name.c_str(), env_var_value.c_str(), 1); } diff --git a/runtime/hsa-runtime/core/util/os.h b/runtime/hsa-runtime/core/util/os.h index 5103178614..00210cc12c 100644 --- a/runtime/hsa-runtime/core/util/os.h +++ b/runtime/hsa-runtime/core/util/os.h @@ -152,6 +152,12 @@ bool WaitForThread(Thread thread); /// @return: bool. bool WaitForAllThreads(Thread* threads, uint thread_count); +/// @brief: Determines if environment key is set. +/// @param: env_var_name(Input), name of the environment value. +/// @return: bool, true for binding any value to environment key, +/// including an empty string. False otherwise +bool IsEnvVarSet(std::string env_var_name); + /// @brief: Sets the environment value. /// @param: env_var_name(Input), name of the environment value. /// @param: env_var_value(Input), value of the environment value.s diff --git a/runtime/hsa-runtime/inc/hsa_ext_amd.h b/runtime/hsa-runtime/inc/hsa_ext_amd.h index b281e46322..66c984df1d 100644 --- a/runtime/hsa-runtime/inc/hsa_ext_amd.h +++ b/runtime/hsa-runtime/inc/hsa_ext_amd.h @@ -163,7 +163,17 @@ typedef enum hsa_amd_agent_info_s { * Queries for support of cooperative queues. See ::HSA_QUEUE_TYPE_COOPERATIVE. * The type of this attribute is bool. */ - HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES = 0xA010 + HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES = 0xA010, + /** + * Queries UUID of an agent. The value is an Ascii string with a maximum + * of 21 chars including NUL. The string value consists of two parts: header + * and body. The header identifies device type (GPU, CPU, DSP) while body + * encodes UUID as a 16 digit hex string + * + * Agents that do not support UUID will return the string "GPU-XX" or + * "CPU-XX" or "DSP-XX" depending upon their device type ::hsa_device_type_t + */ + HSA_AMD_AGENT_INFO_UUID = 0xA011 } hsa_amd_agent_info_t; typedef struct hsa_amd_hdp_flush_s {