From 1e9061fe56087e078a19520bbbe9d8c71f3e84d1 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Fri, 30 Aug 2019 08:53:34 -0500 Subject: [PATCH] roctx marka implementation [ROCm/roctracer commit: 231e25747f1ad94e1bcd2adb207d9a55102007ae] --- projects/roctracer/cmake_modules/env.cmake | 12 +- projects/roctracer/inc/cb_table.h | 76 +++++++++++ projects/roctracer/inc/ext/prof_protocol.h | 9 +- projects/roctracer/inc/roctracer.h | 1 + projects/roctracer/inc/roctracer_hsa.h | 33 +---- projects/roctracer/inc/roctracer_roctx.h | 84 ++++++++++++ projects/roctracer/inc/roctx.h | 75 +++++++++++ projects/roctracer/src/CMakeLists.txt | 1 + projects/roctracer/src/core/roctracer.cpp | 16 ++- projects/roctracer/src/roctx/roctx.cpp | 124 +++++++++++++++++- .../roctracer/src/roctx/roctx_intercept.cpp | 52 ++++++++ projects/roctracer/src/util/logger.h | 1 + 12 files changed, 445 insertions(+), 39 deletions(-) create mode 100644 projects/roctracer/inc/cb_table.h create mode 100644 projects/roctracer/inc/roctracer_roctx.h create mode 100644 projects/roctracer/inc/roctx.h create mode 100644 projects/roctracer/src/roctx/roctx_intercept.cpp diff --git a/projects/roctracer/cmake_modules/env.cmake b/projects/roctracer/cmake_modules/env.cmake index db8ed9d7eb..bac88715a2 100644 --- a/projects/roctracer/cmake_modules/env.cmake +++ b/projects/roctracer/cmake_modules/env.cmake @@ -65,8 +65,16 @@ if ( NOT DEFINED CMAKE_PREFIX_PATH AND DEFINED ENV{CMAKE_PREFIX_PATH} ) set ( CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH} ) endif() -set ( HCC_INC_DIR "$ENV{HCC_HOME}/include" ) -set ( HIP_INC_DIR "$ENV{HIP_PATH}/include" ) +set ( HCC_HOME "/opt/rocm/hcc" ) +set ( HIP_PATH "/opt/rocm/hip" ) +if ( DEFINED ENV{HCC_HOME} ) + set ( HCC_HOME ENV{HCC_HOME} ) +endif() +if ( DEFINED ENV{HIP_PATH} ) + set ( HIP_PATH ENV{HIP_PATH} ) +endif() +set ( HCC_INC_DIR "${HCC_HOME}/include" ) +set ( HIP_INC_DIR "${HIP_PATH}/include" ) ## Extend Compiler flags based on build type string ( TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE ) diff --git a/projects/roctracer/inc/cb_table.h b/projects/roctracer/inc/cb_table.h new file mode 100644 index 0000000000..5d10f5b8ba --- /dev/null +++ b/projects/roctracer/inc/cb_table.h @@ -0,0 +1,76 @@ +/* +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. +*/ + +#ifndef CB_TABLE_H_ +#define CB_TABLE_H_ + +#include "ext/prof_protocol.h" + +#include + +namespace roctracer { + +// Generic callbacks table +template +class CbTable { + public: + typedef std::mutex mutex_t; + + CbTable() { + std::lock_guard lck(mutex_); + for (int i = 0; i < N; i++) { + callback_[i] = NULL; + arg_[i] = NULL; + } + } + + bool set(uint32_t id, activity_rtapi_callback_t callback, void* arg) { + std::lock_guard lck(mutex_); + bool ret = false; + if (id < N) { + callback_[id] = callback; + arg_[id] = arg; + ret = true; + } + return ret; + } + + bool get(uint32_t id, activity_rtapi_callback_t* callback, void** arg) { + std::lock_guard lck(mutex_); + bool ret = false; + if (id < N) { + *callback = callback_[id]; + *arg = arg_[id]; + ret = true; + } + return ret; + } + + private: + activity_rtapi_callback_t callback_[N]; + void* arg_[N]; + mutex_t mutex_; +}; + +} // namespace roctracer + +#endif // CB_TALE_H_ diff --git a/projects/roctracer/inc/ext/prof_protocol.h b/projects/roctracer/inc/ext/prof_protocol.h index d59343d623..d4b2567021 100644 --- a/projects/roctracer/inc/ext/prof_protocol.h +++ b/projects/roctracer/inc/ext/prof_protocol.h @@ -23,13 +23,16 @@ THE SOFTWARE. #ifndef INC_EXT_PROF_PROTOCOL_H_ #define INC_EXT_PROF_PROTOCOL_H_ +#include + // Traced API domains typedef enum { - ACTIVITY_DOMAIN_HSA_API = 0, // HSA domain + ACTIVITY_DOMAIN_HSA_API = 0, // HSA API domain ACTIVITY_DOMAIN_HSA_OPS = 1, // HSA async activity domain ACTIVITY_DOMAIN_HCC_OPS = 2, // HCC async activity domain - ACTIVITY_DOMAIN_HIP_API = 3, // HIP domain - ACTIVITY_DOMAIN_NUMBER = 4 + ACTIVITY_DOMAIN_HIP_API = 3, // HIP API domain + ACTIVITY_DOMAIN_ROCTX = 4, // ROCTX domain + ACTIVITY_DOMAIN_NUMBER } activity_domain_t; // API calback type diff --git a/projects/roctracer/inc/roctracer.h b/projects/roctracer/inc/roctracer.h index 04cd586d88..7ac5a23bb2 100644 --- a/projects/roctracer/inc/roctracer.h +++ b/projects/roctracer/inc/roctracer.h @@ -64,6 +64,7 @@ typedef enum { ROCTRACER_STATUS_BAD_PARAMETER = 5, ROCTRACER_STATUS_HIP_API_ERR = 6, ROCTRACER_STATUS_HCC_OPS_ERR = 7, + ROCTRACER_STATUS_ROCTX_ERR = 8, } roctracer_status_t; //////////////////////////////////////////////////////////////////////////////// diff --git a/projects/roctracer/inc/roctracer_hsa.h b/projects/roctracer/inc/roctracer_hsa.h index f7944d2a8f..c01253e79f 100644 --- a/projects/roctracer/inc/roctracer_hsa.h +++ b/projects/roctracer/inc/roctracer_hsa.h @@ -29,7 +29,7 @@ THE SOFTWARE. #include #include -#include "ext/prof_protocol.h" +#include "cb_table.h" #include "roctracer.h" namespace roctracer { @@ -38,37 +38,6 @@ enum { HSA_OP_ID_async_copy = 0 }; -template -class CbTable { - public: - typedef std::mutex mutex_t; - - CbTable() { - std::lock_guard lck(mutex_); - for (int i = 0; i < N; i++) { - callback_[i] = NULL; - arg_[i] = NULL; - } - } - - void set(uint32_t id, activity_rtapi_callback_t callback, void* arg) { - std::lock_guard lck(mutex_); - callback_[id] = callback; - arg_[id] = arg; - } - - void get(uint32_t id, activity_rtapi_callback_t* callback, void** arg) { - std::lock_guard lck(mutex_); - *callback = callback_[id]; - *arg = arg_[id]; - } - - private: - activity_rtapi_callback_t callback_[N]; - void* arg_[N]; - mutex_t mutex_; -}; - extern CoreApiTable CoreApiTable_saved; extern AmdExtTable AmdExtTable_saved; extern ImageExtTable ImageExtTable_saved; diff --git a/projects/roctracer/inc/roctracer_roctx.h b/projects/roctracer/inc/roctracer_roctx.h new file mode 100644 index 0000000000..aaa95703db --- /dev/null +++ b/projects/roctracer/inc/roctracer_roctx.h @@ -0,0 +1,84 @@ +/* +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. +*/ + +//////////////////////////////////////////////////////////////////////////////// +// +// ROC-TX API +// +// ROC-TX library, Code Annotation API. +// The goal of the implementation is to provide functionality for annotating +// events, code ranges, and resources in applications. +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INC_ROCTRACER_ROCTX_H_ +#define INC_ROCTRACER_ROCTX_H_ + +#include "cb_table.h" + +// ROC-TX API ID enumeration +enum roctx_api_id_t { + ROCTX_API_ID_roctxMarkA = 0, + ROCTX_API_ID_roctxRangePushA = 1, + ROCTX_API_ID_roctxRangePop = 2, + + ROCTX_API_ID_NUMBER, +}; + +// ROCTX callbacks data type +struct roctx_api_data_t { + union { + const char* message; + struct { + const char* message; + } roctxMarkA; + struct { + const char* message; + } roctxRangePushA; + struct { + const char* message; + } roctxRangePop; + } args; +}; + +namespace roctx { + +// ROCTX callbacks table type +typedef roctracer::CbTable cb_table_t; + +} // namespace roctx + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Regiter ROCTX callback for given opertaion id +bool RegisterApiCallback(uint32_t op, void* callback, void* arg); + +// Remove ROCTX callback for given opertaion id +bool RemoveApiCallback(uint32_t op); + +#ifdef __cplusplus +} // extern "C" block +#endif // __cplusplus + +#endif // INC_ROCTRACER_ROCTX_H_ diff --git a/projects/roctracer/inc/roctx.h b/projects/roctracer/inc/roctx.h new file mode 100644 index 0000000000..fd1686edcf --- /dev/null +++ b/projects/roctracer/inc/roctx.h @@ -0,0 +1,75 @@ +/* +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. +*/ + +//////////////////////////////////////////////////////////////////////////////// +// +// ROC-TX API +// +// ROC-TX library, Code Annotation API. +// The goal of the implementation is to provide functionality for annotating +// events, code ranges, and resources in applications. +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INC_ROCTX_H_ +#define INC_ROCTX_H_ + +#include + +#define ROCTX_VERSION_MAJOR 1 +#define ROCTX_VERSION_MINOR 0 + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +//////////////////////////////////////////////////////////////////////////////// +// Returning library version +uint32_t roctx_version_major(); +uint32_t roctx_version_minor(); + +//////////////////////////////////////////////////////////////////////////////// +// Returning the last error +const char* roctracer_error_string(); + +//////////////////////////////////////////////////////////////////////////////// +// Markers annotating API + +// A marker created by given ASCII massage +void roctxMarkA(const char* message); + +//////////////////////////////////////////////////////////////////////////////// +// Ranges annotating API + +// Returns the 0 based level of a nested range being started by given message associated to this range. +// A negative value is returned on the error. +int roctxRangePushA(const char* message); + +// Marks the end of a nested range. +// A negative value is returned on the error. +int roctxRangePop(); + +#ifdef __cplusplus +} // extern "C" block +#endif // __cplusplus + +#endif // INC_ROCTX_H_ diff --git a/projects/roctracer/src/CMakeLists.txt b/projects/roctracer/src/CMakeLists.txt index 37b2654a44..2418ba53a8 100644 --- a/projects/roctracer/src/CMakeLists.txt +++ b/projects/roctracer/src/CMakeLists.txt @@ -30,6 +30,7 @@ add_custom_command ( 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} ${HSA_RUNTIME_HSA_INC_PATH} ) diff --git a/projects/roctracer/src/core/roctracer.cpp b/projects/roctracer/src/core/roctracer.cpp index 5bac30949f..40e401c430 100644 --- a/projects/roctracer/src/core/roctracer.cpp +++ b/projects/roctracer/src/core/roctracer.cpp @@ -23,6 +23,7 @@ THE SOFTWARE. #include "inc/roctracer.h" #include "inc/roctracer_hcc.h" #include "inc/roctracer_hip.h" +#include "inc/roctracer_roctx.h" #define PROF_API_IMPL 1 #include "inc/roctracer_hsa.h" @@ -651,6 +652,7 @@ static inline uint32_t get_op_num(const uint32_t& domain) { case ACTIVITY_DOMAIN_HSA_API: return HSA_API_ID_NUMBER; case ACTIVITY_DOMAIN_HCC_OPS: return hc::HSA_OP_ID_NUMBER; case ACTIVITY_DOMAIN_HIP_API: return HIP_API_ID_NUMBER; + case ACTIVITY_DOMAIN_ROCTX: return ROCTX_API_ID_NUMBER; default: EXC_RAISING(ROCTRACER_STATUS_BAD_DOMAIN, "invalid domain ID(" << domain << ")"); } @@ -680,7 +682,12 @@ static void roctracer_enable_callback_impl( case ACTIVITY_DOMAIN_HCC_OPS: break; case ACTIVITY_DOMAIN_HIP_API: { hipError_t hip_err = roctracer::HipLoader::Instance().RegisterApiCallback(op, (void*)callback, user_data); - if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRegisterApiCallback error(" << hip_err << ")"); + if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRegisterApiCallback(" << op << ") error(" << hip_err << ")"); + break; + } + case ACTIVITY_DOMAIN_ROCTX: { + const bool suc = roctracer::RocTxLoader::Instance().RegisterApiCallback(op, (void*)callback, user_data); + if (suc == false) EXC_RAISING(ROCTRACER_STATUS_ROCTX_ERR, "roctxRegisterApiCallback(" << op << ") failed"); break; } default: @@ -743,6 +750,11 @@ static void roctracer_disable_callback_impl( if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRemoveApiCallback error(" << hip_err << ")"); break; } + case ACTIVITY_DOMAIN_ROCTX: { + const bool suc = roctracer::RocTxLoader::Instance().RemoveApiCallback(op); + if (suc == false) EXC_RAISING(ROCTRACER_STATUS_ROCTX_ERR, "roctxRemoveApiCallback(" << op << ") failed"); + break; + } default: EXC_RAISING(ROCTRACER_STATUS_BAD_DOMAIN, "invalid domain ID(" << domain << ")"); } @@ -841,6 +853,7 @@ static void roctracer_enable_activity_impl( if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRegisterActivityCallback error(" << hip_err << ")"); break; } + case ACTIVITY_DOMAIN_ROCTX: break; default: EXC_RAISING(ROCTRACER_STATUS_BAD_DOMAIN, "invalid domain ID(" << domain << ")"); } @@ -899,6 +912,7 @@ static void roctracer_disable_activity_impl( if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "hipRemoveActivityCallback error(" << hip_err << ")"); break; } + case ACTIVITY_DOMAIN_ROCTX: break; default: EXC_RAISING(ROCTRACER_STATUS_BAD_DOMAIN, "invalid domain ID(" << domain << ")"); } diff --git a/projects/roctracer/src/roctx/roctx.cpp b/projects/roctracer/src/roctx/roctx.cpp index 755ac3635d..1799b17910 100644 --- a/projects/roctracer/src/roctx/roctx.cpp +++ b/projects/roctracer/src/roctx/roctx.cpp @@ -1,5 +1,127 @@ +/* +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 + +#include "inc/ext/prof_protocol.h" +#include "util/exception.h" +#include "util/logger.h" + +#define PUBLIC_API __attribute__((visibility("default"))) +#define CONSTRUCTOR_API __attribute__((constructor)) +#define DESTRUCTOR_API __attribute__((destructor)) + +#define API_METHOD_PREFIX \ + roctx_status_t err = ROCTX_STATUS_SUCCESS; \ + try { + +#define API_METHOD_SUFFIX \ + } \ + catch (std::exception & e) { \ + ERR_LOGGING(__FUNCTION__ << "(), " << e.what()); \ + err = roctx::GetExcStatus(e); \ + } \ + return (err == ROCTX_STATUS_SUCCESS) ? 0 : -1; + +#define API_METHOD_SUFFIX_NRET \ + } \ + catch (std::exception & e) { \ + ERR_LOGGING(__FUNCTION__ << "(), " << e.what()); \ + err = roctx::GetExcStatus(e); \ + } \ + (void)err; \ + +#define API_METHOD_CATCH(X) \ + } \ + catch (std::exception & e) { \ + ERR_LOGGING(__FUNCTION__ << "(), " << e.what()); \ + } \ + (void)err; \ + return X; + +static inline uint32_t GetPid() { return syscall(__NR_getpid); } +static inline uint32_t GetTid() { return syscall(__NR_gettid); } + +//////////////////////////////////////////////////////////////////////////////// +// Library errors enumaration +typedef enum { + ROCTX_STATUS_SUCCESS = 0, + ROCTX_STATUS_ERROR = 1, +} roctx_status_t; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Library implementation +// namespace roctx { -void fun() {} +roctx_status_t GetExcStatus(const std::exception& e) { + const roctracer::util::exception* roctx_exc_ptr = dynamic_cast(&e); + return (roctx_exc_ptr) ? static_cast(roctx_exc_ptr->status()) : ROCTX_STATUS_ERROR; +} +// callbacks table +extern cb_table_t cb_table; } // namespace roctx + +// Logger instantiation +roctracer::util::Logger::mutex_t roctracer::util::Logger::mutex_; +std::atomic roctracer::util::Logger::instance_{}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Public library methods +// +extern "C" { + +PUBLIC_API uint32_t roctx_version_major() { return ROCTX_VERSION_MAJOR; } +PUBLIC_API uint32_t roctx_version_minor() { return ROCTX_VERSION_MINOR; } + +PUBLIC_API const char* roctracer_error_string() { + return strdup(roctracer::util::Logger::LastMessage().c_str()); +} + +PUBLIC_API void roctxMarkA(const char* message) { + API_METHOD_PREFIX + roctx_api_data_t api_data{}; + 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); + if (api_callback_fun) api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxMarkA, &api_data, api_callback_arg); + API_METHOD_SUFFIX_NRET +} + +PUBLIC_API int roctxRangePushA(const char* message) { + API_METHOD_PREFIX + EXC_ABORT(ROCTX_STATUS_ERROR, "method is not implemented"); + API_METHOD_SUFFIX +} + +PUBLIC_API int roctxRangePop() { + API_METHOD_PREFIX + EXC_ABORT(ROCTX_STATUS_ERROR, "method is not implemented"); + API_METHOD_SUFFIX +} + +} // extern "C" diff --git a/projects/roctracer/src/roctx/roctx_intercept.cpp b/projects/roctracer/src/roctx/roctx_intercept.cpp new file mode 100644 index 0000000000..f5cfdf7669 --- /dev/null +++ b/projects/roctracer/src/roctx/roctx_intercept.cpp @@ -0,0 +1,52 @@ +/* +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(callback), arg); +} + +PUBLIC_API bool RemoveApiCallback(uint32_t op) { + return roctx::cb_table.set(op, NULL, NULL); +} + +} // extern "C" diff --git a/projects/roctracer/src/util/logger.h b/projects/roctracer/src/util/logger.h index 5ed90c4a50..42539e7127 100644 --- a/projects/roctracer/src/util/logger.h +++ b/projects/roctracer/src/util/logger.h @@ -32,6 +32,7 @@ THE SOFTWARE. #include #include +#include #include #include #include