34 Devices.begin(), Devices.end(), [&Context](
const device &Dev) {
35 return getSyclObjImpl(Context)->isDeviceValid(getSyclObjImpl(Dev));
42 [&Aspect](
const device &Dev) { return Dev.has(Aspect); });
50 using SpecConstMapT = std::map<std::string, std::vector<unsigned char>>;
53 const bool AllDevicesInTheContext =
55 if (MDevices.empty() || !AllDevicesInTheContext)
56 throw sycl::exception(
58 "Not all devices are associated with the context or "
59 "vector of devices is empty");
61 if (bundle_state::input == State &&
64 "Not all devices have aspect::online_compiler");
66 if (bundle_state::object == State &&
69 "Not all devices have aspect::online_linker");
74 : MContext(
std::move(Ctx)), MDevices(
std::move(Devs)), MState(State) {
76 common_ctor_checks(State);
78 MDeviceImages = detail::ProgramManager::getInstance().getSYCLDeviceImages(
79 MContext, MDevices, State);
86 throw sycl::exception(
88 "Not all devices are associated with the context or "
89 "vector of devices is empty");
97 MDeviceImages.push_back(DevImage);
106 : MContext(InputBundle.get_context()), MDevices(
std::move(Devs)),
107 MState(TargetState) {
109 MSpecConstValues =
getSyclObjImpl(InputBundle)->get_spec_const_map_ref();
111 const std::vector<device> &InputBundleDevices =
113 const bool AllDevsAssociatedWithInputBundle =
115 [&InputBundleDevices](
const device &Dev) {
116 return InputBundleDevices.end() !=
117 std::find(InputBundleDevices.begin(),
118 InputBundleDevices.end(), Dev);
120 if (MDevices.empty() || !AllDevsAssociatedWithInputBundle)
121 throw sycl::exception(
123 "Not all devices are in the set of associated "
124 "devices for input bundle or vector of devices is empty");
129 MDevices.begin(), MDevices.end(),
130 [&DeviceImage](
const device &Dev) {
131 return getSyclObjImpl(DeviceImage)->compatible_with_device(Dev);
135 switch (TargetState) {
136 case bundle_state::object:
137 MDeviceImages.push_back(detail::ProgramManager::getInstance().
compile(
138 DeviceImage, MDevices, PropList));
140 case bundle_state::executable:
141 MDeviceImages.push_back(detail::ProgramManager::getInstance().
build(
142 DeviceImage, MDevices, PropList));
144 case bundle_state::input:
145 throw sycl::runtime_error(
146 "Internal error. The target state should not be input",
147 PI_ERROR_INVALID_OPERATION);
159 if (MDevices.empty())
161 "Vector of devices is empty");
163 if (ObjectBundles.empty())
166 MContext = ObjectBundles[0].get_context();
167 for (
size_t I = 1; I < ObjectBundles.size(); ++I) {
168 if (ObjectBundles[I].get_context() != MContext)
169 throw sycl::exception(
171 "Not all input bundles have the same associated context");
176 const bool AllDevsAssociatedWithInputBundles =
std::all_of(
177 MDevices.begin(), MDevices.end(), [&ObjectBundles](
const device &Dev) {
180 ObjectBundles.begin(), ObjectBundles.end(),
181 [&Dev](const kernel_bundle<bundle_state::object> &KernelBundle) {
182 const std::vector<device> &BundleDevices =
183 getSyclObjImpl(KernelBundle)->get_devices();
184 return BundleDevices.end() != std::find(BundleDevices.begin(),
189 if (!AllDevsAssociatedWithInputBundles)
191 "Not all devices are in the set of associated "
192 "devices for input bundles");
210 [&DeviceImage](
const device &Dev) {
211 return getSyclObjImpl(DeviceImage)
212 ->compatible_with_device(Dev);
216 std::vector<device_image_plain> LinkedResults =
217 detail::ProgramManager::getInstance().link(DeviceImage, MDevices,
219 MDeviceImages.insert(MDeviceImages.end(), LinkedResults.begin(),
220 LinkedResults.end());
224 for (
const kernel_bundle<bundle_state::object> &Bundle : ObjectBundles) {
226 for (
const std::pair<
const std::string, std::vector<unsigned char>>
227 &SpecConst : BundlePtr->MSpecConstValues) {
228 MSpecConstValues[SpecConst.first] = SpecConst.second;
234 const std::vector<kernel_id> &KernelIDs,
236 : MContext(
std::move(Ctx)), MDevices(
std::move(Devs)), MState(State) {
238 common_ctor_checks(State);
240 MDeviceImages = detail::ProgramManager::getInstance().getSYCLDeviceImages(
241 MContext, MDevices, KernelIDs, State);
246 : MContext(
std::move(Ctx)), MDevices(
std::move(Devs)), MState(State) {
248 common_ctor_checks(State);
250 MDeviceImages = detail::ProgramManager::getInstance().getSYCLDeviceImages(
251 MContext, MDevices, Selector, State);
261 MContext = Bundles[0]->MContext;
262 MDevices = Bundles[0]->MDevices;
263 for (
size_t I = 1; I < Bundles.size(); ++I) {
264 if (Bundles[I]->MContext != MContext)
265 throw sycl::exception(
267 "Not all input bundles have the same associated context.");
268 if (Bundles[I]->MDevices != MDevices)
269 throw sycl::exception(
271 "Not all input bundles have the same set of associated devices.");
276 MDeviceImages.insert(MDeviceImages.end(), Bundle->MDeviceImages.begin(),
277 Bundle->MDeviceImages.end());
280 std::sort(MDeviceImages.begin(), MDeviceImages.end(),
283 if (get_bundle_state() == bundle_state::input) {
287 const std::map<std::string,
288 std::vector<device_image_impl::SpecConstDescT>>
289 &SpecConsts = ImgImpl->get_spec_const_data_ref();
290 const std::vector<unsigned char> &Blob =
291 ImgImpl->get_spec_const_blob_ref();
292 for (
const std::pair<
const std::string,
293 std::vector<device_image_impl::SpecConstDescT>>
294 &SpecConst : SpecConsts) {
295 if (SpecConst.second.front().IsSet)
296 set_specialization_constant_raw_value(
297 SpecConst.first.c_str(),
298 Blob.data() + SpecConst.second.front().BlobOffset,
299 SpecConst.second.back().CompositeOffset +
300 SpecConst.second.back().Size);
307 const auto DevImgIt =
308 std::unique(MDeviceImages.begin(), MDeviceImages.end());
311 MDeviceImages.erase(DevImgIt, MDeviceImages.end());
314 for (
const std::pair<
const std::string, std::vector<unsigned char>>
315 &SpecConst : Bundle->MSpecConstValues) {
316 set_specialization_constant_raw_value(SpecConst.first.c_str(),
317 SpecConst.second.data(),
318 SpecConst.second.size());
323 bool empty() const noexcept {
return MDeviceImages.empty(); }
326 return MContext.get_platform().get_backend();
331 const std::vector<device> &
get_devices() const noexcept {
return MDevices; }
336 std::vector<kernel_id> Result;
338 const std::vector<kernel_id> &KernelIDs =
341 Result.insert(Result.end(), KernelIDs.begin(), KernelIDs.end());
345 auto NewIt = std::unique(Result.begin(), Result.end(),
EqualByNameComp{});
346 Result.erase(NewIt, Result.end());
353 const std::shared_ptr<detail::kernel_bundle_impl> &Self)
const {
355 auto It = std::find_if(MDeviceImages.begin(), MDeviceImages.end(),
357 return DeviceImage.has_kernel(KernelID);
360 if (MDeviceImages.end() == It)
362 "The kernel bundle does not contain the kernel "
363 "identified by kernelId.");
365 const std::shared_ptr<detail::device_image_impl> &DeviceImageImpl =
370 std::tie(Kernel, std::ignore, ArgMask) =
371 detail::ProgramManager::getInstance().getOrCreateKernel(
373 DeviceImageImpl->get_program_ref());
375 std::shared_ptr<kernel_impl> KernelImpl =
377 DeviceImageImpl, Self, ArgMask);
379 return detail::createSyclObjFromImpl<kernel>(KernelImpl);
383 return std::any_of(MDeviceImages.begin(), MDeviceImages.end(),
385 return DeviceImage.has_kernel(KernelID);
391 MDeviceImages.begin(), MDeviceImages.end(),
393 return DeviceImage.has_kernel(KernelID, Dev);
399 MDeviceImages.begin(), MDeviceImages.end(),
401 return getSyclObjImpl(DeviceImage)->has_specialization_constants();
406 return contains_specialization_constants() &&
407 std::all_of(MDeviceImages.begin(), MDeviceImages.end(),
409 return getSyclObjImpl(DeviceImage)
410 ->all_specialization_constant_native();
415 return std::any_of(MDeviceImages.begin(), MDeviceImages.end(),
417 return getSyclObjImpl(DeviceImage)
418 ->has_specialization_constant(SpecName);
424 size_t Size) noexcept {
425 if (has_specialization_constant(SpecName))
428 ->set_specialization_constant_raw_value(SpecName, Value);
430 std::vector<unsigned char> &Val = MSpecConstValues[std::string{SpecName}];
437 void *ValueRet)
const noexcept {
439 if (
getSyclObjImpl(DeviceImage)->has_specialization_constant(SpecName)) {
441 ->get_specialization_constant_raw_value(SpecName, ValueRet);
447 if (MSpecConstValues.count(std::string{SpecName}) != 0) {
448 const std::vector<unsigned char> &Val =
449 MSpecConstValues.at(std::string{SpecName});
450 auto *Dest =
static_cast<unsigned char *
>(ValueRet);
451 std::uninitialized_copy(Val.begin(), Val.end(), Dest);
456 "get_specialization_constant_raw_value called for missing constant");
461 std::any_of(MDeviceImages.begin(), MDeviceImages.end(),
463 return getSyclObjImpl(DeviceImage)
464 ->is_specialization_constant_set(SpecName);
466 return SetInDevImg || MSpecConstValues.count(std::string{SpecName}) != 0;
472 return MDeviceImages.data() + MDeviceImages.size();
475 size_t size() const noexcept {
return MDeviceImages.size(); }
480 return MSpecConstValues;
487 if (has_kernel(KernelID, Dev))
492 std::vector<device_image_plain> NewDevImgs =
493 detail::ProgramManager::getInstance().getSYCLDeviceImages(
494 MContext, {Dev}, {KernelID}, BundleState);
497 if (NewDevImgs.empty())
502 for (
auto SpecConst : MSpecConstValues)
504 SpecConst.first.c_str(), SpecConst.second.data());
507 MDeviceImages.insert(MDeviceImages.end(), NewDevImgs.begin(),
514 std::vector<device> MDevices;
515 std::vector<device_image_plain> MDeviceImages;
518 SpecConstMapT MSpecConstValues;
519 bool MIsInterop =
false;