Files
rocm-systems/inc/roctracer.h
T

268 lines
11 KiB
C
Raw Normal View History

2018-08-08 15:47:30 -05:00
/*
Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
2018-05-10 13:19:10 -05:00
////////////////////////////////////////////////////////////////////////////////
//
2018-08-26 19:29:56 -05:00
// ROC Tracer API
2018-05-10 13:19:10 -05:00
//
2018-08-26 19:29:56 -05:00
// ROC-tracer library, Runtimes Generic Callback/Activity APIs.
// The goal of the implementation is to provide a generic independent from
// specific runtime profiler to trace API and asyncronous activity.
2018-05-10 13:19:10 -05:00
//
2018-08-26 19:29:56 -05:00
// The API provides functionality for registering the runtimes API callbacks and
// asyncronous activity records pool support.
2018-05-10 13:19:10 -05:00
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INC_ROCTRACER_H_
#define INC_ROCTRACER_H_
#include <stdint.h>
2018-08-07 03:25:55 -05:00
#include <stddef.h>
2019-12-26 06:40:49 -06:00
#ifndef __cplusplus
#include <stdbool.h>
#endif
2018-05-10 13:19:10 -05:00
#include <ext/prof_protocol.h>
2018-05-10 13:19:10 -05:00
#define ROCTRACER_VERSION_MAJOR 4
2018-05-10 13:19:10 -05:00
#define ROCTRACER_VERSION_MINOR 0
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
////////////////////////////////////////////////////////////////////////////////
// Returning library version
uint32_t roctracer_version_major();
uint32_t roctracer_version_minor();
////////////////////////////////////////////////////////////////////////////////
// Library errors enumaration
typedef enum {
ROCTRACER_STATUS_SUCCESS = 0,
ROCTRACER_STATUS_ERROR = 1,
ROCTRACER_STATUS_UNINIT = 2,
ROCTRACER_STATUS_BREAK = 3,
ROCTRACER_STATUS_BAD_DOMAIN = 4,
2018-06-18 21:43:40 -05:00
ROCTRACER_STATUS_BAD_PARAMETER = 5,
ROCTRACER_STATUS_HIP_API_ERR = 6,
2018-08-07 03:25:55 -05:00
ROCTRACER_STATUS_HCC_OPS_ERR = 7,
2020-01-23 20:55:49 -06:00
ROCTRACER_STATUS_HSA_ERR = 7,
2019-08-30 08:53:34 -05:00
ROCTRACER_STATUS_ROCTX_ERR = 8,
2018-05-10 13:19:10 -05:00
} roctracer_status_t;
////////////////////////////////////////////////////////////////////////////////
// Returning the last error
const char* roctracer_error_string();
////////////////////////////////////////////////////////////////////////////////
2018-11-28 12:36:11 -06:00
// Traced runtime domains
2018-05-10 13:19:10 -05:00
2018-08-07 03:25:55 -05:00
// Activity domain type
typedef activity_domain_t roctracer_domain_t;
2018-05-25 22:39:22 -05:00
2019-03-27 10:34:13 -05:00
// Return Op string by given domain and Op code
2018-05-25 22:39:22 -05:00
// NULL returned on the error and the library errno is set
2019-01-11 22:15:35 -06:00
const char* roctracer_op_string(
2019-01-17 22:39:53 -06:00
uint32_t domain, // tracing domain
uint32_t op, // activity op ID
uint32_t kind); // activity kind
// Return Op code and kind by given string
roctracer_status_t roctracer_op_code(
uint32_t domain, // tracing domain
const char* str, // [in] op string
uint32_t* op, // [out] op code
2019-12-26 06:40:49 -06:00
uint32_t* kind); // [out] op kind code if not NULL
2018-05-10 13:19:10 -05:00
////////////////////////////////////////////////////////////////////////////////
// Callback API
//
2018-08-26 19:11:31 -05:00
// ROC tracer provides support for runtime API callbacks and activity
2018-05-10 13:19:10 -05:00
// 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.
2018-11-28 12:36:11 -06:00
// Runtime API callback type
2018-08-07 03:25:55 -05:00
typedef activity_rtapi_callback_t roctracer_rtapi_callback_t;
2018-05-10 13:19:10 -05:00
// Enable runtime API callbacks
2019-01-11 22:15:35 -06:00
roctracer_status_t roctracer_enable_op_callback(
activity_domain_t domain, // tracing domain
uint32_t op, // API call ID
activity_rtapi_callback_t callback, // callback function pointer
void* arg); // [in/out] callback arg
roctracer_status_t roctracer_enable_domain_callback(
2018-11-28 12:36:11 -06:00
activity_domain_t domain, // tracing domain
2019-01-11 22:15:35 -06:00
activity_rtapi_callback_t callback, // callback function pointer
void* arg); // [in/out] callback arg
roctracer_status_t roctracer_enable_callback(
2018-08-26 19:11:31 -05:00
activity_rtapi_callback_t callback, // callback function pointer
void* arg); // [in/out] callback arg
2018-05-10 13:19:10 -05:00
// Disable runtime API callbacks
2019-01-11 22:15:35 -06:00
roctracer_status_t roctracer_disable_op_callback(
2018-11-28 12:36:11 -06:00
activity_domain_t domain, // tracing domain
2019-01-11 22:15:35 -06:00
uint32_t op); // API call ID
roctracer_status_t roctracer_disable_domain_callback(
activity_domain_t domain); // tracing domain
roctracer_status_t roctracer_disable_callback();
2018-05-10 13:19:10 -05:00
////////////////////////////////////////////////////////////////////////////////
// Activity API
//
// The activity records are asynchronously logged to the pool and can be associated
// with the respective API callbacks using the correlation ID. Activity API can
// be used to enable collecting of the records with timestamping data for API
// calls and the kernel submits.
// Methods return non zero on error and library errno is set.
2018-08-07 03:25:55 -05:00
// Activity record type
typedef activity_record_t roctracer_record_t;
2018-05-10 13:19:10 -05:00
// Return next record
static inline roctracer_status_t roctracer_next_record(
2018-08-26 19:11:31 -05:00
const activity_record_t* record, // [in] record ptr
const activity_record_t** next) // [out] next record ptr
2018-05-10 13:19:10 -05:00
{
2018-08-07 03:25:55 -05:00
*next = record + 1;
2018-05-10 13:19:10 -05:00
return ROCTRACER_STATUS_SUCCESS;
}
// Tracer allocator type
typedef void (*roctracer_allocator_t)(
2018-08-26 19:11:31 -05:00
char** ptr, // memory pointer
size_t size, // memory size
void* arg); // allocator arg
2018-05-10 13:19:10 -05:00
// Pool callback type
typedef void (*roctracer_buffer_callback_t)(
2018-08-26 19:11:31 -05:00
const char* begin, // [in] available buffered trace records
const char* end, // [in] end of buffered trace records
void* arg); // [in/out] callback arg
2018-05-10 13:19:10 -05:00
// Tracer properties
typedef struct {
2018-08-26 19:11:31 -05:00
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
2018-05-10 13:19:10 -05:00
} roctracer_properties_t;
2018-08-07 03:25:55 -05:00
// Tracer memory pool type
typedef void roctracer_pool_t;
2018-05-10 13:19:10 -05:00
// Create tracer memory pool
// The first invocation sets the default pool
2019-12-26 06:40:49 -06:00
roctracer_status_t roctracer_open_pool_expl(
2018-08-26 19:11:31 -05:00
const roctracer_properties_t* properties, // tracer pool properties
2019-12-26 06:40:49 -06:00
roctracer_pool_t** pool); // [out] returns tracer pool if not NULL,
2018-08-26 19:11:31 -05:00
// otherwise sets the default one if it is not set yet
2020-01-13 12:19:04 -06:00
static inline roctracer_status_t roctracer_open_pool(
2019-12-26 06:40:49 -06:00
const roctracer_properties_t* properties) // tracer pool properties
{
return roctracer_open_pool_expl(properties, NULL);
}
2018-08-26 19:11:31 -05:00
// otherwise the error is generated
2018-05-10 13:19:10 -05:00
// Close tracer memory pool
2019-12-26 06:40:49 -06:00
roctracer_status_t roctracer_close_pool_expl(
roctracer_pool_t* pool); // [in] memory pool, NULL is a default one
2020-01-13 12:19:04 -06:00
static inline roctracer_status_t roctracer_close_pool()
2019-12-26 06:40:49 -06:00
{
return roctracer_close_pool_expl(NULL);
}
2018-05-10 13:19:10 -05:00
// Return current default pool
// Set new default pool if the argument is not NULL
2019-12-26 06:40:49 -06:00
roctracer_pool_t* roctracer_default_pool_expl(
roctracer_pool_t* pool); // [in] new default pool if not NULL
2020-01-13 12:19:04 -06:00
static inline roctracer_pool_t* roctracer_default_pool()
2019-12-26 06:40:49 -06:00
{
return roctracer_default_pool_expl(NULL);
}
2018-05-10 13:19:10 -05:00
// Enable activity records logging
2019-12-26 06:40:49 -06:00
roctracer_status_t roctracer_enable_op_activity_expl(
2019-01-11 22:15:35 -06:00
activity_domain_t domain, // tracing domain
uint32_t op, // activity op ID
2019-12-26 06:40:49 -06:00
roctracer_pool_t* pool); // memory pool, NULL is a default one
2020-01-13 12:19:04 -06:00
static inline roctracer_status_t roctracer_enable_op_activity(
2018-11-28 12:36:11 -06:00
activity_domain_t domain, // tracing domain
2019-12-26 06:40:49 -06:00
uint32_t op) // activity op ID
{
return roctracer_enable_op_activity_expl(domain, op, NULL);
}
roctracer_status_t roctracer_enable_domain_activity_expl(
activity_domain_t domain, // tracing domain
roctracer_pool_t* pool); // memory pool, NULL is a default one
2020-01-13 12:19:04 -06:00
static inline roctracer_status_t roctracer_enable_domain_activity(
2019-12-26 06:40:49 -06:00
activity_domain_t domain) // tracing domain
{
return roctracer_enable_domain_activity_expl(domain, NULL);
}
roctracer_status_t roctracer_enable_activity_expl(
roctracer_pool_t* pool); // memory pool, NULL is a default one
2020-01-13 12:19:04 -06:00
static inline roctracer_status_t roctracer_enable_activity()
2019-12-26 06:40:49 -06:00
{
return roctracer_enable_activity_expl(NULL);
}
2018-05-10 13:19:10 -05:00
// Disable activity records logging
2019-01-11 22:15:35 -06:00
roctracer_status_t roctracer_disable_op_activity(
2018-11-28 12:36:11 -06:00
activity_domain_t domain, // tracing domain
2019-01-11 22:15:35 -06:00
uint32_t op); // activity op ID
roctracer_status_t roctracer_disable_domain_activity(
activity_domain_t domain); // tracing domain
roctracer_status_t roctracer_disable_activity();
2018-05-10 13:19:10 -05:00
// Flush available activity records
2019-12-26 06:40:49 -06:00
roctracer_status_t roctracer_flush_activity_expl(
roctracer_pool_t* pool); // memory pool, NULL is a default one
2020-01-13 12:19:04 -06:00
static inline roctracer_status_t roctracer_flush_activity()
2019-12-26 06:40:49 -06:00
{
return roctracer_flush_activity_expl(NULL);
}
2018-05-10 13:19:10 -05:00
2019-12-31 07:05:32 -06:00
// Get system timestamp
roctracer_status_t roctracer_get_timestamp(
uint64_t* timestamp); // [out] return timestamp
// Load/Unload methods
2020-01-27 14:30:44 -06:00
bool roctracer_load();
void roctracer_unload();
2020-06-02 05:10:02 -05:00
void roctracer_flush_buf();
2020-01-27 14:30:44 -06:00
2019-06-24 21:05:12 -05:00
// Set properties
roctracer_status_t roctracer_set_properties(
roctracer_domain_t domain, // tracing domain
void* propertes); // tracing properties
2018-05-10 13:19:10 -05:00
#ifdef __cplusplus
} // extern "C" block
#endif // __cplusplus
#endif // INC_ROCTRACER_H_