11/*
22 *
3- * Copyright (C) 2019-2023 Intel Corporation
3+ * Copyright (C) 2019-2024 Intel Corporation
44 *
55 * SPDX-License-Identifier: MIT
66 *
@@ -235,6 +235,155 @@ TEST_P(
235235 }
236236}
237237
238+ class zeImmediateCommandListAppendCommandListsExpTests
239+ : public ::testing::Test,
240+ public ::testing::WithParamInterface<CustomExecuteParams> {
241+ protected:
242+ void SetUp () override {
243+ ze_device_handle_t device = lzt::zeDevice::get_instance ()->get_device ();
244+ const ze_driver_handle_t driver = lzt::get_default_driver ();
245+ const ze_context_handle_t context = lzt::get_default_context ();
246+ EXPECT_GT (params.num_command_lists , 0 );
247+
248+ print_cmdqueue_exec (params.num_command_lists , params.sync_timeout );
249+
250+ ze_command_queue_desc_t cmdQueueDesc = {
251+ ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC};
252+ ze_command_list_desc_t cmdListDesc = {ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC};
253+
254+ cmdQueueDesc.ordinal = lzt::getComputeQueueGroupOrdinal (device);
255+
256+ cmdQueueDesc.index = 0 ;
257+ cmdQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
258+
259+ EXPECT_EQ (ZE_RESULT_SUCCESS,
260+ zeCommandListCreateImmediate (context, device, &cmdQueueDesc,
261+ &command_list_immediate));
262+ EXPECT_NE (nullptr , command_list_immediate);
263+
264+ EXPECT_EQ (
265+ ZE_RESULT_SUCCESS,
266+ zeCommandQueueCreate (context, device, &cmdQueueDesc, &command_queue));
267+ EXPECT_NE (nullptr , command_queue);
268+
269+ for (uint32_t i = 0 ; i < buff_size_bytes; i++) {
270+ verification_buffer[i] = lzt::generate_value<uint8_t >(0 , 255 , 0 );
271+ }
272+
273+ for (uint32_t i = 0 ; i < params.num_command_lists ; i++) {
274+
275+ void *host_buffer = nullptr ;
276+ ze_host_mem_alloc_desc_t hostDesc = {};
277+ hostDesc.stype = ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC;
278+ hostDesc.pNext = nullptr ;
279+ hostDesc.flags = 0 ;
280+ EXPECT_EQ (ZE_RESULT_SUCCESS,
281+ zeMemAllocHost (context, &hostDesc, buff_size_bytes, 1 ,
282+ (void **)(&host_buffer)));
283+ EXPECT_NE (nullptr , host_buffer);
284+
285+ uint8_t *char_input = static_cast <uint8_t *>(host_buffer);
286+ for (uint32_t j = 0 ; j < buff_size_bytes; j++) {
287+ char_input[j] = verification_buffer[j];
288+ }
289+
290+ host_buffers.push_back (static_cast <uint8_t *>(host_buffer));
291+
292+ void *deive_buffer = nullptr ;
293+ ze_device_mem_alloc_desc_t deviceDesc = {};
294+ deviceDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
295+ deviceDesc.ordinal = 0 ;
296+ deviceDesc.flags = 0 ;
297+ deviceDesc.pNext = nullptr ;
298+
299+ EXPECT_EQ (ZE_RESULT_SUCCESS,
300+ zeMemAllocDevice (context, &deviceDesc, buff_size_bytes,
301+ buff_size_bytes, device, &deive_buffer));
302+ device_buffers.push_back (static_cast <uint8_t *>(deive_buffer));
303+
304+ ze_command_list_handle_t command_list_regular;
305+ cmdListDesc.commandQueueGroupOrdinal =
306+ lzt::getComputeQueueGroupOrdinal (device);
307+ cmdListDesc.flags = 0 ;
308+ EXPECT_EQ (ZE_RESULT_SUCCESS,
309+ zeCommandListCreate (context, device, &cmdListDesc,
310+ &command_list_regular));
311+ EXPECT_NE (nullptr , command_list_regular);
312+
313+ // Copy from host-allocated to device-allocated memory
314+ EXPECT_EQ (ZE_RESULT_SUCCESS,
315+ zeCommandListAppendMemoryCopy (
316+ command_list_regular, deive_buffer, host_buffer,
317+ buff_size_bytes, nullptr , 0 , nullptr ));
318+
319+ EXPECT_EQ (ZE_RESULT_SUCCESS,
320+ zeCommandListAppendBarrier (command_list_regular, nullptr , 0 ,
321+ nullptr ));
322+
323+ // Copy from device-allocated memory back to host-allocated memory
324+ EXPECT_EQ (ZE_RESULT_SUCCESS,
325+ zeCommandListAppendMemoryCopy (command_list_regular, host_buffer,
326+ deive_buffer, buff_size_bytes,
327+ nullptr , 0 , nullptr ));
328+
329+ EXPECT_EQ (ZE_RESULT_SUCCESS, zeCommandListClose (command_list_regular));
330+ list_of_command_lists.push_back (command_list_regular);
331+ }
332+ }
333+
334+ void TearDown () override {
335+ for (uint32_t i = 0 ; i < params.num_command_lists ; i++) {
336+
337+ EXPECT_EQ (
338+ 0 , memcmp (host_buffers.at (i), verification_buffer, buff_size_bytes));
339+
340+ EXPECT_EQ (ZE_RESULT_SUCCESS,
341+ zeCommandListDestroy (list_of_command_lists.at (i)));
342+ lzt::free_memory (host_buffers.at (i));
343+ lzt::free_memory (device_buffers.at (i));
344+ }
345+ lzt::destroy_command_queue (command_queue);
346+ }
347+
348+ static const uint32_t buff_size_bytes = 12 ;
349+ uint8_t verification_buffer[buff_size_bytes];
350+ CustomExecuteParams params = GetParam();
351+
352+ ze_command_queue_handle_t command_queue = nullptr ;
353+ std::vector<ze_command_list_handle_t > list_of_command_lists;
354+
355+ std::vector<uint8_t *> host_buffers;
356+ std::vector<uint8_t *> device_buffers;
357+
358+ ze_command_list_handle_t command_list_immediate;
359+ };
360+
361+ class zeCommandListImmediateAppendCommandListsExpTestsHostSynchronize
362+ : public zeImmediateCommandListAppendCommandListsExpTests {};
363+
364+ TEST_P (
365+ zeCommandListImmediateAppendCommandListsExpTestsHostSynchronize,
366+ GivenCommandListImmediateAppendCommandListsExpAndSyncUsingCommandListHostSynchronizeThenCallSucceeds) {
367+
368+ auto command_lists_initial = list_of_command_lists;
369+ EXPECT_EQ (ZE_RESULT_SUCCESS,
370+ zeCommandListImmediateAppendCommandListsExp (
371+ command_list_immediate, params.num_command_lists ,
372+ list_of_command_lists.data (), nullptr , 0 , nullptr ));
373+
374+ for (int i = 0 ; i < list_of_command_lists.size (); i++) {
375+ ASSERT_EQ (list_of_command_lists[i], command_lists_initial[i]);
376+ }
377+
378+ ze_result_t sync_status = ZE_RESULT_NOT_READY;
379+ while (sync_status != ZE_RESULT_SUCCESS) {
380+ EXPECT_EQ (sync_status, ZE_RESULT_NOT_READY);
381+ sync_status = zeCommandListHostSynchronize (command_list_immediate,
382+ params.sync_timeout );
383+ std::this_thread::yield ();
384+ }
385+ }
386+
238387CustomExecuteParams synchronize_test_input[] = {{1 , 0 },
239388 {2 , UINT32_MAX >> 30 },
240389 {3 , UINT32_MAX >> 28 },
@@ -254,6 +403,12 @@ INSTANTIATE_TEST_SUITE_P(TestIncreasingNumberCommandListsWithSynchronize,
254403 zeCommandQueueExecuteCommandListTestsSynchronize,
255404 testing::ValuesIn (synchronize_test_input));
256405
406+ INSTANTIATE_TEST_SUITE_P (
407+ TestIncreasingNumberCommandListImmediateAppendCommandListsExpWithSynchronize,
408+ zeCommandListImmediateAppendCommandListsExpTestsHostSynchronize,
409+ testing::ValuesIn (synchronize_test_input));
410+
411+
257412class zeCommandQueueExecuteCommandListTestsFence
258413 : public zeCommandQueueExecuteCommandListTests {};
259414
0 commit comments