@@ -85,13 +85,13 @@ typedef activity_domain_t roctracer_domain_t;
|
||||
// Return ID string by given domain and activity/API ID
|
||||
// NULL returned on the error and the library errno is set
|
||||
const char* roctracer_id_string(
|
||||
const uint32_t& domain, // API domain
|
||||
const uint32_t& cid); // API call ID
|
||||
const uint32_t& domain, // tracing domain
|
||||
const uint32_t& id); // activity ID
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Callback API
|
||||
//
|
||||
// ROC profiler frontend provides support for runtime API callbacks and activity
|
||||
// ROC tracer provides support for runtime API callbacks and activity
|
||||
// records logging. The API callbacks provide the API calls arguments and are
|
||||
// called on different phases, on enter, on exit, on kernel completion.
|
||||
// Methods return non-zero on error and library errno is set.
|
||||
@@ -100,15 +100,17 @@ typedef activity_rtapi_callback_t roctracer_rtapi_callback_t;
|
||||
|
||||
// Enable runtime API callbacks
|
||||
roctracer_status_t roctracer_enable_api_callback(
|
||||
activity_domain_t domain, // runtime API domain
|
||||
uint32_t cid, // API call ID
|
||||
activity_rtapi_callback_t callback, // callback function pointer
|
||||
void* arg); // [in/out] callback arg
|
||||
activity_domain_t domain, // runtime API domain
|
||||
uint32_t kind, // API kind
|
||||
uint32_t id, // API call ID
|
||||
activity_rtapi_callback_t callback, // callback function pointer
|
||||
void* arg); // [in/out] callback arg
|
||||
|
||||
// Disable runtime API callbacks
|
||||
roctracer_status_t roctracer_disable_api_callback(
|
||||
activity_domain_t domain, // runtime API domain
|
||||
uint32_t cid); // API call ID
|
||||
activity_domain_t domain, // runtime API domain
|
||||
uint32_t kind, // API kind
|
||||
uint32_t id); // API call ID
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Activity API
|
||||
@@ -124,8 +126,8 @@ typedef activity_record_t roctracer_record_t;
|
||||
|
||||
// Return next record
|
||||
static inline int roctracer_next_record(
|
||||
const activity_record_t* record, // [in] record ptr
|
||||
const activity_record_t** next) // [out] next record ptr
|
||||
const activity_record_t* record, // [in] record ptr
|
||||
const activity_record_t** next) // [out] next record ptr
|
||||
{
|
||||
*next = record + 1;
|
||||
return ROCTRACER_STATUS_SUCCESS;
|
||||
@@ -133,24 +135,24 @@ static inline int roctracer_next_record(
|
||||
|
||||
// Tracer allocator type
|
||||
typedef void (*roctracer_allocator_t)(
|
||||
char** ptr, // memory pointer
|
||||
size_t size, // memory size
|
||||
void* arg); // allocator arg
|
||||
char** ptr, // memory pointer
|
||||
size_t size, // memory size
|
||||
void* arg); // allocator arg
|
||||
|
||||
// Pool callback type
|
||||
typedef void (*roctracer_buffer_callback_t)(
|
||||
const char* begin, // [in] available buffered trace records
|
||||
const char* end, // [in] end of buffered trace records
|
||||
void* arg); // [in/out] callback arg
|
||||
const char* begin, // [in] available buffered trace records
|
||||
const char* end, // [in] end of buffered trace records
|
||||
void* arg); // [in/out] callback arg
|
||||
|
||||
// Tracer properties
|
||||
typedef struct {
|
||||
uint32_t mode; // roctracer mode
|
||||
size_t buffer_size; // buffer size
|
||||
roctracer_allocator_t alloc_fun; // memory alocator function pointer
|
||||
void* alloc_arg; // memory alocator function pointer
|
||||
roctracer_buffer_callback_t buffer_callback_fun; // tracer record callback function
|
||||
void* buffer_callback_arg; // tracer record callback arg
|
||||
uint32_t mode; // roctracer mode
|
||||
size_t buffer_size; // buffer size
|
||||
roctracer_allocator_t alloc_fun; // memory alocator function pointer
|
||||
void* alloc_arg; // memory alocator function pointer
|
||||
roctracer_buffer_callback_t buffer_callback_fun; // tracer record callback function
|
||||
void* buffer_callback_arg; // tracer record callback arg
|
||||
} roctracer_properties_t;
|
||||
|
||||
// Tracer memory pool type
|
||||
@@ -159,34 +161,36 @@ typedef void roctracer_pool_t;
|
||||
// Create tracer memory pool
|
||||
// The first invocation sets the default 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
|
||||
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
|
||||
roctracer_status_t roctracer_close_pool(
|
||||
roctracer_pool_t* pool = NULL); // [in] memory pool, NULL is a default one
|
||||
roctracer_pool_t* pool = NULL); // [in] memory pool, NULL is a default one
|
||||
|
||||
// Return current default pool
|
||||
// Set new default pool if the argument is not NULL
|
||||
roctracer_pool_t* roctracer_default_pool(
|
||||
roctracer_pool_t* pool = NULL); // [in] new default pool if not NULL
|
||||
roctracer_pool_t* pool = NULL); // [in] new default pool if not NULL
|
||||
|
||||
// Enable activity records logging
|
||||
roctracer_status_t roctracer_enable_api_activity(
|
||||
activity_domain_t domain, // runtime API domain
|
||||
uint32_t activity_kind, // activity kind
|
||||
roctracer_pool_t* pool = NULL); // memory pool, NULL is a default one
|
||||
activity_domain_t domain, // runtime API domain
|
||||
uint32_t kind, // activity kind
|
||||
uint32_t id, // activity ID
|
||||
roctracer_pool_t* pool = NULL); // memory pool, NULL is a default one
|
||||
|
||||
// Disable activity records logging
|
||||
roctracer_status_t roctracer_disable_api_activity(
|
||||
activity_domain_t domain, // runtime API domain
|
||||
uint32_t activity_kind); // activity kind
|
||||
activity_domain_t domain, // runtime API domain
|
||||
uint32_t kind, // activity kind
|
||||
uint32_t id); // activity ID
|
||||
|
||||
// Flush available activity records
|
||||
roctracer_status_t roctracer_flush_api_activity(
|
||||
roctracer_pool_t* pool = NULL); // memory pool, NULL is a default one
|
||||
roctracer_pool_t* pool = NULL); // memory pool, NULL is a default one
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C" block
|
||||
|
||||
@@ -47,9 +47,9 @@ typedef uint64_t activity_correlation_id_t;
|
||||
// Activity record type
|
||||
struct activity_record_t {
|
||||
uint32_t domain; // activity domain id
|
||||
uint32_t op_id; // operation id, dispatch/copy/barrier
|
||||
uint32_t activity_kind; // activity kind
|
||||
activity_correlation_id_t correlation_id; // activity correlation ID
|
||||
uint32_t kind; // activity kind
|
||||
uint32_t activity_id; // activity id
|
||||
activity_correlation_id_t correlation_id; // activity correlation ID
|
||||
uint64_t begin_ns; // host begin timestamp
|
||||
uint64_t end_ns; // host end timestamp
|
||||
int device_id; // device id
|
||||
|
||||
@@ -289,7 +289,7 @@ roctracer_record_t* SyncActivityCallback(
|
||||
if (pool == NULL) EXC_ABORT(ROCTRACER_STATUS_ERROR, "ActivityCallback pool is NULL");
|
||||
if (data->phase == ACTIVITY_API_PHASE_ENTER) {
|
||||
record->domain = ACTIVITY_DOMAIN_HIP_API;
|
||||
record->activity_kind = activity_kind;
|
||||
record->kind = activity_kind;
|
||||
record->begin_ns = timer.timestamp_ns();
|
||||
// Correlation ID generating
|
||||
uint64_t correlation_id = data->correlation_id;
|
||||
@@ -367,17 +367,19 @@ PUBLIC_API const char* roctracer_id_string(const uint32_t& domain, const uint32_
|
||||
// Enable runtime API callbacks
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_api_callback(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t cid,
|
||||
uint32_t kind,
|
||||
uint32_t id,
|
||||
roctracer_rtapi_callback_t callback,
|
||||
void* user_data)
|
||||
{
|
||||
API_METHOD_PREFIX
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_ANY:
|
||||
if (cid != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY and cid != 0");
|
||||
cid = HIP_API_ID_ANY;
|
||||
if (id != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY: id != 0");
|
||||
id = HIP_API_ID_ANY;
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
hipError_t hip_err = hipRegisterApiCallback(cid, (void*)callback, user_data);
|
||||
if (kind != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_HIP_API: kind != 0, not supported");
|
||||
hipError_t hip_err = hipRegisterApiCallback(id, (void*)callback, user_data);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRegisterApiCallback error(" << hip_err << ")");
|
||||
break;
|
||||
}
|
||||
@@ -390,15 +392,17 @@ PUBLIC_API roctracer_status_t roctracer_enable_api_callback(
|
||||
// Enable runtime API callbacks
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_api_callback(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t cid)
|
||||
uint32_t kind,
|
||||
uint32_t id)
|
||||
{
|
||||
API_METHOD_PREFIX
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_ANY:
|
||||
if (cid != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY and cid != 0");
|
||||
cid = HIP_API_ID_ANY;
|
||||
if (id != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY: id != 0");
|
||||
id = HIP_API_ID_ANY;
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
hipError_t hip_err = hipRemoveApiCallback(cid);
|
||||
if (kind != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_HIP_API: kind != 0, not supported");
|
||||
hipError_t hip_err = hipRemoveApiCallback(id);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRemoveApiCallback error(" << hip_err << ")");
|
||||
break;
|
||||
}
|
||||
@@ -448,24 +452,28 @@ PUBLIC_API roctracer_status_t roctracer_close_pool(roctracer_pool_t* pool) {
|
||||
// Enable activity records logging
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_api_activity(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t activity_id,
|
||||
uint32_t kind,
|
||||
uint32_t id,
|
||||
roctracer_pool_t* pool)
|
||||
{
|
||||
API_METHOD_PREFIX
|
||||
if (pool == NULL) pool = roctracer_default_pool();
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_ANY:
|
||||
if (activity_id != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY and activity_id != 0");
|
||||
roctracer_enable_api_activity(ACTIVITY_DOMAIN_HCC_OPS, hc::HSA_OP_ID_ANY, pool);
|
||||
roctracer_enable_api_activity(ACTIVITY_DOMAIN_HIP_API, HIP_API_ID_ANY, pool);
|
||||
if (kind != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY: kind != 0");
|
||||
if (id != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY: id != 0");
|
||||
roctracer_enable_api_activity(ACTIVITY_DOMAIN_HCC_OPS, hc::HSA_OP_ID_ANY, 0, pool);
|
||||
roctracer_enable_api_activity(ACTIVITY_DOMAIN_HIP_API, 0, HIP_API_ID_ANY, pool);
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS: {
|
||||
const bool err = Kalmar::CLAMP::SetActivityCallback(activity_id, (void*)roctracer::AsyncActivityCallback, (void*)pool);
|
||||
if (id != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_HCC_OPS: id != 0, not supported");
|
||||
const bool err = Kalmar::CLAMP::SetActivityCallback(kind, (void*)roctracer::AsyncActivityCallback, (void*)pool);
|
||||
if (err == true) HCC_EXC_RAISING(ROCTRACER_STATUS_HCC_OPS_ERR, "Kalmar::CLAMP::SetActivityCallback error");
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
const hipError_t hip_err = hipRegisterActivityCallback(activity_id, (void*)roctracer::SyncActivityCallback, (void*)pool);
|
||||
if (kind != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_HIP_API: kind != 0, not supported");
|
||||
const hipError_t hip_err = hipRegisterActivityCallback(id, (void*)roctracer::SyncActivityCallback, (void*)pool);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRegisterActivityCallback error(" << hip_err << ")");
|
||||
break;
|
||||
}
|
||||
@@ -478,22 +486,26 @@ PUBLIC_API roctracer_status_t roctracer_enable_api_activity(
|
||||
// Disable activity records logging
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_api_activity(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t activity_id)
|
||||
uint32_t kind,
|
||||
uint32_t id)
|
||||
{
|
||||
API_METHOD_PREFIX
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_ANY:
|
||||
if (activity_id != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY and activity_id != 0");
|
||||
roctracer_disable_api_activity(ACTIVITY_DOMAIN_HCC_OPS, hc::HSA_OP_ID_ANY);
|
||||
roctracer_disable_api_activity(ACTIVITY_DOMAIN_HIP_API, HIP_API_ID_ANY);
|
||||
if (kind != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY: kind != 0");
|
||||
if (id != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_ANY: id != 0");
|
||||
roctracer_disable_api_activity(ACTIVITY_DOMAIN_HCC_OPS, hc::HSA_OP_ID_ANY, 0);
|
||||
roctracer_disable_api_activity(ACTIVITY_DOMAIN_HIP_API, 0, HIP_API_ID_ANY);
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS: {
|
||||
const bool err = Kalmar::CLAMP::SetActivityCallback(activity_id, NULL, NULL);
|
||||
if (id != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_HCC_OPS: id != 0, not supported");
|
||||
const bool err = Kalmar::CLAMP::SetActivityCallback(kind, NULL, NULL);
|
||||
if (err == true) HCC_EXC_RAISING(ROCTRACER_STATUS_HCC_OPS_ERR, "Kalmar::CLAMP::SetActivityCallback(NULL) error");
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
const hipError_t hip_err = hipRemoveActivityCallback(activity_id);
|
||||
if (kind != 0) HIP_EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "DOMAIN_HIP_API: kind != 0, not supported");
|
||||
const hipError_t hip_err = hipRemoveActivityCallback(id);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRemoveActivityCallback error(" << hip_err << ")");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -211,18 +211,16 @@ void activity_callback(const char* begin, const char* end, void* arg) {
|
||||
const roctracer_record_t* end_record = reinterpret_cast<const roctracer_record_t*>(end);
|
||||
fprintf(stdout, "\tActivity records:\n"); fflush(stdout);
|
||||
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) device_id(%d) stream_id(%lu)",
|
||||
const char * name = roctracer_id_string(record->domain, record->activity_id);
|
||||
fprintf(stdout, "\t%s\tcorrelation_id(%lu) time_ns(%lu:%lu) device_id(%d) stream_id(%lu)",
|
||||
name,
|
||||
record->op_id,
|
||||
record->activity_kind,
|
||||
record->correlation_id,
|
||||
record->begin_ns,
|
||||
record->end_ns,
|
||||
record->device_id,
|
||||
record->stream_id
|
||||
);
|
||||
if (record->op_id == hc::HSA_OP_ID_COPY) fprintf(stdout, " bytes(0x%zx)", record->bytes);
|
||||
if (record->kind == hc::HSA_OP_ID_COPY) fprintf(stdout, " bytes(0x%zx)", record->bytes);
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
ROCTRACER_CALL(roctracer_next_record(record, &record));
|
||||
@@ -238,15 +236,15 @@ void start_tracing() {
|
||||
properties.buffer_callback_fun = activity_callback;
|
||||
ROCTRACER_CALL(roctracer_open_pool(&properties));
|
||||
// Enable HIP API callbacks
|
||||
ROCTRACER_CALL(roctracer_enable_api_callback(ACTIVITY_DOMAIN_ANY, 0, hip_api_callback, NULL));
|
||||
ROCTRACER_CALL(roctracer_enable_api_callback(ACTIVITY_DOMAIN_ANY, 0, 0, hip_api_callback, NULL));
|
||||
// Enable HIP activity tracing
|
||||
ROCTRACER_CALL(roctracer_enable_api_activity(ACTIVITY_DOMAIN_ANY, 0));
|
||||
ROCTRACER_CALL(roctracer_enable_api_activity(ACTIVITY_DOMAIN_ANY, 0, 0));
|
||||
}
|
||||
|
||||
// Stop tracing routine
|
||||
void stop_tracing() {
|
||||
ROCTRACER_CALL(roctracer_disable_api_callback(ACTIVITY_DOMAIN_ANY, 0));
|
||||
ROCTRACER_CALL(roctracer_disable_api_activity(ACTIVITY_DOMAIN_ANY, 0));
|
||||
ROCTRACER_CALL(roctracer_disable_api_callback(ACTIVITY_DOMAIN_ANY, 0, 0));
|
||||
ROCTRACER_CALL(roctracer_disable_api_activity(ACTIVITY_DOMAIN_ANY, 0, 0));
|
||||
ROCTRACER_CALL(roctracer_close_pool());
|
||||
std::cout << "# STOP #############################" << std::endl << std::flush;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user