@@ -72,6 +72,22 @@ ur_device_handle_t GetDevice(ur_queue_handle_t Queue) {
7272 return Device;
7373}
7474
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+
7591ur_program_handle_t GetProgram (ur_kernel_handle_t Kernel) {
7692 ur_program_handle_t Program{};
7793 [[maybe_unused]] auto Result = getContext ()->urDdiTable .Kernel .pfnGetInfo (
@@ -169,18 +185,20 @@ bool GetDeviceUSMCapability(ur_device_handle_t Device,
169185 return (bool )Flag;
170186}
171187
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 ;
174190 [[maybe_unused]] ur_result_t Result =
175191 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" );
178195
179196 std::vector<ur_device_handle_t > Devices;
180- Devices.resize (PropSize / sizeof ( ur_device_handle_t ) );
197+ Devices.resize (DeviceNum );
181198 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" );
184202
185203 return Devices;
186204}
0 commit comments