diff --git a/openmp/libomptarget/test/offloading/bug49021.cpp b/openmp/libomptarget/test/offloading/bug49021.cpp index 57c9b9c7d9152..feeb48e73e6c4 100644 --- a/openmp/libomptarget/test/offloading/bug49021.cpp +++ b/openmp/libomptarget/test/offloading/bug49021.cpp @@ -68,7 +68,7 @@ template int test_reduction() { return 0; } -template int test_complex() { +template int test_POD() { int ret = 0; ret |= test_map(); ret |= test_reduction(); @@ -78,8 +78,8 @@ template int test_complex() { int main() { int ret = 0; std::cout << "Testing float" << std::endl; - ret |= test_complex(); + ret |= test_POD(); std::cout << "Testing double" << std::endl; - ret |= test_complex(); + ret |= test_POD(); return ret; } diff --git a/openmp/libomptarget/test/offloading/std_complex_arithmetic.cpp b/openmp/libomptarget/test/offloading/std_complex_arithmetic.cpp new file mode 100644 index 0000000000000..b06d605d29f90 --- /dev/null +++ b/openmp/libomptarget/test/offloading/std_complex_arithmetic.cpp @@ -0,0 +1,84 @@ +// RUN: %libomptarget-compilexx-generic && %libomptarget-run-generic +// RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic +// RUN: %libomptarget-compilexx-generic -O3 -ffast-math && \ +// RUN: %libomptarget-run-generic + +#include +#include +#include + +template void test_map() { + std::complex a(0.2, 1), a_check; +#pragma omp target map(from : a_check) + { a_check = a; } + + assert(std::abs(a - a_check) < 1e-6); +} + +template void test_plus(AT a, BT b) { + std::complex c, c_host; + + c_host = a + b; +#pragma omp target map(from : c) + { c = a + b; } + + assert(std::abs(c - c_host) < 1e-6); +} + +template void test_minus(AT a, BT b) { + std::complex c, c_host; + + c_host = a - b; +#pragma omp target map(from : c) + { c = a - b; } + + assert(std::abs(c - c_host) < 1e-6); +} + +template void test_mul(AT a, BT b) { + std::complex c, c_host; + + c_host = a * b; +#pragma omp target map(from : c) + { c = a * b; } + + assert(std::abs(c - c_host) < 1e-6); +} + +template void test_div(AT a, BT b) { + std::complex c, c_host; + + c_host = a / b; +#pragma omp target map(from : c) + { c = a / b; } + + assert(std::abs(c - c_host) < 1e-6); +} + +template void test_complex() { + test_map(); + + test_plus(std::complex(0, 1), std::complex(0.5, 0.3)); + test_plus(std::complex(0, 1), T(0.5)); + test_plus(T(0.5), std::complex(0, 1)); + + test_minus(std::complex(0, 1), std::complex(0.5, 0.3)); + test_minus(std::complex(0, 1), T(0.5)); + test_minus(T(0.5), std::complex(0, 1)); + + test_mul(std::complex(0, 1), std::complex(0.5, 0.3)); + test_mul(std::complex(0, 1), T(0.5)); + test_mul(T(0.5), std::complex(0, 1)); + + test_div(std::complex(0, 1), std::complex(0.5, 0.3)); + test_div(std::complex(0, 1), T(0.5)); + test_div(T(0.5), std::complex(0, 1)); +} + +int main() { + std::cout << "Testing float" << std::endl; + test_complex(); + std::cout << "Testing double" << std::endl; + test_complex(); + return 0; +}