diff --git a/projects/rdc/include/rdc/rdc.h b/projects/rdc/include/rdc/rdc.h index 26beae9411..f9cde1b788 100644 --- a/projects/rdc/include/rdc/rdc.h +++ b/projects/rdc/include/rdc/rdc.h @@ -79,6 +79,7 @@ typedef enum { //!< but none was found RDC_ST_PERM_ERROR, //!< Insufficient permission to complete //!< operation + RDC_ST_DISABLED_MODULE, //!< Attempted loading disabled module RDC_ST_UNKNOWN_ERROR = 0xFFFFFFFF //!< Unknown error } rdc_status_t; diff --git a/projects/rdc/rdc_libs/rdc/src/RdcRocpLib.cc b/projects/rdc/rdc_libs/rdc/src/RdcRocpLib.cc index de91e5e25f..dc43323408 100644 --- a/projects/rdc/rdc_libs/rdc/src/RdcRocpLib.cc +++ b/projects/rdc/rdc_libs/rdc/src/RdcRocpLib.cc @@ -62,8 +62,13 @@ RdcRocpLib::RdcRocpLib() status = rdc_module_init_(0); if (status != RDC_ST_OK) { - RDC_LOG(RDC_ERROR, "Fail to init librdc_rocp.so:" << rdc_status_string(status) - << ". ROCP related function will not work."); + if (status == RDC_ST_DISABLED_MODULE) { + RDC_LOG(RDC_INFO, "Module: librdc_rocp.so is intentionally disabled!"); + } else { + RDC_LOG(RDC_ERROR, + "Fail to init librdc_rocp.so:" << rdc_status_string(status) + << ". ROCP related function will not work."); + } return; } diff --git a/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/RdcTelemetryLib.cc b/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/RdcTelemetryLib.cc index 41a6a50da0..919468bf2e 100644 --- a/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/RdcTelemetryLib.cc +++ b/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/RdcTelemetryLib.cc @@ -38,7 +38,32 @@ THE SOFTWARE. std::unique_ptr rocp_p; +bool is_rocp_disabled() { + const char* value = std::getenv("RDC_DISABLE_ROCP"); + if (value == nullptr) return false; + + std::string value_str = value; + std::transform(value_str.begin(), value_str.end(), value_str.begin(), + [](unsigned char c) { return std::tolower(c); }); + + const std::vector positive_list = {"yes", "true", "1", "on", "y", "t"}; + + return std::any_of(positive_list.begin(), positive_list.end(), + [&value_str](const char* val) { return value_str == val; }); +} + rdc_status_t rdc_module_init(uint64_t flags) { + if (is_rocp_disabled()) { + // rocprofiler does NOT work in gtest. + // GTest starts up multiple instances of the progam under test, + // however HSA does not allow for multiple instances. Since hsa_init() is called at the very + // top of RdcRocpBase constructor - easiest to disable it alltogether when RDC_DISABLE_ROCP is + // set. + // + // We cannot rely on GTEST_DECLARE_bool_ variable because RDC is compiled + // before the tests are. Utilize an env var instead. + return RDC_ST_DISABLED_MODULE; + } rocp_p = std::unique_ptr(new amd::rdc::RdcRocpBase); return RDC_ST_OK; } diff --git a/projects/rdc/tests/rdc_tests/main.cc b/projects/rdc/tests/rdc_tests/main.cc index 82984e7f17..c45b248b0e 100644 --- a/projects/rdc/tests/rdc_tests/main.cc +++ b/projects/rdc/tests/rdc_tests/main.cc @@ -23,6 +23,7 @@ THE SOFTWARE. #include #include +#include #include #include #include @@ -190,6 +191,9 @@ static int startRDCD(std::string* rdcd_path, char* envp[]) { } int main(int argc, char** argv, char* envp[]) { ::testing::InitGoogleTest(&argc, argv); + // disable ROCProfiler because its RDC plugin implementation does not work + // with GTest + setenv("RDC_DISABLE_ROCP", "yes", 0); RDCTstGlobals settings; int ret;