Skip to content

Commit 100645e

Browse files
committed
[CLANG][CUDA] Enable nan/nanf from libdevice in device code
1 parent 93a1470 commit 100645e

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

clang/lib/Headers/__clang_cuda_libdevice_declares.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ __DEVICE__ float __nv_modff(float __a, float *__b);
269269
__DEVICE__ int __nv_mul24(int __a, int __b);
270270
__DEVICE__ long long __nv_mul64hi(long long __a, long long __b);
271271
__DEVICE__ int __nv_mulhi(int __a, int __b);
272-
__DEVICE__ double __nv_nan(const signed char *__a);
273-
__DEVICE__ float __nv_nanf(const signed char *__a);
272+
__DEVICE__ double __nv_nan(const char *__a);
273+
__DEVICE__ float __nv_nanf(const char *__a);
274274
__DEVICE__ double __nv_nearbyint(double __a);
275275
__DEVICE__ float __nv_nearbyintf(float __a);
276276
__DEVICE__ double __nv_nextafter(double __a, double __b);

clang/lib/Headers/__clang_cuda_math.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ __DEVICE__ int max(int __a, int __b) { return __nv_max(__a, __b); }
201201
__DEVICE__ int min(int __a, int __b) { return __nv_min(__a, __b); }
202202
__DEVICE__ double modf(double __a, double *__b) { return __nv_modf(__a, __b); }
203203
__DEVICE__ float modff(float __a, float *__b) { return __nv_modff(__a, __b); }
204+
__DEVICE__ float nanf(const char *__a) { return __nv_nanf(__a); }
205+
__DEVICE__ double nan(const char *__a) { return __nv_nan(__a); }
204206
__DEVICE__ double nearbyint(double __a) { return __builtin_nearbyint(__a); }
205207
__DEVICE__ float nearbyintf(float __a) { return __builtin_nearbyintf(__a); }
206208
__DEVICE__ double nextafter(double __a, double __b) {

clang/test/Headers/Inputs/include/math.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ long lround(double __a);
107107
long lroundf(float __a);
108108
double modf(double __a, double *__b);
109109
float modff(float __a, float *__b);
110+
float nanf(const char *__a);
111+
double nan(const char *__a);
110112
double nearbyint(double __a);
111113
float nearbyintf(float __a);
112114
double nextafter(double __a, double __b);

clang/test/Headers/nvptx_device_cmath_functions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ void test_sqrt(double a1) {
2222
double l4 = fabs(a1);
2323
// CHECK-YES: call noundef i32 @__nv_abs(i32
2424
double l5 = abs((int)a1);
25+
// CHECK-YES: call noundef float @__nv_nanf(ptr noundef
26+
float l6 = nanf("");
27+
// CHECK-YES: call noundef double @__nv_nan(ptr noundef
28+
double l7 = nan("");
2529
}
2630
}

clang/test/Headers/nvptx_device_math_functions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ void test_sqrt(double a1) {
2222
double l4 = fabs(a1);
2323
// CHECK-YES: call noundef i32 @__nv_abs(i32
2424
double l5 = abs((int)a1);
25+
// CHECK-YES: call noundef float @__nv_nanf(ptr noundef
26+
float l6 = nanf("");
27+
// CHECK-YES: call noundef double @__nv_nan(ptr noundef
28+
double l7 = nan("");
2529
}
2630
}

0 commit comments

Comments
 (0)