From 5a7bff83740244f46274c1cf508b085250b26c6f Mon Sep 17 00:00:00 2001 From: Romain Pereira Date: Sat, 4 Oct 2025 01:51:28 +0000 Subject: [PATCH 1/6] [wip] Adding tests for taskgraphs --- tests/6.0/taskgraph/test_taskgraph.c | 39 ++++++++++ .../taskgraph/test_taskgraph_heterogeneous.c | 60 +++++++++++++++ tests/6.0/taskgraph/test_taskgraph_id.c | 73 ++++++++++++++++++ tests/6.0/taskgraph/test_taskgraph_if.c | 52 +++++++++++++ tests/6.0/taskgraph/test_taskgraph_nogroup.c | 54 +++++++++++++ tests/6.0/taskgraph/test_taskgraph_parallel.c | 58 ++++++++++++++ tests/6.0/taskgraph/test_taskgraph_replay.c | 58 ++++++++++++++ tests/6.0/taskgraph/test_taskgraph_reset.c | 75 +++++++++++++++++++ 8 files changed, 469 insertions(+) create mode 100644 tests/6.0/taskgraph/test_taskgraph.c create mode 100644 tests/6.0/taskgraph/test_taskgraph_heterogeneous.c create mode 100644 tests/6.0/taskgraph/test_taskgraph_id.c create mode 100644 tests/6.0/taskgraph/test_taskgraph_if.c create mode 100644 tests/6.0/taskgraph/test_taskgraph_nogroup.c create mode 100644 tests/6.0/taskgraph/test_taskgraph_parallel.c create mode 100644 tests/6.0/taskgraph/test_taskgraph_replay.c create mode 100644 tests/6.0/taskgraph/test_taskgraph_reset.c diff --git a/tests/6.0/taskgraph/test_taskgraph.c b/tests/6.0/taskgraph/test_taskgraph.c new file mode 100644 index 000000000..f5292e85d --- /dev/null +++ b/tests/6.0/taskgraph/test_taskgraph.c @@ -0,0 +1,39 @@ +//===-- test_taskgraph.c ------------------------------------------------===// +// +// OpenMP API Version 6.0 Nov 2024 +// +// Description +// testTaskgraph(): +// Create a taskgraph, and ensures the structured block is executed once +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include "ompvv.h" + +int testTaskgraph(void) +{ + int errors = 0; + int x = 0; + #pragma omp parallel shared(x) + { + # pragma omp single + { + # pragma omp taskgraph + { + ++x; + } + } + } + OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); + return errors; +} + +int main(void) +{ + int errors = 0; + OMPVV_TEST_AND_SET_VERBOSE(errors, testTaskgraph()); + OMPVV_REPORT_AND_RETURN(errors); +} diff --git a/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c b/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c new file mode 100644 index 000000000..dd48f3cfb --- /dev/null +++ b/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c @@ -0,0 +1,60 @@ +//===-- test_taskgraph.c ------------------------------------------------===// +// +// OpenMP API Version 6.0 Nov 2024 +// +// Description +// testTaskgrapHeterogeneoush(): +// Create a taskgraph, spawns 3 tasks +// T1 -> T2 -> T3 +// with (T1, T3) on device, (T2) on host. +// +// Also ensures that the structured block is executed once +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include "ompvv.h" + +int testTaskgraphHeterogeneous(void) +{ + int errors = 0; + + # define N 16 + int x = 0; + int y = 0; + + # pragma omp parallel shared(x, y) + { + # pragma omp single + { + for (int i = 0 ; i < N ; ++i) + { + # pragma omp taskgraph + { + ++x; + + # pragma omp target nowait map(tofrom: y) depend(out: y) + ++y; + + # pragma omp task depend(out: y) + ++y; + + # pragma omp target nowait map(tofrom: y) depend(out: y) + ++y; + } + } + } + } + OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y == 3*N); + return errors; +} + +int main(void) +{ + int errors = 0; + OMPVV_TEST_AND_SET_VERBOSE(errors, testTaskgraphHeterogeneous()); + OMPVV_REPORT_AND_RETURN(errors); +} diff --git a/tests/6.0/taskgraph/test_taskgraph_id.c b/tests/6.0/taskgraph/test_taskgraph_id.c new file mode 100644 index 000000000..db00d5593 --- /dev/null +++ b/tests/6.0/taskgraph/test_taskgraph_id.c @@ -0,0 +1,73 @@ +//===-- test_taskgraph.c ------------------------------------------------===// +// +// OpenMP API Version 6.0 Nov 2024 +// +// Description +// testTaskgraphId(): +// Create 'M' taskgraphs that spawns 3 tasks +// T1 -> T2 -> T3 +// with (T1, T3) on device, (T2) on host. +// Replay taskgraph 'N' times +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include "ompvv.h" + +int testTaskgraphGraphId(void) +{ + int errors = 0; + + # define N 16 + # define M 16 + int x[M]; // number of time the structued block executed for taskgraph i + int y[M]; // number of time tasks executes for taskgraph i + memset(x, 0, sizeof(x)); + memset(y, 0, sizeof(y)); + + # pragma omp parallel shared(x, y) + { + # pragma omp single + { + for (int i = 0 ; i < N ; ++i) + { + for (int j = 0 ; j < M ; ++j) + { + # pragma omp taskgraph graph_id(j) + { + ++x[j]; + + # pragma omp target map(tofrom: y) depend(out: y) + ++y[j]; + + # pragma omp task depend(out: y) + ++y[j]; + + # pragma omp target map(tofrom: y) depend(out: y) + ++y[j]; + } + } + } + } + } + + for (int j = 0 ; j < M ; ++j) + { + // each taskgraph strucuted block must have executed once + OMPVV_TEST_AND_SET_VERBOSE(errors, x[j] == 1); + + // each triplets must have executed N times + OMPVV_TEST_AND_SET_VERBOSE(errors, y[j] == 3*N); + } + + return errors; +} + +int main(void) +{ + int errors = 0; + OMPVV_TEST_AND_SET_VERBOSE(errors, testTaskgraphGraphId()); + OMPVV_REPORT_AND_RETURN(errors); +} diff --git a/tests/6.0/taskgraph/test_taskgraph_if.c b/tests/6.0/taskgraph/test_taskgraph_if.c new file mode 100644 index 000000000..c09ec255e --- /dev/null +++ b/tests/6.0/taskgraph/test_taskgraph_if.c @@ -0,0 +1,52 @@ +//===-- test_taskgraph_if.c ------------------------------------------------===// +// +// OpenMP API Version 6.0 Nov 2024 +// +// Description +// testTaskgraphIf(): +// Call +// taskgraph if(1) +// taskgraph if(0) +// taskgraph if(1) +// and ensures that the structured block is executed only once, +// and records twice +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include "ompvv.h" + +int testTaskgraphIf(void) +{ + int errors = 0; + int x = 0; + int y = 0; + #pragma omp parallel shared(x, y) + { + # pragma omp single + { + for (int i = 0 ; i < 3 ; ++i) + { + # pragma omp taskgraph if(i != 1) + { + ++x; + + # pragma omp task + ++y; + } + } + } + } + OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y == 2); + return errors; +} + +int main(void) +{ + int errors = 0; + OMPVV_TEST_AND_SET_VERBOSE(errors, testTaskgraphIf()); + OMPVV_REPORT_AND_RETURN(errors); +} diff --git a/tests/6.0/taskgraph/test_taskgraph_nogroup.c b/tests/6.0/taskgraph/test_taskgraph_nogroup.c new file mode 100644 index 000000000..170728b47 --- /dev/null +++ b/tests/6.0/taskgraph/test_taskgraph_nogroup.c @@ -0,0 +1,54 @@ +//===-- test_taskgraph.c ------------------------------------------------===// +// +// OpenMP API Version 6.0 Nov 2024 +// +// Description +// testTaskgraphNoGroup(): +// Create a taskgraph, and ensures the structured block is executed once. +// Then reexecute construct twice with if(0) and if(1), +// and ensures that the structured block executed once, +// and records twice +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include "ompvv.h" + +int testTaskgraphNoGroup(void) +{ + int errors = 0; + + # define N 16 + int x = 0; + int y = 0; + #pragma omp parallel shared(x, y) + { + # pragma omp single + { + for (int i = 0 ; i < N ; ++i) + { + # pragma omp taskgraph nogroup + { + ++x; + # pragma omp task shared(y) + { + # pragma omp atomic + ++y; + } + } + } + } + } + OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y == N); + return errors; +} + +int main(void) +{ + int errors = 0; + OMPVV_TEST_AND_SET_VERBOSE(errors, testTaskgraphNoGroup()); + OMPVV_REPORT_AND_RETURN(errors); +} diff --git a/tests/6.0/taskgraph/test_taskgraph_parallel.c b/tests/6.0/taskgraph/test_taskgraph_parallel.c new file mode 100644 index 000000000..07b34329f --- /dev/null +++ b/tests/6.0/taskgraph/test_taskgraph_parallel.c @@ -0,0 +1,58 @@ +//===-- test_taskgraph.c ------------------------------------------------===// +// +// OpenMP API Version 6.0 Nov 2024 +// +// Description +// testTaskgraphParallel(): +// 'N' times, have multiple 'nthreads' threads construcitng/replaying the same taskgraph. +// It should execute the strucuted block once, and the replayable task 'N*nthreads' times +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include "ompvv.h" + +int testTaskgraphParallel(void) +{ + int errors = 0; + + # define N 16 + int x = 0; + int y = 0; + int nthreads = 0; + + #pragma omp parallel shared(x, y, nthreads) + { + # pragma omp single + { + nthreads = omp_get_num_threads(); + } + + for (int i = 0 ; i < N ; ++i) + { + # pragma omp taskgraph + { + ++x; + # pragma omp task shared(y) + { + # pragma omp atomic + ++y; + } + } + } + } + OMPVV_TEST_AND_SET_VERBOSE(errors, nthreads >= 0); + OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y == nthreads*N); + + return errors; +} + +int main(void) +{ + int errors = 0; + OMPVV_TEST_AND_SET_VERBOSE(errors, testTaskgraphParallel()); + OMPVV_REPORT_AND_RETURN(errors); +} diff --git a/tests/6.0/taskgraph/test_taskgraph_replay.c b/tests/6.0/taskgraph/test_taskgraph_replay.c new file mode 100644 index 000000000..9264b72c5 --- /dev/null +++ b/tests/6.0/taskgraph/test_taskgraph_replay.c @@ -0,0 +1,58 @@ +//===-- test_taskgraph.c ------------------------------------------------===// +// +// OpenMP API Version 6.0 Nov 2024 +// +// Description +// testTaskgraph(): +// Create a taskgraph, and ensures that the +// the structured block is executed only once, +// and that the task is replayed +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include "ompvv.h" + +int testTaskgraphReplay(void) +{ + int errors = 0; + # define N 16 + # define M 16 + + int x = 0; + int y = 0; + + #pragma omp parallel shared(x, y) + { + # pragma omp single + { + for (int i = 0 ; i < N ; ++i) + { + # pragma omp taskgraph + { + ++x; + for (int j = 0 ; j < M ; ++j) + { + # pragma omp task shared(y) + { + # pragma omp atomic + ++y; + } + } + } + } + } + } + OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y == M*N); + return errors; +} + +int main(void) +{ + int errors = 0; + OMPVV_TEST_AND_SET_VERBOSE(errors, testTaskgraphReplay()); + OMPVV_REPORT_AND_RETURN(errors); +} diff --git a/tests/6.0/taskgraph/test_taskgraph_reset.c b/tests/6.0/taskgraph/test_taskgraph_reset.c new file mode 100644 index 000000000..c8c6f1f25 --- /dev/null +++ b/tests/6.0/taskgraph/test_taskgraph_reset.c @@ -0,0 +1,75 @@ +//===-- test_taskgraph.c ------------------------------------------------===// +// +// OpenMP API Version 6.0 Nov 2024 +// +// Description +// testTaskgraphGraphReset(): +// Create 'M' taskgraphs that spawns 3 tasks +// T1 -> T2 -> T3 +// with (T1, T3) on device, (T2) on host. +// Replay taskgraphs 'N' times, while reseting every second iterations +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include "ompvv.h" + +int testTaskgraphGraphReset(void) +{ + int errors = 0; + + # define N 16 + # define M 16 + _Static_assert(M % 2 == 0); + + int x[M]; // number of time the structued block executed for taskgraph i + int y[M]; // number of time tasks executes for taskgraph i + memset(x, 0, sizeof(x)); + memset(y, 0, sizeof(y)); + + # pragma omp parallel shared(x, y) + { + # pragma omp single + { + for (int i = 0 ; i < N ; ++i) + { + for (int j = 0 ; j < M ; ++j) + { + # pragma omp taskgraph graph_id(j) graph_reset(j % 2 == 0) + { + ++x[j]; + + # pragma omp target map(tofrom: y) depend(out: y) + ++x[j]; + + # pragma omp task depend(out: y) + ++x[j]; + + # pragma omp target map(tofrom: y) depend(out: y) + ++x[j]; + } + } + } + } + } + + for (int j = 0 ; j < M ; ++j) + { + // each taskgraph strucuted block must have executed once + OMPVV_TEST_AND_SET_VERBOSE(errors, x[j] == M/2); + + // each triplets must have executed N times + OMPVV_TEST_AND_SET_VERBOSE(errors, y[j] == 3*N); + } + + return errors; +} + +int main(void) +{ + int errors = 0; + OMPVV_TEST_AND_SET_VERBOSE(errors, testTaskgraphGraphReset()); + OMPVV_REPORT_AND_RETURN(errors); +} From fd47b8d42c4de20f93a1a021f187d4dc3647e0bc Mon Sep 17 00:00:00 2001 From: Romain Pereira Date: Sat, 4 Oct 2025 01:55:09 +0000 Subject: [PATCH 2/6] Warning on static assert --- tests/6.0/taskgraph/test_taskgraph_reset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/6.0/taskgraph/test_taskgraph_reset.c b/tests/6.0/taskgraph/test_taskgraph_reset.c index c8c6f1f25..e98021345 100644 --- a/tests/6.0/taskgraph/test_taskgraph_reset.c +++ b/tests/6.0/taskgraph/test_taskgraph_reset.c @@ -22,7 +22,7 @@ int testTaskgraphGraphReset(void) # define N 16 # define M 16 - _Static_assert(M % 2 == 0); + _Static_assert(M % 2 == 0, "M must be even"); int x[M]; // number of time the structued block executed for taskgraph i int y[M]; // number of time tasks executes for taskgraph i From 132577184bd55863e322914db5ba111d8134ab90 Mon Sep 17 00:00:00 2001 From: Romain Pereira Date: Sat, 4 Oct 2025 02:13:42 +0000 Subject: [PATCH 3/6] Replaced some target tasks with host task, and set shared where appropriated --- .../taskgraph/test_taskgraph_heterogeneous.c | 14 ++--- tests/6.0/taskgraph/test_taskgraph_id.c | 53 +++++++++---------- tests/6.0/taskgraph/test_taskgraph_if.c | 2 +- tests/6.0/taskgraph/test_taskgraph_nogroup.c | 6 +-- tests/6.0/taskgraph/test_taskgraph_parallel.c | 4 +- tests/6.0/taskgraph/test_taskgraph_replay.c | 8 +-- tests/6.0/taskgraph/test_taskgraph_reset.c | 48 ++++++++--------- 7 files changed, 64 insertions(+), 71 deletions(-) diff --git a/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c b/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c index dd48f3cfb..5b328455f 100644 --- a/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c +++ b/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c @@ -3,12 +3,14 @@ // OpenMP API Version 6.0 Nov 2024 // // Description -// testTaskgrapHeterogeneoush(): -// Create a taskgraph, spawns 3 tasks +// testTaskgraphHeterogeneous(): +// Create a taskgraph, spawns 3 dependent tasks // T1 -> T2 -> T3 // with (T1, T3) on device, (T2) on host. // -// Also ensures that the structured block is executed once +// Ensures that +// - the structured block is executed once +// - 3*N tasks executed/replayed //===----------------------------------------------------------------------===// #include @@ -35,13 +37,13 @@ int testTaskgraphHeterogeneous(void) { ++x; - # pragma omp target nowait map(tofrom: y) depend(out: y) + # pragma omp target nowait map(tofrom: y) depend(out: y) shared(y) ++y; - # pragma omp task depend(out: y) + # pragma omp task depend(out: y) shared(y) ++y; - # pragma omp target nowait map(tofrom: y) depend(out: y) + # pragma omp target nowait map(tofrom: y) depend(out: y) shared(y) ++y; } } diff --git a/tests/6.0/taskgraph/test_taskgraph_id.c b/tests/6.0/taskgraph/test_taskgraph_id.c index db00d5593..c15044d18 100644 --- a/tests/6.0/taskgraph/test_taskgraph_id.c +++ b/tests/6.0/taskgraph/test_taskgraph_id.c @@ -1,13 +1,16 @@ -//===-- test_taskgraph.c ------------------------------------------------===// +//===-- test_taskgraph_id.c ------------------------------------------------===// // // OpenMP API Version 6.0 Nov 2024 // // Description // testTaskgraphId(): -// Create 'M' taskgraphs that spawns 3 tasks +// Create 'N' taskgraphs with id '0<=i T2 -> T3 -// with (T1, T3) on device, (T2) on host. -// Replay taskgraph 'N' times +// +// Replay each taskgraph 'M' times +// +// Ensure that each strucuted block only executed once +// Ensure that each triplets evexecuted 'N' times //===----------------------------------------------------------------------===// #include @@ -22,45 +25,41 @@ int testTaskgraphGraphId(void) # define N 16 # define M 16 - int x[M]; // number of time the structued block executed for taskgraph i - int y[M]; // number of time tasks executes for taskgraph i - memset(x, 0, sizeof(x)); - memset(y, 0, sizeof(y)); + + int x = 0; + int y = 0; # pragma omp parallel shared(x, y) { # pragma omp single { - for (int i = 0 ; i < N ; ++i) + for (int j = 0 ; j < M ; ++j) { - for (int j = 0 ; j < M ; ++j) + for (int i = 0 ; i < N ; ++i) { - # pragma omp taskgraph graph_id(j) + # pragma omp taskgraph graph_id(i) { - ++x[j]; - - # pragma omp target map(tofrom: y) depend(out: y) - ++y[j]; + ++x; - # pragma omp task depend(out: y) - ++y[j]; - - # pragma omp target map(tofrom: y) depend(out: y) - ++y[j]; + for (int i = 0 ; i < 3 ; ++i) + { + # pragma omp task depend(out: y) shared(y) + { + # pragma omp atomic + ++y; + } + } } } } } } - for (int j = 0 ; j < M ; ++j) - { - // each taskgraph strucuted block must have executed once - OMPVV_TEST_AND_SET_VERBOSE(errors, x[j] == 1); + // each taskgraph strucuted block must have executed once + OMPVV_TEST_AND_SET_VERBOSE(errors, x == N); - // each triplets must have executed N times - OMPVV_TEST_AND_SET_VERBOSE(errors, y[j] == 3*N); - } + // each triplets must have executed N times + OMPVV_TEST_AND_SET_VERBOSE(errors, y == 3*N*M); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_if.c b/tests/6.0/taskgraph/test_taskgraph_if.c index c09ec255e..6312b4445 100644 --- a/tests/6.0/taskgraph/test_taskgraph_if.c +++ b/tests/6.0/taskgraph/test_taskgraph_if.c @@ -33,7 +33,7 @@ int testTaskgraphIf(void) { ++x; - # pragma omp task + # pragma omp task shared(y) ++y; } } diff --git a/tests/6.0/taskgraph/test_taskgraph_nogroup.c b/tests/6.0/taskgraph/test_taskgraph_nogroup.c index 170728b47..b5bbd24d3 100644 --- a/tests/6.0/taskgraph/test_taskgraph_nogroup.c +++ b/tests/6.0/taskgraph/test_taskgraph_nogroup.c @@ -4,10 +4,8 @@ // // Description // testTaskgraphNoGroup(): -// Create a taskgraph, and ensures the structured block is executed once. -// Then reexecute construct twice with if(0) and if(1), -// and ensures that the structured block executed once, -// and records twice +// Create a taskgraph nogroup, replay N times, +// and ensures the structured block is executed once. //===----------------------------------------------------------------------===// #include diff --git a/tests/6.0/taskgraph/test_taskgraph_parallel.c b/tests/6.0/taskgraph/test_taskgraph_parallel.c index 07b34329f..496c31dc1 100644 --- a/tests/6.0/taskgraph/test_taskgraph_parallel.c +++ b/tests/6.0/taskgraph/test_taskgraph_parallel.c @@ -4,8 +4,8 @@ // // Description // testTaskgraphParallel(): -// 'N' times, have multiple 'nthreads' threads construcitng/replaying the same taskgraph. -// It should execute the strucuted block once, and the replayable task 'N*nthreads' times +// 'N' times, have 'nthreads' threads construcitng/replaying the same taskgraph. +// It should execute the structured block once, and the replayable task 'N*nthreads' times //===----------------------------------------------------------------------===// #include diff --git a/tests/6.0/taskgraph/test_taskgraph_replay.c b/tests/6.0/taskgraph/test_taskgraph_replay.c index 9264b72c5..44c6ed3c1 100644 --- a/tests/6.0/taskgraph/test_taskgraph_replay.c +++ b/tests/6.0/taskgraph/test_taskgraph_replay.c @@ -3,10 +3,10 @@ // OpenMP API Version 6.0 Nov 2024 // // Description -// testTaskgraph(): -// Create a taskgraph, and ensures that the -// the structured block is executed only once, -// and that the task is replayed +// testTaskgraphReplay(): +// Create a taskgraph of 'M' tasks, replay it 'N' times. +// Ensures that the structured block is executed only once, +// and that the tasks are replayed N times //===----------------------------------------------------------------------===// #include diff --git a/tests/6.0/taskgraph/test_taskgraph_reset.c b/tests/6.0/taskgraph/test_taskgraph_reset.c index e98021345..0fd6b3b07 100644 --- a/tests/6.0/taskgraph/test_taskgraph_reset.c +++ b/tests/6.0/taskgraph/test_taskgraph_reset.c @@ -1,4 +1,4 @@ -//===-- test_taskgraph.c ------------------------------------------------===// +//===-- test_taskgraph_reset.c ------------------------------------------------===// // // OpenMP API Version 6.0 Nov 2024 // @@ -7,7 +7,9 @@ // Create 'M' taskgraphs that spawns 3 tasks // T1 -> T2 -> T3 // with (T1, T3) on device, (T2) on host. -// Replay taskgraphs 'N' times, while reseting every second iterations +// Replay taskgraphs 'N' times, while reseting every second iterations. +// +// Ensures that structured block executed 'N/2' times //===----------------------------------------------------------------------===// #include @@ -21,13 +23,10 @@ int testTaskgraphGraphReset(void) int errors = 0; # define N 16 - # define M 16 - _Static_assert(M % 2 == 0, "M must be even"); + _Static_assert(N % 2 == 0, "N must be even"); - int x[M]; // number of time the structued block executed for taskgraph i - int y[M]; // number of time tasks executes for taskgraph i - memset(x, 0, sizeof(x)); - memset(y, 0, sizeof(y)); + int x = 0; + int y = 0; # pragma omp parallel shared(x, y) { @@ -35,34 +34,29 @@ int testTaskgraphGraphReset(void) { for (int i = 0 ; i < N ; ++i) { - for (int j = 0 ; j < M ; ++j) + # pragma omp taskgraph graph_reset(i % 2 == 0) { - # pragma omp taskgraph graph_id(j) graph_reset(j % 2 == 0) - { - ++x[j]; - - # pragma omp target map(tofrom: y) depend(out: y) - ++x[j]; - - # pragma omp task depend(out: y) - ++x[j]; + # pragma omp atomic + ++x; - # pragma omp target map(tofrom: y) depend(out: y) - ++x[j]; + for (int i = 0 ; i < 3 ; ++i) + { + # pragma omp task depend(out: y) shared(y) + { + # pragma omp atomic + ++y; + } } } } } } - for (int j = 0 ; j < M ; ++j) - { - // each taskgraph strucuted block must have executed once - OMPVV_TEST_AND_SET_VERBOSE(errors, x[j] == M/2); + // each taskgraph strucuted block must have executed once + OMPVV_TEST_AND_SET_VERBOSE(errors, x == N/2); - // each triplets must have executed N times - OMPVV_TEST_AND_SET_VERBOSE(errors, y[j] == 3*N); - } + // each triplets must have executed N times + OMPVV_TEST_AND_SET_VERBOSE(errors, y == 3*N); return errors; } From 95c7f0a348f20901ef6b959460fefdde4218742f Mon Sep 17 00:00:00 2001 From: Romain Pereira Date: Sat, 4 Oct 2025 02:50:13 +0000 Subject: [PATCH 4/6] all conditions were inverted, fixed it --- tests/6.0/taskgraph/test_taskgraph.c | 2 +- tests/6.0/taskgraph/test_taskgraph_heterogeneous.c | 4 ++-- tests/6.0/taskgraph/test_taskgraph_id.c | 4 ++-- tests/6.0/taskgraph/test_taskgraph_if.c | 4 ++-- tests/6.0/taskgraph/test_taskgraph_nogroup.c | 4 ++-- tests/6.0/taskgraph/test_taskgraph_parallel.c | 8 ++++---- tests/6.0/taskgraph/test_taskgraph_replay.c | 4 ++-- tests/6.0/taskgraph/test_taskgraph_reset.c | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/6.0/taskgraph/test_taskgraph.c b/tests/6.0/taskgraph/test_taskgraph.c index f5292e85d..cf0480321 100644 --- a/tests/6.0/taskgraph/test_taskgraph.c +++ b/tests/6.0/taskgraph/test_taskgraph.c @@ -27,7 +27,7 @@ int testTaskgraph(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c b/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c index 5b328455f..6b9bf1a6f 100644 --- a/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c +++ b/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c @@ -49,8 +49,8 @@ int testTaskgraphHeterogeneous(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); - OMPVV_TEST_AND_SET_VERBOSE(errors, y == 3*N); + OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y != 3*N); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_id.c b/tests/6.0/taskgraph/test_taskgraph_id.c index c15044d18..a18644553 100644 --- a/tests/6.0/taskgraph/test_taskgraph_id.c +++ b/tests/6.0/taskgraph/test_taskgraph_id.c @@ -56,10 +56,10 @@ int testTaskgraphGraphId(void) } // each taskgraph strucuted block must have executed once - OMPVV_TEST_AND_SET_VERBOSE(errors, x == N); + OMPVV_TEST_AND_SET_VERBOSE(errors, x != N); // each triplets must have executed N times - OMPVV_TEST_AND_SET_VERBOSE(errors, y == 3*N*M); + OMPVV_TEST_AND_SET_VERBOSE(errors, y != 3*N*M); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_if.c b/tests/6.0/taskgraph/test_taskgraph_if.c index 6312b4445..423b1a794 100644 --- a/tests/6.0/taskgraph/test_taskgraph_if.c +++ b/tests/6.0/taskgraph/test_taskgraph_if.c @@ -39,8 +39,8 @@ int testTaskgraphIf(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); - OMPVV_TEST_AND_SET_VERBOSE(errors, y == 2); + OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y != 2); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_nogroup.c b/tests/6.0/taskgraph/test_taskgraph_nogroup.c index b5bbd24d3..222f36592 100644 --- a/tests/6.0/taskgraph/test_taskgraph_nogroup.c +++ b/tests/6.0/taskgraph/test_taskgraph_nogroup.c @@ -39,8 +39,8 @@ int testTaskgraphNoGroup(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); - OMPVV_TEST_AND_SET_VERBOSE(errors, y == N); + OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y != N); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_parallel.c b/tests/6.0/taskgraph/test_taskgraph_parallel.c index 496c31dc1..abadcfc98 100644 --- a/tests/6.0/taskgraph/test_taskgraph_parallel.c +++ b/tests/6.0/taskgraph/test_taskgraph_parallel.c @@ -21,7 +21,7 @@ int testTaskgraphParallel(void) # define N 16 int x = 0; int y = 0; - int nthreads = 0; + int nthreads = -1; #pragma omp parallel shared(x, y, nthreads) { @@ -43,9 +43,9 @@ int testTaskgraphParallel(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, nthreads >= 0); - OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); - OMPVV_TEST_AND_SET_VERBOSE(errors, y == nthreads*N); + OMPVV_TEST_AND_SET_VERBOSE(errors, nthreads <= 0); + OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y != nthreads*N); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_replay.c b/tests/6.0/taskgraph/test_taskgraph_replay.c index 44c6ed3c1..673526529 100644 --- a/tests/6.0/taskgraph/test_taskgraph_replay.c +++ b/tests/6.0/taskgraph/test_taskgraph_replay.c @@ -45,8 +45,8 @@ int testTaskgraphReplay(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, x == 1); - OMPVV_TEST_AND_SET_VERBOSE(errors, y == M*N); + OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, y != M*N); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_reset.c b/tests/6.0/taskgraph/test_taskgraph_reset.c index 0fd6b3b07..c16aa1505 100644 --- a/tests/6.0/taskgraph/test_taskgraph_reset.c +++ b/tests/6.0/taskgraph/test_taskgraph_reset.c @@ -53,10 +53,10 @@ int testTaskgraphGraphReset(void) } // each taskgraph strucuted block must have executed once - OMPVV_TEST_AND_SET_VERBOSE(errors, x == N/2); + OMPVV_TEST_AND_SET_VERBOSE(errors, x != N/2); // each triplets must have executed N times - OMPVV_TEST_AND_SET_VERBOSE(errors, y == 3*N); + OMPVV_TEST_AND_SET_VERBOSE(errors, y != 3*N); return errors; } From 091773b65dcf62f272f72a627033cb8d09a20de0 Mon Sep 17 00:00:00 2001 From: PEREIRA Romain Date: Thu, 6 Nov 2025 12:58:05 -0600 Subject: [PATCH 5/6] Update tests/6.0/taskgraph/test_taskgraph_if.c Co-authored-by: Swaroop Pophale --- tests/6.0/taskgraph/test_taskgraph_if.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/6.0/taskgraph/test_taskgraph_if.c b/tests/6.0/taskgraph/test_taskgraph_if.c index 423b1a794..26457be34 100644 --- a/tests/6.0/taskgraph/test_taskgraph_if.c +++ b/tests/6.0/taskgraph/test_taskgraph_if.c @@ -5,9 +5,9 @@ // Description // testTaskgraphIf(): // Call -// taskgraph if(1) -// taskgraph if(0) -// taskgraph if(1) +// taskgraph if(0) --> execute structured block, create taskgraph +// taskgraph if(1) --> skip +// taskgraph if(2) --> replay taskgraph // and ensures that the structured block is executed only once, // and records twice //===----------------------------------------------------------------------===// From f7e056004a9dbbe404f29b870a4e26677f82ca51 Mon Sep 17 00:00:00 2001 From: Romain Pereira Date: Tue, 25 Nov 2025 21:01:37 +0000 Subject: [PATCH 6/6] Fix structured block execution tests The spec says: '[...] Execution of the structured block associated with the construct, while optionally creating a taskgraph record of all encountered replayable constructs and the sequence in which they are encountered; or [...]' Tests now check that the structured block executed at least once, and no more than 'N' times in iterative taskgraph calls --- tests/6.0/taskgraph/test_taskgraph.c | 3 +- .../taskgraph/test_taskgraph_heterogeneous.c | 7 +++-- tests/6.0/taskgraph/test_taskgraph_id.c | 31 ++++++++++--------- tests/6.0/taskgraph/test_taskgraph_if.c | 17 +++++++--- tests/6.0/taskgraph/test_taskgraph_nogroup.c | 6 ++-- tests/6.0/taskgraph/test_taskgraph_parallel.c | 8 +++-- tests/6.0/taskgraph/test_taskgraph_replay.c | 8 ++--- tests/6.0/taskgraph/test_taskgraph_reset.c | 14 +++++---- 8 files changed, 54 insertions(+), 40 deletions(-) diff --git a/tests/6.0/taskgraph/test_taskgraph.c b/tests/6.0/taskgraph/test_taskgraph.c index cf0480321..f4b703232 100644 --- a/tests/6.0/taskgraph/test_taskgraph.c +++ b/tests/6.0/taskgraph/test_taskgraph.c @@ -4,7 +4,8 @@ // // Description // testTaskgraph(): -// Create a taskgraph, and ensures the structured block is executed once +// Create a taskgraph +// Ensures the structured block is executed //===----------------------------------------------------------------------===// #include diff --git a/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c b/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c index 6b9bf1a6f..b7660d034 100644 --- a/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c +++ b/tests/6.0/taskgraph/test_taskgraph_heterogeneous.c @@ -9,8 +9,8 @@ // with (T1, T3) on device, (T2) on host. // // Ensures that -// - the structured block is executed once -// - 3*N tasks executed/replayed +// - the structured block is executed 1 to N times +// - 3*N tasks are executed/replayed //===----------------------------------------------------------------------===// #include @@ -49,7 +49,8 @@ int testTaskgraphHeterogeneous(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + + OMPVV_TEST_AND_SET_VERBOSE(errors, !(0 < x && x <= N)); OMPVV_TEST_AND_SET_VERBOSE(errors, y != 3*N); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_id.c b/tests/6.0/taskgraph/test_taskgraph_id.c index a18644553..1c6c69516 100644 --- a/tests/6.0/taskgraph/test_taskgraph_id.c +++ b/tests/6.0/taskgraph/test_taskgraph_id.c @@ -4,13 +4,10 @@ // // Description // testTaskgraphId(): -// Create 'N' taskgraphs with id '0<=i T2 -> T3 -// -// Replay each taskgraph 'M' times -// -// Ensure that each strucuted block only executed once -// Ensure that each triplets evexecuted 'N' times +// Ensure that each taskgraph' structured block executed 1 to M times +// Ensure that each triplets executed precisely M times //===----------------------------------------------------------------------===// #include @@ -26,8 +23,10 @@ int testTaskgraphGraphId(void) # define N 16 # define M 16 - int x = 0; - int y = 0; + int x[N]; + int y[N]; + memset(x, 0, sizeof(x)); + memset(y, 0, sizeof(y)); # pragma omp parallel shared(x, y) { @@ -39,14 +38,13 @@ int testTaskgraphGraphId(void) { # pragma omp taskgraph graph_id(i) { - ++x; - + ++x[i]; for (int i = 0 ; i < 3 ; ++i) { # pragma omp task depend(out: y) shared(y) { # pragma omp atomic - ++y; + ++y[i]; } } } @@ -55,11 +53,14 @@ int testTaskgraphGraphId(void) } } - // each taskgraph strucuted block must have executed once - OMPVV_TEST_AND_SET_VERBOSE(errors, x != N); + for (int i = 0 ; i < N ; ++i) + { + // each taskgraph strucuted block must have executed 1 to M times + OMPVV_TEST_AND_SET_VERBOSE(errors, !(0 < x[i] && x[i] <= M)); - // each triplets must have executed N times - OMPVV_TEST_AND_SET_VERBOSE(errors, y != 3*N*M); + // each triplets must have executed M times + OMPVV_TEST_AND_SET_VERBOSE(errors, y[i] != M); + } return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_if.c b/tests/6.0/taskgraph/test_taskgraph_if.c index 26457be34..8226255b9 100644 --- a/tests/6.0/taskgraph/test_taskgraph_if.c +++ b/tests/6.0/taskgraph/test_taskgraph_if.c @@ -5,11 +5,12 @@ // Description // testTaskgraphIf(): // Call -// taskgraph if(0) --> execute structured block, create taskgraph +// taskgraph if(0) --> execute taskgraph construct, optionally creating a taskgraph record // taskgraph if(1) --> skip -// taskgraph if(2) --> replay taskgraph -// and ensures that the structured block is executed only once, -// and records twice +// taskgraph if(2) --> execute taskgraph construct, maybe replay taskgraph +// record, or optionally create a taskgraph record +// ensures that the structured block is executed 1 or 2 times +// ensures that tasks are executed twice //===----------------------------------------------------------------------===// #include @@ -39,8 +40,14 @@ int testTaskgraphIf(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + + // the structured block must have been executed once or twice + // (once if creating a taskgraph record, twice if creating no taskgraph record) + OMPVV_TEST_AND_SET_VERBOSE(errors, !(x == 1 || x == 2)); + + // the task must execute precisely twice OMPVV_TEST_AND_SET_VERBOSE(errors, y != 2); + return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_nogroup.c b/tests/6.0/taskgraph/test_taskgraph_nogroup.c index 222f36592..a57821a66 100644 --- a/tests/6.0/taskgraph/test_taskgraph_nogroup.c +++ b/tests/6.0/taskgraph/test_taskgraph_nogroup.c @@ -4,8 +4,8 @@ // // Description // testTaskgraphNoGroup(): -// Create a taskgraph nogroup, replay N times, -// and ensures the structured block is executed once. +// Run a taskgraph nogroup construct N times, +// ensures the structured block is executed from 1 to N times //===----------------------------------------------------------------------===// #include @@ -39,7 +39,7 @@ int testTaskgraphNoGroup(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, !(0 < x && x <= N)); OMPVV_TEST_AND_SET_VERBOSE(errors, y != N); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_parallel.c b/tests/6.0/taskgraph/test_taskgraph_parallel.c index abadcfc98..bc83c6328 100644 --- a/tests/6.0/taskgraph/test_taskgraph_parallel.c +++ b/tests/6.0/taskgraph/test_taskgraph_parallel.c @@ -4,8 +4,10 @@ // // Description // testTaskgraphParallel(): -// 'N' times, have 'nthreads' threads construcitng/replaying the same taskgraph. -// It should execute the structured block once, and the replayable task 'N*nthreads' times +// N times, have 'nthreads' threads call the same taskgraph construct +// +// ensure the structured block executed 1 to N times, +// and the replayable task 'N*nthreads' times //===----------------------------------------------------------------------===// #include @@ -44,7 +46,7 @@ int testTaskgraphParallel(void) } } OMPVV_TEST_AND_SET_VERBOSE(errors, nthreads <= 0); - OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, !(0 < x && x <= N)); OMPVV_TEST_AND_SET_VERBOSE(errors, y != nthreads*N); return errors; diff --git a/tests/6.0/taskgraph/test_taskgraph_replay.c b/tests/6.0/taskgraph/test_taskgraph_replay.c index 673526529..0d66d12dd 100644 --- a/tests/6.0/taskgraph/test_taskgraph_replay.c +++ b/tests/6.0/taskgraph/test_taskgraph_replay.c @@ -4,9 +4,9 @@ // // Description // testTaskgraphReplay(): -// Create a taskgraph of 'M' tasks, replay it 'N' times. -// Ensures that the structured block is executed only once, -// and that the tasks are replayed N times +// N times, run a taskgraph construct spawning M tasks +// Ensures that the structured block is executed one to N times +// Ensures that the tasks structured block is executed M*N times //===----------------------------------------------------------------------===// #include @@ -45,7 +45,7 @@ int testTaskgraphReplay(void) } } } - OMPVV_TEST_AND_SET_VERBOSE(errors, x != 1); + OMPVV_TEST_AND_SET_VERBOSE(errors, !(0 < x && x <= N)); OMPVV_TEST_AND_SET_VERBOSE(errors, y != M*N); return errors; } diff --git a/tests/6.0/taskgraph/test_taskgraph_reset.c b/tests/6.0/taskgraph/test_taskgraph_reset.c index c16aa1505..1f632f60a 100644 --- a/tests/6.0/taskgraph/test_taskgraph_reset.c +++ b/tests/6.0/taskgraph/test_taskgraph_reset.c @@ -4,12 +4,12 @@ // // Description // testTaskgraphGraphReset(): -// Create 'M' taskgraphs that spawns 3 tasks +// Run the same taskgraph constructs N times, that spawns 3 tasks // T1 -> T2 -> T3 // with (T1, T3) on device, (T2) on host. -// Replay taskgraphs 'N' times, while reseting every second iterations. -// -// Ensures that structured block executed 'N/2' times +// while reseting every second iterations. +// +// Ensures that structured block executed N/2 to N times //===----------------------------------------------------------------------===// #include @@ -52,8 +52,10 @@ int testTaskgraphGraphReset(void) } } - // each taskgraph strucuted block must have executed once - OMPVV_TEST_AND_SET_VERBOSE(errors, x != N/2); + // taskgraph structured block must have executed at least N/2 times (is + // always creating a taskgraph record), and at most N times (if never + // creating a taskgraph record) + OMPVV_TEST_AND_SET_VERBOSE(errors, (N/2 <= x && x <= N)); // each triplets must have executed N times OMPVV_TEST_AND_SET_VERBOSE(errors, y != 3*N);