[Instrumentation] Fix a warning
[llvm-project.git] / offload / test / offloading / std_complex_arithmetic.cpp
blob641b849bbc3e67a3e0b9d1eb5d1c84b9666d8df0
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
9 // UNSUPPORTED: nvptx64-nvidia-cuda-LTO
11 #include <cassert>
12 #include <complex>
13 #include <iostream>
15 template <typename T> void test_map() {
16 std::complex<T> a(0.2, 1), a_check;
17 #pragma omp target map(from : a_check)
18 { a_check = a; }
20 assert(std::abs(a - a_check) < 1e-6);
23 template <typename RT, typename AT, typename BT> void test_plus(AT a, BT b) {
24 std::complex<RT> c, c_host;
26 c_host = a + b;
27 #pragma omp target map(from : c)
28 { c = a + b; }
30 assert(std::abs(c - c_host) < 1e-6);
33 template <typename RT, typename AT, typename BT> void test_minus(AT a, BT b) {
34 std::complex<RT> c, c_host;
36 c_host = a - b;
37 #pragma omp target map(from : c)
38 { c = a - b; }
40 assert(std::abs(c - c_host) < 1e-6);
43 template <typename RT, typename AT, typename BT> void test_mul(AT a, BT b) {
44 std::complex<RT> c, c_host;
46 c_host = a * b;
47 #pragma omp target map(from : c)
48 { c = a * b; }
50 assert(std::abs(c - c_host) < 1e-6);
53 template <typename RT, typename AT, typename BT> void test_div(AT a, BT b) {
54 std::complex<RT> c, c_host;
56 c_host = a / b;
57 #pragma omp target map(from : c)
58 { c = a / b; }
60 assert(std::abs(c - c_host) < 1e-6);
63 template <typename T> void test_complex() {
64 test_map<T>();
66 test_plus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
67 test_plus<T>(std::complex<T>(0, 1), T(0.5));
68 test_plus<T>(T(0.5), std::complex<T>(0, 1));
70 test_minus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
71 test_minus<T>(std::complex<T>(0, 1), T(0.5));
72 test_minus<T>(T(0.5), std::complex<T>(0, 1));
74 test_mul<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
75 test_mul<T>(std::complex<T>(0, 1), T(0.5));
76 test_mul<T>(T(0.5), std::complex<T>(0, 1));
78 test_div<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
79 test_div<T>(std::complex<T>(0, 1), T(0.5));
80 test_div<T>(T(0.5), std::complex<T>(0, 1));
83 int main() {
84 std::cout << "Testing float" << std::endl;
85 test_complex<float>();
86 std::cout << "Testing double" << std::endl;
87 test_complex<double>();
88 return 0;