Skip to content

Commit 83ee235

Browse files
[SYCL] Support online_compiler::compile compiled with pre-C++11 ABI (intel#16269)
This is an updated version of intel#16179. Run-time ABI mismatch resulting in a segmentation fault was uncovered why enabling extra testing in intel#16235, this new version fixes that.
1 parent 6fd5143 commit 83ee235

File tree

5 files changed

+99
-39
lines changed

5 files changed

+99
-39
lines changed

sycl/include/sycl/detail/string_view.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,19 @@ class string_view {
3737

3838
const char *data() const noexcept { return str; }
3939

40-
friend bool operator==(const string_view &lhs,
41-
std::string_view rhs) noexcept {
40+
friend bool operator==(string_view lhs, std::string_view rhs) noexcept {
4241
return rhs == lhs.data();
4342
}
44-
friend bool operator==(std::string_view lhs,
45-
const string_view &rhs) noexcept {
43+
friend bool operator==(std::string_view lhs, string_view rhs) noexcept {
4644
return lhs == rhs.data();
4745
}
46+
47+
friend bool operator!=(string_view lhs, std::string_view rhs) noexcept {
48+
return rhs != lhs.data();
49+
}
50+
friend bool operator!=(std::string_view lhs, string_view rhs) noexcept {
51+
return lhs != rhs.data();
52+
}
4853
};
4954

5055
} // namespace detail

sycl/include/sycl/ext/intel/experimental/online_compiler.hpp

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
namespace sycl {
1919
inline namespace _V1 {
2020
namespace ext::intel::experimental {
21+
namespace detail {
22+
using namespace sycl::detail;
23+
}
2124

2225
using byte = unsigned char;
2326

@@ -81,6 +84,30 @@ class __SYCL2020_DEPRECATED(
8184
"experimental online_compiler is being deprecated. See "
8285
"'sycl_ext_oneapi_kernel_compiler.asciidoc' instead for new kernel "
8386
"compiler extension to kernel_bundle implementation.") online_compiler {
87+
#if __INTEL_PREVIEW_BREAKING_CHANGES
88+
// Refactor this during next ABI Breaking window. We have an `std::string`
89+
// data member so cannot be accessing `this` when crossing ABI boundary.
90+
#endif
91+
__SYCL_EXPORT static std::vector<byte>
92+
compile_impl(detail::string_view Src,
93+
const std::vector<detail::string_view> &Options,
94+
std::pair<int, int> OutputFormatVersion,
95+
sycl::info::device_type DeviceType, device_arch DeviceArch,
96+
bool Is64Bit, detail::string_view DeviceStepping,
97+
void *&CompileToSPIRVHandle, void *&FreeSPIRVOutputsHandle);
98+
99+
std::vector<byte> compile_impl(const std::string &Source,
100+
const std::vector<std::string> &UserArgs) {
101+
std::vector<sycl::detail::string_view> Args;
102+
for (auto &&Arg : UserArgs)
103+
Args.emplace_back(Arg);
104+
105+
return compile_impl(std::string_view{Source}, Args, OutputFormatVersion,
106+
DeviceType, DeviceArch, Is64Bit,
107+
std::string_view{DeviceStepping}, CompileToSPIRVHandle,
108+
FreeSPIRVOutputsHandle);
109+
}
110+
84111
public:
85112
/// Constructs online compiler which can target any device and produces
86113
/// given compiled code format. Produces 64-bit device code.
@@ -196,9 +223,17 @@ class __SYCL2020_DEPRECATED(
196223
/// OpenCL JIT compiler options must be supported.
197224
template <>
198225
template <>
199-
__SYCL_EXPORT std::vector<byte>
200-
online_compiler<source_language::opencl_c>::compile(
201-
const std::string &src, const std::vector<std::string> &options);
226+
#if !defined(__SYCL_ONLINE_COMPILER_CPP) || \
227+
defined(__INTEL_PREVIEW_BREAKING_CHANGES)
228+
inline
229+
#else
230+
__SYCL_EXPORT
231+
#endif
232+
std::vector<byte>
233+
online_compiler<source_language::opencl_c>::compile(
234+
const std::string &src, const std::vector<std::string> &options) {
235+
return compile_impl(src, options);
236+
}
202237

203238
/// Compiles the given OpenCL source. May throw \c online_compile_error.
204239
/// @param src - contents of the source.
@@ -214,8 +249,17 @@ online_compiler<source_language::opencl_c>::compile(const std::string &src) {
214249
/// @param options - compilation options (implementation defined).
215250
template <>
216251
template <>
217-
__SYCL_EXPORT std::vector<byte> online_compiler<source_language::cm>::compile(
218-
const std::string &src, const std::vector<std::string> &options);
252+
#if !defined(__SYCL_ONLINE_COMPILER_CPP) || \
253+
defined(__INTEL_PREVIEW_BREAKING_CHANGES)
254+
inline
255+
#else
256+
__SYCL_EXPORT
257+
#endif
258+
std::vector<byte>
259+
online_compiler<source_language::cm>::compile(
260+
const std::string &src, const std::vector<std::string> &options) {
261+
return compile_impl(src, options);
262+
}
219263

220264
/// Compiles the given CM source \p src.
221265
template <>

sycl/source/detail/online_compiler/online_compiler.cpp

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#define __SYCL_ONLINE_COMPILER_CPP
10+
911
#include <sycl/detail/os_util.hpp>
1012
#include <sycl/detail/ur.hpp>
1113
#include <sycl/ext/intel/experimental/online_compiler.hpp>
@@ -19,9 +21,11 @@ inline namespace _V1 {
1921
namespace ext::intel::experimental {
2022
namespace detail {
2123

24+
using namespace sycl::detail;
25+
2226
static std::vector<const char *>
2327
prepareOclocArgs(sycl::info::device_type DeviceType, device_arch DeviceArch,
24-
bool Is64Bit, const std::string &DeviceStepping,
28+
bool Is64Bit, string_view DeviceStepping,
2529
const std::string &UserArgs) {
2630
std::vector<const char *> Args = {"ocloc", "-q", "-spv_only", "-device"};
2731

@@ -54,7 +58,7 @@ prepareOclocArgs(sycl::info::device_type DeviceType, device_arch DeviceArch,
5458

5559
if (DeviceStepping != "") {
5660
Args.push_back("-revision_id");
57-
Args.push_back(DeviceStepping.c_str());
61+
Args.push_back(DeviceStepping.data());
5862
}
5963

6064
Args.push_back(Is64Bit ? "-64" : "-32");
@@ -82,11 +86,11 @@ prepareOclocArgs(sycl::info::device_type DeviceType, device_arch DeviceArch,
8286
/// allocated during the compilation.
8387
/// @param UserArgs - User's options to ocloc compiler.
8488
static std::vector<byte>
85-
compileToSPIRV(const std::string &Source, sycl::info::device_type DeviceType,
86-
device_arch DeviceArch, bool Is64Bit,
87-
const std::string &DeviceStepping, void *&CompileToSPIRVHandle,
88-
void *&FreeSPIRVOutputsHandle,
89+
compileToSPIRV(string_view Src, sycl::info::device_type DeviceType,
90+
device_arch DeviceArch, bool Is64Bit, string_view DeviceStepping,
91+
void *&CompileToSPIRVHandle, void *&FreeSPIRVOutputsHandle,
8992
const std::vector<std::string> &UserArgs) {
93+
std::string Source{Src.data()};
9094

9195
if (!CompileToSPIRVHandle) {
9296
#ifdef __SYCL_RT_OS_WINDOWS
@@ -198,11 +202,12 @@ compileToSPIRV(const std::string &Source, sycl::info::device_type DeviceType,
198202
}
199203
} // namespace detail
200204

201-
template <>
202-
template <>
203-
__SYCL_EXPORT std::vector<byte>
204-
online_compiler<source_language::opencl_c>::compile(
205-
const std::string &Source, const std::vector<std::string> &UserArgs) {
205+
template <source_language Lang>
206+
__SYCL_EXPORT std::vector<byte> online_compiler<Lang>::compile_impl(
207+
detail::string_view Src, const std::vector<detail::string_view> &Options,
208+
std::pair<int, int> OutputFormatVersion, sycl::info::device_type DeviceType,
209+
device_arch DeviceArch, bool Is64Bit, detail::string_view DeviceStepping,
210+
void *&CompileToSPIRVHandle, void *&FreeSPIRVOutputsHandle) {
206211

207212
if (OutputFormatVersion != std::pair<int, int>{0, 0}) {
208213
std::string Version = std::to_string(OutputFormatVersion.first) + ", " +
@@ -211,29 +216,31 @@ online_compiler<source_language::opencl_c>::compile(
211216
Version + ") is not supported yet");
212217
}
213218

214-
return detail::compileToSPIRV(Source, DeviceType, DeviceArch, Is64Bit,
215-
DeviceStepping, CompileToSPIRVHandle,
216-
FreeSPIRVOutputsHandle, UserArgs);
217-
}
218-
219-
template <>
220-
template <>
221-
__SYCL_EXPORT std::vector<byte> online_compiler<source_language::cm>::compile(
222-
const std::string &Source, const std::vector<std::string> &UserArgs) {
219+
std::vector<std::string> UserArgs;
220+
for (auto &&Opt : Options)
221+
UserArgs.emplace_back(Opt.data());
223222

224-
if (OutputFormatVersion != std::pair<int, int>{0, 0}) {
225-
std::string Version = std::to_string(OutputFormatVersion.first) + ", " +
226-
std::to_string(OutputFormatVersion.second);
227-
throw online_compile_error(std::string("The output format version (") +
228-
Version + ") is not supported yet");
229-
}
223+
if constexpr (Lang == source_language::cm)
224+
UserArgs.push_back("-cmc");
230225

231-
std::vector<std::string> CMUserArgs = UserArgs;
232-
CMUserArgs.push_back("-cmc");
233-
return detail::compileToSPIRV(Source, DeviceType, DeviceArch, Is64Bit,
226+
return detail::compileToSPIRV(Src, DeviceType, DeviceArch, Is64Bit,
234227
DeviceStepping, CompileToSPIRVHandle,
235-
FreeSPIRVOutputsHandle, CMUserArgs);
228+
FreeSPIRVOutputsHandle, UserArgs);
236229
}
230+
231+
template __SYCL_EXPORT std::vector<byte>
232+
online_compiler<source_language::opencl_c>::compile_impl(
233+
detail::string_view Src, const std::vector<detail::string_view> &Options,
234+
std::pair<int, int> OutputFormatVersion, sycl::info::device_type DeviceType,
235+
device_arch DeviceArch, bool Is64Bit, detail::string_view DeviceStepping,
236+
void *&CompileToSPIRVHandle, void *&FreeSPIRVOutputsHandle);
237+
238+
template __SYCL_EXPORT std::vector<byte>
239+
online_compiler<source_language::cm>::compile_impl(
240+
detail::string_view Src, const std::vector<detail::string_view> &Options,
241+
std::pair<int, int> OutputFormatVersion, sycl::info::device_type DeviceType,
242+
device_arch DeviceArch, bool Is64Bit, detail::string_view DeviceStepping,
243+
void *&CompileToSPIRVHandle, void *&FreeSPIRVOutputsHandle);
237244
} // namespace ext::intel::experimental
238245

239246
namespace ext {

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,7 +2985,9 @@ _ZN4sycl3_V121__isgreaterequal_implEdd
29852985
_ZN4sycl3_V121__isgreaterequal_implEff
29862986
_ZN4sycl3_V122accelerator_selector_vERKNS0_6deviceE
29872987
_ZN4sycl3_V128verifyUSMAllocatorPropertiesERKNS0_13property_listE
2988+
_ZN4sycl3_V13ext5intel12experimental15online_compilerILNS3_15source_languageE0EE12compile_implENS0_6detail11string_viewERKSt6vectorIS8_SaIS8_EESt4pairIiiENS0_4info11device_typeENS3_11device_archEbS8_RPvSK_
29882989
_ZN4sycl3_V13ext5intel12experimental15online_compilerILNS3_15source_languageE0EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISE_EEEEES8_IhSaIhEERKSE_DpRKT_
2990+
_ZN4sycl3_V13ext5intel12experimental15online_compilerILNS3_15source_languageE1EE12compile_implENS0_6detail11string_viewERKSt6vectorIS8_SaIS8_EESt4pairIiiENS0_4info11device_typeENS3_11device_archEbS8_RPvSK_
29892991
_ZN4sycl3_V13ext5intel12experimental15online_compilerILNS3_15source_languageE1EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISE_EEEEES8_IhSaIhEERKSE_DpRKT_
29902992
_ZN4sycl3_V13ext5intel12experimental9pipe_base13get_pipe_nameB5cxx11EPKv
29912993
_ZN4sycl3_V13ext5intel12experimental9pipe_base17wait_non_blockingERKNS0_5eventE

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,8 @@
37433743
?category@exception@_V1@sycl@@QEBAAEBVerror_category@std@@XZ
37443744
?clearArgs@handler@_V1@sycl@@AEAAXXZ
37453745
?code@exception@_V1@sycl@@QEBAAEBVerror_code@std@@XZ
3746+
?compile_impl@?$online_compiler@$00@experimental@intel@ext@_V1@sycl@@CA?AV?$vector@EV?$allocator@E@std@@@std@@Vstring_view@detail@56@AEBV?$vector@Vstring_view@detail@_V1@sycl@@V?$allocator@Vstring_view@detail@_V1@sycl@@@std@@@8@U?$pair@HH@8@W4device_type@info@56@Vdevice_arch@23456@_N0AEAPEAX6@Z
3747+
?compile_impl@?$online_compiler@$0A@@experimental@intel@ext@_V1@sycl@@CA?AV?$vector@EV?$allocator@E@std@@@std@@Vstring_view@detail@56@AEBV?$vector@Vstring_view@detail@_V1@sycl@@V?$allocator@Vstring_view@detail@_V1@sycl@@@std@@@8@U?$pair@HH@8@W4device_type@info@56@Vdevice_arch@23456@_N0AEAPEAX6@Z
37463748
?compile_impl@detail@_V1@sycl@@YA?AV?$shared_ptr@Vkernel_bundle_impl@detail@_V1@sycl@@@std@@AEBV?$kernel_bundle@$0A@@23@AEBV?$vector@Vdevice@_V1@sycl@@V?$allocator@Vdevice@_V1@sycl@@@std@@@5@AEBVproperty_list@23@@Z
37473749
?complete_fusion@fusion_wrapper@experimental@codeplay@ext@_V1@sycl@@QEAA?AVevent@56@AEBVproperty_list@56@@Z
37483750
?computeFallbackKernelBounds@handler@_V1@sycl@@AEAA?AV?$id@$01@23@_K0@Z

0 commit comments

Comments
 (0)