DPC++ Runtime
Runtime libraries for oneAPI DPC++
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>
15 #include <CL/sycl/detail/cl.h>
20 #include <CL/sycl/kernel.hpp>
22 #include <CL/sycl/stl.hpp>
24 
26 namespace sycl {
27 
28 // Forward declarations
29 class context;
30 class device;
31 namespace detail {
32 class program_impl;
33 }
34 
35 enum class program_state { none = 0, compiled = 1, linked = 2 };
36 
43 class __SYCL_EXPORT __SYCL2020_DEPRECATED(
44  "program class is deprecated, use kernel_bundle instead") program {
45 public:
46  program() = delete;
47 
56  explicit program(const context &Context, const property_list &PropList = {});
57 
67  program(const context &Context, std::vector<device> DeviceList,
68  const property_list &PropList = {});
69 
82  program(std::vector<program> ProgramList, const property_list &PropList = {});
83 
97  program(std::vector<program> ProgramList, std::string LinkOptions,
98  const property_list &PropList = {});
99 
111  program(const context &Context, cl_program ClProgram);
112 
113  program(const program &rhs) = default;
114 
115  program(program &&rhs) = default;
116 
117  program &operator=(const program &rhs) = default;
118 
119  program &operator=(program &&rhs) = default;
120 
121  bool operator==(const program &rhs) const { return impl == rhs.impl; }
122 
123  bool operator!=(const program &rhs) const { return impl != rhs.impl; }
124 
128  template <typename propertyT> bool has_property() const;
129 
136  template <typename propertyT> propertyT get_property() const;
137 
145  cl_program get() const;
146 
148  bool is_host() const;
149 
162  template <typename KernelT>
163  void compile_with_kernel_type(std::string CompileOptions = "") {
164  detail::OSModuleHandle M = detail::OSUtil::getOSModuleHandle(
165  detail::KernelInfo<KernelT>::getName());
166  compile_with_kernel_name(detail::KernelInfo<KernelT>::getName(),
167  CompileOptions, M);
168  }
169 
183  void compile_with_source(std::string KernelSource,
184  std::string CompileOptions = "");
185 
199  template <typename KernelT>
200  void build_with_kernel_type(std::string BuildOptions = "") {
201  detail::OSModuleHandle M = detail::OSUtil::getOSModuleHandle(
202  detail::KernelInfo<KernelT>::getName());
203  build_with_kernel_name(detail::KernelInfo<KernelT>::getName(), BuildOptions,
204  M);
205  }
206 
220  void build_with_source(std::string KernelSource,
221  std::string BuildOptions = "");
222 
234  void link(std::string LinkOptions = "");
235 
242  template <typename KernelT> bool has_kernel() const {
243  return has_kernel(detail::KernelInfo<KernelT>::getName(),
244  /*IsCreatedFromSource*/ false);
245  }
246 
256  bool has_kernel(std::string KernelName) const;
257 
264  template <typename KernelT> kernel get_kernel() const {
265  return get_kernel(detail::KernelInfo<KernelT>::getName(),
266  /*IsCreatedFromSource*/ false);
267  }
268 
276  kernel get_kernel(std::string KernelName) const;
277 
281  template <info::program param>
282  typename info::param_traits<info::program, param>::return_type
283  get_info() const;
284 
293  std::vector<std::vector<char>> get_binaries() const;
294 
296  context get_context() const;
297 
299  std::vector<device> get_devices() const;
300 
311  std::string get_compile_options() const;
312 
327  std::string get_link_options() const;
328 
337  std::string get_build_options() const;
338 
340  program_state get_state() const;
341 
347  template <typename ID, typename T>
348  ext::oneapi::experimental::spec_constant<T, ID> set_spec_constant(T Cst) {
349  constexpr const char *Name = detail::SpecConstantInfo<ID>::getName();
350  static_assert(std::is_arithmetic<T>::value ||
351  (std::is_class<T>::value && std::is_pod<T>::value),
352  "unsupported specialization constant type");
353 #ifdef __SYCL_DEVICE_ONLY__
354  (void)Cst;
355  (void)Name;
356  return ext::oneapi::experimental::spec_constant<T, ID>();
357 #else
358  set_spec_constant_impl(Name, &Cst, sizeof(T));
359  return ext::oneapi::experimental::spec_constant<T, ID>(Cst);
360 #endif // __SYCL_DEVICE_ONLY__
361  }
362 
366  backend get_backend() const noexcept;
367 
371  template <backend Backend>
372  __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
373  backend_return_t<Backend, program> get_native() const {
374  return reinterpret_cast<backend_return_t<Backend, program>>(getNative());
375  }
376 
377 private:
378  pi_native_handle getNative() const;
379  program(std::shared_ptr<detail::program_impl> impl);
380 
387  kernel get_kernel(std::string KernelName, bool IsCreatedFromSource) const;
388 
395  bool has_kernel(std::string KernelName, bool IsCreatedFromSource) const;
396 
402  void compile_with_kernel_name(std::string KernelName,
403  std::string CompileOptions,
405 
411  void build_with_kernel_name(std::string KernelName, std::string buildOptions,
413 
414  void set_spec_constant_impl(const char *Name, void *Data, size_t Size);
415 
416  std::shared_ptr<detail::program_impl> impl;
417 
418  template <class Obj>
419  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
420  template <class T>
421  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
422 };
423 } // namespace sycl
424 } // __SYCL_INLINE_NAMESPACE(cl)
425 
426 namespace std {
427 template <> struct hash<cl::sycl::program> {
428  size_t operator()(const cl::sycl::program &prg) const {
429  return hash<std::shared_ptr<cl::sycl::detail::program_impl>>()(
431  }
432 };
433 } // namespace std
434 
435 #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:72
T
__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:123
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:633
stl.hpp
cl::sycl::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:221
__SYCL_DEPRECATED
#define __SYCL_DEPRECATED(message)
Definition: defines_elementary.hpp:47
context.hpp
os_util.hpp
sycl
Definition: invoke_simd.hpp:68
operator==
bool operator==(const Slab &Lhs, const Slab &Rhs)
Definition: usm_allocator.cpp:583
backend_traits.hpp
export.hpp
kernel.hpp
cl.h
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:98
cl::sycl::info::context
context
Definition: info_desc.hpp:42
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::usm::free
void free(void *Ptr, const context &Ctxt, const code_location &CL)
Definition: usm_impl.cpp:220
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:204
std
Definition: accessor.hpp:2617
kernel_desc.hpp
cl::sycl::ext::oneapi::experimental::detail::get_property
static constexpr std::enable_if_t< HasProperty, typename FindCompileTimePropertyValueType< CTPropertyT, PropertiesT >::type > get_property()
Definition: properties.hpp:65
cl::sycl::info::local_mem_type::none
@ none
info_desc.hpp
cl::sycl::instead
std::uint8_t instead
Definition: aliases.hpp:69
cl::sycl::info::device
device
Definition: info_desc.hpp:53
spec_constant.hpp
cl::sycl::info::kernel
kernel
Definition: info_desc.hpp:236
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12