Skip to content

Commit 505a07e

Browse files
jtb20Munesanz
andcommitted
[OpenMP] New/derived taskgraph tests
This patch adds new tests for 'omp taskgraph' functionality, but (unlike the patches posted in PR66919) leave the existing tests using the internal runtime API for record and replay as-is. I have changed the 'print_dot' tests to use FileCheck instead of their own internal checking, though. Co-authored-by: Adrian Munera <[email protected]>
1 parent 0e8d4d5 commit 505a07e

File tree

6 files changed

+271
-32
lines changed

6 files changed

+271
-32
lines changed
Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// REQUIRES: omp_taskgraph_experimental
22
// RUN: %libomp-cxx-compile-and-run
3-
#include <iostream>
4-
#include <fstream>
5-
#include <sstream>
3+
// RUN: cat tdg_0.dot | FileCheck %s
4+
// RUN: rm -f tdg_0.dot
5+
6+
#include <cstdlib>
67
#include <cassert>
78

89
// Compiler-generated code (emulation)
@@ -23,29 +24,14 @@ void func(int *num_exec) {
2324
(*num_exec)++;
2425
}
2526

26-
std::string tdg_string= "digraph TDG {\n"
27-
" compound=true\n"
28-
" subgraph cluster {\n"
29-
" label=TDG_0\n"
30-
" 0[style=bold]\n"
31-
" 1[style=bold]\n"
32-
" 2[style=bold]\n"
33-
" 3[style=bold]\n"
34-
" }\n"
35-
" 0 -> 1 \n"
36-
" 1 -> 2 \n"
37-
" 1 -> 3 \n"
38-
"}";
39-
4027
int main() {
4128
int num_exec = 0;
4229
int x, y;
4330

44-
setenv("KMP_TDG_DOT","TRUE",1);
45-
remove("tdg_0.dot");
31+
setenv("KMP_TDG_DOT", "TRUE", 1);
4632

47-
#pragma omp parallel
48-
#pragma omp single
33+
#pragma omp parallel
34+
#pragma omp single
4935
{
5036
int gtid = __kmpc_global_thread_num(nullptr);
5137
int res = __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */ 0, /* tdg_id */ 0);
@@ -65,16 +51,19 @@ int main() {
6551

6652
assert(num_exec == 4);
6753

68-
std::ifstream tdg_file("tdg_0.dot");
69-
assert(tdg_file.is_open());
70-
71-
std::stringstream tdg_file_stream;
72-
tdg_file_stream << tdg_file.rdbuf();
73-
int equal = tdg_string.compare(tdg_file_stream.str());
74-
75-
assert(equal == 0);
76-
77-
std::cout << "Passed" << std::endl;
7854
return 0;
7955
}
80-
// CHECK: Passed
56+
57+
// CHECK: digraph TDG {
58+
// CHECK-NEXT: compound=true
59+
// CHECK-NEXT: subgraph cluster {
60+
// CHECK-NEXT: label=TDG_0
61+
// CHECK-NEXT: 0[style=bold]
62+
// CHECK-NEXT: 1[style=bold]
63+
// CHECK-NEXT: 2[style=bold]
64+
// CHECK-NEXT: 3[style=bold]
65+
// CHECK-NEXT: }
66+
// CHECK-NEXT: 0 -> 1
67+
// CHECK-NEXT: 1 -> 2
68+
// CHECK-NEXT: 1 -> 3
69+
// CHECK-NEXT: }
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// REQUIRES: omp_taskgraph_experimental
2+
// RUN: %libomp-cxx-compile-and-run
3+
#include <iostream>
4+
#include <cassert>
5+
#define NT 100
6+
7+
// Compiler-generated code (emulation)
8+
typedef struct ident {
9+
void *dummy;
10+
} ident_t;
11+
12+
void func(int *num_exec) { (*num_exec)++; }
13+
14+
int main() {
15+
int num_exec = 0;
16+
int num_tasks = 0;
17+
int x = 0;
18+
#pragma omp parallel
19+
#pragma omp single
20+
for (int iter = 0; iter < NT; ++iter) {
21+
#pragma omp taskgraph
22+
{
23+
num_tasks++;
24+
#pragma omp task
25+
func(&num_exec);
26+
}
27+
}
28+
29+
assert(num_tasks == 1);
30+
assert(num_exec == NT);
31+
32+
std::cout << "Passed" << std::endl;
33+
return 0;
34+
}
35+
// CHECK: Passed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// REQUIRES: omp_taskgraph_experimental
2+
// RUN: %libomp-cxx-compile-and-run
3+
#include <iostream>
4+
#include <cassert>
5+
#define NT 100
6+
#define MULTIPLIER 100
7+
#define DECREMENT 5
8+
9+
int val;
10+
// Compiler-generated code (emulation)
11+
typedef struct ident {
12+
void *dummy;
13+
} ident_t;
14+
15+
void sub() {
16+
#pragma omp atomic
17+
val -= DECREMENT;
18+
}
19+
20+
void add() {
21+
#pragma omp atomic
22+
val += DECREMENT;
23+
}
24+
25+
void mult() {
26+
// no atomicity needed, can only be executed by 1 thread
27+
// and no concurrency with other tasks possible
28+
val *= MULTIPLIER;
29+
}
30+
31+
int main() {
32+
val = 0;
33+
int *x, *y;
34+
#pragma omp parallel
35+
#pragma omp single
36+
for (int iter = 0; iter < NT; ++iter) {
37+
#pragma omp taskgraph
38+
{
39+
#pragma omp task depend(out : y)
40+
add();
41+
#pragma omp task depend(out : x)
42+
sub();
43+
#pragma omp task depend(in : x, y)
44+
mult();
45+
}
46+
}
47+
assert(val == 0);
48+
49+
std::cout << "Passed" << std::endl;
50+
return 0;
51+
}
52+
// CHECK: Passed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// REQUIRES: omp_taskgraph_experimental
2+
// RUN: %libomp-cxx-compile-and-run
3+
#include <iostream>
4+
#include <cassert>
5+
#define NT 20
6+
#define MULTIPLIER 100
7+
#define DECREMENT 5
8+
9+
// Compiler-generated code (emulation)
10+
typedef struct ident {
11+
void *dummy;
12+
} ident_t;
13+
14+
int val;
15+
16+
void sub() {
17+
#pragma omp atomic
18+
val -= DECREMENT;
19+
}
20+
21+
void add() {
22+
#pragma omp atomic
23+
val += DECREMENT;
24+
}
25+
26+
void mult() {
27+
// no atomicity needed, can only be executed by 1 thread
28+
// and no concurrency with other tasks possible
29+
val *= MULTIPLIER;
30+
}
31+
32+
int main() {
33+
int num_tasks = 0;
34+
int *x, *y;
35+
#pragma omp parallel
36+
#pragma omp single
37+
for (int iter = 0; iter < NT; ++iter) {
38+
#pragma omp taskgraph
39+
{
40+
num_tasks++;
41+
#pragma omp task depend(out : y)
42+
add();
43+
#pragma omp task depend(out : x)
44+
sub();
45+
#pragma omp task depend(in : x, y)
46+
mult();
47+
}
48+
#pragma omp taskgraph
49+
{
50+
num_tasks++;
51+
#pragma omp task depend(out : y)
52+
add();
53+
#pragma omp task depend(out : x)
54+
sub();
55+
#pragma omp task depend(in : x, y)
56+
mult();
57+
}
58+
}
59+
60+
assert(num_tasks == 2);
61+
assert(val == 0);
62+
63+
std::cout << "Passed" << std::endl;
64+
return 0;
65+
}
66+
// CHECK: Passed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// REQUIRES: omp_taskgraph_experimental
2+
// RUN: %libomp-cxx-compile-and-run
3+
// RUN: cat tdg_17353.dot | FileCheck %s
4+
// RUN: rm -f tdg_17353.dot
5+
6+
#include <cstdlib>
7+
#include <cassert>
8+
9+
// Compiler-generated code (emulation)
10+
typedef struct ident {
11+
void *dummy;
12+
} ident_t;
13+
14+
void func(int *num_exec) {
15+
#pragma omp atomic
16+
(*num_exec)++;
17+
}
18+
19+
int main() {
20+
int num_exec = 0;
21+
int x, y;
22+
23+
setenv("KMP_TDG_DOT", "TRUE", 1);
24+
25+
#pragma omp parallel
26+
#pragma omp single
27+
{
28+
#pragma omp taskgraph
29+
{
30+
#pragma omp task depend(out : x)
31+
func(&num_exec);
32+
#pragma omp task depend(in : x) depend(out : y)
33+
func(&num_exec);
34+
#pragma omp task depend(in : y)
35+
func(&num_exec);
36+
#pragma omp task depend(in : y)
37+
func(&num_exec);
38+
}
39+
}
40+
41+
assert(num_exec == 4);
42+
43+
return 0;
44+
}
45+
46+
// CHECK: digraph TDG {
47+
// CHECK-NEXT: compound=true
48+
// CHECK-NEXT: subgraph cluster {
49+
// CHECK-NEXT: label=TDG_17353
50+
// CHECK-NEXT: 0[style=bold]
51+
// CHECK-NEXT: 1[style=bold]
52+
// CHECK-NEXT: 2[style=bold]
53+
// CHECK-NEXT: 3[style=bold]
54+
// CHECK-NEXT: }
55+
// CHECK-NEXT: 0 -> 1
56+
// CHECK-NEXT: 1 -> 2
57+
// CHECK-NEXT: 1 -> 3
58+
// CHECK-NEXT: }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// REQUIRES: omp_taskgraph_experimental
2+
// RUN: %libomp-cxx-compile-and-run
3+
#include <iostream>
4+
#include <cassert>
5+
6+
#define NT 20
7+
#define N 128 * 128
8+
9+
typedef struct ident {
10+
void *dummy;
11+
} ident_t;
12+
13+
int main() {
14+
int num_tasks = 0;
15+
16+
int array[N];
17+
for (int i = 0; i < N; ++i)
18+
array[i] = 1;
19+
20+
long sum = 0;
21+
#pragma omp parallel
22+
#pragma omp single
23+
for (int iter = 0; iter < NT; ++iter) {
24+
#pragma omp taskgraph
25+
{
26+
num_tasks++;
27+
#pragma omp taskloop reduction(+ : sum) num_tasks(4096)
28+
for (int i = 0; i < N; ++i) {
29+
sum += array[i];
30+
}
31+
}
32+
}
33+
assert(sum == N * NT);
34+
assert(num_tasks == 1);
35+
36+
std::cout << "Passed" << std::endl;
37+
return 0;
38+
}
39+
// CHECK: Passed

0 commit comments

Comments
 (0)