2 #ifndef _HIP_PROF_API_H 3 #define _HIP_PROF_API_H 9 #include "hip/hcc_detail/hip_prof_str.h" 11 template <
typename Record,
typename Fun,
typename Act>
14 typedef std::recursive_mutex mutex_t;
16 typedef Record record_t;
22 volatile std::atomic<bool> sync;
23 volatile std::atomic<uint32_t> sem;
35 memset(&callbacks_table_, 0,
sizeof(callbacks_table_));
38 bool set_activity(uint32_t
id, act_t fun,
void* arg) {
39 std::lock_guard<mutex_t> lock(mutex_);
41 if (
id < HIP_API_ID_NUMBER) {
43 callbacks_table_.arr[id].act = fun;
44 callbacks_table_.arr[id].a_arg = arg;
52 bool set_callback(uint32_t
id, fun_t fun,
void* arg) {
53 std::lock_guard<mutex_t> lock(mutex_);
55 if (
id < HIP_API_ID_NUMBER) {
57 callbacks_table_.arr[id].fun = fun;
58 callbacks_table_.arr[id].arg = arg;
67 return callbacks_table_.arr[id];
70 inline void sem_sync(
const uint32_t&
id) {
72 if (entry(
id).sync.load() ==
true) sync_wait(
id);
75 inline void sem_release(
const uint32_t&
id) {
80 inline void cb_sync(
const uint32_t&
id) {
81 entry(
id).sync.store(
true);
82 while (entry(
id).sem.load() != 0) {}
85 inline void cb_release(
const uint32_t&
id) {
86 entry(
id).sync.store(
false);
89 inline void sem_increment(
const uint32_t&
id) {
90 const uint32_t prev = entry(
id).sem.fetch_add(1);
91 if (prev == UINT32_MAX) {
92 std::cerr <<
"sem overflow id = " <<
id << std::endl << std::flush;
97 inline void sem_decrement(
const uint32_t&
id) {
98 const uint32_t prev = entry(
id).sem.fetch_sub(1);
100 std::cerr <<
"sem corrupted id = " <<
id << std::endl << std::flush;
105 void sync_wait(
const uint32_t&
id) {
107 while (entry(
id).sync.load() ==
true) {}
117 #include <prof_protocol.h> 119 static const uint32_t HIP_DOMAIN_ID = ACTIVITY_DOMAIN_HIP_API;
120 typedef activity_record_t hip_api_record_t;
121 typedef activity_rtapi_callback_t hip_api_callback_t;
122 typedef activity_sync_callback_t hip_act_callback_t;
125 #define HIP_CB_SPAWNER_OBJECT(CB_ID) \ 126 hip_api_data_t api_data{}; \ 127 INIT_CB_ARGS_DATA(CB_ID, api_data); \ 128 api_callbacks_spawner_t<HIP_API_ID_##CB_ID> __api_tracer(HIP_API_ID_##CB_ID, api_data); 136 class api_callbacks_spawner_t {
138 api_callbacks_spawner_t(
const hip_api_id_t& cid,
hip_api_data_t& api_data) :
142 if (cid_ >= HIP_API_ID_NUMBER) {
143 fprintf(stderr,
"HIP %s bad id %d\n", __FUNCTION__, cid_);
146 callbacks_table.sem_sync(cid_);
148 act = entry(cid_).act;
149 a_arg = entry(cid_).a_arg;
150 fun = entry(cid_).fun;
151 arg = entry(cid_).arg;
154 if (act != NULL) act(cid_, &record_, &api_data_, a_arg);
155 if (fun != NULL) fun(HIP_DOMAIN_ID, cid_, &api_data_, arg);
158 ~api_callbacks_spawner_t() {
160 if (act != NULL) act(cid_, &record_, &api_data_, a_arg);
161 if (fun != NULL) fun(HIP_DOMAIN_ID, cid_, &api_data_, arg);
163 callbacks_table.sem_release(cid_);
167 inline api_callbacks_table_t::hip_cb_table_entry_t& entry(
const uint32_t&
id) {
168 return callbacks_table.entry(
id);
172 hip_api_record_t record_;
174 hip_act_callback_t act;
176 hip_api_callback_t fun;
181 class api_callbacks_spawner_t<HIP_API_ID_NUMBER> {
183 api_callbacks_spawner_t(
const hip_api_id_t& cid,
hip_api_data_t& api_data) {}
188 #define HIP_CB_SPAWNER_OBJECT(x) do {} while(0) 194 bool set_activity(uint32_t
id, act_t fun,
void* arg) {
return false; }
195 bool set_callback(uint32_t
id, fun_t fun,
void* arg) {
return false; }
200 #endif // _HIP_PROF_API_H Definition: hip_prof_api.h:21
Definition: hip_prof_api.h:190
Definition: hip_prof_api.h:30
Definition: hip_prof_api.h:12
Definition: hip_prof_str.h:405