Skip to content

Commit

Permalink
Fix miopen package dependency roctracer etc (#2508)
Browse files Browse the repository at this point in the history
  • Loading branch information
junliume authored Dec 24, 2023
1 parent c06434a commit 4f9364b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ if(MIOPEN_USE_MLIR)
endif()
endif()

set(MIOPEN_PACKAGE_REQS "hip-rocclr")

# Online assembler
find_program(MIOPEN_AMDGCN_ASSEMBLER
Expand All @@ -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)
Expand Down Expand Up @@ -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")
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 @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
31 changes: 21 additions & 10 deletions src/include/miopen/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <miopen/object.hpp>
#include <miopen/config.h>

#ifndef _WIN32
#if MIOPEN_USE_ROCTRACER
#include <roctracer/roctx.h>
#endif

Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -307,8 +309,23 @@ 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_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()) \
Expand All @@ -322,13 +339,7 @@ LogParam(std::ostream& os, std::string name, const std::vector<T>& 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(...)
Expand Down Expand Up @@ -412,7 +423,7 @@ class LogScopeTime
#define MIOPEN_LOG_SCOPE_TIME
#endif

#ifndef _WIN32
#if MIOPEN_USE_ROCTRACER
class LogScopeRoctx
{
public:
Expand Down

0 comments on commit 4f9364b

Please sign in to comment.