From 3e5b949c4e08db792dfde2e9e400fd13246df752 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 23 Oct 2023 16:05:35 +0200 Subject: [PATCH] Add nOS-V RT parallel task tests The runtime tests check that we can submit and inline task (which must emit a pause event before the nested task begins) and that we can run parallel tasks. --- test/rt/nosv/CMakeLists.txt | 2 ++ test/rt/nosv/inline.c | 46 +++++++++++++++++++++++++ test/rt/nosv/parallel-tasks.c | 65 +++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 test/rt/nosv/inline.c create mode 100644 test/rt/nosv/parallel-tasks.c diff --git a/test/rt/nosv/CMakeLists.txt b/test/rt/nosv/CMakeLists.txt index c45926c..24e56e2 100644 --- a/test/rt/nosv/CMakeLists.txt +++ b/test/rt/nosv/CMakeLists.txt @@ -40,6 +40,8 @@ nosv_test(attach.c SORT) nosv_test(waitfor.c SORT) nosv_test(several-tasks.c SORT) nosv_test(init-nested.c SORT) +nosv_test(parallel-tasks.c SORT) +nosv_test(inline.c SORT) # Test multiple instrumentation levels nosv_test(several-tasks.c SORT NAME several-tasks-level-0 LEVEL 0) diff --git a/test/rt/nosv/inline.c b/test/rt/nosv/inline.c new file mode 100644 index 0000000..87c5449 --- /dev/null +++ b/test/rt/nosv/inline.c @@ -0,0 +1,46 @@ +/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#include +#include "compat.h" +#include "common.h" + +static void +worker_run(nosv_task_t task) +{ + UNUSED(task); + sleep_us(50); +} + +static void +worker_comp(nosv_task_t task) +{ + UNUSED(task); + nosv_destroy(task, NOSV_DESTROY_NONE); +} + +/* Runs an inline task inside another one */ + +int +main(void) +{ + nosv_init(); + + nosv_task_t ext_task; + if (nosv_attach(&ext_task, NULL, NULL, NOSV_ATTACH_NONE) != 0) + die("nosv_attach failed"); + + nosv_task_type_t worker; + if (nosv_type_init(&worker, worker_run, NULL, worker_comp, "worker", NULL, NULL, NOSV_TYPE_INIT_NONE) != 0) + die("nosv_type_init failed"); + + nosv_task_t worker_task; + nosv_create(&worker_task, worker, 0, NOSV_CREATE_NONE); + + nosv_submit(worker_task, NOSV_SUBMIT_INLINE); + nosv_type_destroy(worker, NOSV_TYPE_DESTROY_NONE); + + nosv_detach(NOSV_DETACH_NONE); + + nosv_shutdown(); +} diff --git a/test/rt/nosv/parallel-tasks.c b/test/rt/nosv/parallel-tasks.c new file mode 100644 index 0000000..ff4263c --- /dev/null +++ b/test/rt/nosv/parallel-tasks.c @@ -0,0 +1,65 @@ +/* Copyright (c) 2023 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#include +#include +#include +#include +#include "compat.h" +#include "common.h" + +#define NTASKS 200 +#define DEGREE 100 + +atomic_int nr_completed_tasks; + +nosv_task_t tasks[NTASKS]; +nosv_task_t main_task; + +static void +task_run(nosv_task_t task) +{ + UNUSED(task); + sleep_us(5); +} + +static void +task_comp(nosv_task_t task) +{ + UNUSED(task); + + int total = atomic_fetch_add(&nr_completed_tasks, 1); + if (total == NTASKS - 1) { + nosv_submit(main_task, NOSV_SUBMIT_UNLOCKED); + } +} + +int +main(void) +{ + nosv_init(); + + nosv_attach(&main_task, NULL, NULL, NOSV_ATTACH_NONE); + + nosv_task_type_t task_type; + nosv_type_init(&task_type, task_run, NULL, task_comp, "task", NULL, NULL, NOSV_TYPE_INIT_NONE); + + for (int t = 0; t < NTASKS; t++) { + nosv_create(&tasks[t], task_type, 0, NOSV_CREATE_PARALLEL); + nosv_set_task_degree(tasks[t], DEGREE); + nosv_submit(tasks[t], NOSV_SUBMIT_NONE); + } + + nosv_pause(NOSV_PAUSE_NONE); + + for (int t = 0; t < NTASKS; t++) + nosv_destroy(tasks[t], NOSV_DESTROY_NONE); + + nosv_detach(NOSV_DETACH_NONE); + + nosv_type_destroy(task_type, NOSV_TYPE_DESTROY_NONE); + + nosv_shutdown(); + + return 0; +}