Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix miopen package dependency roctracer etc #2508

Merged
merged 11 commits into from
Dec 24, 2023
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,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
Expand All @@ -369,6 +370,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)
Expand Down Expand Up @@ -410,7 +412,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()

junliume marked this conversation as resolved.
Show resolved Hide resolved
if(MIOPEN_USE_ROCBLAS)
set(MIOPEN_PACKAGE_REQS "${MIOPEN_PACKAGE_REQS}, rocblas")
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
1 change: 1 addition & 0 deletions include/miopen/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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
Expand All @@ -114,7 +114,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
Expand Down Expand Up @@ -829,7 +829,7 @@ if(NOT WIN32 AND NOT APPLE)
endif()
endif()

if(NOT WIN32)
if(MIOPEN_USE_ROCTRACER)
target_link_libraries(MIOpen PRIVATE roctx64)
endif()

Expand Down
23 changes: 23 additions & 0 deletions src/include/miopen/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
#include <miopen/config.h>

#ifndef _WIN32
junliume marked this conversation as resolved.
Show resolved Hide resolved
#if MIOPEN_USE_ROCTRACER
#include <roctracer/roctx.h>
#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)
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -307,6 +311,7 @@ LogParam(std::ostream& os, std::string name, const std::vector<T>& 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 \
Expand All @@ -331,6 +336,22 @@ LogParam(std::ostream& os, std::string name, const std::vector<T>& 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
junliume marked this conversation as resolved.
Show resolved Hide resolved
#define MIOPEN_LOG_FUNCTION(...)
#endif

Expand Down Expand Up @@ -413,6 +434,7 @@ class LogScopeTime
#endif

#ifndef _WIN32
junliume marked this conversation as resolved.
Show resolved Hide resolved
#if MIOPEN_USE_ROCTRACER
class LogScopeRoctx
{
public:
Expand All @@ -438,6 +460,7 @@ class LogScopeRoctx
bool m_active{false};
};
#endif
#endif

} // namespace miopen

Expand Down
2 changes: 1 addition & 1 deletion src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions test/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can introduce something like MIOPEN_USE_GTEST, make it enabled by default and fail if Gtest is not found. Then the user can explicitly disable or install GTest.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GTest, like rocTracer are development tools instead of hard dependencies of the library. How about we deal with them in separate PR? I will adopt the other review options in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If GTest is broken, then CI will silently omit many tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we let the default MIOpen and MIOpenDriver target build without the GTest dependency, however, if tests are being built then GTest must be present otherwise compile will fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

return()
endif()

find_package(rocblas)
Expand Down