20 inline namespace _V1 {
23 : impl(
std::make_shared<detail::kernel_id_impl>(Name)) {}
25 const char *kernel_id::get_name() const
noexcept {
return impl->get_name(); }
34 return impl->has_kernel(KernelID);
37 bool device_image_plain::has_kernel(
const kernel_id &KernelID,
39 return impl->has_kernel(KernelID, Dev);
43 return impl->getNative();
50 bool kernel_bundle_plain::empty() const
noexcept {
return impl->empty(); }
53 return impl->get_backend();
57 return impl->get_context();
60 std::vector<device> kernel_bundle_plain::get_devices() const
noexcept {
61 return impl->get_devices();
65 return impl->get_kernel_ids();
68 bool kernel_bundle_plain::contains_specialization_constants() const
noexcept {
69 return impl->contains_specialization_constants();
72 bool kernel_bundle_plain::native_specialization_constant() const
noexcept {
73 return impl->native_specialization_constant();
77 return impl->get_kernel(KernelID, impl);
89 return impl->has_kernel(KernelID);
92 bool kernel_bundle_plain::has_kernel(
const kernel_id &KernelID,
94 return impl->has_kernel(KernelID, Dev);
97 bool kernel_bundle_plain::has_specialization_constant_impl(
98 const char *SpecName)
const noexcept {
99 return impl->has_specialization_constant(SpecName);
102 void kernel_bundle_plain::set_specialization_constant_impl(
103 const char *SpecName,
void *Value,
size_t Size)
noexcept {
104 impl->set_specialization_constant_raw_value(SpecName, Value, Size);
107 void kernel_bundle_plain::get_specialization_constant_impl(
108 const char *SpecName,
void *Value)
const noexcept {
109 impl->get_specialization_constant_raw_value(SpecName, Value);
112 bool kernel_bundle_plain::is_specialization_constant_set(
113 const char *SpecName)
const noexcept {
114 return impl->is_specialization_constant_set(SpecName);
117 bool kernel_bundle_plain::ext_oneapi_has_kernel(
const std::string &name) {
118 return impl->ext_oneapi_has_kernel(name);
121 kernel kernel_bundle_plain::ext_oneapi_get_kernel(
const std::string &name) {
122 return impl->ext_oneapi_get_kernel(name, impl);
129 const std::vector<device>
131 std::vector<device> UniqueDevices;
134 std::unordered_set<device> UniqueDeviceSet;
135 for (
const device &Dev : Devs)
136 if (UniqueDeviceSet.insert(Dev).second)
137 UniqueDevices.push_back(Dev);
139 return UniqueDevices;
143 return detail::ProgramManager::getInstance().getSYCLKernelID(
150 return std::make_shared<detail::kernel_bundle_impl>(Ctx, Devs, State);
155 const std::vector<kernel_id> &KernelIDs,
157 return std::make_shared<detail::kernel_bundle_impl>(Ctx, Devs, KernelIDs,
164 return std::make_shared<detail::kernel_bundle_impl>(Ctx, Devs, Selector,
170 const std::vector<device> &Devs) {
171 return std::make_shared<detail::kernel_bundle_impl>(Ctx, Devs);
174 std::shared_ptr<detail::kernel_bundle_impl>
175 join_impl(
const std::vector<detail::KernelBundleImplPtr> &Bundles,
177 return std::make_shared<detail::kernel_bundle_impl>(Bundles, State);
184 if (Devs.empty() || !AllDevicesInTheContext)
186 "Not all devices are associated with the context or "
187 "vector of devices is empty");
189 if (bundle_state::input == State &&
192 if (bundle_state::object == State &&
196 const std::vector<device_image_plain> DeviceImages =
197 detail::ProgramManager::getInstance()
198 .getSYCLDeviceImagesWithCompatibleState(Ctx, Devs, State);
200 return (
bool)DeviceImages.size();
204 const std::vector<kernel_id> &KernelIds,
209 if (Devs.empty() || !AllDevicesInTheContext)
211 "Not all devices are associated with the context or "
212 "vector of devices is empty");
214 bool DeviceHasRequireAspectForState =
true;
215 if (bundle_state::input == State) {
216 DeviceHasRequireAspectForState =
218 return Dev.has(aspect::online_compiler);
220 }
else if (bundle_state::object == State) {
221 DeviceHasRequireAspectForState =
223 return Dev.has(aspect::online_linker);
227 if (!DeviceHasRequireAspectForState)
230 const std::vector<device_image_plain> DeviceImages =
231 detail::ProgramManager::getInstance()
232 .getSYCLDeviceImagesWithCompatibleState(Ctx, Devs, State);
234 std::set<kernel_id, LessByNameComp> CombinedKernelIDs;
236 const std::shared_ptr<device_image_impl> &DeviceImageImpl =
239 CombinedKernelIDs.insert(DeviceImageImpl->get_kernel_ids_ptr()->begin(),
240 DeviceImageImpl->get_kernel_ids_ptr()->end());
243 const bool AllKernelIDsRepresented =
245 [&CombinedKernelIDs](
const kernel_id &KernelID) {
246 return CombinedKernelIDs.count(KernelID);
249 return AllKernelIDsRepresented;
252 std::shared_ptr<detail::kernel_bundle_impl>
254 const std::vector<device> &Devs,
const property_list &PropList) {
255 return std::make_shared<detail::kernel_bundle_impl>(
256 InputBundle, Devs, PropList, bundle_state::object);
259 std::shared_ptr<detail::kernel_bundle_impl>
261 const std::vector<device> &Devs,
const property_list &PropList) {
262 return std::make_shared<detail::kernel_bundle_impl>(ObjectBundles, Devs,
266 std::shared_ptr<detail::kernel_bundle_impl>
268 const std::vector<device> &Devs,
const property_list &PropList) {
269 return std::make_shared<detail::kernel_bundle_impl>(
270 InputBundle, Devs, PropList, bundle_state::executable);
277 std::vector<sycl::device> IntersectDevices;
278 std::vector<unsigned int> DevsCounters;
279 std::map<device, unsigned int, LessByHash<device>> DevCounters;
284 DevCounters[Device]++;
288 for (
const std::pair<const device, unsigned int> &It : DevCounters)
289 if (ObjectBundles.size() == It.second)
290 IntersectDevices.push_back(It.first);
292 return IntersectDevices;
302 return detail::ProgramManager::getInstance().getAllSYCLKernelIDs();
306 if (KernelIDs.empty())
311 auto doesImageTargetMatchDevice = [](
const device &Dev,
312 const detail::RTDeviceBinaryImage &Img) {
313 const char *Target = Img.getRawData().DeviceTargetSpec;
316 if (BE == sycl::backend::ext_intel_esimd_emulator) {
318 return (Prop && (detail::DeviceBinaryProperty(Prop).asUint32() != 0));
321 return (BE == sycl::backend::opencl ||
322 BE == sycl::backend::ext_oneapi_level_zero);
328 return Dev.
is_gpu() && (BE == sycl::backend::opencl ||
329 BE == sycl::backend::ext_oneapi_level_zero);
334 return BE == sycl::backend::ext_oneapi_cuda;
336 return BE == sycl::backend::ext_oneapi_hip;
346 for (
const auto &KernelID : KernelIDs) {
347 std::set<detail::RTDeviceBinaryImage *> BinImages =
348 detail::ProgramManager::getInstance().getRawDeviceImages({KernelID});
351 [&](
const detail::RTDeviceBinaryImage *Img) {
352 return doesDevSupportDeviceRequirements(Dev, *Img) &&
353 doesImageTargetMatchDevice(Dev, *Img);
364 namespace ext::oneapi::experimental {
375 bool BE_Acceptable = (BE == sycl::backend::ext_oneapi_level_zero) ||
376 (BE == sycl::backend::opencl);
379 if (Language == source_language::opencl) {
381 }
else if (Language == source_language::spirv) {
396 const std::string &Source) {
403 "kernel_bundle creation from source not supported");
405 std::shared_ptr<kernel_bundle_impl> KBImpl =
406 std::make_shared<kernel_bundle_impl>(SyclContext, Language, Source);
407 return sycl::detail::createSyclObjFromImpl<source_kb>(KBImpl);
413 const std::vector<std::byte> &Bytes) {
417 "kernel_bundle creation from source not supported");
419 std::shared_ptr<kernel_bundle_impl> KBImpl =
420 std::make_shared<kernel_bundle_impl>(SyclContext, Language, Bytes);
421 return sycl::detail::createSyclObjFromImpl<source_kb>(KBImpl);
430 const std::vector<device> &Devices,
432 std::string *LogPtr) {
433 std::vector<device> UniqueDevices =
435 std::shared_ptr<kernel_bundle_impl> sourceImpl =
getSyclObjImpl(SourceKB);
436 std::shared_ptr<kernel_bundle_impl> KBImpl =
437 sourceImpl->build_from_source(UniqueDevices,
BuildOptions, LogPtr);
438 return 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
Returns the backend associated with this 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
Check if device is a CPU 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.
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)
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)
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
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 OpenCLC_Compilation_Available()
exe_kb build_from_source(source_kb &SourceKB, const std::vector< device > &Devices, const std::vector< std::string > &BuildOptions, std::string *LogPtr)
bool is_source_kernel_bundle_supported(backend BE, source_language Language)
kernel_bundle< bundle_state::ext_oneapi_source > create_kernel_bundle_from_source(const context &SyclContext, source_language Language, const std::string &Source)
sycl::detail::kernel_bundle_impl kernel_bundle_impl
kernel_bundle< sycl::bundle_state::ext_oneapi_source > source_kb
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()
uintptr_t pi_native_handle
#define __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64_X86_64
Device-specific binary images produced from SPIR-V 64-bit <-> various "spir64_*" triples for specific...
#define __SYCL_PI_DEVICE_BINARY_TARGET_NVPTX64
PTX 64-bit image <-> "nvptx64", 64-bit NVIDIA PTX device.
#define __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64
SPIR-V 64-bit image <-> "spir64", 64-bit OpenCL device.
#define __SYCL_PI_DEVICE_BINARY_TARGET_AMDGCN
#define __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64_GEN
#define __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64_FPGA
bool all_of(const simd_mask< _Tp, _Abi > &) noexcept
_Abi const simd< _Tp, _Abi > & noexcept
bool none_of(const simd_mask< _Tp, _Abi > &) noexcept