1 // RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic 2 3 // Wrong results on amdgpu 4 // XFAIL: amdgcn-amd-amdhsa 5 6 #include <iostream> 7 8 template <typename T> int test_map() { 9 std::cout << "map(complex<>)" << std::endl; 10 T a(0.2), a_check; 11 #pragma omp target map(from : a_check) 12 { a_check = a; } 13 14 if (a_check != a) { 15 std::cout << " wrong results"; 16 return 1; 17 } 18 19 return 0; 20 } 21 22 template <typename T> int test_reduction() { 23 std::cout << "flat parallelism" << std::endl; 24 T sum(0), sum_host(0); 25 const int size = 100; 26 T array[size]; 27 for (int i = 0; i < size; i++) { 28 array[i] = i; 29 sum_host += array[i]; 30 } 31 32 #pragma omp target teams distribute parallel for map(to: array[:size]) \ 33 reduction(+ : sum) 34 for (int i = 0; i < size; i++) 35 sum += array[i]; 36 37 if (sum != sum_host) 38 std::cout << " wrong results " << sum << " host " << sum_host << std::endl; 39 40 std::cout << "hierarchical parallelism" << std::endl; 41 const int nblock(10), block_size(10); 42 T block_sum[nblock]; 43 #pragma omp target teams distribute map(to \ 44 : array[:size]) \ 45 map(from \ 46 : block_sum[:nblock]) 47 for (int ib = 0; ib < nblock; ib++) { 48 T partial_sum = 0; 49 const int istart = ib * block_size; 50 const int iend = (ib + 1) * block_size; 51 #pragma omp parallel for reduction(+ : partial_sum) 52 for (int i = istart; i < iend; i++) 53 partial_sum += array[i]; 54 block_sum[ib] = partial_sum; 55 } 56 57 sum = 0; 58 for (int ib = 0; ib < nblock; ib++) { 59 sum += block_sum[ib]; 60 } 61 62 if (sum != sum_host) { 63 std::cout << " wrong results " << sum << " host " << sum_host << std::endl; 64 return 1; 65 } 66 67 return 0; 68 } 69 70 template <typename T> int test_complex() { 71 int ret = 0; 72 ret |= test_map<T>(); 73 ret |= test_reduction<T>(); 74 return ret; 75 } 76 77 int main() { 78 int ret = 0; 79 std::cout << "Testing float" << std::endl; 80 ret |= test_complex<float>(); 81 std::cout << "Testing double" << std::endl; 82 ret |= test_complex<double>(); 83 return ret; 84 } 85