[RISCV][VLOPT] Add vector narrowing integer right shift instructions to isSupportedIn...
[llvm-project.git] / offload / test / offloading / parallel_target_teams_reduction_min.cpp
blob1ab4e9868985e3b5c194308457878ecbd7c9ad2d
1 // RUN: %libomptarget-compilexx-and-run-generic
2 // RUN: %libomptarget-compileoptxx-and-run-generic
4 // FIXME: This is a bug in host offload, this should run fine.
5 // REQUIRES: gpu
7 // This test validates that the OpenMP target reductions to find a minimum work
8 // as indended for a few common data types.
10 #include <algorithm>
11 #include <cassert>
12 #include <limits>
13 #include <vector>
15 template <class Tp> void test_min_idx_reduction() {
16 const Tp length = 1000;
17 const Tp nminimas = 8;
18 std::vector<float> a(length, 3.0f);
19 const Tp step = length / nminimas;
20 for (Tp i = 0; i < nminimas; i++) {
21 a[i * step] -= 1.0f;
23 for (Tp i = 0; i < nminimas; i++) {
24 Tp idx = a.size();
25 float *b = a.data();
26 #pragma omp target teams distribute parallel for reduction(min : idx) \
27 map(always, to : b[0 : length])
28 for (Tp j = 0; j < length - 1; j++) {
29 if (b[j] < b[j + 1]) {
30 idx = std::min(idx, j);
33 assert(idx == i * step &&
34 "#pragma omp target teams distribute parallel for "
35 "reduction(min:<identifier list>) does not work as intended.");
36 a[idx] += 1.0f;
40 template <class Tp> void test_min_val_reduction() {
41 const int length = 1000;
42 const int half = length / 2;
43 std::vector<Tp> a(length, (Tp)3);
44 a[half] -= (Tp)1;
45 Tp min_val = std::numeric_limits<Tp>::max();
46 Tp *b = a.data();
47 #pragma omp target teams distribute parallel for reduction(min : min_val) \
48 map(always, to : b[0 : length])
49 for (int i = 0; i < length; i++) {
50 min_val = std::min(min_val, b[i]);
52 assert(std::abs(((double)a[half + 1]) - ((double)min_val) - 1.0) < 1e-6 &&
53 "#pragma omp target teams distribute parallel for "
54 "reduction(min:<identifier list>) does not work as intended.");
57 int main() {
58 // Reducing over indices
59 test_min_idx_reduction<int>();
60 test_min_idx_reduction<unsigned int>();
61 test_min_idx_reduction<long>();
63 // Reducing over values
64 test_min_val_reduction<int>();
65 test_min_val_reduction<unsigned int>();
66 test_min_val_reduction<long>();
67 test_min_val_reduction<float>();
68 test_min_val_reduction<double>();
69 return 0;