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
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)
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
;
27 #pragma omp target map(from : c)
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
;
37 #pragma omp target map(from : c)
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
;
47 #pragma omp target map(from : c)
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
;
57 #pragma omp target map(from : c)
60 assert(std::abs(c
- c_host
) < 1e-6);
63 template <typename T
> void test_complex() {
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));
84 std::cout
<< "Testing float" << std::endl
;
85 test_complex
<float>();
86 std::cout
<< "Testing double" << std::endl
;
87 test_complex
<double>();