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