@@ -3814,7 +3814,6 @@ pi_result piProgramLink(pi_context Context, pi_uint32 NumDevices,
3814
3814
void (*PFnNotify)(pi_program Program, void *UserData),
3815
3815
void *UserData, pi_program *RetProgram) {
3816
3816
// We only support one device with Level Zero currently.
3817
- pi_device Device = Context->Devices [0 ];
3818
3817
if (NumDevices != 1 ) {
3819
3818
zePrint (" piProgramLink: level_zero supports only one device." );
3820
3819
return PI_INVALID_VALUE;
@@ -3834,7 +3833,13 @@ pi_result piProgramLink(pi_context Context, pi_uint32 NumDevices,
3834
3833
}
3835
3834
3836
3835
// Validate input parameters.
3837
- PI_ASSERT (DeviceList && DeviceList[0 ] == Device, PI_INVALID_DEVICE);
3836
+ PI_ASSERT (DeviceList, PI_INVALID_DEVICE);
3837
+ {
3838
+ auto DeviceEntry =
3839
+ find (Context->Devices .begin (), Context->Devices .end (), DeviceList[0 ]);
3840
+ if (DeviceEntry == Context->Devices .end ())
3841
+ return PI_INVALID_DEVICE;
3842
+ }
3838
3843
PI_ASSERT (!PFnNotify && !UserData, PI_INVALID_VALUE);
3839
3844
if (NumInputPrograms == 0 || InputPrograms == nullptr )
3840
3845
return PI_INVALID_VALUE;
@@ -4017,7 +4022,14 @@ pi_result piProgramBuild(pi_program Program, pi_uint32 NumDevices,
4017
4022
PI_ASSERT (!PFnNotify && !UserData, PI_INVALID_VALUE);
4018
4023
4019
4024
std::scoped_lock Guard (Program->Mutex );
4020
-
4025
+ // Check if device belongs to associated context.
4026
+ PI_ASSERT (Program->Context , PI_INVALID_PROGRAM);
4027
+ {
4028
+ auto DeviceEntry = find (Program->Context ->Devices .begin (),
4029
+ Program->Context ->Devices .end (), DeviceList[0 ]);
4030
+ if (DeviceEntry == Program->Context ->Devices .end ())
4031
+ return PI_INVALID_VALUE;
4032
+ }
4021
4033
// It is legal to build a program created from either IL or from native
4022
4034
// device code.
4023
4035
if (Program->State != _pi_program::IL &&
0 commit comments