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 {
1921namespace ext ::intel::experimental {
2022namespace detail {
2123
24+ using namespace sycl ::detail;
25+
2226static std::vector<const char *>
2327prepareOclocArgs (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,12 @@ prepareOclocArgs(sycl::info::device_type DeviceType, device_arch DeviceArch,
8286// / allocated during the compilation.
8387// / @param UserArgs - User's options to ocloc compiler.
8488static std::vector<byte>
85- compileToSPIRV (const std::string &Source , sycl::info::device_type DeviceType,
89+ compileToSPIRV (string_view Src , sycl::info::device_type DeviceType,
8690 device_arch DeviceArch, bool Is64Bit,
87- const std::string & DeviceStepping, void *&CompileToSPIRVHandle,
91+ string_view DeviceStepping, void *&CompileToSPIRVHandle,
8892 void *&FreeSPIRVOutputsHandle,
8993 const std::vector<std::string> &UserArgs) {
94+ std::string Source{Src.data ()};
9095
9196 if (!CompileToSPIRVHandle) {
9297#ifdef __SYCL_RT_OS_WINDOWS
@@ -198,11 +203,11 @@ compileToSPIRV(const std::string &Source, sycl::info::device_type DeviceType,
198203}
199204} // namespace detail
200205
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 ) {
206+ template <source_language Lang >
207+ __SYCL_EXPORT std::vector<byte> online_compiler<Lang>::compile_impl(
208+ detail::string_view Src,
209+ detail::string_view DeviceStepping,
210+ const std::vector<detail::string_view > &Options ) {
206211
207212 if (OutputFormatVersion != std::pair<int , int >{0 , 0 }) {
208213 std::string Version = std::to_string (OutputFormatVersion.first ) + " , " +
@@ -211,29 +216,27 @@ online_compiler<source_language::opencl_c>::compile(
211216 Version + " ) is not supported yet" );
212217 }
213218
214- return detail::compileToSPIRV (Source, DeviceType, DeviceArch, Is64Bit,
219+ std::vector<std::string> UserArgs;
220+ for (auto &&Opt : Options)
221+ UserArgs.emplace_back (Opt.data ());
222+
223+ if constexpr (Lang == source_language::cm)
224+ UserArgs.push_back (" -cmc" );
225+
226+ return detail::compileToSPIRV (Src, DeviceType, DeviceArch, Is64Bit,
215227 DeviceStepping, CompileToSPIRVHandle,
216228 FreeSPIRVOutputsHandle, UserArgs);
217229}
218230
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) {
231+ template __SYCL_EXPORT std::vector<byte >
232+ online_compiler<source_language::opencl_c>::compile_impl(
233+ detail::string_view Src, detail::string_view DeviceStepping,
234+ const std::vector<detail::string_view > &Options);
223235
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- }
236+ template __SYCL_EXPORT std::vector<byte>
237+ online_compiler<source_language::cm>::compile_impl(
238+ detail::string_view Src, detail::string_view DeviceStepping,
239+ const std::vector<detail::string_view> &Options);
237240} // namespace ext::intel::experimental
238241
239242namespace ext {
0 commit comments