Skip to content

Commit 14aabdd

Browse files
authored
[SYCL] Throw exception when device does not support queries in sycl_ext_intel_device_info (#14788)
This PR implements specializations of `get_device_info` function for the queries defined in [sycl_ext_intel_device_info](https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/supported/sycl_ext_intel_device_info.md) so that when a device does not support the corresponding aspect for a query, an exception is thrown with error code set to `errc::feature_not_supported` as stipulated in the extension spec.
1 parent 19880a5 commit 14aabdd

File tree

2 files changed

+153
-8
lines changed

2 files changed

+153
-8
lines changed

sycl/source/detail/device_info.hpp

Lines changed: 152 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,16 +1273,161 @@ template <typename Param>
12731273
typename Param::return_type get_device_info(const DeviceImplPtr &Dev) {
12741274
static_assert(is_device_info_desc<Param>::value,
12751275
"Invalid device information descriptor");
1276-
if (std::is_same<Param,
1277-
sycl::_V1::ext::intel::info::device::free_memory>::value) {
1278-
if (!Dev->has(aspect::ext_intel_free_memory))
1279-
throw exception(
1280-
make_error_code(errc::invalid),
1281-
"The device does not have the ext_intel_free_memory aspect");
1282-
}
12831276
return get_device_info_impl<typename Param::return_type, Param>::get(Dev);
12841277
}
12851278

1279+
template <>
1280+
inline ext::intel::info::device::device_id::return_type
1281+
get_device_info<ext::intel::info::device::device_id>(const DeviceImplPtr &Dev) {
1282+
if (!Dev->has(aspect::ext_intel_device_id))
1283+
throw exception(make_error_code(errc::feature_not_supported),
1284+
"The device does not have the ext_intel_device_id aspect");
1285+
using Param = ext::intel::info::device::device_id;
1286+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1287+
}
1288+
1289+
template <>
1290+
inline ext::intel::info::device::uuid::return_type
1291+
get_device_info<ext::intel::info::device::uuid>(const DeviceImplPtr &Dev) {
1292+
if (!Dev->has(aspect::ext_intel_device_info_uuid))
1293+
throw exception(
1294+
make_error_code(errc::feature_not_supported),
1295+
"The device does not have the ext_intel_device_info_uuid aspect");
1296+
using Param = ext::intel::info::device::uuid;
1297+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1298+
}
1299+
1300+
template <>
1301+
inline ext::intel::info::device::pci_address::return_type
1302+
get_device_info<ext::intel::info::device::pci_address>(
1303+
const DeviceImplPtr &Dev) {
1304+
if (!Dev->has(aspect::ext_intel_pci_address))
1305+
throw exception(
1306+
make_error_code(errc::feature_not_supported),
1307+
"The device does not have the ext_intel_pci_address aspect");
1308+
using Param = ext::intel::info::device::pci_address;
1309+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1310+
}
1311+
1312+
template <>
1313+
inline ext::intel::info::device::gpu_eu_simd_width::return_type
1314+
get_device_info<ext::intel::info::device::gpu_eu_simd_width>(
1315+
const DeviceImplPtr &Dev) {
1316+
if (!Dev->has(aspect::ext_intel_gpu_eu_simd_width))
1317+
throw exception(
1318+
make_error_code(errc::feature_not_supported),
1319+
"The device does not have the ext_intel_gpu_eu_simd_width aspect");
1320+
using Param = ext::intel::info::device::gpu_eu_simd_width;
1321+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1322+
}
1323+
1324+
template <>
1325+
inline ext::intel::info::device::gpu_eu_count::return_type
1326+
get_device_info<ext::intel::info::device::gpu_eu_count>(
1327+
const DeviceImplPtr &Dev) {
1328+
if (!Dev->has(aspect::ext_intel_gpu_eu_count))
1329+
throw exception(
1330+
make_error_code(errc::feature_not_supported),
1331+
"The device does not have the ext_intel_gpu_eu_count aspect");
1332+
using Param = ext::intel::info::device::gpu_eu_count;
1333+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1334+
}
1335+
1336+
template <>
1337+
inline ext::intel::info::device::gpu_slices::return_type
1338+
get_device_info<ext::intel::info::device::gpu_slices>(
1339+
const DeviceImplPtr &Dev) {
1340+
if (!Dev->has(aspect::ext_intel_gpu_slices))
1341+
throw exception(make_error_code(errc::feature_not_supported),
1342+
"The device does not have the ext_intel_gpu_slices aspect");
1343+
using Param = ext::intel::info::device::gpu_slices;
1344+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1345+
}
1346+
1347+
template <>
1348+
inline ext::intel::info::device::gpu_subslices_per_slice::return_type
1349+
get_device_info<ext::intel::info::device::gpu_subslices_per_slice>(
1350+
const DeviceImplPtr &Dev) {
1351+
if (!Dev->has(aspect::ext_intel_gpu_subslices_per_slice))
1352+
throw exception(make_error_code(errc::feature_not_supported),
1353+
"The device does not have the "
1354+
"ext_intel_gpu_subslices_per_slice aspect");
1355+
using Param = ext::intel::info::device::gpu_subslices_per_slice;
1356+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1357+
}
1358+
1359+
template <>
1360+
inline ext::intel::info::device::gpu_eu_count_per_subslice::return_type
1361+
get_device_info<ext::intel::info::device::gpu_eu_count_per_subslice>(
1362+
const DeviceImplPtr &Dev) {
1363+
if (!Dev->has(aspect::ext_intel_gpu_eu_count_per_subslice))
1364+
throw exception(make_error_code(errc::feature_not_supported),
1365+
"The device does not have the "
1366+
"ext_intel_gpu_eu_count_per_subslice aspect");
1367+
using Param = ext::intel::info::device::gpu_eu_count_per_subslice;
1368+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1369+
}
1370+
1371+
template <>
1372+
inline ext::intel::info::device::gpu_hw_threads_per_eu::return_type
1373+
get_device_info<ext::intel::info::device::gpu_hw_threads_per_eu>(
1374+
const DeviceImplPtr &Dev) {
1375+
if (!Dev->has(aspect::ext_intel_gpu_hw_threads_per_eu))
1376+
throw exception(
1377+
make_error_code(errc::feature_not_supported),
1378+
"The device does not have the ext_intel_gpu_hw_threads_per_eu aspect");
1379+
using Param = ext::intel::info::device::gpu_hw_threads_per_eu;
1380+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1381+
}
1382+
1383+
template <>
1384+
inline ext::intel::info::device::max_mem_bandwidth::return_type
1385+
get_device_info<ext::intel::info::device::max_mem_bandwidth>(
1386+
const DeviceImplPtr &Dev) {
1387+
if (!Dev->has(aspect::ext_intel_max_mem_bandwidth))
1388+
throw exception(
1389+
make_error_code(errc::feature_not_supported),
1390+
"The device does not have the ext_intel_max_mem_bandwidth aspect");
1391+
using Param = ext::intel::info::device::max_mem_bandwidth;
1392+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1393+
}
1394+
1395+
template <>
1396+
inline ext::intel::info::device::free_memory::return_type
1397+
get_device_info<ext::intel::info::device::free_memory>(
1398+
const DeviceImplPtr &Dev) {
1399+
if (!Dev->has(aspect::ext_intel_free_memory))
1400+
throw exception(
1401+
make_error_code(errc::feature_not_supported),
1402+
"The device does not have the ext_intel_free_memory aspect");
1403+
using Param = ext::intel::info::device::free_memory;
1404+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1405+
}
1406+
1407+
template <>
1408+
inline ext::intel::info::device::memory_clock_rate::return_type
1409+
get_device_info<ext::intel::info::device::memory_clock_rate>(
1410+
const DeviceImplPtr &Dev) {
1411+
if (!Dev->has(aspect::ext_intel_memory_clock_rate))
1412+
throw exception(
1413+
make_error_code(errc::feature_not_supported),
1414+
"The device does not have the ext_intel_memory_clock_rate aspect");
1415+
using Param = ext::intel::info::device::memory_clock_rate;
1416+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1417+
}
1418+
1419+
template <>
1420+
inline ext::intel::info::device::memory_bus_width::return_type
1421+
get_device_info<ext::intel::info::device::memory_bus_width>(
1422+
const DeviceImplPtr &Dev) {
1423+
if (!Dev->has(aspect::ext_intel_memory_bus_width))
1424+
throw exception(
1425+
make_error_code(errc::feature_not_supported),
1426+
"The device does not have the ext_intel_memory_bus_width aspect");
1427+
using Param = ext::intel::info::device::memory_bus_width;
1428+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1429+
}
1430+
12861431
// Returns the list of all progress guarantees that can be requested for
12871432
// work_groups from the coordination level of root_group when using the device
12881433
// given by Dev. First it calls getProgressGuarantee to get the strongest

sycl/test-e2e/Basic/get_info_aspect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main() {
1717
sycl::device d(sycl::default_selector_v);
1818
size_t mem_free = d.get_info<sycl::ext::intel::info::device::free_memory>();
1919
} catch (const sycl::exception &e) {
20-
assert(e.code() == sycl::errc::invalid);
20+
assert(e.code() == sycl::errc::feature_not_supported);
2121
std::cout << "Expected exception encountered: " << e.what() << std::endl;
2222
failed = false;
2323
}

0 commit comments

Comments
 (0)