@@ -72,6 +72,22 @@ ur_device_handle_t GetDevice(ur_queue_handle_t Queue) {
72
72
return Device;
73
73
}
74
74
75
+ std::vector<ur_device_handle_t > GetDevices (ur_context_handle_t Context) {
76
+ std::vector<ur_device_handle_t > Devices{};
77
+ uint32_t DeviceNum = 0 ;
78
+ [[maybe_unused]] ur_result_t Result;
79
+ Result = getContext ()->urDdiTable .Context .pfnGetInfo (
80
+ Context, UR_CONTEXT_INFO_NUM_DEVICES, sizeof (uint32_t ), &DeviceNum,
81
+ nullptr );
82
+ assert (Result == UR_RESULT_SUCCESS && " getDevices(Context) failed" );
83
+ Devices.resize (DeviceNum);
84
+ Result = getContext ()->urDdiTable .Context .pfnGetInfo (
85
+ Context, UR_CONTEXT_INFO_DEVICES,
86
+ sizeof (ur_device_handle_t ) * DeviceNum, Devices.data (), nullptr );
87
+ assert (Result == UR_RESULT_SUCCESS && " getDevices(Context) failed" );
88
+ return Devices;
89
+ }
90
+
75
91
ur_program_handle_t GetProgram (ur_kernel_handle_t Kernel) {
76
92
ur_program_handle_t Program{};
77
93
[[maybe_unused]] auto Result = getContext ()->urDdiTable .Kernel .pfnGetInfo (
@@ -169,18 +185,20 @@ bool GetDeviceUSMCapability(ur_device_handle_t Device,
169
185
return (bool )Flag;
170
186
}
171
187
172
- std::vector<ur_device_handle_t > GetProgramDevices (ur_program_handle_t Program) {
173
- size_t PropSize ;
188
+ std::vector<ur_device_handle_t > GetDevices (ur_program_handle_t Program) {
189
+ uint32_t DeviceNum = 0 ;
174
190
[[maybe_unused]] ur_result_t Result =
175
191
getContext ()->urDdiTable .Program .pfnGetInfo (
176
- Program, UR_PROGRAM_INFO_DEVICES, 0 , nullptr , &PropSize);
177
- assert (Result == UR_RESULT_SUCCESS);
192
+ Program, UR_PROGRAM_INFO_NUM_DEVICES, sizeof (DeviceNum), &DeviceNum,
193
+ nullptr );
194
+ assert (Result == UR_RESULT_SUCCESS && " getDevices(Program) failed" );
178
195
179
196
std::vector<ur_device_handle_t > Devices;
180
- Devices.resize (PropSize / sizeof ( ur_device_handle_t ) );
197
+ Devices.resize (DeviceNum );
181
198
Result = getContext ()->urDdiTable .Program .pfnGetInfo (
182
- Program, UR_PROGRAM_INFO_DEVICES, PropSize, Devices.data (), nullptr );
183
- assert (Result == UR_RESULT_SUCCESS);
199
+ Program, UR_PROGRAM_INFO_DEVICES,
200
+ DeviceNum * sizeof (ur_device_handle_t ), Devices.data (), nullptr );
201
+ assert (Result == UR_RESULT_SUCCESS && " getDevices(Program) failed" );
184
202
185
203
return Devices;
186
204
}
0 commit comments