DPC++ Runtime
Runtime libraries for oneAPI DPC++
online_compiler.hpp
Go to the documentation of this file.
1 //===------- online_compiler.hpp - Online source compilation service ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
12 #include <sycl/detail/export.hpp> // for __SYCL_EXPORT
13 #include <sycl/device.hpp>
14 
15 #include <string>
16 #include <vector>
17 
18 namespace sycl {
19 inline namespace _V1 {
20 namespace ext::intel::experimental {
21 
22 using byte = unsigned char;
23 
25  spir_v = 0 // the only format supported for now
26 };
27 
28 class device_arch {
29 public:
30  static constexpr int any = 0;
31 
32  device_arch(int Val) : Val(Val) {}
33 
34  // TODO1: the list must be extended with a bunch of new GPUs available.
35  // TODO2: the list of supported GPUs grows rapidly.
36  // The API must allow user to define the target GPU option even if it is
37  // not listed in this enumerator below.
38  enum gpu {
39  gpu_any = 1,
40  gpu_gen9 = 2,
45  gpu_gen11 = 4,
47  gpu_gen12 = 5,
50  };
51 
52  enum cpu {
53  cpu_any = 1,
54  };
55 
56  enum fpga {
57  fpga_any = 1,
58  };
59 
60  operator int() { return Val; }
61 
62 private:
63  int Val;
64 };
65 
68 public:
69  online_compile_error() = default;
70  online_compile_error(const std::string &Msg) : sycl::exception(Msg) {}
71 };
72 
74 enum class source_language { opencl_c = 0, cm = 1 };
75 
78 template <source_language Lang>
80  "experimental online_compiler is being deprecated. See "
81  "'sycl_ext_oneapi_kernel_compiler.asciidoc' instead for new kernel "
82  "compiler extension to kernel_bundle implementation.") online_compiler {
83 public:
89  : OutputFormat(fmt), OutputFormatVersion({0, 0}),
90  DeviceType(sycl::info::device_type::all), DeviceArch(device_arch::any),
91  Is64Bit(true), DeviceStepping("") {}
92 
98  online_compiler(sycl::info::device_type dev_type, device_arch arch,
100  : OutputFormat(fmt), OutputFormatVersion({0, 0}), DeviceType(dev_type),
101  DeviceArch(arch), Is64Bit(true), DeviceStepping("") {}
102 
104  // TODO: the initial version generates the generic code (SKL now), need
105  // to do additional device::info calls to determine the device by it's
106  // features.
107  online_compiler(const sycl::device &)
108  : OutputFormat(compiled_code_format::spir_v), OutputFormatVersion({0, 0}),
109  DeviceType(sycl::info::device_type::all), DeviceArch(device_arch::any),
110  Is64Bit(true), DeviceStepping("") {}
111 
118  template <typename... Tys>
119  std::vector<byte> compile(const std::string &src, const Tys &...args);
120 
122  online_compiler<Lang> &setOutputFormat(compiled_code_format fmt) {
123  OutputFormat = fmt;
124  return *this;
125  }
126 
129  online_compiler<Lang> &setOutputFormatVersion(int major, int minor) {
130  OutputFormatVersion = {major, minor};
131  return *this;
132  }
133 
135  online_compiler<Lang> &setTargetDeviceType(sycl::info::device_type type) {
136  DeviceType = type;
137  return *this;
138  }
139 
141  online_compiler<Lang> &setTargetDeviceArch(device_arch arch) {
142  DeviceArch = arch;
143  return *this;
144  }
145 
147  online_compiler<Lang> &set32bitTarget() {
148  Is64Bit = false;
149  return *this;
150  };
151 
153  online_compiler<Lang> &set64bitTarget() {
154  Is64Bit = true;
155  return *this;
156  };
157 
160  online_compiler<Lang> &setTargetDeviceStepping(const std::string &id) {
161  DeviceStepping = id;
162  return *this;
163  }
164 
165 private:
167  compiled_code_format OutputFormat;
168 
170  std::pair<int, int> OutputFormatVersion;
171 
173  sycl::info::device_type DeviceType;
174 
176  device_arch DeviceArch;
177 
179  bool Is64Bit;
180 
182  std::string DeviceStepping;
183 
185  void *CompileToSPIRVHandle = nullptr;
186  void *FreeSPIRVOutputsHandle = nullptr;
187 };
188 
189 // Specializations of the online_compiler class and 'compile' function for
190 // particular languages and parameter types.
191 
196 template <>
197 template <>
198 __SYCL_EXPORT std::vector<byte>
200  const std::string &src, const std::vector<std::string> &options);
201 
204 template <>
205 template <>
206 std::vector<byte>
208  return compile(src, std::vector<std::string>{});
209 }
210 
214 template <>
215 template <>
216 __SYCL_EXPORT std::vector<byte> online_compiler<source_language::cm>::compile(
217  const std::string &src, const std::vector<std::string> &options);
218 
220 template <>
221 template <>
222 std::vector<byte>
223 online_compiler<source_language::cm>::compile(const std::string &src) {
224  return compile(src, std::vector<std::string>{});
225 }
226 
227 } // namespace ext::intel::experimental
228 } // namespace _V1
229 } // namespace sycl
sycl::_V1::ext::intel::experimental::device_arch::device_arch
device_arch(int Val)
Definition: online_compiler.hpp:32
sycl::_V1::__SYCL2020_DEPRECATED
signed char __SYCL2020_DEPRECATED
Definition: aliases.hpp:94
sycl::_V1::ext::intel::experimental::device_arch::gpu_gen12
@ gpu_gen12
Definition: online_compiler.hpp:47
sycl::_V1::instead
std::uint8_t instead
Definition: aliases.hpp:93
sycl::_V1::compile
kernel_bundle< bundle_state::object > compile(const kernel_bundle< bundle_state::input > &InputBundle, const std::vector< device > &Devs, const property_list &PropList={})
Definition: kernel_bundle.hpp:713
device.hpp
sycl::_V1::ext::intel::experimental::device_arch::fpga_any
@ fpga_any
Definition: online_compiler.hpp:57
sycl::_V1::ext::intel::experimental::online_compile_error::online_compile_error
online_compile_error(const std::string &Msg)
Definition: online_compiler.hpp:70
sycl::_V1::ext::intel::experimental::device_arch::cpu_any
@ cpu_any
Definition: online_compiler.hpp:53
sycl::_V1::all
std::enable_if_t< detail::is_vigeninteger_v< T >, int > all(T x)
Definition: builtins_legacy_marray_vec.hpp:1108
sycl
Definition: access.hpp:18
sycl::_V1::ext::intel::experimental::device_arch::gpu
gpu
Definition: online_compiler.hpp:38
sycl::_V1::ext::intel::experimental::compiled_code_format
compiled_code_format
Definition: online_compiler.hpp:24
sycl::_V1::id
A unique identifier of an item in an index space.
Definition: array.hpp:20
sycl::_V1::kernel
Provides an abstraction of a SYCL kernel.
Definition: kernel.hpp:74
export.hpp
sycl::_V1::ext::intel::experimental::device_arch::gpu_tgllp
@ gpu_tgllp
Definition: online_compiler.hpp:49
defines_elementary.hpp
sycl::_V1::ext::intel::experimental::device_arch::any
static constexpr int any
Definition: online_compiler.hpp:30
sycl::_V1::ext::intel::experimental::source_language::cm
@ cm
sycl::_V1::ext::intel::experimental::device_arch::cpu
cpu
Definition: online_compiler.hpp:52
sycl::_V1::exception
Definition: exception.hpp:68
sycl::_V1::kernel_bundle
The kernel_bundle class represents collection of device images in a particular state.
Definition: kernel.hpp:32
sycl::_V1::ext::intel::experimental::device_arch::gpu_skl
@ gpu_skl
Definition: online_compiler.hpp:41
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:59
sycl::_V1::ext::intel::experimental::device_arch::gpu_gen9_5
@ gpu_gen9_5
Definition: online_compiler.hpp:42
sycl::_V1::ext::intel::experimental::device_arch::gpu_kbl
@ gpu_kbl
Definition: online_compiler.hpp:43
sycl::_V1::info::device_type
device_type
Definition: info_desc.hpp:53
sycl::_V1::ext::intel::experimental::online_compile_error::online_compile_error
online_compile_error()=default
sycl::_V1::ext::intel::experimental::source_language::opencl_c
@ opencl_c
sycl::_V1::ext::intel::experimental::device_arch::gpu_tgl
@ gpu_tgl
Definition: online_compiler.hpp:48
sycl::_V1::ext::intel::experimental::source_language
source_language
Designates a source language for the online compiler.
Definition: online_compiler.hpp:74
sycl::_V1::ext::intel::experimental::device_arch::gpu_icl
@ gpu_icl
Definition: online_compiler.hpp:46
sycl::_V1::ext::intel::experimental::compiled_code_format::spir_v
@ spir_v
sycl::_V1::ext::intel::experimental::device_arch::fpga
fpga
Definition: online_compiler.hpp:56
sycl::_V1::ext::intel::experimental::online_compile_error
Represents an error happend during online compilation.
Definition: online_compiler.hpp:67
sycl::_V1::ext::intel::experimental::device_arch::gpu_gen11
@ gpu_gen11
Definition: online_compiler.hpp:45
sycl::_V1::ext::intel::experimental::device_arch
Definition: online_compiler.hpp:28
sycl::_V1::ext::intel::experimental::device_arch::gpu_cfl
@ gpu_cfl
Definition: online_compiler.hpp:44
sycl::_V1::ext::intel::experimental::device_arch::gpu_any
@ gpu_any
Definition: online_compiler.hpp:39
sycl::_V1::ext::intel::experimental::device_arch::gpu_gen9
@ gpu_gen9
Definition: online_compiler.hpp:40