Skip to content

Commit c786894

Browse files
[SYCL][ABI-break] Rename SYCL host-side math builtins (#6645)
Due to a bug in GCC versions older than 11.1 SYCL math builtins may fail to compile when using GCC as the host compiler. To work around this issue, this commit renames all host-side builtin implementations used by the SYCL math builtins. The bug: ```c++ #include <cmath> namespace __host_std { template <typename R, typename T> inline R __invoke_sqrt(T a) { extern R sqrt(T); return sqrt(a); } } int main() { __host_std::__invoke_sqrt<double>(3.5); return 0; } ``` With gcc 10.4: ``` <source>: In instantiation of 'R __host_std::__invoke_sqrt(T) [with R = double; T = double]': <source>:12:42: required from here <source>:6:18: error: local external declaration 'R __host_std::sqrt(T) [with R = double; T = double]' [-fpermissive] 6 | extern R sqrt(T); | ^~~~ In file included from /usr/include/features.h:461, from /opt/compiler-explorer/gcc-10.4.0/include/c++/10.4.0/x86_64-linux-gnu/bits/os_defines.h:39, from /opt/compiler-explorer/gcc-10.4.0/include/c++/10.4.0/x86_64-linux-gnu/bits/c++config.h:522, from /opt/compiler-explorer/gcc-10.4.0/include/c++/10.4.0/cmath:41, from <source>:1: /usr/include/x86_64-linux-gnu/bits/mathcalls.h:143:1: note: does not match previous declaration 'double sqrt(double)' 143 | __MATHCALL (sqrt,, (_Mdouble_ __x)); | ^~~~~~~~~~ Compiler returned: 1 ``` Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
1 parent 2a1151b commit c786894

File tree

9 files changed

+5356
-4719
lines changed

9 files changed

+5356
-4719
lines changed

sycl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ set(SYCL_MINOR_VERSION 7)
3030
set(SYCL_PATCH_VERSION 0)
3131
# Don't forget to re-enable sycl_symbols_windows.dump once we leave ABI-breaking
3232
# window!
33-
set(SYCL_DEV_ABI_VERSION 12)
33+
set(SYCL_DEV_ABI_VERSION 13)
3434
if (SYCL_ADD_DEV_VERSION_POSTFIX)
3535
set(SYCL_VERSION_POSTFIX "-${SYCL_DEV_ABI_VERSION}")
3636
endif()

sycl/include/sycl/detail/builtins.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#define __SYCL_EXTERN_IT2_SAME(Ret, prefix, call, Arg)
2626
#define __SYCL_EXTERN_IT3(Ret, prefix, call, Arg1, Arg2, Arg3)
2727
#else
28-
#define __FUNC_PREFIX_OCL
29-
#define __FUNC_PREFIX_CORE
28+
#define __FUNC_PREFIX_OCL sycl_host_
29+
#define __FUNC_PREFIX_CORE sycl_host_
3030
#define __SYCL_EXTERN_IT1(Ret, prefix, call, Arg) \
3131
extern Ret __SYCL_PPCAT(prefix, call)(Arg)
3232
#define __SYCL_EXTERN_IT2_SAME(Ret, prefix, call, Arg) \

sycl/source/detail/builtins_common.cpp

Lines changed: 84 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -65,132 +65,154 @@ template <typename T> inline T __sign(T x) {
6565

6666
// --------------- 4.13.5 Common functions. Host implementations ---------------
6767
// fclamp
68-
__SYCL_EXPORT s::cl_float fclamp(s::cl_float x, s::cl_float minval,
69-
s::cl_float maxval) __NOEXC {
68+
__SYCL_EXPORT s::cl_float sycl_host_fclamp(s::cl_float x, s::cl_float minval,
69+
s::cl_float maxval) __NOEXC {
7070
return __fclamp(x, minval, maxval);
7171
}
72-
__SYCL_EXPORT s::cl_double fclamp(s::cl_double x, s::cl_double minval,
73-
s::cl_double maxval) __NOEXC {
72+
__SYCL_EXPORT s::cl_double sycl_host_fclamp(s::cl_double x, s::cl_double minval,
73+
s::cl_double maxval) __NOEXC {
7474
return __fclamp(x, minval, maxval);
7575
}
76-
__SYCL_EXPORT s::cl_half fclamp(s::cl_half x, s::cl_half minval,
77-
s::cl_half maxval) __NOEXC {
76+
__SYCL_EXPORT s::cl_half sycl_host_fclamp(s::cl_half x, s::cl_half minval,
77+
s::cl_half maxval) __NOEXC {
7878
return __fclamp(x, minval, maxval);
7979
}
80-
MAKE_1V_2V_3V(fclamp, s::cl_float, s::cl_float, s::cl_float, s::cl_float)
81-
MAKE_1V_2V_3V(fclamp, s::cl_double, s::cl_double, s::cl_double, s::cl_double)
82-
MAKE_1V_2V_3V(fclamp, s::cl_half, s::cl_half, s::cl_half, s::cl_half)
80+
MAKE_1V_2V_3V(sycl_host_fclamp, s::cl_float, s::cl_float, s::cl_float,
81+
s::cl_float)
82+
MAKE_1V_2V_3V(sycl_host_fclamp, s::cl_double, s::cl_double, s::cl_double,
83+
s::cl_double)
84+
MAKE_1V_2V_3V(sycl_host_fclamp, s::cl_half, s::cl_half, s::cl_half, s::cl_half)
8385

8486
// degrees
85-
__SYCL_EXPORT s::cl_float degrees(s::cl_float radians) __NOEXC {
87+
__SYCL_EXPORT s::cl_float sycl_host_degrees(s::cl_float radians) __NOEXC {
8688
return __degrees(radians);
8789
}
88-
__SYCL_EXPORT s::cl_double degrees(s::cl_double radians) __NOEXC {
90+
__SYCL_EXPORT s::cl_double sycl_host_degrees(s::cl_double radians) __NOEXC {
8991
return __degrees(radians);
9092
}
91-
__SYCL_EXPORT s::cl_half degrees(s::cl_half radians) __NOEXC {
93+
__SYCL_EXPORT s::cl_half sycl_host_degrees(s::cl_half radians) __NOEXC {
9294
return __degrees(radians);
9395
}
94-
MAKE_1V(degrees, s::cl_float, s::cl_float)
95-
MAKE_1V(degrees, s::cl_double, s::cl_double)
96-
MAKE_1V(degrees, s::cl_half, s::cl_half)
96+
MAKE_1V(sycl_host_degrees, s::cl_float, s::cl_float)
97+
MAKE_1V(sycl_host_degrees, s::cl_double, s::cl_double)
98+
MAKE_1V(sycl_host_degrees, s::cl_half, s::cl_half)
9799

98100
// fmin_common
99-
__SYCL_EXPORT s::cl_float fmin_common(s::cl_float x, s::cl_float y) __NOEXC {
101+
__SYCL_EXPORT s::cl_float sycl_host_fmin_common(s::cl_float x,
102+
s::cl_float y) __NOEXC {
100103
return std::fmin(x, y);
101104
}
102-
__SYCL_EXPORT s::cl_double fmin_common(s::cl_double x, s::cl_double y) __NOEXC {
105+
__SYCL_EXPORT s::cl_double sycl_host_fmin_common(s::cl_double x,
106+
s::cl_double y) __NOEXC {
103107
return std::fmin(x, y);
104108
}
105-
__SYCL_EXPORT s::cl_half fmin_common(s::cl_half x, s::cl_half y) __NOEXC {
109+
__SYCL_EXPORT s::cl_half sycl_host_fmin_common(s::cl_half x,
110+
s::cl_half y) __NOEXC {
106111
return std::fmin(x, y);
107112
}
108-
MAKE_1V_2V(fmin_common, s::cl_float, s::cl_float, s::cl_float)
109-
MAKE_1V_2V(fmin_common, s::cl_double, s::cl_double, s::cl_double)
110-
MAKE_1V_2V(fmin_common, s::cl_half, s::cl_half, s::cl_half)
113+
MAKE_1V_2V(sycl_host_fmin_common, s::cl_float, s::cl_float, s::cl_float)
114+
MAKE_1V_2V(sycl_host_fmin_common, s::cl_double, s::cl_double, s::cl_double)
115+
MAKE_1V_2V(sycl_host_fmin_common, s::cl_half, s::cl_half, s::cl_half)
111116

112117
// fmax_common
113-
__SYCL_EXPORT s::cl_float fmax_common(s::cl_float x, s::cl_float y) __NOEXC {
118+
__SYCL_EXPORT s::cl_float sycl_host_fmax_common(s::cl_float x,
119+
s::cl_float y) __NOEXC {
114120
return std::fmax(x, y);
115121
}
116-
__SYCL_EXPORT s::cl_double fmax_common(s::cl_double x, s::cl_double y) __NOEXC {
122+
__SYCL_EXPORT s::cl_double sycl_host_fmax_common(s::cl_double x,
123+
s::cl_double y) __NOEXC {
117124
return std::fmax(x, y);
118125
}
119-
__SYCL_EXPORT s::cl_half fmax_common(s::cl_half x, s::cl_half y) __NOEXC {
126+
__SYCL_EXPORT s::cl_half sycl_host_fmax_common(s::cl_half x,
127+
s::cl_half y) __NOEXC {
120128
return std::fmax(x, y);
121129
}
122-
MAKE_1V_2V(fmax_common, s::cl_float, s::cl_float, s::cl_float)
123-
MAKE_1V_2V(fmax_common, s::cl_double, s::cl_double, s::cl_double)
124-
MAKE_1V_2V(fmax_common, s::cl_half, s::cl_half, s::cl_half)
130+
MAKE_1V_2V(sycl_host_fmax_common, s::cl_float, s::cl_float, s::cl_float)
131+
MAKE_1V_2V(sycl_host_fmax_common, s::cl_double, s::cl_double, s::cl_double)
132+
MAKE_1V_2V(sycl_host_fmax_common, s::cl_half, s::cl_half, s::cl_half)
125133

126134
// mix
127-
__SYCL_EXPORT s::cl_float mix(s::cl_float x, s::cl_float y,
128-
s::cl_float a) __NOEXC {
135+
__SYCL_EXPORT s::cl_float sycl_host_mix(s::cl_float x, s::cl_float y,
136+
s::cl_float a) __NOEXC {
129137
return __mix(x, y, a);
130138
}
131-
__SYCL_EXPORT s::cl_double mix(s::cl_double x, s::cl_double y,
132-
s::cl_double a) __NOEXC {
139+
__SYCL_EXPORT s::cl_double sycl_host_mix(s::cl_double x, s::cl_double y,
140+
s::cl_double a) __NOEXC {
133141
return __mix(x, y, a);
134142
}
135-
__SYCL_EXPORT s::cl_half mix(s::cl_half x, s::cl_half y, s::cl_half a) __NOEXC {
143+
__SYCL_EXPORT s::cl_half sycl_host_mix(s::cl_half x, s::cl_half y,
144+
s::cl_half a) __NOEXC {
136145
return __mix(x, y, a);
137146
}
138-
MAKE_1V_2V_3V(mix, s::cl_float, s::cl_float, s::cl_float, s::cl_float)
139-
MAKE_1V_2V_3V(mix, s::cl_double, s::cl_double, s::cl_double, s::cl_double)
140-
MAKE_1V_2V_3V(mix, s::cl_half, s::cl_half, s::cl_half, s::cl_half)
147+
MAKE_1V_2V_3V(sycl_host_mix, s::cl_float, s::cl_float, s::cl_float, s::cl_float)
148+
MAKE_1V_2V_3V(sycl_host_mix, s::cl_double, s::cl_double, s::cl_double,
149+
s::cl_double)
150+
MAKE_1V_2V_3V(sycl_host_mix, s::cl_half, s::cl_half, s::cl_half, s::cl_half)
141151

142152
// radians
143-
__SYCL_EXPORT s::cl_float radians(s::cl_float degrees) __NOEXC {
153+
__SYCL_EXPORT s::cl_float sycl_host_radians(s::cl_float degrees) __NOEXC {
144154
return __radians(degrees);
145155
}
146-
__SYCL_EXPORT s::cl_double radians(s::cl_double degrees) __NOEXC {
156+
__SYCL_EXPORT s::cl_double sycl_host_radians(s::cl_double degrees) __NOEXC {
147157
return __radians(degrees);
148158
}
149-
__SYCL_EXPORT s::cl_half radians(s::cl_half degrees) __NOEXC {
159+
__SYCL_EXPORT s::cl_half sycl_host_radians(s::cl_half degrees) __NOEXC {
150160
return __radians(degrees);
151161
}
152-
MAKE_1V(radians, s::cl_float, s::cl_float)
153-
MAKE_1V(radians, s::cl_double, s::cl_double)
154-
MAKE_1V(radians, s::cl_half, s::cl_half)
162+
MAKE_1V(sycl_host_radians, s::cl_float, s::cl_float)
163+
MAKE_1V(sycl_host_radians, s::cl_double, s::cl_double)
164+
MAKE_1V(sycl_host_radians, s::cl_half, s::cl_half)
155165

156166
// step
157-
__SYCL_EXPORT s::cl_float step(s::cl_float edge, s::cl_float x) __NOEXC {
167+
__SYCL_EXPORT s::cl_float sycl_host_step(s::cl_float edge,
168+
s::cl_float x) __NOEXC {
158169
return __step(edge, x);
159170
}
160-
__SYCL_EXPORT s::cl_double step(s::cl_double edge, s::cl_double x) __NOEXC {
171+
__SYCL_EXPORT s::cl_double sycl_host_step(s::cl_double edge,
172+
s::cl_double x) __NOEXC {
161173
return __step(edge, x);
162174
}
163-
__SYCL_EXPORT s::cl_half step(s::cl_half edge, s::cl_half x) __NOEXC {
175+
__SYCL_EXPORT s::cl_half sycl_host_step(s::cl_half edge, s::cl_half x) __NOEXC {
164176
return __step(edge, x);
165177
}
166-
MAKE_1V_2V(step, s::cl_float, s::cl_float, s::cl_float)
167-
MAKE_1V_2V(step, s::cl_double, s::cl_double, s::cl_double)
168-
MAKE_1V_2V(step, s::cl_half, s::cl_half, s::cl_half)
178+
MAKE_1V_2V(sycl_host_step, s::cl_float, s::cl_float, s::cl_float)
179+
MAKE_1V_2V(sycl_host_step, s::cl_double, s::cl_double, s::cl_double)
180+
MAKE_1V_2V(sycl_host_step, s::cl_half, s::cl_half, s::cl_half)
169181

170182
// smoothstep
171-
__SYCL_EXPORT s::cl_float smoothstep(s::cl_float edge0, s::cl_float edge1,
172-
s::cl_float x) __NOEXC {
183+
__SYCL_EXPORT s::cl_float sycl_host_smoothstep(s::cl_float edge0,
184+
s::cl_float edge1,
185+
s::cl_float x) __NOEXC {
173186
return __smoothstep(edge0, edge1, x);
174187
}
175-
__SYCL_EXPORT s::cl_double smoothstep(s::cl_double edge0, s::cl_double edge1,
176-
s::cl_double x) __NOEXC {
188+
__SYCL_EXPORT s::cl_double sycl_host_smoothstep(s::cl_double edge0,
189+
s::cl_double edge1,
190+
s::cl_double x) __NOEXC {
177191
return __smoothstep(edge0, edge1, x);
178192
}
179-
__SYCL_EXPORT s::cl_half smoothstep(s::cl_half edge0, s::cl_half edge1,
180-
s::cl_half x) __NOEXC {
193+
__SYCL_EXPORT s::cl_half
194+
sycl_host_smoothstep(s::cl_half edge0, s::cl_half edge1, s::cl_half x) __NOEXC {
181195
return __smoothstep(edge0, edge1, x);
182196
}
183-
MAKE_1V_2V_3V(smoothstep, s::cl_float, s::cl_float, s::cl_float, s::cl_float)
184-
MAKE_1V_2V_3V(smoothstep, s::cl_double, s::cl_double, s::cl_double,
197+
MAKE_1V_2V_3V(sycl_host_smoothstep, s::cl_float, s::cl_float, s::cl_float,
198+
s::cl_float)
199+
MAKE_1V_2V_3V(sycl_host_smoothstep, s::cl_double, s::cl_double, s::cl_double,
185200
s::cl_double)
186-
MAKE_1V_2V_3V(smoothstep, s::cl_half, s::cl_half, s::cl_half, s::cl_half)
201+
MAKE_1V_2V_3V(sycl_host_smoothstep, s::cl_half, s::cl_half, s::cl_half,
202+
s::cl_half)
187203

188204
// sign
189-
__SYCL_EXPORT s::cl_float sign(s::cl_float x) __NOEXC { return __sign(x); }
190-
__SYCL_EXPORT s::cl_double sign(s::cl_double x) __NOEXC { return __sign(x); }
191-
__SYCL_EXPORT s::cl_half sign(s::cl_half x) __NOEXC { return __sign(x); }
192-
MAKE_1V(sign, s::cl_float, s::cl_float)
193-
MAKE_1V(sign, s::cl_double, s::cl_double)
194-
MAKE_1V(sign, s::cl_half, s::cl_half)
205+
__SYCL_EXPORT s::cl_float sycl_host_sign(s::cl_float x) __NOEXC {
206+
return __sign(x);
207+
}
208+
__SYCL_EXPORT s::cl_double sycl_host_sign(s::cl_double x) __NOEXC {
209+
return __sign(x);
210+
}
211+
__SYCL_EXPORT s::cl_half sycl_host_sign(s::cl_half x) __NOEXC {
212+
return __sign(x);
213+
}
214+
MAKE_1V(sycl_host_sign, s::cl_float, s::cl_float)
215+
MAKE_1V(sycl_host_sign, s::cl_double, s::cl_double)
216+
MAKE_1V(sycl_host_sign, s::cl_half, s::cl_half)
195217

196218
} // namespace __host_std

0 commit comments

Comments
 (0)