HSA API callbacks and hsa test

This commit is contained in:
Evgeny
2018-11-28 12:36:11 -06:00
parent 65d8c3be39
commit 8f4cece27e
15 changed files with 5326 additions and 107 deletions
+21 -2
View File
@@ -27,6 +27,7 @@ THE SOFTWARE.
#include <cstdint>
#include <cstddef>
#include <iostream>
#define HSART_CALL(call) \
do { \
@@ -45,10 +46,13 @@ class Timer {
public:
typedef uint64_t timestamp_t;
typedef long double freq_t;
typedef decltype(hsa_system_get_info)* hsa_system_get_info_fn_t;
Timer() {
// Initialization
inline void init(const hsa_system_get_info_fn_t& get_info_fn) {
hsa_system_get_info_fn = get_info_fn;
timestamp_t timestamp_hz = 0;
HSART_CALL(hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &timestamp_hz));
HSART_CALL(get_info_fn(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &timestamp_hz));
timestamp_rate_ = (freq_t)1000000000 / (freq_t)timestamp_hz;
}
@@ -66,8 +70,23 @@ class Timer {
HSART_CALL(hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP, &timestamp));
return timestamp_to_ns(timestamp);
}
timestamp_t timestamp_fn_ns() const {
timestamp_t timestamp;
HSART_CALL(hsa_system_get_info_fn(HSA_SYSTEM_INFO_TIMESTAMP, &timestamp));
return timestamp_to_ns(timestamp);
}
Timer() {
init(hsa_system_get_info);
}
Timer(hsa_system_get_info_fn_t f) {
init(f);
}
private:
// hsa_system_get_info function
hsa_system_get_info_fn_t hsa_system_get_info_fn;
// Timestamp rate
freq_t timestamp_rate_;
};
+3 -2
View File
@@ -26,9 +26,10 @@ THE SOFTWARE.
// Traced API domains
typedef enum {
ACTIVITY_DOMAIN_ANY = 0, // Any domain
ACTIVITY_DOMAIN_HIP_API = 1, // HIP domain
ACTIVITY_DOMAIN_HSA_API = 1, // HSA domain
ACTIVITY_DOMAIN_HCC_OPS = 2, // HCC domain
ACTIVITY_DOMAIN_NUMBER = 3
ACTIVITY_DOMAIN_HIP_API = 3, // HIP domain
ACTIVITY_DOMAIN_NUMBER = 4
} activity_domain_t;
// API calback type
+4206
View File
File diff suppressed because it is too large Load Diff
+11 -5
View File
@@ -71,7 +71,7 @@ typedef enum {
const char* roctracer_error_string();
////////////////////////////////////////////////////////////////////////////////
// Traced runtime API domains
// Traced runtime domains
// Activity domain type
typedef activity_domain_t roctracer_domain_t;
@@ -83,6 +83,11 @@ const char* roctracer_id_string(
const uint32_t& id, // activity ID
const uint32_t& kind); // activity kind
// Set properties
roctracer_status_t roctracer_set_properties(
roctracer_domain_t domain, // tracing domain
void* propertes); // tracing properties
////////////////////////////////////////////////////////////////////////////////
// Callback API
//
@@ -91,18 +96,19 @@ const char* roctracer_id_string(
// called on different phases, on enter, on exit, on kernel completion.
// Methods return non-zero on error and library errno is set.
// Runtime API callback type
typedef activity_rtapi_callback_t roctracer_rtapi_callback_t;
// Enable runtime API callbacks
roctracer_status_t roctracer_enable_callback(
activity_domain_t domain, // runtime API domain
activity_domain_t domain, // tracing domain
uint32_t id, // API call ID
activity_rtapi_callback_t callback, // callback function pointer
void* arg); // [in/out] callback arg
// Disable runtime API callbacks
roctracer_status_t roctracer_disable_callback(
activity_domain_t domain, // runtime API domain
activity_domain_t domain, // tracing domain
uint32_t id); // API call ID
////////////////////////////////////////////////////////////////////////////////
@@ -170,13 +176,13 @@ roctracer_pool_t* roctracer_default_pool(
// Enable activity records logging
roctracer_status_t roctracer_enable_activity(
activity_domain_t domain, // runtime API domain
activity_domain_t domain, // tracing domain
uint32_t id, // activity ID
roctracer_pool_t* pool = NULL); // memory pool, NULL is a default one
// Disable activity records logging
roctracer_status_t roctracer_disable_activity(
activity_domain_t domain, // runtime API domain
activity_domain_t domain, // tracing domain
uint32_t id); // activity ID
// Flush available activity records
+74
View File
@@ -0,0 +1,74 @@
/*
Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef INC_ROCTRACER_HSA_H_
#define INC_ROCTRACER_HSA_H_
#include <mutex>
#include <hsa.h>
#include <hsa_api_trace.h>
#include <hsa_ext_amd.h>
#include "ext/prof_protocol.h"
#include "roctracer.h"
namespace roctracer {
namespace hsa_support {
template <int N>
class CbTable {
public:
typedef std::mutex mutex_t;
CbTable() {
std::lock_guard<mutex_t> lck(mutex_);
for (int i = 0; i < N; i++) {
callback_[i] = NULL;
arg_[i] = NULL;
}
}
void set(uint32_t id, activity_rtapi_callback_t callback, void* arg) {
std::lock_guard<mutex_t> lck(mutex_);
callback_[id] = callback;
arg_[id] = arg;
}
void get(uint32_t id, activity_rtapi_callback_t* callback, void** arg) {
std::lock_guard<mutex_t> lck(mutex_);
*callback = callback_[id];
*arg = arg_[id];
}
private:
activity_rtapi_callback_t callback_[N];
void* arg_[N];
mutex_t mutex_;
};
extern CoreApiTable CoreApiTable_saved;
extern AmdExtTable AmdExtTable_saved;
extern ImageExtTable ImageExtTable_saved;
};
};
#include "inc/hsa_prof_str.h"
#endif // INC_ROCTRACER_HSA_H_