From 1a5c0dd44c8e8cae59de88e26e8d77e6240c89f0 Mon Sep 17 00:00:00 2001 From: Jun Liu Date: Mon, 6 Nov 2023 16:52:55 -0800 Subject: [PATCH 1/8] Fix miopen package dependency roctracer etc --- CMakeLists.txt | 7 ++++++- src/CMakeLists.txt | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc1d2594e0..448fd03037 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -357,6 +357,7 @@ if(MIOPEN_USE_MLIR) math(EXPR rocMLIR_VERSION_FLAT "(${rocMLIR_VERSION_MAJOR} * 1000 + ${rocMLIR_VERSION_MINOR}) * 100000 + ${rocMLIR_VERSION_PATCH}") endif() +set(MIOPEN_PACKAGE_REQS "hip-rocclr") # Online assembler find_program(MIOPEN_AMDGCN_ASSEMBLER @@ -377,6 +378,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) @@ -418,7 +420,10 @@ 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_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, roctracer") if(MIOPEN_USE_ROCBLAS) set(MIOPEN_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, rocblas") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d4b9aba8a3..a0f4c14a04 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -846,7 +846,12 @@ if(NOT WIN32 AND NOT APPLE) endif() if(NOT WIN32) - target_link_libraries(MIOpen PRIVATE roctx64) + find_library(rocTracer roctx64) + if(rocTracer) + MESSAGE(STATUS "rocTracer: " ${rocTracer}) + target_link_libraries(MIOpen PRIVATE roctx64) + list(APPEND PACKAGE_DEPENDS PACKAGE roctracer) + endif() endif() ############################################################ From a9df7c40f7beb0506f486ff03975410922d48443 Mon Sep 17 00:00:00 2001 From: Jun Liu Date: Mon, 6 Nov 2023 17:37:15 -0800 Subject: [PATCH 2/8] fix CI docker for missing package --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 9a722cdf06..f183a6eb6d 100755 --- a/Dockerfile +++ b/Dockerfile @@ -49,6 +49,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 && \ From 84aaab6af25c1533aeadc5e81ed664c63bb5afba Mon Sep 17 00:00:00 2001 From: Jun Liu Date: Tue, 7 Nov 2023 12:20:54 -0800 Subject: [PATCH 3/8] fix a cmake rabit hole --- src/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0f4c14a04..ae959354d4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -850,7 +850,6 @@ if(NOT WIN32) if(rocTracer) MESSAGE(STATUS "rocTracer: " ${rocTracer}) target_link_libraries(MIOpen PRIVATE roctx64) - list(APPEND PACKAGE_DEPENDS PACKAGE roctracer) endif() endif() From 45c946c67feb1621dcda440e8b547f0cd52e7083 Mon Sep 17 00:00:00 2001 From: Jun Liu Date: Wed, 8 Nov 2023 11:01:40 -0800 Subject: [PATCH 4/8] protect for Win32 --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 448fd03037..20096e28ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -423,7 +423,9 @@ set(MIOPEN_SYSTEM_FIND_DB_SUFFIX "${MIOPEN_BACKEND}" CACHE PATH "Filename suffix # 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_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, roctracer") +if(NOT WIN32) + set(MIOPEN_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, roctracer") +endif() if(MIOPEN_USE_ROCBLAS) set(MIOPEN_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, rocblas") From b328015dc0655ebcd6b3f7a0cda4c566f0597b2e Mon Sep 17 00:00:00 2001 From: Jun Liu Date: Tue, 14 Nov 2023 14:39:13 -0800 Subject: [PATCH 5/8] make roctracer optional --- CMakeLists.txt | 15 +++++++++++++-- include/miopen/config.h.in | 1 + src/CMakeLists.txt | 12 ++++-------- src/include/miopen/logger.hpp | 23 +++++++++++++++++++++++ src/logger.cpp | 2 +- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20096e28ba..003b6cb83d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -423,8 +423,19 @@ set(MIOPEN_SYSTEM_FIND_DB_SUFFIX "${MIOPEN_BACKEND}" CACHE PATH "Filename suffix # 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. -if(NOT WIN32) - set(MIOPEN_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, roctracer") +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) diff --git a/include/miopen/config.h.in b/include/miopen/config.h.in index 734d19f263..a90d0ac1d6 100644 --- a/include/miopen/config.h.in +++ b/include/miopen/config.h.in @@ -32,6 +32,7 @@ #cmakedefine01 MIOPEN_USE_MIOPENTENSILE #cmakedefine01 MIOPEN_USE_MIOPENGEMM #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 ae959354d4..0f4bfc02a0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,7 +103,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 @@ -120,7 +120,7 @@ set( MIOpen_Source find_db.cpp fused_api.cpp fusion.cpp - fusion/problem_description.cpp + fusion/problem_description.cpp generic_search.cpp handle_api.cpp invoker_cache.cpp @@ -845,12 +845,8 @@ if(NOT WIN32 AND NOT APPLE) endif() endif() -if(NOT WIN32) - find_library(rocTracer roctx64) - if(rocTracer) - MESSAGE(STATUS "rocTracer: " ${rocTracer}) - target_link_libraries(MIOpen PRIVATE roctx64) - endif() +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..47dcb68b54 100644 --- a/src/include/miopen/logger.hpp +++ b/src/include/miopen/logger.hpp @@ -39,8 +39,10 @@ #include #ifndef _WIN32 +#if MIOPEN_USE_ROCTRACER #include #endif +#endif // See https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms #define MIOPEN_PP_CAT(x, y) MIOPEN_PP_PRIMITIVE_CAT(x, y) @@ -224,7 +226,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,6 +311,7 @@ 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_FUNCTION(...) \ miopen::LogScopeRoctx logtx; \ do \ @@ -331,6 +336,22 @@ LogParam(std::ostream& os, std::string name, const std::vector& vec, bool ind } \ } while(false) #else +#define MIOPEN_LOG_FUNCTION(...) \ + do \ + if(miopen::IsLoggingFunctionCalls()) \ + { \ + std::ostringstream miopen_log_func_ss; \ + miopen_log_func_ss << miopen::LoggingPrefix() << __PRETTY_FUNCTION__ << "{" \ + << std::endl; \ + std::cerr << miopen_log_func_ss.str(); \ + MIOPEN_PP_EACH_ARGS(MIOPEN_LOG_FUNCTION_EACH, __VA_ARGS__) \ + std::ostringstream().swap(miopen_log_func_ss); \ + miopen_log_func_ss << miopen::LoggingPrefix() << "}" << std::endl; \ + std::cerr << miopen_log_func_ss.str(); \ + } \ + while(false) +#endif +#else #define MIOPEN_LOG_FUNCTION(...) #endif @@ -413,6 +434,7 @@ class LogScopeTime #endif #ifndef _WIN32 +#if MIOPEN_USE_ROCTRACER class LogScopeRoctx { public: @@ -438,6 +460,7 @@ class LogScopeRoctx bool m_active{false}; }; #endif +#endif } // namespace miopen diff --git a/src/logger.cpp b/src/logger.cpp index f8045f9ac7..11887a2f46 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -128,7 +128,7 @@ bool IsLoggingFunctionCalls() bool IsLoggingToRoctx() { - return miopen::IsEnabled(MIOPEN_ENABLE_LOGGING_ROCTX{}) && !IsLoggingDebugQuiet(); + return miopen::IsEnabled(MIOPEN_ENABLE_LOGGING_ROCTX{}); } bool IsLogging(const LoggingLevel level, const bool disableQuieting) From 6facf19d3c7d9b33c3a034e58fa000a1e178b551 Mon Sep 17 00:00:00 2001 From: Jun Liu Date: Tue, 14 Nov 2023 14:59:42 -0800 Subject: [PATCH 6/8] making gtest optional too --- test/gtest/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index c5d51e2652..1b5da244b7 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -1,8 +1,10 @@ -find_package(GTest CONFIG REQUIRED) +find_package(GTest CONFIG) if(GTest_FOUND) MESSAGE(STATUS "GoogleTest: " ${GTest}) - enable_testing() include(GoogleTest) +else() + message(WARNING "GoogleTest is not found! Skip GTests ... try install GTest or MIOpen dependencies.") + return() endif() find_package(rocblas) From 914151989903dedfafd4727d2f04e909a30f3663 Mon Sep 17 00:00:00 2001 From: Jun Liu Date: Tue, 14 Nov 2023 15:40:23 -0800 Subject: [PATCH 7/8] adopt review opinions --- src/include/miopen/logger.hpp | 34 +++++++++++----------------------- test/gtest/CMakeLists.txt | 2 +- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/include/miopen/logger.hpp b/src/include/miopen/logger.hpp index 47dcb68b54..d12280c429 100644 --- a/src/include/miopen/logger.hpp +++ b/src/include/miopen/logger.hpp @@ -38,11 +38,9 @@ #include #include -#ifndef _WIN32 #if MIOPEN_USE_ROCTRACER #include #endif -#endif // See https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms #define MIOPEN_PP_CAT(x, y) MIOPEN_PP_PRIMITIVE_CAT(x, y) @@ -312,32 +310,24 @@ LogParam(std::ostream& os, std::string name, const std::vector& vec, bool ind } while(false); #if MIOPEN_USE_ROCTRACER -#define MIOPEN_LOG_FUNCTION(...) \ - miopen::LogScopeRoctx logtx; \ - do \ - { \ - if(miopen::IsLoggingFunctionCalls()) \ - { \ - std::ostringstream miopen_log_func_ss; \ - miopen_log_func_ss << miopen::LoggingPrefix() << __PRETTY_FUNCTION__ << "{" \ - << std::endl; \ - std::cerr << miopen_log_func_ss.str(); \ - MIOPEN_PP_EACH_ARGS(MIOPEN_LOG_FUNCTION_EACH, __VA_ARGS__) \ - std::ostringstream().swap(miopen_log_func_ss); \ - miopen_log_func_ss << miopen::LoggingPrefix() << "}" << std::endl; \ - std::cerr << miopen_log_func_ss.str(); \ - } \ +#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()); \ - } \ - } while(false) + } #else +#define MIOPEN_LOG_ROCTX_DEFINE_OBJECT +#define MIOPEN_LOG_ROCTX_DO_LOGGING(...) +#endif + #define MIOPEN_LOG_FUNCTION(...) \ + MIOPEN_LOG_ROCTX_DEFINE_OBJECT \ do \ + { \ if(miopen::IsLoggingFunctionCalls()) \ { \ std::ostringstream miopen_log_func_ss; \ @@ -349,8 +339,8 @@ 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(); \ } \ - while(false) -#endif + MIOPEN_LOG_ROCTX_DO_LOGGING(__VA_ARGS__) \ + } while(false) #else #define MIOPEN_LOG_FUNCTION(...) #endif @@ -433,7 +423,6 @@ class LogScopeTime #define MIOPEN_LOG_SCOPE_TIME #endif -#ifndef _WIN32 #if MIOPEN_USE_ROCTRACER class LogScopeRoctx { @@ -460,7 +449,6 @@ class LogScopeRoctx bool m_active{false}; }; #endif -#endif } // namespace miopen diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 1b5da244b7..11f00e36d5 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -3,7 +3,7 @@ if(GTest_FOUND) MESSAGE(STATUS "GoogleTest: " ${GTest}) include(GoogleTest) else() - message(WARNING "GoogleTest is not found! Skip GTests ... try install GTest or MIOpen dependencies.") + message(WARNING "GoogleTest is not found! Skip GTests ... try install GTest or preferably follow instructions to install MIOpen dependencies.") return() endif() From 907eaaf285ed2a99287f394369f481a5f805c069 Mon Sep 17 00:00:00 2001 From: Jun Liu Date: Wed, 22 Nov 2023 23:07:37 -0800 Subject: [PATCH 8/8] fix clang format issues --- src/include/miopen/logger.hpp | 16 ++++++++-------- src/logger.cpp | 5 +---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/include/miopen/logger.hpp b/src/include/miopen/logger.hpp index d12280c429..22a28bc95b 100644 --- a/src/include/miopen/logger.hpp +++ b/src/include/miopen/logger.hpp @@ -311,14 +311,14 @@ LogParam(std::ostream& os, std::string name, const std::vector& vec, bool ind #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()); \ - } +#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(...) diff --git a/src/logger.cpp b/src/logger.cpp index 11887a2f46..b819b576b3 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -126,10 +126,7 @@ bool IsLoggingFunctionCalls() return miopen::IsEnabled(MIOPEN_ENABLE_LOGGING{}) && !IsLoggingDebugQuiet(); } -bool IsLoggingToRoctx() -{ - return miopen::IsEnabled(MIOPEN_ENABLE_LOGGING_ROCTX{}); -} +bool IsLoggingToRoctx() { return miopen::IsEnabled(MIOPEN_ENABLE_LOGGING_ROCTX{}); } bool IsLogging(const LoggingLevel level, const bool disableQuieting) {