1 // RUN: %libomptarget-compilexx-run-and-check-generic
2 
3 // Error on the gpu that crashes the host
4 // UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
5 
6 #include <iostream>
7 
8 template <typename LOOP_BODY>
9 inline void forall(int Begin, int End, LOOP_BODY LoopBody) {
10 #pragma omp target parallel for schedule(static)
11   for (int I = Begin; I < End; ++I) {
12     LoopBody(I);
13   }
14 }
15 
16 #define N (1000)
17 
18 //
19 // Demonstration of the RAJA abstraction using lambdas
20 // Requires data mapping onto the target section
21 //
22 int main() {
23   double A[N], B[N], C[N];
24 
25   for (int I = 0; I < N; I++) {
26     A[I] = I + 1;
27     B[I] = -I;
28     C[I] = -9;
29   }
30 
31 #pragma omp target data map(tofrom : C [0:N]) map(to : A [0:N], B [0:N])
32   {
33     forall(0, N, [&](int I) { C[I] += A[I] + B[I]; });
34   }
35 
36   int Fail = 0;
37   for (int I = 0; I < N; I++) {
38     if (C[I] != -8) {
39       std::cout << "Failed at " << I << " with val " << C[I] << std::endl;
40       Fail = 1;
41     }
42   }
43 
44   // CHECK: Succeeded
45   if (Fail) {
46     std::cout << "Failed" << std::endl;
47   } else {
48     std::cout << "Succeeded" << std::endl;
49   }
50 
51   return 0;
52 }
53