adding roctracer_id_string; domain any; HIP/HCC domains

[ROCm/roctracer commit: 53b9f54af8]
Этот коммит содержится в:
Evgeny
2018-06-01 19:09:18 -05:00
родитель 75565148f8
Коммит b5a33313b0
4 изменённых файлов: 97 добавлений и 157 удалений
+29 -40
Просмотреть файл
@@ -99,9 +99,11 @@ const char* roctracer_error_string();
// Traced API domains
typedef enum {
ROCTRACER_API_DOMAIN_ANY = 0, // Any domain
ROCTRACER_API_DOMAIN_HIP = 1, // HIP API domain
} roctracer_api_domain_t;
ROCTRACER_DOMAIN_ANY = 0, // Any domain
ROCTRACER_DOMAIN_HIP_API = 1, // HIP domain
ROCTRACER_DOMAIN_HCC_OPS = 2, // HCC domain
ROCTRACER_DOMAIN_NUMBER
} roctracer_domain_t;
// Traced calls ID enumeration
typedef hip_cb_id_t roctracer_hip_api_cid_t;
@@ -109,18 +111,15 @@ typedef hip_cb_id_t roctracer_hip_api_cid_t;
// Correlation ID type
typedef uint64_t roctracer_correletion_id_t;
// Return method name by given API domain and call ID
// Validates tracing domains revisions consistency
roctracer_status_t roctracer_validate_domains();
// Return ID string by given domain and activity/API ID
// NULL returned on the error and the library errno is set
const char* roctracer_get_api_name(
const char* roctracer_id_string(
const uint32_t& domain, // API domain
const uint32_t& cid); // API call ID
// Return activity name by given API domain operation ID and activity kind
// NULL returned on the error and the library errno is set
const char* roctracer_get_activity_name(
const uint32_t& domain, // API domain
const uint32_t& kind); // Activity kind
////////////////////////////////////////////////////////////////////////////////
// Callback API
//
@@ -140,16 +139,16 @@ typedef enum {
typedef hip_cb_fun_t roctracer_api_callback_t;
// Enable runtime API callbacks
int roctracer_enable_api_callback(
roctracer_api_domain_t domain, // runtime API domain
uint32_t cid, // API call ID
roctracer_api_callback_t callback, // callback function pointer
void* arg); // [in/out] callback arg
roctracer_status_t roctracer_enable_api_callback(
roctracer_domain_t domain, // runtime API domain
uint32_t cid, // API call ID
roctracer_api_callback_t callback, // callback function pointer
void* arg); // [in/out] callback arg
// Disable runtime API callbacks
int roctracer_disable_api_callback(
roctracer_api_domain_t domain, // runtime API domain
uint32_t cid); // API call ID
roctracer_status_t roctracer_disable_api_callback(
roctracer_domain_t domain, // runtime API domain
uint32_t cid); // API call ID
////////////////////////////////////////////////////////////////////////////////
// Activity API
@@ -164,25 +163,15 @@ int roctracer_disable_api_callback(
typedef void roctracer_pool_t;
// Activity record
#if 0
typedef hip_act_record_t roctracer_record_t;
typedef hip_dispatch_record_t roctracer_dispatch_record_t;
typedef hip_copy_record_t roctracer_memcpy_record_t;
typedef hip_barrier_record_t roctracer_barrier_record_t;
#else
typedef hip_act_record_t roctracer_record_t;
typedef hip_copy_record_t roctracer_async_record_t;
typedef roctracer_async_record_t roctracer_dispatch_record_t;
typedef roctracer_async_record_t roctracer_memcpy_record_t;
typedef roctracer_async_record_t roctracer_barrier_record_t;
#endif
typedef hip_ops_record_t roctracer_async_record_t;
// Return next record
static inline int roctracer_next_record(
const roctracer_record_t* record, // [in] record ptr
const roctracer_record_t** next) // [out] next record ptr
{
*next = (record->async) ?
*next = (record->op_id != 0) ?
reinterpret_cast<const roctracer_async_record_t*>(record) + 1 :
record + 1;
return ROCTRACER_STATUS_SUCCESS;
@@ -212,14 +201,14 @@ typedef struct {
// Create tracer memory pool
// The first invocation sets the default pool
int roctracer_open_pool(
roctracer_status_t roctracer_open_pool(
const roctracer_properties_t* properties, // tracer pool properties
roctracer_pool_t** pool = NULL); // [out] returns tracer pool if not NULL,
// otherwise sets the default one if it is not set yet
// otherwise the error is generated
// Close tracer memory pool
int roctracer_close_pool(
roctracer_status_t roctracer_close_pool(
roctracer_pool_t* pool = NULL); // [in] memory pool, NULL is a default one
// Return current default pool
@@ -228,18 +217,18 @@ roctracer_pool_t* roctracer_default_pool(
roctracer_pool_t* pool = NULL); // [in] new default pool if not NULL
// Enable activity records logging
int roctracer_enable_api_activity(
roctracer_api_domain_t domain, // runtime API domain
uint32_t activity_kind, // activity kind
roctracer_status_t roctracer_enable_api_activity(
roctracer_domain_t domain, // runtime API domain
uint32_t activity_kind, // activity kind
roctracer_pool_t* pool = NULL); // memory pool, NULL is a default one
// Disable activity records logging
int roctracer_disable_api_activity(
roctracer_api_domain_t domain, // runtime API domain
uint32_t activity_kind); // activity kind
roctracer_status_t roctracer_disable_api_activity(
roctracer_domain_t domain, // runtime API domain
uint32_t activity_kind); // activity kind
// Flush available activity records
int roctracer_flush_api_activity(
roctracer_status_t roctracer_flush_api_activity(
roctracer_pool_t* pool = NULL); // memory pool, NULL is a default one
#ifdef __cplusplus
+52 -88
Просмотреть файл
@@ -34,8 +34,15 @@
} \
} while (0)
#define HIPAPI_CALL(call) \
do { \
hipError_t err = call; \
if (err != hipSuccess) \
HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, #call " error(" << err << ")"); \
} while (0)
#define API_METHOD_PREFIX \
int err = 0; \
roctracer_status_t err = ROCTRACER_STATUS_SUCCESS; \
try {
#define API_METHOD_SUFFIX \
@@ -63,9 +70,9 @@ extern "C" const char* HSAOp_get_name(const uint32_t& id);
//
namespace roctracer {
int GetExcStatus(const std::exception& e) {
roctracer_status_t GetExcStatus(const std::exception& e) {
const util::exception* roctracer_exc_ptr = dynamic_cast<const util::exception*>(&e);
return (roctracer_exc_ptr) ? static_cast<int>(roctracer_exc_ptr->status()) : 1;
return (roctracer_exc_ptr) ? static_cast<roctracer_status_t>(roctracer_exc_ptr->status()) : ROCTRACER_STATUS_ERROR;
}
class GlobalCounter {
@@ -147,12 +154,13 @@ class MemoryPool {
char* next = write_ptr_ + sizeof(Record);
if (next > buffer_end_) {
if (write_ptr_ == buffer_begin_) EXC_ABORT(ROCTRACER_STATUS_ERROR, "buffer size(" << buffer_size_ << ") is less then the record(" << sizeof(Record) << ")");
spawn_reader(buffer_begin_, buffer_end_);
spawn_reader(buffer_begin_, write_ptr_);
buffer_begin_ = (buffer_end_ == pool_end_) ? pool_begin_ : buffer_end_;
buffer_end_ = buffer_begin_ + buffer_size_;
write_ptr_ = buffer_begin_;
next = write_ptr_ + sizeof(Record);
}
Record* ptr = reinterpret_cast<Record*>(write_ptr_);
write_ptr_ = next;
@@ -297,6 +305,7 @@ void ActivityCallback(
if (pool == NULL) EXC_ABORT(ROCTRACER_STATUS_ERROR, "ActivityCallback pool is NULL");
if (data->phase == ROCTRACER_API_PHASE_ENTER) {
*record = pool->getRecord<roctracer_record_t>();
(*record)->domain = ROCTRACER_DOMAIN_HIP_API;
(*record)->activity_kind = activity_kind;
(*record)->begin_ns = timer.timestamp_ns();
// Correlation ID generating
@@ -315,64 +324,15 @@ void ActivityCallback(
}
}
// HCC activity record type
struct hcc_record_t {
uint32_t op_id; // operation id, dispatch/copy/barrier
uint32_t command_id; // command kind
uint32_t async; // aysnc record, 0/1
uint64_t correlation_id; // activity correlation ID
uint64_t begin_ns; // host begin timestamp, nano-seconds
uint64_t end_ns; // host end timestamp, nano-seconds
int device_id;
uint64_t stream_id;
size_t bytes;
};
void ActivityAsyncCallback(
uint32_t op_id,
void* record,
void* arg)
{
if (op_id == 0) {
// HIP record Sync
roctracer_record_t* record_ptr = reinterpret_cast<roctracer_record_t*>(record);
*reinterpret_cast<uint64_t*>(arg) = record_ptr->correlation_id;
} else {
if (sizeof(hcc_record_t) != sizeof(roctracer_memcpy_record_t)) EXC_ABORT(ROCTRACER_STATUS_ERROR, "record types missmatch");
MemoryPool* pool = reinterpret_cast<MemoryPool*>(arg);
switch (op_id) {
// Dispatch record
case 1: {
roctracer_dispatch_record_t* record_ptr = pool->getRecord<roctracer_dispatch_record_t>();
*record_ptr = *reinterpret_cast<roctracer_dispatch_record_t*>(record);
break;
}
// Memcpy record
case 2: {
roctracer_memcpy_record_t* record_ptr = pool->getRecord<roctracer_memcpy_record_t>();
*record_ptr = *reinterpret_cast<roctracer_memcpy_record_t*>(record);
break;
}
// Barrier record
case 3: {
roctracer_barrier_record_t* record_ptr = pool->getRecord<roctracer_barrier_record_t>();
*record_ptr = *reinterpret_cast<roctracer_barrier_record_t*>(record);
break;
}
// Unknown ID
default:
EXC_ABORT(ROCTRACER_STATUS_ERROR, "Unknown op ID");
}
#if 0
std::cout << "ActivityAsyncCallback " << record_ptr->name
<< " id(" << op_id << "." << record_ptr->activity_kind << ")"
<< " record(" << record << ")"
<< " correlation_id(" << record_ptr->correlation_id << ")"
<< " time-ns(" << start << ":" << end << ")"
<< " arg(" << arg << ")"
<< std::endl << std::flush;
#endif
}
MemoryPool* pool = reinterpret_cast<MemoryPool*>(arg);
roctracer_async_record_t* record_ptr = pool->getRecord<roctracer_async_record_t>();
*record_ptr = *reinterpret_cast<roctracer_async_record_t*>(record);
record_ptr->domain = ROCTRACER_DOMAIN_HCC_OPS;
}
util::Logger::mutex_t util::Logger::mutex_;
@@ -394,28 +354,24 @@ PUBLIC_API const char* roctracer_error_string() {
return strdup(roctracer::util::Logger::LastMessage().c_str());
}
// Return method name by given API domain and call ID
// NULL returned on the error and the library errno is set
PUBLIC_API const char* roctracer_get_api_name(const uint32_t& domain, const uint32_t& cid) {
// Validates tracing domains revisions consistency
PUBLIC_API roctracer_status_t roctracer_validate_domains() {
API_METHOD_PREFIX
switch (domain) {
case ROCTRACER_API_DOMAIN_HIP: {
return hipApiName(cid);
break;
}
default:
EXC_RAISING(ROCTRACER_STATUS_BAD_DOMAIN, "invalid domain ID(" << domain << ")");
}
API_METHOD_CATCH(NULL)
HIPAPI_CALL(hipValidateActivityRecord());
API_METHOD_SUFFIX
}
// Return activity name by given API domain and activity kind
// Return ID string by given domain and activity/API ID
// NULL returned on the error and the library errno is set
PUBLIC_API const char* roctracer_get_activity_name(const uint32_t& domain, const uint32_t& kind) {
PUBLIC_API const char* roctracer_id_string(const uint32_t& domain, const uint32_t& id) {
API_METHOD_PREFIX
switch (domain) {
case ROCTRACER_API_DOMAIN_HIP: {
return HSAOp_get_name(kind);
case ROCTRACER_DOMAIN_HIP_API: {
return hipApiName(id);
break;
}
case ROCTRACER_DOMAIN_HCC_OPS: {
return HSAOp_get_name(id);
break;
}
default:
@@ -425,15 +381,17 @@ PUBLIC_API const char* roctracer_get_activity_name(const uint32_t& domain, const
}
// Enable runtime API callbacks
PUBLIC_API int roctracer_enable_api_callback(
roctracer_api_domain_t domain,
PUBLIC_API roctracer_status_t roctracer_enable_api_callback(
roctracer_domain_t domain,
uint32_t cid,
roctracer_api_callback_t callback,
void* user_data)
{
API_METHOD_PREFIX
switch (domain) {
case ROCTRACER_API_DOMAIN_HIP: {
case ROCTRACER_DOMAIN_ANY:
cid = 0;
case ROCTRACER_DOMAIN_HIP_API: {
hipError_t hip_err = hipRegisterApiCallback(cid, callback, user_data);
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRegisterApiCallback error(" << hip_err << ")");
break;
@@ -445,13 +403,15 @@ PUBLIC_API int roctracer_enable_api_callback(
}
// Enable runtime API callbacks
PUBLIC_API int roctracer_disable_api_callback(
roctracer_api_domain_t domain,
PUBLIC_API roctracer_status_t roctracer_disable_api_callback(
roctracer_domain_t domain,
uint32_t cid)
{
API_METHOD_PREFIX
switch (domain) {
case ROCTRACER_API_DOMAIN_HIP: {
case ROCTRACER_DOMAIN_ANY:
cid = 0;
case ROCTRACER_DOMAIN_HIP_API: {
hipError_t hip_err = hipRemoveApiCallback(cid);
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRemoveApiCallback error(" << hip_err << ")");
break;
@@ -471,7 +431,7 @@ roctracer_pool_t* roctracer_default_pool(roctracer_pool_t* pool) {
}
// Open memory pool
PUBLIC_API int roctracer_open_pool(
PUBLIC_API roctracer_status_t roctracer_open_pool(
const roctracer_properties_t* properties,
roctracer_pool_t** pool)
{
@@ -487,7 +447,7 @@ PUBLIC_API int roctracer_open_pool(
}
// Close memory pool
PUBLIC_API int roctracer_close_pool(roctracer_pool_t* pool) {
PUBLIC_API roctracer_status_t roctracer_close_pool(roctracer_pool_t* pool) {
API_METHOD_PREFIX
roctracer_pool_t* ptr = (pool == NULL) ? roctracer_default_pool() : pool;
roctracer::MemoryPool* memory_pool = reinterpret_cast<roctracer::MemoryPool*>(ptr);
@@ -497,15 +457,17 @@ PUBLIC_API int roctracer_close_pool(roctracer_pool_t* pool) {
}
// Enable activity records logging
PUBLIC_API int roctracer_enable_api_activity(
roctracer_api_domain_t domain,
PUBLIC_API roctracer_status_t roctracer_enable_api_activity(
roctracer_domain_t domain,
uint32_t activity_kind,
roctracer_pool_t* pool)
{
API_METHOD_PREFIX
if (pool == NULL) pool = roctracer_default_pool();
switch (domain) {
case ROCTRACER_API_DOMAIN_HIP: {
case ROCTRACER_DOMAIN_ANY:
activity_kind = 0;
case ROCTRACER_DOMAIN_HIP_API: {
const hipError_t hip_err = hipRegisterActivityCallback(activity_kind, roctracer::ActivityCallback, roctracer::ActivityAsyncCallback, pool);
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRegisterActivityCallback error(" << hip_err << ")");
break;
@@ -517,13 +479,15 @@ PUBLIC_API int roctracer_enable_api_activity(
}
// Disable activity records logging
PUBLIC_API int roctracer_disable_api_activity(
roctracer_api_domain_t domain,
PUBLIC_API roctracer_status_t roctracer_disable_api_activity(
roctracer_domain_t domain,
uint32_t activity_kind)
{
API_METHOD_PREFIX
switch (domain) {
case ROCTRACER_API_DOMAIN_HIP: {
case ROCTRACER_DOMAIN_ANY:
activity_kind = 0;
case ROCTRACER_DOMAIN_HIP_API: {
const hipError_t hip_err = hipRemoveActivityCallback(activity_kind);
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRemoveActivityCallback error(" << hip_err << ")");
break;
@@ -535,7 +499,7 @@ PUBLIC_API int roctracer_disable_api_activity(
}
// Flush available activity records
PUBLIC_API int roctracer_flush_api_activity(roctracer_pool_t* pool) {
PUBLIC_API roctracer_status_t roctracer_flush_api_activity(roctracer_pool_t* pool) {
API_METHOD_PREFIX
if (pool == NULL) pool = roctracer_default_pool();
roctracer::MemoryPool* memory_pool = reinterpret_cast<roctracer::MemoryPool*>(pool);
+2 -1
Просмотреть файл
@@ -18,10 +18,11 @@ export HCC_HOME=$(HCC_PATH)
.PHONY: test
ITERATIONS?=10
all: clean $(EXECUTABLE) test
CXXFLAGS =-g -I$(ROOT_PATH) -I$(ROOT_PATH)/inc
CXXFLAGS =-g -I$(ROOT_PATH) -I$(ROOT_PATH)/inc -DITERATIONS=$(ITERATIONS)
CXX=$(HIPCC)
+14 -28
Просмотреть файл
@@ -25,7 +25,9 @@ THE SOFTWARE.
// hip header file
#include <hip/hip_runtime.h>
#define ITERATIONS 1
#ifndef ITERATIONS
# define ITERATIONS 100
#endif
#define WIDTH 1024
@@ -148,13 +150,6 @@ int main() {
} \
} while (0)
struct ihipModuleSymbol_t {
uint64_t _object; // The kernel object.
uint32_t _groupSegmentSize;
uint32_t _privateSegmentSize;
std::string _name; // TODO - review for performance cost. Name is just used for debug.
};
// HIP API callback function
extern "C" void hip_api_callback(
uint32_t domain,
@@ -165,7 +160,7 @@ extern "C" void hip_api_callback(
(void)arg;
const hip_cb_data_t* data = reinterpret_cast<const hip_cb_data_t*>(callback_data);
fprintf(stdout, "<%s id(%u)\tcorrelation_id(%lu) %s> ",
roctracer_get_api_name(ROCTRACER_API_DOMAIN_HIP, cid),
roctracer_id_string(ROCTRACER_DOMAIN_HIP_API, cid),
cid,
data->correlation_id,
(data->phase == ROCTRACER_API_PHASE_ENTER) ? "on-enter" : "on-exit");
@@ -189,7 +184,7 @@ extern "C" void hip_api_callback(
break;
case HIP_API_ID_hipModuleLaunchKernel:
fprintf(stdout, "kernel(\"%s\") stream(%p)",
data->args.hipModuleLaunchKernel.f->_name.c_str(),
hipKernelNameRef(data->args.hipModuleLaunchKernel.f),
data->args.hipModuleLaunchKernel.stream);
break;
case HIP_API_ID_hipLaunchKernel:
@@ -222,13 +217,10 @@ extern "C" void hip_api_callback(
// hipMalloc id(3) correlation_id(1): begin_ns(1525888652762640464) end_ns(1525888652762877067)
void activity_callback(const char* begin, const char* end, void* arg) {
const roctracer_record_t* record = reinterpret_cast<const roctracer_record_t*>(begin);
const roctracer_record_t* next = NULL;
ROCTRACER_CALL(roctracer_next_record(record, &next));
const roctracer_record_t* end_record = reinterpret_cast<const roctracer_record_t*>(end);
fprintf(stdout, "\tActivity records:\n"); fflush(stdout);
while (reinterpret_cast<const char*>(next) <= end) {
const char * name = (record->op_id == 0) ?
roctracer_get_api_name(ROCTRACER_API_DOMAIN_HIP, record->activity_kind) :
roctracer_get_activity_name(ROCTRACER_API_DOMAIN_HIP, record->activity_kind);
while (record < end_record) {
const char * name = roctracer_id_string(record->domain, record->activity_kind);
fprintf(stdout, "\t%s op(%u) id(%u)\tcorrelation_id(%lu) time_ns(%lu:%lu)",
name,
record->op_id,
@@ -244,28 +236,22 @@ void activity_callback(const char* begin, const char* end, void* arg) {
}
fprintf(stdout, "\n");
fflush(stdout);
record = next;
ROCTRACER_CALL(roctracer_next_record(record, &next));
ROCTRACER_CALL(roctracer_next_record(record, &record));
}
}
// Initialize function
void init_tracing() {
// Check tracer domains consitency
ROCTRACER_CALL(roctracer_validate_domains());
// Enable HIP API callbacks
ROCTRACER_CALL(roctracer_enable_api_callback(ROCTRACER_API_DOMAIN_HIP, HIP_API_ID_hipMemcpy, hip_api_callback, NULL));
ROCTRACER_CALL(roctracer_enable_api_callback(ROCTRACER_API_DOMAIN_HIP, HIP_API_ID_hipMalloc, hip_api_callback, NULL));
ROCTRACER_CALL(roctracer_enable_api_callback(ROCTRACER_API_DOMAIN_HIP, HIP_API_ID_hipFree, hip_api_callback, NULL));
ROCTRACER_CALL(roctracer_enable_api_callback(ROCTRACER_API_DOMAIN_HIP, HIP_API_ID_hipModuleLaunchKernel, hip_api_callback, NULL));
ROCTRACER_CALL(roctracer_enable_api_callback(ROCTRACER_DOMAIN_ANY, 0, hip_api_callback, NULL));
// Enable HIP activity tracing
roctracer_properties_t properties{};
properties.buffer_size = 16;
properties.buffer_size = 8;
properties.buffer_callback_fun = activity_callback;
ROCTRACER_CALL(roctracer_open_pool(&properties));
ROCTRACER_CALL(roctracer_enable_api_activity(ROCTRACER_API_DOMAIN_HIP, HIP_API_ID_hipMemcpy));
ROCTRACER_CALL(roctracer_enable_api_activity(ROCTRACER_API_DOMAIN_HIP, HIP_API_ID_hipMalloc));
ROCTRACER_CALL(roctracer_enable_api_activity(ROCTRACER_API_DOMAIN_HIP, HIP_API_ID_hipFree));
ROCTRACER_CALL(roctracer_enable_api_activity(ROCTRACER_API_DOMAIN_HIP, HIP_API_ID_hipModuleLaunchKernel));
ROCTRACER_CALL(roctracer_enable_api_activity(ROCTRACER_DOMAIN_ANY, 0));
}
void finish_tracing() {