diff --git a/CMakeLists.txt b/CMakeLists.txt index 12c5d3f8e1..00dcb726fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,6 +354,7 @@ if(MIOPEN_USE_MLIR) endif() endif() +set(MIOPEN_PACKAGE_REQS "hip-rocclr") # Online assembler find_program(MIOPEN_AMDGCN_ASSEMBLER @@ -374,6 +375,7 @@ message(STATUS "AMDGCN assembler: ${MIOPEN_AMDGCN_ASSEMBLER}") if(MIOPEN_USE_COMGR) find_package(amd_comgr REQUIRED CONFIG) message(STATUS "Build with comgr ${amd_comgr_VERSION}") + set(MIOPEN_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, amd_comgr") endif() if(MIOPEN_USE_HIPRTC) @@ -420,7 +422,23 @@ else() endif() set(MIOPEN_SYSTEM_FIND_DB_SUFFIX "${MIOPEN_BACKEND}" CACHE PATH "Filename suffix for the system find-db files") -set(MIOPEN_PACKAGE_REQS "hip-rocclr") +# PR-2391 Add the ability to log function calls to roctx. +# This allows attached profilers to see which MIOpen calls are being called by application and which kernels are being invoked by MIOpen. +# Enabled via the MIOPEN_ENABLE_LOGGING_ROCTX env var. +set(MIOPEN_USE_ROCTRACER ON CACHE BOOL "") +if(NOT WIN32 AND MIOPEN_USE_ROCTRACER) + find_library(rocTracer roctx64) + if(rocTracer) + MESSAGE(STATUS "Build with rocTracer: " ${rocTracer}) + set(MIOPEN_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, roctracer") + else() + message(WARNING "rocTracer cannot be found! Build without rocTracer") + set(MIOPEN_USE_ROCTRACER OFF) + endif() +else() + message(STATUS "Build without rocTracer") + set(MIOPEN_USE_ROCTRACER OFF) +endif() if(MIOPEN_USE_ROCBLAS) set(MIOPEN_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, rocblas") diff --git a/Dockerfile b/Dockerfile index e2e9af51c3..e3a724ff14 100755 --- a/Dockerfile +++ b/Dockerfile @@ -50,6 +50,7 @@ DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated \ python3-pip \ python3-venv \ rocblas \ + rocm-developer-tools \ rpm \ software-properties-common && \ apt-get clean && \ diff --git a/include/miopen/config.h.in b/include/miopen/config.h.in index b95942e76e..cb40e6d85d 100644 --- a/include/miopen/config.h.in +++ b/include/miopen/config.h.in @@ -30,6 +30,7 @@ #cmakedefine01 MIOPEN_BACKEND_HIP #cmakedefine01 MIOPEN_MODE_NOGPU #cmakedefine01 MIOPEN_USE_ROCBLAS +#cmakedefine01 MIOPEN_USE_ROCTRACER #cmakedefine01 MIOPEN_BUILD_DEV #cmakedefine01 MIOPEN_GPU_SYNC diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f40650c1c..b5526d56ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -99,7 +99,7 @@ set( MIOpen_Source conv/invokers/impl_gemm_dynamic.cpp conv/invokers/ocl_wrw_rdc.cpp conv/problem_description.cpp - conv/solver_finders.cpp + conv/solver_finders.cpp conv_algo_name.cpp convolution.cpp convolution_api.cpp @@ -841,7 +841,7 @@ if(NOT WIN32 AND NOT APPLE) endif() endif() -if(NOT WIN32) +if(MIOPEN_USE_ROCTRACER) target_link_libraries(MIOpen PRIVATE roctx64) endif() diff --git a/src/include/miopen/logger.hpp b/src/include/miopen/logger.hpp index dc18eae5c0..22a28bc95b 100644 --- a/src/include/miopen/logger.hpp +++ b/src/include/miopen/logger.hpp @@ -38,7 +38,7 @@ #include #include -#ifndef _WIN32 +#if MIOPEN_USE_ROCTRACER #include #endif @@ -224,7 +224,9 @@ std::string LoggingPrefix(); bool IsLogging(LoggingLevel level, bool disableQuieting = false); bool IsLoggingCmd(); bool IsLoggingFunctionCalls(); +#if MIOPEN_USE_ROCTRACER bool IsLoggingToRoctx(); +#endif namespace logger { @@ -307,8 +309,23 @@ LogParam(std::ostream& os, std::string name, const std::vector& vec, bool ind miopen::LogParam(miopen_log_func_ostream, #param, param, false) << " | "; \ } while(false); +#if MIOPEN_USE_ROCTRACER +#define MIOPEN_LOG_ROCTX_DEFINE_OBJECT miopen::LogScopeRoctx logtx; +#define MIOPEN_LOG_ROCTX_DO_LOGGING(...) \ + if(miopen::IsLoggingToRoctx()) \ + { \ + std::ostringstream miopen_log_func_ss; \ + miopen_log_func_ss << "s_api = " << __FUNCTION__ << " | "; \ + MIOPEN_PP_EACH_ARGS(MIOPEN_LOG_FUNCTION_EACH_ROCTX, __VA_ARGS__) \ + logtx.logRange(miopen_log_func_ss.str()); \ + } +#else +#define MIOPEN_LOG_ROCTX_DEFINE_OBJECT +#define MIOPEN_LOG_ROCTX_DO_LOGGING(...) +#endif + #define MIOPEN_LOG_FUNCTION(...) \ - miopen::LogScopeRoctx logtx; \ + MIOPEN_LOG_ROCTX_DEFINE_OBJECT \ do \ { \ if(miopen::IsLoggingFunctionCalls()) \ @@ -322,13 +339,7 @@ LogParam(std::ostream& os, std::string name, const std::vector& vec, bool ind miopen_log_func_ss << miopen::LoggingPrefix() << "}" << std::endl; \ std::cerr << miopen_log_func_ss.str(); \ } \ - if(miopen::IsLoggingToRoctx()) \ - { \ - std::ostringstream miopen_log_func_ss; \ - miopen_log_func_ss << "s_api = " << __FUNCTION__ << " | "; \ - MIOPEN_PP_EACH_ARGS(MIOPEN_LOG_FUNCTION_EACH_ROCTX, __VA_ARGS__) \ - logtx.logRange(miopen_log_func_ss.str()); \ - } \ + MIOPEN_LOG_ROCTX_DO_LOGGING(__VA_ARGS__) \ } while(false) #else #define MIOPEN_LOG_FUNCTION(...) @@ -412,7 +423,7 @@ class LogScopeTime #define MIOPEN_LOG_SCOPE_TIME #endif -#ifndef _WIN32 +#if MIOPEN_USE_ROCTRACER class LogScopeRoctx { public: