Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / offloading / std_complex_arithmetic.cpp
blob44f87ad732bfbf7f06876b77745424f43200b063
1 // RUN: %libomptarget-compilexx-generic && %libomptarget-run-generic
2 // RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic
3 // RUN: %libomptarget-compilexx-generic -O3 -ffast-math && \
4 // RUN: %libomptarget-run-generic
6 // FIXME: This fails to link due to missing math symbols. We should provide the
7 // needed math functions in the GPU `libm` and require the GPU C library.
8 // UNSUPPORTED: amdgcn-amd-amdhsa
10 #include <cassert>
11 #include <complex>
12 #include <iostream>
14 template <typename T> void test_map() {
15 std::complex<T> a(0.2, 1), a_check;
16 #pragma omp target map(from : a_check)
17 { a_check = a; }
19 assert(std::abs(a - a_check) < 1e-6);
22 template <typename RT, typename AT, typename BT> void test_plus(AT a, BT b) {
23 std::complex<RT> c, c_host;
25 c_host = a + b;
26 #pragma omp target map(from : c)
27 { c = a + b; }
29 assert(std::abs(c - c_host) < 1e-6);
32 template <typename RT, typename AT, typename BT> void test_minus(AT a, BT b) {
33 std::complex<RT> c, c_host;
35 c_host = a - b;
36 #pragma omp target map(from : c)
37 { c = a - b; }
39 assert(std::abs(c - c_host) < 1e-6);
42 template <typename RT, typename AT, typename BT> void test_mul(AT a, BT b) {
43 std::complex<RT> c, c_host;
45 c_host = a * b;
46 #pragma omp target map(from : c)
47 { c = a * b; }
49 assert(std::abs(c - c_host) < 1e-6);
52 template <typename RT, typename AT, typename BT> void test_div(AT a, BT b) {
53 std::complex<RT> c, c_host;
55 c_host = a / b;
56 #pragma omp target map(from : c)
57 { c = a / b; }
59 assert(std::abs(c - c_host) < 1e-6);
62 template <typename T> void test_complex() {
63 test_map<T>();
65 test_plus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
66 test_plus<T>(std::complex<T>(0, 1), T(0.5));
67 test_plus<T>(T(0.5), std::complex<T>(0, 1));
69 test_minus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
70 test_minus<T>(std::complex<T>(0, 1), T(0.5));
71 test_minus<T>(T(0.5), std::complex<T>(0, 1));
73 test_mul<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
74 test_mul<T>(std::complex<T>(0, 1), T(0.5));
75 test_mul<T>(T(0.5), std::complex<T>(0, 1));
77 test_div<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
78 test_div<T>(std::complex<T>(0, 1), T(0.5));
79 test_div<T>(T(0.5), std::complex<T>(0, 1));
82 int main() {
83 std::cout << "Testing float" << std::endl;
84 test_complex<float>();
85 std::cout << "Testing double" << std::endl;
86 test_complex<double>();
87 return 0;