DPC++ Runtime
Runtime libraries for oneAPI DPC++
program.cpp
Go to the documentation of this file.
1 //==--------------- program.cpp --- 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 #include <CL/sycl/program.hpp>
12 #include <detail/backend_impl.hpp>
13 #include <detail/program_impl.hpp>
14 
15 #include <vector>
16 
18 namespace sycl {
19 
20 program::program(const context &context, const property_list &PropList)
21  : impl(std::make_shared<detail::program_impl>(
22  detail::getSyclObjImpl(context), PropList)) {}
23 
24 program::program(const context &context, std::vector<device> deviceList,
25  const property_list &PropList)
26  : impl(std::make_shared<detail::program_impl>(
27  detail::getSyclObjImpl(context), deviceList, PropList)) {}
28 
29 program::program(std::vector<program> programList,
30  const property_list &PropList)
31  : program(std::move(programList), /*linkOptions=*/"", PropList) {}
32 
33 program::program(std::vector<program> programList, std::string linkOptions,
34  const property_list &PropList) {
35  std::vector<std::shared_ptr<detail::program_impl>> impls;
36  for (auto &x : programList) {
37  impls.push_back(detail::getSyclObjImpl(x));
38  }
39  impl = std::make_shared<detail::program_impl>(impls, linkOptions, PropList);
40 }
41 
42 program::program(const context &context, cl_program clProgram)
43  : impl(std::make_shared<detail::program_impl>(
44  detail::getSyclObjImpl(context),
45  detail::pi::cast<pi_native_handle>(clProgram))) {
46  // The implementation constructor takes ownership of the native handle so we
47  // must retain it in order to adhere to SYCL 1.2.1 spec (Rev6, section 4.3.1.)
48  clRetainProgram(clProgram);
49 }
50 
51 backend program::get_backend() const noexcept { return getImplBackend(impl); }
52 
53 pi_native_handle program::getNative() const { return impl->getNative(); }
54 
55 program::program(std::shared_ptr<detail::program_impl> impl) : impl(impl) {}
56 
57 cl_program program::get() const { return impl->get(); }
58 
59 bool program::is_host() const { return impl->is_host(); }
60 
61 void program::compile_with_source(std::string kernelSource,
62  std::string compileOptions) {
63  impl->compile_with_source(kernelSource, compileOptions);
64 }
65 
66 void program::build_with_source(std::string kernelSource,
67  std::string buildOptions) {
68  impl->build_with_source(kernelSource, buildOptions);
69 }
70 
71 void program::compile_with_kernel_name(std::string KernelName,
72  std::string compileOptions,
74  impl->compile_with_kernel_name(KernelName, compileOptions, M);
75 }
76 
77 void program::build_with_kernel_name(std::string KernelName,
78  std::string buildOptions,
80  impl->build_with_kernel_name(KernelName, buildOptions, M);
81 }
82 
83 void program::link(std::string linkOptions) { impl->link(linkOptions); }
84 
85 bool program::has_kernel(std::string kernelName) const {
86  return has_kernel(kernelName, /*IsCreatedFromSource*/ true);
87 }
88 
89 bool program::has_kernel(std::string kernelName,
90  bool IsCreatedFromSource) const {
91  return impl->has_kernel(kernelName, IsCreatedFromSource);
92 }
93 
94 kernel program::get_kernel(std::string kernelName) const {
95  return get_kernel(kernelName, /*IsCreatedFromSource*/ true);
96 }
97 
98 kernel program::get_kernel(std::string kernelName,
99  bool IsCreatedFromSource) const {
100  return impl->get_kernel(kernelName, impl, IsCreatedFromSource);
101 }
102 
103 template <info::program param>
104 typename info::param_traits<info::program, param>::return_type
105 program::get_info() const {
106  return impl->get_info<param>();
107 }
108 
109 #define __SYCL_PARAM_TRAITS_SPEC(param_type, param, ret_type) \
110  template __SYCL_EXPORT ret_type program::get_info<info::param_type::param>() \
111  const;
112 
113 #include <CL/sycl/info/program_traits.def>
114 
115 #undef __SYCL_PARAM_TRAITS_SPEC
116 
117 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
118  template <> __SYCL_EXPORT bool program::has_property<param_type>() const { \
119  return impl->has_property<param_type>(); \
120  }
121 #include <CL/sycl/detail/properties_traits.def>
122 
123 #undef __SYCL_PARAM_TRAITS_SPEC
124 
125 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
126  template <> \
127  __SYCL_EXPORT param_type program::get_property<param_type>() const { \
128  return impl->get_property<param_type>(); \
129  }
130 #include <CL/sycl/detail/properties_traits.def>
131 
132 #undef __SYCL_PARAM_TRAITS_SPEC
133 
134 std::vector<std::vector<char>> program::get_binaries() const {
135  return impl->get_binaries();
136 }
137 
138 context program::get_context() const { return impl->get_context(); }
139 
140 std::vector<device> program::get_devices() const { return impl->get_devices(); }
141 
142 std::string program::get_compile_options() const {
143  return impl->get_compile_options();
144 }
145 
146 std::string program::get_link_options() const {
147  return impl->get_link_options();
148 }
149 
150 std::string program::get_build_options() const {
151  return impl->get_build_options();
152 }
153 
154 program_state program::get_state() const { return impl->get_state(); }
155 
156 void program::set_spec_constant_impl(const char *Name, void *Data,
157  size_t Size) {
158  impl->set_spec_constant_impl(Name, Data, Size);
159 }
160 
161 } // namespace sycl
162 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::backend
backend
Definition: backend_types.hpp:21
property_list.hpp
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::info::kernel
kernel
Definition: info_desc.hpp:236
sycl
Definition: invoke_simd.hpp:68
cast
To cast(From value)
Definition: pi_opencl.cpp:42
cl::sycl::detail::getImplBackend
backend getImplBackend(const T &Impl)
Definition: backend_impl.hpp:16
program.hpp
program_impl.hpp
all_properties.hpp
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:76
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:2616
backend_impl.hpp
cl::sycl::info::context
context
Definition: info_desc.hpp:42
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12