Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface proposal : pull request 5 #61

Open
wants to merge 22 commits into
base: rocm-4.3.x
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0adba5c
Fix fine-grained control
yoann-heitz Sep 21, 2021
b4e487e
Add buffer for tracing KFD API
yoann-heitz Sep 21, 2021
a669e4a
Isolate flushing function for roctx
yoann-heitz Sep 21, 2021
bb24c82
Isolate flushing instructions for HSA activity
yoann-heitz Sep 21, 2021
f06ef8d
Isolate flushing instructions for HIP API
yoann-heitz Sep 22, 2021
035a498
Isolate flushing instructions for HIP activity
yoann-heitz Sep 22, 2021
77d23b6
Update HSA activity flushing function signature
yoann-heitz Sep 23, 2021
9b390bf
Update HIP activity (HCC ops) flushing function signature
yoann-heitz Sep 23, 2021
3787d72
Move roctx_trace_entry_t to a new header
yoann-heitz Sep 23, 2021
9d0dd89
Update CMakeLists to take into account the new header
yoann-heitz Sep 23, 2021
dccd171
Move hsa_api_trace_entry_t to roctracer_trace_entries.h
yoann-heitz Sep 23, 2021
5b06b80
Move hsa_activity_trace_entry_t to roctracer_trace_entries.h
yoann-heitz Sep 23, 2021
a73995f
Move hip_api_trace_entry_t to roctracer_trace_entries.h
yoann-heitz Sep 23, 2021
abbab33
Move hip_activity_trace_entry_t to roctracer_trace_entries.h
yoann-heitz Sep 23, 2021
b3a0781
Move kfd_api_trace_entry_t to roctracer_trace_entries.h
yoann-heitz Sep 23, 2021
0d36ffa
Add loading instructions for opening/closing output plugin
yoann-heitz Sep 24, 2021
6297eba
Add overloading instructions for rocTX
yoann-heitz Sep 24, 2021
bcd300c
Add overloading instructions for HSA API
yoann-heitz Sep 24, 2021
d7b88de
Add overloading instructions for HSA activity
yoann-heitz Sep 24, 2021
ffff6cb
Add overloading instructions for HIP API
yoann-heitz Sep 24, 2021
7a41a43
Add overloading instructions for HIP activity
yoann-heitz Sep 24, 2021
1cc010d
Add overloading instructions for KFD API
yoann-heitz Sep 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix fine-grained control
Replaced all C++ standard vectors with C arrays in functions used to enable fine-grained control. These vectors appeared to be empty at the moment when roctracer_enable_op_callback is called in OnLoad function. This may be due to the fact that this function is called by another .so or DLL library and exchanging STL objects (like C++ vectors) through these kinds of libraries can lead to unexpected behavior when the libraries were not compiled with the same compiler and compiler version. The use of C native objects can solve these issues.
yoann-heitz committed Sep 21, 2021
commit 0adba5ccb79110a410686ce3af3bbe14e0eb5d83
79 changes: 53 additions & 26 deletions test/tool/tracer_tool.cpp
Original file line number Diff line number Diff line change
@@ -109,10 +109,13 @@ bool trace_hip_api = false;
bool trace_hip_activity = false;
bool trace_kfd = false;
bool trace_pcs = false;
// API trace vector
std::vector<std::string> hsa_api_vec;
std::vector<std::string> kfd_api_vec;
std::vector<std::string> hip_api_vec;
// API trace arrays and sizes
uint32_t hsa_api_array_size=0;
char** hsa_api_array;
uint32_t kfd_api_array_size=0;
char** kfd_api_array;
uint32_t hip_api_array_size=0;
char** hip_api_array;

