Skip to content

Commit 0e68f48

Browse files
committed
[OpenMP] add a offload test involving std::complex
Taken from the llvm/llvm-project#57064 reproducer. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D133258
1 parent 86e8164 commit 0e68f48

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

openmp/libomptarget/test/offloading/bug49021.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ template <typename T> int test_reduction() {
6868
return 0;
6969
}
7070

71-
template <typename T> int test_complex() {
71+
template <typename T> int test_POD() {
7272
int ret = 0;
7373
ret |= test_map<T>();
7474
ret |= test_reduction<T>();
@@ -78,8 +78,8 @@ template <typename T> int test_complex() {
7878
int main() {
7979
int ret = 0;
8080
std::cout << "Testing float" << std::endl;
81-
ret |= test_complex<float>();
81+
ret |= test_POD<float>();
8282
std::cout << "Testing double" << std::endl;
83-
ret |= test_complex<double>();
83+
ret |= test_POD<double>();
8484
return ret;
8585
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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
5+
6+
#include <cassert>
7+
#include <complex>
8+
#include <iostream>
9+
10+
template <typename T> void test_map() {
11+
std::complex<T> a(0.2, 1), a_check;
12+
#pragma omp target map(from : a_check)
13+
{ a_check = a; }
14+
15+
assert(std::abs(a - a_check) < 1e-6);
16+
}
17+
18+
template <typename RT, typename AT, typename BT> void test_plus(AT a, BT b) {
19+
std::complex<RT> c, c_host;
20+
21+
c_host = a + b;
22+
#pragma omp target map(from : c)
23+
{ c = a + b; }
24+
25+
assert(std::abs(c - c_host) < 1e-6);
26+
}
27+
28+
template <typename RT, typename AT, typename BT> void test_minus(AT a, BT b) {
29+
std::complex<RT> c, c_host;
30+
31+
c_host = a - b;
32+
#pragma omp target map(from : c)
33+
{ c = a - b; }
34+
35+
assert(std::abs(c - c_host) < 1e-6);
36+
}
37+
38+
template <typename RT, typename AT, typename BT> void test_mul(AT a, BT b) {
39+
std::complex<RT> c, c_host;
40+
41+
c_host = a * b;
42+
#pragma omp target map(from : c)
43+
{ c = a * b; }
44+
45+
assert(std::abs(c - c_host) < 1e-6);
46+
}
47+
48+
template <typename RT, typename AT, typename BT> void test_div(AT a, BT b) {
49+
std::complex<RT> c, c_host;
50+
51+
c_host = a / b;
52+
#pragma omp target map(from : c)
53+
{ c = a / b; }
54+
55+
assert(std::abs(c - c_host) < 1e-6);
56+
}
57+
58+
template <typename T> void test_complex() {
59+
test_map<T>();
60+
61+
test_plus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
62+
test_plus<T>(std::complex<T>(0, 1), T(0.5));
63+
test_plus<T>(T(0.5), std::complex<T>(0, 1));
64+
65+
test_minus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
66+
test_minus<T>(std::complex<T>(0, 1), T(0.5));
67+
test_minus<T>(T(0.5), std::complex<T>(0, 1));
68+
69+
test_mul<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
70+
test_mul<T>(std::complex<T>(0, 1), T(0.5));
71+
test_mul<T>(T(0.5), std::complex<T>(0, 1));
72+
73+
test_div<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
74+
test_div<T>(std::complex<T>(0, 1), T(0.5));
75+
test_div<T>(T(0.5), std::complex<T>(0, 1));
76+
}
77+
78+
int main() {
79+
std::cout << "Testing float" << std::endl;
80+
test_complex<float>();
81+
std::cout << "Testing double" << std::endl;
82+
test_complex<double>();
83+
return 0;
84+
}

0 commit comments

Comments
 (0)