diff --git a/projects/roctracer/inc/ext/prof_protocol.h b/projects/roctracer/inc/ext/prof_protocol.h index 6a824d551e..1ba622feb5 100644 --- a/projects/roctracer/inc/ext/prof_protocol.h +++ b/projects/roctracer/inc/ext/prof_protocol.h @@ -55,6 +55,9 @@ typedef enum { ACTIVITY_API_PHASE_ENTER = 0, ACTIVITY_API_PHASE_EXIT = 1 } activ /* Correlation id */ typedef uint64_t activity_correlation_id_t; +/* Timestamp in nanoseconds */ +typedef uint64_t roctracer_timestamp_t; + /* Activity record type */ typedef struct activity_record_s { uint32_t domain; /* activity domain id */ @@ -63,8 +66,8 @@ typedef struct activity_record_s { union { struct { activity_correlation_id_t correlation_id; /* activity ID */ - uint64_t begin_ns; /* host begin timestamp */ - uint64_t end_ns; /* host end timestamp */ + roctracer_timestamp_t begin_ns; /* host begin timestamp */ + roctracer_timestamp_t end_ns; /* host end timestamp */ }; struct { uint32_t se; /* sampled SE */ diff --git a/projects/roctracer/inc/roctracer.h b/projects/roctracer/inc/roctracer.h index 457532a469..1ac7dbf296 100644 --- a/projects/roctracer/inc/roctracer.h +++ b/projects/roctracer/inc/roctracer.h @@ -802,7 +802,7 @@ ROCTRACER_API roctracer_status_t roctracer_flush_activity() ROCTRACER_VERSION_4_ * @retval ::ROCTRACER_STATUS_SUCCESS The function has been executed * successfully. */ -ROCTRACER_API roctracer_status_t roctracer_get_timestamp(uint64_t* timestamp) ROCTRACER_VERSION_4_1; +ROCTRACER_API roctracer_status_t roctracer_get_timestamp(roctracer_timestamp_t* timestamp) ROCTRACER_VERSION_4_1; /** @} */ diff --git a/projects/roctracer/src/roctracer/roctracer.cpp b/projects/roctracer/src/roctracer/roctracer.cpp index 518f56e254..2c3ca4958e 100644 --- a/projects/roctracer/src/roctracer/roctracer.cpp +++ b/projects/roctracer/src/roctracer/roctracer.cpp @@ -145,7 +145,7 @@ roctracer_stop_cb_t roctracer_stop_cb = nullptr; namespace util { -uint64_t timestamp_ns() { +roctracer_timestamp_t timestamp_ns() { uint64_t sysclock; hsa_status_t status = hsa_support::hsa_system_get_info_fn(HSA_SYSTEM_INFO_TIMESTAMP, &sysclock); @@ -320,7 +320,7 @@ void* HIP_SyncApiDataCallback(uint32_t op_id, roctracer_record_t* record, const void* HIP_SyncActivityCallback(uint32_t op_id, roctracer_record_t* record, const void* callback_data, void* arg) { - const uint64_t timestamp_ns = util::timestamp_ns(); + const roctracer_timestamp_t timestamp_ns = util::timestamp_ns(); void* ret = nullptr; const hip_api_data_t* data = reinterpret_cast(callback_data); hip_api_data_t* data_ptr = const_cast(data); @@ -1171,7 +1171,7 @@ ROCTRACER_API void roctracer_stop() { } } -ROCTRACER_API roctracer_status_t roctracer_get_timestamp(uint64_t* timestamp) { +ROCTRACER_API roctracer_status_t roctracer_get_timestamp(roctracer_timestamp_t* timestamp) { API_METHOD_PREFIX *timestamp = util::timestamp_ns(); API_METHOD_SUFFIX diff --git a/projects/roctracer/src/roctracer/tracker.h b/projects/roctracer/src/roctracer/tracker.h index 25e7b6ad6b..d651c28857 100644 --- a/projects/roctracer/src/roctracer/tracker.h +++ b/projects/roctracer/src/roctracer/tracker.h @@ -48,8 +48,8 @@ class Tracker { std::atomic valid; entry_type_t type; uint64_t correlation_id; - uint64_t begin; // begin timestamp, ns - uint64_t end; // end timestamp, ns + roctracer_timestamp_t begin; // begin timestamp, ns + roctracer_timestamp_t end; // end timestamp, ns hsa_agent_t agent; uint32_t dev_index; hsa_signal_t orig; @@ -96,7 +96,7 @@ class Tracker { private: // Entry completion inline static void Complete(hsa_signal_value_t signal_value, entry_t* entry) { - static uint64_t sysclock_period = []() { + static roctracer_timestamp_t sysclock_period = []() { uint64_t sysclock_hz = 0; hsa_status_t status = hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &sysclock_hz); if (status != HSA_STATUS_SUCCESS) FATAL_LOGGING("hsa_system_get_info failed"); diff --git a/projects/roctracer/src/tracer_tool/tracer_tool.cpp b/projects/roctracer/src/tracer_tool/tracer_tool.cpp index 325dfc0780..f25c133a62 100644 --- a/projects/roctracer/src/tracer_tool/tracer_tool.cpp +++ b/projects/roctracer/src/tracer_tool/tracer_tool.cpp @@ -82,14 +82,13 @@ inline static void DEBUG_TRACE(const char* fmt, ...) { #define DEBUG_TRACE(...) #endif -typedef uint64_t timestamp_t; -thread_local timestamp_t hsa_begin_timestamp = 0; -thread_local timestamp_t hip_begin_timestamp = 0; +thread_local roctracer_timestamp_t hsa_begin_timestamp = 0; +thread_local roctracer_timestamp_t hip_begin_timestamp = 0; namespace util { -inline timestamp_t timestamp_ns() { - timestamp_t timestamp; +inline roctracer_timestamp_t timestamp_ns() { + roctracer_timestamp_t timestamp; CHECK_ROCTRACER(roctracer_get_timestamp(×tamp)); return timestamp; } @@ -191,7 +190,7 @@ void flush_thr_fun() { struct roctx_trace_entry_t { std::atomic valid; uint32_t cid; - timestamp_t time; + roctracer_timestamp_t time; uint32_t pid; uint32_t tid; roctx_range_id_t rid; @@ -237,8 +236,8 @@ void roctx_api_callback(uint32_t domain, uint32_t cid, const void* callback_data struct hsa_api_trace_entry_t { std::atomic valid; uint32_t cid; - timestamp_t begin; - timestamp_t end; + roctracer_timestamp_t begin; + roctracer_timestamp_t end; uint32_t pid; uint32_t tid; hsa_api_data_t data; @@ -263,7 +262,7 @@ void hsa_api_callback(uint32_t domain, uint32_t cid, const void* callback_data, if (data->phase == ACTIVITY_API_PHASE_ENTER) { hsa_begin_timestamp = util::timestamp_ns(); } else { - const timestamp_t end_timestamp = + const roctracer_timestamp_t end_timestamp = (cid == HSA_API_ID_hsa_shut_down) ? hsa_begin_timestamp : util::timestamp_ns(); hsa_api_trace_entry_t* entry = hsa_api_trace_buffer.GetEntry(); entry->cid = cid; @@ -283,8 +282,8 @@ struct hip_api_trace_entry_t { std::atomic valid; uint32_t domain; uint32_t cid; - timestamp_t begin; - timestamp_t end; + roctracer_timestamp_t begin; + roctracer_timestamp_t end; uint32_t pid; uint32_t tid; hip_api_data_t data; @@ -307,8 +306,8 @@ void hip_api_flush_cb(hip_api_trace_entry_t* entry) { const uint32_t cid = entry->cid; const hip_api_data_t* data = &(entry->data); const uint64_t correlation_id = data->correlation_id; - const timestamp_t begin_timestamp = entry->begin; - const timestamp_t end_timestamp = entry->end; + const roctracer_timestamp_t begin_timestamp = entry->begin; + const roctracer_timestamp_t end_timestamp = entry->end; std::ostringstream rec_ss; std::ostringstream oss; @@ -346,7 +345,7 @@ roctracer::TraceBuffer hip_api_trace_buffer("HIP API", 0x void hip_api_callback(uint32_t domain, uint32_t cid, const void* callback_data, void* arg) { (void)arg; const hip_api_data_t* data = reinterpret_cast(callback_data); - const timestamp_t timestamp = util::timestamp_ns(); + const roctracer_timestamp_t timestamp = util::timestamp_ns(); hip_api_trace_entry_t* entry = NULL; if (data->phase == ACTIVITY_API_PHASE_ENTER) { @@ -423,7 +422,7 @@ void mark_api_callback(uint32_t domain, uint32_t cid, const void* callback_data, (void)arg; const char* name = reinterpret_cast(callback_data); - const timestamp_t timestamp = util::timestamp_ns(); + const roctracer_timestamp_t timestamp = util::timestamp_ns(); hip_api_trace_entry_t* entry = hip_api_trace_buffer.GetEntry(); entry->cid = 0; entry->domain = domain; @@ -443,7 +442,7 @@ void mark_api_callback(uint32_t domain, uint32_t cid, const void* callback_data, struct hip_act_trace_entry_t { std::atomic valid; uint32_t kind; - timestamp_t dur; + roctracer_timestamp_t dur; uint64_t correlation_id; }; @@ -838,7 +837,7 @@ ROCTRACER_EXPORT bool OnLoad(HsaApiTable* table, uint64_t runtime_version, // App begin timestamp begin_ts_file.txt begin_ts_file_handle = open_output_file(output_prefix, "begin_ts_file.txt"); - const timestamp_t app_start_time = util::timestamp_ns(); + const roctracer_timestamp_t app_start_time = util::timestamp_ns(); fprintf(begin_ts_file_handle, "%lu\n", app_start_time); // Enable HSA API callbacks/activity