LOADER_INSTANTIATE();
TRACE_BUFFER_INSTANTIATE();
@@ -511,9 +514,9 @@ void hip_api_flush_cb(hip_api_trace_entry_t* entry) {
if (hip_api_stats != NULL) {
hip_api_stats->add_event(cid, end_timestamp - begin_timestamp);
if (is_hip_kernel_launch_api(cid)) {
hip_kernel_mutex.lock();
hip_kernel_mutex.lock();
(*hip_kernel_map)[correlation_id] = entry->name;
hip_kernel_mutex.unlock();
hip_kernel_mutex.unlock();
}
} else {
const char* str = hipApiString((hip_api_id_t)cid, data);
@@ -913,7 +916,13 @@ void tool_load() {
if (name == "HSA") {
found = true;
trace_hsa_api = true;
hsa_api_vec = api_vec;
hsa_api_array_size = api_vec.size();
if(hsa_api_array_size > 0){
hsa_api_array = (char**)malloc(api_vec.size() * sizeof(char*));
for(uint64_t i = 0 ; i < api_vec.size(); i++){
hsa_api_array[i] = strdup(api_vec[i].c_str());
}
}
}
if (name == "GPU") {
found = true;
@@ -923,12 +932,24 @@ void tool_load() {
found = true;
trace_hip_api = true;
trace_hip_activity = true;
hip_api_vec = api_vec;
hip_api_array_size = api_vec.size();
if(hip_api_array_size > 0){
hip_api_array = (char**)malloc(api_vec.size() * sizeof(char*));
for(uint64_t i = 0 ; i < api_vec.size(); i++){
hip_api_array[i] = strdup(api_vec[i].c_str());
}
}
}
if (name == "KFD") {
found = true;
trace_kfd = true;
kfd_api_vec = api_vec;
kfd_api_array_size = api_vec.size();
if(kfd_api_array_size > 0){
kfd_api_array = (char**)malloc(api_vec.size() * sizeof(char*));
for(uint64_t i = 0 ; i < api_vec.size(); i++){
kfd_api_array[i] = strdup(api_vec[i].c_str());
}
}
}
}

@@ -1008,14 +1029,16 @@ void tool_load() {
roctracer_set_properties(ACTIVITY_DOMAIN_KFD_API, NULL);

printf(" KFD-trace(");
if (kfd_api_vec.size() != 0) {
for (unsigned i = 0; i < kfd_api_vec.size(); ++i) {
if (kfd_api_array_size != 0) {
for (unsigned i = 0; i < kfd_api_array_size; ++i) {
uint32_t cid = KFD_API_ID_NUMBER;
const char* api = kfd_api_vec[i].c_str();
const char* api = kfd_api_array[i];
ROCTRACER_CALL(roctracer_op_code(ACTIVITY_DOMAIN_KFD_API, api, &cid, NULL));
ROCTRACER_CALL(roctracer_enable_op_callback(ACTIVITY_DOMAIN_KFD_API, cid, kfd_api_callback, NULL));
printf(" %s", api);
free((char*)api);
}
free(kfd_api_array);
} else {
ROCTRACER_CALL(roctracer_enable_domain_callback(ACTIVITY_DOMAIN_KFD_API, kfd_api_callback, NULL));
}
@@ -1052,14 +1075,16 @@ extern "C" PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version,
roctracer_set_properties(ACTIVITY_DOMAIN_HSA_API, (void*)table);

fprintf(stdout, " HSA-trace("); fflush(stdout);
if (hsa_api_vec.size() != 0) {
for (unsigned i = 0; i < hsa_api_vec.size(); ++i) {
if (hsa_api_array_size != 0) {
for (unsigned i = 0; i < hsa_api_array_size; ++i) {
uint32_t cid = HSA_API_ID_NUMBER;
const char* api = hsa_api_vec[i].c_str();
const char* api = hsa_api_array[i];
ROCTRACER_CALL(roctracer_op_code(ACTIVITY_DOMAIN_HSA_API, api, &cid, NULL));
ROCTRACER_CALL(roctracer_enable_op_callback(ACTIVITY_DOMAIN_HSA_API, cid, hsa_api_callback, NULL));
printf(" %s", api);
free((char*)api);
}
free(hsa_api_array);
} else {
ROCTRACER_CALL(roctracer_enable_domain_callback(ACTIVITY_DOMAIN_HSA_API, hsa_api_callback, NULL));
}
@@ -1100,26 +1125,28 @@ extern "C" PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version,
// Enable tracing
if (trace_hip_api) {
hip_api_file_handle = open_output_file(output_prefix, "hip_api_trace.txt");
if (hip_api_vec.size() != 0) {
for (unsigned i = 0; i < hip_api_vec.size(); ++i) {
if (hip_api_array_size != 0) {
for (unsigned i = 0; i < hip_api_array_size; ++i) {
uint32_t cid = HIP_API_ID_NUMBER;
const char* api = hip_api_vec[i].c_str();
const char* api = hip_api_array[i];
ROCTRACER_CALL(roctracer_op_code(ACTIVITY_DOMAIN_HIP_API, api, &cid, NULL));
ROCTRACER_CALL(roctracer_enable_op_callback(ACTIVITY_DOMAIN_HIP_API, cid, hip_api_callback, NULL));
printf(" %s", api);
free((char*)api);
}
free(hip_api_array);
} else {
ROCTRACER_CALL(roctracer_enable_domain_callback(ACTIVITY_DOMAIN_HIP_API, hip_api_callback, NULL));
}

if (is_stats_opt) {
const char* path = NULL;
FILE* f = open_output_file(output_prefix, "hip_api_stats.csv", &path);
const char* path = NULL;
FILE* f = open_output_file(output_prefix, "hip_api_stats.csv", &path);
hip_api_stats = new EvtStats(f, path);
for (uint32_t id = 0; id < HIP_API_ID_NUMBER; id += 1) {
for (uint32_t id = 0; id < HIP_API_ID_NUMBER; id += 1) {
const char* label = roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, id, 0);
hip_api_stats->set_label(id, label);
}
}
}
}

@@ -1128,11 +1155,11 @@ extern "C" PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version,
ROCTRACER_CALL(roctracer_enable_domain_activity(ACTIVITY_DOMAIN_HCC_OPS));

if (is_stats_opt) {
FILE* f = NULL;
const char* path = NULL;
f = open_output_file(output_prefix, "hip_kernel_stats.csv", &path);
FILE* f = NULL;
const char* path = NULL;
f = open_output_file(output_prefix, "hip_kernel_stats.csv", &path);
hip_kernel_stats = new EvtStatsA(f, path);
f = open_output_file(output_prefix, "hip_memcpy_stats.csv", &path);
f = open_output_file(output_prefix, "hip_memcpy_stats.csv", &path);
hip_memcpy_stats = new EvtStatsA(f, path);
}
}