roctx marka implementation

Tento commit je obsažen v:
Evgeny
2019-08-30 08:53:34 -05:00
rodič 7a2005c4a0
revize 231e25747f
12 změnil soubory, kde provedl 445 přidání a 39 odebrání
+1
Zobrazit soubor
@@ -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} )
+15 -1
Zobrazit soubor
@@ -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 << ")");
}
+123 -1
Zobrazit soubor
@@ -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 <string.h>
#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<const roctracer::util::exception*>(&e);
return (roctx_exc_ptr) ? static_cast<roctx_status_t>(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*> 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"
+52
Zobrazit soubor
@@ -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<activity_rtapi_callback_t>(callback), arg);
}
PUBLIC_API bool RemoveApiCallback(uint32_t op) {
return roctx::cb_table.set(op, NULL, NULL);
}
} // extern "C"
+1
Zobrazit soubor
@@ -32,6 +32,7 @@ THE SOFTWARE.
#include <stdarg.h>
#include <stdlib.h>
#include <atomic>
#include <string>
#include <iostream>
#include <sstream>