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)
72 };
73 
75 enum class source_language { opencl_c = 0, cm = 1 };
76 
79 template <source_language Lang>
81  "experimental online_compiler is being deprecated. See "
82  "'sycl_ext_oneapi_kernel_compiler.asciidoc' instead for new kernel "
83  "compiler extension to kernel_bundle implementation.") online_compiler {
84 public:
90  : OutputFormat(fmt), OutputFormatVersion({0, 0}),
91  DeviceType(sycl::info::device_type::all), DeviceArch(device_arch::any),
92  Is64Bit(true), DeviceStepping("") {}
93 
99  online_compiler(sycl::info::device_type dev_type, device_arch arch,
101  : OutputFormat(fmt), OutputFormatVersion({0, 0}), DeviceType(dev_type),
102  DeviceArch(arch), Is64Bit(true), DeviceStepping("") {}
103 
105  // TODO: the initial version generates the generic code (SKL now), need
106  // to do additional device::info calls to determine the device by it's
107  // features.
108  online_compiler(const sycl::device &)
109  : OutputFormat(compiled_code_format::spir_v), OutputFormatVersion({0, 0}),
110  DeviceType(sycl::info::device_type::all), DeviceArch(device_arch::any),
111  Is64Bit(true), DeviceStepping("") {}
112 
119  template <typename... Tys>
120  std::vector<byte> compile(const std::string &src, const Tys &...args);
121 
123  online_compiler<Lang> &setOutputFormat(compiled_code_format fmt) {
124  OutputFormat = fmt;
125  return *this;
126  }
127 
130  online_compiler<Lang> &setOutputFormatVersion(int major, int minor) {
131  OutputFormatVersion = {major, minor};
132  return *this;
133  }
134 
136  online_compiler<Lang> &setTargetDeviceType(sycl::info::device_type type) {
137  DeviceType = type;
138  return *this;
139  }
140 
142  online_compiler<Lang> &setTargetDeviceArch(device_arch arch) {
143  DeviceArch = arch;
144  return *this;
145  }
146 
148  online_compiler<Lang> &set32bitTarget() {
149  Is64Bit = false;
150  return *this;
151  };
152 
154  online_compiler<Lang> &set64bitTarget() {
155  Is64Bit = true;
156  return *this;
157  };
158 
161  online_compiler<Lang> &setTargetDeviceStepping(const std::string &id) {
162  DeviceStepping = id;
163  return *this;
164  }
165 
166 private:
168  compiled_code_format OutputFormat;
169 
171  std::pair<int, int> OutputFormatVersion;
172 
174  sycl::info::device_type DeviceType;
175 
177  device_arch DeviceArch;
178 
180  bool Is64Bit;
181 
183  std::string DeviceStepping;
184 
186  void *CompileToSPIRVHandle = nullptr;
187  void *FreeSPIRVOutputsHandle = nullptr;
188 };
189 
190 // Specializations of the online_compiler class and 'compile' function for
191 // particular languages and parameter types.
192 
197 template <>
198 template <>
199 __SYCL_EXPORT std::vector<byte>
201  const std::string &src, const std::vector<std::string> &options);
202 
205 template <>
206 template <>
207 std::vector<byte>
209  return compile(src, std::vector<std::string>{});
210 }
211 
215 template <>
216 template <>
217 __SYCL_EXPORT std::vector<byte> online_compiler<source_language::cm>::compile(
218  const std::string &src, const std::vector<std::string> &options);
219 
221 template <>
222 template <>
223 std::vector<byte>
224 online_compiler<source_language::cm>::compile(const std::string &src) {
225  return compile(src, std::vector<std::string>{});
226 }
227 
228 } // namespace ext::intel::experimental
229 } // namespace _V1
230 } // namespace sycl
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
Represents an error happend during online compilation.
The kernel_bundle class represents collection of device images in a particular state.
Provides an abstraction of a SYCL kernel.
Definition: kernel.hpp:71
source_language
Designates a source language for the online compiler.
kernel_bundle< bundle_state::object > compile(const kernel_bundle< bundle_state::input > &InputBundle, const std::vector< device > &Devs, const property_list &PropList={})
signed char __SYCL2020_DEPRECATED
Definition: aliases.hpp:94
std::uint8_t instead
Definition: aliases.hpp:93
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition: exception.cpp:65
Definition: access.hpp:18