Skip to content

Commit 718280c

Browse files
pdhaliwal-amdtstellar
authored andcommitted
[AMDGPU][OpenMP] Use complex definitions from complex_cmath.h
Following nvptx approach, this patch uses complex function definitions from complex_cmath.h. With this patch, ovo passes 23/34 complex mathematical test cases. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D109344 (cherry picked from commit 12dcbf9)
1 parent 0c2f859 commit 718280c

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

clang/lib/Headers/openmp_wrappers/complex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#ifndef _LIBCPP_STD_VER
3737

3838
#pragma omp begin declare variant match( \
39-
device = {arch(nvptx, nvptx64)}, \
39+
device = {arch(amdgcn, nvptx, nvptx64)}, \
4040
implementation = {extension(match_any, allow_templates)})
4141

4242
#include <complex_cmath.h>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// RUN: %clang_cc1 -verify -internal-isystem %S/Inputs/include -fopenmp -x c++ -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-x86-host.bc
2+
// RUN: %clang_cc1 -verify -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/Inputs/include -fopenmp -x c++ -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -aux-triple x86_64-unknown-unknown -o - | FileCheck %s
3+
// expected-no-diagnostics
4+
5+
#include <cmath>
6+
#include <complex>
7+
8+
// CHECK: define weak {{.*}} @__muldc3
9+
// CHECK-DAG: call i32 @__ocml_isnan_f64(
10+
// CHECK-DAG: call i32 @__ocml_isinf_f64(
11+
12+
// CHECK: define weak {{.*}} @__mulsc3
13+
// CHECK-DAG: call i32 @__ocml_isnan_f32(
14+
// CHECK-DAG: call i32 @__ocml_isinf_f32(
15+
// CHECK-DAG: call float @__ocml_copysign_f32(
16+
17+
// CHECK: define weak {{.*}} @__divdc3
18+
// CHECK-DAG: call i32 @__ocml_isnan_f64(
19+
// CHECK-DAG: call i32 @__ocml_isinf_f64(
20+
// CHECK-DAG: call i32 @__ocml_isfinite_f64(
21+
// CHECK-DAG: call double @__ocml_copysign_f64(
22+
// CHECK-DAG: call double @__ocml_scalbn_f64(
23+
// CHECK-DAG: call double @__ocml_fabs_f64(
24+
// CHECK-DAG: call double @__ocml_logb_f64(
25+
26+
// CHECK: define weak {{.*}} @__divsc3
27+
// CHECK-DAG: call i32 @__ocml_isnan_f32(
28+
// CHECK-DAG: call i32 @__ocml_isinf_f32(
29+
// CHECK-DAG: call i32 @__ocml_isfinite_f32(
30+
// CHECK-DAG: call float @__ocml_copysign_f32(
31+
// CHECK-DAG: call float @__ocml_scalbn_f32(
32+
// CHECK-DAG: call float @__ocml_fabs_f32(
33+
// CHECK-DAG: call float @__ocml_logb_f32(
34+
35+
// We actually check that there are no declarations of non-OpenMP functions.
36+
// That is, as long as we don't call an unkown function with a name that
37+
// doesn't start with '__' we are good :)
38+
39+
// CHECK-NOT: declare.*@[^_]
40+
41+
void test_scmplx(std::complex<float> a) {
42+
#pragma omp target
43+
{
44+
(void)(a * (a / a));
45+
}
46+
}
47+
48+
void test_dcmplx(std::complex<double> a) {
49+
#pragma omp target
50+
{
51+
(void)(a * (a / a));
52+
}
53+
}
54+
55+
template <typename T>
56+
std::complex<T> test_template_math_calls(std::complex<T> a) {
57+
decltype(a) r = a;
58+
#pragma omp target
59+
{
60+
r = std::sin(r);
61+
r = std::cos(r);
62+
r = std::exp(r);
63+
r = std::atan(r);
64+
r = std::acos(r);
65+
}
66+
return r;
67+
}
68+
69+
std::complex<float> test_scall(std::complex<float> a) {
70+
decltype(a) r;
71+
#pragma omp target
72+
{
73+
r = std::sin(a);
74+
}
75+
return test_template_math_calls(r);
76+
}
77+
78+
std::complex<double> test_dcall(std::complex<double> a) {
79+
decltype(a) r;
80+
#pragma omp target
81+
{
82+
r = std::exp(a);
83+
}
84+
return test_template_math_calls(r);
85+
}

0 commit comments

Comments
 (0)