Skip to content

Commit

Permalink
Merge branch 'label-fix' into 'master'
Browse files Browse the repository at this point in the history
task_type_label may be nullptr. Generate a label in this case like nanos6 does

Closes #14

See merge request nos-v/nodes!41
  • Loading branch information
kevinsala committed Jan 12, 2024
2 parents 70ce0ed + e5752e5 commit 70de5f1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
23 changes: 3 additions & 20 deletions src/tasks/TaskInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of NODES and is licensed under the terms contained in the COPYING file.
Copyright (C) 2021-2023 Barcelona Supercomputing Center (BSC)
Copyright (C) 2021-2024 Barcelona Supercomputing Center (BSC)
*/

#include <cassert>
Expand All @@ -14,6 +14,7 @@ std::vector<nosv_task_type_t> TaskInfo::_taskTypes;
std::vector<nanos6_task_info_t *> TaskInfo::_taskInfos;
SpinLock TaskInfo::_lock;
bool TaskInfo::_initialized;
size_t TaskInfo::unlabeledTaskInfos = 0;


void TaskInfo::registerTaskInfo(nanos6_task_info_t *taskInfo)
Expand All @@ -28,25 +29,7 @@ void TaskInfo::registerTaskInfo(nanos6_task_info_t *taskInfo)
_lock.lock();

if (_initialized) {
// Create the task type
nosv_task_type_t type;
int err = nosv_type_init(
&type, /* Out: The pointer to the type */
&(TaskInfo::runWrapper), /* Run callback wrapper for the tasks */
&(TaskFinalization::taskEndedCallback), /* End callback for when a task completes user code execution */
&(TaskFinalization::taskCompletedCallback), /* Completed callback for when a task completely finishes */
taskInfo->implementations->task_type_label, /* Task type label */
(void *) taskInfo, /* Metadata: Link to NODES' taskinfo */
&(TaskInfo::getCostWrapper),
NOSV_TYPE_INIT_NONE
);
if (err)
ErrorHandler::fail("nosv_type_init failed: ", nosv_get_error_string(err));

// Save a nOS-V type link in the task info
taskInfo->task_type_data = (void *) type;

_taskTypes.push_back(type);
createTaskType(taskInfo);
} else {
_taskInfos.push_back(taskInfo);
}
Expand Down
63 changes: 41 additions & 22 deletions src/tasks/TaskInfo.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of NODES and is licensed under the terms contained in the COPYING file.
Copyright (C) 2021-2023 Barcelona Supercomputing Center (BSC)
Copyright (C) 2021-2024 Barcelona Supercomputing Center (BSC)
*/

#ifndef TASK_INFO_HPP
Expand Down Expand Up @@ -44,6 +44,9 @@ class TaskInfo {
//! Whether the manager has been initialized (after the runtime)
static bool _initialized;

// Global number of unlabeled task infos
static size_t unlabeledTaskInfos;

public:

//! \brief Run wrapper for task types
Expand Down Expand Up @@ -144,27 +147,7 @@ class TaskInfo {
_lock.lock();

for (size_t i = 0; i < _taskInfos.size(); ++i) {
nanos6_task_info_t *taskInfo = _taskInfos[i];

// Create the task type
nosv_task_type_t type;
int err = nosv_type_init(
&type, /* Out: The pointer to the type */
&(TaskInfo::runWrapper), /* Run callback wrapper for the tasks */
&(TaskFinalization::taskEndedCallback), /* End callback for when a task completes user code execution */
&(TaskFinalization::taskCompletedCallback), /* Completed callback for when a task completely finishes */
taskInfo->implementations->task_type_label, /* Task type label */
(void *) taskInfo, /* Metadata: Link to NODES' taskinfo */
&(TaskInfo::getCostWrapper),
NOSV_TYPE_INIT_NONE
);
if (err)
ErrorHandler::fail("nosv_type_init failed: ", nosv_get_error_string(err));

// Save a nOS-V type link in the task info
taskInfo->task_type_data = (void *) type;

_taskTypes.push_back(type);
createTaskType(_taskInfos[i]);
}

_lock.unlock();
Expand Down Expand Up @@ -200,6 +183,42 @@ class TaskInfo {
//! \brief Unregister all the registered taskinfos
static void shutdown();

//! \brief Create a nOS-V task type from a taskinfo and link them
//!
//! \param[in] taskInfo A pointer to the taskinfo
static inline nosv_task_type_t createTaskType(nanos6_task_info_t *taskInfo)
{
std::string label;
if (taskInfo->implementations->task_type_label) {
label = taskInfo->implementations->task_type_label;
} else {
label = "Unlabeled" + std::to_string(unlabeledTaskInfos++);
}

// Create the task type
nosv_task_type_t type;
int err = nosv_type_init(
&type, /* Out: The pointer to the type */
&(TaskInfo::runWrapper), /* Run callback wrapper for the tasks */
&(TaskFinalization::taskEndedCallback), /* End callback for when a task completes user code execution */
&(TaskFinalization::taskCompletedCallback), /* Completed callback for when a task completely finishes */
label.c_str(), /* Task type label */
(void *) taskInfo, /* Metadata: Link to NODES' taskinfo */
&(TaskInfo::getCostWrapper),
NOSV_TYPE_INIT_NONE
);
if (err)
ErrorHandler::fail("nosv_type_init failed: ", nosv_get_error_string(err));

// Link the taskinfo to the task type
taskInfo->task_type_data = (void *) type;

// Save the task type to destroy during the finalization
_taskTypes.push_back(type);

return type;
}

};

#endif // TASK_INFO_HPP

0 comments on commit 70de5f1

Please sign in to comment.