1// RUN: %libomptarget-compile-run-and-check-generic
2// REQUIRES: ompt
3// UNSUPPORTED: aarch64-unknown-linux-gnu
4// UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
5// UNSUPPORTED: x86_64-pc-linux-gnu
6// UNSUPPORTED: x86_64-pc-linux-gnu-LTO
7// UNSUPPORTED: s390x-ibm-linux-gnu
8// UNSUPPORTED: s390x-ibm-linux-gnu-LTO
9
10/*
11 * Example OpenMP program that registers EMI callbacks.
12 * Explicitly testing for an initialized device num and
13 * #pragma omp target [data enter / data exit / update]
14 * The latter with the addition of a nowait clause.
15 */
16
17#include <omp.h>
18#include <stdio.h>
19
20#include "callbacks.h"
21#include "register_emi.h"
22
23#define N 100000
24
25#pragma omp declare target
26int c[N];
27#pragma omp end declare target
28
29int main() {
30 int a[N];
31 int b[N];
32
33 int i;
34
35 for (i = 0; i < N; i++)
36 a[i] = 0;
37
38 for (i = 0; i < N; i++)
39 b[i] = i;
40
41 for (i = 0; i < N; i++)
42 c[i] = 0;
43
44#pragma omp target enter data map(to : a)
45#pragma omp target parallel for
46 {
47 for (int j = 0; j < N; j++)
48 a[j] = b[j];
49 }
50#pragma omp target exit data map(from : a)
51
52#pragma omp target parallel for map(alloc : c)
53 {
54 for (int j = 0; j < N; j++)
55 c[j] = 2 * j + 1;
56 }
57#pragma omp target update from(c) nowait
58#pragma omp barrier
59
60 int rc = 0;
61 for (i = 0; i < N; i++) {
62 if (a[i] != i) {
63 rc++;
64 printf(format: "Wrong value: a[%d]=%d\n", i, a[i]);
65 }
66 }
67
68 for (i = 0; i < N; i++) {
69 if (c[i] != 2 * i + 1) {
70 rc++;
71 printf(format: "Wrong value: c[%d]=%d\n", i, c[i]);
72 }
73 }
74
75 if (!rc)
76 printf(format: "Success\n");
77
78 return rc;
79}
80
81/// CHECK-NOT: Callback Target EMI:
82/// CHECK-NOT: device_num=-1
83/// CHECK: Callback Init:
84/// CHECK: Callback Load:
85/// CHECK: Callback Target EMI: kind=2 endpoint=1
86/// CHECK-NOT: device_num=-1
87/// CHECK-NOT: code=(nil)
88/// CHECK: code=[[CODE1:.*]]
89/// CHECK: Callback DataOp EMI: endpoint=1 optype=1
90/// CHECK: code=[[CODE1]]
91/// CHECK: Callback DataOp EMI: endpoint=2 optype=1
92/// CHECK-NOT: dest=(nil)
93/// CHECK: code=[[CODE1]]
94/// CHECK: Callback DataOp EMI: endpoint=1 optype=2
95/// CHECK: code=[[CODE1]]
96/// CHECK: Callback DataOp EMI: endpoint=2 optype=2
97/// CHECK: code=[[CODE1]]
98/// CHECK: Callback Target EMI: kind=2 endpoint=2
99/// CHECK-NOT: device_num=-1
100/// CHECK: code=[[CODE1]]
101/// CHECK: Callback Target EMI: kind=1 endpoint=1
102/// CHECK-NOT: device_num=-1
103/// CHECK-NOT: code=(nil)
104/// CHECK: code=[[CODE2:.*]]
105/// CHECK: Callback DataOp EMI: endpoint=1 optype=1
106/// CHECK: code=[[CODE2]]
107/// CHECK: Callback DataOp EMI: endpoint=2 optype=1
108/// CHECK-NOT: dest=(nil)
109/// CHECK: code=[[CODE2]]
110/// CHECK: Callback DataOp EMI: endpoint=1 optype=2
111/// CHECK: code=[[CODE2]]
112/// CHECK: Callback DataOp EMI: endpoint=2 optype=2
113/// CHECK: code=[[CODE2]]
114/// CHECK: Callback Submit EMI: endpoint=1 req_num_teams=1
115/// CHECK: Callback Submit EMI: endpoint=2 req_num_teams=1
116/// CHECK: Callback DataOp EMI: endpoint=1 optype=3
117/// CHECK: code=[[CODE2]]
118/// CHECK: Callback DataOp EMI: endpoint=2 optype=3
119/// CHECK: code=[[CODE2]]
120/// CHECK: Callback DataOp EMI: endpoint=1 optype=4
121/// CHECK: code=[[CODE2]]
122/// CHECK: Callback DataOp EMI: endpoint=2 optype=4
123/// CHECK: code=[[CODE2]]
124/// CHECK: Callback Target EMI: kind=1 endpoint=2
125/// CHECK-NOT: device_num=-1
126/// CHECK: code=[[CODE2]]
127/// CHECK: Callback Target EMI: kind=3 endpoint=1
128/// CHECK-NOT: device_num=-1
129/// CHECK-NOT: code=(nil)
130/// CHECK: code=[[CODE3:.*]]
131/// CHECK: Callback DataOp EMI: endpoint=1 optype=3
132/// CHECK: code=[[CODE3]]
133/// CHECK: Callback DataOp EMI: endpoint=2 optype=3
134/// CHECK: code=[[CODE3]]
135/// CHECK: Callback DataOp EMI: endpoint=1 optype=4
136/// CHECK: code=[[CODE3]]
137/// CHECK: Callback DataOp EMI: endpoint=2 optype=4
138/// CHECK: code=[[CODE3]]
139/// CHECK: Callback Target EMI: kind=3 endpoint=2
140/// CHECK-NOT: device_num=-1
141/// CHECK: code=[[CODE3]]
142/// CHECK: Callback Target EMI: kind=1 endpoint=1
143/// CHECK-NOT: device_num=-1
144/// CHECK-NOT: code=(nil)
145/// CHECK: code=[[CODE4:.*]]
146/// CHECK: Callback Submit EMI: endpoint=1 req_num_teams=1
147/// CHECK: Callback Submit EMI: endpoint=2 req_num_teams=1
148/// CHECK: Callback Target EMI: kind=1 endpoint=2
149/// CHECK-NOT: device_num=-1
150/// CHECK: code=[[CODE4]]
151/// CHECK: Callback Target EMI: kind=4 endpoint=1
152/// CHECK-NOT: device_num=-1
153/// CHECK-NOT: code=(nil)
154/// CHECK: code=[[CODE5:.*]]
155/// CHECK: Callback DataOp EMI: endpoint=1 optype=3
156/// CHECK: code=[[CODE5]]
157/// CHECK: Callback DataOp EMI: endpoint=2 optype=3
158/// CHECK: code=[[CODE5]]
159/// CHECK: Callback Target EMI: kind=4 endpoint=2
160/// CHECK-NOT: device_num=-1
161/// CHECK: code=[[CODE5]]
162/// CHECK: Callback Fini:
163

source code of offload/test/ompt/veccopy_data.c