From 4eaa3b4eb4ffc19715302ab28a6150666ad44c28 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 22 Jan 2019 20:36:57 -0600 Subject: [PATCH] async-copy trace output file [ROCm/roctracer commit: 89682898c1f989d348407a639566603a5085dde3] --- projects/roctracer/build_proto.sh | 1 + projects/roctracer/src/core/roctracer.cpp | 35 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/projects/roctracer/build_proto.sh b/projects/roctracer/build_proto.sh index b9f4f14602..271e11b7a4 100755 --- a/projects/roctracer/build_proto.sh +++ b/projects/roctracer/build_proto.sh @@ -24,6 +24,7 @@ cmake \ $ROCTRACER_ROOT/inc/ext popd +make install make package exit 0 diff --git a/projects/roctracer/src/core/roctracer.cpp b/projects/roctracer/src/core/roctracer.cpp index da07bbd56e..95ad920981 100644 --- a/projects/roctracer/src/core/roctracer.cpp +++ b/projects/roctracer/src/core/roctracer.cpp @@ -28,6 +28,7 @@ THE SOFTWARE. #include #include +#include #include #include #include @@ -88,6 +89,13 @@ namespace roctracer { decltype(hsa_amd_memory_async_copy)* hsa_amd_memory_async_copy_fn; decltype(hsa_amd_memory_async_copy_rect)* hsa_amd_memory_async_copy_rect_fn; +// Profiling results output dir +const char* result_prefix = NULL; +// Global results file handle +FILE* result_file_handle = NULL; +// True if a result file is opened +bool result_file_opened = false; + namespace hsa_support { // callbacks table cb_table_t cb_table; @@ -368,7 +376,7 @@ void HCC_AsyncActivityCallback(uint32_t op_id, void* record, void* arg) { bool hsa_async_copy_handler(hsa_signal_value_t value, void* arg) { ::proxy::Tracker::entry_t* entry = reinterpret_cast<::proxy::Tracker::entry_t*>(arg); - printf("%lu:%lu async-copy%lu\n", entry->record->begin, entry->record->end, entry->index); + fprintf(result_file_handle, "%lu:%lu async-copy%lu\n", entry->record->begin, entry->record->end, entry->index); return false; } @@ -802,8 +810,33 @@ PUBLIC_API roctracer_status_t roctracer_set_properties( // HSA-runtime tool on-load method PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version, uint64_t failed_tool_count, const char* const* failed_tool_names) { + // Output file + roctracer::result_prefix = getenv("ROCP_OUTPUT_DIR"); + if (roctracer::result_prefix != NULL) { + DIR* dir = opendir(roctracer::result_prefix); + if (dir == NULL) { + std::ostringstream errmsg; + errmsg << "ROCTracer: Cannot open output directory '" << roctracer::result_prefix << "'"; + perror(errmsg.str().c_str()); + abort(); + } + std::ostringstream oss; + oss << roctracer::result_prefix << "/trace_async_copy.txt"; + roctracer::result_file_handle = fopen(oss.str().c_str(), "w"); + if (roctracer::result_file_handle == NULL) { + std::ostringstream errmsg; + errmsg << "ROCTracer: fopen error, file '" << oss.str().c_str() << "'"; + perror(errmsg.str().c_str()); + abort(); + } + } else roctracer::result_file_handle = stdout; + + roctracer::result_file_opened = (roctracer::result_prefix != NULL) && (roctracer::result_file_handle != NULL); + + // initialize HSA tracing roctracer_set_properties(ACTIVITY_DOMAIN_HSA_API, (void*)table); + // enabled HSA async-copy tracing hsa_status_t status = hsa_amd_profiling_async_copy_enable(true); if (status != HSA_STATUS_SUCCESS) EXC_ABORT(status, "hsa_amd_profiling_async_copy_enable"); roctracer::hsa_amd_memory_async_copy_fn = table->amd_ext_->hsa_amd_memory_async_copy_fn;