SWDEV-351980 - Don't allocate hip_api_data and record

The HIP runtime is now allocating the hip_api_data and record on its
stack so we don't need the thread local record_data_pair stack anymore.

Refactor the API callback function to handle both the case where
synchronous user callbacks are requested and the case where asynchronous
records are requested (enable_callback & enable_activity respectively).
If the callback argument (memory pool) is not null, then activity
records are requested.

Remove CorrelationIdRegister and CorrelationIdLookup. These were used
by the HIP runtime to associate a HIP record id to a ROCtracer
correlation id. Instead, the HIP runtime is now using the correlation
ID returned in the hip_api_data_t.

Added a test to check enabling/disabling concurrent callbacks and
activities.

Change-Id: I5850cfead9861eb3602a3e8fcb7b22580d5fc979


[ROCm/roctracer commit: 88c6e0a700]
This commit is contained in:
Laurent Morichetti
2022-08-04 11:38:08 -07:00
orang tua 9674c2b11a
melakukan f50c9d4149
8 mengubah file dengan 283 tambahan dan 197 penghapusan
@@ -133,6 +133,12 @@ target_include_directories(memory_pool PRIVATE ${PROJECT_SOURCE_DIR}/src/roctrac
target_link_libraries(memory_pool Threads::Threads atomic)
add_dependencies(mytest memory_pool)
## Build the activity_and_callback test
set_source_files_properties(directed/activity_and_callback.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
hip_add_executable(activity_and_callback directed/activity_and_callback.cpp)
target_link_libraries(activity_and_callback roctracer)
add_dependencies(mytest activity_and_callback)
## 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)
@@ -0,0 +1,139 @@
/* 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 <hip/hip_runtime.h>
#include <roctracer.h>
#define HIP_PROF_HIP_API_STRING 1
#include <roctracer_hip.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
__global__ void kernel() {}
template <typename T> inline void CHECK(T status);
template <> inline void CHECK(hipError_t err) {
if (err != hipSuccess) {
std::cerr << hipGetErrorString(err) << std::endl;
abort();
}
}
template <> inline void CHECK(roctracer_status_t status) {
if (status != ROCTRACER_STATUS_SUCCESS) {
std::cerr << roctracer_error_string() << std::endl;
abort();
}
}
namespace {
uint32_t GetPid() {
static auto pid = syscall(__NR_getpid);
return pid;
}
uint32_t GetTid() {
static thread_local auto tid = syscall(__NR_gettid);
return tid;
}
void hip_api_callback(uint32_t domain, uint32_t cid, const void* callback_data, void* arg) {
const hip_api_data_t* data = static_cast<const hip_api_data_t*>(callback_data);
fprintf(stdout, "<%s id(%u)\tcorrelation_id(%lu) %s pid(%d) tid(%d)>\n",
roctracer_op_string(domain, cid, 0), cid, data->correlation_id,
(data->phase == ACTIVITY_API_PHASE_ENTER) ? "on-enter" : "on-exit", GetPid(), GetTid());
}
void buffer_callback(const char* begin, const char* end, void* arg) {
for (const roctracer_record_t* record = (const roctracer_record_t*)begin;
record < (const roctracer_record_t*)end; CHECK(roctracer_next_record(record, &record))) {
fprintf(stdout, "\t%s\tcorrelation_id(%lu) time_ns(%lu:%lu)\n",
roctracer_op_string(record->domain, record->op, record->kind), record->correlation_id,
record->begin_ns, record->end_ns);
}
}
} // namespace
int main() {
CHECK(hipSetDevice(0));
roctracer_properties_t properties{};
properties.buffer_callback_fun = buffer_callback;
properties.buffer_callback_arg = nullptr;
properties.buffer_size = 1024;
CHECK(roctracer_open_pool(&properties));
// 1: callbacks only
CHECK(roctracer_enable_domain_callback(ACTIVITY_DOMAIN_HIP_API, hip_api_callback, nullptr));
CHECK(hipSetDevice(0));
kernel<<<1, 1>>>();
CHECK(hipDeviceSynchronize());
CHECK(roctracer_flush_activity());
// 2: callbacks and activities
CHECK(roctracer_enable_domain_activity(ACTIVITY_DOMAIN_HIP_API));
CHECK(hipSetDevice(0));
kernel<<<1, 1>>>();
CHECK(hipDeviceSynchronize());
CHECK(roctracer_flush_activity());
// 3: activities only
CHECK(roctracer_disable_domain_callback(ACTIVITY_DOMAIN_HIP_API));
CHECK(hipSetDevice(0));
kernel<<<1, 1>>>();
CHECK(hipDeviceSynchronize());
CHECK(roctracer_flush_activity());
// 4: callbacks only
CHECK(roctracer_enable_domain_callback(ACTIVITY_DOMAIN_HIP_API, hip_api_callback, nullptr));
CHECK(roctracer_disable_domain_activity(ACTIVITY_DOMAIN_HIP_API));
CHECK(hipSetDevice(0));
kernel<<<1, 1>>>();
CHECK(hipDeviceSynchronize());
CHECK(roctracer_flush_activity());
// 5: callbacks and activities
CHECK(roctracer_enable_domain_activity(ACTIVITY_DOMAIN_HIP_API));
CHECK(hipSetDevice(0));
kernel<<<1, 1>>>();
CHECK(hipDeviceSynchronize());
CHECK(roctracer_flush_activity());
// 6: callbacks only
CHECK(roctracer_disable_domain_activity(ACTIVITY_DOMAIN_HIP_API));
CHECK(hipSetDevice(0));
kernel<<<1, 1>>>();
CHECK(hipDeviceSynchronize());
CHECK(roctracer_flush_activity());
// 7: none
CHECK(roctracer_disable_domain_callback(ACTIVITY_DOMAIN_HIP_API));
CHECK(roctracer_disable_domain_activity(ACTIVITY_DOMAIN_HIP_API));
CHECK(hipSetDevice(0));
kernel<<<1, 1>>>();
CHECK(hipDeviceSynchronize());
CHECK(roctracer_flush_activity());
return 0;
}
@@ -0,0 +1,65 @@
<hipSetDevice id(186) correlation_id(1) on-enter pid(877336) tid(877336)>
<hipSetDevice id(186) correlation_id(1) on-exit pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(2) on-enter pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(2) on-exit pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(3) on-enter pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(3) on-exit pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(4) on-enter pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(4) on-exit pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(5) on-enter pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(5) on-exit pid(877336) tid(877336)>
<hipSetDevice id(186) correlation_id(6) on-enter pid(877336) tid(877336)>
<hipSetDevice id(186) correlation_id(6) on-exit pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(7) on-enter pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(7) on-exit pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(8) on-enter pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(8) on-exit pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(9) on-enter pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(9) on-exit pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(10) on-enter pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(10) on-exit pid(877336) tid(877336)>
hipSetDevice correlation_id(6) time_ns(861794298279896:861794298283613)
__hipPushCallConfiguration correlation_id(7) time_ns(861794298290125:861794298293211)
__hipPopCallConfiguration correlation_id(8) time_ns(861794298293903:861794298295325)
hipLaunchKernel correlation_id(9) time_ns(861794298296377:861794298313029)
hipDeviceSynchronize correlation_id(10) time_ns(861794298313470:861794298331113)
hipSetDevice correlation_id(11) time_ns(861794298565986:861794298566277)
__hipPushCallConfiguration correlation_id(12) time_ns(861794298566738:861794298567148)
__hipPopCallConfiguration correlation_id(13) time_ns(861794298567569:861794298568010)
hipLaunchKernel correlation_id(14) time_ns(861794298568391:861794298577638)
hipDeviceSynchronize correlation_id(15) time_ns(861794298578069:861794298594841)
<hipSetDevice id(186) correlation_id(16) on-enter pid(877336) tid(877336)>
<hipSetDevice id(186) correlation_id(16) on-exit pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(17) on-enter pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(17) on-exit pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(18) on-enter pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(18) on-exit pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(19) on-enter pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(19) on-exit pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(20) on-enter pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(20) on-exit pid(877336) tid(877336)>
<hipSetDevice id(186) correlation_id(21) on-enter pid(877336) tid(877336)>
<hipSetDevice id(186) correlation_id(21) on-exit pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(22) on-enter pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(22) on-exit pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(23) on-enter pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(23) on-exit pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(24) on-enter pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(24) on-exit pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(25) on-enter pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(25) on-exit pid(877336) tid(877336)>
hipSetDevice correlation_id(21) time_ns(861794299364583:861794299365585)
__hipPushCallConfiguration correlation_id(22) time_ns(861794299366106:861794299367329)
__hipPopCallConfiguration correlation_id(23) time_ns(861794299367830:861794299369082)
hipLaunchKernel correlation_id(24) time_ns(861794299369523:861794299377227)
hipDeviceSynchronize correlation_id(25) time_ns(861794299377748:861794299394730)
<hipSetDevice id(186) correlation_id(26) on-enter pid(877336) tid(877336)>
<hipSetDevice id(186) correlation_id(26) on-exit pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(27) on-enter pid(877336) tid(877336)>
<__hipPushCallConfiguration id(2) correlation_id(27) on-exit pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(28) on-enter pid(877336) tid(877336)>
<__hipPopCallConfiguration id(1) correlation_id(28) on-exit pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(29) on-enter pid(877336) tid(877336)>
<hipLaunchKernel id(107) correlation_id(29) on-exit pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(30) on-enter pid(877336) tid(877336)>
<hipDeviceSynchronize id(48) correlation_id(30) on-exit pid(877336) tid(877336)>
@@ -18,5 +18,6 @@ hsa_co_trace --check-none
code_obj_trace --check-none
trace_buffer --check-none
memory_pool --check-none
activity_and_callback_trace --check-order .*
roctx_test_trace --check-count .*
backward_compat_test_trace --check-none
backward_compat_test_trace --check-none
+3 -1
Melihat File
@@ -176,14 +176,16 @@ export ROCP_TOOL_LIB=./test/libcodeobj_test.so
export HSA_TOOLS_LIB="librocprofiler64.so"
eval_test "tool tracer codeobj" ./test/MatrixTranspose code_obj_trace
unset LD_PRELOAD
#valgrind --leak-check=full $tbin
#valgrind --tool=massif $tbin
#ms_print massif.out.<N>
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 "backward compatibilty tests" ./test/backward_compat_test backward_compat_test_trace
eval_test "backward compatibility 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