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