DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
program.hpp
Go to the documentation of this file.
1 //==--------------- program.hpp --- SYCL program ---------------------------==//
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 
11 #ifdef __SYCL_INTERNAL_API
12 
13 #include <CL/sycl/context.hpp>
19 #include <CL/sycl/kernel.hpp>
21 #include <CL/sycl/stl.hpp>
23 
25 namespace sycl {
26 
27 // Forward declarations
28 class context;
29 class device;
30 namespace detail {
31 class program_impl;
32 }
33 
34 enum class program_state { none = 0, compiled = 1, linked = 2 };
35 
42 class __SYCL_EXPORT __SYCL2020_DEPRECATED(
43  "program class is deprecated, use kernel_bundle instead") program {
44 public:
45  program() = delete;
46 
55  explicit program(const context &Context, const property_list &PropList = {});
56 
66  program(const context &Context, std::vector<device> DeviceList,
67  const property_list &PropList = {});
68 
81  program(std::vector<program> ProgramList, const property_list &PropList = {});
82 
96  program(std::vector<program> ProgramList, std::string LinkOptions,
97  const property_list &PropList = {});
98 
110  program(const context &Context, cl_program ClProgram);
111 
112  program(const program &rhs) = default;
113 
114  program(program &&rhs) = default;
115 
116  program &operator=(const program &rhs) = default;
117 
118  program &operator=(program &&rhs) = default;
119 
120  bool operator==(const program &rhs) const { return impl == rhs.impl; }
121 
122  bool operator!=(const program &rhs) const { return impl != rhs.impl; }
123 
127  template <typename propertyT> bool has_property() const;
128 
135  template <typename propertyT> propertyT get_property() const;
136 
144  cl_program get() const;
145 
147  bool is_host() const;
148 
161  template <typename KernelT>
162  void compile_with_kernel_type(std::string CompileOptions = "") {
163  detail::OSModuleHandle M = detail::OSUtil::getOSModuleHandle(
164  detail::KernelInfo<KernelT>::getName());
165  compile_with_kernel_name(detail::KernelInfo<KernelT>::getName(),
166  CompileOptions, M);
167  }
168 
182  void compile_with_source(std::string KernelSource,
183  std::string CompileOptions = "");
184 
198  template <typename KernelT>
199  void build_with_kernel_type(std::string BuildOptions = "") {
200  detail::OSModuleHandle M = detail::OSUtil::getOSModuleHandle(
201  detail::KernelInfo<KernelT>::getName());
202  build_with_kernel_name(detail::KernelInfo<KernelT>::getName(), BuildOptions,
203  M);
204  }
205 
219  void build_with_source(std::string KernelSource,
220  std::string BuildOptions = "");
221 
233  void link(std::string LinkOptions = "");
234 
241  template <typename KernelT> bool has_kernel() const {
242  return has_kernel(detail::KernelInfo<KernelT>::getName(),
243  /*IsCreatedFromSource*/ false);
244  }
245 
255  bool has_kernel(std::string KernelName) const;
256 
263  template <typename KernelT> kernel get_kernel() const {
264  return get_kernel(detail::KernelInfo<KernelT>::getName(),
265  /*IsCreatedFromSource*/ false);
266  }
267 
275  kernel get_kernel(std::string KernelName) const;
276 
280  template <info::program param>
281  typename info::param_traits<info::program, param>::return_type
282  get_info() const;
283 
292  std::vector<std::vector<char>> get_binaries() const;
293 
295  context get_context() const;
296 
298  std::vector<device> get_devices() const;
299 
310  std::string get_compile_options() const;
311 
326  std::string get_link_options() const;
327 
336  std::string get_build_options() const;
337 
339  program_state get_state() const;
340 
346  template <typename ID, typename T>
347  ext::oneapi::experimental::spec_constant<T, ID> set_spec_constant(T Cst) {
348  constexpr const char *Name = detail::SpecConstantInfo<ID>::getName();
349  static_assert(std::is_arithmetic<T>::value ||
350  (std::is_class<T>::value && std::is_pod<T>::value),
351  "unsupported specialization constant type");
352 #ifdef __SYCL_DEVICE_ONLY__
353  (void)Cst;
354  (void)Name;
355  return ext::oneapi::experimental::spec_constant<T, ID>();
356 #else
357  set_spec_constant_impl(Name, &Cst, sizeof(T));
358  return ext::oneapi::experimental::spec_constant<T, ID>(Cst);
359 #endif // __SYCL_DEVICE_ONLY__
360  }
361 
365  backend get_backend() const noexcept;
366 
370  template <backend Backend>
371  __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
372  backend_return_t<Backend, program> get_native() const {
373  return reinterpret_cast<backend_return_t<Backend, program>>(getNative());
374  }
375 
376 private:
377  pi_native_handle getNative() const;
378  program(std::shared_ptr<detail::program_impl> impl);
379 
386  kernel get_kernel(std::string KernelName, bool IsCreatedFromSource) const;
387 
394  bool has_kernel(std::string KernelName, bool IsCreatedFromSource) const;
395 
401  void compile_with_kernel_name(std::string KernelName,
402  std::string CompileOptions,
404 
410  void build_with_kernel_name(std::string KernelName, std::string buildOptions,
412 
413  void set_spec_constant_impl(const char *Name, void *Data, size_t Size);
414 
415  std::shared_ptr<detail::program_impl> impl;
416 
417  template <class Obj>
418  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
419  template <class T>
420  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
421 };
422 } // namespace sycl
423 } // __SYCL_INLINE_NAMESPACE(cl)
424 
425 namespace std {
426 template <> struct hash<cl::sycl::program> {
427  size_t operator()(const cl::sycl::program &prg) const {
428  return hash<std::shared_ptr<cl::sycl::detail::program_impl>>()(
430  }
431 };
432 } // namespace std
433 
434 #endif
cl::sycl::backend
backend
Definition: backend_types.hpp:21
property_list.hpp
cl::sycl::backend_return_t
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:65
T
cl::sycl::info::device
device
Definition: info_desc.hpp:50
__SYCL2020_DEPRECATED
#define __SYCL2020_DEPRECATED(message)
Definition: defines_elementary.hpp:56
cl::sycl::get_native
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:68
cl::sycl::link
kernel_bundle< bundle_state::executable > link(const std::vector< kernel_bundle< bundle_state::object >> &ObjectBundles, const std::vector< device > &Devs, const property_list &PropList={})
Definition: kernel_bundle.hpp:667
cl::sycl::operator!=
bool operator!=(const multi_ptr< ElementType, Space > &lhs, const multi_ptr< ElementType, Space > &rhs)
Definition: multi_ptr.hpp:626
stl.hpp
cl::sycl::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:215
__SYCL_DEPRECATED
#define __SYCL_DEPRECATED(message)
Definition: defines_elementary.hpp:47
context.hpp
os_util.hpp
cl::sycl::info::kernel
kernel
Definition: info_desc.hpp:230
detail
Definition: pi_opencl.cpp:86
operator==
bool operator==(const Slab &Lhs, const Slab &Rhs)
Definition: usm_allocator.cpp:546
backend_traits.hpp
export.hpp
kernel.hpp
cl::sycl::detail::usm::free
void free(void *Ptr, const context &Ctxt)
Definition: usm_impl.cpp:132
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:73
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl::sycl::detail::OSModuleHandle
intptr_t OSModuleHandle
Uniquely identifies an operating system module (executable or a dynamic library)
Definition: os_util.hpp:48
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:198
std
Definition: accessor.hpp:2532
kernel_desc.hpp
cl::sycl::info::local_mem_type::none
@ none
info_desc.hpp
cl::sycl::instead
std::uint8_t instead
Definition: aliases.hpp:68
cl::sycl::info::context
context
Definition: info_desc.hpp:41
spec_constant.hpp
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12