Skip to content

Commit

Permalink
[SYCL] Fix device libraries and SYCL headers with spirv64 target (#13288
Browse files Browse the repository at this point in the history
)

``__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 <nick.sarnie@intel.com>
  • Loading branch information
sarnex committed Apr 4, 2024
1 parent 239f1aa commit b8f3942
Show file tree
Hide file tree
Showing 41 changed files with 245 additions and 243 deletions.
4 changes: 2 additions & 2 deletions libdevice/atomic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "device.h"

#ifdef __SPIR__
#if defined(__SPIR__) || defined(__SPIRV__)

#define SPIR_GLOBAL __attribute__((opencl_global))

Expand Down Expand Up @@ -111,4 +111,4 @@ static inline void atomicStore(int *Ptr, int V) {
__spv::MemorySemanticsMask::SequentiallyConsistent, V);
}

#endif // __SPIR__
#endif // __SPIR__ || __SPIRV__
4 changes: 2 additions & 2 deletions libdevice/bfloat16_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "device.h"

#ifdef __SPIR__
#if defined(__SPIR__) || defined(__SPIRV__)

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

#endif // __SPIR__
#endif // __SPIR__ || __SPIRV__
4 changes: 2 additions & 2 deletions libdevice/cmath_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "device_math.h"

#if defined(__SPIR__) || defined(__NVPTX__)
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__NVPTX__)

DEVICE_EXTERN_C_INLINE
int abs(int x) { return __devicelib_abs(x); }
Expand Down Expand Up @@ -167,4 +167,4 @@ DEVICE_EXTERN_C_INLINE
float rintf(float x) { return __nv_rintf(x); }
#endif // __NVPTX__

#endif // __SPIR__ || __NVPTX__
#endif // __SPIR__ || __SPIRV__ || __NVPTX__
4 changes: 2 additions & 2 deletions libdevice/cmath_wrapper_fp64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "device_math.h"

#if defined(__SPIR__) || defined(__NVPTX__)
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__NVPTX__)

// All exported functions in math and complex device libraries are weak
// reference. If users provide their own math or complex functions(with
Expand Down Expand Up @@ -464,4 +464,4 @@ double _Sinh(double x, double y) { // compute y * sinh(x), |y| <= 1
}
}
#endif // defined(_WIN32)
#endif // __SPIR__ || __NVPTX__
#endif // __SPIR__ || __SPIRV__ || __NVPTX__
4 changes: 2 additions & 2 deletions libdevice/complex_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "device_complex.h"

#ifdef __SPIR__
#if defined(__SPIR__) || defined(__SPIRV__)

DEVICE_EXTERN_C_INLINE
float cimagf(float __complex__ z) { return __devicelib_cimagf(z); }
Expand Down Expand Up @@ -99,4 +99,4 @@ DEVICE_EXTERN_C_INLINE
float __complex__ __divsc3(float __a, float __b, float __c, float __d) {
return __devicelib___divsc3(__a, __b, __c, __d);
}
#endif // __SPIR__
#endif // __SPIR__ || __SPIRV__
4 changes: 2 additions & 2 deletions libdevice/complex_wrapper_fp64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "device_complex.h"

#ifdef __SPIR__
#if defined(__SPIR__) || defined(__SPIRV__)

DEVICE_EXTERN_C_INLINE
double cimag(double __complex__ z) { return __devicelib_cimag(z); }
Expand Down Expand Up @@ -100,4 +100,4 @@ DEVICE_EXTERN_C_INLINE
double __complex__ __divdc3(double __a, double __b, double __c, double __d) {
return __devicelib___divdc3(__a, __b, __c, __d);
}
#endif // __SPIR__
#endif // __SPIR__ || __SPIRV__
4 changes: 2 additions & 2 deletions libdevice/crt_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "wrapper.h"

#if defined(__SPIR__) || defined(__NVPTX__)
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__NVPTX__)
DEVICE_EXTERN_C_INLINE
void *memcpy(void *dest, const void *src, size_t n) {
return __devicelib_memcpy(dest, src, n);
Expand Down Expand Up @@ -64,4 +64,4 @@ void __assert_fail(const char *expr, const char *file, unsigned int line,
__spirv_LocalInvocationId_z());
}
#endif
#endif // __SPIR__ || __NVPTX__
#endif // __SPIR__ || __SPIRV__ || __NVPTX__
8 changes: 4 additions & 4 deletions libdevice/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define EXTERN_C
#endif // __cplusplus

#if defined(__SPIR__) || defined(__NVPTX__)
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__NVPTX__)
#ifdef __SYCL_DEVICE_ONLY__
#define DEVICE_EXTERNAL SYCL_EXTERNAL __attribute__((weak))
#else // __SYCL_DEVICE_ONLY__
Expand All @@ -27,11 +27,11 @@
DEVICE_EXTERNAL EXTERN_C __attribute__((always_inline))
#define DEVICE_EXTERN_C_NOINLINE \
DEVICE_EXTERNAL EXTERN_C __attribute__((noinline))
#endif // __SPIR__ || __NVPTX__
#endif // __SPIR__ || __SPIRV__ || __NVPTX__

#if defined(__SPIR__) || defined(__LIBDEVICE_HOST_IMPL__)
#if defined(__SPIR__) || defined(__SPIRV__) || defined(__LIBDEVICE_HOST_IMPL__)
#define __LIBDEVICE_IMF_ENABLED__
#endif // __SPIR__ || __LIBDEVICE_HOST_IMPL__
#endif // __SPIR__ || __SPIRV__ || __LIBDEVICE_HOST_IMPL__

#ifdef __LIBDEVICE_HOST_IMPL__
// For host implementation, all functions will be located in a static library
Expand Down
4 changes: 2 additions & 2 deletions libdevice/device_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "device.h"

#ifdef __SPIR__
#if defined(__SPIR__) || defined(__SPIRV__)

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

DEVICE_EXTERN_C
float __complex__ __devicelib___divsc3(float a, float b, float c, float d);
#endif // __SPIR__
#endif // __SPIR__ || __SPIRV__
#endif // __LIBDEVICE_DEVICE_COMPLEX_H_
Loading

0 comments on commit b8f3942

Please sign in to comment.