diff --git a/runtime/hsa-runtime/CMakeLists.txt b/runtime/hsa-runtime/CMakeLists.txt index 93796b3f7d..321d6e98a4 100644 --- a/runtime/hsa-runtime/CMakeLists.txt +++ b/runtime/hsa-runtime/CMakeLists.txt @@ -289,6 +289,9 @@ if(rocprofiler-register_FOUND) HSA_VERSION_MINOR=${VERSION_MINOR} HSA_VERSION_PATCH=${VERSION_PATCH}) target_link_libraries(${CORE_RUNTIME_TARGET} PRIVATE rocprofiler-register::rocprofiler-register) + set(HSA_DEP_ROCPROFILER_REGISTER ON) +else() + set(HSA_DEP_ROCPROFILER_REGISTER OFF) endif() ## Set the VERSION and SOVERSION values @@ -463,6 +466,9 @@ if ( ROCM_DEP_ROCMCORE ) string ( APPEND CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS ", rocm-core" ) string ( APPEND CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ", rocm-core-asan" ) endif() +if ( HSA_DEP_ROCPROFILER_REGISTER ) + string ( APPEND CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS ", rocprofiler-register" ) +endif() # Declare package relationships (hsa-ext-rocr-dev is a legacy package that we subsume) set ( CPACK_DEBIAN_PACKAGE_BREAKS "hsa-ext-rocr-dev" ) set ( CPACK_DEBIAN_PACKAGE_REPLACES "hsa-ext-rocr-dev" ) @@ -505,6 +511,9 @@ if ( ROCM_DEP_ROCMCORE ) string ( APPEND CPACK_RPM_BINARY_PACKAGE_REQUIRES " rocm-core" ) string ( APPEND CPACK_RPM_ASAN_PACKAGE_REQUIRES " rocm-core-asan" ) endif() +if ( HSA_DEP_ROCPROFILER_REGISTER ) + string ( APPEND CPACK_RPM_BINARY_PACKAGE_REQUIRES " rocprofiler-register" ) +endif() # Declare package relationships (hsa-ext-rocr-dev is a legacy package that we subsume) set ( CPACK_RPM_PACKAGE_PROVIDES "hsa-ext-rocr-dev hsa-rocr-dev" ) set ( CPACK_RPM_PACKAGE_OBSOLETES "hsa-ext-rocr-dev" ) diff --git a/runtime/hsa-runtime/core/runtime/runtime.cpp b/runtime/hsa-runtime/core/runtime/runtime.cpp index d1910f6e57..148c5e371b 100644 --- a/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -2102,48 +2102,39 @@ void Runtime::LoadTools() { typedef void (*tool_add_t)(Runtime*); #if defined(HSA_ROCPROFILER_REGISTER) && HSA_ROCPROFILER_REGISTER > 0 - auto* profiler_api_table_ = static_cast(&hsa_api_table_); - auto lib_id = rocprofiler_register_library_indentifier_t{}; - auto rocp_reg_status = - rocprofiler_register_library_api_table("hsa", &ROCPROFILER_REGISTER_IMPORT_FUNC(hsa), - ROCP_REG_VERSION, &profiler_api_table_, 1, &lib_id); + if (!flag().disable_tool_register()) { + auto* profiler_api_table_ = static_cast(&hsa_api_table_); + auto lib_id = rocprofiler_register_library_indentifier_t{}; + auto rocp_reg_status = + rocprofiler_register_library_api_table("hsa", &ROCPROFILER_REGISTER_IMPORT_FUNC(hsa), + ROCP_REG_VERSION, &profiler_api_table_, 1, &lib_id); - if (rocp_reg_status != ROCP_REG_SUCCESS && flag().report_tool_load_failures()) { - // hsa-runtime, in non-debug mode, enables reporting tool load failures by default, - // which is good scheme for when tools were only loaded via the HSA_TOOLS_LIB env variable - // but, with automatic detection, this will result in reporting that no tools were available. - // So if no tools were available and flag().report_tool_load_failures() is true, we make - // sure that HSA_TOOLS_REPORT_LOAD_FAILURE was explicitly set and, if not, we suppress - // reporting that no tools were found - if (rocp_reg_status != ROCP_REG_NO_TOOLS || - (rocp_reg_status == ROCP_REG_NO_TOOLS && - flag().report_tool_load_failures_explicitly_set())) { - fprintf(stderr, "[hsa-runtime][%i] rocprofiler-register failed with error code %i: %s\n", + if (rocp_reg_status != ROCP_REG_SUCCESS && flag().report_tool_register_failures()) { + fprintf(stderr, "[hsa-runtime][%i] rocprofiler-register returned status code %i: %s\n", getpid(), rocp_reg_status, rocprofiler_register_error_string(rocp_reg_status)); } - } - bool allow_v1_registration = false; - if(os::IsEnvVarSet("HSA_TOOLS_ROCPROFILER_V1_TOOLS")) - { - // assume true if env variable is set - allow_v1_registration = true; - auto allow_v1_value = os::GetEnvVar("HSA_TOOLS_ROCPROFILER_V1_TOOLS"); - // support using numbers, off, false, no, n, or f - if (!allow_v1_value.empty()) { - if (allow_v1_value.find_first_not_of("0123456789") == std::string::npos) { - allow_v1_registration = (std::stoi(allow_v1_value) != 0); - } else if (std::regex_match( - allow_v1_value, - std::regex{"^(off|false|no|n|f)$", std::regex_constants::icase})) { - allow_v1_registration = false; + bool allow_v1_registration = false; + if (os::IsEnvVarSet("HSA_TOOLS_ROCPROFILER_V1_TOOLS")) { + // assume true if env variable is set + allow_v1_registration = true; + auto allow_v1_value = os::GetEnvVar("HSA_TOOLS_ROCPROFILER_V1_TOOLS"); + // support using numbers, off, false, no, n, or f + if (!allow_v1_value.empty()) { + if (allow_v1_value.find_first_not_of("0123456789") == std::string::npos) { + allow_v1_registration = (std::stoi(allow_v1_value) != 0); + } else if (std::regex_match( + allow_v1_value, + std::regex{"^(off|false|no|n|f)$", std::regex_constants::icase})) { + allow_v1_registration = false; + } } } - } - // if rocprofiler library supports registration and v1 support not explicitly requested, - // do not use old method - if (rocp_reg_status == ROCP_REG_SUCCESS && !allow_v1_registration) return; + // if rocprofiler library supports registration and v1 support not explicitly requested, + // do not use old method + if (rocp_reg_status == ROCP_REG_SUCCESS && !allow_v1_registration) return; + } #endif std::vector failed; diff --git a/runtime/hsa-runtime/core/util/flag.h b/runtime/hsa-runtime/core/util/flag.h index 170fd54eee..ff09283994 100644 --- a/runtime/hsa-runtime/core/util/flag.h +++ b/runtime/hsa-runtime/core/util/flag.h @@ -151,13 +151,18 @@ class Flag { var = os::GetEnvVar("HSA_TOOLS_REPORT_LOAD_FAILURE"); - report_tool_load_failures_explicit_ = (var.empty()) ? false : true; ifdebug { report_tool_load_failures_ = (var == "1") ? true : false; } else { report_tool_load_failures_ = (var == "0") ? false : true; } + var = os::GetEnvVar("HSA_TOOLS_DISABLE_REGISTER"); + disable_tool_register_ = (var == "1") ? true : false; + + var = os::GetEnvVar("HSA_TOOLS_REPORT_REGISTER_FAILURE"); + report_tool_register_failures_ = (var == "1") ? true : false; + var = os::GetEnvVar("HSA_DISABLE_FRAGMENT_ALLOCATOR"); disable_fragment_alloc_ = (var == "1") ? true : false; @@ -250,9 +255,9 @@ class Flag { bool report_tool_load_failures() const { return report_tool_load_failures_; } - bool report_tool_load_failures_explicitly_set() const { - return report_tool_load_failures_explicit_; - } + bool report_tool_register_failures() const { return report_tool_register_failures_; } + + bool disable_tool_register() const { return disable_tool_register_; } bool disable_fragment_alloc() const { return disable_fragment_alloc_; } @@ -340,7 +345,8 @@ class Flag { bool sdma_wait_idle_; bool enable_queue_fault_message_; bool report_tool_load_failures_; - bool report_tool_load_failures_explicit_; + bool report_tool_register_failures_ = false; + bool disable_tool_register_ = false; bool disable_fragment_alloc_; bool rev_copy_dir_; bool fine_grain_pcie_;