Run clang-format on all source files
Change-Id: Ifb52ca306286b6b2d473821bed9db28e9f616d50
Tento commit je obsažen v:
odevzdal
Laurent Morichetti
rodič
89f6880371
revize
15ab5d9cda
@@ -27,7 +27,7 @@ namespace roctracer {
|
||||
enum { API_CB_MASK = 0x1, ACT_CB_MASK = 0x2 };
|
||||
|
||||
class hip_act_cb_tracker_t {
|
||||
private:
|
||||
private:
|
||||
std::map<uint32_t, uint32_t> data;
|
||||
|
||||
public:
|
||||
|
||||
+73
-63
@@ -25,29 +25,29 @@
|
||||
#include <mutex>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#define ONLD_TRACE(str) \
|
||||
if (getenv("ROCP_ONLOAD_TRACE")) do { \
|
||||
std::cout << "PID(" << GetPid() << "): TRACER_LOADER::" << __FUNCTION__ << " " << str << std::endl << std::flush; \
|
||||
} while(0);
|
||||
#define ONLD_TRACE(str) \
|
||||
if (getenv("ROCP_ONLOAD_TRACE")) do { \
|
||||
std::cout << "PID(" << GetPid() << "): TRACER_LOADER::" << __FUNCTION__ << " " << str \
|
||||
<< std::endl \
|
||||
<< std::flush; \
|
||||
} while (0);
|
||||
|
||||
namespace roctracer {
|
||||
|
||||
// Base runtime loader class
|
||||
template <class T>
|
||||
class BaseLoader : public T {
|
||||
template <class T> class BaseLoader : public T {
|
||||
static uint32_t GetPid() { return syscall(__NR_getpid); }
|
||||
|
||||
public:
|
||||
public:
|
||||
typedef std::mutex mutex_t;
|
||||
typedef BaseLoader<T> loader_t;
|
||||
|
||||
bool Enabled() const { return (handle_ != NULL); }
|
||||
|
||||
template <class fun_t>
|
||||
fun_t* GetFun(const char* fun_name) {
|
||||
template <class fun_t> fun_t* GetFun(const char* fun_name) {
|
||||
if (handle_ == NULL) return NULL;
|
||||
|
||||
fun_t *f = (fun_t*) dlsym(handle_, fun_name);
|
||||
fun_t* f = (fun_t*)dlsym(handle_, fun_name);
|
||||
if ((to_check_symb_ == true) && (f == NULL)) {
|
||||
fprintf(stderr, "roctracer: symbol lookup '%s' failed: \"%s\"\n", fun_name, dlerror());
|
||||
abort();
|
||||
@@ -68,11 +68,11 @@ class BaseLoader : public T {
|
||||
}
|
||||
|
||||
static loader_t* GetRef() { return instance_; }
|
||||
static void SetLibName(const char *name) { lib_name_ = name; }
|
||||
static void SetLibName(const char* name) { lib_name_ = name; }
|
||||
|
||||
private:
|
||||
private:
|
||||
BaseLoader() {
|
||||
const int flags = (to_load_ == true) ? RTLD_LAZY : RTLD_LAZY|RTLD_NOLOAD;
|
||||
const int flags = (to_load_ == true) ? RTLD_LAZY : RTLD_LAZY | RTLD_NOLOAD;
|
||||
handle_ = dlopen(lib_name_, flags);
|
||||
ONLD_TRACE("(" << lib_name_ << " = " << handle_ << ")");
|
||||
if ((to_check_open_ == true) && (handle_ == NULL)) {
|
||||
@@ -99,14 +99,14 @@ class BaseLoader : public T {
|
||||
|
||||
// 'rocprofiler' library loader class
|
||||
class RocpApi {
|
||||
public:
|
||||
public:
|
||||
typedef BaseLoader<RocpApi> Loader;
|
||||
|
||||
typedef bool (RegisterCallback_t)(uint32_t op, void* callback, void* arg);
|
||||
typedef bool (OperateCallback_t)(uint32_t op);
|
||||
typedef bool (InitCallback_t)(void* callback, void* arg);
|
||||
typedef bool (EnableCallback_t)(uint32_t op, bool enable);
|
||||
typedef const char* (NameCallback_t)(uint32_t op);
|
||||
typedef bool(RegisterCallback_t)(uint32_t op, void* callback, void* arg);
|
||||
typedef bool(OperateCallback_t)(uint32_t op);
|
||||
typedef bool(InitCallback_t)(void* callback, void* arg);
|
||||
typedef bool(EnableCallback_t)(uint32_t op, bool enable);
|
||||
typedef const char*(NameCallback_t)(uint32_t op);
|
||||
|
||||
RegisterCallback_t* RegisterApiCallback;
|
||||
OperateCallback_t* RemoveApiCallback;
|
||||
@@ -118,7 +118,7 @@ class RocpApi {
|
||||
OperateCallback_t* RemoveEvtCallback;
|
||||
NameCallback_t* GetEvtName;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void init(Loader* loader) {
|
||||
RegisterApiCallback = loader->GetFun<RegisterCallback_t>("RegisterApiCallback");
|
||||
RemoveApiCallback = loader->GetFun<OperateCallback_t>("RemoveApiCallback");
|
||||
@@ -134,29 +134,36 @@ class RocpApi {
|
||||
|
||||
// HIP runtime library loader class
|
||||
#if STATIC_BUILD
|
||||
__attribute__((weak)) hipError_t hipRegisterApiCallback(uint32_t id, void* fun, void* arg) { return hipErrorUnknown; }
|
||||
__attribute__((weak)) hipError_t hipRegisterApiCallback(uint32_t id, void* fun, void* arg) {
|
||||
return hipErrorUnknown;
|
||||
}
|
||||
__attribute__((weak)) hipError_t hipRemoveApiCallback(uint32_t id) { return hipErrorUnknown; }
|
||||
__attribute__((weak)) hipError_t hipRegisterActivityCallback(uint32_t id, void* fun, void* arg) { return hipErrorUnknown; }
|
||||
__attribute__((weak)) hipError_t hipRegisterActivityCallback(uint32_t id, void* fun, void* arg) {
|
||||
return hipErrorUnknown;
|
||||
}
|
||||
__attribute__((weak)) hipError_t hipRemoveActivityCallback(uint32_t id) { return hipErrorUnknown; }
|
||||
__attribute__((weak)) const char* hipKernelNameRef(const hipFunction_t f) { return NULL; }
|
||||
__attribute__((weak)) const char* hipKernelNameRefByPtr(const void* hostFunction, hipStream_t stream) { return NULL; }
|
||||
__attribute__((weak)) const char* hipKernelNameRefByPtr(const void* hostFunction,
|
||||
hipStream_t stream) {
|
||||
return NULL;
|
||||
}
|
||||
__attribute__((weak)) int hipGetStreamDeviceId(hipStream_t stream) { return 0; }
|
||||
__attribute__((weak)) const char* hipApiName(uint32_t id) { return NULL; }
|
||||
|
||||
class HipLoaderStatic {
|
||||
public:
|
||||
public:
|
||||
typedef std::mutex mutex_t;
|
||||
typedef HipLoaderStatic loader_t;
|
||||
typedef std::atomic<loader_t*> instance_t;
|
||||
|
||||
typedef hipError_t (RegisterApiCallback_t)(uint32_t id, void* fun, void* arg);
|
||||
typedef hipError_t (RemoveApiCallback_t)(uint32_t id);
|
||||
typedef hipError_t (RegisterActivityCallback_t)(uint32_t id, void* fun, void* arg);
|
||||
typedef hipError_t (RemoveActivityCallback_t)(uint32_t id);
|
||||
typedef const char* (KernelNameRef_t)(const hipFunction_t f);
|
||||
typedef const char* (KernelNameRefByPtr_t)(const void* hostFunction, hipStream_t stream);
|
||||
typedef int (GetStreamDeviceId_t)(hipStream_t stream);
|
||||
typedef const char* (ApiName_t)(uint32_t id);
|
||||
typedef hipError_t(RegisterApiCallback_t)(uint32_t id, void* fun, void* arg);
|
||||
typedef hipError_t(RemoveApiCallback_t)(uint32_t id);
|
||||
typedef hipError_t(RegisterActivityCallback_t)(uint32_t id, void* fun, void* arg);
|
||||
typedef hipError_t(RemoveActivityCallback_t)(uint32_t id);
|
||||
typedef const char*(KernelNameRef_t)(const hipFunction_t f);
|
||||
typedef const char*(KernelNameRefByPtr_t)(const void* hostFunction, hipStream_t stream);
|
||||
typedef int(GetStreamDeviceId_t)(hipStream_t stream);
|
||||
typedef const char*(ApiName_t)(uint32_t id);
|
||||
|
||||
RegisterApiCallback_t* RegisterApiCallback;
|
||||
RemoveApiCallback_t* RemoveApiCallback;
|
||||
@@ -181,7 +188,7 @@ class HipLoaderStatic {
|
||||
|
||||
bool Enabled() const { return true; }
|
||||
|
||||
private:
|
||||
private:
|
||||
HipLoaderStatic() {
|
||||
RegisterApiCallback = hipRegisterApiCallback;
|
||||
RemoveApiCallback = hipRemoveApiCallback;
|
||||
@@ -189,7 +196,7 @@ class HipLoaderStatic {
|
||||
RemoveActivityCallback = hipRemoveActivityCallback;
|
||||
KernelNameRef = hipKernelNameRef;
|
||||
KernelNameRefByPtr = hipKernelNameRefByPtr;
|
||||
GetStreamDeviceId = hipGetStreamDeviceId;
|
||||
GetStreamDeviceId = hipGetStreamDeviceId;
|
||||
ApiName = hipApiName;
|
||||
}
|
||||
|
||||
@@ -198,7 +205,7 @@ class HipLoaderStatic {
|
||||
};
|
||||
#else
|
||||
class HipApi {
|
||||
public:
|
||||
public:
|
||||
typedef BaseLoader<HipApi> Loader;
|
||||
|
||||
typedef decltype(hipRegisterApiCallback) RegisterApiCallback_t;
|
||||
@@ -219,15 +226,16 @@ class HipApi {
|
||||
GetStreamDeviceId_t* GetStreamDeviceId;
|
||||
ApiName_t* ApiName;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void init(Loader* loader) {
|
||||
RegisterApiCallback = loader->GetFun<RegisterApiCallback_t>("hipRegisterApiCallback");
|
||||
RemoveApiCallback = loader->GetFun<RemoveApiCallback_t>("hipRemoveApiCallback");
|
||||
RegisterActivityCallback = loader->GetFun<RegisterActivityCallback_t>("hipRegisterActivityCallback");
|
||||
RegisterActivityCallback =
|
||||
loader->GetFun<RegisterActivityCallback_t>("hipRegisterActivityCallback");
|
||||
RemoveActivityCallback = loader->GetFun<RemoveActivityCallback_t>("hipRemoveActivityCallback");
|
||||
KernelNameRef = loader->GetFun<KernelNameRef_t>("hipKernelNameRef");
|
||||
KernelNameRefByPtr = loader->GetFun<KernelNameRefByPtr_t>("hipKernelNameRefByPtr");
|
||||
GetStreamDeviceId = loader->GetFun<GetStreamDeviceId_t>("hipGetStreamDeviceId");
|
||||
GetStreamDeviceId = loader->GetFun<GetStreamDeviceId_t>("hipGetStreamDeviceId");
|
||||
ApiName = loader->GetFun<ApiName_t>("hipApiName");
|
||||
}
|
||||
};
|
||||
@@ -236,17 +244,19 @@ class HipApi {
|
||||
// HCC runtime library loader class
|
||||
#include "inc/roctracer_hcc.h"
|
||||
class HccApi {
|
||||
public:
|
||||
public:
|
||||
typedef BaseLoader<HccApi> Loader;
|
||||
|
||||
hipInitAsyncActivityCallback_t* InitActivityCallback;
|
||||
hipEnableAsyncActivityCallback_t* EnableActivityCallback;
|
||||
hipGetOpName_t* GetOpName;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void init(Loader* loader) {
|
||||
InitActivityCallback = loader->GetFun<hipInitAsyncActivityCallback_t>("hipInitActivityCallback");
|
||||
EnableActivityCallback = loader->GetFun<hipEnableAsyncActivityCallback_t>("hipEnableActivityCallback");
|
||||
InitActivityCallback =
|
||||
loader->GetFun<hipInitAsyncActivityCallback_t>("hipInitActivityCallback");
|
||||
EnableActivityCallback =
|
||||
loader->GetFun<hipEnableAsyncActivityCallback_t>("hipEnableActivityCallback");
|
||||
GetOpName = loader->GetFun<hipGetOpName_t>("hipGetCmdName");
|
||||
}
|
||||
};
|
||||
@@ -254,7 +264,7 @@ class HccApi {
|
||||
// rocTX runtime library loader class
|
||||
#include "inc/roctracer_roctx.h"
|
||||
class RocTxApi {
|
||||
public:
|
||||
public:
|
||||
typedef BaseLoader<RocTxApi> Loader;
|
||||
|
||||
typedef decltype(RegisterApiCallback) RegisterApiCallback_t;
|
||||
@@ -265,7 +275,7 @@ class RocTxApi {
|
||||
RemoveApiCallback_t* RemoveApiCallback;
|
||||
RangeStackIterate_t* RangeStackIterate;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void init(Loader* loader) {
|
||||
RegisterApiCallback = loader->GetFun<RegisterApiCallback_t>("RegisterApiCallback");
|
||||
RemoveApiCallback = loader->GetFun<RemoveApiCallback_t>("RemoveApiCallback");
|
||||
@@ -284,31 +294,31 @@ typedef BaseLoader<HipApi> HipLoaderShared;
|
||||
typedef HipLoaderShared HipLoader;
|
||||
#endif
|
||||
|
||||
} // namespace roctracer
|
||||
} // namespace roctracer
|
||||
|
||||
#define LOADER_INSTANTIATE_2() \
|
||||
template<class T> typename roctracer::BaseLoader<T>::mutex_t roctracer::BaseLoader<T>::mutex_; \
|
||||
template<class T> std::atomic<roctracer::BaseLoader<T>*> roctracer::BaseLoader<T>::instance_{}; \
|
||||
template<class T> bool roctracer::BaseLoader<T>::to_load_ = false; \
|
||||
template<class T> bool roctracer::BaseLoader<T>::to_check_open_ = true; \
|
||||
template<class T> bool roctracer::BaseLoader<T>::to_check_symb_ = true; \
|
||||
template<> const char* roctracer::RocpLoader::lib_name_ = "librocprofiler64.so"; \
|
||||
template<> bool roctracer::RocpLoader::to_load_ = true; \
|
||||
template<> const char* roctracer::HccLoader::lib_name_ = "libamdhip64.so"; \
|
||||
template<> const char* roctracer::RocTxLoader::lib_name_ = "libroctx64.so"; \
|
||||
template<> bool roctracer::RocTxLoader::to_load_ = true;
|
||||
#define LOADER_INSTANTIATE_2() \
|
||||
template <class T> typename roctracer::BaseLoader<T>::mutex_t roctracer::BaseLoader<T>::mutex_; \
|
||||
template <class T> std::atomic<roctracer::BaseLoader<T>*> roctracer::BaseLoader<T>::instance_{}; \
|
||||
template <class T> bool roctracer::BaseLoader<T>::to_load_ = false; \
|
||||
template <class T> bool roctracer::BaseLoader<T>::to_check_open_ = true; \
|
||||
template <class T> bool roctracer::BaseLoader<T>::to_check_symb_ = true; \
|
||||
template <> const char* roctracer::RocpLoader::lib_name_ = "librocprofiler64.so"; \
|
||||
template <> bool roctracer::RocpLoader::to_load_ = true; \
|
||||
template <> const char* roctracer::HccLoader::lib_name_ = "libamdhip64.so"; \
|
||||
template <> const char* roctracer::RocTxLoader::lib_name_ = "libroctx64.so"; \
|
||||
template <> bool roctracer::RocTxLoader::to_load_ = true;
|
||||
|
||||
#if STATIC_BUILD
|
||||
#define LOADER_INSTANTIATE_HIP() \
|
||||
roctracer::HipLoaderStatic::mutex_t roctracer::HipLoaderStatic::mutex_; \
|
||||
#define LOADER_INSTANTIATE_HIP() \
|
||||
roctracer::HipLoaderStatic::mutex_t roctracer::HipLoaderStatic::mutex_; \
|
||||
roctracer::HipLoaderStatic::instance_t roctracer::HipLoaderStatic::instance_{};
|
||||
#else
|
||||
#define LOADER_INSTANTIATE_HIP() \
|
||||
template<> const char* roctracer::HipLoaderShared::lib_name_ = "libamdhip64.so";
|
||||
#define LOADER_INSTANTIATE_HIP() \
|
||||
template <> const char* roctracer::HipLoaderShared::lib_name_ = "libamdhip64.so";
|
||||
#endif
|
||||
|
||||
#define LOADER_INSTANTIATE() \
|
||||
LOADER_INSTANTIATE_2(); \
|
||||
#define LOADER_INSTANTIATE() \
|
||||
LOADER_INSTANTIATE_2(); \
|
||||
LOADER_INSTANTIATE_HIP();
|
||||
|
||||
#endif // SRC_CORE_LOADER_H_
|
||||
#endif // SRC_CORE_LOADER_H_
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
namespace roctracer {
|
||||
|
||||
class MemoryPool {
|
||||
public:
|
||||
public:
|
||||
typedef std::mutex mutex_t;
|
||||
|
||||
static void allocator_default(char** ptr, size_t size, void* arg) {
|
||||
@@ -52,12 +52,12 @@ class MemoryPool {
|
||||
} else if (size != 0) {
|
||||
*ptr = reinterpret_cast<char*>(realloc(*ptr, size));
|
||||
} else {
|
||||
free(*ptr);
|
||||
free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
MemoryPool(const roctracer_properties_t& properties) {
|
||||
MemoryPool(const roctracer_properties_t& properties) {
|
||||
// Assigning pool allocator
|
||||
alloc_fun_ = allocator_default;
|
||||
alloc_arg_ = NULL;
|
||||
@@ -89,14 +89,14 @@ class MemoryPool {
|
||||
~MemoryPool() {
|
||||
Flush();
|
||||
PTHREAD_CALL(pthread_cancel(consumer_thread_));
|
||||
void *res;
|
||||
void* res;
|
||||
PTHREAD_CALL(pthread_join(consumer_thread_, &res));
|
||||
if (res != PTHREAD_CANCELED) EXC_ABORT(ROCTRACER_STATUS_ERROR, "consumer thread wasn't stopped correctly");
|
||||
if (res != PTHREAD_CANCELED)
|
||||
EXC_ABORT(ROCTRACER_STATUS_ERROR, "consumer thread wasn't stopped correctly");
|
||||
allocator_default(&pool_begin_, 0, alloc_arg_);
|
||||
}
|
||||
|
||||
template <typename Record>
|
||||
void Write(const Record& record) {
|
||||
template <typename Record> void Write(const Record& record) {
|
||||
std::lock_guard<mutex_t> lock(write_mutex_);
|
||||
getRecord<Record>(record);
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class MemoryPool {
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
struct consumer_arg_t {
|
||||
MemoryPool* obj;
|
||||
const char* begin;
|
||||
@@ -126,11 +126,13 @@ class MemoryPool {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Record>
|
||||
Record* getRecord(const Record& init) {
|
||||
template <typename Record> Record* getRecord(const Record& init) {
|
||||
char* next = write_ptr_ + sizeof(Record);
|
||||
if (next > buffer_end_) {
|
||||
if (write_ptr_ == buffer_begin_) EXC_ABORT(ROCTRACER_STATUS_ERROR, "buffer size(" << buffer_size_ << ") is less then the record(" << sizeof(Record) << ")");
|
||||
if (write_ptr_ == buffer_begin_)
|
||||
EXC_ABORT(ROCTRACER_STATUS_ERROR,
|
||||
"buffer size(" << buffer_size_ << ") is less then the record(" << sizeof(Record)
|
||||
<< ")");
|
||||
spawn_reader(buffer_begin_, write_ptr_);
|
||||
buffer_begin_ = (buffer_end_ == pool_end_) ? pool_begin_ : buffer_end_;
|
||||
buffer_end_ = buffer_begin_ + buffer_size_;
|
||||
@@ -145,12 +147,10 @@ class MemoryPool {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void reset_reader(consumer_arg_t* arg) {
|
||||
arg->valid.store(false);
|
||||
}
|
||||
static void reset_reader(consumer_arg_t* arg) { arg->valid.store(false); }
|
||||
|
||||
static void sync_reader(const consumer_arg_t* arg) {
|
||||
while(arg->valid.load() == true) PTHREAD_CALL(sched_yield());
|
||||
while (arg->valid.load() == true) PTHREAD_CALL(sched_yield());
|
||||
}
|
||||
|
||||
static void* reader_fun(void* consumer_arg) {
|
||||
|
||||
+267
-258
@@ -66,7 +66,6 @@
|
||||
#define API_METHOD_PREFIX \
|
||||
roctracer_status_t err = ROCTRACER_STATUS_SUCCESS; \
|
||||
try {
|
||||
|
||||
#define API_METHOD_SUFFIX \
|
||||
} \
|
||||
catch (std::exception & e) { \
|
||||
@@ -83,10 +82,12 @@
|
||||
(void)err; \
|
||||
return X;
|
||||
|
||||
#define ONLOAD_TRACE(str) \
|
||||
if (getenv("ROCP_ONLOAD_TRACE")) do { \
|
||||
std::cout << "PID(" << GetPid() << "): TRACER_LIB::" << __FUNCTION__ << " " << str << std::endl << std::flush; \
|
||||
} while(0);
|
||||
#define ONLOAD_TRACE(str) \
|
||||
if (getenv("ROCP_ONLOAD_TRACE")) do { \
|
||||
std::cout << "PID(" << GetPid() << "): TRACER_LIB::" << __FUNCTION__ << " " << str \
|
||||
<< std::endl \
|
||||
<< std::flush; \
|
||||
} while (0);
|
||||
#define ONLOAD_TRACE_BEG() ONLOAD_TRACE("begin")
|
||||
#define ONLOAD_TRACE_END() ONLOAD_TRACE("end")
|
||||
|
||||
@@ -95,7 +96,8 @@ static inline uint32_t GetPid() { return syscall(__NR_getpid); }
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Mark callback
|
||||
//
|
||||
typedef void (mark_api_callback_t)(uint32_t domain, uint32_t cid, const void* callback_data, void* arg);
|
||||
typedef void(mark_api_callback_t)(uint32_t domain, uint32_t cid, const void* callback_data,
|
||||
void* arg);
|
||||
mark_api_callback_t* mark_api_callback_ptr = NULL;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -195,7 +197,8 @@ ActJournal* act_journal;
|
||||
template <typename Functor> struct journal_functor_t {
|
||||
Functor func_;
|
||||
journal_functor_t(Functor&& f) : func_(std::forward<Functor>(f)) {}
|
||||
template <typename Data> bool operator ()(activity_domain_t domain, uint32_t op, Data&& /* data */) const {
|
||||
template <typename Data>
|
||||
bool operator()(activity_domain_t domain, uint32_t op, Data&& /* data */) const {
|
||||
func_(domain, op);
|
||||
return true;
|
||||
}
|
||||
@@ -208,13 +211,13 @@ using act_dis_functor_t = journal_functor_t<roctracer_disable_op_activity_t>;
|
||||
|
||||
template <>
|
||||
template <typename Data>
|
||||
bool cb_en_functor_t::operator ()(activity_domain_t domain, uint32_t op, Data&& data) const {
|
||||
bool cb_en_functor_t::operator()(activity_domain_t domain, uint32_t op, Data&& data) const {
|
||||
func_(domain, op, data.callback, data.user_data);
|
||||
return true;
|
||||
}
|
||||
template <>
|
||||
template <typename Data>
|
||||
bool act_en_functor_t::operator ()(activity_domain_t domain, uint32_t op, Data&& data) const {
|
||||
bool act_en_functor_t::operator()(activity_domain_t domain, uint32_t op, Data&& data) const {
|
||||
func_(domain, op, data.pool);
|
||||
return true;
|
||||
}
|
||||
@@ -222,9 +225,7 @@ bool act_en_functor_t::operator ()(activity_domain_t domain, uint32_t op, Data&&
|
||||
void hsa_async_copy_handler(::proxy::Tracker::entry_t* entry);
|
||||
void hsa_kernel_handler(::proxy::Tracker::entry_t* entry);
|
||||
constexpr TraceBuffer<trace_entry_t>::flush_prm_t trace_buffer_prm[] = {
|
||||
{COPY_ENTRY_TYPE, hsa_async_copy_handler},
|
||||
{KERNEL_ENTRY_TYPE, hsa_kernel_handler}
|
||||
};
|
||||
{COPY_ENTRY_TYPE, hsa_async_copy_handler}, {KERNEL_ENTRY_TYPE, hsa_kernel_handler}};
|
||||
TraceBuffer<trace_entry_t>* trace_buffer = NULL;
|
||||
|
||||
namespace hsa_support {
|
||||
@@ -250,18 +251,19 @@ roctracer_stop_cb_t roctracer_stop_cb = NULL;
|
||||
|
||||
roctracer_status_t GetExcStatus(const std::exception& e) {
|
||||
const util::exception* roctracer_exc_ptr = dynamic_cast<const util::exception*>(&e);
|
||||
return (roctracer_exc_ptr) ? static_cast<roctracer_status_t>(roctracer_exc_ptr->status()) : ROCTRACER_STATUS_ERROR;
|
||||
return (roctracer_exc_ptr) ? static_cast<roctracer_status_t>(roctracer_exc_ptr->status())
|
||||
: ROCTRACER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
class GlobalCounter {
|
||||
public:
|
||||
public:
|
||||
typedef std::mutex mutex_t;
|
||||
typedef uint64_t counter_t;
|
||||
typedef std::atomic<counter_t> atomic_counter_t;
|
||||
|
||||
static counter_t Increment() { return counter_.fetch_add(1, std::memory_order_relaxed); }
|
||||
|
||||
private:
|
||||
private:
|
||||
static mutex_t mutex_;
|
||||
static atomic_counter_t counter_;
|
||||
};
|
||||
@@ -273,12 +275,12 @@ struct roctracer_api_data_t {
|
||||
union {
|
||||
hip_api_data_t hip;
|
||||
};
|
||||
roctracer_api_data_t() {};
|
||||
roctracer_api_data_t(){};
|
||||
};
|
||||
struct record_pair_t {
|
||||
roctracer_record_t record;
|
||||
roctracer_api_data_t data;
|
||||
record_pair_t() {};
|
||||
record_pair_t(){};
|
||||
};
|
||||
typedef std::stack<record_pair_t> record_pair_stack_t;
|
||||
static thread_local record_pair_stack_t* record_pair_stack = NULL;
|
||||
@@ -295,15 +297,18 @@ static thread_local std::stack<activity_correlation_id_t> external_id_stack;
|
||||
static inline void CorrelationIdRegistr(const activity_correlation_id_t& correlation_id) {
|
||||
std::lock_guard<correlation_id_mutex_t> lck(correlation_id_mutex);
|
||||
const auto ret = correlation_id_map.insert({correlation_id, correlation_id_tls});
|
||||
if (ret.second == false) EXC_ABORT(ROCTRACER_STATUS_ERROR, "HCC activity id is not unique(" << correlation_id << ")");
|
||||
if (ret.second == false)
|
||||
EXC_ABORT(ROCTRACER_STATUS_ERROR, "HCC activity id is not unique(" << correlation_id << ")");
|
||||
|
||||
DEBUG_TRACE("CorrelationIdRegistr id(%lu) id_tls(%lu)\n", correlation_id, correlation_id_tls);
|
||||
}
|
||||
|
||||
static inline activity_correlation_id_t CorrelationIdLookup(const activity_correlation_id_t& correlation_id) {
|
||||
static inline activity_correlation_id_t CorrelationIdLookup(
|
||||
const activity_correlation_id_t& correlation_id) {
|
||||
std::lock_guard<correlation_id_mutex_t> lck(correlation_id_mutex);
|
||||
auto it = correlation_id_map.find(correlation_id);
|
||||
if (it == correlation_id_map.end()) EXC_ABORT(ROCTRACER_STATUS_ERROR, "HCC activity id lookup failed(" << correlation_id << ")");
|
||||
if (it == correlation_id_map.end())
|
||||
EXC_ABORT(ROCTRACER_STATUS_ERROR, "HCC activity id lookup failed(" << correlation_id << ")");
|
||||
const activity_correlation_id_t ret_val = it->second;
|
||||
correlation_id_map.erase(it);
|
||||
|
||||
@@ -320,14 +325,14 @@ hip_act_cb_tracker_t* hip_act_cb_tracker = NULL;
|
||||
inline uint32_t HipApiActivityEnableCheck(uint32_t op) {
|
||||
if (hip_act_cb_tracker == NULL) EXC_ABORT(ROCTRACER_STATUS_ERROR, "hip_act_cb_tracker is NULL");
|
||||
const uint32_t mask = hip_act_cb_tracker->enable_check(op, API_CB_MASK);
|
||||
const uint32_t ret = (mask & ACT_CB_MASK);
|
||||
const uint32_t ret = (mask & ACT_CB_MASK);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline uint32_t HipApiActivityDisableCheck(uint32_t op) {
|
||||
if (hip_act_cb_tracker == NULL) EXC_ABORT(ROCTRACER_STATUS_ERROR, "hip_act_cb_tracker is NULL");
|
||||
const uint32_t mask = hip_act_cb_tracker->disable_check(op, API_CB_MASK);
|
||||
const uint32_t ret = (mask & ACT_CB_MASK);
|
||||
const uint32_t ret = (mask & ACT_CB_MASK);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -340,16 +345,12 @@ inline uint32_t HipActActivityEnableCheck(uint32_t op) {
|
||||
inline uint32_t HipActActivityDisableCheck(uint32_t op) {
|
||||
if (hip_act_cb_tracker == NULL) EXC_ABORT(ROCTRACER_STATUS_ERROR, "hip_act_cb_tracker is NULL");
|
||||
const uint32_t mask = hip_act_cb_tracker->disable_check(op, ACT_CB_MASK);
|
||||
const uint32_t ret = (mask & API_CB_MASK);
|
||||
const uint32_t ret = (mask & API_CB_MASK);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* HIP_SyncApiDataCallback(
|
||||
uint32_t op_id,
|
||||
roctracer_record_t* record,
|
||||
const void* callback_data,
|
||||
void* arg)
|
||||
{
|
||||
void* HIP_SyncApiDataCallback(uint32_t op_id, roctracer_record_t* record, const void* callback_data,
|
||||
void* arg) {
|
||||
static hsa_rt_utils::Timer timer;
|
||||
if (record_pair_stack == NULL) record_pair_stack = new record_pair_stack_t;
|
||||
|
||||
@@ -397,19 +398,18 @@ void* HIP_SyncApiDataCallback(
|
||||
correlation_id_tls = 0;
|
||||
}
|
||||
|
||||
const char * name = roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, op_id, 0);
|
||||
DEBUG_TRACE("HIP_SyncApiDataCallback(\"%s\") phase(%d): op(%u) record(%p) data(%p) pool(%p) depth(%d) correlation_id(%lu) time_ns(%lu)\n",
|
||||
name, phase, op_id, record, data, pool, (int)(record_pair_stack->size()), (data_ptr) ? data_ptr->correlation_id : 0, timer.timestamp_ns());
|
||||
const char* name = roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, op_id, 0);
|
||||
DEBUG_TRACE(
|
||||
"HIP_SyncApiDataCallback(\"%s\") phase(%d): op(%u) record(%p) data(%p) pool(%p) depth(%d) "
|
||||
"correlation_id(%lu) time_ns(%lu)\n",
|
||||
name, phase, op_id, record, data, pool, (int)(record_pair_stack->size()),
|
||||
(data_ptr) ? data_ptr->correlation_id : 0, timer.timestamp_ns());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* HIP_SyncActivityCallback(
|
||||
uint32_t op_id,
|
||||
roctracer_record_t* record,
|
||||
const void* callback_data,
|
||||
void* arg)
|
||||
{
|
||||
void* HIP_SyncActivityCallback(uint32_t op_id, roctracer_record_t* record,
|
||||
const void* callback_data, void* arg) {
|
||||
static hsa_rt_utils::Timer timer;
|
||||
const timestamp_t timestamp_ns = timer.timestamp_ns();
|
||||
if (record_pair_stack == NULL) record_pair_stack = new record_pair_stack_t;
|
||||
@@ -462,8 +462,9 @@ void* HIP_SyncActivityCallback(
|
||||
|
||||
// Getting record of stacked
|
||||
if (record == NULL) {
|
||||
if (record_pair_stack->empty()) EXC_ABORT(ROCTRACER_STATUS_ERROR, "ActivityCallback exit: record stack is empty");
|
||||
auto& top = record_pair_stack->top();
|
||||
if (record_pair_stack->empty())
|
||||
EXC_ABORT(ROCTRACER_STATUS_ERROR, "ActivityCallback exit: record stack is empty");
|
||||
auto& top = record_pair_stack->top();
|
||||
record = &(top.record);
|
||||
}
|
||||
|
||||
@@ -491,9 +492,12 @@ void* HIP_SyncActivityCallback(
|
||||
correlation_id_tls = 0;
|
||||
}
|
||||
|
||||
const char * name = roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, op_id, 0);
|
||||
DEBUG_TRACE("HIP_SyncActivityCallback(\"%s\") phase(%d): op(%u) record(%p) data(%p) pool(%p) depth(%d) correlation_id(%lu) beg_ns(%lu) end_ns(%lu)\n",
|
||||
name, phase, op_id, record, data, pool, (int)(record_pair_stack->size()), (data_ptr) ? data_ptr->correlation_id : 0, timestamp_ns);
|
||||
const char* name = roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, op_id, 0);
|
||||
DEBUG_TRACE(
|
||||
"HIP_SyncActivityCallback(\"%s\") phase(%d): op(%u) record(%p) data(%p) pool(%p) depth(%d) "
|
||||
"correlation_id(%lu) beg_ns(%lu) end_ns(%lu)\n",
|
||||
name, phase, op_id, record, data, pool, (int)(record_pair_stack->size()),
|
||||
(data_ptr) ? data_ptr->correlation_id : 0, timestamp_ns);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -510,9 +514,12 @@ void HCC_AsyncActivityCallback(uint32_t op_id, void* record, void* arg) {
|
||||
if (record_ptr->correlation_id == 0) return;
|
||||
pool->Write(*record_ptr);
|
||||
|
||||
const char * name = roctracer_op_string(ACTIVITY_DOMAIN_HCC_OPS, record_ptr->op, record_ptr->kind);
|
||||
DEBUG_TRACE("HCC_AsyncActivityCallback(\"%s\"): op(%u) kind(%u) record(%p) pool(%p) correlation_id(%d) beg_ns(%lu) end_ns(%lu)\n",
|
||||
name, record_ptr->op, record_ptr->kind, record, pool, record_ptr->correlation_id, record_ptr->begin_ns, record_ptr->end_ns);
|
||||
const char* name = roctracer_op_string(ACTIVITY_DOMAIN_HCC_OPS, record_ptr->op, record_ptr->kind);
|
||||
DEBUG_TRACE(
|
||||
"HCC_AsyncActivityCallback(\"%s\"): op(%u) kind(%u) record(%p) pool(%p) correlation_id(%d) "
|
||||
"beg_ns(%lu) end_ns(%lu)\n",
|
||||
name, record_ptr->op, record_ptr->kind, record, pool, record_ptr->correlation_id,
|
||||
record_ptr->begin_ns, record_ptr->end_ns);
|
||||
}
|
||||
|
||||
// Open output file
|
||||
@@ -528,7 +535,8 @@ FILE* open_output_file(const char* prefix, const char* name) {
|
||||
perror(errmsg.str().c_str());
|
||||
abort();
|
||||
}
|
||||
} else file_handle = stdout;
|
||||
} else
|
||||
file_handle = stdout;
|
||||
return file_handle;
|
||||
}
|
||||
|
||||
@@ -542,16 +550,11 @@ void hsa_kernel_handler(::proxy::Tracker::entry_t* entry) {
|
||||
if (index == 0) {
|
||||
kernel_file_handle = open_output_file(hsa_support::output_prefix, "results.txt");
|
||||
}
|
||||
fprintf(kernel_file_handle, "dispatch[%lu], gpu-id(%u), tid(%u), kernel-name(\"%s\"), time(%lu,%lu,%lu,%lu)\n",
|
||||
index,
|
||||
//::util::HsaRsrcFactory::Instance().GetAgentInfo(entry->agent)->dev_index,
|
||||
entry->dev_index,
|
||||
entry->kernel.tid,
|
||||
entry->kernel.name,
|
||||
entry->dispatch,
|
||||
entry->begin,
|
||||
entry->end,
|
||||
entry->complete);
|
||||
fprintf(kernel_file_handle,
|
||||
"dispatch[%lu], gpu-id(%u), tid(%u), kernel-name(\"%s\"), time(%lu,%lu,%lu,%lu)\n", index,
|
||||
//::util::HsaRsrcFactory::Instance().GetAgentInfo(entry->agent)->dev_index,
|
||||
entry->dev_index, entry->kernel.tid, entry->kernel.name, entry->dispatch, entry->begin,
|
||||
entry->end, entry->complete);
|
||||
#if 0
|
||||
fprintf(file_handle, "dispatch[%u], gpu-id(%u), queue-id(%u), queue-index(%lu), tid(%lu), grd(%u), wgr(%u), lds(%u), scr(%u), vgpr(%u), sgpr(%u), fbar(%u), sig(0x%lx), kernel-name(\"%s\")",
|
||||
index,
|
||||
@@ -581,32 +584,29 @@ void hsa_kernel_handler(::proxy::Tracker::entry_t* entry) {
|
||||
|
||||
void hsa_async_copy_handler(::proxy::Tracker::entry_t* entry) {
|
||||
activity_record_t record{};
|
||||
record.domain = ACTIVITY_DOMAIN_HSA_OPS; // activity domain id
|
||||
record.begin_ns = entry->begin; // host begin timestamp
|
||||
record.end_ns = entry->end; // host end timestamp
|
||||
record.device_id = 0; // device id
|
||||
record.domain = ACTIVITY_DOMAIN_HSA_OPS; // activity domain id
|
||||
record.begin_ns = entry->begin; // host begin timestamp
|
||||
record.end_ns = entry->end; // host end timestamp
|
||||
record.device_id = 0; // device id
|
||||
|
||||
hsa_support::async_copy_callback_fun(hsa_support::HSA_OP_ID_async_copy, &record, hsa_support::async_copy_callback_arg);
|
||||
hsa_support::async_copy_callback_fun(hsa_support::HSA_OP_ID_async_copy, &record,
|
||||
hsa_support::async_copy_callback_arg);
|
||||
}
|
||||
|
||||
hsa_status_t hsa_amd_memory_async_copy_interceptor(
|
||||
void* dst, hsa_agent_t dst_agent, const void* src,
|
||||
hsa_agent_t src_agent, size_t size, uint32_t num_dep_signals,
|
||||
const hsa_signal_t* dep_signals, hsa_signal_t completion_signal)
|
||||
{
|
||||
hsa_status_t hsa_amd_memory_async_copy_interceptor(void* dst, hsa_agent_t dst_agent,
|
||||
const void* src, hsa_agent_t src_agent,
|
||||
size_t size, uint32_t num_dep_signals,
|
||||
const hsa_signal_t* dep_signals,
|
||||
hsa_signal_t completion_signal) {
|
||||
hsa_status_t status = HSA_STATUS_SUCCESS;
|
||||
if (hsa_support::async_copy_callback_enabled) {
|
||||
trace_entry_t* entry = trace_buffer->GetEntry();
|
||||
::proxy::Tracker::Enable(COPY_ENTRY_TYPE, hsa_agent_t{}, completion_signal, entry);
|
||||
status = hsa_amd_memory_async_copy_fn(dst, dst_agent, src,
|
||||
src_agent, size, num_dep_signals,
|
||||
status = hsa_amd_memory_async_copy_fn(dst, dst_agent, src, src_agent, size, num_dep_signals,
|
||||
dep_signals, entry->signal);
|
||||
if (status != HSA_STATUS_SUCCESS) ::proxy::Tracker::Disable(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = hsa_amd_memory_async_copy_fn(dst, dst_agent, src,
|
||||
src_agent, size, num_dep_signals,
|
||||
} else {
|
||||
status = hsa_amd_memory_async_copy_fn(dst, dst_agent, src, src_agent, size, num_dep_signals,
|
||||
dep_signals, completion_signal);
|
||||
}
|
||||
return status;
|
||||
@@ -616,24 +616,18 @@ hsa_status_t hsa_amd_memory_async_copy_rect_interceptor(
|
||||
const hsa_pitched_ptr_t* dst, const hsa_dim3_t* dst_offset, const hsa_pitched_ptr_t* src,
|
||||
const hsa_dim3_t* src_offset, const hsa_dim3_t* range, hsa_agent_t copy_agent,
|
||||
hsa_amd_copy_direction_t dir, uint32_t num_dep_signals, const hsa_signal_t* dep_signals,
|
||||
hsa_signal_t completion_signal)
|
||||
{
|
||||
hsa_signal_t completion_signal) {
|
||||
hsa_status_t status = HSA_STATUS_SUCCESS;
|
||||
if (hsa_support::async_copy_callback_enabled) {
|
||||
trace_entry_t* entry = trace_buffer->GetEntry();
|
||||
::proxy::Tracker::Enable(COPY_ENTRY_TYPE, hsa_agent_t{}, completion_signal, entry);
|
||||
status = hsa_amd_memory_async_copy_rect_fn(dst, dst_offset, src,
|
||||
src_offset, range, copy_agent,
|
||||
dir, num_dep_signals, dep_signals,
|
||||
entry->signal);
|
||||
status = hsa_amd_memory_async_copy_rect_fn(dst, dst_offset, src, src_offset, range, copy_agent,
|
||||
dir, num_dep_signals, dep_signals, entry->signal);
|
||||
if (status != HSA_STATUS_SUCCESS) ::proxy::Tracker::Disable(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = hsa_amd_memory_async_copy_rect_fn(dst, dst_offset, src,
|
||||
src_offset, range, copy_agent,
|
||||
dir, num_dep_signals, dep_signals,
|
||||
completion_signal);
|
||||
} else {
|
||||
status =
|
||||
hsa_amd_memory_async_copy_rect_fn(dst, dst_offset, src, src_offset, range, copy_agent, dir,
|
||||
num_dep_signals, dep_signals, completion_signal);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -685,11 +679,7 @@ PUBLIC_API const char* roctracer_error_string() {
|
||||
|
||||
// Return Op string by given domain and activity/API codes
|
||||
// NULL returned on the error and the library errno is set
|
||||
PUBLIC_API const char* roctracer_op_string(
|
||||
uint32_t domain,
|
||||
uint32_t op,
|
||||
uint32_t kind)
|
||||
{
|
||||
PUBLIC_API const char* roctracer_op_string(uint32_t domain, uint32_t op, uint32_t kind) {
|
||||
API_METHOD_PREFIX
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_HSA_API:
|
||||
@@ -711,18 +701,15 @@ PUBLIC_API const char* roctracer_op_string(
|
||||
}
|
||||
|
||||
// Return Op code and kind by given string
|
||||
PUBLIC_API roctracer_status_t roctracer_op_code(
|
||||
uint32_t domain,
|
||||
const char* str,
|
||||
uint32_t* op,
|
||||
uint32_t* kind)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_op_code(uint32_t domain, const char* str, uint32_t* op,
|
||||
uint32_t* kind) {
|
||||
API_METHOD_PREFIX
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_HSA_API: {
|
||||
*op = roctracer::hsa_support::GetApiCode(str);
|
||||
if (*op == HSA_API_ID_NUMBER) {
|
||||
EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "Invalid API name \"" << str << "\", domain ID(" << domain << ")");
|
||||
EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER,
|
||||
"Invalid API name \"" << str << "\", domain ID(" << domain << ")");
|
||||
}
|
||||
if (kind != NULL) *kind = 0;
|
||||
break;
|
||||
@@ -730,7 +717,8 @@ PUBLIC_API roctracer_status_t roctracer_op_code(
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
*op = hipApiIdByName(str);
|
||||
if (*op == HIP_API_ID_NONE) {
|
||||
EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "Invalid API name \"" << str << "\", domain ID(" << domain << ")");
|
||||
EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER,
|
||||
"Invalid API name \"" << str << "\", domain ID(" << domain << ")");
|
||||
}
|
||||
if (kind != NULL) *kind = 0;
|
||||
break;
|
||||
@@ -743,13 +731,20 @@ PUBLIC_API roctracer_status_t roctracer_op_code(
|
||||
|
||||
static inline uint32_t get_op_begin(uint32_t domain) {
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_HSA_OPS: return 0;
|
||||
case ACTIVITY_DOMAIN_HSA_API: return 0;
|
||||
case ACTIVITY_DOMAIN_HSA_EVT: return 0;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS: return 0;
|
||||
case ACTIVITY_DOMAIN_HIP_API: return HIP_API_ID_FIRST;
|
||||
case ACTIVITY_DOMAIN_EXT_API: return 0;
|
||||
case ACTIVITY_DOMAIN_ROCTX: return 0;
|
||||
case ACTIVITY_DOMAIN_HSA_OPS:
|
||||
return 0;
|
||||
case ACTIVITY_DOMAIN_HSA_API:
|
||||
return 0;
|
||||
case ACTIVITY_DOMAIN_HSA_EVT:
|
||||
return 0;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS:
|
||||
return 0;
|
||||
case ACTIVITY_DOMAIN_HIP_API:
|
||||
return HIP_API_ID_FIRST;
|
||||
case ACTIVITY_DOMAIN_EXT_API:
|
||||
return 0;
|
||||
case ACTIVITY_DOMAIN_ROCTX:
|
||||
return 0;
|
||||
default:
|
||||
EXC_RAISING(ROCTRACER_STATUS_BAD_DOMAIN, "invalid domain ID(" << domain << ")");
|
||||
}
|
||||
@@ -758,13 +753,21 @@ static inline uint32_t get_op_begin(uint32_t domain) {
|
||||
|
||||
static inline uint32_t get_op_end(uint32_t domain) {
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_HSA_OPS: return HSA_OP_ID_NUMBER;
|
||||
case ACTIVITY_DOMAIN_HSA_API: return HSA_API_ID_NUMBER;
|
||||
case ACTIVITY_DOMAIN_HSA_EVT: return HSA_EVT_ID_NUMBER;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS: return HIP_OP_ID_NUMBER;
|
||||
case ACTIVITY_DOMAIN_HIP_API: return HIP_API_ID_LAST + 1;;
|
||||
case ACTIVITY_DOMAIN_EXT_API: return 0;
|
||||
case ACTIVITY_DOMAIN_ROCTX: return ROCTX_API_ID_NUMBER;
|
||||
case ACTIVITY_DOMAIN_HSA_OPS:
|
||||
return HSA_OP_ID_NUMBER;
|
||||
case ACTIVITY_DOMAIN_HSA_API:
|
||||
return HSA_API_ID_NUMBER;
|
||||
case ACTIVITY_DOMAIN_HSA_EVT:
|
||||
return HSA_EVT_ID_NUMBER;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS:
|
||||
return HIP_OP_ID_NUMBER;
|
||||
case ACTIVITY_DOMAIN_HIP_API:
|
||||
return HIP_API_ID_LAST + 1;
|
||||
;
|
||||
case ACTIVITY_DOMAIN_EXT_API:
|
||||
return 0;
|
||||
case ACTIVITY_DOMAIN_ROCTX:
|
||||
return ROCTX_API_ID_NUMBER;
|
||||
default:
|
||||
EXC_RAISING(ROCTRACER_STATUS_BAD_DOMAIN, "invalid domain ID(" << domain << ")");
|
||||
}
|
||||
@@ -772,14 +775,12 @@ static inline uint32_t get_op_end(uint32_t domain) {
|
||||
}
|
||||
|
||||
// Enable runtime API callbacks
|
||||
static roctracer_status_t roctracer_enable_callback_fun(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op,
|
||||
roctracer_rtapi_callback_t callback,
|
||||
void* user_data)
|
||||
{
|
||||
static roctracer_status_t roctracer_enable_callback_fun(roctracer_domain_t domain, uint32_t op,
|
||||
roctracer_rtapi_callback_t callback,
|
||||
void* user_data) {
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_HSA_OPS: break;
|
||||
case ACTIVITY_DOMAIN_HSA_OPS:
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HSA_API: {
|
||||
#if 0
|
||||
if (op == HSA_API_ID_DISPATCH) {
|
||||
@@ -792,28 +793,42 @@ static roctracer_status_t roctracer_enable_callback_fun(
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HSA_EVT: {
|
||||
const bool succ = roctracer::RocpLoader::Instance().RegisterEvtCallback(op, (void*)callback, user_data);
|
||||
if (succ == false) HCC_EXC_RAISING(ROCTRACER_STATUS_HSA_ERR, "HSA::RegisterEvtCallback error(" << op << ") failed");
|
||||
const bool succ =
|
||||
roctracer::RocpLoader::Instance().RegisterEvtCallback(op, (void*)callback, user_data);
|
||||
if (succ == false)
|
||||
HCC_EXC_RAISING(ROCTRACER_STATUS_HSA_ERR,
|
||||
"HSA::RegisterEvtCallback error(" << op << ") failed");
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HCC_OPS: break;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS:
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
if (roctracer::HipLoader::Instance().Enabled() == false) break;
|
||||
std::lock_guard<roctracer::hip_activity_mutex_t> lock(roctracer::hip_activity_mutex);
|
||||
|
||||
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, "HIP::RegisterApiCallback(" << op << ") error(" << hip_err << ")");
|
||||
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,
|
||||
"HIP::RegisterApiCallback(" << op << ") error(" << hip_err << ")");
|
||||
|
||||
if (roctracer::HipApiActivityEnableCheck(op) == 0) {
|
||||
hip_err = roctracer::HipLoader::Instance().RegisterActivityCallback(op, (void*)roctracer::HIP_SyncApiDataCallback, (void*)1);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "HIPAPI: HIP::RegisterActivityCallback(" << op << ") error(" << hip_err << ")");
|
||||
hip_err = roctracer::HipLoader::Instance().RegisterActivityCallback(
|
||||
op, (void*)roctracer::HIP_SyncApiDataCallback, (void*)1);
|
||||
if (hip_err != hipSuccess)
|
||||
HIP_EXC_RAISING(
|
||||
ROCTRACER_STATUS_HIP_API_ERR,
|
||||
"HIPAPI: HIP::RegisterActivityCallback(" << op << ") error(" << hip_err << ")");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_ROCTX: {
|
||||
if (roctracer::RocTxLoader::Instance().Enabled()) {
|
||||
const bool suc = roctracer::RocTxLoader::Instance().RegisterApiCallback(op, (void*)callback, user_data);
|
||||
if (suc == false) EXC_RAISING(ROCTRACER_STATUS_ROCTX_ERR, "ROCTX::RegisterApiCallback(" << op << ") failed");
|
||||
const bool suc =
|
||||
roctracer::RocTxLoader::Instance().RegisterApiCallback(op, (void*)callback, user_data);
|
||||
if (suc == false)
|
||||
EXC_RAISING(ROCTRACER_STATUS_ROCTX_ERR,
|
||||
"ROCTX::RegisterApiCallback(" << op << ") failed");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -823,32 +838,23 @@ static roctracer_status_t roctracer_enable_callback_fun(
|
||||
return ROCTRACER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void roctracer_enable_callback_impl(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op,
|
||||
roctracer_rtapi_callback_t callback,
|
||||
void* user_data)
|
||||
{
|
||||
static void roctracer_enable_callback_impl(roctracer_domain_t domain, uint32_t op,
|
||||
roctracer_rtapi_callback_t callback, void* user_data) {
|
||||
roctracer::cb_journal->Insert(domain, op, {callback, user_data});
|
||||
roctracer_enable_callback_fun(domain, op, callback, user_data);
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_op_callback(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op,
|
||||
roctracer_rtapi_callback_t callback,
|
||||
void* user_data)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_op_callback(roctracer_domain_t domain, uint32_t op,
|
||||
roctracer_rtapi_callback_t callback,
|
||||
void* user_data) {
|
||||
API_METHOD_PREFIX
|
||||
roctracer_enable_callback_impl(domain, op, callback, user_data);
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_domain_callback(
|
||||
roctracer_domain_t domain,
|
||||
roctracer_rtapi_callback_t callback,
|
||||
void* user_data)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_domain_callback(roctracer_domain_t domain,
|
||||
roctracer_rtapi_callback_t callback,
|
||||
void* user_data) {
|
||||
API_METHOD_PREFIX
|
||||
const uint32_t op_end = get_op_end(domain);
|
||||
for (uint32_t op = get_op_begin(domain); op < op_end; ++op)
|
||||
@@ -856,10 +862,8 @@ PUBLIC_API roctracer_status_t roctracer_enable_domain_callback(
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_callback(
|
||||
roctracer_rtapi_callback_t callback,
|
||||
void* user_data)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_callback(roctracer_rtapi_callback_t callback,
|
||||
void* user_data) {
|
||||
API_METHOD_PREFIX
|
||||
for (uint32_t domain = 0; domain < ACTIVITY_DOMAIN_NUMBER; ++domain) {
|
||||
const uint32_t op_end = get_op_end(domain);
|
||||
@@ -870,12 +874,10 @@ PUBLIC_API roctracer_status_t roctracer_enable_callback(
|
||||
}
|
||||
|
||||
// Disable runtime API callbacks
|
||||
static roctracer_status_t roctracer_disable_callback_fun(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op)
|
||||
{
|
||||
static roctracer_status_t roctracer_disable_callback_fun(roctracer_domain_t domain, uint32_t op) {
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_HSA_OPS: break;
|
||||
case ACTIVITY_DOMAIN_HSA_OPS:
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HSA_API: {
|
||||
#if 0
|
||||
if (op == HSA_API_ID_DISPATCH) {
|
||||
@@ -887,29 +889,38 @@ static roctracer_status_t roctracer_disable_callback_fun(
|
||||
roctracer::hsa_support::cb_table.set(op, NULL, NULL);
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HCC_OPS: break;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS:
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
if (roctracer::HipLoader::Instance().Enabled() == false) break;
|
||||
std::lock_guard<roctracer::hip_activity_mutex_t> lock(roctracer::hip_activity_mutex);
|
||||
|
||||
const hipError_t hip_err = roctracer::HipLoader::Instance().RemoveApiCallback(op);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "HIP::RemoveApiCallback(" << op << "), error(" << hip_err << ")");
|
||||
if (hip_err != hipSuccess)
|
||||
HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR,
|
||||
"HIP::RemoveApiCallback(" << op << "), error(" << hip_err << ")");
|
||||
|
||||
if (roctracer::HipApiActivityDisableCheck(op) == 0) {
|
||||
const hipError_t hip_err = roctracer::HipLoader::Instance().RemoveActivityCallback(op);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "HIPAPI: HIP::RemoveActivityCallback op(" << op << "), error(" << hip_err << ")");
|
||||
if (hip_err != hipSuccess)
|
||||
HIP_EXC_RAISING(
|
||||
ROCTRACER_STATUS_HIP_API_ERR,
|
||||
"HIPAPI: HIP::RemoveActivityCallback op(" << op << "), error(" << hip_err << ")");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HSA_EVT: {
|
||||
const bool succ = roctracer::RocpLoader::Instance().RemoveEvtCallback(op);
|
||||
if (succ == false) HCC_EXC_RAISING(ROCTRACER_STATUS_HSA_ERR, "HSA::RemoveEvtCallback error(" << op << ") failed");
|
||||
if (succ == false)
|
||||
HCC_EXC_RAISING(ROCTRACER_STATUS_HSA_ERR,
|
||||
"HSA::RemoveEvtCallback error(" << op << ") failed");
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_ROCTX: {
|
||||
if (roctracer::RocTxLoader::Instance().Enabled()) {
|
||||
const bool suc = roctracer::RocTxLoader::Instance().RemoveApiCallback(op);
|
||||
if (suc == false) EXC_RAISING(ROCTRACER_STATUS_ROCTX_ERR, "ROCTX::RemoveApiCallback(" << op << ") failed");
|
||||
if (suc == false)
|
||||
EXC_RAISING(ROCTRACER_STATUS_ROCTX_ERR, "ROCTX::RemoveApiCallback(" << op << ") failed");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -919,26 +930,19 @@ static roctracer_status_t roctracer_disable_callback_fun(
|
||||
return ROCTRACER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void roctracer_disable_callback_impl(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op)
|
||||
{
|
||||
roctracer::cb_journal->Remove(domain, op);
|
||||
roctracer_disable_callback_fun(domain, op);
|
||||
static void roctracer_disable_callback_impl(roctracer_domain_t domain, uint32_t op) {
|
||||
roctracer::cb_journal->Remove(domain, op);
|
||||
roctracer_disable_callback_fun(domain, op);
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_op_callback(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_op_callback(roctracer_domain_t domain,
|
||||
uint32_t op) {
|
||||
API_METHOD_PREFIX
|
||||
roctracer_disable_callback_impl(domain, op);
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_domain_callback(
|
||||
roctracer_domain_t domain)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_domain_callback(roctracer_domain_t domain) {
|
||||
API_METHOD_PREFIX
|
||||
const uint32_t op_end = get_op_end(domain);
|
||||
for (uint32_t op = get_op_begin(domain); op < op_end; ++op)
|
||||
@@ -946,8 +950,7 @@ PUBLIC_API roctracer_status_t roctracer_disable_domain_callback(
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_callback()
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_callback() {
|
||||
API_METHOD_PREFIX
|
||||
for (uint32_t domain = 0; domain < ACTIVITY_DOMAIN_NUMBER; ++domain) {
|
||||
const uint32_t op_end = get_op_end(domain);
|
||||
@@ -966,10 +969,8 @@ PUBLIC_API roctracer_pool_t* roctracer_default_pool_expl(roctracer_pool_t* pool)
|
||||
}
|
||||
|
||||
// Open memory pool
|
||||
PUBLIC_API roctracer_status_t roctracer_open_pool_expl(
|
||||
const roctracer_properties_t* properties,
|
||||
roctracer_pool_t** pool)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_open_pool_expl(const roctracer_properties_t* properties,
|
||||
roctracer_pool_t** pool) {
|
||||
API_METHOD_PREFIX
|
||||
std::lock_guard<roctracer::memory_pool_mutex_t> lock(roctracer::memory_pool_mutex);
|
||||
if ((pool == NULL) && (roctracer::memory_pool != NULL)) {
|
||||
@@ -977,8 +978,10 @@ PUBLIC_API roctracer_status_t roctracer_open_pool_expl(
|
||||
}
|
||||
roctracer::MemoryPool* p = new roctracer::MemoryPool(*properties);
|
||||
if (p == NULL) EXC_RAISING(ROCTRACER_STATUS_ERROR, "MemoryPool() error");
|
||||
if (pool != NULL) *pool = p;
|
||||
else roctracer::memory_pool = p;
|
||||
if (pool != NULL)
|
||||
*pool = p;
|
||||
else
|
||||
roctracer::memory_pool = p;
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
@@ -988,17 +991,14 @@ PUBLIC_API roctracer_status_t roctracer_close_pool_expl(roctracer_pool_t* pool)
|
||||
std::lock_guard<roctracer::memory_pool_mutex_t> lock(roctracer::memory_pool_mutex);
|
||||
roctracer_pool_t* ptr = (pool == NULL) ? roctracer_default_pool() : pool;
|
||||
roctracer::MemoryPool* memory_pool = reinterpret_cast<roctracer::MemoryPool*>(ptr);
|
||||
delete(memory_pool);
|
||||
delete (memory_pool);
|
||||
if (pool == NULL) roctracer::memory_pool = NULL;
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
// Enable activity records logging
|
||||
static roctracer_status_t roctracer_enable_activity_fun(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op,
|
||||
roctracer_pool_t* pool)
|
||||
{
|
||||
static roctracer_status_t roctracer_enable_activity_fun(roctracer_domain_t domain, uint32_t op,
|
||||
roctracer_pool_t* pool) {
|
||||
if (pool == NULL) pool = roctracer_default_pool();
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_HSA_OPS: {
|
||||
@@ -1008,27 +1008,31 @@ static roctracer_status_t roctracer_enable_activity_fun(
|
||||
const bool init_phase = (roctracer::RocpLoader::GetRef() == NULL);
|
||||
if (roctracer::RocpLoader::GetRef() == NULL) break;
|
||||
if (init_phase == true) {
|
||||
roctracer::RocpLoader::Instance().InitActivityCallback((void*)roctracer::HSA_AsyncActivityCallback,
|
||||
(void*)pool);
|
||||
roctracer::RocpLoader::Instance().InitActivityCallback(
|
||||
(void*)roctracer::HSA_AsyncActivityCallback, (void*)pool);
|
||||
}
|
||||
const bool succ = roctracer::RocpLoader::Instance().EnableActivityCallback(op, true);
|
||||
if (succ == false) HCC_EXC_RAISING(ROCTRACER_STATUS_HSA_ERR, "HSA::EnableActivityCallback error");
|
||||
if (succ == false)
|
||||
HCC_EXC_RAISING(ROCTRACER_STATUS_HSA_ERR, "HSA::EnableActivityCallback error");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HSA_API: break;
|
||||
case ACTIVITY_DOMAIN_HSA_EVT: break;
|
||||
case ACTIVITY_DOMAIN_HSA_API:
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HSA_EVT:
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS: {
|
||||
const bool init_phase = (roctracer::HccLoader::GetRef() == NULL);
|
||||
if (roctracer::HccLoader::Instance().Enabled() == false) break;
|
||||
|
||||
if (init_phase == true) {
|
||||
roctracer::HccLoader::Instance().InitActivityCallback((void*)roctracer::HCC_ActivityIdCallback,
|
||||
(void*)roctracer::HCC_AsyncActivityCallback,
|
||||
(void*)pool);
|
||||
roctracer::HccLoader::Instance().InitActivityCallback(
|
||||
(void*)roctracer::HCC_ActivityIdCallback, (void*)roctracer::HCC_AsyncActivityCallback,
|
||||
(void*)pool);
|
||||
}
|
||||
const bool succ = roctracer::HccLoader::Instance().EnableActivityCallback(op, true);
|
||||
if (succ == false) HCC_EXC_RAISING(ROCTRACER_STATUS_HCC_OPS_ERR, "HCC::EnableActivityCallback error");
|
||||
if (succ == false)
|
||||
HCC_EXC_RAISING(ROCTRACER_STATUS_HCC_OPS_ERR, "HCC::EnableActivityCallback error");
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
@@ -1036,41 +1040,38 @@ static roctracer_status_t roctracer_enable_activity_fun(
|
||||
std::lock_guard<roctracer::hip_activity_mutex_t> lock(roctracer::hip_activity_mutex);
|
||||
|
||||
if (roctracer::HipActActivityEnableCheck(op) == 0) {
|
||||
const hipError_t hip_err = roctracer::HipLoader::Instance().RegisterActivityCallback(op, (void*)roctracer::HIP_SyncActivityCallback, (void*)pool);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "HIP::RegisterActivityCallback(" << op << " error(" << hip_err << ")");
|
||||
const hipError_t hip_err = roctracer::HipLoader::Instance().RegisterActivityCallback(
|
||||
op, (void*)roctracer::HIP_SyncActivityCallback, (void*)pool);
|
||||
if (hip_err != hipSuccess)
|
||||
HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR,
|
||||
"HIP::RegisterActivityCallback(" << op << " error(" << hip_err << ")");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_ROCTX: break;
|
||||
case ACTIVITY_DOMAIN_ROCTX:
|
||||
break;
|
||||
default:
|
||||
EXC_RAISING(ROCTRACER_STATUS_BAD_DOMAIN, "invalid domain ID(" << domain << ")");
|
||||
}
|
||||
return ROCTRACER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void roctracer_enable_activity_impl(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op,
|
||||
roctracer_pool_t* pool)
|
||||
{
|
||||
roctracer::act_journal->Insert(domain, op, {pool});
|
||||
roctracer_enable_activity_fun(domain, op, pool);
|
||||
static void roctracer_enable_activity_impl(roctracer_domain_t domain, uint32_t op,
|
||||
roctracer_pool_t* pool) {
|
||||
roctracer::act_journal->Insert(domain, op, {pool});
|
||||
roctracer_enable_activity_fun(domain, op, pool);
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_op_activity_expl(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op,
|
||||
roctracer_pool_t* pool)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_op_activity_expl(roctracer_domain_t domain,
|
||||
uint32_t op,
|
||||
roctracer_pool_t* pool) {
|
||||
API_METHOD_PREFIX
|
||||
roctracer_enable_activity_impl(domain, op, pool);
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_domain_activity_expl(
|
||||
roctracer_domain_t domain,
|
||||
roctracer_pool_t* pool)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_domain_activity_expl(roctracer_domain_t domain,
|
||||
roctracer_pool_t* pool) {
|
||||
API_METHOD_PREFIX
|
||||
const uint32_t op_end = get_op_end(domain);
|
||||
for (uint32_t op = get_op_begin(domain); op < op_end; ++op)
|
||||
@@ -1078,9 +1079,7 @@ PUBLIC_API roctracer_status_t roctracer_enable_domain_activity_expl(
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_activity_expl(
|
||||
roctracer_pool_t* pool)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_enable_activity_expl(roctracer_pool_t* pool) {
|
||||
API_METHOD_PREFIX
|
||||
for (uint32_t domain = 0; domain < ACTIVITY_DOMAIN_NUMBER; ++domain) {
|
||||
const uint32_t op_end = get_op_end(domain);
|
||||
@@ -1091,10 +1090,7 @@ PUBLIC_API roctracer_status_t roctracer_enable_activity_expl(
|
||||
}
|
||||
|
||||
// Disable activity records logging
|
||||
static roctracer_status_t roctracer_disable_activity_fun(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op)
|
||||
{
|
||||
static roctracer_status_t roctracer_disable_activity_fun(roctracer_domain_t domain, uint32_t op) {
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_HSA_OPS: {
|
||||
if (op == HSA_OP_ID_COPY) {
|
||||
@@ -1102,17 +1098,23 @@ static roctracer_status_t roctracer_disable_activity_fun(
|
||||
} else {
|
||||
if (roctracer::RocpLoader::GetRef() == NULL) break;
|
||||
const bool succ = roctracer::RocpLoader::Instance().EnableActivityCallback(op, false);
|
||||
if (succ == false) HCC_EXC_RAISING(ROCTRACER_STATUS_HSA_ERR, "HSA::EnableActivityCallback(false) error, op(" << op << ")");
|
||||
if (succ == false)
|
||||
HCC_EXC_RAISING(ROCTRACER_STATUS_HSA_ERR,
|
||||
"HSA::EnableActivityCallback(false) error, op(" << op << ")");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HSA_API: break;
|
||||
case ACTIVITY_DOMAIN_HSA_EVT: break;
|
||||
case ACTIVITY_DOMAIN_HSA_API:
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HSA_EVT:
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HCC_OPS: {
|
||||
if (roctracer::HccLoader::Instance().Enabled() == false) break;
|
||||
|
||||
const bool succ = roctracer::HccLoader::Instance().EnableActivityCallback(op, false);
|
||||
if (succ == false) HCC_EXC_RAISING(ROCTRACER_STATUS_HCC_OPS_ERR, "HCC::EnableActivityCallback(NULL) error, op(" << op << ")");
|
||||
if (succ == false)
|
||||
HCC_EXC_RAISING(ROCTRACER_STATUS_HCC_OPS_ERR,
|
||||
"HCC::EnableActivityCallback(NULL) error, op(" << op << ")");
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
@@ -1121,40 +1123,40 @@ static roctracer_status_t roctracer_disable_activity_fun(
|
||||
|
||||
if (roctracer::HipActActivityDisableCheck(op) == 0) {
|
||||
const hipError_t hip_err = roctracer::HipLoader::Instance().RemoveActivityCallback(op);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "HIP::RemoveActivityCallback op(" << op << "), error(" << hip_err << ")");
|
||||
if (hip_err != hipSuccess)
|
||||
HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR,
|
||||
"HIP::RemoveActivityCallback op(" << op << "), error(" << hip_err << ")");
|
||||
} else {
|
||||
const hipError_t hip_err = roctracer::HipLoader::Instance().RegisterActivityCallback(op, (void*)roctracer::HIP_SyncApiDataCallback, (void*)1);
|
||||
if (hip_err != hipSuccess) HIP_EXC_RAISING(ROCTRACER_STATUS_HIP_API_ERR, "HIPACT: HIP::RegisterActivityCallback(" << op << ") error(" << hip_err << ")");
|
||||
const hipError_t hip_err = roctracer::HipLoader::Instance().RegisterActivityCallback(
|
||||
op, (void*)roctracer::HIP_SyncApiDataCallback, (void*)1);
|
||||
if (hip_err != hipSuccess)
|
||||
HIP_EXC_RAISING(
|
||||
ROCTRACER_STATUS_HIP_API_ERR,
|
||||
"HIPACT: HIP::RegisterActivityCallback(" << op << ") error(" << hip_err << ")");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_ROCTX: break;
|
||||
case ACTIVITY_DOMAIN_ROCTX:
|
||||
break;
|
||||
default:
|
||||
EXC_RAISING(ROCTRACER_STATUS_BAD_DOMAIN, "invalid domain ID(" << domain << ")");
|
||||
}
|
||||
return ROCTRACER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void roctracer_disable_activity_impl(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op)
|
||||
{
|
||||
static void roctracer_disable_activity_impl(roctracer_domain_t domain, uint32_t op) {
|
||||
roctracer::act_journal->Remove(domain, op);
|
||||
roctracer_disable_activity_fun(domain, op);
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_op_activity(
|
||||
roctracer_domain_t domain,
|
||||
uint32_t op)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_op_activity(roctracer_domain_t domain,
|
||||
uint32_t op) {
|
||||
API_METHOD_PREFIX
|
||||
roctracer_disable_activity_impl(domain, op);
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_domain_activity(
|
||||
roctracer_domain_t domain)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_domain_activity(roctracer_domain_t domain) {
|
||||
API_METHOD_PREFIX
|
||||
const uint32_t op_end = get_op_end(domain);
|
||||
for (uint32_t op = get_op_begin(domain); op < op_end; ++op)
|
||||
@@ -1162,8 +1164,7 @@ PUBLIC_API roctracer_status_t roctracer_disable_domain_activity(
|
||||
API_METHOD_SUFFIX
|
||||
}
|
||||
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_activity()
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_disable_activity() {
|
||||
API_METHOD_PREFIX
|
||||
for (uint32_t domain = 0; domain < ACTIVITY_DOMAIN_NUMBER; ++domain) {
|
||||
const uint32_t op_end = get_op_end(domain);
|
||||
@@ -1185,7 +1186,8 @@ PUBLIC_API roctracer_status_t roctracer_flush_activity_expl(roctracer_pool_t* po
|
||||
|
||||
// Notifies that the calling thread is entering an external API region.
|
||||
// Push an external correlation id for the calling thread.
|
||||
PUBLIC_API roctracer_status_t roctracer_activity_push_external_correlation_id(activity_correlation_id_t id) {
|
||||
PUBLIC_API roctracer_status_t
|
||||
roctracer_activity_push_external_correlation_id(activity_correlation_id_t id) {
|
||||
API_METHOD_PREFIX
|
||||
roctracer::external_id_stack.push(id);
|
||||
API_METHOD_SUFFIX
|
||||
@@ -1194,7 +1196,8 @@ PUBLIC_API roctracer_status_t roctracer_activity_push_external_correlation_id(ac
|
||||
// Notifies that the calling thread is leaving an external API region.
|
||||
// Pop an external correlation id for the calling thread.
|
||||
// 'lastId' returns the last external correlation
|
||||
PUBLIC_API roctracer_status_t roctracer_activity_pop_external_correlation_id(activity_correlation_id_t* last_id) {
|
||||
PUBLIC_API roctracer_status_t
|
||||
roctracer_activity_pop_external_correlation_id(activity_correlation_id_t* last_id) {
|
||||
API_METHOD_PREFIX
|
||||
if (last_id != NULL) *last_id = 0;
|
||||
|
||||
@@ -1214,7 +1217,8 @@ PUBLIC_API roctracer_status_t roctracer_activity_pop_external_correlation_id(act
|
||||
PUBLIC_API void roctracer_mark(const char* str) {
|
||||
if (mark_api_callback_ptr) {
|
||||
mark_api_callback_ptr(ACTIVITY_DOMAIN_EXT_API, ACTIVITY_EXT_OP_MARK, str, NULL);
|
||||
roctracer::GlobalCounter::Increment(); // account for user-defined markers when tracking correlation id
|
||||
roctracer::GlobalCounter::Increment(); // account for user-defined markers when tracking
|
||||
// correlation id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1245,15 +1249,14 @@ PUBLIC_API roctracer_status_t roctracer_get_timestamp(uint64_t* timestamp) {
|
||||
}
|
||||
|
||||
// Set properties
|
||||
PUBLIC_API roctracer_status_t roctracer_set_properties(
|
||||
roctracer_domain_t domain,
|
||||
void* properties)
|
||||
{
|
||||
PUBLIC_API roctracer_status_t roctracer_set_properties(roctracer_domain_t domain,
|
||||
void* properties) {
|
||||
API_METHOD_PREFIX
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_HSA_OPS: {
|
||||
// HSA OPS properties
|
||||
roctracer::hsa_ops_properties_t* ops_properties = reinterpret_cast<roctracer::hsa_ops_properties_t*>(properties);
|
||||
roctracer::hsa_ops_properties_t* ops_properties =
|
||||
reinterpret_cast<roctracer::hsa_ops_properties_t*>(properties);
|
||||
HsaApiTable* table = reinterpret_cast<HsaApiTable*>(ops_properties->table);
|
||||
roctracer::hsa_support::async_copy_callback_fun = ops_properties->async_copy_callback_fun;
|
||||
roctracer::hsa_support::async_copy_callback_arg = ops_properties->async_copy_callback_arg;
|
||||
@@ -1271,9 +1274,12 @@ PUBLIC_API roctracer_status_t roctracer_set_properties(
|
||||
hsa_status_t status = hsa_amd_profiling_async_copy_enable(true);
|
||||
if (status != HSA_STATUS_SUCCESS) EXC_ABORT(status, "hsa_amd_profiling_async_copy_enable");
|
||||
roctracer::hsa_amd_memory_async_copy_fn = table->amd_ext_->hsa_amd_memory_async_copy_fn;
|
||||
roctracer::hsa_amd_memory_async_copy_rect_fn = table->amd_ext_->hsa_amd_memory_async_copy_rect_fn;
|
||||
table->amd_ext_->hsa_amd_memory_async_copy_fn = roctracer::hsa_amd_memory_async_copy_interceptor;
|
||||
table->amd_ext_->hsa_amd_memory_async_copy_rect_fn = roctracer::hsa_amd_memory_async_copy_rect_interceptor;
|
||||
roctracer::hsa_amd_memory_async_copy_rect_fn =
|
||||
table->amd_ext_->hsa_amd_memory_async_copy_rect_fn;
|
||||
table->amd_ext_->hsa_amd_memory_async_copy_fn =
|
||||
roctracer::hsa_amd_memory_async_copy_interceptor;
|
||||
table->amd_ext_->hsa_amd_memory_async_copy_rect_fn =
|
||||
roctracer::hsa_amd_memory_async_copy_rect_interceptor;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1291,11 +1297,13 @@ PUBLIC_API roctracer_status_t roctracer_set_properties(
|
||||
case ACTIVITY_DOMAIN_HCC_OPS:
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
mark_api_callback_ptr = reinterpret_cast<mark_api_callback_t*>(properties);
|
||||
if (roctracer::hip_act_cb_tracker == NULL) roctracer::hip_act_cb_tracker = new roctracer::hip_act_cb_tracker_t;
|
||||
if (roctracer::hip_act_cb_tracker == NULL)
|
||||
roctracer::hip_act_cb_tracker = new roctracer::hip_act_cb_tracker_t;
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_EXT_API: {
|
||||
roctracer_ext_properties_t* ops_properties = reinterpret_cast<roctracer_ext_properties_t*>(properties);
|
||||
roctracer_ext_properties_t* ops_properties =
|
||||
reinterpret_cast<roctracer_ext_properties_t*>(properties);
|
||||
roctracer::ext_support::roctracer_start_cb = ops_properties->start_cb;
|
||||
roctracer::ext_support::roctracer_stop_cb = ops_properties->stop_cb;
|
||||
break;
|
||||
@@ -1349,7 +1357,8 @@ PUBLIC_API void roctracer_flush_buf() {
|
||||
CONSTRUCTOR_API void constructor() {
|
||||
ONLOAD_TRACE_BEG();
|
||||
roctracer::util::Logger::Create();
|
||||
roctracer::trace_buffer = new roctracer::TraceBuffer<roctracer::trace_entry_t>("HSA GPU", 0x200000, roctracer::trace_buffer_prm, 2);
|
||||
roctracer::trace_buffer = new roctracer::TraceBuffer<roctracer::trace_entry_t>(
|
||||
"HSA GPU", 0x200000, roctracer::trace_buffer_prm, 2);
|
||||
roctracer_load();
|
||||
ONLOAD_TRACE_END();
|
||||
}
|
||||
|
||||
@@ -50,11 +50,7 @@
|
||||
} while (0)
|
||||
|
||||
namespace roctracer {
|
||||
enum {
|
||||
TRACE_ENTRY_INV = 0,
|
||||
TRACE_ENTRY_INIT = 1,
|
||||
TRACE_ENTRY_COMPL = 2
|
||||
};
|
||||
enum { TRACE_ENTRY_INV = 0, TRACE_ENTRY_INIT = 1, TRACE_ENTRY_COMPL = 2 };
|
||||
|
||||
enum entry_type_t {
|
||||
DFLT_ENTRY_TYPE = 0,
|
||||
@@ -68,8 +64,8 @@ struct trace_entry_t {
|
||||
std::atomic<uint32_t> valid;
|
||||
entry_type_t type;
|
||||
uint64_t dispatch;
|
||||
uint64_t begin; // kernel begin timestamp, ns
|
||||
uint64_t end; // kernel end timestamp, ns
|
||||
uint64_t begin; // kernel begin timestamp, ns
|
||||
uint64_t end; // kernel end timestamp, ns
|
||||
uint64_t complete;
|
||||
hsa_agent_t agent;
|
||||
uint32_t dev_index;
|
||||
@@ -86,8 +82,7 @@ struct trace_entry_t {
|
||||
};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct push_element_fun {
|
||||
template <class T> struct push_element_fun {
|
||||
T* const elem_;
|
||||
T** prev_;
|
||||
bool fun(T* node) {
|
||||
@@ -105,10 +100,12 @@ struct push_element_fun {
|
||||
push_element_fun(T* elem, T** prev) : elem_(elem), prev_(prev) {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct call_element_fun {
|
||||
template <class T> struct call_element_fun {
|
||||
void (T::*fptr_)();
|
||||
bool fun(T* node) const { (node->*fptr_)(); return false; }
|
||||
bool fun(T* node) const {
|
||||
(node->*fptr_)();
|
||||
return false;
|
||||
}
|
||||
call_element_fun(void (T::*f)()) : fptr_(f) {}
|
||||
};
|
||||
|
||||
@@ -118,18 +115,26 @@ struct TraceBufferBase {
|
||||
virtual void StartWorkerThread() = 0;
|
||||
virtual void Flush() = 0;
|
||||
|
||||
static void StartWorkerThreadAll() { foreach(call_element_fun<TraceBufferBase>(&TraceBufferBase::StartWorkerThread)); }
|
||||
static void FlushAll() { foreach(call_element_fun<TraceBufferBase>(&TraceBufferBase::Flush)); }
|
||||
static void StartWorkerThreadAll() {
|
||||
foreach (call_element_fun<TraceBufferBase>(&TraceBufferBase::StartWorkerThread))
|
||||
;
|
||||
}
|
||||
static void FlushAll() {
|
||||
foreach (call_element_fun<TraceBufferBase>(&TraceBufferBase::Flush))
|
||||
;
|
||||
}
|
||||
|
||||
static void Push(TraceBufferBase* elem) {
|
||||
if (head_elem_ == NULL) head_elem_ = elem;
|
||||
else foreach(push_element_fun<TraceBufferBase>(elem, &head_elem_));
|
||||
if (head_elem_ == NULL)
|
||||
head_elem_ = elem;
|
||||
else
|
||||
foreach (push_element_fun<TraceBufferBase>(elem, &head_elem_))
|
||||
;
|
||||
}
|
||||
|
||||
TraceBufferBase(const uint32_t& prior) : priority_(prior), next_elem_(NULL) {}
|
||||
|
||||
template<class F>
|
||||
static void foreach(const F& f_in) {
|
||||
template <class F> static void foreach (const F& f_in) {
|
||||
std::lock_guard<mutex_t> lck(mutex_);
|
||||
F f = f_in;
|
||||
TraceBufferBase* p = head_elem_;
|
||||
@@ -146,9 +151,8 @@ struct TraceBufferBase {
|
||||
static mutex_t mutex_;
|
||||
};
|
||||
|
||||
template <typename Entry>
|
||||
class TraceBuffer : protected TraceBufferBase {
|
||||
public:
|
||||
template <typename Entry> class TraceBuffer : protected TraceBufferBase {
|
||||
public:
|
||||
typedef void (*callback_t)(Entry*);
|
||||
typedef TraceBuffer<Entry> Obj;
|
||||
typedef uint64_t pointer_t;
|
||||
@@ -161,11 +165,9 @@ class TraceBuffer : protected TraceBufferBase {
|
||||
callback_t fun;
|
||||
};
|
||||
|
||||
TraceBuffer(const char* name, uint32_t size, const flush_prm_t* flush_prm_arr, uint32_t flush_prm_count, uint32_t prior = 0) :
|
||||
TraceBufferBase(prior),
|
||||
size_(size),
|
||||
work_thread_started_(false)
|
||||
{
|
||||
TraceBuffer(const char* name, uint32_t size, const flush_prm_t* flush_prm_arr,
|
||||
uint32_t flush_prm_count, uint32_t prior = 0)
|
||||
: TraceBufferBase(prior), size_(size), work_thread_started_(false) {
|
||||
name_ = strdup(name);
|
||||
data_ = allocate_fun();
|
||||
next_ = allocate_fun();
|
||||
@@ -204,7 +206,7 @@ class TraceBuffer : protected TraceBufferBase {
|
||||
std::lock_guard<mutex_t> lck(mutex_);
|
||||
if (work_thread_started_ == true) {
|
||||
PTHREAD_CALL(pthread_cancel(work_thread_));
|
||||
void *res;
|
||||
void* res;
|
||||
PTHREAD_CALL(pthread_join(work_thread_, &res));
|
||||
if (res != PTHREAD_CANCELED) FATAL("consumer thread wasn't stopped correctly");
|
||||
work_thread_started_ = false;
|
||||
@@ -223,7 +225,7 @@ class TraceBuffer : protected TraceBufferBase {
|
||||
|
||||
void Flush() { flush_buf(); }
|
||||
|
||||
private:
|
||||
private:
|
||||
void flush_buf() {
|
||||
std::lock_guard<mutex_t> lck(mutex_);
|
||||
|
||||
@@ -231,7 +233,7 @@ class TraceBuffer : protected TraceBufferBase {
|
||||
pointer_t curr_pointer = write_pointer_.load(std::memory_order_relaxed);
|
||||
buf_list_it_t it = buf_list_.begin();
|
||||
buf_list_it_t end_it = buf_list_.end();
|
||||
while(it != end_it) {
|
||||
while (it != end_it) {
|
||||
Entry* buf = *it;
|
||||
Entry* ptr = buf + (pointer % size_);
|
||||
Entry* end_ptr = buf + size_;
|
||||
@@ -261,15 +263,13 @@ class TraceBuffer : protected TraceBufferBase {
|
||||
}
|
||||
|
||||
inline Entry* allocate_fun() {
|
||||
Entry* ptr = (Entry*) malloc(size_ * sizeof(Entry));
|
||||
Entry* ptr = (Entry*)malloc(size_ * sizeof(Entry));
|
||||
if (ptr == NULL) FATAL("malloc failed");
|
||||
//memset(ptr, 0, size_ * sizeof(Entry));
|
||||
// memset(ptr, 0, size_ * sizeof(Entry));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void free_fun(void* ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
inline void free_fun(void* ptr) { free(ptr); }
|
||||
|
||||
static void* allocate_worker(void* arg) {
|
||||
Obj* obj = (Obj*)arg;
|
||||
@@ -321,8 +321,8 @@ class TraceBuffer : protected TraceBufferBase {
|
||||
};
|
||||
} // namespace roctracer
|
||||
|
||||
#define TRACE_BUFFER_INSTANTIATE() \
|
||||
roctracer::TraceBufferBase* roctracer::TraceBufferBase::head_elem_ = NULL; \
|
||||
#define TRACE_BUFFER_INSTANTIATE() \
|
||||
roctracer::TraceBufferBase* roctracer::TraceBufferBase::head_elem_ = NULL; \
|
||||
roctracer::TraceBufferBase::mutex_t roctracer::TraceBufferBase::mutex_;
|
||||
|
||||
#endif // SRC_CORE_TRACE_BUFFER_H_
|
||||
|
||||
@@ -31,9 +31,7 @@ class HsaQueue : public Queue {
|
||||
public:
|
||||
HsaQueue(const util::AgentInfo* agent_info, hsa_queue_t* queue) : queue_(queue) {}
|
||||
|
||||
void Submit(const packet_t* packet) {
|
||||
util::HsaRsrcFactory::Instance().Submit(queue_, packet);
|
||||
}
|
||||
void Submit(const packet_t* packet) { util::HsaRsrcFactory::Instance().Submit(queue_, packet); }
|
||||
|
||||
private:
|
||||
hsa_queue_t* queue_;
|
||||
|
||||
@@ -27,10 +27,10 @@ void InterceptQueue::HsaIntercept(HsaApiTable* table) {
|
||||
}
|
||||
|
||||
InterceptQueue::mutex_t InterceptQueue::mutex_;
|
||||
//rocprofiler_callback_t InterceptQueue::dispatch_callback_ = NULL;
|
||||
//InterceptQueue::queue_callback_t InterceptQueue::create_callback_ = NULL;
|
||||
//InterceptQueue::queue_callback_t InterceptQueue::destroy_callback_ = NULL;
|
||||
//void* InterceptQueue::callback_data_ = NULL;
|
||||
// rocprofiler_callback_t InterceptQueue::dispatch_callback_ = NULL;
|
||||
// InterceptQueue::queue_callback_t InterceptQueue::create_callback_ = NULL;
|
||||
// InterceptQueue::queue_callback_t InterceptQueue::destroy_callback_ = NULL;
|
||||
// void* InterceptQueue::callback_data_ = NULL;
|
||||
InterceptQueue::obj_map_t* InterceptQueue::obj_map_ = NULL;
|
||||
const char* InterceptQueue::kernel_none_ = "";
|
||||
bool InterceptQueue::in_create_call_ = false;
|
||||
|
||||
@@ -37,7 +37,9 @@
|
||||
#include "util/hsa_rsrc_factory.h"
|
||||
#include "util/exception.h"
|
||||
|
||||
namespace roctracer { extern TraceBuffer<trace_entry_t>* trace_buffer; }
|
||||
namespace roctracer {
|
||||
extern TraceBuffer<trace_entry_t>* trace_buffer;
|
||||
}
|
||||
|
||||
namespace rocprofiler {
|
||||
extern decltype(hsa_queue_create)* hsa_queue_create_fn;
|
||||
@@ -48,25 +50,25 @@ class InterceptQueue {
|
||||
typedef std::recursive_mutex mutex_t;
|
||||
typedef std::map<uint64_t, InterceptQueue*> obj_map_t;
|
||||
typedef hsa_status_t (*queue_callback_t)(hsa_queue_t*, void* data);
|
||||
typedef void (*queue_event_callback_t)(hsa_status_t status, hsa_queue_t *queue, void *arg);
|
||||
typedef void (*queue_event_callback_t)(hsa_status_t status, hsa_queue_t* queue, void* arg);
|
||||
typedef uint32_t queue_id_t;
|
||||
|
||||
static void HsaIntercept(HsaApiTable* table);
|
||||
|
||||
static hsa_status_t InterceptQueueCreate(hsa_agent_t agent, uint32_t size, hsa_queue_type32_t type,
|
||||
void (*callback)(hsa_status_t status, hsa_queue_t* source,
|
||||
void* data),
|
||||
void* data, uint32_t private_segment_size,
|
||||
uint32_t group_segment_size, hsa_queue_t** queue,
|
||||
const bool& tracker_on) {
|
||||
static hsa_status_t InterceptQueueCreate(
|
||||
hsa_agent_t agent, uint32_t size, hsa_queue_type32_t type,
|
||||
void (*callback)(hsa_status_t status, hsa_queue_t* source, void* data), void* data,
|
||||
uint32_t private_segment_size, uint32_t group_segment_size, hsa_queue_t** queue,
|
||||
const bool& tracker_on) {
|
||||
std::lock_guard<mutex_t> lck(mutex_);
|
||||
hsa_status_t status = HSA_STATUS_ERROR;
|
||||
|
||||
if (in_create_call_) EXC_ABORT(status, "recursive InterceptQueueCreate()");
|
||||
in_create_call_ = true;
|
||||
|
||||
ProxyQueue* proxy = ProxyQueue::Create(agent, size, type, queue_event_callback, data, private_segment_size,
|
||||
group_segment_size, queue, &status);
|
||||
ProxyQueue* proxy =
|
||||
ProxyQueue::Create(agent, size, type, queue_event_callback, data, private_segment_size,
|
||||
group_segment_size, queue, &status);
|
||||
if (status != HSA_STATUS_SUCCESS) EXC_ABORT(status, "ProxyQueue::Create()");
|
||||
|
||||
status = util::HsaRsrcFactory::HsaApi()->hsa_amd_profiling_set_profiler_enabled(*queue, true);
|
||||
@@ -78,7 +80,8 @@ class InterceptQueue {
|
||||
obj->queue_id = current_queue_id;
|
||||
(*obj_map_)[(uint64_t)(*queue)] = obj;
|
||||
|
||||
status = (is_enabled) ? proxy->SetInterceptCB(OnSubmitCB, obj) : proxy->SetInterceptCB(OnSubmitCB_dummy, obj);
|
||||
status = (is_enabled) ? proxy->SetInterceptCB(OnSubmitCB, obj)
|
||||
: proxy->SetInterceptCB(OnSubmitCB_dummy, obj);
|
||||
|
||||
#if 0
|
||||
if (create_callback_ != NULL) {
|
||||
@@ -96,15 +99,17 @@ class InterceptQueue {
|
||||
void* data),
|
||||
void* data, uint32_t private_segment_size,
|
||||
uint32_t group_segment_size, hsa_queue_t** queue) {
|
||||
return InterceptQueueCreate(agent, size, type, callback, data, private_segment_size, group_segment_size, queue, false);
|
||||
return InterceptQueueCreate(agent, size, type, callback, data, private_segment_size,
|
||||
group_segment_size, queue, false);
|
||||
}
|
||||
|
||||
static hsa_status_t QueueCreateTracked(hsa_agent_t agent, uint32_t size, hsa_queue_type32_t type,
|
||||
void (*callback)(hsa_status_t status, hsa_queue_t* source,
|
||||
void* data),
|
||||
void* data, uint32_t private_segment_size,
|
||||
uint32_t group_segment_size, hsa_queue_t** queue) {
|
||||
return InterceptQueueCreate(agent, size, type, callback, data, private_segment_size, group_segment_size, queue, true);
|
||||
void (*callback)(hsa_status_t status, hsa_queue_t* source,
|
||||
void* data),
|
||||
void* data, uint32_t private_segment_size,
|
||||
uint32_t group_segment_size, hsa_queue_t** queue) {
|
||||
return InterceptQueueCreate(agent, size, type, callback, data, private_segment_size,
|
||||
group_segment_size, queue, true);
|
||||
}
|
||||
|
||||
static hsa_status_t QueueDestroy(hsa_queue_t* queue) {
|
||||
@@ -122,8 +127,8 @@ class InterceptQueue {
|
||||
return status;
|
||||
}
|
||||
|
||||
static void OnSubmitCB_dummy(const void* in_packets, uint64_t count, uint64_t user_que_idx, void* data,
|
||||
hsa_amd_queue_intercept_packet_writer writer) {
|
||||
static void OnSubmitCB_dummy(const void* in_packets, uint64_t count, uint64_t user_que_idx,
|
||||
void* data, hsa_amd_queue_intercept_packet_writer writer) {
|
||||
const packet_t* packets_arr = reinterpret_cast<const packet_t*>(in_packets);
|
||||
|
||||
// Submitting the original packets if profiling was not enabled
|
||||
@@ -161,8 +166,10 @@ class InterceptQueue {
|
||||
::proxy::Tracker::entry_t* entry = roctracer::trace_buffer->GetEntry();
|
||||
entry->kernel.tid = syscall(__NR_gettid);
|
||||
entry->kernel.name = kernel_name;
|
||||
::proxy::Tracker::Enable(roctracer::KERNEL_ENTRY_TYPE, obj->agent_info_->dev_id, completion_signal, entry);
|
||||
const_cast<hsa_kernel_dispatch_packet_t*>(dispatch_packet)->completion_signal = entry->signal;
|
||||
::proxy::Tracker::Enable(roctracer::KERNEL_ENTRY_TYPE, obj->agent_info_->dev_id,
|
||||
completion_signal, entry);
|
||||
const_cast<hsa_kernel_dispatch_packet_t*>(dispatch_packet)->completion_signal =
|
||||
entry->signal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +197,7 @@ class InterceptQueue {
|
||||
static void Enable(bool val) { is_enabled = val; }
|
||||
|
||||
private:
|
||||
static void queue_event_callback(hsa_status_t status, hsa_queue_t *queue, void *arg) {
|
||||
static void queue_event_callback(hsa_status_t status, hsa_queue_t* queue, void* arg) {
|
||||
if (status != HSA_STATUS_SUCCESS) EXC_ABORT(status, "queue error handling is not supported");
|
||||
InterceptQueue* obj = GetObj(queue);
|
||||
if (obj->queue_event_callback_) obj->queue_event_callback_(status, obj->queue_, arg);
|
||||
@@ -201,7 +208,8 @@ class InterceptQueue {
|
||||
return static_cast<hsa_packet_type_t>((*header >> HSA_PACKET_HEADER_TYPE) & header_type_mask);
|
||||
}
|
||||
|
||||
static const amd_kernel_code_t* GetKernelCode(const hsa_kernel_dispatch_packet_t* dispatch_packet) {
|
||||
static const amd_kernel_code_t* GetKernelCode(
|
||||
const hsa_kernel_dispatch_packet_t* dispatch_packet) {
|
||||
const amd_kernel_code_t* kernel_code = NULL;
|
||||
hsa_status_t status =
|
||||
util::HsaRsrcFactory::Instance().LoaderApi()->hsa_ven_amd_loader_query_host_address(
|
||||
@@ -256,22 +264,19 @@ class InterceptQueue {
|
||||
assert(queue == obj->queue_);
|
||||
delete obj;
|
||||
obj_map_->erase(it);
|
||||
status = HSA_STATUS_SUCCESS;;
|
||||
status = HSA_STATUS_SUCCESS;
|
||||
;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
InterceptQueue(const hsa_agent_t& agent, hsa_queue_t* const queue, ProxyQueue* proxy) :
|
||||
queue_(queue),
|
||||
proxy_(proxy)
|
||||
{
|
||||
InterceptQueue(const hsa_agent_t& agent, hsa_queue_t* const queue, ProxyQueue* proxy)
|
||||
: queue_(queue), proxy_(proxy) {
|
||||
agent_info_ = util::HsaRsrcFactory::Instance().GetAgentInfo(agent);
|
||||
queue_event_callback_ = NULL;
|
||||
}
|
||||
|
||||
~InterceptQueue() {
|
||||
ProxyQueue::Destroy(proxy_);
|
||||
}
|
||||
~InterceptQueue() { ProxyQueue::Destroy(proxy_); }
|
||||
|
||||
static bool is_enabled;
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ ProxyQueue* ProxyQueue::Create(hsa_agent_t agent, uint32_t size, hsa_queue_type3
|
||||
hsa_status_t* status) {
|
||||
hsa_status_t suc = HSA_STATUS_ERROR;
|
||||
ProxyQueue* instance =
|
||||
(rocp_type_) ? (ProxyQueue*) new SimpleProxyQueue() : (ProxyQueue*) new HsaProxyQueue();
|
||||
(rocp_type_) ? (ProxyQueue*)new SimpleProxyQueue() : (ProxyQueue*)new HsaProxyQueue();
|
||||
if (instance != NULL) {
|
||||
suc = instance->Init(agent, size, type, callback, data, private_segment_size,
|
||||
group_segment_size, queue);
|
||||
group_segment_size, queue);
|
||||
if (suc != HSA_STATUS_SUCCESS) {
|
||||
delete instance;
|
||||
instance = NULL;
|
||||
|
||||
@@ -25,13 +25,19 @@ void SimpleProxyQueue::HsaIntercept(HsaApiTable* table) {
|
||||
table->core_->hsa_signal_store_relaxed_fn = rocprofiler::SimpleProxyQueue::SignalStore;
|
||||
table->core_->hsa_signal_store_screlease_fn = rocprofiler::SimpleProxyQueue::SignalStore;
|
||||
|
||||
table->core_->hsa_queue_load_write_index_relaxed_fn = rocprofiler::SimpleProxyQueue::GetQueueIndex;
|
||||
table->core_->hsa_queue_store_write_index_relaxed_fn = rocprofiler::SimpleProxyQueue::SetQueueIndex;
|
||||
table->core_->hsa_queue_load_read_index_relaxed_fn = rocprofiler::SimpleProxyQueue::GetSubmitIndex;
|
||||
table->core_->hsa_queue_load_write_index_relaxed_fn =
|
||||
rocprofiler::SimpleProxyQueue::GetQueueIndex;
|
||||
table->core_->hsa_queue_store_write_index_relaxed_fn =
|
||||
rocprofiler::SimpleProxyQueue::SetQueueIndex;
|
||||
table->core_->hsa_queue_load_read_index_relaxed_fn =
|
||||
rocprofiler::SimpleProxyQueue::GetSubmitIndex;
|
||||
|
||||
table->core_->hsa_queue_load_write_index_scacquire_fn = rocprofiler::SimpleProxyQueue::GetQueueIndex;
|
||||
table->core_->hsa_queue_store_write_index_screlease_fn = rocprofiler::SimpleProxyQueue::SetQueueIndex;
|
||||
table->core_->hsa_queue_load_read_index_scacquire_fn = rocprofiler::SimpleProxyQueue::GetSubmitIndex;
|
||||
table->core_->hsa_queue_load_write_index_scacquire_fn =
|
||||
rocprofiler::SimpleProxyQueue::GetQueueIndex;
|
||||
table->core_->hsa_queue_store_write_index_screlease_fn =
|
||||
rocprofiler::SimpleProxyQueue::SetQueueIndex;
|
||||
table->core_->hsa_queue_load_read_index_scacquire_fn =
|
||||
rocprofiler::SimpleProxyQueue::GetSubmitIndex;
|
||||
}
|
||||
|
||||
SimpleProxyQueue::queue_map_t* SimpleProxyQueue::queue_map_ = NULL;
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "util/hsa_rsrc_factory.h"
|
||||
|
||||
#ifndef ROCP_PROXY_LOCK
|
||||
# define ROCP_PROXY_LOCK 1
|
||||
#define ROCP_PROXY_LOCK 1
|
||||
#endif
|
||||
|
||||
namespace rocprofiler {
|
||||
@@ -125,7 +125,8 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
const uint64_t que_idx = hsa_queue_load_write_index_relaxed_fn(queue_);
|
||||
|
||||
// Waiting untill there is a free space in the queue
|
||||
while (que_idx >= (hsa_queue_load_read_index_relaxed_fn(queue_) + size_));
|
||||
while (que_idx >= (hsa_queue_load_read_index_relaxed_fn(queue_) + size_))
|
||||
;
|
||||
|
||||
// Increment the write index
|
||||
hsa_queue_store_write_index_relaxed_fn(queue_, que_idx + 1);
|
||||
@@ -160,8 +161,7 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
queue_mask_(0),
|
||||
submit_index_(0),
|
||||
on_submit_cb_(NULL),
|
||||
on_submit_cb_data_(NULL)
|
||||
{
|
||||
on_submit_cb_data_(NULL) {
|
||||
printf("ROCProfiler: SimpleProxyQueue is enabled\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -200,8 +200,8 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
|
||||
if (queue_map_ == NULL) queue_map_ = new queue_map_t;
|
||||
(*queue_map_)[queue_->doorbell_signal.handle] = this;
|
||||
}
|
||||
else abort();
|
||||
} else
|
||||
abort();
|
||||
}
|
||||
}
|
||||
if (status != HSA_STATUS_SUCCESS) abort();
|
||||
|
||||
+17
-11
@@ -35,20 +35,21 @@
|
||||
|
||||
namespace proxy {
|
||||
class Tracker {
|
||||
public:
|
||||
public:
|
||||
typedef util::HsaRsrcFactory::timestamp_t timestamp_t;
|
||||
typedef roctracer::trace_entry_t entry_t;
|
||||
typedef roctracer::entry_type_t entry_type_t;
|
||||
|
||||
// Add tracker entry
|
||||
inline static void Enable(entry_type_t type, const hsa_agent_t& agent, const hsa_signal_t& signal, entry_t* entry) {
|
||||
inline static void Enable(entry_type_t type, const hsa_agent_t& agent, const hsa_signal_t& signal,
|
||||
entry_t* entry) {
|
||||
hsa_status_t status = HSA_STATUS_ERROR;
|
||||
util::HsaRsrcFactory* hsa_rsrc = &(util::HsaRsrcFactory::Instance());
|
||||
|
||||
// Creating a new tracker entry
|
||||
entry->type = type;
|
||||
entry->agent = agent;
|
||||
entry->dev_index = 0; //hsa_rsrc->GetAgentInfo(agent)->dev_index;
|
||||
entry->dev_index = 0; // hsa_rsrc->GetAgentInfo(agent)->dev_index;
|
||||
entry->orig = signal;
|
||||
entry->dispatch = hsa_rsrc->TimestampNs();
|
||||
entry->valid.store(roctracer::TRACE_ENTRY_INIT, std::memory_order_release);
|
||||
@@ -56,7 +57,8 @@ class Tracker {
|
||||
// Creating a proxy signal
|
||||
status = hsa_signal_create(1, 0, NULL, &(entry->signal));
|
||||
if (status != HSA_STATUS_SUCCESS) EXC_RAISING(status, "hsa_signal_create");
|
||||
status = hsa_amd_signal_async_handler(entry->signal, HSA_SIGNAL_CONDITION_LT, 1, Handler, entry);
|
||||
status =
|
||||
hsa_amd_signal_async_handler(entry->signal, HSA_SIGNAL_CONDITION_LT, 1, Handler, entry);
|
||||
if (status != HSA_STATUS_SUCCESS) EXC_RAISING(status, "hsa_amd_signal_async_handler");
|
||||
}
|
||||
|
||||
@@ -66,7 +68,7 @@ class Tracker {
|
||||
entry->valid.store(roctracer::TRACE_ENTRY_INV, std::memory_order_release);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
// Entry completion
|
||||
inline static void Complete(hsa_signal_value_t signal_value, entry_t* entry) {
|
||||
// Query begin/end and complete timestamps
|
||||
@@ -74,12 +76,14 @@ class Tracker {
|
||||
if (entry->type == roctracer::COPY_ENTRY_TYPE) {
|
||||
hsa_amd_profiling_async_copy_time_t async_copy_time{};
|
||||
hsa_status_t status = hsa_amd_profiling_get_async_copy_time(entry->signal, &async_copy_time);
|
||||
if (status != HSA_STATUS_SUCCESS) EXC_RAISING(status, "hsa_amd_profiling_get_async_copy_time");
|
||||
if (status != HSA_STATUS_SUCCESS)
|
||||
EXC_RAISING(status, "hsa_amd_profiling_get_async_copy_time");
|
||||
entry->begin = hsa_rsrc->SysclockToNs(async_copy_time.start);
|
||||
entry->end = hsa_rsrc->SysclockToNs(async_copy_time.end);
|
||||
} else {
|
||||
hsa_amd_profiling_dispatch_time_t dispatch_time{};
|
||||
hsa_status_t status = hsa_amd_profiling_get_dispatch_time(entry->agent, entry->signal, &dispatch_time);
|
||||
hsa_status_t status =
|
||||
hsa_amd_profiling_get_dispatch_time(entry->agent, entry->signal, &dispatch_time);
|
||||
if (status != HSA_STATUS_SUCCESS) EXC_RAISING(status, "hsa_amd_profiling_get_dispatch_time");
|
||||
entry->begin = hsa_rsrc->SysclockToNs(dispatch_time.start);
|
||||
entry->end = hsa_rsrc->SysclockToNs(dispatch_time.end);
|
||||
@@ -101,7 +105,8 @@ class Tracker {
|
||||
orig_signal_ptr->end_ts = prof_signal_ptr->end_ts;
|
||||
|
||||
const hsa_signal_value_t new_value = hsa_signal_load_relaxed(orig) - 1;
|
||||
if (signal_value != new_value) EXC_ABORT(HSA_STATUS_ERROR, "Tracker::Complete bad signal value");
|
||||
if (signal_value != new_value)
|
||||
EXC_ABORT(HSA_STATUS_ERROR, "Tracker::Complete bad signal value");
|
||||
hsa_signal_store_screlease(orig, signal_value);
|
||||
}
|
||||
hsa_signal_destroy(signal);
|
||||
@@ -111,7 +116,8 @@ class Tracker {
|
||||
static bool Handler(hsa_signal_value_t signal_value, void* arg) {
|
||||
// Acquire entry
|
||||
entry_t* entry = reinterpret_cast<entry_t*>(arg);
|
||||
while (entry->valid.load(std::memory_order_acquire) != roctracer::TRACE_ENTRY_INIT) sched_yield();
|
||||
while (entry->valid.load(std::memory_order_acquire) != roctracer::TRACE_ENTRY_INIT)
|
||||
sched_yield();
|
||||
|
||||
// Complete entry
|
||||
Tracker::Complete(signal_value, entry);
|
||||
@@ -119,6 +125,6 @@ class Tracker {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace rocprofiler
|
||||
} // namespace proxy
|
||||
|
||||
#endif // SRC_PROXY_TRACKER_H_
|
||||
#endif // SRC_PROXY_TRACKER_H_
|
||||
|
||||
@@ -34,11 +34,12 @@ typedef hsa_ext_amd_aql_pm4_packet_t packet_t;
|
||||
typedef uint32_t packet_word_t;
|
||||
typedef uint64_t timestamp_t;
|
||||
|
||||
inline std::ostream& operator<< (std::ostream& out, const event_t& event) {
|
||||
out << "[block_name(" << event.block_name << "). block_index(" << event.block_index << "). counter_id(" << event.counter_id << ")]";
|
||||
inline std::ostream& operator<<(std::ostream& out, const event_t& event) {
|
||||
out << "[block_name(" << event.block_name << "). block_index(" << event.block_index
|
||||
<< "). counter_id(" << event.counter_id << ")]";
|
||||
return out;
|
||||
}
|
||||
inline std::ostream& operator<< (std::ostream& out, const parameter_t& parameter) {
|
||||
inline std::ostream& operator<<(std::ostream& out, const parameter_t& parameter) {
|
||||
out << "[parameter_name(" << parameter.parameter_name << "). value(" << parameter.value << ")]";
|
||||
return out;
|
||||
}
|
||||
|
||||
+22
-12
@@ -37,7 +37,6 @@
|
||||
#define API_METHOD_PREFIX \
|
||||
roctx_status_t err = ROCTX_STATUS_SUCCESS; \
|
||||
try {
|
||||
|
||||
#define API_METHOD_SUFFIX \
|
||||
} \
|
||||
catch (std::exception & e) { \
|
||||
@@ -52,7 +51,7 @@
|
||||
ERR_LOGGING(__FUNCTION__ << "(), " << e.what()); \
|
||||
err = roctx::GetExcStatus(e); \
|
||||
} \
|
||||
(void)err; \
|
||||
(void)err;
|
||||
|
||||
#define API_METHOD_CATCH(X) \
|
||||
} \
|
||||
@@ -84,8 +83,10 @@ thread_map_t thread_map;
|
||||
static thread_local message_stack_t* message_stack = NULL;
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
void thread_data_init() {
|
||||
@@ -124,7 +125,8 @@ PUBLIC_API void roctxMarkA(const char* 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);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxMarkA, &api_data, api_callback_arg);
|
||||
API_METHOD_SUFFIX_NRET
|
||||
}
|
||||
|
||||
@@ -137,7 +139,9 @@ PUBLIC_API int roctxRangePushA(const char* 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);
|
||||
if (api_callback_fun) api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangePushA, &api_data, api_callback_arg);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangePushA, &api_data,
|
||||
api_callback_arg);
|
||||
roctx::message_stack->push(strdup(message));
|
||||
|
||||
return roctx::message_stack->size() - 1;
|
||||
@@ -152,11 +156,13 @@ PUBLIC_API int roctxRangePop() {
|
||||
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);
|
||||
if (api_callback_fun) api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangePop, &api_data, api_callback_arg);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangePop, &api_data,
|
||||
api_callback_arg);
|
||||
if (roctx::message_stack->empty()) {
|
||||
EXC_ABORT(ROCTX_STATUS_ERROR, "Pop from empty stack!");
|
||||
EXC_ABORT(ROCTX_STATUS_ERROR, "Pop from empty stack!");
|
||||
} else {
|
||||
roctx::message_stack->pop();
|
||||
roctx::message_stack->pop();
|
||||
}
|
||||
|
||||
return roctx::message_stack->size();
|
||||
@@ -173,7 +179,9 @@ PUBLIC_API roctx_range_id_t roctxRangeStartA(const char* message) {
|
||||
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);
|
||||
if (api_callback_fun) api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangeStartA, &api_data, api_callback_arg);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangeStartA, &api_data,
|
||||
api_callback_arg);
|
||||
|
||||
return roctx_range_counter;
|
||||
API_METHOD_CATCH(-1);
|
||||
@@ -186,14 +194,16 @@ PUBLIC_API void roctxRangeStop(roctx_range_id_t 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);
|
||||
if (api_callback_fun) api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangeStop, &api_data, api_callback_arg);
|
||||
if (api_callback_fun)
|
||||
api_callback_fun(ACTIVITY_DOMAIN_ROCTX, ROCTX_API_ID_roctxRangeStop, &api_data,
|
||||
api_callback_arg);
|
||||
API_METHOD_SUFFIX_NRET
|
||||
}
|
||||
|
||||
PUBLIC_API void RangeStackIterate(roctx_range_iterate_cb_t callback, void* arg) {
|
||||
for (const auto& entry : roctx::thread_map) {
|
||||
const auto tid = entry.first;
|
||||
for (roctx::message_stack_t stack = *(entry.second); !stack.empty(); stack.pop()){
|
||||
for (roctx::message_stack_t stack = *(entry.second); !stack.empty(); stack.pop()) {
|
||||
std::string message = stack.top();
|
||||
roctx_range_data_t data{};
|
||||
data.message = message.c_str();
|
||||
|
||||
@@ -45,8 +45,6 @@ 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);
|
||||
}
|
||||
PUBLIC_API bool RemoveApiCallback(uint32_t op) { return roctx::cb_table.set(op, NULL, NULL); }
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -43,12 +43,12 @@
|
||||
#define HCC_EXC_RAISING(error, stream) \
|
||||
do { \
|
||||
EXC_RAISING(error, "HCC error: " << stream); \
|
||||
} while(0)
|
||||
} while (0)
|
||||
|
||||
#define HIP_EXC_RAISING(error, stream) \
|
||||
do { \
|
||||
EXC_RAISING(error, "HIP error: " << stream); \
|
||||
} while(0)
|
||||
} while (0)
|
||||
|
||||
namespace roctracer {
|
||||
namespace util {
|
||||
|
||||
@@ -69,13 +69,15 @@ static hsa_status_t FindGlobalPool(hsa_amd_memory_pool_t pool, void* data, bool
|
||||
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
err = HsaRsrcFactory::HsaApi()->hsa_amd_memory_pool_get_info(pool, HSA_AMD_MEMORY_POOL_INFO_SEGMENT, &segment);
|
||||
err = HsaRsrcFactory::HsaApi()->hsa_amd_memory_pool_get_info(
|
||||
pool, HSA_AMD_MEMORY_POOL_INFO_SEGMENT, &segment);
|
||||
CHECK_STATUS("hsa_amd_memory_pool_get_info", err);
|
||||
if (HSA_AMD_SEGMENT_GLOBAL != segment) {
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
err = HsaRsrcFactory::HsaApi()->hsa_amd_memory_pool_get_info(pool, HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS, &flag);
|
||||
err = HsaRsrcFactory::HsaApi()->hsa_amd_memory_pool_get_info(
|
||||
pool, HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS, &flag);
|
||||
CHECK_STATUS("hsa_amd_memory_pool_get_info", err);
|
||||
|
||||
uint32_t karg_st = flag & HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT;
|
||||
@@ -128,19 +130,22 @@ HsaRsrcFactory::HsaRsrcFactory(bool initialize_hsa) : initialize_hsa_(initialize
|
||||
#ifdef ROCP_LD_AQLPROFILE
|
||||
status = LoadAqlProfileLib(&aqlprofile_api_);
|
||||
#else
|
||||
status = hsa_api_.hsa_system_get_major_extension_table(HSA_EXTENSION_AMD_AQLPROFILE, hsa_ven_amd_aqlprofile_VERSION_MAJOR, sizeof(aqlprofile_api_), &aqlprofile_api_);
|
||||
status = hsa_api_.hsa_system_get_major_extension_table(HSA_EXTENSION_AMD_AQLPROFILE,
|
||||
hsa_ven_amd_aqlprofile_VERSION_MAJOR,
|
||||
sizeof(aqlprofile_api_), &aqlprofile_api_);
|
||||
#endif
|
||||
CHECK_STATUS("aqlprofile API table load failed", status);
|
||||
|
||||
// Get Loader API table
|
||||
loader_api_ = {0};
|
||||
status = hsa_api_.hsa_system_get_major_extension_table(HSA_EXTENSION_AMD_LOADER, 1, sizeof(loader_api_), &loader_api_);
|
||||
status = hsa_api_.hsa_system_get_major_extension_table(HSA_EXTENSION_AMD_LOADER, 1,
|
||||
sizeof(loader_api_), &loader_api_);
|
||||
CHECK_STATUS("loader API table query failed", status);
|
||||
|
||||
// Instantiate HSA timer
|
||||
timer_ = new HsaTimer(&hsa_api_);
|
||||
CHECK_STATUS("HSA timer allocation failed",
|
||||
(timer_ == NULL) ? HSA_STATUS_ERROR : HSA_STATUS_SUCCESS);
|
||||
(timer_ == NULL) ? HSA_STATUS_ERROR : HSA_STATUS_SUCCESS);
|
||||
|
||||
// Time correlation
|
||||
const uint32_t corr_iters = 1000;
|
||||
@@ -148,7 +153,8 @@ HsaRsrcFactory::HsaRsrcFactory(bool initialize_hsa) : initialize_hsa_(initialize
|
||||
CorrelateTime(HsaTimer::TIME_ID_CLOCK_MONOTONIC, corr_iters);
|
||||
|
||||
// System timeout
|
||||
timeout_ = (timeout_ns_ == HsaTimer::TIMESTAMP_MAX) ? timeout_ns_ : timer_->ns_to_sysclock(timeout_ns_);
|
||||
timeout_ =
|
||||
(timeout_ns_ == HsaTimer::TIMESTAMP_MAX) ? timeout_ns_ : timer_->ns_to_sysclock(timeout_ns_);
|
||||
}
|
||||
|
||||
// Destructor of the class
|
||||
@@ -174,9 +180,12 @@ void HsaRsrcFactory::InitHsaApiTable(HsaApiTable* table) {
|
||||
|
||||
hsa_api_.hsa_queue_create = table->core_->hsa_queue_create_fn;
|
||||
hsa_api_.hsa_queue_destroy = table->core_->hsa_queue_destroy_fn;
|
||||
hsa_api_.hsa_queue_load_write_index_relaxed = table->core_->hsa_queue_load_write_index_relaxed_fn;
|
||||
hsa_api_.hsa_queue_store_write_index_relaxed = table->core_->hsa_queue_store_write_index_relaxed_fn;
|
||||
hsa_api_.hsa_queue_load_read_index_relaxed = table->core_->hsa_queue_load_read_index_relaxed_fn;
|
||||
hsa_api_.hsa_queue_load_write_index_relaxed =
|
||||
table->core_->hsa_queue_load_write_index_relaxed_fn;
|
||||
hsa_api_.hsa_queue_store_write_index_relaxed =
|
||||
table->core_->hsa_queue_store_write_index_relaxed_fn;
|
||||
hsa_api_.hsa_queue_load_read_index_relaxed =
|
||||
table->core_->hsa_queue_load_read_index_relaxed_fn;
|
||||
|
||||
hsa_api_.hsa_signal_create = table->core_->hsa_signal_create_fn;
|
||||
hsa_api_.hsa_signal_destroy = table->core_->hsa_signal_destroy_fn;
|
||||
@@ -185,18 +194,22 @@ void HsaRsrcFactory::InitHsaApiTable(HsaApiTable* table) {
|
||||
hsa_api_.hsa_signal_wait_scacquire = table->core_->hsa_signal_wait_scacquire_fn;
|
||||
hsa_api_.hsa_signal_store_screlease = table->core_->hsa_signal_store_screlease_fn;
|
||||
|
||||
hsa_api_.hsa_code_object_reader_create_from_file = table->core_->hsa_code_object_reader_create_from_file_fn;
|
||||
hsa_api_.hsa_code_object_reader_create_from_file =
|
||||
table->core_->hsa_code_object_reader_create_from_file_fn;
|
||||
hsa_api_.hsa_executable_create_alt = table->core_->hsa_executable_create_alt_fn;
|
||||
hsa_api_.hsa_executable_load_agent_code_object = table->core_->hsa_executable_load_agent_code_object_fn;
|
||||
hsa_api_.hsa_executable_load_agent_code_object =
|
||||
table->core_->hsa_executable_load_agent_code_object_fn;
|
||||
hsa_api_.hsa_executable_freeze = table->core_->hsa_executable_freeze_fn;
|
||||
hsa_api_.hsa_executable_get_symbol = table->core_->hsa_executable_get_symbol_fn;
|
||||
hsa_api_.hsa_executable_symbol_get_info = table->core_->hsa_executable_symbol_get_info_fn;
|
||||
hsa_api_.hsa_executable_iterate_symbols = table->core_->hsa_executable_iterate_symbols_fn;
|
||||
|
||||
hsa_api_.hsa_system_get_info = table->core_->hsa_system_get_info_fn;
|
||||
hsa_api_.hsa_system_get_major_extension_table = table->core_->hsa_system_get_major_extension_table_fn;
|
||||
hsa_api_.hsa_system_get_major_extension_table =
|
||||
table->core_->hsa_system_get_major_extension_table_fn;
|
||||
|
||||
hsa_api_.hsa_amd_agent_iterate_memory_pools = table->amd_ext_->hsa_amd_agent_iterate_memory_pools_fn;
|
||||
hsa_api_.hsa_amd_agent_iterate_memory_pools =
|
||||
table->amd_ext_->hsa_amd_agent_iterate_memory_pools_fn;
|
||||
hsa_api_.hsa_amd_memory_pool_get_info = table->amd_ext_->hsa_amd_memory_pool_get_info_fn;
|
||||
hsa_api_.hsa_amd_memory_pool_allocate = table->amd_ext_->hsa_amd_memory_pool_allocate_fn;
|
||||
hsa_api_.hsa_amd_agents_allow_access = table->amd_ext_->hsa_amd_agents_allow_access_fn;
|
||||
@@ -204,9 +217,12 @@ void HsaRsrcFactory::InitHsaApiTable(HsaApiTable* table) {
|
||||
hsa_api_.hsa_amd_memory_async_copy_rect = table->amd_ext_->hsa_amd_memory_async_copy_rect_fn;
|
||||
|
||||
hsa_api_.hsa_amd_signal_async_handler = table->amd_ext_->hsa_amd_signal_async_handler_fn;
|
||||
hsa_api_.hsa_amd_profiling_set_profiler_enabled = table->amd_ext_->hsa_amd_profiling_set_profiler_enabled_fn;
|
||||
hsa_api_.hsa_amd_profiling_get_async_copy_time = table->amd_ext_->hsa_amd_profiling_get_async_copy_time_fn;
|
||||
hsa_api_.hsa_amd_profiling_get_dispatch_time = table->amd_ext_->hsa_amd_profiling_get_dispatch_time_fn;
|
||||
hsa_api_.hsa_amd_profiling_set_profiler_enabled =
|
||||
table->amd_ext_->hsa_amd_profiling_set_profiler_enabled_fn;
|
||||
hsa_api_.hsa_amd_profiling_get_async_copy_time =
|
||||
table->amd_ext_->hsa_amd_profiling_get_async_copy_time_fn;
|
||||
hsa_api_.hsa_amd_profiling_get_dispatch_time =
|
||||
table->amd_ext_->hsa_amd_profiling_get_dispatch_time_fn;
|
||||
} else {
|
||||
hsa_api_.hsa_init = hsa_init;
|
||||
hsa_api_.hsa_shut_down = hsa_shut_down;
|
||||
@@ -302,10 +318,13 @@ const AgentInfo* HsaRsrcFactory::AddAgentInfo(const hsa_agent_t agent) {
|
||||
agent_info->dev_type = HSA_DEVICE_TYPE_CPU;
|
||||
agent_info->dev_index = cpu_list_.size();
|
||||
|
||||
status = hsa_api_.hsa_amd_agent_iterate_memory_pools(agent, FindStandardPool, &agent_info->cpu_pool);
|
||||
status =
|
||||
hsa_api_.hsa_amd_agent_iterate_memory_pools(agent, FindStandardPool, &agent_info->cpu_pool);
|
||||
if ((status == HSA_STATUS_INFO_BREAK) && (cpu_pool_ == NULL)) cpu_pool_ = &agent_info->cpu_pool;
|
||||
status = hsa_api_.hsa_amd_agent_iterate_memory_pools(agent, FindKernArgPool, &agent_info->kern_arg_pool);
|
||||
if ((status == HSA_STATUS_INFO_BREAK) && (kern_arg_pool_ == NULL)) kern_arg_pool_ = &agent_info->kern_arg_pool;
|
||||
status = hsa_api_.hsa_amd_agent_iterate_memory_pools(agent, FindKernArgPool,
|
||||
&agent_info->kern_arg_pool);
|
||||
if ((status == HSA_STATUS_INFO_BREAK) && (kern_arg_pool_ == NULL))
|
||||
kern_arg_pool_ = &agent_info->kern_arg_pool;
|
||||
agent_info->gpu_pool = {};
|
||||
|
||||
cpu_list_.push_back(agent_info);
|
||||
@@ -317,28 +336,34 @@ const AgentInfo* HsaRsrcFactory::AddAgentInfo(const hsa_agent_t agent) {
|
||||
agent_info->dev_id = agent;
|
||||
agent_info->dev_type = HSA_DEVICE_TYPE_GPU;
|
||||
hsa_api_.hsa_agent_get_info(agent, HSA_AGENT_INFO_NAME, agent_info->name);
|
||||
const int gfxip_label_len = std::min (strlen(agent_info->name) - 2, sizeof (agent_info->gfxip) - 1);
|
||||
const int gfxip_label_len =
|
||||
std::min(strlen(agent_info->name) - 2, sizeof(agent_info->gfxip) - 1);
|
||||
memcpy(agent_info->gfxip, agent_info->name, gfxip_label_len);
|
||||
agent_info->gfxip[gfxip_label_len] = '\0';
|
||||
hsa_api_.hsa_agent_get_info(agent, HSA_AGENT_INFO_WAVEFRONT_SIZE, &agent_info->max_wave_size);
|
||||
hsa_api_.hsa_agent_get_info(agent, HSA_AGENT_INFO_QUEUE_MAX_SIZE, &agent_info->max_queue_size);
|
||||
hsa_api_.hsa_agent_get_info(agent, HSA_AGENT_INFO_PROFILE, &agent_info->profile);
|
||||
agent_info->is_apu = (agent_info->profile == HSA_PROFILE_FULL) ? true : false;
|
||||
hsa_api_.hsa_agent_get_info(agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT),
|
||||
&agent_info->cu_num);
|
||||
hsa_api_.hsa_agent_get_info(agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU),
|
||||
&agent_info->waves_per_cu);
|
||||
hsa_api_.hsa_agent_get_info(agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU),
|
||||
&agent_info->simds_per_cu);
|
||||
hsa_api_.hsa_agent_get_info(agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_NUM_SHADER_ENGINES),
|
||||
&agent_info->se_num);
|
||||
hsa_api_.hsa_agent_get_info(
|
||||
agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT),
|
||||
&agent_info->cu_num);
|
||||
hsa_api_.hsa_agent_get_info(agent,
|
||||
static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_NUM_SHADER_ARRAYS_PER_SE),
|
||||
&agent_info->shader_arrays_per_se);
|
||||
static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU),
|
||||
&agent_info->waves_per_cu);
|
||||
hsa_api_.hsa_agent_get_info(agent,
|
||||
static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU),
|
||||
&agent_info->simds_per_cu);
|
||||
hsa_api_.hsa_agent_get_info(
|
||||
agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_NUM_SHADER_ENGINES),
|
||||
&agent_info->se_num);
|
||||
hsa_api_.hsa_agent_get_info(
|
||||
agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_NUM_SHADER_ARRAYS_PER_SE),
|
||||
&agent_info->shader_arrays_per_se);
|
||||
|
||||
agent_info->cpu_pool = {};
|
||||
agent_info->kern_arg_pool = {};
|
||||
status = hsa_api_.hsa_amd_agent_iterate_memory_pools(agent, FindStandardPool, &agent_info->gpu_pool);
|
||||
status =
|
||||
hsa_api_.hsa_amd_agent_iterate_memory_pools(agent, FindStandardPool, &agent_info->gpu_pool);
|
||||
CHECK_ITER_STATUS("hsa_amd_agent_iterate_memory_pools(gpu pool)", status);
|
||||
|
||||
// GFX8 and GFX9 SGPR/VGPR block sizes
|
||||
@@ -435,7 +460,7 @@ bool HsaRsrcFactory::CreateQueue(const AgentInfo* agent_info, uint32_t num_pkts,
|
||||
hsa_queue_t** queue) {
|
||||
hsa_status_t status;
|
||||
status = hsa_api_.hsa_queue_create(agent_info->dev_id, num_pkts, HSA_QUEUE_TYPE_MULTI, NULL, NULL,
|
||||
UINT32_MAX, UINT32_MAX, queue);
|
||||
UINT32_MAX, UINT32_MAX, queue);
|
||||
return (status == HSA_STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -458,7 +483,8 @@ uint8_t* HsaRsrcFactory::AllocateLocalMemory(const AgentInfo* agent_info, size_t
|
||||
hsa_status_t status = HSA_STATUS_ERROR;
|
||||
uint8_t* buffer = NULL;
|
||||
size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK;
|
||||
status = hsa_api_.hsa_amd_memory_pool_allocate(agent_info->gpu_pool, size, 0, reinterpret_cast<void**>(&buffer));
|
||||
status = hsa_api_.hsa_amd_memory_pool_allocate(agent_info->gpu_pool, size, 0,
|
||||
reinterpret_cast<void**>(&buffer));
|
||||
uint8_t* ptr = (status == HSA_STATUS_SUCCESS) ? buffer : NULL;
|
||||
return ptr;
|
||||
}
|
||||
@@ -473,7 +499,8 @@ uint8_t* HsaRsrcFactory::AllocateKernArgMemory(const AgentInfo* agent_info, size
|
||||
uint8_t* buffer = NULL;
|
||||
if (!cpu_agents_.empty()) {
|
||||
size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK;
|
||||
status = hsa_api_.hsa_amd_memory_pool_allocate(*kern_arg_pool_, size, 0, reinterpret_cast<void**>(&buffer));
|
||||
status = hsa_api_.hsa_amd_memory_pool_allocate(*kern_arg_pool_, size, 0,
|
||||
reinterpret_cast<void**>(&buffer));
|
||||
// Both the CPU and GPU can access the kernel arguments
|
||||
if (status == HSA_STATUS_SUCCESS) {
|
||||
hsa_agent_t ag_list[1] = {agent_info->dev_id};
|
||||
@@ -493,7 +520,8 @@ uint8_t* HsaRsrcFactory::AllocateSysMemory(const AgentInfo* agent_info, size_t s
|
||||
uint8_t* buffer = NULL;
|
||||
size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK;
|
||||
if (!cpu_agents_.empty()) {
|
||||
status = hsa_api_.hsa_amd_memory_pool_allocate(*cpu_pool_, size, 0, reinterpret_cast<void**>(&buffer));
|
||||
status = hsa_api_.hsa_amd_memory_pool_allocate(*cpu_pool_, size, 0,
|
||||
reinterpret_cast<void**>(&buffer));
|
||||
// Both the CPU and GPU can access the memory
|
||||
if (status == HSA_STATUS_SUCCESS) {
|
||||
hsa_agent_t ag_list[1] = {agent_info->dev_id};
|
||||
@@ -518,16 +546,18 @@ uint8_t* HsaRsrcFactory::AllocateCmdMemory(const AgentInfo* agent_info, size_t s
|
||||
}
|
||||
|
||||
// Wait signal
|
||||
hsa_signal_value_t HsaRsrcFactory::SignalWait(const hsa_signal_t& signal, const hsa_signal_value_t& signal_value) const {
|
||||
hsa_signal_value_t HsaRsrcFactory::SignalWait(const hsa_signal_t& signal,
|
||||
const hsa_signal_value_t& signal_value) const {
|
||||
const hsa_signal_value_t exp_value = signal_value - 1;
|
||||
hsa_signal_value_t ret_value = signal_value;
|
||||
while (1) {
|
||||
ret_value =
|
||||
hsa_api_.hsa_signal_wait_scacquire(signal, HSA_SIGNAL_CONDITION_LT, signal_value, timeout_, HSA_WAIT_STATE_BLOCKED);
|
||||
ret_value = hsa_api_.hsa_signal_wait_scacquire(signal, HSA_SIGNAL_CONDITION_LT, signal_value,
|
||||
timeout_, HSA_WAIT_STATE_BLOCKED);
|
||||
if (ret_value == exp_value) break;
|
||||
if (ret_value != signal_value) {
|
||||
std::cerr << "Error: HsaRsrcFactory::SignalWait: signal_value(" << signal_value
|
||||
<< "), ret_value(" << ret_value << ")" << std::endl << std::flush;
|
||||
<< "), ret_value(" << ret_value << ")" << std::endl
|
||||
<< std::flush;
|
||||
abort();
|
||||
}
|
||||
}
|
||||
@@ -535,7 +565,8 @@ hsa_signal_value_t HsaRsrcFactory::SignalWait(const hsa_signal_t& signal, const
|
||||
}
|
||||
|
||||
// Wait signal with signal value restore
|
||||
void HsaRsrcFactory::SignalWaitRestore(const hsa_signal_t& signal, const hsa_signal_value_t& signal_value) const {
|
||||
void HsaRsrcFactory::SignalWaitRestore(const hsa_signal_t& signal,
|
||||
const hsa_signal_value_t& signal_value) const {
|
||||
SignalWait(signal, signal_value);
|
||||
hsa_api_.hsa_signal_store_relaxed(const_cast<hsa_signal_t&>(signal), signal_value);
|
||||
}
|
||||
@@ -599,13 +630,13 @@ bool HsaRsrcFactory::LoadAndFinalize(const AgentInfo* agent_info, const char* br
|
||||
}
|
||||
|
||||
// Create executable.
|
||||
status = hsa_api_.hsa_executable_create_alt(HSA_PROFILE_FULL, HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT,
|
||||
NULL, executable);
|
||||
status = hsa_api_.hsa_executable_create_alt(
|
||||
HSA_PROFILE_FULL, HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT, NULL, executable);
|
||||
CHECK_STATUS("Error in creating executable object", status);
|
||||
|
||||
// Load code object.
|
||||
status = hsa_api_.hsa_executable_load_agent_code_object(*executable, agent_info->dev_id, code_obj_rdr,
|
||||
NULL, NULL);
|
||||
status = hsa_api_.hsa_executable_load_agent_code_object(*executable, agent_info->dev_id,
|
||||
code_obj_rdr, NULL, NULL);
|
||||
CHECK_STATUS("Error in loading executable object", status);
|
||||
|
||||
// Freeze executable.
|
||||
@@ -615,7 +646,7 @@ bool HsaRsrcFactory::LoadAndFinalize(const AgentInfo* agent_info, const char* br
|
||||
// Get symbol handle.
|
||||
hsa_executable_symbol_t kernelSymbol;
|
||||
status = hsa_api_.hsa_executable_get_symbol(*executable, NULL, kernel_name, agent_info->dev_id, 0,
|
||||
&kernelSymbol);
|
||||
&kernelSymbol);
|
||||
CHECK_STATUS("Error in looking up kernel symbol", status);
|
||||
|
||||
// Update output parameter
|
||||
@@ -659,7 +690,8 @@ uint64_t HsaRsrcFactory::Submit(hsa_queue_t* queue, const void* packet) {
|
||||
}
|
||||
|
||||
uint32_t slot_idx = (uint32_t)(write_idx % queue->size);
|
||||
uint32_t* queue_slot = reinterpret_cast<uint32_t*>((uintptr_t)(queue->base_address) + (slot_idx * slot_size_b));
|
||||
uint32_t* queue_slot =
|
||||
reinterpret_cast<uint32_t*>((uintptr_t)(queue->base_address) + (slot_idx * slot_size_b));
|
||||
const uint32_t* slot_data = reinterpret_cast<const uint32_t*>(packet);
|
||||
|
||||
// Copy buffered commands into the queue slot.
|
||||
@@ -709,18 +741,22 @@ void HsaRsrcFactory::EnableExecutableTracking(HsaApiTable* table) {
|
||||
table->core_->hsa_executable_freeze_fn = hsa_executable_freeze_interceptor;
|
||||
}
|
||||
|
||||
hsa_status_t HsaRsrcFactory::executable_symbols_cb(hsa_executable_t exec, hsa_executable_symbol_t symbol, void *data) {
|
||||
hsa_status_t HsaRsrcFactory::executable_symbols_cb(hsa_executable_t exec,
|
||||
hsa_executable_symbol_t symbol, void* data) {
|
||||
hsa_symbol_kind_t value = (hsa_symbol_kind_t)0;
|
||||
hsa_status_t status = hsa_api_.hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_TYPE, &value);
|
||||
hsa_status_t status =
|
||||
hsa_api_.hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_TYPE, &value);
|
||||
CHECK_STATUS("Error in getting symbol info", status);
|
||||
if (value == HSA_SYMBOL_KIND_KERNEL) {
|
||||
uint64_t addr = 0;
|
||||
uint32_t len = 0;
|
||||
status = hsa_api_.hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_OBJECT, &addr);
|
||||
status = hsa_api_.hsa_executable_symbol_get_info(
|
||||
symbol, HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_OBJECT, &addr);
|
||||
CHECK_STATUS("Error in getting kernel object", status);
|
||||
status = hsa_api_.hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_NAME_LENGTH, &len);
|
||||
status = hsa_api_.hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_NAME_LENGTH,
|
||||
&len);
|
||||
CHECK_STATUS("Error in getting name len", status);
|
||||
char *name = new char[len + 1];
|
||||
char* name = new char[len + 1];
|
||||
status = hsa_api_.hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_NAME, name);
|
||||
CHECK_STATUS("Error in getting kernel name", status);
|
||||
name[len] = 0;
|
||||
@@ -733,12 +769,15 @@ hsa_status_t HsaRsrcFactory::executable_symbols_cb(hsa_executable_t exec, hsa_ex
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
hsa_status_t HsaRsrcFactory::hsa_executable_freeze_interceptor(hsa_executable_t executable, const char *options) {
|
||||
hsa_status_t HsaRsrcFactory::hsa_executable_freeze_interceptor(hsa_executable_t executable,
|
||||
const char* options) {
|
||||
std::lock_guard<mutex_t> lck(mutex_);
|
||||
if (symbols_map_ == NULL) symbols_map_ = new symbols_map_t;
|
||||
hsa_status_t status = hsa_api_.hsa_executable_iterate_symbols(executable, executable_symbols_cb, NULL);
|
||||
hsa_status_t status =
|
||||
hsa_api_.hsa_executable_iterate_symbols(executable, executable_symbols_cb, NULL);
|
||||
CHECK_STATUS("Error in iterating executable symbols", status);
|
||||
return hsa_api_.hsa_executable_freeze(executable, options);;
|
||||
return hsa_api_.hsa_executable_freeze(executable, options);
|
||||
;
|
||||
}
|
||||
|
||||
void HsaRsrcFactory::DumpHandles(FILE* file) {
|
||||
@@ -746,10 +785,14 @@ void HsaRsrcFactory::DumpHandles(FILE* file) {
|
||||
auto end = agent_map_.end();
|
||||
for (auto it = beg; it != end; ++it) {
|
||||
const AgentInfo* agent_info = it->second;
|
||||
fprintf(file, "0x%lx agent %s\n", agent_info->dev_id.handle, (agent_info->dev_type == HSA_DEVICE_TYPE_CPU) ? "cpu" : "gpu");
|
||||
if (agent_info->cpu_pool.handle != 0) fprintf(file, "0x%lx pool cpu\n", agent_info->cpu_pool.handle);
|
||||
if (agent_info->kern_arg_pool.handle != 0) fprintf(file, "0x%lx pool cpu kernarg\n", agent_info->kern_arg_pool.handle);
|
||||
if (agent_info->gpu_pool.handle != 0) fprintf(file, "0x%lx pool gpu%u\n", agent_info->gpu_pool.handle, agent_info->dev_index);
|
||||
fprintf(file, "0x%lx agent %s\n", agent_info->dev_id.handle,
|
||||
(agent_info->dev_type == HSA_DEVICE_TYPE_CPU) ? "cpu" : "gpu");
|
||||
if (agent_info->cpu_pool.handle != 0)
|
||||
fprintf(file, "0x%lx pool cpu\n", agent_info->cpu_pool.handle);
|
||||
if (agent_info->kern_arg_pool.handle != 0)
|
||||
fprintf(file, "0x%lx pool cpu kernarg\n", agent_info->kern_arg_pool.handle);
|
||||
if (agent_info->gpu_pool.handle != 0)
|
||||
fprintf(file, "0x%lx pool gpu%u\n", agent_info->gpu_pool.handle, agent_info->dev_index);
|
||||
}
|
||||
fflush(file);
|
||||
}
|
||||
|
||||
@@ -44,23 +44,25 @@
|
||||
#define HSA_QUEUE_ALIGN_BYTES 64
|
||||
#define HSA_PACKET_ALIGN_BYTES 64
|
||||
|
||||
#define CHECK_STATUS(msg, status) do { \
|
||||
if ((status) != HSA_STATUS_SUCCESS) { \
|
||||
const char* emsg = 0; \
|
||||
hsa_status_string(status, &emsg); \
|
||||
printf("%s: %s\n", msg, emsg ? emsg : "<unknown error>"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
#define CHECK_STATUS(msg, status) \
|
||||
do { \
|
||||
if ((status) != HSA_STATUS_SUCCESS) { \
|
||||
const char* emsg = 0; \
|
||||
hsa_status_string(status, &emsg); \
|
||||
printf("%s: %s\n", msg, emsg ? emsg : "<unknown error>"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_ITER_STATUS(msg, status) do { \
|
||||
if ((status) != HSA_STATUS_INFO_BREAK) { \
|
||||
const char* emsg = 0; \
|
||||
hsa_status_string(status, &emsg); \
|
||||
printf("%s: %s\n", msg, emsg ? emsg : "<unknown error>"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
#define CHECK_ITER_STATUS(msg, status) \
|
||||
do { \
|
||||
if ((status) != HSA_STATUS_INFO_BREAK) { \
|
||||
const char* emsg = 0; \
|
||||
hsa_status_string(status, &emsg); \
|
||||
printf("%s: %s\n", msg, emsg ? emsg : "<unknown error>"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
namespace util {
|
||||
static const size_t MEM_PAGE_BYTES = 0x1000;
|
||||
@@ -174,15 +176,12 @@ class HsaTimer {
|
||||
static const timestamp_t TIMESTAMP_MAX = UINT64_MAX;
|
||||
typedef long double freq_t;
|
||||
|
||||
enum time_id_t {
|
||||
TIME_ID_CLOCK_REALTIME = 0,
|
||||
TIME_ID_CLOCK_MONOTONIC = 1,
|
||||
TIME_ID_NUMBER
|
||||
};
|
||||
enum time_id_t { TIME_ID_CLOCK_REALTIME = 0, TIME_ID_CLOCK_MONOTONIC = 1, TIME_ID_NUMBER };
|
||||
|
||||
HsaTimer(const hsa_pfn_t* hsa_api) : hsa_api_(hsa_api) {
|
||||
timestamp_t sysclock_hz = 0;
|
||||
hsa_status_t status = hsa_api_->hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &sysclock_hz);
|
||||
hsa_status_t status =
|
||||
hsa_api_->hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &sysclock_hz);
|
||||
CHECK_STATUS("hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY)", status);
|
||||
sysclock_factor_ = (freq_t)1000000000 / (freq_t)sysclock_hz;
|
||||
}
|
||||
@@ -217,8 +216,8 @@ class HsaTimer {
|
||||
|
||||
// Return pair of correlated values of profiling timestamp and time with
|
||||
// correlation error for a given time ID and number of iterations
|
||||
void correlated_pair_ns(time_id_t time_id, uint32_t iters,
|
||||
timestamp_t* timestamp_v, timestamp_t* time_v, timestamp_t* error_v) const {
|
||||
void correlated_pair_ns(time_id_t time_id, uint32_t iters, timestamp_t* timestamp_v,
|
||||
timestamp_t* time_v, timestamp_t* error_v) const {
|
||||
clockid_t clock_id = 0;
|
||||
switch (time_id) {
|
||||
case TIME_ID_CLOCK_REALTIME:
|
||||
@@ -357,7 +356,8 @@ class HsaRsrcFactory {
|
||||
uint8_t* AllocateCmdMemory(const AgentInfo* agent_info, size_t size);
|
||||
|
||||
// Wait signal
|
||||
hsa_signal_value_t SignalWait(const hsa_signal_t& signal, const hsa_signal_value_t& signal_value) const;
|
||||
hsa_signal_value_t SignalWait(const hsa_signal_t& signal,
|
||||
const hsa_signal_value_t& signal_value) const;
|
||||
|
||||
// Wait signal with signal value restore
|
||||
void SignalWaitRestore(const hsa_signal_t& signal, const hsa_signal_value_t& signal_value) const;
|
||||
@@ -403,7 +403,9 @@ class HsaRsrcFactory {
|
||||
const hsa_ven_amd_loader_1_00_pfn_t* LoaderApi() const { return &loader_api_; }
|
||||
|
||||
// Methods for system-clock/ns conversion and timestamp in 'ns'
|
||||
timestamp_t SysclockToNs(const timestamp_t& sysclock) const { return timer_->sysclock_to_ns(sysclock); }
|
||||
timestamp_t SysclockToNs(const timestamp_t& sysclock) const {
|
||||
return timer_->sysclock_to_ns(sysclock);
|
||||
}
|
||||
timestamp_t NsToSysclock(const timestamp_t& time) const { return timer_->ns_to_sysclock(time); }
|
||||
timestamp_t TimestampNs() const { return timer_->timestamp_ns(); }
|
||||
|
||||
@@ -482,8 +484,10 @@ class HsaRsrcFactory {
|
||||
typedef std::map<uint64_t, const char*> symbols_map_t;
|
||||
static symbols_map_t* symbols_map_;
|
||||
static bool executable_tracking_on_;
|
||||
static hsa_status_t hsa_executable_freeze_interceptor(hsa_executable_t executable, const char *options);
|
||||
static hsa_status_t executable_symbols_cb(hsa_executable_t exec, hsa_executable_symbol_t symbol, void *data);
|
||||
static hsa_status_t hsa_executable_freeze_interceptor(hsa_executable_t executable,
|
||||
const char* options);
|
||||
static hsa_status_t executable_symbols_cb(hsa_executable_t exec, hsa_executable_symbol_t symbol,
|
||||
void* data);
|
||||
|
||||
// HSA runtime API table
|
||||
static hsa_pfn_t hsa_api_;
|
||||
@@ -507,8 +511,8 @@ class HsaRsrcFactory {
|
||||
timestamp_t time_error_[HsaTimer::TIME_ID_NUMBER];
|
||||
|
||||
// CPU/kern-arg memory pools
|
||||
hsa_amd_memory_pool_t *cpu_pool_;
|
||||
hsa_amd_memory_pool_t *kern_arg_pool_;
|
||||
hsa_amd_memory_pool_t* cpu_pool_;
|
||||
hsa_amd_memory_pool_t* kern_arg_pool_;
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
|
||||
+20
-20
@@ -168,32 +168,32 @@ class Logger {
|
||||
} // namespace roctracer
|
||||
|
||||
#define ERR_LOGGING(stream) \
|
||||
do { \
|
||||
roctracer::util::Logger::Instance() << "error: " << roctracer::util::Logger::begm \
|
||||
<< stream << roctracer::util::Logger::endl; \
|
||||
} while(0)
|
||||
do { \
|
||||
roctracer::util::Logger::Instance() \
|
||||
<< "error: " << roctracer::util::Logger::begm << stream << roctracer::util::Logger::endl; \
|
||||
} while (0)
|
||||
|
||||
#define INFO_LOGGING(stream) \
|
||||
do { \
|
||||
roctracer::util::Logger::Instance() << "info: " << roctracer::util::Logger::begm << stream \
|
||||
<< roctracer::util::Logger::endl; \
|
||||
} while(0)
|
||||
do { \
|
||||
roctracer::util::Logger::Instance() \
|
||||
<< "info: " << roctracer::util::Logger::begm << stream << roctracer::util::Logger::endl; \
|
||||
} while (0)
|
||||
|
||||
#define WARN_LOGGING(stream) \
|
||||
do { \
|
||||
std::cerr << "ROCProfiler: " << stream << std::endl; \
|
||||
roctracer::util::Logger::Instance() << "warning: " << roctracer::util::Logger::begm << stream \
|
||||
<< roctracer::util::Logger::endl; \
|
||||
} while(0)
|
||||
do { \
|
||||
std::cerr << "ROCProfiler: " << stream << std::endl; \
|
||||
roctracer::util::Logger::Instance() << "warning: " << roctracer::util::Logger::begm << stream \
|
||||
<< roctracer::util::Logger::endl; \
|
||||
} while (0)
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DBG_LOGGING(stream) \
|
||||
do { \
|
||||
roctracer::util::Logger::Instance() << roctracer::util::Logger::begm << "debug: \"" \
|
||||
<< stream << "\"" < < < < \
|
||||
do { \
|
||||
roctracer::util::Logger::Instance() \
|
||||
<< roctracer::util::Logger::begm << "debug: \"" << stream << "\"" < < < < \
|
||||
" in " << __FUNCTION__ << " at " << __FILE__ << " line " << __LINE__ \
|
||||
<< roctracer::util::Logger::endl; \
|
||||
} while(0)
|
||||
<< roctracer::util::Logger::endl; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#if DEBUG_TRACE_ON
|
||||
@@ -204,8 +204,8 @@ inline static void DEBUG_TRACE(const char* fmt, ...) {
|
||||
va_list valist;
|
||||
va_start(valist, fmt);
|
||||
vsnprintf(buf, size, fmt, valist);
|
||||
printf("%u:%u %s",
|
||||
roctracer::util::Logger::GetPid(), roctracer::util::Logger::GetTid(), buf); fflush(stdout);
|
||||
printf("%u:%u %s", roctracer::util::Logger::GetPid(), roctracer::util::Logger::GetTid(), buf);
|
||||
fflush(stdout);
|
||||
va_end(valist);
|
||||
}
|
||||
#else
|
||||
|
||||
Odkázat v novém úkolu
Zablokovat Uživatele