6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
+ #define __SYCL_ONLINE_COMPILER_CPP
10
+
9
11
#include < sycl/detail/os_util.hpp>
10
12
#include < sycl/detail/ur.hpp>
11
13
#include < sycl/ext/intel/experimental/online_compiler.hpp>
@@ -19,9 +21,11 @@ inline namespace _V1 {
19
21
namespace ext ::intel::experimental {
20
22
namespace detail {
21
23
24
+ using namespace sycl ::detail;
25
+
22
26
static std::vector<const char *>
23
27
prepareOclocArgs (sycl::info::device_type DeviceType, device_arch DeviceArch,
24
- bool Is64Bit, const std::string & DeviceStepping,
28
+ bool Is64Bit, string_view DeviceStepping,
25
29
const std::string &UserArgs) {
26
30
std::vector<const char *> Args = {" ocloc" , " -q" , " -spv_only" , " -device" };
27
31
@@ -54,7 +58,7 @@ prepareOclocArgs(sycl::info::device_type DeviceType, device_arch DeviceArch,
54
58
55
59
if (DeviceStepping != " " ) {
56
60
Args.push_back (" -revision_id" );
57
- Args.push_back (DeviceStepping.c_str ());
61
+ Args.push_back (DeviceStepping.data ());
58
62
}
59
63
60
64
Args.push_back (Is64Bit ? " -64" : " -32" );
@@ -82,11 +86,11 @@ prepareOclocArgs(sycl::info::device_type DeviceType, device_arch DeviceArch,
82
86
// / allocated during the compilation.
83
87
// / @param UserArgs - User's options to ocloc compiler.
84
88
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,
89
92
const std::vector<std::string> &UserArgs) {
93
+ std::string Source{Src.data ()};
90
94
91
95
if (!CompileToSPIRVHandle) {
92
96
#ifdef __SYCL_RT_OS_WINDOWS
@@ -198,11 +202,12 @@ compileToSPIRV(const std::string &Source, sycl::info::device_type DeviceType,
198
202
}
199
203
} // namespace detail
200
204
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) {
206
211
207
212
if (OutputFormatVersion != std::pair<int , int >{0 , 0 }) {
208
213
std::string Version = std::to_string (OutputFormatVersion.first ) + " , " +
@@ -211,29 +216,31 @@ online_compiler<source_language::opencl_c>::compile(
211
216
Version + " ) is not supported yet" );
212
217
}
213
218
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 ());
223
222
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" );
230
225
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,
234
227
DeviceStepping, CompileToSPIRVHandle,
235
- FreeSPIRVOutputsHandle, CMUserArgs );
228
+ FreeSPIRVOutputsHandle, UserArgs );
236
229
}
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);
237
244
} // namespace ext::intel::experimental
238
245
239
246
namespace ext {
0 commit comments