Dosyalar
rocm-systems/hipamd/src/hip_prof_api.h
T
Laurent Morichetti 82bce811ee SWDEV-351980 - Consolidate registration tables in the roctracer library
Remove the api_callbacks_table_t that was holding the API activities and
user callbacks. Instead use a single roctracer callback (TracerCallback)
used to report both API activities and callbacks.

Remove the hipInitActivityCallback that was setting the ROCtracer
callback and memory pool for asynchronous activities as it did not
allow disctinct pools to be used for each activity.  Instead, use
hipRegisterTracerCallback to set the single roctracer callback.

Change-Id: I4c10f04f29a6e4cce8caf15db3016c3f72c86b04
2022-09-21 02:41:39 -04:00

99 satır
3.5 KiB
C++

/* Copyright (c) 2019 - 2021 Advanced Micro Devices, Inc.
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. */
#ifndef HIP_SRC_HIP_PROF_API_H
#define HIP_SRC_HIP_PROF_API_H
#include <atomic>
#include <cassert>
#include <iostream>
#include <shared_mutex>
#include <utility>
#if USE_PROF_API
#include "hip/amd_detail/hip_prof_str.h"
#include "platform/prof_protocol.h"
struct hip_api_trace_data_t {
hip_api_data_t api_data;
uint64_t phase_enter_timestamp;
uint64_t phase_data;
void (*phase_enter)(hip_api_id_t operation_id, hip_api_trace_data_t* data);
void (*phase_exit)(hip_api_id_t operation_id, hip_api_trace_data_t* data);
};
// HIP API callbacks spawner object macro
#define HIP_CB_SPAWNER_OBJECT(operation_id) \
api_callbacks_spawner_t<HIP_API_ID_##operation_id> __api_tracer( \
[=](auto& api_data) { INIT_CB_ARGS_DATA(operation_id, api_data); });
template <hip_api_id_t operation_id> class api_callbacks_spawner_t {
public:
template <typename Functor> api_callbacks_spawner_t(Functor init_cb_args_data) {
static_assert(operation_id >= HIP_API_ID_FIRST && operation_id <= HIP_API_ID_LAST,
"invalid HIP_API operation id");
if (auto function = activity_prof::report_activity.load(std::memory_order_relaxed); function &&
(enabled_ = function(ACTIVITY_DOMAIN_HIP_API, operation_id, &trace_data_) == 0)) {
activity_prof::correlation_id = trace_data_.api_data.correlation_id;
if (trace_data_.phase_enter != nullptr) {
init_cb_args_data(trace_data_.api_data);
trace_data_.phase_enter(operation_id, &trace_data_);
}
}
}
~api_callbacks_spawner_t() {
if (enabled_) {
if (trace_data_.phase_exit != nullptr) trace_data_.phase_exit(operation_id, &trace_data_);
activity_prof::correlation_id = 0;
}
}
private:
bool enabled_{false};
union {
hip_api_trace_data_t trace_data_;
};
};
template <> class api_callbacks_spawner_t<HIP_API_ID_NONE> {
public:
template <typename Functor> api_callbacks_spawner_t(Functor) {}
};
#else
#define HIP_CB_SPAWNER_OBJECT(x) \
do { \
} while (false)
class api_callbacks_table_t {
public:
bool set_activity(hip_api_id_t, activity_sync_callback_t, void*) { return false; }
bool set_callback(hip_api_id_t, activity_rtapi_callback_t, void*) { return false; }
};
#endif
#endif // HIP_SRC_HIP_PROF_API_H