Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable PaRSEC profiling system #227

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion ttg/ttg/parsec/ttg.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
#include <parsec/parsec_comm_engine.h>
#include <parsec/parsec_internal.h>
#include <parsec/scheduling.h>
#if defined(PARSEC_PROF_TRACE)
#include <parsec/profiling.h>
#endif
#include <cstdlib>
#include <cstring>

Expand Down Expand Up @@ -161,7 +164,12 @@ namespace ttg_parsec {

public:
static constexpr const int PARSEC_TTG_MAX_AM_SIZE = 1024 * 1024;
WorldImpl(int *argc, char **argv[], int ncores) : WorldImplBase(query_comm_size(), query_comm_rank()) {
WorldImpl(int *argc, char **argv[], int ncores) : WorldImplBase(query_comm_size(), query_comm_rank())
#if defined(PARSEC_PROF_TRACE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make that initialization independent of PARSEC_PROF_TRACE but make it an assignment here https://github.com/TESSEorg/ttg/pull/227/files#diff-b16b2b248d6db2366353f63da94be820a8905343d7452acc0639ffcaf3100068R330

, profiling_array_occupied(0)
, profiling_array_size(0)
#endif
{
ttg::detail::register_world(*this);
ctx = parsec_init(ncores, argc, argv);
es = ctx->virtual_processes[0]->execution_streams[0];
Expand All @@ -178,6 +186,7 @@ namespace ttg_parsec {
tpool->taskpool_id = -1;
tpool->update_nb_runtime_task = parsec_add_fetch_runtime_task;
tpool->taskpool_type = PARSEC_TASKPOOL_TYPE_TTG;
tpool->taskpool_name = "TTG Taskpool";
parsec_taskpool_reserve_id(tpool);

#ifdef TTG_USE_USER_TERMDET
Expand Down Expand Up @@ -273,6 +282,21 @@ namespace ttg_parsec {
#endif // TTG_USE_USER_TERMDET
}

template <typename keyT, typename output_terminalsT, typename derivedT, typename input_valueTs = ttg::typelist<>>
void register_new_tt(const TT<keyT, output_terminalsT, derivedT, input_valueTs> *t) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be sufficient to take TTBase* here since you only need the name.

#if defined(PARSEC_PROF_TRACE)
if(profiling_array_occupied+2 >= profiling_array_size) {
profiling_array_size += 64;
tpool->profiling_array = (int*)realloc((void*)tpool->profiling_array, profiling_array_size * sizeof(int));
}
parsec_profiling_add_dictionary_keyword(t->get_name().c_str(), "fill:000000", 0, NULL,
(int*)&tpool->profiling_array[profiling_array_occupied],
(int*)&tpool->profiling_array[profiling_array_occupied+1]);
profiling_array_occupied += 2;
#endif
tpool->nb_task_classes++;
}

protected:
virtual void fence_impl(void) override {
int rank = this->rank();
Expand Down Expand Up @@ -302,6 +326,10 @@ namespace ttg_parsec {
parsec_execution_stream_t *es = nullptr;
parsec_taskpool_t *tpool = nullptr;
bool parsec_taskpool_started = false;
#if defined(PARSEC_PROF_TRACE)
std::size_t profiling_array_size;
std::size_t profiling_array_occupied;
#endif
};

namespace detail {
Expand Down Expand Up @@ -331,6 +359,9 @@ namespace ttg_parsec {
PARSEC_LIST_ITEM_SINGLETON(&this->parsec_task);
parsec_task.mempool_owner = mempool;
parsec_task.task_class = task_class;
// We save the address of this task in the locals, so we can lookup the task from its locals
// This is mostly used in make_key, called by the profiling.
*(uintptr_t*)parsec_task.locals = (uintptr_t)this;
}

parsec_ttg_task_base_t(parsec_thread_mempool_t *mempool, parsec_task_class_t *task_class,
Expand All @@ -343,6 +374,9 @@ namespace ttg_parsec {
parsec_task.taskpool = taskpool;
parsec_task.priority = priority;
parsec_task.chore_id = 0;
// We save the address of this task in the locals, so we can lookup the task from its locals
// This is mostly used in make_key, called by the profiling.
*(uintptr_t*)parsec_task.locals = (uintptr_t)this;
}
};

Expand Down Expand Up @@ -2206,6 +2240,10 @@ namespace ttg_parsec {
}
}

static parsec_key_t make_key(const parsec_taskpool_t *tp, const parsec_assignment_t *as) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand what make_key does... parsec_assignment_t is a struct with one integer member. How is it safe to cast it to a uintptr_t below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.locals is an array of assignment_t with more than 4 of them, so there is room in self.locals to store the pointer-size int. Not clean, but I'm abusing the only space I have to store stack information.

return (parsec_key_t)(*(uintptr_t*)as);
}

parsec_key_fn_t tasks_hash_fcts = {key_equal, key_print, key_hash};

static parsec_hook_return_t complete_task_and_release(parsec_execution_stream_t *es, parsec_task_t *t) {
Expand Down Expand Up @@ -2267,6 +2305,10 @@ namespace ttg_parsec {
self.nb_locals = 0;
self.nb_flows = numflows;

self.make_key = make_key;
self.key_functions = &tasks_hash_fcts;
world_impl.register_new_tt(this);

// function_id_to_instance[self.task_class_id] = this;

if constexpr (derived_has_cuda_op()) {
Expand Down