@@ -82,6 +82,8 @@ int main( int argc, char *argv[] )
8282 ze_device_handle_t pDevice = nullptr ;
8383 uint32_t driverCount = 0 ;
8484 zel_tracer_handle_t tracer = nullptr ;
85+ std::vector<ze_driver_handle_t > drivers;
86+ std::vector<std::vector<ze_device_handle_t >> devices_per_driver;
8587 if ( init_ze (legacy_init, driverCount, driverTypeDesc) )
8688 {
8789
@@ -106,7 +108,6 @@ int main( int argc, char *argv[] )
106108 }
107109 }
108110
109- std::vector<ze_driver_handle_t > drivers;
110111 if (legacy_init) {
111112 status = zeDriverGet (&driverCount, nullptr );
112113 if (status != ZE_RESULT_SUCCESS) {
@@ -131,87 +132,98 @@ int main( int argc, char *argv[] )
131132
132133 for ( uint32_t driver = 0 ; driver < driverCount; ++driver )
133134 {
135+ std::vector<ze_device_handle_t > devices;
134136 std::cout << " Driver # " << driver << " \n " ;
135137 pDriver = drivers[driver];
136138 pDevice = findDevice ( pDriver, type );
139+ if (pDevice) {
140+ devices.push_back (pDevice);
141+ }
142+ devices_per_driver.push_back (devices);
137143 }
138144 }
139145
140- if ( !pDevice )
146+ if ( devices_per_driver. empty () || drivers. empty () )
141147 {
142148 std::cout << " Did NOT find matching " << to_string (type) <<" device!" << " \n " ;
143149 return -1 ;
144150 }
145151
152+ for (size_t driver_idx = 0 ; driver_idx < drivers.size (); ++driver_idx) {
153+ pDriver = drivers[driver_idx];
154+ for (size_t device_idx = 0 ; device_idx < devices_per_driver[driver_idx].size (); ++device_idx) {
155+ pDevice = devices_per_driver[driver_idx][device_idx];
156+ std::cout << " Executing on Driver #" << driver_idx << " , Device #" << device_idx << std::endl;
157+ // Create the context
158+ ze_context_handle_t context;
159+ ze_context_desc_t context_desc = {};
160+ context_desc.stype = ZE_STRUCTURE_TYPE_CONTEXT_DESC;
161+ status = zeContextCreate (pDriver, &context_desc, &context);
162+ if (status != ZE_RESULT_SUCCESS) {
163+ std::cout << " zeContextCreate Failed with return code: " << to_string (status) << std::endl;
164+ continue ;
165+ }
146166
147- // Create the context
148- ze_context_handle_t context;
149- ze_context_desc_t context_desc = {};
150- context_desc.stype = ZE_STRUCTURE_TYPE_CONTEXT_DESC;
151- status = zeContextCreate (pDriver, &context_desc, &context);
152- if (status != ZE_RESULT_SUCCESS) {
153- std::cout << " zeContextCreate Failed with return code: " << to_string (status) << std::endl;
154- exit (1 );
155- }
156-
157- // Create an immediate command list for direct submission
158- ze_command_queue_desc_t altdesc = {};
159- altdesc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
160- ze_command_list_handle_t command_list = {};
161- status = zeCommandListCreateImmediate (context, pDevice, &altdesc, &command_list);
162- if (status != ZE_RESULT_SUCCESS) {
163- std::cout << " zeCommandListCreateImmediate Failed with return code: " << to_string (status) << std::endl;
164- exit (1 );
165- }
167+ // Create an immediate command list for direct submission
168+ ze_command_queue_desc_t altdesc = {};
169+ altdesc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
170+ ze_command_list_handle_t command_list = {};
171+ status = zeCommandListCreateImmediate (context, pDevice, &altdesc, &command_list);
172+ if (status != ZE_RESULT_SUCCESS) {
173+ std::cout << " zeCommandListCreateImmediate Failed with return code: " << to_string (status) << std::endl;
174+ continue ;
175+ }
166176
167- // Create an event to be signaled by the device
168- ze_event_pool_desc_t ep_desc = {};
169- ep_desc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;
170- ep_desc.count = 1 ;
171- ep_desc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
172- ze_event_desc_t ev_desc = {};
173- ev_desc.stype = ZE_STRUCTURE_TYPE_EVENT_DESC;
174- ev_desc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
175- ev_desc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
176- ze_event_handle_t event;
177- ze_event_pool_handle_t event_pool;
178-
179- status = zeEventPoolCreate (context, &ep_desc, 1 , &pDevice, &event_pool);
180- if (status != ZE_RESULT_SUCCESS) {
181- std::cout << " zeEventPoolCreate Failed with return code: " << to_string (status) << std::endl;
182- exit ( 1 ) ;
183- }
177+ // Create an event to be signaled by the device
178+ ze_event_pool_desc_t ep_desc = {};
179+ ep_desc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;
180+ ep_desc.count = 1 ;
181+ ep_desc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
182+ ze_event_desc_t ev_desc = {};
183+ ev_desc.stype = ZE_STRUCTURE_TYPE_EVENT_DESC;
184+ ev_desc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
185+ ev_desc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
186+ ze_event_handle_t event;
187+ ze_event_pool_handle_t event_pool;
188+
189+ status = zeEventPoolCreate (context, &ep_desc, 1 , &pDevice, &event_pool);
190+ if (status != ZE_RESULT_SUCCESS) {
191+ std::cout << " zeEventPoolCreate Failed with return code: " << to_string (status) << std::endl;
192+ continue ;
193+ }
184194
185- status = zeEventCreate (event_pool, &ev_desc, &event);
186- if (status != ZE_RESULT_SUCCESS) {
187- std::cout << " zeEventCreate Failed with return code: " << to_string (status) << std::endl;
188- exit ( 1 ) ;
189- }
195+ status = zeEventCreate (event_pool, &ev_desc, &event);
196+ if (status != ZE_RESULT_SUCCESS) {
197+ std::cout << " zeEventCreate Failed with return code: " << to_string (status) << std::endl;
198+ continue ;
199+ }
190200
191- // signal the event from the device and wait for completion
192- zeCommandListAppendSignalEvent (command_list, event);
193- zeEventHostSynchronize (event, UINT64_MAX );
194- std::cout << " Congratulations, the device completed execution!\n " ;
195-
196- zeContextDestroy (context);
197- zeCommandListDestroy (command_list);
198- zeEventDestroy (event);
199- zeEventPoolDestroy (event_pool);
200-
201- if (tracing_enabled) {
202- status = zelTracerDestroy (tracer);
203- if (status != ZE_RESULT_SUCCESS) {
204- std::cout << " zelTracerDestroy Failed with return code: " << to_string (status) << std::endl;
205- exit (1 );
206- }
207- }
201+ // signal the event from the device and wait for completion
202+ zeCommandListAppendSignalEvent (command_list, event);
203+ zeEventHostSynchronize (event, UINT64_MAX );
204+ std::cout << " Congratulations, Executing on Driver # " << driver_idx << " , Device # " << device_idx << " completed execution!" << std::endl ;
205+
206+ zeContextDestroy (context);
207+ zeCommandListDestroy (command_list);
208+ zeEventDestroy (event);
209+ zeEventPoolDestroy (event_pool);
210+
211+ if (tracing_enabled) {
212+ status = zelTracerDestroy (tracer);
213+ if (status != ZE_RESULT_SUCCESS) {
214+ std::cout << " zelTracerDestroy Failed with return code: " << to_string (status) << std::endl;
215+ exit (1 );
216+ }
217+ }
208218
209- if (tracing_runtime_enabled) {
210- std::cout << " Disable Tracing Layer after init" << std::endl;
211- status = zelDisableTracingLayer ();
212- if (status != ZE_RESULT_SUCCESS) {
213- std::cout << " zelDisableTracingLayer Failed with return code: " << to_string (status) << std::endl;
214- exit (1 );
219+ if (tracing_runtime_enabled) {
220+ std::cout << " Disable Tracing Layer after init" << std::endl;
221+ status = zelDisableTracingLayer ();
222+ if (status != ZE_RESULT_SUCCESS) {
223+ std::cout << " zelDisableTracingLayer Failed with return code: " << to_string (status) << std::endl;
224+ exit (1 );
225+ }
226+ }
215227 }
216228 }
217229
0 commit comments