@@ -28,7 +28,14 @@ program_impl::program_impl(ContextImplPtr Context)
2828
2929program_impl::program_impl (ContextImplPtr Context,
3030 vector_class<device> DeviceList)
31- : MContext(Context), MDevices(DeviceList) {}
31+ : MContext(Context), MDevices(DeviceList) {
32+ if (Context->getDevices ().size () > 1 ) {
33+ throw feature_not_supported (
34+ " multiple devices within a context are not supported with "
35+ " sycl::program and sycl::kernel" ,
36+ PI_INVALID_OPERATION);
37+ }
38+ }
3239
3340program_impl::program_impl (
3441 vector_class<shared_ptr_class<program_impl>> ProgramList,
@@ -51,6 +58,12 @@ program_impl::program_impl(
5158 }
5259
5360 MContext = ProgramList[0 ]->MContext ;
61+ if (MContext->getDevices ().size () > 1 ) {
62+ throw feature_not_supported (
63+ " multiple devices within a context are not supported with "
64+ " sycl::program and sycl::kernel" ,
65+ PI_INVALID_OPERATION);
66+ }
5467 MDevices = ProgramList[0 ]->MDevices ;
5568 vector_class<device> DevicesSorted;
5669 if (!is_host ()) {
@@ -105,6 +118,13 @@ program_impl::program_impl(ContextImplPtr Context,
105118 RT::PiProgram Program)
106119 : MProgram(Program), MContext(Context), MLinkable(true ) {
107120
121+ if (Context->getDevices ().size () > 1 ) {
122+ throw feature_not_supported (
123+ " multiple devices within a context are not supported with "
124+ " sycl::program and sycl::kernel" ,
125+ PI_INVALID_OPERATION);
126+ }
127+
108128 const detail::plugin &Plugin = getPlugin ();
109129 if (MProgram == nullptr ) {
110130 assert (InteropProgram &&
@@ -233,7 +253,7 @@ void program_impl::build_with_kernel_name(string_class KernelName,
233253 if (is_cacheable_with_options (BuildOptions)) {
234254 MProgramAndKernelCachingAllowed = true ;
235255 MProgram = ProgramManager::getInstance ().getBuiltPIProgram (
236- Module, get_context (), KernelName, this ,
256+ Module, get_context (), get_devices ()[ 0 ], KernelName, this ,
237257 /* JITCompilationIsRequired=*/ (!BuildOptions.empty ()));
238258 const detail::plugin &Plugin = getPlugin ();
239259 Plugin.call <PiApiKind::piProgramRetain>(MProgram);
@@ -356,7 +376,7 @@ void program_impl::build(const string_class &Options) {
356376 check_device_feature_support<info::device::is_compiler_available>(MDevices);
357377 vector_class<RT::PiDevice> Devices (get_pi_devices ());
358378 const detail::plugin &Plugin = getPlugin ();
359- ProgramManager::getInstance ().flushSpecConstants (*this );
379+ ProgramManager::getInstance ().flushSpecConstants (*this , get_pi_devices ()[ 0 ] );
360380 RT::PiResult Err = Plugin.call_nocheck <PiApiKind::piProgramBuild>(
361381 MProgram, Devices.size (), Devices.data (), Options.c_str (), nullptr ,
362382 nullptr );
@@ -404,7 +424,8 @@ RT::PiKernel program_impl::get_pi_kernel(const string_class &KernelName) const {
404424 if (is_cacheable ()) {
405425 std::tie (Kernel, std::ignore) =
406426 ProgramManager::getInstance ().getOrCreateKernel (
407- MProgramModuleHandle, get_context (), KernelName, this );
427+ MProgramModuleHandle, get_context (), get_devices ()[0 ], KernelName,
428+ this );
408429 getPlugin ().call <PiApiKind::piKernelRetain>(Kernel);
409430 } else {
410431 const detail::plugin &Plugin = getPlugin ();
@@ -453,9 +474,10 @@ void program_impl::create_pi_program_with_kernel_name(
453474 bool JITCompilationIsRequired) {
454475 assert (!MProgram && " This program already has an encapsulated PI program" );
455476 ProgramManager &PM = ProgramManager::getInstance ();
477+ const device FirstDevice = get_devices ()[0 ];
456478 RTDeviceBinaryImage &Img = PM.getDeviceImage (
457- Module, KernelName, get_context (), JITCompilationIsRequired);
458- MProgram = PM.createPIProgram (Img, get_context ());
479+ Module, KernelName, get_context (), FirstDevice, JITCompilationIsRequired);
480+ MProgram = PM.createPIProgram (Img, get_context (), FirstDevice );
459481}
460482
461483template <>
0 commit comments