From 472e96a084334eadb8fc8bb9d4ba67d5d4d124c5 Mon Sep 17 00:00:00 2001 From: "Jonathan R. Madsen" Date: Wed, 14 Sep 2022 00:07:33 -0500 Subject: [PATCH] Fix building w/ hip, etc. but w/o rocprofiler (#159) - Fixes builds with `OMNITRACE_USE_ROCPROFILER=OFF` but `OMNITRACE_USE_ROCTRACER=ON` - Move rocprofiler/hsa_rsrc_factory.{hpp,cpp}` to rocm folder --- cmake/Modules/Findroctracer.cmake | 16 +++++++++++++++- source/lib/omnitrace/library/CMakeLists.txt | 6 ++---- .../omnitrace/library/components/CMakeLists.txt | 2 +- .../omnitrace/library/components/rocprofiler.hpp | 4 ++-- source/lib/omnitrace/library/rocm.cpp | 8 +++++--- .../library/{rocprofiler => rocm}/CMakeLists.txt | 2 +- .../{rocprofiler => rocm}/hsa_rsrc_factory.cpp | 8 +------- .../{rocprofiler => rocm}/hsa_rsrc_factory.hpp | 0 source/lib/omnitrace/library/rocprofiler.cpp | 8 +++----- 9 files changed, 30 insertions(+), 24 deletions(-) rename source/lib/omnitrace/library/{rocprofiler => rocm}/CMakeLists.txt (78%) rename source/lib/omnitrace/library/{rocprofiler => rocm}/hsa_rsrc_factory.cpp (99%) rename source/lib/omnitrace/library/{rocprofiler => rocm}/hsa_rsrc_factory.hpp (100%) diff --git a/cmake/Modules/Findroctracer.cmake b/cmake/Modules/Findroctracer.cmake index 5a11c18229..6ae3571be2 100644 --- a/cmake/Modules/Findroctracer.cmake +++ b/cmake/Modules/Findroctracer.cmake @@ -70,6 +70,13 @@ find_library( PATHS ${roctracer_ROOT_DIR} ${_ROCM_ROCTRACER_PATHS} PATH_SUFFIXES lib lib64) +find_library( + roctracer_hsa-runtime_LIBRARY + NAMES hsa-runtime64 hsa-runtime + HINTS ${roctracer_ROOT_DIR} ${_ROCM_ROCTRACER_PATHS} + PATHS ${roctracer_ROOT_DIR} ${_ROCM_ROCTRACER_PATHS} + PATH_SUFFIXES lib lib64) + # try not to directly use the hsakmt::hsakmt target because it hardcodes the # INTERFACE_LINK_LIBRARIES used when it was built find_package(hsakmt HINTS ${_ROCM_ROCTRACER_PATHS} PATHS ${_ROCM_ROCTRACER_PATHS}) @@ -124,7 +131,8 @@ if(roctracer_LIBRARY) get_filename_component(roctracer_LIBRARY_DIR "${roctracer_LIBRARY}" PATH CACHE) endif() -mark_as_advanced(roctracer_LIBRARY roctracer_roctx_LIBRARY roctracer_hsakmt_LIBRARY) +mark_as_advanced(roctracer_LIBRARY roctracer_roctx_LIBRARY roctracer_hsakmt_LIBRARY + roctracer_hsa-runtime_LIBRARY) # ----------------------------------------------------------------------------------------# @@ -163,6 +171,12 @@ if(roctracer_FOUND) target_link_libraries(roctracer::roctx INTERFACE ${roctracer_hsakmt_LIBRARY}) endif() + if(roctracer_hsa-runtime_LIBRARY) + list(APPEND roctracer_LIBRARIES ${roctracer_hsa-runtime_LIBRARY}) + target_link_libraries(roctracer::roctracer + INTERFACE ${roctracer_hsa-runtime_LIBRARY}) + endif() + endif() # ------------------------------------------------------------------------------# diff --git a/source/lib/omnitrace/library/CMakeLists.txt b/source/lib/omnitrace/library/CMakeLists.txt index 098afa7f01..b99c95f6c4 100644 --- a/source/lib/omnitrace/library/CMakeLists.txt +++ b/source/lib/omnitrace/library/CMakeLists.txt @@ -58,9 +58,7 @@ target_sources(omnitrace-object-library PRIVATE ${library_sources} ${library_hea ${CMAKE_CURRENT_BINARY_DIR}/defines.hpp) if(OMNITRACE_USE_ROCTRACER OR OMNITRACE_USE_ROCPROFILER) - target_sources( - omnitrace-object-library PRIVATE ${CMAKE_CURRENT_LIST_DIR}/rocprofiler.cpp - ${CMAKE_CURRENT_LIST_DIR}/rocm.cpp) + target_sources(omnitrace-object-library PRIVATE ${CMAKE_CURRENT_LIST_DIR}/rocm.cpp) endif() if(OMNITRACE_USE_ROCTRACER) @@ -84,4 +82,4 @@ if(OMNITRACE_USE_ROCM_SMI) endif() add_subdirectory(components) -add_subdirectory(rocprofiler) +add_subdirectory(rocm) diff --git a/source/lib/omnitrace/library/components/CMakeLists.txt b/source/lib/omnitrace/library/components/CMakeLists.txt index fdd5183adb..5a3b4f7f08 100644 --- a/source/lib/omnitrace/library/components/CMakeLists.txt +++ b/source/lib/omnitrace/library/components/CMakeLists.txt @@ -35,7 +35,7 @@ set(component_headers target_sources(omnitrace-object-library PRIVATE ${component_sources} ${component_headers}) -if(OMNITRACE_USE_ROCTRACER OR OMNITRACE_USE_ROCPROFILER) +if(OMNITRACE_USE_ROCPROFILER) target_sources(omnitrace-object-library PRIVATE ${CMAKE_CURRENT_LIST_DIR}/rocprofiler.cpp) endif() diff --git a/source/lib/omnitrace/library/components/rocprofiler.hpp b/source/lib/omnitrace/library/components/rocprofiler.hpp index a46a46241e..bb3ed6f1f3 100644 --- a/source/lib/omnitrace/library/components/rocprofiler.hpp +++ b/source/lib/omnitrace/library/components/rocprofiler.hpp @@ -131,7 +131,7 @@ struct rocprofiler [[nodiscard]] static scope::transient_destructor protect_flush_activity(); }; -#if !defined(OMNITRACE_USE_ROCTRACER) +#if !defined(OMNITRACE_USE_ROCPROFILER) inline void rocprofiler::setup() {} @@ -215,7 +215,7 @@ struct get_storage } // namespace operation } // namespace tim -#if !defined(OMNITRACE_USE_ROCTRACER) +#if !defined(OMNITRACE_USE_ROCPROFILER) OMNITRACE_DEFINE_CONCRETE_TRAIT(is_available, component::rocprofiler_data, false_type) #endif diff --git a/source/lib/omnitrace/library/rocm.cpp b/source/lib/omnitrace/library/rocm.cpp index 9c526a8415..990d546e39 100644 --- a/source/lib/omnitrace/library/rocm.cpp +++ b/source/lib/omnitrace/library/rocm.cpp @@ -27,9 +27,9 @@ #include "library/debug.hpp" #include "library/dynamic_library.hpp" #include "library/gpu.hpp" +#include "library/rocm/hsa_rsrc_factory.hpp" #include "library/rocm_smi.hpp" #include "library/rocprofiler.hpp" -#include "library/rocprofiler/hsa_rsrc_factory.hpp" #include "library/roctracer.hpp" #include "library/runtime.hpp" #include "library/sampling.hpp" @@ -62,7 +62,9 @@ # define OMNITRACE_HIP_API_ARGS 0 #endif -#include +#if defined(OMNITRACE_USE_ROCPROFILER) && OMNITRACE_USE_ROCPROFILER > 0 +# include +#endif using namespace omnitrace; @@ -162,12 +164,12 @@ extern "C" const char* const* failed_tool_names) { OMNITRACE_BASIC_VERBOSE_F(2 || rocm::on_load_trace, "Loading...\n"); + OMNITRACE_SCOPED_SAMPLING_ON_CHILD_THREADS(false); if(!tim::get_env("OMNITRACE_INIT_TOOLING", true)) return true; if(!tim::settings::enabled()) return true; roctracer_is_init() = true; - OMNITRACE_SCOPED_SAMPLING_ON_CHILD_THREADS(false); OMNITRACE_BASIC_VERBOSE_F(1 || rocm::on_load_trace, "Loading ROCm tooling...\n"); tim::consume_parameters(table, runtime_version, failed_tool_count, diff --git a/source/lib/omnitrace/library/rocprofiler/CMakeLists.txt b/source/lib/omnitrace/library/rocm/CMakeLists.txt similarity index 78% rename from source/lib/omnitrace/library/rocprofiler/CMakeLists.txt rename to source/lib/omnitrace/library/rocm/CMakeLists.txt index 2c63eb3478..357ca9383c 100644 --- a/source/lib/omnitrace/library/rocprofiler/CMakeLists.txt +++ b/source/lib/omnitrace/library/rocm/CMakeLists.txt @@ -1,5 +1,5 @@ # -if(OMNITRACE_USE_ROCPROFILER) +if(OMNITRACE_USE_ROCPROFILER OR OMNITRACE_USE_ROCTRACER) target_sources( omnitrace-object-library PRIVATE ${CMAKE_CURRENT_LIST_DIR}/hsa_rsrc_factory.hpp ${CMAKE_CURRENT_LIST_DIR}/hsa_rsrc_factory.cpp) diff --git a/source/lib/omnitrace/library/rocprofiler/hsa_rsrc_factory.cpp b/source/lib/omnitrace/library/rocm/hsa_rsrc_factory.cpp similarity index 99% rename from source/lib/omnitrace/library/rocprofiler/hsa_rsrc_factory.cpp rename to source/lib/omnitrace/library/rocm/hsa_rsrc_factory.cpp index 99663de104..223b49166c 100644 --- a/source/lib/omnitrace/library/rocprofiler/hsa_rsrc_factory.cpp +++ b/source/lib/omnitrace/library/rocm/hsa_rsrc_factory.cpp @@ -20,18 +20,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -#include "library/rocprofiler/hsa_rsrc_factory.hpp" +#include "library/rocm/hsa_rsrc_factory.hpp" #include "library/debug.hpp" #include "library/defines.hpp" #include -#include - -#define PUBLIC_API __attribute__((visibility("default"))) -#define CONSTRUCTOR_API __attribute__((constructor)) -#define DESTRUCTOR_API __attribute__((destructor)) - #include #include #include diff --git a/source/lib/omnitrace/library/rocprofiler/hsa_rsrc_factory.hpp b/source/lib/omnitrace/library/rocm/hsa_rsrc_factory.hpp similarity index 100% rename from source/lib/omnitrace/library/rocprofiler/hsa_rsrc_factory.hpp rename to source/lib/omnitrace/library/rocm/hsa_rsrc_factory.hpp diff --git a/source/lib/omnitrace/library/rocprofiler.cpp b/source/lib/omnitrace/library/rocprofiler.cpp index e4f99ed733..b19473859a 100644 --- a/source/lib/omnitrace/library/rocprofiler.cpp +++ b/source/lib/omnitrace/library/rocprofiler.cpp @@ -27,7 +27,7 @@ #include "library/gpu.hpp" #include "library/perfetto.hpp" #include "library/rocm.hpp" -#include "library/rocprofiler/hsa_rsrc_factory.hpp" +#include "library/rocm/hsa_rsrc_factory.hpp" #include #include @@ -144,8 +144,6 @@ void rocm_dump_context_entry(context_entry_t* entry, rocprofiler_feature_t* features, unsigned feature_count) { - // static rocm_metric_type last_timestamp = get_last_timestamp_ns(); - volatile std::atomic* valid = reinterpret_cast*>(&entry->valid); while(valid->load() == false) @@ -191,8 +189,8 @@ rocm_context_handler(const rocprofiler_pool_entry_t* entry, void* arg) context_entry_t* ctx_entry = reinterpret_cast(entry->payload); handler_arg_t* handler_arg = reinterpret_cast(arg); - rocm::lock_t _lk{ rocm::rocm_mutex, std::defer_lock }; - if(!_lk.owns_lock()) _lk.lock(); + // rocm::lock_t _lk{ rocm::rocm_mutex, std::defer_lock }; + // if(!_lk.owns_lock()) _lk.lock(); rocm_dump_context_entry(ctx_entry, handler_arg->features, handler_arg->feature_count);