Fix hsa_support::timestamp_ns if HSA is not yet initialized

Default to the HSA runtime's hsa_system_get_info if the saved HSA
functions table is not yet initialized.

Change-Id: I3659095a5ad662f7ca8b0d92bd035901c6d66bb0
This commit is contained in:
Laurent Morichetti
2022-09-08 18:30:54 -07:00
parent db69cc1c9f
commit 87ffbd27f4
5 changed files with 119 additions and 8 deletions
+8
View File
@@ -20,6 +20,8 @@
## IN THE SOFTWARE.
################################################################################
get_property(HSA_RUNTIME_INCLUDE_DIRECTORIES TARGET hsa-runtime64::hsa-runtime64 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
# Set the HIP language runtime link flags as FindHIP does not set them.
set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG})
set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP})
@@ -139,6 +141,12 @@ hip_add_executable(multi_pool_activities directed/multi_pool_activities.cpp)
target_link_libraries(multi_pool_activities roctracer)
add_dependencies(mytest multi_pool_activities)
## Build the dlopen test
add_executable(dlopen directed/dlopen.cpp)
target_include_directories(dlopen PRIVATE ${PROJECT_SOURCE_DIR}/inc ${HSA_RUNTIME_INCLUDE_DIRECTORIES})
target_link_libraries(dlopen dl)
add_dependencies(mytest dlopen)
## 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)
+94
View File
@@ -0,0 +1,94 @@
/* 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"
#include <dlfcn.h>
#include <hsa/hsa.h>
#include <cassert>
using get_timestamp_t = decltype(roctracer_get_timestamp);
using hsa_init_t = decltype(hsa_init);
using hsa_shut_down_t = decltype(hsa_shut_down);
int main() {
// CASE 1: HSA is not loaded.
//
{
void* tracer_library = dlopen("libroctracer64.so", RTLD_LAZY);
assert(tracer_library != nullptr);
auto* get_timestamp =
reinterpret_cast<get_timestamp_t*>(dlsym(tracer_library, "roctracer_get_timestamp"));
assert(get_timestamp != nullptr);
roctracer_timestamp_t timestamp;
(*get_timestamp)(&timestamp);
dlclose(tracer_library);
}
// CASE 2 Load the roctracer after hsa_init().
//
void* hsa_library = dlopen("libhsa-runtime64.so.1", RTLD_LAZY);
assert(hsa_library != nullptr);
auto* hsa_init = reinterpret_cast<hsa_init_t*>(dlsym(hsa_library, "hsa_init"));
auto* hsa_shut_down = reinterpret_cast<hsa_shut_down_t*>(dlsym(hsa_library, "hsa_shut_down"));
assert(hsa_init != nullptr && hsa_shut_down != nullptr);
{
(*hsa_init)();
void* tracer_library = dlopen("libroctracer64.so", RTLD_LAZY);
assert(tracer_library != nullptr);
auto* get_timestamp =
reinterpret_cast<get_timestamp_t*>(dlsym(tracer_library, "roctracer_get_timestamp"));
assert(get_timestamp != nullptr);
roctracer_timestamp_t timestamp;
(*get_timestamp)(&timestamp);
dlclose(tracer_library);
(*hsa_shut_down)();
}
// CASE 3: Load and use the roctracer before hsa_init().
//
{
void* tracer_library = dlopen("libroctracer64.so", RTLD_LAZY);
assert(tracer_library != nullptr);
auto* get_timestamp =
reinterpret_cast<get_timestamp_t*>(dlsym(tracer_library, "roctracer_get_timestamp"));
assert(get_timestamp != nullptr);
roctracer_timestamp_t timestamp;
(*get_timestamp)(&timestamp);
(*hsa_init)();
(*hsa_shut_down)();
dlclose(tracer_library);
}
return 0;
}
@@ -21,3 +21,4 @@ activity_and_callback_trace --check-order .*
multi_pool_activities_trace --check-order .*
roctx_test_trace --check-count .*
backward_compat_test_trace --check-none
dlopen --check-none
+1
View File
@@ -181,6 +181,7 @@ eval_test "directed TraceBuffer test" ./test/trace_buffer trace_buffer
eval_test "directed MemoryPool test" ./test/memory_pool memory_pool
eval_test "enable/disable callbacks and activities test" ./test/activity_and_callback activity_and_callback_trace
eval_test "use multiple memory pools in HIP activities test" ./test/multi_pool_activities multi_pool_activities_trace
eval_test "Dynamically load the tracer library test" ./test/dlopen dlopen
eval_test "backward compatibility tests" ./test/backward_compat_test backward_compat_test_trace