Skip to content

Commit b8f3942

Browse files
authored
[SYCL] Fix device libraries and SYCL headers with spirv64 target (#13288)
``__SPIR__`` is only defined for the default `spir64` target with SYCL. We also want to support `spirv64`, so check for `__SPIRV__` too. I found this problem while working on thinLTO, if we compile device libraries with `spirv64` today, they all end up empty because of the ifdefs being false. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 239f1aa commit b8f3942

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+245
-243
lines changed

libdevice/atomic.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "device.h"
1313

14-
#ifdef __SPIR__
14+
#if defined(__SPIR__) || defined(__SPIRV__)
1515

1616
#define SPIR_GLOBAL __attribute__((opencl_global))
1717

@@ -111,4 +111,4 @@ static inline void atomicStore(int *Ptr, int V) {
111111
__spv::MemorySemanticsMask::SequentiallyConsistent, V);
112112
}
113113

114-
#endif // __SPIR__
114+
#endif // __SPIR__ || __SPIRV__

libdevice/bfloat16_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "device.h"
1010

11-
#ifdef __SPIR__
11+
#if defined(__SPIR__) || defined(__SPIRV__)
1212

1313
#include <CL/__spirv/spirv_ops.hpp>
1414
#include <cstdint>
@@ -23,4 +23,4 @@ float __devicelib_ConvertBF16ToFINTEL(const uint16_t &x) {
2323
return __spirv_ConvertBF16ToFINTEL(x);
2424
}
2525

26-
#endif // __SPIR__
26+
#endif // __SPIR__ || __SPIRV__

libdevice/cmath_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "device_math.h"
1010

11-
#if defined(__SPIR__) || defined(__NVPTX__)
11+
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__NVPTX__)
1212

1313
DEVICE_EXTERN_C_INLINE
1414
int abs(int x) { return __devicelib_abs(x); }
@@ -167,4 +167,4 @@ DEVICE_EXTERN_C_INLINE
167167
float rintf(float x) { return __nv_rintf(x); }
168168
#endif // __NVPTX__
169169

170-
#endif // __SPIR__ || __NVPTX__
170+
#endif // __SPIR__ || __SPIRV__ || __NVPTX__

libdevice/cmath_wrapper_fp64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "device_math.h"
1111

12-
#if defined(__SPIR__) || defined(__NVPTX__)
12+
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__NVPTX__)
1313

1414
// All exported functions in math and complex device libraries are weak
1515
// reference. If users provide their own math or complex functions(with
@@ -464,4 +464,4 @@ double _Sinh(double x, double y) { // compute y * sinh(x), |y| <= 1
464464
}
465465
}
466466
#endif // defined(_WIN32)
467-
#endif // __SPIR__ || __NVPTX__
467+
#endif // __SPIR__ || __SPIRV__ || __NVPTX__

libdevice/complex_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "device_complex.h"
1010

11-
#ifdef __SPIR__
11+
#if defined(__SPIR__) || defined(__SPIRV__)
1212

1313
DEVICE_EXTERN_C_INLINE
1414
float cimagf(float __complex__ z) { return __devicelib_cimagf(z); }
@@ -99,4 +99,4 @@ DEVICE_EXTERN_C_INLINE
9999
float __complex__ __divsc3(float __a, float __b, float __c, float __d) {
100100
return __devicelib___divsc3(__a, __b, __c, __d);
101101
}
102-
#endif // __SPIR__
102+
#endif // __SPIR__ || __SPIRV__

libdevice/complex_wrapper_fp64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "device_complex.h"
1111

12-
#ifdef __SPIR__
12+
#if defined(__SPIR__) || defined(__SPIRV__)
1313

1414
DEVICE_EXTERN_C_INLINE
1515
double cimag(double __complex__ z) { return __devicelib_cimag(z); }
@@ -100,4 +100,4 @@ DEVICE_EXTERN_C_INLINE
100100
double __complex__ __divdc3(double __a, double __b, double __c, double __d) {
101101
return __devicelib___divdc3(__a, __b, __c, __d);
102102
}
103-
#endif // __SPIR__
103+
#endif // __SPIR__ || __SPIRV__

libdevice/crt_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "wrapper.h"
1010

11-
#if defined(__SPIR__) || defined(__NVPTX__)
11+
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__NVPTX__)
1212
DEVICE_EXTERN_C_INLINE
1313
void *memcpy(void *dest, const void *src, size_t n) {
1414
return __devicelib_memcpy(dest, src, n);
@@ -64,4 +64,4 @@ void __assert_fail(const char *expr, const char *file, unsigned int line,
6464
__spirv_LocalInvocationId_z());
6565
}
6666
#endif
67-
#endif // __SPIR__ || __NVPTX__
67+
#endif // __SPIR__ || __SPIRV__ || __NVPTX__

libdevice/device.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define EXTERN_C
1616
#endif // __cplusplus
1717

18-
#if defined(__SPIR__) || defined(__NVPTX__)
18+
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__NVPTX__)
1919
#ifdef __SYCL_DEVICE_ONLY__
2020
#define DEVICE_EXTERNAL SYCL_EXTERNAL __attribute__((weak))
2121
#else // __SYCL_DEVICE_ONLY__
@@ -27,11 +27,11 @@
2727
DEVICE_EXTERNAL EXTERN_C __attribute__((always_inline))
2828
#define DEVICE_EXTERN_C_NOINLINE \
2929
DEVICE_EXTERNAL EXTERN_C __attribute__((noinline))
30-
#endif // __SPIR__ || __NVPTX__
30+
#endif // __SPIR__ || __SPIRV__ || __NVPTX__
3131

32-
#if defined(__SPIR__) || defined(__LIBDEVICE_HOST_IMPL__)
32+
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__LIBDEVICE_HOST_IMPL__)
3333
#define __LIBDEVICE_IMF_ENABLED__
34-
#endif // __SPIR__ || __LIBDEVICE_HOST_IMPL__
34+
#endif // __SPIR__ || __SPIRV__ || __LIBDEVICE_HOST_IMPL__
3535

3636
#ifdef __LIBDEVICE_HOST_IMPL__
3737
// For host implementation, all functions will be located in a static library

libdevice/device_complex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "device.h"
1212

13-
#ifdef __SPIR__
13+
#if defined(__SPIR__) || defined(__SPIRV__)
1414

1515
// TODO: This needs to be more robust.
1616
// clang doesn't recognize the c11 CMPLX macro, but it does have
@@ -165,5 +165,5 @@ double __complex__ __devicelib___divdc3(double a, double b, double c, double d);
165165

166166
DEVICE_EXTERN_C
167167
float __complex__ __devicelib___divsc3(float a, float b, float c, float d);
168-
#endif // __SPIR__
168+
#endif // __SPIR__ || __SPIRV__
169169
#endif // __LIBDEVICE_DEVICE_COMPLEX_H_

0 commit comments

Comments
 (0)