adding queue destroy callback

Bu işleme şunda yer alıyor:
Evgeny
2018-02-21 19:59:47 -06:00
ebeveyn a9a5119399
işleme 33b3546fe4
6 değiştirilmiş dosya ile 92 ekleme ve 49 silme
+8 -1
Dosyayı Görüntüle
@@ -329,7 +329,7 @@ class Context {
const profile_vector_t profile_vector = GetProfiles(group_index);
for (auto& tuple : profile_vector) {
// Wait for stop packet to complete
const uint64_t timeout = UINT64_MAX;
const uint64_t timeout = timeout_;
bool complete = false;
while (!complete) {
const hsa_signal_value_t signal_value = hsa_signal_wait_scacquire(tuple.completion_signal, HSA_SIGNAL_CONDITION_LT, 1, timeout,
@@ -372,6 +372,10 @@ class Context {
}
}
static void SetTimeout(uint64_t timeout) {
timeout_ = timeout;
}
private:
// Getting profling packets
profile_vector_t GetProfiles(const uint32_t& index) {
@@ -469,6 +473,9 @@ class Context {
return info;
}
// Profiling data waiting timeout
static uint64_t timeout_;
// GPU handel
const hsa_agent_t agent_;
const util::AgentInfo* agent_info_;
+3 -2
Dosyayı Görüntüle
@@ -7,8 +7,9 @@ void InterceptQueue::HsaIntercept(HsaApiTable* table) {
}
InterceptQueue::mutex_t InterceptQueue::mutex_;
rocprofiler_callback_t InterceptQueue::on_dispatch_cb_ = NULL;
void* InterceptQueue::on_dispatch_cb_data_ = NULL;
rocprofiler_callback_t InterceptQueue::dispatch_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_ = "";
} // namespace rocprofiler
+27 -17
Dosyayı Görüntüle
@@ -23,6 +23,7 @@ class InterceptQueue {
public:
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);
static void HsaIntercept(HsaApiTable* table);
@@ -39,7 +40,7 @@ class InterceptQueue {
ProxyQueue* proxy = ProxyQueue::Create(agent, size, type, callback, data, private_segment_size,
group_segment_size, queue, &status);
if (status == HSA_STATUS_SUCCESS) {
InterceptQueue* obj = new InterceptQueue(agent, proxy);
InterceptQueue* obj = new InterceptQueue(agent, *queue, proxy);
(*obj_map_)[(uint64_t)(*queue)] = obj;
status = proxy->SetInterceptCB(OnSubmitCB, obj);
}
@@ -53,9 +54,15 @@ class InterceptQueue {
std::lock_guard<mutex_t> lck(mutex_);
hsa_status_t status = HSA_STATUS_ERROR;
if (destroy_callback_ != NULL) {
status = destroy_callback_(queue, callback_data_);
if (status != HSA_STATUS_SUCCESS) return status;
}
obj_map_t::iterator it = obj_map_->find((uint64_t)queue);
if (it != obj_map_->end()) {
const InterceptQueue* obj = it->second;
assert(queue == obj->queue_);
delete obj;
obj_map_->erase(it);
status = HSA_STATUS_SUCCESS;
@@ -74,14 +81,17 @@ class InterceptQueue {
bool to_submit = true;
const packet_t* packet = &packets_arr[j];
if ((GetHeaderType(packet) == HSA_PACKET_TYPE_KERNEL_DISPATCH) && (on_dispatch_cb_ != NULL)) {
if ((GetHeaderType(packet) == HSA_PACKET_TYPE_KERNEL_DISPATCH) && (dispatch_callback_ != NULL)) {
rocprofiler_group_t group = {};
const hsa_kernel_dispatch_packet_t* dispatch_packet =
reinterpret_cast<const hsa_kernel_dispatch_packet_t*>(packet);
const char* kernel_name = GetKernelName(dispatch_packet);
rocprofiler_callback_data_t data = {obj->agent_info_->dev_id, user_que_idx,
dispatch_packet->kernel_object, kernel_name};
hsa_status_t status = on_dispatch_cb_(&data, on_dispatch_cb_data_, &group);
rocprofiler_callback_data_t data = {obj->agent_info_->dev_id,
obj->queue_,
user_que_idx,
dispatch_packet->kernel_object,
kernel_name};
hsa_status_t status = dispatch_callback_(&data, callback_data_, &group);
free(const_cast<char*>(kernel_name));
if ((status == HSA_STATUS_SUCCESS) && (group.context != NULL)) {
Context* context = reinterpret_cast<Context*>(group.context);
@@ -112,20 +122,18 @@ class InterceptQueue {
}
}
static void SetDispatchCB(rocprofiler_callback_t on_dispatch_cb, void* data) {
static void SetCallbacks(rocprofiler_callback_t dispatch_callback, queue_callback_t destroy_callback, void* data) {
std::lock_guard<mutex_t> lck(mutex_);
on_dispatch_cb_ = on_dispatch_cb;
on_dispatch_cb_data_ = data;
}
static void UnsetDispatchCB() {
std::lock_guard<mutex_t> lck(mutex_);
on_dispatch_cb_ = NULL;
on_dispatch_cb_data_ = NULL;
callback_data_ = data;
dispatch_callback_ = dispatch_callback;
destroy_callback_ = destroy_callback;
}
private:
InterceptQueue(const hsa_agent_t& agent, ProxyQueue* proxy) : 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);
}
~InterceptQueue() { ProxyQueue::Destroy(proxy_); }
@@ -164,11 +172,13 @@ class InterceptQueue {
static mutex_t mutex_;
static const packet_word_t header_type_mask = (1ul << HSA_PACKET_HEADER_WIDTH_TYPE) - 1;
static rocprofiler_callback_t on_dispatch_cb_;
static void* on_dispatch_cb_data_;
static rocprofiler_callback_t dispatch_callback_;
static queue_callback_t destroy_callback_;
static void* callback_data_;
static obj_map_t* obj_map_;
static const char* kernel_none_;
hsa_queue_t* const queue_;
ProxyQueue* const proxy_;
const util::AgentInfo* agent_info_;
};
+13 -7
Dosyayı Görüntüle
@@ -141,6 +141,12 @@ void UnloadTool() {
CONSTRUCTOR_API void constructor() {
util::Logger::Create();
const char* timeout_str = getenv("ROCP_DATA_TIMEOUT");
if (timeout_str != NULL) {
const uint64_t timeout_val = strtoull(timeout_str, NULL, 0);
Context::SetTimeout(timeout_val);
}
}
DESTRUCTOR_API void destructor() {
@@ -168,6 +174,7 @@ const MetricsDict* GetMetrics(const hsa_agent_t& agent) {
util::Logger::mutex_t util::Logger::mutex_;
util::Logger* util::Logger::instance_ = NULL;
uint64_t Context::timeout_ = 1000;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -341,18 +348,17 @@ PUBLIC_API hsa_status_t rocprofiler_get_metrics(const rocprofiler_t* handle) {
API_METHOD_SUFFIX
}
// Set kernel dispatch observer
PUBLIC_API hsa_status_t rocprofiler_set_dispatch_callback(rocprofiler_callback_t callback,
void* data) {
// Set/remove queue callbacks
PUBLIC_API hsa_status_t rocprofiler_set_queue_callbacks(rocprofiler_queue_callbacks_t callbacks, void* data) {
API_METHOD_PREFIX
rocprofiler::InterceptQueue::SetDispatchCB(callback, data);
rocprofiler::InterceptQueue::SetCallbacks(callbacks.dispatch, callbacks.destroy, data);
API_METHOD_SUFFIX
}
// Set kernel dispatch observer
PUBLIC_API hsa_status_t rocprofiler_remove_dispatch_callback() {
// Remove queue callbacks
PUBLIC_API hsa_status_t rocprofiler_remove_queue_callbacks() {
API_METHOD_PREFIX
rocprofiler::InterceptQueue::UnsetDispatchCB();
rocprofiler::InterceptQueue::SetCallbacks(NULL, NULL, NULL);
API_METHOD_SUFFIX
}