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