Skip to content

Commit

Permalink
Adding support for handling the taskstubs schedule event
Browse files Browse the repository at this point in the history
The schedule event includes arguments to the task, those are now
propagated to the gtrace output. Also, the memory transfer event
also includes the source and destination information in the trace
data. This requires the latest version of the taskstubs API headers.
  • Loading branch information
khuck committed Oct 16, 2024
1 parent eb2c215 commit 0095160
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/apex/apex_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ typedef enum _profile_type {
APEX_COUNTER /*!< This profile is a sampled counter */
} apex_profile_type;

/** The type of task_wrapper argument
*
*/
typedef enum _argument_type {
APEX_LONG_INTEGER_TYPE = 0,
APEX_UNSIGNED_LONG_INTEGER_TYPE = 0,
APEX_DOUBLE_TYPE,
APEX_STRING_TYPE,
APEX_POINTER_TYPE,
APEX_ARRAY_TYPE
} apex_argument_type_t;

/**
* The profile object for a timer in APEX.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/apex/task_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct task_wrapper;
#include <unordered_set>
#include "dependency_tree.hpp"
#include "apex_clock.hpp"
#include <variant>

namespace apex {

Expand Down Expand Up @@ -89,6 +90,14 @@ struct task_wrapper {
*/
bool explicit_trace_start;
task_state_t state;
/**
\brief Vector of arguments to the task, optional data from taskStubs implementation
only used by the google trace events format output.
*/
using argument = std::variant<uint64_t,int64_t,double,std::string,void*>;
std::vector<apex_argument_type_t> argument_types;
std::vector<argument> arguments;
std::vector<std::string> argument_names;
/**
\brief Constructor.
*/
Expand Down
89 changes: 84 additions & 5 deletions src/apex/taskstubs_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ std::shared_ptr<apex::task_wrapper> safeLookup(

void safeErase(
tasktimer_guid_t guid) {
APEX_UNUSED(guid);
return;
/*
getMyMap().erase(guid);
*/
{
std::scoped_lock lock{mtx()};
getCommonMap().erase(guid);
}
//safePrint("Destroyed", guid);
*/
return;
}

extern "C" {
Expand Down Expand Up @@ -186,10 +188,56 @@ extern "C" {
apex_timer == nullptr ? "unknown" : apex_timer->task_id->get_name().c_str());
static bool& over = apex::get_program_over();
if (over) return;
// TODO: handle the schedule event, somehow
APEX_UNUSED(timer);
APEX_UNUSED(arguments);
APEX_UNUSED(argument_count);
for (uint64_t i = 0 ; i < argument_count ; i++) {
switch (arguments[i].type) {
case TASKTIMER_LONG_INTEGER_TYPE: {
apex::task_wrapper::argument tmp = (int64_t)arguments[i].l_value;
apex_timer->arguments.push_back(tmp);
apex_timer->argument_types.push_back(APEX_LONG_INTEGER_TYPE);
break;
}
case TASKTIMER_UNSIGNED_LONG_INTEGER_TYPE: {
apex::task_wrapper::argument tmp = (uint64_t)arguments[i].u_value;
apex_timer->arguments.push_back(tmp);
apex_timer->argument_types.push_back(APEX_UNSIGNED_LONG_INTEGER_TYPE);
break;
}
case TASKTIMER_DOUBLE_TYPE: {
apex::task_wrapper::argument tmp = arguments[i].d_value;
apex_timer->arguments.push_back(tmp);
apex_timer->argument_types.push_back(APEX_DOUBLE_TYPE);
break;
}
case TASKTIMER_STRING_TYPE: {
apex::task_wrapper::argument tmp = std::string(arguments[i].c_value);
apex_timer->arguments.push_back(tmp);
apex_timer->argument_types.push_back(APEX_STRING_TYPE);
break;
}
case TASKTIMER_POINTER_TYPE: {
apex::task_wrapper::argument tmp = arguments[i].p_value;
apex_timer->arguments.push_back(tmp);
apex_timer->argument_types.push_back(APEX_POINTER_TYPE);
break;
}
case TASKTIMER_ARRAY_TYPE: {
apex::task_wrapper::argument tmp = arguments[i].a_value;
apex_timer->arguments.push_back(tmp);
apex_timer->argument_types.push_back(APEX_ARRAY_TYPE);
break;
}
default:
break;
}
if (arguments[i].name != nullptr) {
apex_timer->argument_names.push_back(std::string(arguments[i].name));
} else {
std::string tmpname{"arg["};
tmpname = tmpname + std::to_string(i+2); // add two, because GUID and parent GUID are 0,1
tmpname = tmpname + "]";
apex_timer->argument_names.push_back(tmpname);
}
}
}

void tasktimer_start_impl(
Expand Down Expand Up @@ -332,10 +380,41 @@ extern "C" {
const void* dest_ptr) {
std::shared_ptr<apex::task_wrapper> parent = safeLookup(guid, "data transfer");
auto task = apex::new_task("data xfer", 0, parent);
const auto getspace = [](tasktimer_execution_space_p& space) {
std::stringstream ss;
ss << (space->type == TASKTIMER_DEVICE_CPU ? "CPU " : "GPU ");
ss << space->device_id << "," << space->instance_id;
return ss.str();
};
/* source_type */
task->arguments.push_back(apex::task_wrapper::argument(std::string(getspace(source_type))));
task->argument_types.push_back(APEX_STRING_TYPE);
task->argument_names.push_back("source_type");
/* source_name */
task->arguments.push_back(apex::task_wrapper::argument(std::string(source_name)));
task->argument_types.push_back(APEX_STRING_TYPE);
task->argument_names.push_back("source_name");
/* source_ptr */
task->arguments.push_back(apex::task_wrapper::argument((void*)source_ptr));
task->argument_types.push_back(APEX_POINTER_TYPE);
task->argument_names.push_back("source_ptr");
/* dest_type */
task->arguments.push_back(apex::task_wrapper::argument(std::string(getspace(dest_type))));
task->argument_types.push_back(APEX_STRING_TYPE);
task->argument_names.push_back("dest_type");
/* dest_name */
task->arguments.push_back(apex::task_wrapper::argument(std::string(dest_name)));
task->argument_types.push_back(APEX_STRING_TYPE);
task->argument_names.push_back("dest_name");
/* dest_ptr */
task->arguments.push_back(apex::task_wrapper::argument((void*)dest_ptr));
task->argument_types.push_back(APEX_POINTER_TYPE);
task->argument_names.push_back("dest_ptr");
timerStack(task, true);
}

void tasktimer_data_transfer_stop_impl(tasktimer_guid_t guid) {
APEX_UNUSED(guid);
timerStack(nullptr, false);
}

Expand Down
38 changes: 32 additions & 6 deletions src/apex/trace_event_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,38 @@ inline void trace_event_listener::_common_stop(std::shared_ptr<profiler> &p) {
} else {
std::string pguid = parents_to_string(p->tt_ptr);
ss << "{\"name\":\"" << p->get_task_id()->get_name()
<< "\",\"cat\":\"CPU\""
<< ",\"ph\":\"X\",\"pid\":"
<< saved_node_id << ",\"tid\":" << _tid
<< ",\"ts\":" << p->get_start_us() << ",\"dur\":"
<< p->get_stop_us() - p->get_start_us()
<< ",\"args\":{\"GUID\":" << p->guid << ",\"Parent GUID\":" << pguid << "}},\n";
<< "\",\"cat\":\"CPU\""
<< ",\"ph\":\"X\",\"pid\":"
<< saved_node_id << ",\"tid\":" << _tid
<< ",\"ts\":" << p->get_start_us() << ",\"dur\":"
<< p->get_stop_us() - p->get_start_us()
<< ",\"args\":{\"GUID\":" << p->guid << ",\"Parent GUID\":" << pguid;
for (size_t a = 0 ; a < p->tt_ptr->arguments.size() ; a++) {
auto& arg = p->tt_ptr->arguments[a];
switch (p->tt_ptr->argument_types[a]) {
case APEX_LONG_INTEGER_TYPE: {
ss << ",\"" << p->tt_ptr->argument_names[a] << "\":\"" << std::get<long>(arg) << "\"";
break;
}
case APEX_DOUBLE_TYPE: {
ss << ",\"" << p->tt_ptr->argument_names[a] << "\":\"" << std::get<double>(arg) << "\"";
break;
}
case APEX_STRING_TYPE: {
ss << ",\"" << p->tt_ptr->argument_names[a] << "\":\"" << std::get<std::string>(arg) << "\"";
break;
}
case APEX_POINTER_TYPE:
case APEX_ARRAY_TYPE: {
ss << ",\"" << p->tt_ptr->argument_names[a] << "\":\"" << std::hex << std::get<void*>(arg) << "\"";
break;
}
default: {
break;
}
}
}
ss << "}},\n";
}
#if APEX_HAVE_PAPI
int i = 0;
Expand Down

0 comments on commit 0095160

Please sign in to comment.