From 2603a49ce3608601e5cf53cced71da837225ba7f Mon Sep 17 00:00:00 2001 From: Laurent Morichetti Date: Sat, 21 May 2022 11:54:32 -0700 Subject: [PATCH] Remove internal functions from the ROCtracer API The roctracer_load, roctracer_unload, and roctrace_flush_buf functions are not part of the ROCtracer API, and should not be exposed in the API header file, but keep the functions in the library for backward compatibility. Add src/roctracer/backward_compat.cpp to implement retired functions. Add test/app/backward_compat_test.cpp to test that the retired functions are still accessible in the latest roctracer library. Change-Id: I4c94310a7bfccfeae9384dac5db18fc79b4c5b17 [ROCm/roctracer commit: 8ee9d859ed8b8db462ed5d91a664ef98013a1449] --- projects/roctracer/inc/roctracer.h | 24 -------------- .../src/roctracer/backward_compat.cpp | 28 ++++++++++++++++ projects/roctracer/src/roctracer/exportmap | 11 ++++--- .../roctracer/src/roctracer/roctracer.cpp | 28 +++------------- .../roctracer/src/tracer_tool/tracer_tool.cpp | 6 ---- projects/roctracer/test/CMakeLists.txt | 5 +++ .../test/app/backward_compat_test.cpp | 32 +++++++++++++++++++ .../golden_traces/tests_trace_cmp_levels.txt | 1 + projects/roctracer/test/run.sh | 2 ++ 9 files changed, 79 insertions(+), 58 deletions(-) create mode 100644 projects/roctracer/src/roctracer/backward_compat.cpp create mode 100644 projects/roctracer/test/app/backward_compat_test.cpp diff --git a/projects/roctracer/inc/roctracer.h b/projects/roctracer/inc/roctracer.h index 7bc6603a50..830572d2b4 100644 --- a/projects/roctracer/inc/roctracer.h +++ b/projects/roctracer/inc/roctracer.h @@ -773,30 +773,6 @@ roctracer_status_t roctracer_get_timestamp(uint64_t* timestamp); /** @} */ -/** \defgroup internal_group Internal Operations - * - * \todo Should these operation be part of the API? - * - * @{ - */ - -/** - * Load ROC Tracer library. - */ -bool roctracer_load(); - -/** - * Unload ROC Tracer library. - */ -void roctracer_unload(); - -/** - * Flush trace buffers. - */ -void roctracer_flush_buf(); - -/** @} */ - #ifdef __cplusplus } // extern "C" block #endif // __cplusplus diff --git a/projects/roctracer/src/roctracer/backward_compat.cpp b/projects/roctracer/src/roctracer/backward_compat.cpp new file mode 100644 index 0000000000..2fa761b9e4 --- /dev/null +++ b/projects/roctracer/src/roctracer/backward_compat.cpp @@ -0,0 +1,28 @@ +/* Copyright (c) 2022 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "roctracer.h" + +#define PUBLIC_API __attribute__((visibility("default"))) + +// Deprecated functions: +extern "C" PUBLIC_API int roctracer_load() { return 1; } +extern "C" PUBLIC_API void roctracer_unload() {} +extern "C" PUBLIC_API void roctracer_flush_buf() {} diff --git a/projects/roctracer/src/roctracer/exportmap b/projects/roctracer/src/roctracer/exportmap index 9571c113a0..9df5c91457 100644 --- a/projects/roctracer/src/roctracer/exportmap +++ b/projects/roctracer/src/roctracer/exportmap @@ -1,3 +1,9 @@ +ROCTRACER_4.0 { +global: roctracer_flush_buf; + roctracer_load; + roctracer_unload; +}; + ROCTRACER_4.1 { global: OnLoad; OnUnload; @@ -25,9 +31,7 @@ global: OnLoad; roctracer_error_string; roctracer_flush_activity; roctracer_flush_activity_expl; - roctracer_flush_buf; roctracer_get_timestamp; - roctracer_load; roctracer_mark; roctracer_next_record; roctracer_op_code; @@ -37,8 +41,7 @@ global: OnLoad; roctracer_set_properties; roctracer_start; roctracer_stop; - roctracer_unload; roctracer_version_major; roctracer_version_minor; local: *; -}; +} ROCTRACER_4.0; diff --git a/projects/roctracer/src/roctracer/roctracer.cpp b/projects/roctracer/src/roctracer/roctracer.cpp index 919b87cb6f..e80e4a901e 100644 --- a/projects/roctracer/src/roctracer/roctracer.cpp +++ b/projects/roctracer/src/roctracer/roctracer.cpp @@ -832,18 +832,14 @@ PUBLIC_API roctracer_status_t roctracer_open_pool_expl(const roctracer_propertie API_METHOD_SUFFIX } -PUBLIC_API roctracer_status_t roctracer_open_pool( - const roctracer_properties_t* properties) -{ +PUBLIC_API roctracer_status_t roctracer_open_pool(const roctracer_properties_t* properties) { API_METHOD_PREFIX roctracer_open_pool_impl(properties, nullptr); API_METHOD_SUFFIX } -PUBLIC_API roctracer_status_t roctracer_next_record( - const activity_record_t* record, - const activity_record_t** next) -{ +PUBLIC_API roctracer_status_t roctracer_next_record(const activity_record_t* record, + const activity_record_t** next) { API_METHOD_PREFIX *next = record + 1; API_METHOD_SUFFIX @@ -1079,7 +1075,7 @@ PUBLIC_API roctracer_status_t roctracer_close_pool() { API_METHOD_PREFIX roctracer_close_pool_impl(NULL); API_METHOD_SUFFIX - } +} // Flush available activity records static void roctracer_flush_activity_impl(roctracer_pool_t* pool) { @@ -1224,22 +1220,6 @@ PUBLIC_API roctracer_status_t roctracer_set_properties(roctracer_domain_t domain API_METHOD_SUFFIX } -PUBLIC_API bool roctracer_load() { - ONLOAD_TRACE_BEG(); - ONLOAD_TRACE_END(); - return true; -} - -PUBLIC_API void roctracer_unload() { - ONLOAD_TRACE_BEG(); - ONLOAD_TRACE_END(); -} - -PUBLIC_API void roctracer_flush_buf() { - ONLOAD_TRACE_BEG(); - ONLOAD_TRACE_END(); -} - CONSTRUCTOR_API void constructor() { ONLOAD_TRACE_BEG(); util::Logger::Create(); diff --git a/projects/roctracer/src/tracer_tool/tracer_tool.cpp b/projects/roctracer/src/tracer_tool/tracer_tool.cpp index fca0138f17..d1bc6d8267 100644 --- a/projects/roctracer/src/tracer_tool/tracer_tool.cpp +++ b/projects/roctracer/src/tracer_tool/tracer_tool.cpp @@ -718,16 +718,12 @@ void tool_unload() { close_tracing_pool(); roctracer::TraceBufferBase::FlushAll(); - roctracer_flush_buf(); close_file_handles(); - if (hip_api_stats) hip_api_stats->dump(); if (hip_kernel_stats) hip_kernel_stats->dump(); if (hip_memcpy_stats) hip_memcpy_stats->dump(); - roctracer_unload(); - ONLOAD_TRACE_END(); } @@ -900,8 +896,6 @@ extern "C" PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version, const char* const* failed_tool_names) { ONLOAD_TRACE_BEG(); - roctracer_load(); - const char* output_prefix = getenv("ROCP_OUTPUT_DIR"); // Dumping HSA handles for agents diff --git a/projects/roctracer/test/CMakeLists.txt b/projects/roctracer/test/CMakeLists.txt index 43915f3dbf..48398c9c75 100644 --- a/projects/roctracer/test/CMakeLists.txt +++ b/projects/roctracer/test/CMakeLists.txt @@ -111,6 +111,11 @@ hip_add_executable(roctx_test EXCLUDE_FROM_ALL app/roctx_test.cpp) target_link_libraries(roctx_test Threads::Threads roctx) add_dependencies(mytest roctx_test) +## Build the backward compatibility test +add_executable(backward_compat_test EXCLUDE_FROM_ALL app/backward_compat_test.cpp) +target_link_libraries(backward_compat_test roctracer) +add_dependencies(mytest backward_compat_test) + ## Copy the golden traces and test scripts configure_file(run.sh ${PROJECT_BINARY_DIR} COPYONLY) execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink run.sh ${PROJECT_BINARY_DIR}/run_ci.sh) diff --git a/projects/roctracer/test/app/backward_compat_test.cpp b/projects/roctracer/test/app/backward_compat_test.cpp new file mode 100644 index 0000000000..6f637cdd60 --- /dev/null +++ b/projects/roctracer/test/app/backward_compat_test.cpp @@ -0,0 +1,32 @@ +/* Copyright (c) 2022 Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#include "roctracer.h" + +extern "C" int roctracer_load(); // Removed in ROCTX 4.1 +extern "C" void roctracer_unload(); // Removed in ROCTX 4.1 +extern "C" void roctracer_flush_buf(); // Removed in ROCTX 4.1 + +int main() { + if (roctracer_load() != 1) return -1; + roctracer_flush_buf(); + roctracer_unload(); + return 0; +} diff --git a/projects/roctracer/test/golden_traces/tests_trace_cmp_levels.txt b/projects/roctracer/test/golden_traces/tests_trace_cmp_levels.txt index eab5b72648..6fb420f4e3 100644 --- a/projects/roctracer/test/golden_traces/tests_trace_cmp_levels.txt +++ b/projects/roctracer/test/golden_traces/tests_trace_cmp_levels.txt @@ -17,3 +17,4 @@ hsa_co_trace --check-none code_obj_trace --check-none trace_buffer_trace --check-none roctx_test_trace --check-count .* +backward_compat_test_trace --check-none \ No newline at end of file diff --git a/projects/roctracer/test/run.sh b/projects/roctracer/test/run.sh index 5d1e26dda5..d06c7ebc3a 100755 --- a/projects/roctracer/test/run.sh +++ b/projects/roctracer/test/run.sh @@ -185,6 +185,8 @@ eval_test "tool tracer codeobj" ./test/MatrixTranspose code_obj_trace eval_test "directed TraceBuffer test" ./test/trace_buffer trace_buffer_trace +eval_test "backward compatibilty tests" ./test/backward_compat_test backward_compat_test_trace + echo "$test_number tests total / $test_runnum tests run / $test_status tests failed" if [ $test_status != 0 ] ; then echo $failed_tests