22 inline namespace _V1 {
25 : impl(
std::make_shared<detail::kernel_id_impl>(Name)) {}
27 const char *kernel_id::get_name() const
noexcept {
return impl->get_name(); }
36 return impl->has_kernel(KernelID);
39 bool device_image_plain::has_kernel(
const kernel_id &KernelID,
41 return impl->has_kernel(KernelID, Dev);
44 ur_native_handle_t device_image_plain::getNative()
const {
45 return impl->getNative();
52 bool kernel_bundle_plain::empty() const
noexcept {
return impl->empty(); }
55 return impl->get_backend();
59 return impl->get_context();
62 std::vector<device> kernel_bundle_plain::get_devices() const
noexcept {
63 return impl->get_devices();
67 return impl->get_kernel_ids();
70 bool kernel_bundle_plain::contains_specialization_constants() const
noexcept {
71 return impl->contains_specialization_constants();
74 bool kernel_bundle_plain::native_specialization_constant() const
noexcept {
75 return impl->native_specialization_constant();
79 return impl->get_kernel(KernelID, impl);
91 return impl->has_kernel(KernelID);
94 bool kernel_bundle_plain::has_kernel(
const kernel_id &KernelID,
96 return impl->has_kernel(KernelID, Dev);
99 bool kernel_bundle_plain::has_specialization_constant_impl(
100 const char *SpecName)
const noexcept {
101 return impl->has_specialization_constant(SpecName);
104 void kernel_bundle_plain::set_specialization_constant_impl(
105 const char *SpecName,
void *Value,
size_t Size)
noexcept {
106 impl->set_specialization_constant_raw_value(SpecName, Value, Size);
109 void kernel_bundle_plain::get_specialization_constant_impl(
110 const char *SpecName,
void *Value)
const noexcept {
111 impl->get_specialization_constant_raw_value(SpecName, Value);
114 bool kernel_bundle_plain::is_specialization_constant_set(
115 const char *SpecName)
const noexcept {
116 return impl->is_specialization_constant_set(SpecName);
120 return impl->ext_oneapi_has_kernel(name.
data());
124 return impl->ext_oneapi_get_kernel(name.
data(), impl);
131 const std::vector<device>
133 std::vector<device> UniqueDevices;
136 std::unordered_set<device> UniqueDeviceSet;
137 for (
const device &Dev : Devs)
138 if (UniqueDeviceSet.insert(Dev).second)
139 UniqueDevices.push_back(Dev);
141 return UniqueDevices;
145 return detail::ProgramManager::getInstance().getSYCLKernelID(
152 return std::make_shared<detail::kernel_bundle_impl>(Ctx, Devs, State);
157 const std::vector<kernel_id> &KernelIDs,
159 return std::make_shared<detail::kernel_bundle_impl>(Ctx, Devs, KernelIDs,
166 return std::make_shared<detail::kernel_bundle_impl>(Ctx, Devs, Selector,
172 const std::vector<device> &Devs) {
173 return std::make_shared<detail::kernel_bundle_impl>(Ctx, Devs);
176 std::shared_ptr<detail::kernel_bundle_impl>
177 join_impl(
const std::vector<detail::KernelBundleImplPtr> &Bundles,
179 return std::make_shared<detail::kernel_bundle_impl>(Bundles, State);
186 if (Devs.empty() || !AllDevicesInTheContext)
188 "Not all devices are associated with the context or "
189 "vector of devices is empty");
191 if (bundle_state::input == State &&
194 if (bundle_state::object == State &&
198 const std::vector<device_image_plain> DeviceImages =
199 detail::ProgramManager::getInstance()
200 .getSYCLDeviceImagesWithCompatibleState(Ctx, Devs, State);
202 return (
bool)DeviceImages.size();
206 const std::vector<kernel_id> &KernelIds,
211 if (Devs.empty() || !AllDevicesInTheContext)
213 "Not all devices are associated with the context or "
214 "vector of devices is empty");
216 bool DeviceHasRequireAspectForState =
true;
217 if (bundle_state::input == State) {
218 DeviceHasRequireAspectForState =
220 return Dev.has(aspect::online_compiler);
222 }
else if (bundle_state::object == State) {
223 DeviceHasRequireAspectForState =
225 return Dev.has(aspect::online_linker);
229 if (!DeviceHasRequireAspectForState)
232 const std::vector<device_image_plain> DeviceImages =
233 detail::ProgramManager::getInstance()
234 .getSYCLDeviceImagesWithCompatibleState(Ctx, Devs, State);
236 std::set<kernel_id, LessByNameComp> CombinedKernelIDs;
238 const std::shared_ptr<device_image_impl> &DeviceImageImpl =
241 CombinedKernelIDs.insert(DeviceImageImpl->get_kernel_ids_ptr()->begin(),
242 DeviceImageImpl->get_kernel_ids_ptr()->end());
245 const bool AllKernelIDsRepresented =
247 [&CombinedKernelIDs](
const kernel_id &KernelID) {
248 return CombinedKernelIDs.count(KernelID);
251 return AllKernelIDsRepresented;
254 std::shared_ptr<detail::kernel_bundle_impl>
256 const std::vector<device> &Devs,
const property_list &PropList) {
257 return std::make_shared<detail::kernel_bundle_impl>(
258 InputBundle, Devs, PropList, bundle_state::object);
261 std::shared_ptr<detail::kernel_bundle_impl>
263 const std::vector<device> &Devs,
const property_list &PropList) {
264 return std::make_shared<detail::kernel_bundle_impl>(ObjectBundles, Devs,
268 std::shared_ptr<detail::kernel_bundle_impl>
270 const std::vector<device> &Devs,
const property_list &PropList) {
271 return std::make_shared<detail::kernel_bundle_impl>(
272 InputBundle, Devs, PropList, bundle_state::executable);
279 std::vector<sycl::device> IntersectDevices;
280 std::vector<unsigned int> DevsCounters;
281 std::map<device, unsigned int, LessByHash<device>> DevCounters;
286 DevCounters[Device]++;
290 for (
const std::pair<const device, unsigned int> &It : DevCounters)
291 if (ObjectBundles.size() == It.second)
292 IntersectDevices.push_back(It.first);
294 return IntersectDevices;
304 return detail::ProgramManager::getInstance().getAllSYCLKernelIDs();
308 if (KernelIDs.empty())
313 auto doesImageTargetMatchDevice = [](
const device &Dev,
314 const detail::RTDeviceBinaryImage &Img) {
315 const char *Target = Img.getRawData().DeviceTargetSpec;
318 return (BE == sycl::backend::opencl ||
319 BE == sycl::backend::ext_oneapi_level_zero);
324 return Dev.
is_gpu() && (BE == sycl::backend::opencl ||
325 BE == sycl::backend::ext_oneapi_level_zero);
329 return BE == sycl::backend::ext_oneapi_cuda;
331 return BE == sycl::backend::ext_oneapi_hip;
341 for (
const auto &KernelID : KernelIDs) {
342 std::set<detail::RTDeviceBinaryImage *> BinImages =
343 detail::ProgramManager::getInstance().getRawDeviceImages({KernelID});
346 [&](
const detail::RTDeviceBinaryImage *Img) {
347 return doesDevSupportDeviceRequirements(Dev, *Img) &&
348 doesImageTargetMatchDevice(Dev, *Img);
359 namespace ext::oneapi::experimental {
372 bool BE_Acceptable = (BE == sycl::backend::ext_oneapi_level_zero) ||
373 (BE == sycl::backend::opencl);
375 if (Language == source_language::opencl) {
377 }
else if (Language == source_language::spirv) {
379 }
else if (Language == source_language::sycl) {
392 using include_pairs_t = std::vector<std::pair<std::string, std::string>>;
394 std::pair<sycl::detail::string_view, sycl::detail::string_view>>;
399 sycl::detail::string_view SourceView,
404 std::string Source{SourceView.data()};
406 size_t n = IncludePairViews.size();
407 IncludePairs.reserve(n);
408 for (
auto &p : IncludePairViews)
409 IncludePairs.push_back({p.first.data(), p.second.data()});
414 "kernel_bundle creation from source not supported");
420 std::shared_ptr<kernel_bundle_impl> KBImpl =
421 std::make_shared<kernel_bundle_impl>(SyclContext, Language, Source,
423 return sycl::detail::createSyclObjFromImpl<source_kb>(KBImpl);
428 const std::vector<std::byte> &Bytes,
434 "kernel_bundle creation from source not supported");
436 std::shared_ptr<kernel_bundle_impl> KBImpl =
437 std::make_shared<kernel_bundle_impl>(SyclContext, Language, Bytes);
438 return sycl::detail::createSyclObjFromImpl<source_kb>(KBImpl);
446 source_kb &SourceKB,
const std::vector<device> &Devices,
447 const std::vector<sycl::detail::string_view> &
BuildOptions,
448 sycl::detail::string *LogView,
450 std::vector<std::string> Options;
451 for (
const sycl::detail::string_view option :
BuildOptions)
452 Options.push_back(option.data());
454 std::vector<std::string> KernelNames;
456 KernelNames.push_back(name.
data());
459 std::string *LogPtr =
nullptr;
462 std::vector<device> UniqueDevices =
464 std::shared_ptr<kernel_bundle_impl> sourceImpl =
getSyclObjImpl(SourceKB);
465 std::shared_ptr<kernel_bundle_impl> KBImpl = sourceImpl->build_from_source(
466 UniqueDevices, Options, LogPtr, KernelNames);
467 auto result = sycl::detail::createSyclObjFromImpl<exe_kb>(KBImpl);
The context class represents a SYCL context on which kernel functions may be executed.
backend get_backend() const noexcept
Gets OpenCL interoperability context.
const char * data() const noexcept
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
bool is_accelerator() const
Check if device is an accelerator device.
bool is_gpu() const
Check if device is a GPU device.
static std::vector< device > get_devices(info::device_type deviceType=info::device_type::all)
Query available SYCL devices.
backend get_backend() const noexcept
Returns the backend associated with this device.
bool is_cpu() const
Get instance of device.
The kernel_bundle class represents collection of device images in a particular state.
Objects of the class identify kernel is some kernel_bundle related APIs.
Provides an abstraction of a SYCL kernel.
Objects of the property_list class are containers for the SYCL properties.
#define __SYCL_DEVICE_BINARY_TARGET_SPIRV64_FPGA
#define __SYCL_DEVICE_BINARY_TARGET_AMDGCN
#define __SYCL_DEVICE_BINARY_TARGET_NVPTX64
PTX 64-bit image <-> "nvptx64", 64-bit NVIDIA PTX device.
#define __SYCL_DEVICE_BINARY_TARGET_SPIRV64
SPIR-V 64-bit image <-> "spir64", 64-bit OpenCL device.
#define __SYCL_DEVICE_BINARY_TARGET_SPIRV64_X86_64
Device-specific binary images produced from SPIR-V 64-bit <-> various "spir64_*" triples for specific...
#define __SYCL_DEVICE_BINARY_TARGET_SPIRV64_GEN
std::vector< sycl::device > find_device_intersection(const std::vector< kernel_bundle< bundle_state::object >> &ObjectBundles)
std::shared_ptr< detail::kernel_bundle_impl > build_impl(const kernel_bundle< bundle_state::input > &InputBundle, const std::vector< device > &Devs, const property_list &PropList)
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
static bool checkAllDevicesAreInContext(const std::vector< device > &Devices, const context &Context)
std::function< bool(const detail::DeviceImageImplPtr &DevImgImpl)> DevImgSelectorImpl
static bool checkAllDevicesHaveAspect(const std::vector< device > &Devices, aspect Aspect)
const std::vector< device > removeDuplicateDevices(const std::vector< device > &Devs)
detail::KernelBundleImplPtr get_kernel_bundle_impl(const context &Ctx, const std::vector< device > &Devs, bundle_state State)
std::shared_ptr< detail::kernel_bundle_impl > compile_impl(const kernel_bundle< bundle_state::input > &InputBundle, const std::vector< device > &Devs, const property_list &PropList)
std::shared_ptr< detail::kernel_bundle_impl > join_impl(const std::vector< detail::KernelBundleImplPtr > &Bundles, bundle_state State)
kernel_id get_kernel_id_impl(string_view KernelName)
std::shared_ptr< detail::kernel_bundle_impl > KernelBundleImplPtr
bool has_kernel_bundle_impl(const context &Ctx, const std::vector< device > &Devs, bundle_state State)
detail::KernelBundleImplPtr get_empty_interop_kernel_bundle_impl(const context &Ctx, const std::vector< device > &Devs)
std::shared_ptr< detail::kernel_bundle_impl > link_impl(const std::vector< kernel_bundle< bundle_state::object >> &ObjectBundles, const std::vector< device > &Devs, const property_list &PropList)
bool SYCL_Compilation_Available()
source_kb make_kernel_bundle_from_source(const context &SyclContext, source_language Language, const std::vector< std::byte > &Bytes, include_pairs_view_t IncludePairs)
bool OpenCLC_Compilation_Available()
std::vector< std::pair< std::string, std::string > > include_pairs_t
std::vector< std::pair< sycl::detail::string_view, sycl::detail::string_view > > include_pairs_view_t
exe_kb build_from_source(source_kb &SourceKB, const std::vector< device > &Devices, const std::vector< sycl::detail::string_view > &BuildOptions, sycl::detail::string *LogView, const std::vector< sycl::detail::string_view > &RegisteredKernelNames)
bool is_source_kernel_bundle_supported(backend BE, source_language Language)
sycl::detail::kernel_bundle_impl kernel_bundle_impl
std::vector< kernel_id > get_kernel_ids()
bool is_compatible(const std::vector< kernel_id > &KernelIDs, const device &Dev)
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
bool all_of(const simd_mask< _Tp, _Abi > &) noexcept
_Abi const simd< _Tp, _Abi > & noexcept
bool none_of(const simd_mask< _Tp, _Abi > &) noexcept