1414namespace urinfo {
1515struct app {
1616 bool verbose = false ;
17+ bool linear_ids = true ;
18+ bool ignore_device_selector = false ;
1719 ur_loader_config_handle_t loaderConfig = nullptr ;
1820 std::vector<ur_adapter_handle_t > adapters;
1921 std::unordered_map<ur_adapter_handle_t , std::vector<ur_platform_handle_t >>
@@ -23,6 +25,16 @@ struct app {
2325
2426 app (int argc, const char **argv) {
2527 parseArgs (argc, argv);
28+ if (!ignore_device_selector) {
29+ if (auto device_selector = std::getenv (" ONEAPI_DEVICE_SELECTOR" )) {
30+ std::fprintf (stderr,
31+ " info: Output filtered by ONEAPI_DEVICE_SELECTOR "
32+ " environment variable, which is set to \" %s\" .\n "
33+ " To see all devices, use the "
34+ " --ignore-device-selector CLI option.\n\n " ,
35+ device_selector);
36+ }
37+ }
2638 UR_CHECK (urLoaderConfigCreate (&loaderConfig));
2739 UR_CHECK (urLoaderConfigEnableLayer (loaderConfig,
2840 " UR_LAYER_FULL_VALIDATION" ));
@@ -40,6 +52,10 @@ devices which are currently visible in the local execution environment.
4052 -h, --help show this help message and exit
4153 --version show version number and exit
4254 -v, --verbose print additional information
55+ --no-linear-ids do not show linear device ids
56+ --ignore-device-selector
57+ do not use ONEAPI_DEVICE_SELECTOR to filter list of
58+ devices
4359)" ;
4460 for (int argi = 1 ; argi < argc; argi++) {
4561 std::string_view arg{argv[argi]};
@@ -51,6 +67,10 @@ devices which are currently visible in the local execution environment.
5167 std::exit (0 );
5268 } else if (arg == " -v" || arg == " --verbose" ) {
5369 verbose = true ;
70+ } else if (arg == " --no-linear-ids" ) {
71+ linear_ids = false ;
72+ } else if (arg == " --ignore-device-selector" ) {
73+ ignore_device_selector = true ;
5474 } else {
5575 std::fprintf (stderr, " error: invalid argument: %s\n " ,
5676 argv[argi]);
@@ -65,21 +85,21 @@ devices which are currently visible in the local execution environment.
6585 uint32_t numAdapters = 0 ;
6686 UR_CHECK (urAdapterGet (0 , nullptr , &numAdapters));
6787 if (numAdapters == 0 ) {
68- std::cout << " No adapters found.\n " ;
6988 std::exit (0 );
7089 }
7190 adapters.resize (numAdapters);
7291 UR_CHECK (urAdapterGet (numAdapters, adapters.data (), nullptr ));
7392
93+ auto urDeviceGetFn =
94+ ignore_device_selector ? urDeviceGet : urDeviceGetSelected;
95+
7496 for (size_t adapterIndex = 0 ; adapterIndex < adapters.size ();
7597 adapterIndex++) {
7698 auto adapter = adapters[adapterIndex];
7799 // Enumerate platforms
78100 uint32_t numPlatforms = 0 ;
79101 UR_CHECK (urPlatformGet (&adapter, 1 , 0 , nullptr , &numPlatforms));
80102 if (numPlatforms == 0 ) {
81- std::cout << " No platforms found in adapter " << adapterIndex
82- << " .\n " ;
83103 continue ;
84104 }
85105 adapterPlatformsMap[adapter].resize (numPlatforms);
@@ -92,17 +112,15 @@ devices which are currently visible in the local execution environment.
92112 auto platform = adapterPlatformsMap[adapter][platformIndex];
93113 // Enumerate devices
94114 uint32_t numDevices = 0 ;
95- UR_CHECK (urDeviceGet (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr ,
96- &numDevices));
115+ UR_CHECK (urDeviceGetFn (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr ,
116+ &numDevices));
97117 if (numDevices == 0 ) {
98- std::cout << " No devices found platform " << platformIndex
99- << " .\n " ;
100118 continue ;
101119 }
102120 platformDevicesMap[platform].resize (numDevices);
103- UR_CHECK (urDeviceGet (platform, UR_DEVICE_TYPE_ALL, numDevices,
104- platformDevicesMap[platform].data (),
105- nullptr ));
121+ UR_CHECK (urDeviceGetFn (platform, UR_DEVICE_TYPE_ALL, numDevices,
122+ platformDevicesMap[platform].data (),
123+ nullptr ));
106124 }
107125 }
108126 }
@@ -112,23 +130,37 @@ devices which are currently visible in the local execution environment.
112130 adapterIndex++) {
113131 auto adapter = adapters[adapterIndex];
114132 auto &platforms = adapterPlatformsMap[adapter];
133+ size_t adapter_device_id = 0 ;
134+ std::string adapter_backend = urinfo::getAdapterBackend (adapter);
115135 for (size_t platformIndex = 0 ; platformIndex < platforms.size ();
116136 platformIndex++) {
117137 auto platform = platforms[platformIndex];
118138 auto &devices = platformDevicesMap[platform];
119139 for (size_t deviceIndex = 0 ; deviceIndex < devices.size ();
120140 deviceIndex++) {
121141 auto device = devices[deviceIndex];
122- std::cout << " [adapter(" << adapterIndex << " ,"
123- << urinfo::getAdapterBackend (adapter) << " ):"
124- << " platform(" << platformIndex << " ):"
125- << " device(" << deviceIndex << " ,"
126- << urinfo::getDeviceType (device) << " )] "
127- << urinfo::getPlatformName (platform) << " , "
128- << urinfo::getDeviceName (device) << " "
142+ auto device_type = urinfo::getDeviceType (device);
143+
144+ if (linear_ids) {
145+ std::cout << " [" << adapter_backend << " :"
146+ << device_type << " ]" ;
147+ std::cout << " [" << adapter_backend << " :"
148+ << adapter_device_id << " ]" ;
149+ } else {
150+ std::cout << " [adapter(" << adapterIndex << " ,"
151+ << adapter_backend << " ):"
152+ << " platform(" << platformIndex << " ):"
153+ << " device(" << deviceIndex << " ,"
154+ << device_type << " )]" ;
155+ }
156+
157+ std::cout << " " << urinfo::getPlatformName (platform)
158+ << " , " << urinfo::getDeviceName (device) << " "
129159 << urinfo::getDeviceVersion (device) << " "
130160 << " [" << urinfo::getDeviceDriverVersion (device)
131161 << " ]\n " ;
162+
163+ adapter_device_id++;
132164 }
133165 }
134166 }
0 commit comments