Make roctracer_cb_table.h a private header
Move roctracer_cb_table.h to the src/core directory, as it should not be exposed as a public header, and rename it callback_table.h Change-Id: Ib448cbd32a275df0268d53bd8d1da0bdc9201470
Αυτή η υποβολή περιλαμβάνεται σε:
@@ -53,7 +53,6 @@ target_link_libraries( ${TARGET_LIB} PRIVATE ${HSA_RUNTIME_LIB} c stdc++ )
|
||||
set ( ROCTX_LIB "roctx64" )
|
||||
set ( ROCTX_LIB_SRC
|
||||
${LIB_DIR}/roctx/roctx.cpp
|
||||
${LIB_DIR}/roctx/roctx_intercept.cpp
|
||||
)
|
||||
add_library ( ${ROCTX_LIB} SHARED ${ROCTX_LIB_SRC} )
|
||||
target_include_directories ( ${ROCTX_LIB} PRIVATE ${LIB_DIR} ${ROOT_DIR} ${ROOT_DIR}/inc ${HSA_RUNTIME_INC_PATH} ${GEN_INC_DIR} )
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/* Copyright (c) 2018-2022 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 CALLBACK_TABLE_H_
|
||||
#define CALLBACK_TABLE_H_
|
||||
|
||||
#include <ext/prof_protocol.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
|
||||
namespace roctracer {
|
||||
|
||||
// Generic callbacks table
|
||||
template <uint32_t N> class CallbackTable {
|
||||
public:
|
||||
CallbackTable()
|
||||
// Zero initialize the callbacks array as the function pointer is used to determine if the
|
||||
// callback is enabled.
|
||||
: callbacks_() {}
|
||||
|
||||
void Set(uint32_t id, activity_rtapi_callback_t callback, void* arg) {
|
||||
assert(id < N && "id is out of range");
|
||||
std::lock_guard lock(mutex_);
|
||||
callbacks_[id] = {callback, arg};
|
||||
}
|
||||
|
||||
void Get(uint32_t id, activity_rtapi_callback_t* callback, void** arg) const {
|
||||
assert(id < N && "id is out of range");
|
||||
std::lock_guard lock(mutex_);
|
||||
std::tie(*callback, *arg) = callbacks_[id];
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<std::pair<activity_rtapi_callback_t /* callback */, void* /* arg */>, N> callbacks_;
|
||||
mutable std::mutex mutex_;
|
||||
};
|
||||
|
||||
} // namespace roctracer
|
||||
|
||||
#endif // CALLBACK_TABLE_H_
|
||||
@@ -788,7 +788,8 @@ static roctracer_status_t roctracer_enable_callback_fun(roctracer_domain_t domai
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
roctracer::hsa_support::cb_table.set(op, callback, user_data);
|
||||
if (op >= HSA_API_ID_NUMBER) return ROCTRACER_STATUS_BAD_PARAMETER;
|
||||
roctracer::hsa_support::cb_table.Set(op, callback, user_data);
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HSA_EVT: {
|
||||
@@ -885,7 +886,8 @@ static roctracer_status_t roctracer_disable_callback_fun(roctracer_domain_t doma
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
roctracer::hsa_support::cb_table.set(op, NULL, NULL);
|
||||
if (op >= HSA_API_ID_NUMBER) return ROCTRACER_STATUS_BAD_PARAMETER;
|
||||
roctracer::hsa_support::cb_table.Set(op, NULL, NULL);
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HCC_OPS:
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <stack>
|
||||
|
||||
#include "inc/ext/prof_protocol.h"
|
||||
#include "core/callback_table.h"
|
||||
#include "util/exception.h"
|
||||
#include "util/logger.h"
|
||||
|
||||
@@ -75,6 +76,14 @@ typedef enum {
|
||||
// Library implementation
|
||||
//
|
||||
namespace roctx {
|
||||
|
||||
// ROCTX callbacks table type
|
||||
typedef roctracer::CallbackTable<ROCTX_API_ID_NUMBER> cb_table_t;
|
||||
|
||||
// callbacks table
|
||||
cb_table_t cb_table;
|
||||
|
||||
|
||||
typedef std::stack<std::string> message_stack_t;
|
||||
typedef std::map<uint32_t, message_stack_t*> thread_map_t;
|
||||
typedef std::mutex map_mutex_t;
|
||||
@@ -124,7 +133,7 @@ PUBLIC_API void roctxMarkA(const char* message) {
|
||||
api_data.args.roctxMarkA.message = strdup(message);
|
||||
activity_rtapi_callback_t api_callback_fun = NULL;
|
||||
void* api_callback_arg = NULL;
|
||||
roctx::cb_table.get(ROCTX_API_ID_roctxMarkA, &api_callback_fun, &api_callback_arg);
|
||||
roctx::cb_table.Get(ROCTX_API_ID_roctxMarkA, &api_callback_fun, &api_callback_arg);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxMarkA, &api_data, api_callback_arg);
|
||||
API_METHOD_SUFFIX_NRET
|
||||
@@ -138,7 +147,7 @@ PUBLIC_API int roctxRangePushA(const char* message) {
|
||||
api_data.args.roctxRangePushA.message = strdup(message);
|
||||
activity_rtapi_callback_t api_callback_fun = NULL;
|
||||
void* api_callback_arg = NULL;
|
||||
roctx::cb_table.get(ROCTX_API_ID_roctxRangePushA, &api_callback_fun, &api_callback_arg);
|
||||
roctx::cb_table.Get(ROCTX_API_ID_roctxRangePushA, &api_callback_fun, &api_callback_arg);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangePushA, &api_data,
|
||||
api_callback_arg);
|
||||
@@ -155,7 +164,7 @@ PUBLIC_API int roctxRangePop() {
|
||||
roctx_api_data_t api_data{};
|
||||
activity_rtapi_callback_t api_callback_fun = NULL;
|
||||
void* api_callback_arg = NULL;
|
||||
roctx::cb_table.get(ROCTX_API_ID_roctxRangePop, &api_callback_fun, &api_callback_arg);
|
||||
roctx::cb_table.Get(ROCTX_API_ID_roctxRangePop, &api_callback_fun, &api_callback_arg);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangePop, &api_data,
|
||||
api_callback_arg);
|
||||
@@ -178,7 +187,7 @@ PUBLIC_API roctx_range_id_t roctxRangeStartA(const char* message) {
|
||||
api_data.args.roctxRangeStartA.id = roctx_range_counter;
|
||||
activity_rtapi_callback_t api_callback_fun = NULL;
|
||||
void* api_callback_arg = NULL;
|
||||
roctx::cb_table.get(ROCTX_API_ID_roctxRangeStartA, &api_callback_fun, &api_callback_arg);
|
||||
roctx::cb_table.Get(ROCTX_API_ID_roctxRangeStartA, &api_callback_fun, &api_callback_arg);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangeStartA, &api_data,
|
||||
api_callback_arg);
|
||||
@@ -193,7 +202,7 @@ PUBLIC_API void roctxRangeStop(roctx_range_id_t rangeId) {
|
||||
api_data.args.roctxRangeStop.id = rangeId;
|
||||
activity_rtapi_callback_t api_callback_fun = NULL;
|
||||
void* api_callback_arg = NULL;
|
||||
roctx::cb_table.get(ROCTX_API_ID_roctxRangeStop, &api_callback_fun, &api_callback_arg);
|
||||
roctx::cb_table.Get(ROCTX_API_ID_roctxRangeStop, &api_callback_fun, &api_callback_arg);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangeStop, &api_data,
|
||||
api_callback_arg);
|
||||
@@ -213,4 +222,16 @@ PUBLIC_API void RangeStackIterate(roctx_range_iterate_cb_t callback, void* arg)
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC_API bool RegisterApiCallback(uint32_t op, void* callback, void* arg) {
|
||||
if (op >= ROCTX_API_ID_NUMBER) return false;
|
||||
roctx::cb_table.Set(op, reinterpret_cast<activity_rtapi_callback_t>(callback), arg);
|
||||
return true;
|
||||
}
|
||||
|
||||
PUBLIC_API bool RemoveApiCallback(uint32_t op) {
|
||||
if (op >= ROCTX_API_ID_NUMBER) return false;
|
||||
roctx::cb_table.Get(op, NULL, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "inc/roctx.h"
|
||||
#include "inc/roctracer_roctx.h"
|
||||
#include "util/logger.h"
|
||||
|
||||
#define PUBLIC_API __attribute__((visibility("default")))
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Library implementation
|
||||
//
|
||||
namespace roctx {
|
||||
|
||||
// callbacks table
|
||||
cb_table_t cb_table;
|
||||
|
||||
} // namespace roctx
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Public library methods
|
||||
//
|
||||
extern "C" {
|
||||
|
||||
PUBLIC_API bool RegisterApiCallback(uint32_t op, void* callback, void* arg) {
|
||||
return roctx::cb_table.set(op, reinterpret_cast<activity_rtapi_callback_t>(callback), arg);
|
||||
}
|
||||
|
||||
PUBLIC_API bool RemoveApiCallback(uint32_t op) { return roctx::cb_table.set(op, NULL, NULL); }
|
||||
|
||||
} // extern "C"
|
||||
Αναφορά σε νέο ζήτημα
Block a user