diff --git a/CMakeLists.txt b/CMakeLists.txt index 850edaa..bc9dfad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24") cmake_policy(SET CMP0135 NEW) endif() -set(STACK_VERSION 1.8.0 CACHE STRING "Main project version") +set(STACK_VERSION 1.10.0 CACHE STRING "Main project version") project(npu-linux-driver VERSION ${STACK_VERSION}) set(BUILD_NUMBER "dev-0" CACHE STRING "Build number composed of name and unique number used as driver version") diff --git a/cmake/compiler_flags.cmake b/cmake/compiler_flags.cmake index 74f5300..906f70b 100644 --- a/cmake/compiler_flags.cmake +++ b/cmake/compiler_flags.cmake @@ -12,7 +12,7 @@ add_compile_options( # Compiler warnings - -Wall -Wextra -Werror -Wno-unused-parameter + -Wall -Wextra -Werror -Wno-unused-parameter -Wvla # Control flow integrity $<$:-fcf-protection=full> # Format string defence diff --git a/cmake/packaging/setup.cmake b/cmake/packaging/setup.cmake index 43cf84c..43c3628 100644 --- a/cmake/packaging/setup.cmake +++ b/cmake/packaging/setup.cmake @@ -42,7 +42,8 @@ if (EXISTS "/etc/debian_version") elseif(EXISTS "/etc/portage") set(PACKAGE_TYPE "ebuild") else() - message(FATAL_ERROR "Unable to detect package type for this system") + message(WARNING "Unable to detect package type for this system") + return() endif() include(${CMAKE_CURRENT_LIST_DIR}/generators/${PACKAGE_TYPE}.cmake) diff --git a/compiler/compiler_source.cmake b/compiler/compiler_source.cmake index 6288124..51c0084 100644 --- a/compiler/compiler_source.cmake +++ b/compiler/compiler_source.cmake @@ -17,10 +17,10 @@ endif() include(ExternalProject) # OpenVINO + NPU Plugin package options -set(OPENVINO_REVISION 7edb05f29487cbf5cc6a7d7ae0a8e228aac763b0) -set(VPUX_PLUGIN_REVISION 1a83394af6430a8a4a29dfc6faf50ed26594e387) -set(VPUX_PLUGIN_RELEASE npu_ud_2024_36_rc1) -set(OPENCV_REVISION 5dc1b39e4c9dfb3339e0b910f7d824a02474ceed) +set(OPENVINO_REVISION 0ebff040fd22daa37612a82fdf930ffce4ebb099) +set(VPUX_PLUGIN_REVISION 4f89b7c000d98bb8f4bf5bb058967bbd02834caa) +set(VPUX_PLUGIN_RELEASE npu_ud_2024_44_rc1) +set(OPENCV_REVISION 78195bc3dfe20b96e721ae8b32d0aa3491755e78) # Directories set(OPENVINO_PREFIX_DIR "${CMAKE_BINARY_DIR}/third_party/openvino") diff --git a/compiler/include/npu_driver_compiler.h b/compiler/include/npu_driver_compiler.h index 2353af2..94e60cd 100644 --- a/compiler/include/npu_driver_compiler.h +++ b/compiler/include/npu_driver_compiler.h @@ -22,8 +22,8 @@ extern "C" { #endif -#define VCL_COMPILER_VERSION_MAJOR 5 -#define VCL_COMPILER_VERSION_MINOR 8 +#define VCL_COMPILER_VERSION_MAJOR 6 +#define VCL_COMPILER_VERSION_MINOR 1 #define VCL_PROFILING_VERSION_MAJOR 2 #define VCL_PROFILING_VERSION_MINOR 0 @@ -69,7 +69,7 @@ typedef struct __vcl_log_handle_t* vcl_log_handle_t; /////////////////////////////////////////////////////////////////////////////// /// @brief Defines type of requested data. -/// Must be in sync with \b _ze_graph_profiling_type_t +/// Must be in sync with _ze_graph_profiling_type_t typedef enum __vcl_profiling_request_type_t { VCL_PROFILING_LAYER_LEVEL = 0x1, VCL_PROFILING_TASK_LEVEL = 0x2, @@ -120,10 +120,9 @@ typedef struct __vcl_profiling_properties_t { typedef enum __vcl_platform_t { VCL_PLATFORM_UNKNOWN = -1, - VCL_PLATFORM_VPU3700, ///< VPU3700 - VCL_PLATFORM_VPU3720, ///< NPU3720 - VCL_PLATFORM_VPU4000, ///< NPU4000 - + VCL_PLATFORM_VPU3700 = 0, ///< VPU3700 + VCL_PLATFORM_VPU3720 = 1, ///< VPU3720 + VCL_PLATFORM_VPU4000 = 2, ///< VPU4000 } vcl_platform_t; /////////////////////////////////////////////////////////////////////////////// @@ -164,6 +163,23 @@ typedef struct __vcl_executable_desc_t { uint64_t optionsSize; ///< Size of options } vcl_executable_desc_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Defines query description to be passed during query network creation +/// +/// Format of modelIRData (defined in L0 adaptor): +/// 1. API version : vcl_version_info_t +/// 2. Num of data elements (now only xml + weights = 2) : uint32_t +/// 3. Size of data 1 (xml) : uint64_t +/// 4. Data 1 : $2 bytes +/// 5. Size of data 2 (weights) : uint64_t +/// 6. Data 2 : $4 bytes +typedef struct __vcl_query_desc_t { + const uint8_t* modelIRData; + uint64_t modelIRSize; ///< Size of modelIRData + const char* options; ///< Compiler config options + uint64_t optionsSize; ///< Size of options +} vcl_query_desc_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Defines input that is required to create profiling handler typedef struct __vcl_profiling_input_t { @@ -196,8 +212,8 @@ VCL_APIEXPORT vcl_result_t VCL_APICALL vclCompilerGetProperties(vcl_compiler_han /////////////////////////////////////////////////////////////////////////////// /// @brief Create an querynetwork object and return the handle -VCL_APIEXPORT vcl_result_t VCL_APICALL vclQueryNetworkCreate(vcl_compiler_handle_t compiler, uint8_t* modelIR, - uint64_t modelIRSize, vcl_query_handle_t* query); +VCL_APIEXPORT vcl_result_t VCL_APICALL vclQueryNetworkCreate(vcl_compiler_handle_t compiler, vcl_query_desc_t desc, + vcl_query_handle_t* query); /////////////////////////////////////////////////////////////////////////////// /// @brief Retrieve result of query network @@ -214,6 +230,16 @@ VCL_APIEXPORT vcl_result_t VCL_APICALL vclQueryNetworkDestroy(vcl_query_handle_t VCL_APIEXPORT vcl_result_t VCL_APICALL vclExecutableCreate(vcl_compiler_handle_t compiler, vcl_executable_desc_t desc, vcl_executable_handle_t* executable); +typedef struct __vcl_allocator_t { + uint8_t* (*allocate)(uint64_t); + void (*deallocate)(uint8_t*); +} vcl_allocator_t; + +VCL_APIEXPORT vcl_result_t VCL_APICALL vclAllocatedExecutableCreate(vcl_compiler_handle_t compiler, + vcl_executable_desc_t desc, + vcl_allocator_t const* allocator, + uint8_t** blobBuffer, uint64_t* blobSize); + /////////////////////////////////////////////////////////////////////////////// /// @brief Destroys the executable and releases the cached blob. VCL_APIEXPORT vcl_result_t VCL_APICALL vclExecutableDestroy(vcl_executable_handle_t executable); diff --git a/firmware/bin/vpu_37xx_v0.0.bin b/firmware/bin/vpu_37xx_v0.0.bin index 61d30df..6195ce5 100644 --- a/firmware/bin/vpu_37xx_v0.0.bin +++ b/firmware/bin/vpu_37xx_v0.0.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d0639a72240b89d37e827d89edb3f13f0c995a5b7d8a28e5e48ca326bf4effad -size 2485040 +oid sha256:2600c098d22d49531edd263c6720e9e385d68ffbd1c87f36d7db86dbf381328a +size 2428000 diff --git a/firmware/bin/vpu_40xx_v0.0.bin b/firmware/bin/vpu_40xx_v0.0.bin index 1754db5..7bdf024 100755 Binary files a/firmware/bin/vpu_40xx_v0.0.bin and b/firmware/bin/vpu_40xx_v0.0.bin differ diff --git a/firmware/include/api/vpu_dma_hw_40xx.h b/firmware/include/api/vpu_dma_hw_40xx.h index 1c083f1..16e1cb1 100644 --- a/firmware/include/api/vpu_dma_hw_40xx.h +++ b/firmware/include/api/vpu_dma_hw_40xx.h @@ -62,10 +62,11 @@ typedef enum { // Number of dimensions for the dynamic task transfer typedef enum { - DMA_DYN_NUM_DIM_DISABLED = 0, // 1D dynamic task transfer - DMA_DYN_NUM_DIM_2D, // 2D dynamic task transfer - DMA_DYN_NUM_DIM_3D, // 3D dynamic task transfer - DMA_DYN_NUM_DIM_MAX + DMA_DYN_DIM_DISABLED = 0, // No dynamic task dimensionality + DMA_DYN_DIM_2D, // Enable DESCRIPTOR.*_DIM_SIZE[1]/DESCRIPTOR.*_LIST_SIZE to be dynamic + DMA_DYN_DIM_3D, // Enable DESCRIPTOR.*_DIM_SIZE[2] to be dynamic + DMA_DYN_DIM_2D_3D, // Enable both 2D and 3D dynamic task dimensionality + DMA_DYN_DIM_MAX } DmaDynamicDimensions; // Burst Length Encoding @@ -178,6 +179,12 @@ typedef enum { DMA_MODE_MAX, } DmaJobMode; +typedef enum { + DMA_CTRG_0, + DMA_CTRG_1, + DMA_CTRG_MAX, +} DmaCtrgEnum; + #pragma pack(push, 1) #define DMA_L2CACHE_ALIGNMENT (32) // Descriptors must be 32-byte aligned @@ -387,7 +394,9 @@ typedef struct ALIGN_DMA(DMA_L2CACHE_ALIGNMENT) { uint16_t task_dyn_id; // Dynamic task phase ID uint16_t rsvd8; // Reserved uint32_t task_dyn_addr; // Dynamic Task address - uint64_t pad[2]; // Padding to make all descriptors 32-Byte aligned + uint32_t ptr_wr_addr; // Address used to write the Task Descriptor pointer + uint32_t rsvd9; // Reserved + uint64_t pad[1]; // Padding to make all descriptors 32-Byte aligned } DmaDescriptor; static_assert(sizeof(DmaDescriptor) == 192, "DmaDescriptor size != 192"); diff --git a/firmware/include/api/vpu_jsm_api.h b/firmware/include/api/vpu_jsm_api.h index c5b773d..69affd5 100644 --- a/firmware/include/api/vpu_jsm_api.h +++ b/firmware/include/api/vpu_jsm_api.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: MIT */ /* - * Copyright (c) 2020-2023, Intel Corporation. + * Copyright (c) 2020-2024, Intel Corporation. */ /** @@ -22,7 +22,7 @@ /* * Minor version changes when API backward compatibility is preserved. */ -#define VPU_JSM_API_VER_MINOR 23 +#define VPU_JSM_API_VER_MINOR 25 /* * API header changed (field names, documentation, formatting) but API itself has not been changed @@ -74,6 +74,7 @@ #define VPU_JSM_STATUS_MVNCI_INTERNAL_ERROR 0xCU /* Job status returned when the job was preempted mid-inference */ #define VPU_JSM_STATUS_PREEMPTED_MID_INFERENCE 0xDU +#define VPU_JSM_STATUS_MVNCI_CONTEXT_VIOLATION_HW 0xEU /* * Host <-> VPU IPC channels. @@ -88,21 +89,23 @@ */ enum { /* - * Null sumbmission mask. - * When set, batch buffer's commands are not processed but returned as successful immediately, except fences and - * timestamps. Used for testing and profiling purposes. + * Null submission mask. + * When set, batch buffer's commands are not processed but returned as + * successful immediately, except fences and timestamps. * When cleared, batch buffer's commands are processed normally. + * Used for testing and profiling purposes. */ VPU_JOB_FLAGS_NULL_SUBMISSION_MASK = (1 << 0U), /* * Inline command mask. * When set, the object in job queue is an inline command (see struct vpu_inline_cmd below). - * When cleared, the object in job queue is an engine job (see struct vpu_job below). + * When cleared, the object in job queue is a job (see struct vpu_job below). */ VPU_JOB_FLAGS_INLINE_CMD_MASK = (1 << 1U), /* * VPU private data mask. - * Reserved for the VPU to store private data about the job (or inline command) while being processed. + * Reserved for the VPU to store private data about the job (or inline command) + * while being processed. */ VPU_JOB_FLAGS_PRIVATE_DATA_MASK = 0xFFFF0000U }; @@ -113,19 +116,21 @@ enum { enum { /* * No job done notification mask. - * When set, indicates that no job done notification should be sent for any job from this queue. - * When cleared, indicates that job done notification should be sent for every job completed from this queue. + * When set, indicates that no job done notification should be sent for any + * job from this queue. When cleared, indicates that job done notification + * should be sent for every job completed from this queue. */ VPU_JOB_QUEUE_FLAGS_NO_JOB_DONE_MASK = (1 << 0U), /* * Native fence usage mask. - * When set, indicates that job queue uses native fences (as inline commands in job queue). Such queues may also use - * legacy fences (as commands in batch buffers). + * When set, indicates that job queue uses native fences (as inline commands + * in job queue). Such queues may also use legacy fences (as commands in batch buffers). * When cleared, indicates the job queue only uses legacy fences. - * NOTE: For queues using native fences, VPU expects that all jobs in the queue are immediately followed by an - * inline command object. This object is expected to be a fence signal command in most cases, but can also be a NOP - * in case the host does not need per-job fence signalling. Other inline commands objects can be inserted between - * "job and inline command" pairs. + * NOTE: For queues using native fences, VPU expects that all jobs in the queue + * are immediately followed by an inline command object. This object is expected + * to be a fence signal command in most cases, but can also be a NOP in case the host + * does not need per-job fence signalling. Other inline commands objects can be + * inserted between "job and inline command" pairs. */ VPU_JOB_QUEUE_FLAGS_USE_NATIVE_FENCE_MASK = (1 << 1U), @@ -166,7 +171,7 @@ enum { /* * vpu_jsm_engine_reset_context flag definitions */ -#define VPU_ENGINE_RESET_CONTEXT_FLAG_COLLATERAL_DAMAGE_MASK (1 << 0) +#define VPU_ENGINE_RESET_CONTEXT_FLAG_COLLATERAL_DAMAGE_MASK (1 << 0U) #define VPU_ENGINE_RESET_CONTEXT_HANG_PRIMARY_CAUSE 0 #define VPU_ENGINE_RESET_CONTEXT_COLLATERAL_DAMAGE 1 @@ -187,18 +192,19 @@ enum { /* * Fence wait. * VPU waits for the fence current value to reach monitored value. - * Fence wait operations are executed upon job dispatching. While waiting for the fence to be satisfied, VPU blocks - * fetching of the next objects in the queue. Jobs present in the queue prior to the fence wait object may be processed + * Fence wait operations are executed upon job dispatching. While waiting for + * the fence to be satisfied, VPU blocks fetching of the next objects in the queue. + * Jobs present in the queue prior to the fence wait object may be processed * concurrently. */ #define VPU_INLINE_CMD_TYPE_FENCE_WAIT 0x1 /* * Fence signal. - * VPU sets the fence current value to the provided value. If new current value is equal to or higher than monitored - * value, VPU sends fence signalled notification to the host. - * Fence signal operations are executed upon completion of all the jobs present in the queue prior to them, and in-order - * relative to each other in the queue. But jobs in-between them may be processed concurrently and may complete - * out-of-order. + * VPU sets the fence current value to the provided value. If new current value + * is equal to or higher than monitored value, VPU sends fence signalled notification + * to the host. Fence signal operations are executed upon completion of all the jobs + * present in the queue prior to them, and in-order relative to each other in the queue. + * But jobs in-between them may be processed concurrently and may complete out-of-order. */ #define VPU_INLINE_CMD_TYPE_FENCE_SIGNAL 0x2 @@ -218,35 +224,37 @@ enum vpu_job_scheduling_priority_band { * Jobs defines the actual workloads to be executed by a given engine. */ struct vpu_job { - volatile uint64_t batch_buf_addr; /**< Address of VPU commands batch buffer */ - volatile uint32_t job_id; /**< Job ID */ - volatile uint32_t flags; /**< Flags bit field, see VPU_JOB_FLAGS_* above */ - union { - struct { - /** - * Doorbell ring timestamp taken by KMD from SoC's global system clock, in microseconds. - * NPU can convert this value to its own fixed clock's timebase, to match other profiling timestamps. - */ - volatile uint64_t doorbell_timestamp; - volatile uint64_t host_tracking_id; /**< Extra id for job tracking, used only in the firmware perf traces */ - }; - struct { - volatile uint64_t root_page_table_addr; /**< Address of root page table to use for this job */ - volatile uint64_t root_page_table_update_counter; /**< Page tables update events counter */ - }; - }; - volatile uint64_t primary_preempt_buf_addr; /**< Address of the primary preemption buffer to use for this job */ - volatile uint32_t primary_preempt_buf_size; /**< Size of the primary preemption buffer to use for this job */ - volatile uint32_t secondary_preempt_buf_size; /**< Size of secondary preemption buffer to use for this job */ - volatile uint64_t secondary_preempt_buf_addr; /**< Address of secondary preemption buffer to use for this job */ + /**< Address of VPU commands batch buffer */ + volatile uint64_t batch_buf_addr; + /**< Job ID */ + volatile uint32_t job_id; + /**< Flags bit field, see VPU_JOB_FLAGS_* above */ + volatile uint32_t flags; + /** + * Doorbell ring timestamp taken by KMD from SoC's global system clock, in + * microseconds. NPU can convert this value to its own fixed clock's timebase, + * to match other profiling timestamps. + */ + volatile uint64_t doorbell_timestamp; + /**< Extra id for job tracking, used only in the firmware perf traces */ + volatile uint64_t host_tracking_id; + /**< Address of the primary preemption buffer to use for this job */ + volatile uint64_t primary_preempt_buf_addr; + /**< Size of the primary preemption buffer to use for this job */ + volatile uint32_t primary_preempt_buf_size; + /**< Size of secondary preemption buffer to use for this job */ + volatile uint32_t secondary_preempt_buf_size; + /**< Address of secondary preemption buffer to use for this job */ + volatile uint64_t secondary_preempt_buf_addr; uint64_t reserved_0; }; typedef struct vpu_job vpu_job_t; /* * Inline command format. - * Inline commands are the commands executed at scheduler level (typically, synchronization directives). - * Inline command and job objects must be of the same size and have flags field at same offset. + * Inline commands are the commands executed at scheduler level (typically, + * synchronization directives). Inline command and job objects must be of + * the same size and have flags field at same offset. */ struct vpu_inline_cmd { uint64_t reserved_0; @@ -269,8 +277,8 @@ struct vpu_inline_cmd { /* User VA of the log buffer in which to add log entry on completion. */ volatile uint64_t log_buffer_va; } fence; - /* Other commands do not have a payload. Payload definition for future inline commands can be inserted here. */ - /* Ensure total size of vpu_inline_cmd structure is 64B, like vpu_job structure. */ + /* Other commands do not have a payload. */ + /* Payload definition for future inline commands can be inserted here. */ uint64_t reserved_1[6]; } payload; }; @@ -336,7 +344,7 @@ enum vpu_trace_entity_type { struct vpu_hws_log_buffer_header { /* Written by VPU after adding a log entry. Initialised by host to 0. */ uint32_t first_free_entry_index; - /* Incremented by VPU every time the VPU overwrites the 0th entry; initialised by host to 0. */ + /* Incremented by VPU every time the VPU writes the 0th entry; initialised by host to 0. */ uint32_t wraparound_count; /* * This is the number of buffers that can be stored in the log buffer provided by the host. @@ -407,7 +415,10 @@ struct vpu_hws_native_fence_log_entry { /* Operation type, see enum vpu_hws_native_fence_log_op. */ uint64_t op_type; uint64_t reserved_0; - /* VPU_HWS_NATIVE_FENCE_LOG_OP_WAIT_UNBLOCKED only: Timestamp at which fence wait was started (in NPU SysTime). */ + /* + * VPU_HWS_NATIVE_FENCE_LOG_OP_WAIT_UNBLOCKED only: Timestamp at which fence + * wait was started (in NPU SysTime). + */ uint64_t fence_wait_start_ts; uint64_t reserved_1; /* Timestamp at which fence operation was completed (in NPU SysTime). */ @@ -526,7 +537,7 @@ enum vpu_ipc_msg_type { /* IPC Host -> Device, General commands */ VPU_IPC_MSG_GENERAL_CMD = 0x1200, - VPU_IPC_MSG_BLOB_DEINIT = VPU_IPC_MSG_GENERAL_CMD, + VPU_IPC_MSG_BLOB_DEINIT_DEPRECATED = VPU_IPC_MSG_GENERAL_CMD, /** * Control dyndbg behavior by executing a dyndbg command; equivalent to * Linux command: `echo '' > /dynamic_debug/control`. @@ -634,7 +645,7 @@ enum vpu_ipc_msg_type { /** Response to VPU_IPC_MSG_DYNDBG_CONTROL. */ VPU_IPC_MSG_DYNDBG_CONTROL_RSP = 0x2301, /** - * Acknowledgement of completion of the save procedure initiated by + * Acknowledgment of completion of the save procedure initiated by * VPU_IPC_MSG_PWR_D0I3_ENTER */ VPU_IPC_MSG_PWR_D0I3_ENTER_DONE = 0x2302, @@ -818,12 +829,6 @@ struct vpu_jsm_metric_streamer_update { }; typedef struct vpu_jsm_metric_streamer_update vpu_jsm_metric_streamer_update_t; -struct vpu_ipc_msg_payload_blob_deinit { - /* 64-bit unique ID for the blob to be de-initialized. */ - uint64_t blob_id; -}; -typedef struct vpu_ipc_msg_payload_blob_deinit vpu_ipc_msg_payload_blob_deinit_t; - struct vpu_ipc_msg_payload_job_done { /* Engine to which the job was submitted. */ uint32_t engine_idx; @@ -940,12 +945,6 @@ struct vpu_ipc_msg_payload_get_power_level_count_done { }; typedef struct vpu_ipc_msg_payload_get_power_level_count_done vpu_ipc_msg_payload_get_power_level_count_done_t; -struct vpu_ipc_msg_payload_blob_deinit_done { - /* 64-bit unique ID for the blob de-initialized. */ - uint64_t blob_id; -}; -typedef struct vpu_ipc_msg_payload_blob_deinit_done vpu_ipc_msg_payload_blob_deinit_done_t; - /* HWS priority band setup request / response */ struct vpu_ipc_msg_payload_hws_priority_band_setup { /* @@ -1113,9 +1112,7 @@ struct vpu_ipc_msg_payload_hws_set_scheduling_log { */ uint64_t notify_index; /* - * Enable extra events to be output to log for debug of scheduling algorithm. - * Interpreted by VPU as a boolean to enable or disable, expected values are - * 0 and 1. + * Field is now deprecated, will be removed when KMD is updated to support removal */ uint32_t enable_extra_events; /* Zero Padding */ @@ -1491,7 +1488,6 @@ union vpu_ipc_msg_payload { struct vpu_jsm_metric_streamer_start metric_streamer_start; struct vpu_jsm_metric_streamer_stop metric_streamer_stop; struct vpu_jsm_metric_streamer_update metric_streamer_update; - struct vpu_ipc_msg_payload_blob_deinit blob_deinit; struct vpu_ipc_msg_payload_ssid_release ssid_release; struct vpu_jsm_hws_register_db hws_register_db; struct vpu_ipc_msg_payload_job_done job_done; @@ -1503,7 +1499,6 @@ union vpu_ipc_msg_payload { struct vpu_ipc_msg_payload_query_engine_hb_done query_engine_hb_done; struct vpu_ipc_msg_payload_get_power_level_count_done get_power_level_count_done; struct vpu_jsm_metric_streamer_done metric_streamer_done; - struct vpu_ipc_msg_payload_blob_deinit_done blob_deinit_done; struct vpu_ipc_msg_payload_trace_config trace_config; struct vpu_ipc_msg_payload_trace_capability_rsp trace_capability; struct vpu_ipc_msg_payload_trace_get_name trace_get_name; diff --git a/firmware/include/api/vpu_jsm_job_cmd_api.h b/firmware/include/api/vpu_jsm_job_cmd_api.h index 36e1516..c64c37b 100644 --- a/firmware/include/api/vpu_jsm_job_cmd_api.h +++ b/firmware/include/api/vpu_jsm_job_cmd_api.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: MIT */ /* - * Copyright (c) 2021-2023, Intel Corporation. + * Copyright (c) 2021-2024, Intel Corporation. */ /** @@ -20,7 +20,7 @@ * Minor version changes when API backward compatibility is preserved. * Resets to 0 if Major version is incremented. */ -#define VPU_JSM_JOB_CMD_API_VER_MINOR 5 +#define VPU_JSM_JOB_CMD_API_VER_MINOR 6 /* * API header changed (field names, documentation, formatting) but API itself has not been changed @@ -73,11 +73,11 @@ enum vpu_cmd_type { VPU_CMD_BARRIER = 0x0103, VPU_CMD_METRIC_QUERY_BEGIN = 0x0104, VPU_CMD_METRIC_QUERY_END = 0x0105, + VPU_CMD_MEMORY_FILL = 0x0202, /** Implemented by Copy Engine */ VPU_CMD_COPY_SYSTEM_TO_LOCAL = 0x0200, VPU_CMD_COPY_LOCAL_TO_SYSTEM = 0x0201, - VPU_CMD_MEMORY_FILL = 0x0202, VPU_CMD_COPY_SYSTEM_TO_SYSTEM = 0x0203, /** Implemented by Compute Engine */ @@ -85,8 +85,8 @@ enum vpu_cmd_type { VPU_CMD_JIT_MAPPED_INFERENCE_EXECUTE = 0x0301, VPU_CMD_COPY_LOCAL_TO_LOCAL = 0x0302, VPU_CMD_CLEAR_BUFFER = 0x0303, - VPU_CMD_OV_BLOB_INITIALIZE = 0x0304, - VPU_CMD_OV_BLOB_EXECUTE = 0x0305, + VPU_CMD_OV_BLOB_INITIALIZE_DEPRECATED = 0x0304, + VPU_CMD_OV_BLOB_EXECUTE_DEPRECATED = 0x0305, VPU_CMD_INFERENCE_EXECUTE = 0x0306, VPU_CMD_DXIL_COPY = 0x0307 }; @@ -160,32 +160,6 @@ typedef struct vpu_cmd_resource_descriptor_table { uint32_t reserved_0; /**< Unused */ } vpu_cmd_resource_descriptor_table_t; -/** - * @brief Copy command descriptor on VPU 30xx - * - * @see VPU_CMD_COPY_SYSTEM_TO_LOCAL - * @see VPU_CMD_COPY_LOCAL_TO_SYSTEM - * @see VPU_CMD_COPY_SYSTEM_TO_SYSTEM - * @see VPU_CMD_COPY_LOCAL_TO_LOCAL - */ -typedef struct vpu_cmd_copy_descriptor_30xx { - /** - * COPY_SYSTEM_TO_LOCAL: Host DDR, - * COPY_LOCAL_TO_SYSTEM/COPY_LOCAL_TO_LOCAL: VPU DDR - 16 byte aligned - */ - uint64_t src_address; - /** - * COPY_SYSTEM_TO_LOCAL/COPY_LOCAL_TO_LOCAL: VPU DDR, - * COPY_SYSTEM_TO_LOCAL: Host DDR - 16 byte aligned - */ - uint64_t dst_address; - /** Copy Size in bytes - multiple of 16 bytes */ - uint32_t size; - /** Padding for 64-byte alignment */ - uint32_t reserved_0[11]; -} vpu_cmd_copy_descriptor_30xx_t; -typedef vpu_cmd_copy_descriptor_30xx_t vpu_cmd_copy_descriptor_kmb_t; - /** * @brief Copy command descriptor on VPU 37xx * Note VPU 37xx does not have a LOCAL memory @@ -212,7 +186,6 @@ typedef struct vpu_cmd_copy_descriptor_37xx { uint32_t size; /**< Copy Size in bytes - max 16 MB */ uint32_t reserved_1[7]; /**< Unused */ } vpu_cmd_copy_descriptor_37xx_t; -typedef vpu_cmd_copy_descriptor_37xx_t vpu_cmd_copy_descriptor_mtl_t; /** * @brief Copy command descriptor on VPU 40xx or later @@ -229,7 +202,6 @@ typedef struct vpu_cmd_copy_descriptor_40xx { uint64_t dst_address; /**< Destination address */ uint64_t reserved_3[17]; /**< Unused */ } vpu_cmd_copy_descriptor_40xx_t; -typedef vpu_cmd_copy_descriptor_40xx_t vpu_cmd_copy_descriptor_lnl_t; /** * @brief Command buffer header @@ -287,7 +259,6 @@ typedef struct vpu_cmd_copy_buffer { * @brief Offset in the descriptor heap where the array of copy descriptors start * @see vpu_cmd_copy_descriptor_37xx_t * @see vpu_cmd_copy_descriptor_40xx_t - * @see vpu_cmd_copy_descriptor_30xx_t * @see vpu_cmd_buffer_header_t.descriptor_heap_base_address * NOTE: Resulting address (heap base plus offset) must be aligned on a 64B boundary * to allow proper handling of VPU cache operations. @@ -338,48 +309,6 @@ typedef struct vpu_cmd_dxil { uint32_t reserved_2; /**< Reserved */ } vpu_cmd_dxil_t; -/** - * @brief Parse inference from a blob - * @see VPU_CMD_OV_BLOB_INITIALIZE - */ -typedef struct vpu_cmd_ov_blob_initialize { - vpu_cmd_header_t header; - /** Size of the kernel ASM */ - uint32_t kernel_size; - /** - * Offset from KernelHeapBaseAddress to kernel blob - * NOTE: Resulting address (heap base plus offset) must be aligned on a 64B boundary - * to allow proper handling of VPU cache operations. - */ - uint64_t kernel_offset; - /** Size in bytes of the Init descriptor table - scratch */ - uint32_t desc_table_size; - /** Reserved */ - uint32_t reserved_0; - /** Offset from the base of the descriptor heap */ - uint64_t desc_table_offset; - /** Unique Blob Id */ - uint64_t blob_id; -} vpu_cmd_ov_blob_initialize_t; - -/** - * @brief Run inference on a previously initialized blob. - * @see VPU_CMD_OV_BLOB_EXECUTE - */ -typedef struct vpu_cmd_ov_blob_execute { - vpu_cmd_header_t header; - /** Size in bytes of Exec descriptor table - input, output */ - uint32_t desc_table_size; - /** - * Offset from the base of the descriptor heap - * NOTE: Resulting address (heap base plus offset) must be aligned on a 64B boundary - * to allow proper handling of VPU cache operations. - */ - uint64_t desc_table_offset; - /** Unique Blob id */ - uint64_t blob_id; -} vpu_cmd_ov_blob_execute_t; - typedef struct vpu_cmd_inference_entry { /** Virtual address and size of the host mapped inference */ vpu_cmd_resource_descriptor_t host_mapped_inference; @@ -424,9 +353,9 @@ typedef struct vpu_cmd_timestamp { uint32_t type; /** * Timestamp address - * NOTE: (MTL) - Address must be aligned on a 64B boundary to allow proper handling of + * NOTE: (VPU 37xx) - Address must be aligned on a 64B boundary to allow proper handling of * VPU cache operations. - * (LNL) - Address must be aligned on a 8B boundary as RISC-V facilitates cache-bypass, + * (VPU 40xx) - Address must be aligned on a 8B boundary as RISC-V facilitates cache-bypass, * memory access. */ uint64_t timestamp_address; diff --git a/firmware/include/api/vpu_nnrt_api_37xx.h b/firmware/include/api/vpu_nnrt_api_37xx.h index 2d55f2d..d9604b5 100644 --- a/firmware/include/api/vpu_nnrt_api_37xx.h +++ b/firmware/include/api/vpu_nnrt_api_37xx.h @@ -8,6 +8,7 @@ #include "vpu_nce_hw_37xx.h" #include "vpu_dma_hw_37xx.h" +#include "vpu_pwrmgr_api.h" /* * When a change is made to vpu_nnrt_api_37xx.h that breaks backwards compatibility @@ -28,7 +29,7 @@ */ #define VPU_NNRT_37XX_API_VER_MAJOR 7 #define VPU_NNRT_37XX_API_VER_MINOR 0 -#define VPU_NNRT_37XX_API_VER_PATCH 3 +#define VPU_NNRT_37XX_API_VER_PATCH 4 #define VPU_NNRT_37XX_API_VER ((VPU_NNRT_37XX_API_VER_MAJOR << 16) | VPU_NNRT_37XX_API_VER_MINOR) /* Index in the API version table, same for all HW generations */ @@ -77,9 +78,6 @@ namespace nn_public { -constexpr uint32_t VPU_SCALABILITY_NUM_OF_FREQ = 5; -constexpr uint32_t VPU_SCALABILITY_VALUES_PER_FREQ = 5; - #pragma pack(push, 1) template @@ -337,27 +335,11 @@ static_assert(offsetof(VpuMappedInference, barrier_configs) % 8 == 0, "Alignment static_assert(offsetof(VpuMappedInference, shv_rt_configs) % 4 == 0, "Alignment error"); static_assert(offsetof(VpuMappedInference, reserved1_) % 8 == 0, "Alignment error"); -struct VPU_ALIGNED_STRUCT(8) VpuPerformanceMetrics { - uint32_t freq_base; ///< Base of frequency values used in tables (in MHz). - uint32_t freq_step; ///< Step of frequency for each entry in tables (in MHz). - uint32_t bw_base; ///< Base of bandwidth values used in tables (in MB/s). - uint32_t bw_step; ///< Step of bandwidth values used in tables (in MB/s). - - /// Inner arrays are for different bandwidth values. - /// Outer arrays are for different frequency values. - uint64_t ticks[VPU_SCALABILITY_NUM_OF_FREQ][VPU_SCALABILITY_VALUES_PER_FREQ]; ///< Table of infr. execution time - float scalability[VPU_SCALABILITY_NUM_OF_FREQ][VPU_SCALABILITY_VALUES_PER_FREQ]; ///< Table of infr. scalability - - float activity_factor; ///< Compiler estimated activity factor for the inference. -}; - -static_assert(sizeof(VpuPerformanceMetrics) == 320, "VpuPerformanceMetrics size != 320"); - struct VPU_ALIGNED_STRUCT(8) VpuHostParsedInference { uint64_t reserved; VpuResourceRequirements resource_requirements_; uint8_t pad_[4]; - VpuPerformanceMetrics performance_metrics_; + struct VpuPerformanceMetrics performance_metrics_; VpuTaskReference mapped_; }; diff --git a/firmware/include/api/vpu_nnrt_api_40xx.h b/firmware/include/api/vpu_nnrt_api_40xx.h index 4483c84..4a2fb79 100644 --- a/firmware/include/api/vpu_nnrt_api_40xx.h +++ b/firmware/include/api/vpu_nnrt_api_40xx.h @@ -9,6 +9,7 @@ #include "vpu_nce_hw_40xx.h" #include "vpu_dma_hw_40xx.h" #include "vpu_media_hw.h" +#include "vpu_pwrmgr_api.h" /* * When a change is made to vpu_nnrt_api_40xx.h that breaks backwards compatibility @@ -29,7 +30,7 @@ */ #define VPU_NNRT_40XX_API_VER_MAJOR 11 #define VPU_NNRT_40XX_API_VER_MINOR 4 -#define VPU_NNRT_40XX_API_VER_PATCH 6 +#define VPU_NNRT_40XX_API_VER_PATCH 10 #define VPU_NNRT_40XX_API_VER ((VPU_NNRT_40XX_API_VER_MAJOR << 16) | VPU_NNRT_40XX_API_VER_MINOR) /* Index in the API version table, same for all HW generations */ @@ -80,9 +81,6 @@ namespace nn_public { #pragma pack(push, 1) -constexpr uint32_t VPU_SCALABILITY_NUM_OF_FREQ = 5; -constexpr uint32_t VPU_SCALABILITY_VALUES_PER_FREQ = 5; - template struct VPU_ALIGNED_STRUCT(8) VpuPtr { uint64_t ptr; @@ -152,9 +150,7 @@ struct VPU_ALIGNED_STRUCT(8) VpuTaskBarrierDependency { uint64_t wait_mask_lo_; uint64_t post_mask_hi_; uint64_t post_mask_lo_; - uint8_t group_; - uint8_t mask_; - uint8_t pad_[6]; + uint8_t reserved_[8]; }; static_assert(sizeof(VpuTaskBarrierDependency) == 40, "VpuTaskBarrierDependency size != 40"); @@ -173,29 +169,22 @@ struct VPU_ALIGNED_STRUCT(32) VpuDPUInvariant { VpuDPUInvariantRegisters registers_; VpuTaskBarrierDependency barriers_; VpuTaskSchedulingBarrierConfig barriers_sched_; - uint32_t output_sparsity_offset_; - int32_t hwp_cmx_base_offset_; + uint8_t reserved_[8]; uint16_t variant_count_; uint8_t cluster_; - uint8_t is_cont_conv_; - VpuHWPStatMode dpu_prof_mode; - uint8_t pad_[3]; + uint8_t pad_[5]; }; static_assert(sizeof(VpuDPUInvariant) == 352, "VpuDPUInvariant size != 352"); static_assert(offsetof(VpuDPUInvariant, barriers_) % 8 == 0, "Alignment error"); static_assert(offsetof(VpuDPUInvariant, barriers_sched_) % 4 == 0, "Alignment error"); -static_assert(offsetof(VpuDPUInvariant, output_sparsity_offset_) % 4 == 0, "Alignment error"); +static_assert(offsetof(VpuDPUInvariant, variant_count_) % 2 == 0, "Alignment error"); struct VPU_ALIGNED_STRUCT(32) VpuDPUVariant { VpuDPUVariantRegisters registers_; VpuPtr invariant_; uint32_t invariant_index_; - uint32_t output_sparsity_offset_; - uint32_t weight_table_offset_; - int32_t wload_id_; - uint8_t cluster_; - uint8_t pad_[7]; + uint8_t pad_[20]; }; static_assert(sizeof(VpuDPUVariant) == 224, "VpuDPUVariant size != 224"); @@ -204,8 +193,7 @@ static_assert(offsetof(VpuDPUVariant, invariant_index_) % 4 == 0, "Alignment err struct VPU_ALIGNED_STRUCT(4) VpuResourceRequirements { uint32_t nn_slice_length_; - uint32_t ddr_scratch_length_; - uint8_t reserved[2]; // Reserved due to deprecated member. + uint8_t reserved_[6]; uint8_t nn_slice_count_; uint8_t nn_barriers_; }; @@ -216,8 +204,8 @@ struct VPU_ALIGNED_STRUCT(8) VpuNNShaveRuntimeConfigs { uint64_t reserved; uint64_t runtime_entry; // when useScheduleEmbeddedRt = true this is a windowed address uint64_t act_rt_window_base; - uint32_t stack_frames[VPU_AS_TOTAL]; // UNUSED - to be removed - uint32_t stack_size; // UNUSED - to be removed + uint32_t stack_frames[VPU_AS_TOTAL]; + uint32_t stack_size; uint32_t code_window_buffer_size; uint32_t perf_metrics_mask; uint32_t runtime_version; @@ -244,7 +232,7 @@ struct VPU_ALIGNED_STRUCT(8) VpuActKernelRange { VpuPtr kernel_entry; VpuPtr text_window_base; uint32_t code_size; - uint32_t data_sec_size; + uint8_t reserved_[4]; uint32_t kernel_invo_count; uint8_t pad1_[4]; }; @@ -259,9 +247,7 @@ struct VPU_ALIGNED_STRUCT(32) VpuActKernelInvocation { VpuPtr perf_packet_out; VpuTaskBarrierDependency barriers; VpuTaskSchedulingBarrierConfig barriers_sched; - // The schedule compiler can infer an index if it's needed pre/post inference - // Update: we can/will use the index to virtualize a WI FIFO state in a preemption payload - uint32_t invo_index; + uint8_t reserved_[4]; uint32_t invo_tile; uint32_t kernel_range_index; uint32_t next_aki_wl_addr; @@ -270,7 +256,7 @@ struct VPU_ALIGNED_STRUCT(32) VpuActKernelInvocation { static_assert(sizeof(VpuActKernelInvocation) == 96, "VpuActKernelInvocation size != 96"); static_assert(offsetof(VpuActKernelInvocation, barriers) % 8 == 0, "Alignment error"); static_assert(offsetof(VpuActKernelInvocation, barriers_sched) % 4 == 0, "Alignment error"); -static_assert(offsetof(VpuActKernelInvocation, invo_index) % 4 == 0, "Alignment error"); +static_assert(offsetof(VpuActKernelInvocation, invo_tile) % 4 == 0, "Alignment error"); struct VPU_ALIGNED_STRUCT(16) VpuMediaTask { union VPU_ALIGNED_STRUCT(16) { @@ -342,30 +328,11 @@ static_assert(offsetof(VpuMappedInference, shv_rt_configs) % 8 == 0, "Alignment static_assert(offsetof(VpuMappedInference, hwp_workpoint_cfg_addr) % 8 == 0, "Alignment error"); static_assert(offsetof(VpuMappedInference, managed_inference) % 8 == 0, "Alignment error"); -struct VPU_ALIGNED_STRUCT(8) VpuPerformanceMetrics { - uint32_t freq_base; ///< Base of frequency values used in tables (in MHz). - uint32_t freq_step; ///< Step of frequency for each entry in tables (in MHz). - uint32_t bw_base; ///< Base of bandwidth values used in tables (in MB/s). - uint32_t bw_step; ///< Step of bandwidth values used in tables (in MB/s). - - /// Inner arrays are for different bandwidth values. - /// Outer arrays are for different frequency values. - uint64_t ticks[VPU_SCALABILITY_NUM_OF_FREQ][VPU_SCALABILITY_VALUES_PER_FREQ]; ///< Table of infr. execution time - float scalability[VPU_SCALABILITY_NUM_OF_FREQ][VPU_SCALABILITY_VALUES_PER_FREQ]; ///< Table of infr. scalability - - float activity_factor; ///< Compiler estimated activity factor for the inference. -}; - -static_assert(sizeof(VpuPerformanceMetrics) == 320, "VpuPerformanceMetrics size != 320"); -static_assert(offsetof(VpuPerformanceMetrics, ticks) % 8 == 0, "Alignment error"); -static_assert(offsetof(VpuPerformanceMetrics, scalability) % 4 == 0, "Alignment error"); -static_assert(offsetof(VpuPerformanceMetrics, activity_factor) % 4 == 0, "Alignment error"); - struct VPU_ALIGNED_STRUCT(32) VpuHostParsedInference { uint64_t reserved_; VpuResourceRequirements resource_requirements_; uint8_t pad_[4]; - VpuPerformanceMetrics performance_metrics_; + struct VpuPerformanceMetrics performance_metrics_; VpuTaskReference mapped_; }; diff --git a/firmware/include/api/vpu_pwrmgr_api.h b/firmware/include/api/vpu_pwrmgr_api.h new file mode 100644 index 0000000..17c3e20 --- /dev/null +++ b/firmware/include/api/vpu_pwrmgr_api.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright (c) 2022-2024, Intel Corporation. + */ + +#ifndef VPU_PWRMGR_API_H +#define VPU_PWRMGR_API_H + +#if defined(_MSC_VER) +#define VPU_ALIGNED_STRUCT(alignment) __declspec(align(alignment)) +#elif defined(__GNUC__) || defined(__clang__) +#define VPU_ALIGNED_STRUCT(alignment) __attribute__((aligned(alignment))) +#else +#error Define alignment macro +#endif + +#pragma pack(push, 1) + +#define VPU_SCALABILITY_NUM_OF_FREQ 5 +#define VPU_SCALABILITY_VALUES_PER_FREQ 5 + +struct VPU_ALIGNED_STRUCT(8) VpuPerformanceMetrics { + uint32_t freq_base; ///< Base of frequency values used in tables (in MHz). + uint32_t freq_step; ///< Step of frequency for each entry in tables (in MHz). + uint32_t bw_base; ///< Base of bandwidth values used in tables (in MB/s). + uint32_t bw_step; ///< Step of bandwidth values used in tables (in MB/s). + + /// Inner arrays are for different bandwidth values. + /// Outer arrays are for different frequency values. + uint64_t ticks[VPU_SCALABILITY_NUM_OF_FREQ][VPU_SCALABILITY_VALUES_PER_FREQ]; ///< Table of infr. execution time + float scalability[VPU_SCALABILITY_NUM_OF_FREQ][VPU_SCALABILITY_VALUES_PER_FREQ]; ///< Table of infr. scalability + + float activity_factor; ///< Compiler estimated activity factor for the inference. +}; + +static_assert(sizeof(struct VpuPerformanceMetrics) == 320, "VpuPerformanceMetrics size != 320"); +static_assert(offsetof(struct VpuPerformanceMetrics, ticks) % 8 == 0, "Alignment error"); +static_assert(offsetof(struct VpuPerformanceMetrics, scalability) % 4 == 0, "Alignment error"); +static_assert(offsetof(struct VpuPerformanceMetrics, activity_factor) % 4 == 0, "Alignment error"); + +#pragma pack(pop) + +#endif diff --git a/third_party/level-zero b/third_party/level-zero index fd459f2..24ad9d6 160000 --- a/third_party/level-zero +++ b/third_party/level-zero @@ -1 +1 @@ -Subproject commit fd459f28041c176df23a0b7b791ff20a7689d237 +Subproject commit 24ad9d613a6df5613683f5b70a440cd0a732de7b diff --git a/third_party/level-zero-npu-extensions b/third_party/level-zero-npu-extensions index 518d641..a63155a 160000 --- a/third_party/level-zero-npu-extensions +++ b/third_party/level-zero-npu-extensions @@ -1 +1 @@ -Subproject commit 518d64125521cd0f8c98d65f9a0fb40013e95d15 +Subproject commit a63155ae4e64feaaa6931f4696c2e2e699063875 diff --git a/third_party/vpux_elf b/third_party/vpux_elf index 43c1c32..98f6fc4 160000 --- a/third_party/vpux_elf +++ b/third_party/vpux_elf @@ -1 +1 @@ -Subproject commit 43c1c32447328c688e6295142ab74a6ab150d504 +Subproject commit 98f6fc4e93c0aca2c7620a32bd5c684b515f8532 diff --git a/umd/CMakeLists.txt b/umd/CMakeLists.txt index 35e5914..bfddad8 100644 --- a/umd/CMakeLists.txt +++ b/umd/CMakeLists.txt @@ -36,6 +36,7 @@ set(VPU_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # Enable extra warning and -ftrapv that abort program on signed arithmetic overflow add_compile_options(-Winvalid-pch -Wconversion -Wuninitialized -ftrapv) +add_compile_options(-fvisibility=hidden -fvisibility-inlines-hidden) # Project-wide include paths include_directories("${CMAKE_CURRENT_SOURCE_DIR}/vpu_driver/include") @@ -44,4 +45,7 @@ include_directories(SYSTEM ${VPU_KMD_INCLUDE_DIR}) add_subdirectory_unique(vpu_driver/source) add_subdirectory_unique(vpu_driver/unit_tests) + add_subdirectory_unique(level_zero_driver) +add_subdirectory_unique(level_zero_driver/api) +add_subdirectory_unique(level_zero_driver/unit_tests) diff --git a/umd/level_zero_driver/CMakeLists.txt b/umd/level_zero_driver/CMakeLists.txt index faae60e..5b685d6 100644 --- a/umd/level_zero_driver/CMakeLists.txt +++ b/umd/level_zero_driver/CMakeLists.txt @@ -4,35 +4,25 @@ # SPDX-License-Identifier: MIT # -set(TARGET_NAME_L0 ze_intel_vpu) +set(TARGET_NAME_L0_DRV level_zero_driver) -string(TIMESTAMP UNIX_SECONDS %s UTC) -set(DRIVER_VERSION ${UNIX_SECONDS} CACHE STRING "Decimal value that set Level Zero driverVersion") -add_compile_definitions(DRIVER_VERSION=${DRIVER_VERSION}) -message(STATUS "Level Zero driver version: ${DRIVER_VERSION}") - -add_library(${TARGET_NAME_L0} SHARED) +add_library(${TARGET_NAME_L0_DRV} STATIC) +set_property(TARGET ${TARGET_NAME_L0_DRV} PROPERTY POSITION_INDEPENDENT_CODE ON) find_package(OpenSSL REQUIRED) -target_link_libraries(${TARGET_NAME_L0} +target_link_libraries(${TARGET_NAME_L0_DRV} + fw_vpu_api_headers vpu_driver - dl vpux_elf OpenSSL::SSL ) -set_target_properties(${TARGET_NAME_L0} PROPERTIES - FOLDER ${TARGET_NAME_L0} - VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" - SOVERSION "${PROJECT_VERSION_MAJOR}" -) +string(TIMESTAMP UNIX_SECONDS %s UTC) +set(DRIVER_VERSION ${UNIX_SECONDS} CACHE STRING "Decimal value that set Level Zero driverVersion") +message(STATUS "Level Zero driver version: ${DRIVER_VERSION}") + +target_compile_definitions(${TARGET_NAME_L0_DRV} PUBLIC DRIVER_VERSION=${DRIVER_VERSION}) -add_subdirectories() add_subdirectory(core/source) add_subdirectory(ext/source) add_subdirectory(tools/source) - -target_include_directories(${TARGET_NAME_L0} PUBLIC ddi) - -install(TARGETS ${TARGET_NAME_L0} - COMPONENT level-zero-npu) diff --git a/umd/level_zero_driver/api/CMakeLists.txt b/umd/level_zero_driver/api/CMakeLists.txt index 0303f1a..fdba672 100644 --- a/umd/level_zero_driver/api/CMakeLists.txt +++ b/umd/level_zero_driver/api/CMakeLists.txt @@ -1,12 +1,39 @@ # -# Copyright (C) 2022 Intel Corporation +# Copyright (C) 2022-2024 Intel Corporation # # SPDX-License-Identifier: MIT # -add_subdirectory(core) +set(TARGET_NAME_L0 ze_intel_vpu) +add_library(${TARGET_NAME_L0} SHARED) + +target_link_libraries(${TARGET_NAME_L0} level_zero_driver) + +set_target_properties(${TARGET_NAME_L0} PROPERTIES + FOLDER ${TARGET_NAME_L0} + VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" + SOVERSION "${PROJECT_VERSION_MAJOR}" +) + +target_sources(${TARGET_NAME_L0} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/ze_cmdlist.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ze_cmdqueue.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ze_context.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ze_device.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ze_driver.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ze_event.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ze_fence.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ze_memory.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ze_misc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/zes_device.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/zes_driver.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/zes_engine.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/zes_misc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/zet_metric.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/zet_misc.cpp +) + add_subdirectory(ext) -add_subdirectory(tools) -set(L0_API_SOURCE "") -set_property(GLOBAL PROPERTY L0_API_SOURCE ${L0_API_SOURCE}) +install(TARGETS ${TARGET_NAME_L0} + COMPONENT level-zero-npu) diff --git a/umd/level_zero_driver/api/core/CMakeLists.txt b/umd/level_zero_driver/api/core/CMakeLists.txt deleted file mode 100644 index 065014e..0000000 --- a/umd/level_zero_driver/api/core/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright (C) 2022-2024 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -target_sources(${TARGET_NAME_L0} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/ze_barrier.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_cmdlist.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_cmdqueue.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_context.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_core_loader.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_driver.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_device.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_fence.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_event.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_memory.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_copy.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/zes_device.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/zes_driver.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/zes_loader.cpp -) diff --git a/umd/level_zero_driver/api/core/ze_barrier.hpp b/umd/level_zero_driver/api/core/ze_barrier.hpp deleted file mode 100644 index 803141e..0000000 --- a/umd/level_zero_driver/api/core/ze_barrier.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "level_zero_driver/core/source/cmdlist/cmdlist.hpp" -#include "level_zero_driver/include/l0_exception.hpp" - -#include - -namespace L0 { -ze_result_t zeCommandListAppendBarrier(ze_command_list_handle_t hCommandList, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - - L0_HANDLE_EXCEPTION_AND_RETURN(L0::CommandList::fromHandle(hCommandList) - ->appendBarrier(hSignalEvent, numWaitEvents, phWaitEvents)); -} - -ze_result_t zeCommandListAppendMemoryRangesBarrier(ze_command_list_handle_t hCommandList, - uint32_t numRanges, - const size_t *pRangeSizes, - const void **pRanges, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} -} // namespace L0 - -extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendBarrier(ze_command_list_handle_t hCommandList, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendBarrier(hCommandList, hSignalEvent, numWaitEvents, phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendMemoryRangesBarrier(ze_command_list_handle_t hCommandList, - uint32_t numRanges, - const size_t *pRangeSizes, - const void **pRanges, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendMemoryRangesBarrier(hCommandList, - numRanges, - pRangeSizes, - pRanges, - hSignalEvent, - numWaitEvents, - phWaitEvents); -} -} // extern "C" diff --git a/umd/level_zero_driver/api/core/ze_cmdlist.hpp b/umd/level_zero_driver/api/core/ze_cmdlist.hpp deleted file mode 100644 index 37b4d60..0000000 --- a/umd/level_zero_driver/api/core/ze_cmdlist.hpp +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "level_zero_driver/core/source/cmdlist/cmdlist.hpp" -#include "level_zero_driver/core/source/cmdlist/immediate_cmdlist.hpp" -#include "level_zero_driver/core/source/context/context.hpp" -#include "level_zero_driver/include/l0_exception.hpp" - -#include - -namespace L0 { -ze_result_t zeCommandListCreate(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - const ze_command_list_desc_t *desc, - ze_command_list_handle_t *phCommandList) { - L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::create(hContext, hDevice, desc, phCommandList)); -} - -ze_result_t zeCommandListCreateImmediate(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - const ze_command_queue_desc_t *altdesc, - ze_command_list_handle_t *phCommandList) { - L0_HANDLE_EXCEPTION_AND_RETURN( - ImmediateCommandList::create(hContext, hDevice, altdesc, phCommandList)); -} - -ze_result_t zeCommandListImmediateGetIndex(ze_command_list_handle_t hCommandListImmediate, - uint32_t *pIndex) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeCommandListIsImmediate(ze_command_list_handle_t hCommandList, - ze_bool_t *pIsImmediate) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - CommandList::fromHandle(hCommandList)->isImmediate(pIsImmediate)); -} - -ze_result_t zeCommandListHostSynchronize(ze_command_list_handle_t hCommandList, uint64_t timeout) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - ImmediateCommandList::fromHandle(hCommandList)->hostSynchronize(timeout)); -} - -ze_result_t zeCommandListDestroy(ze_command_list_handle_t hCommandList) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList)->destroy()); -} - -ze_result_t zeCommandListClose(ze_command_list_handle_t hCommandList) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList)->close()); -} - -ze_result_t zeCommandListReset(ze_command_list_handle_t hCommandList) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList)->reset()); -} - -ze_result_t zeCommandListAppendWriteGlobalTimestamp(ze_command_list_handle_t hCommandList, - uint64_t *dstptr, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - CommandList::fromHandle(hCommandList) - ->appendWriteGlobalTimestamp(dstptr, hSignalEvent, numWaitEvents, phWaitEvents)); -} - -ze_result_t zeCommandListAppendQueryKernelTimestamps(ze_command_list_handle_t hCommandList, - uint32_t numEvents, - ze_event_handle_t *phEvents, - void *dstptr, - const size_t *pOffsets, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeCommandListGetNextCommandIdExp(ze_command_list_handle_t hCommandList, - const ze_mutable_command_id_exp_desc_t *desc, - uint64_t *pCommandId) { - L0_HANDLE_EXCEPTION_AND_RETURN( - CommandList::fromHandle(hCommandList)->getNextCommandId(desc, pCommandId)); -} - -ze_result_t zeCommandListUpdateMutableCommandsExp(ze_command_list_handle_t hCommandList, - const ze_mutable_commands_exp_desc_t *desc) { - L0_HANDLE_EXCEPTION_AND_RETURN( - CommandList::fromHandle(hCommandList)->updateMutableCommands(desc)); -} - -} // namespace L0 - -extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListCreate(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - const ze_command_list_desc_t *desc, - ze_command_list_handle_t *phCommandList) { - return L0::zeCommandListCreate(hContext, hDevice, desc, phCommandList); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListCreateImmediate(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - const ze_command_queue_desc_t *altdesc, - ze_command_list_handle_t *phCommandList) { - return L0::zeCommandListCreateImmediate(hContext, hDevice, altdesc, phCommandList); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListImmediateGetIndex(ze_command_list_handle_t hCommandListImmediate, uint32_t *pIndex) { - return L0::zeCommandListImmediateGetIndex(hCommandListImmediate, pIndex); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListIsImmediate(ze_command_list_handle_t hCommandList, - ze_bool_t *pIsImmediate) { - return L0::zeCommandListIsImmediate(hCommandList, pIsImmediate); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListHostSynchronize(ze_command_list_handle_t hCommandList, uint64_t timeout) { - return L0::zeCommandListHostSynchronize(hCommandList, timeout); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListDestroy(ze_command_list_handle_t hCommandList) { - return L0::zeCommandListDestroy(hCommandList); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListClose(ze_command_list_handle_t hCommandList) { - return L0::zeCommandListClose(hCommandList); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListReset(ze_command_list_handle_t hCommandList) { - return L0::zeCommandListReset(hCommandList); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendWriteGlobalTimestamp(ze_command_list_handle_t hCommandList, - uint64_t *dstptr, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendWriteGlobalTimestamp(hCommandList, - dstptr, - hSignalEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendQueryKernelTimestamps(ze_command_list_handle_t hCommandList, - uint32_t numEvents, - ze_event_handle_t *phEvents, - void *dstptr, - const size_t *pOffsets, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendQueryKernelTimestamps(hCommandList, - numEvents, - phEvents, - dstptr, - pOffsets, - hSignalEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListGetNextCommandIdExp(ze_command_list_handle_t hCommandList, - const ze_mutable_command_id_exp_desc_t *desc, - uint64_t *pCommandId) { - return L0::zeCommandListGetNextCommandIdExp(hCommandList, desc, pCommandId); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListUpdateMutableCommandsExp(ze_command_list_handle_t hCommandList, - const ze_mutable_commands_exp_desc_t *desc) { - return L0::zeCommandListUpdateMutableCommandsExp(hCommandList, desc); -} - -} // extern "C" diff --git a/umd/level_zero_driver/api/core/ze_context.hpp b/umd/level_zero_driver/api/core/ze_context.hpp deleted file mode 100644 index d401009..0000000 --- a/umd/level_zero_driver/api/core/ze_context.hpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "level_zero_driver/core/source/context/context.hpp" -#include "level_zero_driver/core/source/driver/driver_handle.hpp" -#include "level_zero_driver/include/l0_exception.hpp" -#include - -namespace L0 { -ze_result_t zeContextCreate(ze_driver_handle_t hDriver, - const ze_context_desc_t *desc, - ze_context_handle_t *phContext) { - if (hDriver == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - L0::DriverHandle::fromHandle(hDriver)->createContext(desc, phContext)); -} - -ze_result_t zeContextDestroy(ze_context_handle_t hContext) { - if (hContext == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(L0::Context::fromHandle(hContext)->destroy()); -} - -ze_result_t zeContextGetStatus(ze_context_handle_t hContext) { - if (hContext == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(L0::Context::fromHandle(hContext)->getStatus()); -} - -ze_result_t -zeVirtualMemReserve(ze_context_handle_t hContext, const void *pStart, size_t size, void **pptr) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeVirtualMemFree(ze_context_handle_t hContext, const void *ptr, size_t size) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeVirtualMemQueryPageSize(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - size_t size, - size_t *pagesize) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zePhysicalMemCreate(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - ze_physical_mem_desc_t *desc, - ze_physical_mem_handle_t *phPhysicalMemory) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zePhysicalMemDestroy(ze_context_handle_t hContext, - ze_physical_mem_handle_t hPhysicalMemory) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeVirtualMemMap(ze_context_handle_t hContext, - const void *ptr, - size_t size, - ze_physical_mem_handle_t hPhysicalMemory, - size_t offset, - ze_memory_access_attribute_t access) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeVirtualMemUnmap(ze_context_handle_t hContext, const void *ptr, size_t size) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeVirtualMemSetAccessAttribute(ze_context_handle_t hContext, - const void *ptr, - size_t size, - ze_memory_access_attribute_t access) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeVirtualMemGetAccessAttribute(ze_context_handle_t hContext, - const void *ptr, - size_t size, - ze_memory_access_attribute_t *access, - size_t *outSize) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeContextSystemBarrier(ze_context_handle_t hContext, ze_device_handle_t hDevice) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeContextMakeMemoryResident(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - void *ptr, - size_t size) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeContextEvictMemory(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - void *ptr, - size_t size) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeContextMakeImageResident(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - ze_image_handle_t hImage) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeContextEvictImage(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - ze_image_handle_t hImage) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} -} // namespace L0 - -extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zeContextCreate(ze_driver_handle_t hDriver, - const ze_context_desc_t *desc, - ze_context_handle_t *phContext) { - return L0::zeContextCreate(hDriver, desc, phContext); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeContextDestroy(ze_context_handle_t hContext) { - return L0::zeContextDestroy(hContext); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeContextGetStatus(ze_context_handle_t hContext) { - return L0::zeContextGetStatus(hContext); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeVirtualMemReserve(ze_context_handle_t hContext, - const void *pStart, - size_t size, - void **pptr) { - return L0::zeVirtualMemReserve(hContext, pStart, size, pptr); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeVirtualMemFree(ze_context_handle_t hContext, - const void *ptr, - size_t size) { - return L0::zeVirtualMemFree(hContext, ptr, size); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeVirtualMemQueryPageSize(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - size_t size, - size_t *pagesize) { - return L0::zeVirtualMemQueryPageSize(hContext, hDevice, size, pagesize); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zePhysicalMemCreate(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - ze_physical_mem_desc_t *desc, - ze_physical_mem_handle_t *phPhysicalMemory) { - return L0::zePhysicalMemCreate(hContext, hDevice, desc, phPhysicalMemory); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zePhysicalMemDestroy(ze_context_handle_t hContext, - ze_physical_mem_handle_t hPhysicalMemory) { - return L0::zePhysicalMemDestroy(hContext, hPhysicalMemory); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeVirtualMemMap(ze_context_handle_t hContext, - const void *ptr, - size_t size, - ze_physical_mem_handle_t hPhysicalMemory, - size_t offset, - ze_memory_access_attribute_t access) { - return L0::zeVirtualMemMap(hContext, ptr, size, hPhysicalMemory, offset, access); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeVirtualMemUnmap(ze_context_handle_t hContext, - const void *ptr, - size_t size) { - return L0::zeVirtualMemUnmap(hContext, ptr, size); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeVirtualMemSetAccessAttribute(ze_context_handle_t hContext, - const void *ptr, - size_t size, - ze_memory_access_attribute_t access) { - return L0::zeVirtualMemSetAccessAttribute(hContext, ptr, size, access); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeVirtualMemGetAccessAttribute(ze_context_handle_t hContext, - const void *ptr, - size_t size, - ze_memory_access_attribute_t *access, - size_t *outSize) { - return L0::zeVirtualMemGetAccessAttribute(hContext, ptr, size, access, outSize); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeContextSystemBarrier(ze_context_handle_t hContext, - ze_device_handle_t hDevice) { - return L0::zeContextSystemBarrier(hContext, hDevice); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeContextMakeMemoryResident(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - void *ptr, - size_t size) { - return L0::zeContextMakeMemoryResident(hContext, hDevice, ptr, size); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeContextEvictMemory(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - void *ptr, - size_t size) { - return L0::zeContextEvictMemory(hContext, hDevice, ptr, size); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeContextMakeImageResident(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - ze_image_handle_t hImage) { - return L0::zeContextMakeImageResident(hContext, hDevice, hImage); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeContextEvictImage(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - ze_image_handle_t hImage) { - return L0::zeContextEvictImage(hContext, hDevice, hImage); -} -} // extern "C" diff --git a/umd/level_zero_driver/api/core/ze_copy.hpp b/umd/level_zero_driver/api/core/ze_copy.hpp deleted file mode 100644 index ea0ba2e..0000000 --- a/umd/level_zero_driver/api/core/ze_copy.hpp +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "level_zero_driver/core/source/cmdlist/cmdlist.hpp" -#include "level_zero_driver/include/l0_exception.hpp" -#include - -namespace L0 { -ze_result_t zeCommandListAppendMemoryCopy(ze_command_list_handle_t hCommandList, - void *dstptr, - const void *srcptr, - size_t size, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - L0::CommandList::fromHandle(hCommandList) - ->appendMemoryCopy(dstptr, srcptr, size, hEvent, numWaitEvents, phWaitEvents)); -} - -ze_result_t zeCommandListAppendMemoryFill(ze_command_list_handle_t hCommandList, - void *ptr, - const void *pattern, - size_t patternSize, - size_t size, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(L0::CommandList::fromHandle(hCommandList) - ->appendMemoryFill(ptr, - pattern, - patternSize, - size, - hEvent, - numWaitEvents, - phWaitEvents)); -} - -ze_result_t zeCommandListAppendMemoryCopyRegion(ze_command_list_handle_t hCommandList, - void *dstptr, - const ze_copy_region_t *dstRegion, - uint32_t dstPitch, - uint32_t dstSlicePitch, - const void *srcptr, - const ze_copy_region_t *srcRegion, - uint32_t srcPitch, - uint32_t srcSlicePitch, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeCommandListAppendImageCopy(ze_command_list_handle_t hCommandList, - ze_image_handle_t hDstImage, - ze_image_handle_t hSrcImage, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeCommandListAppendImageCopyRegion(ze_command_list_handle_t hCommandList, - ze_image_handle_t hDstImage, - ze_image_handle_t hSrcImage, - const ze_image_region_t *pDstRegion, - const ze_image_region_t *pSrcRegion, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeCommandListAppendImageCopyToMemory(ze_command_list_handle_t hCommandList, - void *dstptr, - ze_image_handle_t hSrcImage, - const ze_image_region_t *pSrcRegion, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeCommandListAppendImageCopyFromMemory(ze_command_list_handle_t hCommandList, - ze_image_handle_t hDstImage, - const void *srcptr, - const ze_image_region_t *pDstRegion, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeCommandListAppendMemoryPrefetch(ze_command_list_handle_t hCommandList, - const void *ptr, - size_t size) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeCommandListAppendMemAdvise(ze_command_list_handle_t hCommandList, - ze_device_handle_t hDevice, - const void *ptr, - size_t size, - ze_memory_advice_t advice) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeCommandListAppendMemoryCopyFromContext(ze_command_list_handle_t hCommandList, - void *dstptr, - ze_context_handle_t hContextSrc, - const void *srcptr, - size_t size, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} -} // namespace L0 - -extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendMemoryCopy(ze_command_list_handle_t hCommandList, - void *dstptr, - const void *srcptr, - size_t size, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendMemoryCopy(hCommandList, - dstptr, - srcptr, - size, - hEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendMemoryFill(ze_command_list_handle_t hCommandList, - void *ptr, - const void *pattern, - size_t patternSize, - size_t size, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendMemoryFill(hCommandList, - ptr, - pattern, - patternSize, - size, - hEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendMemoryCopyRegion(ze_command_list_handle_t hCommandList, - void *dstptr, - const ze_copy_region_t *dstRegion, - uint32_t dstPitch, - uint32_t dstSlicePitch, - const void *srcptr, - const ze_copy_region_t *srcRegion, - uint32_t srcPitch, - uint32_t srcSlicePitch, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendMemoryCopyRegion(hCommandList, - dstptr, - dstRegion, - dstPitch, - dstSlicePitch, - srcptr, - srcRegion, - srcPitch, - srcSlicePitch, - hEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendImageCopy(ze_command_list_handle_t hCommandList, - ze_image_handle_t hDstImage, - ze_image_handle_t hSrcImage, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendImageCopy(hCommandList, - hDstImage, - hSrcImage, - hEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendImageCopyRegion(ze_command_list_handle_t hCommandList, - ze_image_handle_t hDstImage, - ze_image_handle_t hSrcImage, - const ze_image_region_t *pDstRegion, - const ze_image_region_t *pSrcRegion, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendImageCopyRegion(hCommandList, - hDstImage, - hSrcImage, - pDstRegion, - pSrcRegion, - hEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendImageCopyToMemory(ze_command_list_handle_t hCommandList, - void *dstptr, - ze_image_handle_t hSrcImage, - const ze_image_region_t *pSrcRegion, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendImageCopyToMemory(hCommandList, - dstptr, - hSrcImage, - pSrcRegion, - hEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendImageCopyFromMemory(ze_command_list_handle_t hCommandList, - ze_image_handle_t hDstImage, - const void *srcptr, - const ze_image_region_t *pDstRegion, - ze_event_handle_t hEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendImageCopyFromMemory(hCommandList, - hDstImage, - srcptr, - pDstRegion, - hEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendMemoryPrefetch(ze_command_list_handle_t hCommandList, - const void *ptr, - size_t size) { - return L0::zeCommandListAppendMemoryPrefetch(hCommandList, ptr, size); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendMemAdvise(ze_command_list_handle_t hCommandList, - ze_device_handle_t hDevice, - const void *ptr, - size_t size, - ze_memory_advice_t advice) { - return L0::zeCommandListAppendMemAdvise(hCommandList, hDevice, ptr, size, advice); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendMemoryCopyFromContext(ze_command_list_handle_t hCommandList, - void *dstptr, - ze_context_handle_t hContextSrc, - const void *srcptr, - size_t size, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeCommandListAppendMemoryCopyFromContext(hCommandList, - dstptr, - hContextSrc, - srcptr, - size, - hSignalEvent, - numWaitEvents, - phWaitEvents); -} -} // extern "C" diff --git a/umd/level_zero_driver/api/core/ze_core_api_tables.hpp b/umd/level_zero_driver/api/core/ze_core_api_tables.hpp deleted file mode 100644 index 441d057..0000000 --- a/umd/level_zero_driver/api/core/ze_core_api_tables.hpp +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2022 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "ze_barrier.hpp" -#include "ze_cmdlist.hpp" -#include "ze_cmdqueue.hpp" -#include "ze_context.hpp" -#include "ze_copy.hpp" -#include "ze_device.hpp" -#include "ze_driver.hpp" -#include "ze_event.hpp" -#include "ze_fence.hpp" -#include "ze_memory.hpp" diff --git a/umd/level_zero_driver/api/core/ze_core_loader.cpp b/umd/level_zero_driver/api/core/ze_core_loader.cpp deleted file mode 100644 index 36b4ced..0000000 --- a/umd/level_zero_driver/api/core/ze_core_loader.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "level_zero_driver/api/core/ze_barrier.hpp" -#include "level_zero_driver/api/core/ze_cmdlist.hpp" -#include "level_zero_driver/api/core/ze_cmdqueue.hpp" -#include "level_zero_driver/api/core/ze_context.hpp" -#include "level_zero_driver/api/core/ze_copy.hpp" -#include "level_zero_driver/api/core/ze_device.hpp" -#include "level_zero_driver/api/core/ze_driver.hpp" -#include "level_zero_driver/api/core/ze_event.hpp" -#include "level_zero_driver/api/core/ze_fence.hpp" -#include "level_zero_driver/api/core/ze_memory.hpp" - -#include -#include - -#if defined(__cplusplus) -extern "C" { -#endif -ZE_APIEXPORT ze_result_t ZE_APICALL zeGetDriverProcAddrTable(ze_api_version_t version, - ze_driver_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnGet = L0::zeDriverGet; - pDdiTable->pfnGetApiVersion = L0::zeDriverGetApiVersion; - pDdiTable->pfnGetProperties = L0::zeDriverGetProperties; - pDdiTable->pfnGetIpcProperties = L0::zeDriverGetIpcProperties; - pDdiTable->pfnGetExtensionProperties = L0::zeDriverGetExtensionProperties; - pDdiTable->pfnGetExtensionFunctionAddress = L0::zeDriverGetExtensionFunctionAddress; - return ZE_RESULT_SUCCESS; -} - -ZE_DLLEXPORT ze_result_t ZE_APICALL zeGetMemProcAddrTable(ze_api_version_t version, - ze_mem_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnAllocShared = L0::zeMemAllocShared; - pDdiTable->pfnAllocDevice = L0::zeMemAllocDevice; - pDdiTable->pfnAllocHost = L0::zeMemAllocHost; - pDdiTable->pfnFree = L0::zeMemFree; - pDdiTable->pfnGetAllocProperties = L0::zeMemGetAllocProperties; - pDdiTable->pfnGetAddressRange = L0::zeMemGetAddressRange; - pDdiTable->pfnGetIpcHandle = L0::zeMemGetIpcHandle; - pDdiTable->pfnOpenIpcHandle = L0::zeMemOpenIpcHandle; - pDdiTable->pfnCloseIpcHandle = L0::zeMemCloseIpcHandle; - return ZE_RESULT_SUCCESS; -} - -ZE_DLLEXPORT ze_result_t ZE_APICALL zeGetContextProcAddrTable(ze_api_version_t version, - ze_context_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnCreate = L0::zeContextCreate; - pDdiTable->pfnDestroy = L0::zeContextDestroy; - pDdiTable->pfnGetStatus = L0::zeContextGetStatus; - pDdiTable->pfnSystemBarrier = L0::zeContextSystemBarrier; - pDdiTable->pfnMakeMemoryResident = L0::zeContextMakeMemoryResident; - pDdiTable->pfnEvictMemory = L0::zeContextEvictMemory; - pDdiTable->pfnMakeImageResident = L0::zeContextMakeImageResident; - pDdiTable->pfnEvictImage = L0::zeContextEvictImage; - return ZE_RESULT_SUCCESS; -} - -ZE_DLLEXPORT ze_result_t ZE_APICALL -zeGetPhysicalMemProcAddrTable(ze_api_version_t version, ze_physical_mem_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnCreate = L0::zePhysicalMemCreate; - pDdiTable->pfnDestroy = L0::zePhysicalMemDestroy; - return ZE_RESULT_SUCCESS; -} - -ZE_DLLEXPORT ze_result_t ZE_APICALL -zeGetVirtualMemProcAddrTable(ze_api_version_t version, ze_virtual_mem_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnReserve = L0::zeVirtualMemReserve; - pDdiTable->pfnFree = L0::zeVirtualMemFree; - pDdiTable->pfnQueryPageSize = L0::zeVirtualMemQueryPageSize; - pDdiTable->pfnMap = L0::zeVirtualMemMap; - pDdiTable->pfnUnmap = L0::zeVirtualMemUnmap; - pDdiTable->pfnSetAccessAttribute = L0::zeVirtualMemSetAccessAttribute; - pDdiTable->pfnGetAccessAttribute = L0::zeVirtualMemGetAccessAttribute; - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGetGlobalProcAddrTable(ze_api_version_t version, - ze_global_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnInit = L0::zeInit; - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGetDeviceProcAddrTable(ze_api_version_t version, - ze_device_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnGet = L0::zeDeviceGet; - pDdiTable->pfnGetCommandQueueGroupProperties = L0::zeDeviceGetCommandQueueGroupProperties; - pDdiTable->pfnGetSubDevices = L0::zeDeviceGetSubDevices; - pDdiTable->pfnGetProperties = L0::zeDeviceGetProperties; - pDdiTable->pfnGetComputeProperties = L0::zeDeviceGetComputeProperties; - pDdiTable->pfnGetModuleProperties = L0::zeDeviceGetModuleProperties; - pDdiTable->pfnGetMemoryProperties = L0::zeDeviceGetMemoryProperties; - pDdiTable->pfnGetMemoryAccessProperties = L0::zeDeviceGetMemoryAccessProperties; - pDdiTable->pfnGetCacheProperties = L0::zeDeviceGetCacheProperties; - pDdiTable->pfnGetImageProperties = L0::zeDeviceGetImageProperties; - pDdiTable->pfnGetP2PProperties = L0::zeDeviceGetP2PProperties; - pDdiTable->pfnCanAccessPeer = L0::zeDeviceCanAccessPeer; - pDdiTable->pfnGetStatus = L0::zeDeviceGetStatus; - pDdiTable->pfnGetGlobalTimestamps = L0::zeDeviceGetGlobalTimestamps; - pDdiTable->pfnGetExternalMemoryProperties = L0::zeDeviceGetExternalMemoryProperties; - pDdiTable->pfnPciGetPropertiesExt = L0::zeDevicePciGetPropertiesExt; - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGetCommandQueueProcAddrTable(ze_api_version_t version, ze_command_queue_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnCreate = L0::zeCommandQueueCreate; - pDdiTable->pfnDestroy = L0::zeCommandQueueDestroy; - pDdiTable->pfnExecuteCommandLists = L0::zeCommandQueueExecuteCommandLists; - pDdiTable->pfnSynchronize = L0::zeCommandQueueSynchronize; - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGetCommandListProcAddrTable(ze_api_version_t version, ze_command_list_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnAppendBarrier = L0::zeCommandListAppendBarrier; - pDdiTable->pfnAppendMemoryRangesBarrier = L0::zeCommandListAppendMemoryRangesBarrier; - pDdiTable->pfnCreate = L0::zeCommandListCreate; - pDdiTable->pfnCreateImmediate = L0::zeCommandListCreateImmediate; - pDdiTable->pfnImmediateGetIndex = L0::zeCommandListImmediateGetIndex; - pDdiTable->pfnIsImmediate = L0::zeCommandListIsImmediate; - pDdiTable->pfnHostSynchronize = L0::zeCommandListHostSynchronize; - pDdiTable->pfnDestroy = L0::zeCommandListDestroy; - pDdiTable->pfnClose = L0::zeCommandListClose; - pDdiTable->pfnReset = L0::zeCommandListReset; - pDdiTable->pfnAppendMemoryCopy = L0::zeCommandListAppendMemoryCopy; - pDdiTable->pfnAppendMemoryCopyRegion = L0::zeCommandListAppendMemoryCopyRegion; - pDdiTable->pfnAppendMemoryFill = L0::zeCommandListAppendMemoryFill; - pDdiTable->pfnAppendImageCopy = L0::zeCommandListAppendImageCopy; - pDdiTable->pfnAppendImageCopyRegion = L0::zeCommandListAppendImageCopyRegion; - pDdiTable->pfnAppendImageCopyToMemory = L0::zeCommandListAppendImageCopyToMemory; - pDdiTable->pfnAppendImageCopyFromMemory = L0::zeCommandListAppendImageCopyFromMemory; - pDdiTable->pfnAppendMemoryPrefetch = L0::zeCommandListAppendMemoryPrefetch; - pDdiTable->pfnAppendMemAdvise = L0::zeCommandListAppendMemAdvise; - pDdiTable->pfnAppendSignalEvent = L0::zeCommandListAppendSignalEvent; - pDdiTable->pfnAppendWaitOnEvents = L0::zeCommandListAppendWaitOnEvents; - pDdiTable->pfnAppendEventReset = L0::zeCommandListAppendEventReset; - pDdiTable->pfnAppendLaunchCooperativeKernel = - nullptr; // zeCommandListAppendLaunchCooperativeKernel - pDdiTable->pfnAppendLaunchKernelIndirect = nullptr; // zeCommandListAppendLaunchKernelIndirect - pDdiTable->pfnAppendLaunchMultipleKernelsIndirect = - nullptr; // zeCommandListAppendLaunchMultipleKernelsIndirect - pDdiTable->pfnAppendWriteGlobalTimestamp = L0::zeCommandListAppendWriteGlobalTimestamp; - pDdiTable->pfnAppendMemoryCopyFromContext = L0::zeCommandListAppendMemoryCopyFromContext; - pDdiTable->pfnAppendQueryKernelTimestamps = L0::zeCommandListAppendQueryKernelTimestamps; - return ZE_RESULT_SUCCESS; -} - -ZE_DLLEXPORT ze_result_t ZE_APICALL -zeGetCommandListExpProcAddrTable(ze_api_version_t version, - ze_command_list_exp_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnGetNextCommandIdExp = L0::zeCommandListGetNextCommandIdExp; - pDdiTable->pfnUpdateMutableCommandsExp = L0::zeCommandListUpdateMutableCommandsExp; - - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGetFenceProcAddrTable(ze_api_version_t version, - ze_fence_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnCreate = L0::zeFenceCreate; - pDdiTable->pfnDestroy = L0::zeFenceDestroy; - pDdiTable->pfnHostSynchronize = L0::zeFenceHostSynchronize; - pDdiTable->pfnQueryStatus = L0::zeFenceQueryStatus; - pDdiTable->pfnReset = L0::zeFenceReset; - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGetEventPoolProcAddrTable(ze_api_version_t version, ze_event_pool_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnCreate = L0::zeEventPoolCreate; - pDdiTable->pfnDestroy = L0::zeEventPoolDestroy; - pDdiTable->pfnGetIpcHandle = L0::zeEventPoolGetIpcHandle; - pDdiTable->pfnOpenIpcHandle = L0::zeEventPoolOpenIpcHandle; - pDdiTable->pfnCloseIpcHandle = L0::zeEventPoolCloseIpcHandle; - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGetEventProcAddrTable(ze_api_version_t version, - ze_event_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnCreate = L0::zeEventCreate; - pDdiTable->pfnDestroy = L0::zeEventDestroy; - pDdiTable->pfnHostSignal = L0::zeEventHostSignal; - pDdiTable->pfnHostSynchronize = L0::zeEventHostSynchronize; - pDdiTable->pfnQueryStatus = L0::zeEventQueryStatus; - pDdiTable->pfnHostReset = L0::zeEventHostReset; - pDdiTable->pfnQueryKernelTimestamp = L0::zeEventQueryKernelTimestamp; - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGetImageProcAddrTable(ze_api_version_t version, - ze_image_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnGetProperties = nullptr; // zeImageGetProperties - pDdiTable->pfnCreate = nullptr; // zeImageCreate - pDdiTable->pfnDestroy = nullptr; // zeImageDestroy - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGetModuleProcAddrTable(ze_api_version_t version, - ze_module_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnCreate = nullptr; // zeModuleCreate - pDdiTable->pfnDestroy = nullptr; // zeModuleDestroy - pDdiTable->pfnDynamicLink = nullptr; // zeModuleDynamicLink - pDdiTable->pfnGetNativeBinary = nullptr; // zeModuleGetNativeBinary - pDdiTable->pfnGetGlobalPointer = nullptr; // zeModuleGetGlobalPointer - pDdiTable->pfnGetKernelNames = nullptr; // zeModuleGetKernelNames - pDdiTable->pfnGetFunctionPointer = nullptr; // zeModuleGetFunctionPointer - pDdiTable->pfnGetProperties = nullptr; // zeModuleGetProperties - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGetModuleBuildLogProcAddrTable(ze_api_version_t version, - ze_module_build_log_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnDestroy = nullptr; // zeModuleBuildLogDestroy - pDdiTable->pfnGetString = nullptr; // zeModuleBuildLogGetString - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGetKernelProcAddrTable(ze_api_version_t version, - ze_kernel_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnCreate = nullptr; // zeKernelCreate - pDdiTable->pfnDestroy = nullptr; // zeKernelDestroy - pDdiTable->pfnSetGroupSize = nullptr; // zeKernelSetGroupSize - pDdiTable->pfnSuggestGroupSize = nullptr; // zeKernelSuggestGroupSize - pDdiTable->pfnSuggestMaxCooperativeGroupCount = - nullptr; // zeKernelSuggestMaxCooperativeGroupCount - pDdiTable->pfnSetArgumentValue = nullptr; // zeKernelSetArgumentValue - pDdiTable->pfnSetIndirectAccess = nullptr; // zeKernelSetIndirectAccess - pDdiTable->pfnGetIndirectAccess = nullptr; // zeKernelGetIndirectAccess - pDdiTable->pfnGetSourceAttributes = nullptr; // zeKernelGetSourceAttributes - pDdiTable->pfnGetProperties = nullptr; // zeKernelGetProperties - pDdiTable->pfnSetCacheConfig = nullptr; // zeKernelSetCacheConfig - pDdiTable->pfnGetName = nullptr; // zeKernelGetName - return ZE_RESULT_SUCCESS; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGetSamplerProcAddrTable(ze_api_version_t version, - ze_sampler_dditable_t *pDdiTable) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnCreate = nullptr; // zeSamplerCreate - pDdiTable->pfnDestroy = nullptr; // zeSamplerDestroy - return ZE_RESULT_SUCCESS; -} -#if defined(__cplusplus) -} -#endif diff --git a/umd/level_zero_driver/api/core/ze_driver.hpp b/umd/level_zero_driver/api/core/ze_driver.hpp deleted file mode 100644 index 0f18493..0000000 --- a/umd/level_zero_driver/api/core/ze_driver.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "level_zero_driver/core/source/driver/driver.hpp" -#include "level_zero_driver/core/source/driver/driver_handle.hpp" -#include "level_zero_driver/include/l0_exception.hpp" -#include - -namespace L0 { -ze_result_t zeInit(ze_init_flags_t flags) { - L0_HANDLE_EXCEPTION_AND_RETURN(L0::init(flags)); -} - -ze_result_t zeDriverGet(uint32_t *pCount, ze_driver_handle_t *phDrivers) { - L0_HANDLE_EXCEPTION_AND_RETURN(L0::driverHandleGet(pCount, phDrivers)); -} - -ze_result_t zeDriverGetProperties(ze_driver_handle_t hDriver, ze_driver_properties_t *pProperties) { - if (hDriver == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - L0::DriverHandle::fromHandle(hDriver)->getProperties(pProperties)); -} - -ze_result_t zeDriverGetApiVersion(ze_driver_handle_t hDriver, ze_api_version_t *version) { - if (hDriver == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(L0::DriverHandle::fromHandle(hDriver)->getApiVersion(version)); -} - -ze_result_t zeDriverGetIpcProperties(ze_driver_handle_t hDriver, - ze_driver_ipc_properties_t *pIPCProperties) { - if (hDriver == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - L0::DriverHandle::fromHandle(hDriver)->getIPCProperties(pIPCProperties)); -} - -ze_result_t zeDriverGetExtensionProperties(ze_driver_handle_t hDriver, - uint32_t *pCount, - ze_driver_extension_properties_t *pExtensionProperties) { - if (hDriver == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - L0::DriverHandle::fromHandle(hDriver)->getExtensionProperties(pCount, - pExtensionProperties)); -} - -ze_result_t zeDriverGetExtensionFunctionAddress(ze_driver_handle_t hDriver, - const char *name, - void **ppFunctionAddress) { - if (hDriver == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - L0::DriverHandle::fromHandle(hDriver)->getExtensionFunctionAddress(name, - ppFunctionAddress)); -} -} // namespace L0 - -extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zeInit(ze_init_flags_t flags) { - return L0::zeInit(flags); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDriverGet(uint32_t *pCount, ze_driver_handle_t *phDrivers) { - return L0::zeDriverGet(pCount, phDrivers); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDriverGetProperties(ze_driver_handle_t hDriver, - ze_driver_properties_t *pProperties) { - return L0::zeDriverGetProperties(hDriver, pProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDriverGetApiVersion(ze_driver_handle_t hDriver, - ze_api_version_t *version) { - return L0::zeDriverGetApiVersion(hDriver, version); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDriverGetIpcProperties(ze_driver_handle_t hDriver, ze_driver_ipc_properties_t *pIPCProperties) { - return L0::zeDriverGetIpcProperties(hDriver, pIPCProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDriverGetExtensionProperties(ze_driver_handle_t hDriver, - uint32_t *pCount, - ze_driver_extension_properties_t *pExtensionProperties) { - return L0::zeDriverGetExtensionProperties(hDriver, pCount, pExtensionProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDriverGetExtensionFunctionAddress(ze_driver_handle_t hDriver, - const char *name, - void **ppFunctionAddress) { - return L0::zeDriverGetExtensionFunctionAddress(hDriver, name, ppFunctionAddress); -} -} // extern "C" diff --git a/umd/level_zero_driver/api/core/ze_event.hpp b/umd/level_zero_driver/api/core/ze_event.hpp deleted file mode 100644 index 9211d5b..0000000 --- a/umd/level_zero_driver/api/core/ze_event.hpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "level_zero_driver/core/source/cmdlist/cmdlist.hpp" -#include "level_zero_driver/core/source/event/event.hpp" -#include "level_zero_driver/core/source/event/eventpool.hpp" -#include "level_zero_driver/include/l0_exception.hpp" - -#include - -namespace L0 { -ze_result_t zeEventPoolCreate(ze_context_handle_t hContext, - const ze_event_pool_desc_t *desc, - uint32_t numDevices, - ze_device_handle_t *phDevices, - ze_event_pool_handle_t *phEventPool) { - if (hContext == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - EventPool::create(hContext, desc, numDevices, phDevices, phEventPool)); -} - -ze_result_t zeEventPoolDestroy(ze_event_pool_handle_t hEventPool) { - if (hEventPool == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(EventPool::fromHandle(hEventPool)->destroy()); -} - -ze_result_t zeEventCreate(ze_event_pool_handle_t hEventPool, - const ze_event_desc_t *desc, - ze_event_handle_t *phEvent) { - if (hEventPool == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(EventPool::fromHandle(hEventPool)->createEvent(desc, phEvent)); -} - -ze_result_t zeEventPoolGetIpcHandle(ze_event_pool_handle_t hEventPool, - ze_ipc_event_pool_handle_t *phIpc) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeEventPoolOpenIpcHandle(ze_context_handle_t hContext, - ze_ipc_event_pool_handle_t hIpc, - ze_event_pool_handle_t *phEventPool) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeEventPoolCloseIpcHandle(ze_event_pool_handle_t hEventPool) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t zeEventDestroy(ze_event_handle_t hEvent) { - if (hEvent == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->destroy()); -} - -ze_result_t zeCommandListAppendSignalEvent(ze_command_list_handle_t hCommandList, - ze_event_handle_t hEvent) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - CommandList::fromHandle(hCommandList)->CommandList::appendSignalEvent(hEvent)); -} - -ze_result_t zeCommandListAppendWaitOnEvents(ze_command_list_handle_t hCommandList, - uint32_t numEvents, - ze_event_handle_t *phEvents) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList) - ->CommandList::appendWaitOnEvents(numEvents, phEvents)); -} - -ze_result_t zeEventHostSignal(ze_event_handle_t hEvent) { - if (hEvent == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->hostSignal()); -} - -ze_result_t zeEventHostSynchronize(ze_event_handle_t hEvent, uint64_t timeout) { - if (hEvent == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->hostSynchronize(timeout)); -} - -ze_result_t zeEventQueryStatus(ze_event_handle_t hEvent) { - if (hEvent == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->queryStatus()); -} - -ze_result_t zeCommandListAppendEventReset(ze_command_list_handle_t hCommandList, - ze_event_handle_t hEvent) { - if (hCommandList == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList)->appendEventReset(hEvent)); -} - -ze_result_t zeEventHostReset(ze_event_handle_t hEvent) { - if (hEvent == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->reset()); -} - -ze_result_t zeEventQueryKernelTimestamp(ze_event_handle_t hEvent, - ze_kernel_timestamp_result_t *timestampType) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} -} // namespace L0 - -extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventPoolCreate(ze_context_handle_t hContext, - const ze_event_pool_desc_t *desc, - uint32_t numDevices, - ze_device_handle_t *phDevices, - ze_event_pool_handle_t *phEventPool) { - return L0::zeEventPoolCreate(hContext, desc, numDevices, phDevices, phEventPool); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventPoolDestroy(ze_event_pool_handle_t hEventPool) { - return L0::zeEventPoolDestroy(hEventPool); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventCreate(ze_event_pool_handle_t hEventPool, - const ze_event_desc_t *desc, - ze_event_handle_t *phEvent) { - return L0::zeEventCreate(hEventPool, desc, phEvent); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventDestroy(ze_event_handle_t hEvent) { - return L0::zeEventDestroy(hEvent); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventPoolGetIpcHandle(ze_event_pool_handle_t hEventPool, - ze_ipc_event_pool_handle_t *phIpc) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventPoolOpenIpcHandle(ze_context_handle_t hContext, - ze_ipc_event_pool_handle_t hIpc, - ze_event_pool_handle_t *phEventPool) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventPoolCloseIpcHandle(ze_event_pool_handle_t hEventPool) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendSignalEvent(ze_command_list_handle_t hCommandList, ze_event_handle_t hEvent) { - return L0::zeCommandListAppendSignalEvent(hCommandList, hEvent); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendWaitOnEvents(ze_command_list_handle_t hCommandList, - uint32_t numEvents, - ze_event_handle_t *phEvents) { - return L0::zeCommandListAppendWaitOnEvents(hCommandList, numEvents, phEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventHostSignal(ze_event_handle_t hEvent) { - return L0::zeEventHostSignal(hEvent); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventHostSynchronize(ze_event_handle_t hEvent, - uint64_t timeout) { - return L0::zeEventHostSynchronize(hEvent, timeout); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventQueryStatus(ze_event_handle_t hEvent) { - return L0::zeEventQueryStatus(hEvent); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandListAppendEventReset(ze_command_list_handle_t hCommandList, ze_event_handle_t hEvent) { - return L0::zeCommandListAppendEventReset(hCommandList, hEvent); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeEventHostReset(ze_event_handle_t hEvent) { - return L0::zeEventHostReset(hEvent); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeEventQueryKernelTimestamp(ze_event_handle_t hEvent, ze_kernel_timestamp_result_t *timestampType) { - return L0::zeEventQueryKernelTimestamp(hEvent, timestampType); -} -} // extern "C" diff --git a/umd/level_zero_driver/api/core/zes_device.hpp b/umd/level_zero_driver/api/core/zes_device.hpp deleted file mode 100644 index b3c4c31..0000000 --- a/umd/level_zero_driver/api/core/zes_device.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "level_zero_driver/core/source/device/device.hpp" -#include "level_zero_driver/core/source/driver/driver.hpp" -#include "level_zero_driver/core/source/driver/driver_handle.hpp" -#include "level_zero_driver/include/l0_exception.hpp" -#include -#include - -namespace L0 { - -ze_result_t -zesDeviceGet(zes_driver_handle_t hDriver, uint32_t *pCount, zes_device_handle_t *phDevices) { - if (static_cast(hDriver) == nullptr || pCount == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - L0_HANDLE_EXCEPTION_AND_RETURN( - L0::DriverHandle::fromHandle(static_cast(hDriver)) - ->getDevice(pCount, static_cast(phDevices))); -} - -ze_result_t zesDeviceGetProperties(zes_device_handle_t hDevice, - zes_device_properties_t *pProperties) { - if (static_cast(hDevice) == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - - L0_HANDLE_EXCEPTION_AND_RETURN(L0::Device::fromHandle(static_cast(hDevice)) - ->getProperties(pProperties)); -} - -} // namespace L0 - -extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zesDeviceGet(zes_driver_handle_t hDriver, - uint32_t *pCount, - zes_device_handle_t *phDevices) { - return L0::zesDeviceGet(hDriver, pCount, phDevices); -} -ZE_APIEXPORT ze_result_t ZE_APICALL zesDeviceGetProperties(zes_device_handle_t hDevice, - zes_device_properties_t *pProperties) { - return L0::zesDeviceGetProperties(hDevice, pProperties); -} - -} // extern "C" \ No newline at end of file diff --git a/umd/level_zero_driver/api/core/zes_driver.hpp b/umd/level_zero_driver/api/core/zes_driver.hpp deleted file mode 100644 index 0fb8de0..0000000 --- a/umd/level_zero_driver/api/core/zes_driver.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "level_zero_driver/core/source/device/device.hpp" -#include "level_zero_driver/core/source/driver/driver.hpp" -#include "level_zero_driver/core/source/driver/driver_handle.hpp" -#include "level_zero_driver/include/l0_exception.hpp" -#include -#include - -namespace L0 { -ze_result_t zesInit(zes_init_flags_t flags) { - L0_HANDLE_EXCEPTION_AND_RETURN(L0::init(flags)); -} - -ze_result_t zesDriverGet(uint32_t *pCount, zes_driver_handle_t *phDrivers) { - if (pCount == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; - } - - L0_HANDLE_EXCEPTION_AND_RETURN( - L0::driverHandleGet(pCount, static_cast(phDrivers))); -} - -} // namespace L0 - -extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zesInit(zes_init_flags_t flags) { - return L0::zesInit(flags); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zesDriverGet(uint32_t *pCount, zes_driver_handle_t *phDrivers) { - return L0::zesDriverGet(pCount, phDrivers); -} - -} // extern "C" \ No newline at end of file diff --git a/umd/level_zero_driver/api/ext/CMakeLists.txt b/umd/level_zero_driver/api/ext/CMakeLists.txt index 84be6a8..5484b86 100644 --- a/umd/level_zero_driver/api/ext/CMakeLists.txt +++ b/umd/level_zero_driver/api/ext/CMakeLists.txt @@ -6,4 +6,5 @@ target_sources(${TARGET_NAME_L0} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ze_graph.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ze_queue.cpp ) diff --git a/umd/level_zero_driver/api/ext/ze_graph.cpp b/umd/level_zero_driver/api/ext/ze_graph.cpp index 6524ef7..3faa99e 100644 --- a/umd/level_zero_driver/api/ext/ze_graph.cpp +++ b/umd/level_zero_driver/api/ext/ze_graph.cpp @@ -11,7 +11,7 @@ #include "level_zero/ze_api.h" #include "level_zero/ze_graph_ext.h" #include "level_zero/ze_graph_profiling_ext.h" -#include "level_zero_driver/api/tools/ze_tools_loader.h" +#include "level_zero_driver/api/zet_misc.hpp" #include "level_zero_driver/core/source/cmdlist/cmdlist.hpp" #include "level_zero_driver/core/source/context/context.hpp" #include "level_zero_driver/core/source/device/device.hpp" @@ -21,45 +21,10 @@ #include "level_zero_driver/include/l0_exception.hpp" #include "vpu_driver/source/utilities/log.hpp" -#include #include namespace L0 { -static ze_result_t translateHandle(zel_handle_type_t type, void *handler, void **pHandler) { - void *loaderHandle = getLoaderHandle(); - if (loaderHandle == nullptr) { - LOG_E("Failed to open libze_loader.so.1 library"); - return ZE_RESULT_ERROR_UNKNOWN; - } - - static void *functionPointer = dlsym(loaderHandle, "zelLoaderTranslateHandle"); - if (functionPointer == nullptr) { - LOG_E("Failed to get 'zelLoaderTranslateHandle' from libze_loader.so.1, reason: %s", - dlerror()); - return ZE_RESULT_ERROR_UNKNOWN; - } - - static auto *pLoaderTranslateHandler = - reinterpret_cast(functionPointer); - - auto result = pLoaderTranslateHandler(type, handler, pHandler); - if (result != ZE_RESULT_SUCCESS) - LOG_E("Failed to translate handler of type %i", type); - - return result; -} - -template -static inline ze_result_t translateHandle(zel_handle_type_t type, T handler, T *pHandler) { - return translateHandle(type, handler, reinterpret_cast(pHandler)); -} - -template -static inline ze_result_t translateHandle(zel_handle_type_t type, T &handler) { - return translateHandle(type, handler, &handler); -} - ze_result_t ZE_APICALL zeGraphCreate(ze_context_handle_t hContext, ze_device_handle_t hDevice, const ze_graph_desc_t *pDesc, @@ -97,6 +62,19 @@ ze_result_t ZE_APICALL zeGraphGetProperties(ze_graph_handle_t hGraph, L0_HANDLE_EXCEPTION_AND_RETURN(L0::Graph::fromHandle(hGraph)->getProperties(pGraphProperties)); } +ze_result_t ZE_APICALL zeGraphGetProperties2(ze_graph_handle_t hGraph, + ze_graph_properties_2_t *pGraphProperties) { + if (hGraph == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (pGraphProperties == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + } + + L0_HANDLE_EXCEPTION_AND_RETURN(L0::Graph::fromHandle(hGraph)->getProperties2(pGraphProperties)); +} + ze_result_t ZE_APICALL zeGraphGetArgumentProperties(ze_graph_handle_t hGraph, uint32_t argIndex, @@ -168,6 +146,14 @@ ze_result_t ZE_APICALL zeAppendGraphInitialize(ze_command_list_handle_t hCommand appendGraphInitialize(hCommandList, hGraph, hSignalEvent, numWaitEvents, phWaitEvents)); } +ze_result_t ZE_APICALL zeGraphInitialize(ze_graph_handle_t hGraph) { + if (hGraph == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + L0_HANDLE_EXCEPTION_AND_RETURN(L0::Graph::fromHandle(hGraph)->parserInitialize()); +} + static ze_result_t appendGraphExecute(ze_command_list_handle_t hCommandList, ze_graph_handle_t hGraph, ze_graph_profiling_query_handle_t hProfilingQuery, @@ -237,6 +223,25 @@ ze_result_t ZE_APICALL zeGraphGetNativeBinary(ze_graph_handle_t hGraph, L0::Graph::fromHandle(hGraph)->getNativeBinary(pSize, pGraphNativeBinary)); } +ze_result_t ZE_APICALL zeGraphGetNativeBinary2(ze_graph_handle_t hGraph, + size_t *pSize, + const uint8_t **pGraphNativeBinary) { + if (hGraph == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (pSize == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (pGraphNativeBinary == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + } + + L0_HANDLE_EXCEPTION_AND_RETURN( + L0::Graph::fromHandle(hGraph)->getNativeBinary2(pSize, pGraphNativeBinary)); +} + ze_result_t ZE_APICALL zeDeviceGetGraphProperties(ze_device_handle_t hDevice, ze_device_graph_properties_t *pDeviceGraphProperties) { @@ -502,193 +507,3 @@ zeGraphProfilingLogGetString(ze_graph_profiling_query_handle_t hProfilingQuery, } } // namespace L0 - -extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphCreate(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - const ze_graph_desc_t *pDesc, - ze_graph_handle_t *phGraph) { - return L0::zeGraphCreate(hContext, hDevice, pDesc, phGraph); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphDestroy(ze_graph_handle_t hGraph) { - return L0::zeGraphDestroy(hGraph); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphGetProperties(ze_graph_handle_t hGraph, - ze_graph_properties_t *pGraphProperties) { - return L0::zeGraphGetProperties(hGraph, pGraphProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphGetArgumentProperties(ze_graph_handle_t hGraph, - uint32_t argIndex, - ze_graph_argument_properties_t *pGraphArgumentProperties) { - return L0::zeGraphGetArgumentProperties(hGraph, argIndex, pGraphArgumentProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphSetArgumentValue(ze_graph_handle_t hGraph, - uint32_t argIndex, - const void *pArgValue) { - return L0::zeGraphSetArgumentValue(hGraph, argIndex, pArgValue); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeAppendGraphInitialize(ze_command_list_handle_t hCommandList, - ze_graph_handle_t hGraph, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeAppendGraphInitialize(hCommandList, - hGraph, - hSignalEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeAppendGraphExecute(ze_command_list_handle_t hCommandList, - ze_graph_handle_t hGraph, - ze_graph_profiling_query_handle_t hProfilingQuery, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zeAppendGraphExecute(hCommandList, - hGraph, - hProfilingQuery, - hSignalEvent, - numWaitEvents, - phWaitEvents); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphGetNativeBinary(ze_graph_handle_t hGraph, - size_t *pSize, - uint8_t *pGraphNativeBinary) { - return L0::zeGraphGetNativeBinary(hGraph, pSize, pGraphNativeBinary); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetGraphProperties(ze_device_handle_t hDevice, - ze_device_graph_properties_t *pDeviceGraphProperties) { - return L0::zeDeviceGetGraphProperties(hDevice, pDeviceGraphProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetGraphProperties2(ze_device_handle_t hDevice, - ze_device_graph_properties_2_t *pDeviceGraphProperties2) { - return L0::zeDeviceGetGraphProperties2(hDevice, pDeviceGraphProperties2); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphGetArgumentMetadata(ze_graph_handle_t hGraph, - uint32_t argIndex, - ze_graph_argument_metadata_t *pGraphArgumentMetadata) { - return L0::zeGraphGetArgumentMetadata(hGraph, argIndex, pGraphArgumentMetadata); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphGetArgumentProperties2(ze_graph_handle_t hGraph, - uint32_t argIndex, - ze_graph_argument_properties_2_t *pGraphArgumentProperties) { - return L0::zeGraphGetArgumentProperties2(hGraph, argIndex, pGraphArgumentProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphGetArgumentProperties3(ze_graph_handle_t hGraph, - uint32_t argIndex, - ze_graph_argument_properties_3_t *pGraphArgumentProperties) { - return L0::zeGraphGetArgumentProperties3(hGraph, argIndex, pGraphArgumentProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphQueryNetworkCreate(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - const ze_graph_desc_t *desc, - ze_graph_query_network_handle_t *phGraphQueryNetwork) { - return L0::zeGraphQueryNetworkCreate(hContext, hDevice, desc, phGraphQueryNetwork); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphQueryNetworkDestroy(ze_graph_query_network_handle_t hGraphQueryNetwork) { - return L0::zeGraphQueryNetworkDestroy(hGraphQueryNetwork); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphQueryNetworkGetSupportedLayers(ze_graph_query_network_handle_t hGraphQueryNetwork, - size_t *pSize, - char *pSupportedLayers) { - return L0::zeGraphQueryNetworkGetSupportedLayers(hGraphQueryNetwork, pSize, pSupportedLayers); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphBuildLogGetString(ze_graph_handle_t hGraph, - uint32_t *pSize, - char *pBuildLog) { - return L0::zeGraphBuildLogGetString(hGraph, pSize, pBuildLog); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphCreate2(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - const ze_graph_desc_2_t *desc, - ze_graph_handle_t *phGraph) { - return L0::zeGraphCreate2(hContext, hDevice, desc, phGraph); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphQueryNetworkCreate2(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - const ze_graph_desc_2_t *desc, - ze_graph_query_network_handle_t *phGraphQueryNetwork) { - return L0::zeGraphQueryNetworkCreate2(hContext, hDevice, desc, phGraphQueryNetwork); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphQueryContextMemory(ze_context_handle_t hContext, - ze_graph_memory_query_type_t type, - ze_graph_memory_query_t *query) { - return L0::zeGraphQueryContextMemory(hContext, type, query); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphProfilingPoolCreate(ze_graph_handle_t hGraph, - uint32_t count, - ze_graph_profiling_pool_handle_t *phProfilingPool) { - return L0::zeGraphProfilingPoolCreate(hGraph, count, phProfilingPool); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphProfilingPoolDestroy(ze_graph_profiling_pool_handle_t hProfilingPool) { - return L0::zeGraphProfilingPoolDestroy(hProfilingPool); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphProfilingQueryCreate(ze_graph_profiling_pool_handle_t hProfilingPool, - uint32_t index, - ze_graph_profiling_query_handle_t *phProfilingQuery) { - return L0::zeGraphProfilingQueryCreate(hProfilingPool, index, phProfilingQuery); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphProfilingQueryDestroy(ze_graph_profiling_query_handle_t hProfilingQuery) { - return L0::zeGraphProfilingQueryDestroy(hProfilingQuery); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphProfilingQueryGetData(ze_graph_profiling_query_handle_t hProfilingQuery, - ze_graph_profiling_type_t type, - uint32_t *pSize, - uint8_t *pData) { - return L0::zeGraphProfilingQueryGetData(hProfilingQuery, type, pSize, pData); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDeviceGetProfilingDataProperties( - ze_device_handle_t hDevice, - ze_device_profiling_data_properties_t *pDeviceProfilingDataProperties) { - return L0::zeDeviceGetProfilingDataProperties(hDevice, pDeviceProfilingDataProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeGraphProfilingLogGetString(ze_graph_profiling_query_handle_t hProfilingQuery, - uint32_t *pSize, - char *pProfilingLog) { - return L0::zeGraphProfilingLogGetString(hProfilingQuery, pSize, pProfilingLog); -} - -} // extern "C" diff --git a/umd/level_zero_driver/api/ext/ze_graph.hpp b/umd/level_zero_driver/api/ext/ze_graph.hpp index ee735c2..7fdd74b 100644 --- a/umd/level_zero_driver/api/ext/ze_graph.hpp +++ b/umd/level_zero_driver/api/ext/ze_graph.hpp @@ -26,6 +26,9 @@ ze_result_t ZE_APICALL zeGraphDestroy(ze_graph_handle_t hGraph); ze_result_t ZE_APICALL zeGraphGetProperties(ze_graph_handle_t hGraph, ze_graph_properties_t *pGraphProperties); +ze_result_t ZE_APICALL zeGraphGetProperties2(ze_graph_handle_t hGraph, + ze_graph_properties_2_t *pGraphProperties); + ze_result_t ZE_APICALL zeGraphGetArgumentProperties(ze_graph_handle_t hGraph, uint32_t argIndex, @@ -41,6 +44,8 @@ ze_result_t ZE_APICALL zeAppendGraphInitialize(ze_command_list_handle_t hCommand uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents); +ze_result_t ZE_APICALL zeGraphInitialize(ze_graph_handle_t hGraph); + ze_result_t ZE_APICALL zeAppendGraphExecute(ze_command_list_handle_t hCommandList, ze_graph_handle_t hGraph, ze_graph_profiling_query_handle_t hProfilingQuery, @@ -52,6 +57,10 @@ ze_result_t ZE_APICALL zeGraphGetNativeBinary(ze_graph_handle_t hGraph, size_t *pSize, uint8_t *pGraphNativeBinary); +ze_result_t ZE_APICALL zeGraphGetNativeBinary2(ze_graph_handle_t hGraph, + size_t *pSize, + const uint8_t **pGraphNativeBinary); + ze_result_t ZE_APICALL zeDeviceGetGraphProperties(ze_device_handle_t hDevice, ze_device_graph_properties_t *pDeviceGraphProperties); diff --git a/umd/level_zero_driver/api/ext/ze_queue.cpp b/umd/level_zero_driver/api/ext/ze_queue.cpp new file mode 100644 index 0000000..0f9b325 --- /dev/null +++ b/umd/level_zero_driver/api/ext/ze_queue.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero_driver/api/ext/ze_queue.hpp" + +#include "level_zero_driver/api/zet_misc.hpp" +#include "level_zero_driver/core/source/cmdqueue/cmdqueue.hpp" +#include "level_zero_driver/include/l0_exception.hpp" + +#include +#include +#include + +namespace L0 { +ze_result_t ZE_APICALL +zeCommandQueueSetWorkloadType(ze_command_queue_handle_t hCommandQueue, + ze_command_queue_workload_type_t workloadType) { + if (hCommandQueue == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + auto result = translateHandle(ZEL_HANDLE_COMMAND_LIST, hCommandQueue); + if (result != ZE_RESULT_SUCCESS) { + return result; + } + + L0_HANDLE_EXCEPTION_AND_RETURN( + CommandQueue::fromHandle(hCommandQueue)->setWorkloadType(workloadType)); +} + +} // namespace L0 diff --git a/umd/level_zero_driver/api/ext/ze_queue.hpp b/umd/level_zero_driver/api/ext/ze_queue.hpp new file mode 100644 index 0000000..c480042 --- /dev/null +++ b/umd/level_zero_driver/api/ext/ze_queue.hpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "level_zero/ze_api.h" +#include "level_zero/ze_command_queue_npu_ext.h" + +namespace L0 { + +ze_result_t ZE_APICALL zeCommandQueueSetWorkloadType(ze_command_queue_handle_t hCommandQueue, + ze_command_queue_workload_type_t workloadType); + +} // namespace L0 diff --git a/umd/level_zero_driver/api/tools/CMakeLists.txt b/umd/level_zero_driver/api/tools/CMakeLists.txt deleted file mode 100644 index f368c7d..0000000 --- a/umd/level_zero_driver/api/tools/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -# Copyright (C) 2022 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -target_sources(${TARGET_NAME_L0} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/zet_metric.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ze_tools_loader.cpp -) diff --git a/umd/level_zero_driver/api/tools/ze_tools_api_tables.hpp b/umd/level_zero_driver/api/tools/ze_tools_api_tables.hpp deleted file mode 100644 index 1c85432..0000000 --- a/umd/level_zero_driver/api/tools/ze_tools_api_tables.hpp +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2022 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "zet_metric.hpp" diff --git a/umd/level_zero_driver/api/tools/ze_tools_loader.cpp b/umd/level_zero_driver/api/tools/ze_tools_loader.cpp deleted file mode 100644 index bb61537..0000000 --- a/umd/level_zero_driver/api/tools/ze_tools_loader.cpp +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include - -#include "level_zero/loader/ze_loader.h" -#include "level_zero_driver/api/tools/zet_metric.hpp" - -#include -#include -#include -#include - -#if defined(__cplusplus) -extern "C" { -#endif -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's Device table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetDeviceProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_device_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnGetDebugProperties = nullptr; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's Context table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetContextProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_context_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnActivateMetricGroups = L0::zetContextActivateMetricGroups; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's CommandList table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetCommandListProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_command_list_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnAppendMetricStreamerMarker = L0::zetCommandListAppendMetricStreamerMarker; - - pDdiTable->pfnAppendMetricQueryBegin = L0::zetCommandListAppendMetricQueryBegin; - - pDdiTable->pfnAppendMetricQueryEnd = L0::zetCommandListAppendMetricQueryEnd; - - pDdiTable->pfnAppendMetricMemoryBarrier = L0::zetCommandListAppendMetricMemoryBarrier; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's Kernel table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetKernelProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_kernel_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnGetProfileInfo = nullptr; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's Module table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetModuleProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_module_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnGetDebugInfo = nullptr; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's Debug table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetDebugProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_debug_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnAttach = nullptr; - - pDdiTable->pfnDetach = nullptr; - - pDdiTable->pfnReadEvent = nullptr; - - pDdiTable->pfnAcknowledgeEvent = nullptr; - - pDdiTable->pfnInterrupt = nullptr; - - pDdiTable->pfnResume = nullptr; - - pDdiTable->pfnReadMemory = nullptr; - - pDdiTable->pfnWriteMemory = nullptr; - - pDdiTable->pfnGetRegisterSetProperties = nullptr; - - pDdiTable->pfnReadRegisters = nullptr; - - pDdiTable->pfnWriteRegisters = nullptr; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's Metric table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_metric_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnGet = L0::zetMetricGet; - - pDdiTable->pfnGetProperties = L0::zetMetricGetProperties; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's MetricGroup table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricGroupProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_metric_group_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnGet = L0::zetMetricGroupGet; - - pDdiTable->pfnGetProperties = L0::zetMetricGroupGetProperties; - - pDdiTable->pfnCalculateMetricValues = L0::zetMetricGroupCalculateMetricValues; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's MetricQuery table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricQueryProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_metric_query_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnCreate = L0::zetMetricQueryCreate; - - pDdiTable->pfnDestroy = L0::zetMetricQueryDestroy; - - pDdiTable->pfnReset = L0::zetMetricQueryReset; - - pDdiTable->pfnGetData = L0::zetMetricQueryGetData; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's MetricQueryPool table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricQueryPoolProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_metric_query_pool_dditable_t - *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnCreate = L0::zetMetricQueryPoolCreate; - - pDdiTable->pfnDestroy = L0::zetMetricQueryPoolDestroy; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's MetricStreamer table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricStreamerProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_metric_streamer_dditable_t - *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnOpen = L0::zetMetricStreamerOpen; - - pDdiTable->pfnClose = L0::zetMetricStreamerClose; - - pDdiTable->pfnReadData = L0::zetMetricStreamerReadData; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's TracerExp table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetTracerExpProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zet_tracer_exp_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnCreate = nullptr; - - pDdiTable->pfnDestroy = nullptr; - - pDdiTable->pfnSetPrologues = nullptr; - - pDdiTable->pfnSetEpilogues = nullptr; - - pDdiTable->pfnSetEnabled = nullptr; - - return result; -} -#if defined(__cplusplus) -} -#endif - -namespace L0 { - -void *getLoaderHandle() { - static void *loaderHandle = dlopen("libze_loader.so.1", RTLD_LAZY | RTLD_LOCAL); - return loaderHandle; -} - -std::string getLoaderVersion() { - std::string version = "not available"; - void *loaderHandle = getLoaderHandle(); - - if (loaderHandle == nullptr) { - return version; - } - - static void *functionPointer = dlsym(loaderHandle, "zelLoaderGetVersions"); - if (functionPointer == nullptr) { - return version; - } - - zel_component_version_t loaderVersion; - size_t num = 1; - static auto *pLoaderGetVersions = - reinterpret_cast(functionPointer); - if (pLoaderGetVersions(&num, &loaderVersion) != ZE_RESULT_SUCCESS) { - return version; - } - - version = std::to_string(loaderVersion.component_lib_version.major) + "."; - version += std::to_string(loaderVersion.component_lib_version.minor) + "."; - version += std::to_string(loaderVersion.component_lib_version.patch); - return version; -} -} // namespace L0 diff --git a/umd/level_zero_driver/api/tools/ze_tools_loader.h b/umd/level_zero_driver/api/tools/ze_tools_loader.h deleted file mode 100644 index 77afeef..0000000 --- a/umd/level_zero_driver/api/tools/ze_tools_loader.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include - -#pragma once - -namespace L0 { -void *getLoaderHandle(); -std::string getLoaderVersion(); -} // namespace L0 diff --git a/umd/level_zero_driver/api/ze_cmdlist.cpp b/umd/level_zero_driver/api/ze_cmdlist.cpp new file mode 100644 index 0000000..781946e --- /dev/null +++ b/umd/level_zero_driver/api/ze_cmdlist.cpp @@ -0,0 +1,337 @@ +/* + * Copyright (C) 2022-2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include +#include + +#include "level_zero_driver/core/source/cmdlist/cmdlist.hpp" +#include "level_zero_driver/core/source/cmdlist/immediate_cmdlist.hpp" +#include "level_zero_driver/core/source/context/context.hpp" +#include "level_zero_driver/include/l0_exception.hpp" + +#include +#include + +namespace L0 { +ze_result_t zeCommandListAppendBarrier(ze_command_list_handle_t hCommandList, + ze_event_handle_t hSignalEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + L0_HANDLE_EXCEPTION_AND_RETURN(L0::CommandList::fromHandle(hCommandList) + ->appendBarrier(hSignalEvent, numWaitEvents, phWaitEvents)); +} + +ze_result_t zeCommandListAppendMemoryRangesBarrier(ze_command_list_handle_t hCommandList, + uint32_t numRanges, + const size_t *pRangeSizes, + const void **pRanges, + ze_event_handle_t hSignalEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListCreate(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + const ze_command_list_desc_t *desc, + ze_command_list_handle_t *phCommandList) { + L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::create(hContext, hDevice, desc, phCommandList)); +} + +ze_result_t zeCommandListCreateImmediate(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + const ze_command_queue_desc_t *altdesc, + ze_command_list_handle_t *phCommandList) { + L0_HANDLE_EXCEPTION_AND_RETURN( + ImmediateCommandList::create(hContext, hDevice, altdesc, phCommandList)); +} + +ze_result_t zeCommandListImmediateGetIndex(ze_command_list_handle_t hCommandListImmediate, + uint32_t *pIndex) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListIsImmediate(ze_command_list_handle_t hCommandList, + ze_bool_t *pIsImmediate) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + CommandList::fromHandle(hCommandList)->isImmediate(pIsImmediate)); +} + +ze_result_t zeCommandListHostSynchronize(ze_command_list_handle_t hCommandList, uint64_t timeout) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + ImmediateCommandList::fromHandle(hCommandList)->hostSynchronize(timeout)); +} + +ze_result_t zeCommandListDestroy(ze_command_list_handle_t hCommandList) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList)->destroy()); +} + +ze_result_t zeCommandListClose(ze_command_list_handle_t hCommandList) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList)->close()); +} + +ze_result_t zeCommandListReset(ze_command_list_handle_t hCommandList) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList)->reset()); +} + +ze_result_t zeCommandListAppendMemoryCopy(ze_command_list_handle_t hCommandList, + void *dstptr, + const void *srcptr, + size_t size, + ze_event_handle_t hEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + L0::CommandList::fromHandle(hCommandList) + ->appendMemoryCopy(dstptr, srcptr, size, hEvent, numWaitEvents, phWaitEvents)); +} + +ze_result_t zeCommandListAppendMemoryFill(ze_command_list_handle_t hCommandList, + void *ptr, + const void *pattern, + size_t patternSize, + size_t size, + ze_event_handle_t hEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(L0::CommandList::fromHandle(hCommandList) + ->appendMemoryFill(ptr, + pattern, + patternSize, + size, + hEvent, + numWaitEvents, + phWaitEvents)); +} + +ze_result_t zeCommandListAppendMemoryCopyRegion(ze_command_list_handle_t hCommandList, + void *dstptr, + const ze_copy_region_t *dstRegion, + uint32_t dstPitch, + uint32_t dstSlicePitch, + const void *srcptr, + const ze_copy_region_t *srcRegion, + uint32_t srcPitch, + uint32_t srcSlicePitch, + ze_event_handle_t hEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListAppendImageCopy(ze_command_list_handle_t hCommandList, + ze_image_handle_t hDstImage, + ze_image_handle_t hSrcImage, + ze_event_handle_t hEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListAppendImageCopyRegion(ze_command_list_handle_t hCommandList, + ze_image_handle_t hDstImage, + ze_image_handle_t hSrcImage, + const ze_image_region_t *pDstRegion, + const ze_image_region_t *pSrcRegion, + ze_event_handle_t hEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListAppendImageCopyToMemory(ze_command_list_handle_t hCommandList, + void *dstptr, + ze_image_handle_t hSrcImage, + const ze_image_region_t *pSrcRegion, + ze_event_handle_t hEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListAppendImageCopyFromMemory(ze_command_list_handle_t hCommandList, + ze_image_handle_t hDstImage, + const void *srcptr, + const ze_image_region_t *pDstRegion, + ze_event_handle_t hEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListAppendMemoryPrefetch(ze_command_list_handle_t hCommandList, + const void *ptr, + size_t size) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListAppendMemAdvise(ze_command_list_handle_t hCommandList, + ze_device_handle_t hDevice, + const void *ptr, + size_t size, + ze_memory_advice_t advice) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListAppendMemoryCopyFromContext(ze_command_list_handle_t hCommandList, + void *dstptr, + ze_context_handle_t hContextSrc, + const void *srcptr, + size_t size, + ze_event_handle_t hSignalEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListAppendWriteGlobalTimestamp(ze_command_list_handle_t hCommandList, + uint64_t *dstptr, + ze_event_handle_t hSignalEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + CommandList::fromHandle(hCommandList) + ->appendWriteGlobalTimestamp(dstptr, hSignalEvent, numWaitEvents, phWaitEvents)); +} + +ze_result_t zeCommandListAppendQueryKernelTimestamps(ze_command_list_handle_t hCommandList, + uint32_t numEvents, + ze_event_handle_t *phEvents, + void *dstptr, + const size_t *pOffsets, + ze_event_handle_t hSignalEvent, + uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeCommandListGetNextCommandIdExp(ze_command_list_handle_t hCommandList, + const ze_mutable_command_id_exp_desc_t *desc, + uint64_t *pCommandId) { + L0_HANDLE_EXCEPTION_AND_RETURN( + CommandList::fromHandle(hCommandList)->getNextCommandId(desc, pCommandId)); +} + +ze_result_t zeCommandListUpdateMutableCommandsExp(ze_command_list_handle_t hCommandList, + const ze_mutable_commands_exp_desc_t *desc) { + L0_HANDLE_EXCEPTION_AND_RETURN( + CommandList::fromHandle(hCommandList)->updateMutableCommands(desc)); +} + +ze_result_t zeCommandListAppendSignalEvent(ze_command_list_handle_t hCommandList, + ze_event_handle_t hEvent) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + CommandList::fromHandle(hCommandList)->CommandList::appendSignalEvent(hEvent)); +} + +ze_result_t zeCommandListAppendWaitOnEvents(ze_command_list_handle_t hCommandList, + uint32_t numEvents, + ze_event_handle_t *phEvents) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList) + ->CommandList::appendWaitOnEvents(numEvents, phEvents)); +} + +ze_result_t zeCommandListAppendEventReset(ze_command_list_handle_t hCommandList, + ze_event_handle_t hEvent) { + if (hCommandList == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(CommandList::fromHandle(hCommandList)->appendEventReset(hEvent)); +} +} // namespace L0 + +extern "C" { +ZE_APIEXPORT ze_result_t ZE_APICALL +zeGetCommandListProcAddrTable(ze_api_version_t version, ze_command_list_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnAppendBarrier = L0::zeCommandListAppendBarrier; + pDdiTable->pfnAppendMemoryRangesBarrier = L0::zeCommandListAppendMemoryRangesBarrier; + pDdiTable->pfnCreate = L0::zeCommandListCreate; + pDdiTable->pfnCreateImmediate = L0::zeCommandListCreateImmediate; + pDdiTable->pfnImmediateGetIndex = L0::zeCommandListImmediateGetIndex; + pDdiTable->pfnIsImmediate = L0::zeCommandListIsImmediate; + pDdiTable->pfnHostSynchronize = L0::zeCommandListHostSynchronize; + pDdiTable->pfnDestroy = L0::zeCommandListDestroy; + pDdiTable->pfnClose = L0::zeCommandListClose; + pDdiTable->pfnReset = L0::zeCommandListReset; + pDdiTable->pfnAppendMemoryCopy = L0::zeCommandListAppendMemoryCopy; + pDdiTable->pfnAppendMemoryCopyRegion = L0::zeCommandListAppendMemoryCopyRegion; + pDdiTable->pfnAppendMemoryFill = L0::zeCommandListAppendMemoryFill; + pDdiTable->pfnAppendImageCopy = L0::zeCommandListAppendImageCopy; + pDdiTable->pfnAppendImageCopyRegion = L0::zeCommandListAppendImageCopyRegion; + pDdiTable->pfnAppendImageCopyToMemory = L0::zeCommandListAppendImageCopyToMemory; + pDdiTable->pfnAppendImageCopyFromMemory = L0::zeCommandListAppendImageCopyFromMemory; + pDdiTable->pfnAppendMemoryPrefetch = L0::zeCommandListAppendMemoryPrefetch; + pDdiTable->pfnAppendMemAdvise = L0::zeCommandListAppendMemAdvise; + pDdiTable->pfnAppendSignalEvent = L0::zeCommandListAppendSignalEvent; + pDdiTable->pfnAppendWaitOnEvents = L0::zeCommandListAppendWaitOnEvents; + pDdiTable->pfnAppendEventReset = L0::zeCommandListAppendEventReset; + pDdiTable->pfnAppendLaunchCooperativeKernel = + nullptr; // zeCommandListAppendLaunchCooperativeKernel + pDdiTable->pfnAppendLaunchKernelIndirect = nullptr; // zeCommandListAppendLaunchKernelIndirect + pDdiTable->pfnAppendLaunchMultipleKernelsIndirect = + nullptr; // zeCommandListAppendLaunchMultipleKernelsIndirect + pDdiTable->pfnAppendWriteGlobalTimestamp = L0::zeCommandListAppendWriteGlobalTimestamp; + pDdiTable->pfnAppendMemoryCopyFromContext = L0::zeCommandListAppendMemoryCopyFromContext; + pDdiTable->pfnAppendQueryKernelTimestamps = L0::zeCommandListAppendQueryKernelTimestamps; + return ZE_RESULT_SUCCESS; +} + +ZE_DLLEXPORT ze_result_t ZE_APICALL +zeGetCommandListExpProcAddrTable(ze_api_version_t version, + ze_command_list_exp_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnGetNextCommandIdExp = L0::zeCommandListGetNextCommandIdExp; + pDdiTable->pfnUpdateMutableCommandsExp = L0::zeCommandListUpdateMutableCommandsExp; + + return ZE_RESULT_SUCCESS; +} +} diff --git a/umd/level_zero_driver/api/core/ze_cmdqueue.hpp b/umd/level_zero_driver/api/ze_cmdqueue.cpp similarity index 60% rename from umd/level_zero_driver/api/core/ze_cmdqueue.hpp rename to umd/level_zero_driver/api/ze_cmdqueue.cpp index e6ae182..7d153ea 100644 --- a/umd/level_zero_driver/api/core/ze_cmdqueue.hpp +++ b/umd/level_zero_driver/api/ze_cmdqueue.cpp @@ -5,12 +5,15 @@ * */ -#pragma once +#include #include "level_zero_driver/core/source/cmdqueue/cmdqueue.hpp" #include "level_zero_driver/core/source/context/context.hpp" +#include "level_zero_driver/core/source/fence/fence.hpp" #include "level_zero_driver/include/l0_exception.hpp" + #include +#include namespace L0 { ze_result_t zeCommandQueueCreate(ze_context_handle_t hContext, @@ -51,30 +54,17 @@ ze_result_t zeCommandQueueSynchronize(ze_command_queue_handle_t hCommandQueue, u extern "C" { ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandQueueCreate(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - const ze_command_queue_desc_t *desc, - ze_command_queue_handle_t *phCommandQueue) { - return L0::zeCommandQueueCreate(hContext, hDevice, desc, phCommandQueue); -} +zeGetCommandQueueProcAddrTable(ze_api_version_t version, ze_command_queue_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; -ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandQueueDestroy(ze_command_queue_handle_t hCommandQueue) { - return L0::zeCommandQueueDestroy(hCommandQueue); -} + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandQueueExecuteCommandLists(ze_command_queue_handle_t hCommandQueue, - uint32_t numCommandLists, - ze_command_list_handle_t *phCommandLists, - ze_fence_handle_t hFence) { - return L0::zeCommandQueueExecuteCommandLists(hCommandQueue, - numCommandLists, - phCommandLists, - hFence); + pDdiTable->pfnCreate = L0::zeCommandQueueCreate; + pDdiTable->pfnDestroy = L0::zeCommandQueueDestroy; + pDdiTable->pfnExecuteCommandLists = L0::zeCommandQueueExecuteCommandLists; + pDdiTable->pfnSynchronize = L0::zeCommandQueueSynchronize; + return ZE_RESULT_SUCCESS; } - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeCommandQueueSynchronize(ze_command_queue_handle_t hCommandQueue, uint64_t timeout) { - return L0::zeCommandQueueSynchronize(hCommandQueue, timeout); } -} // extern "C" diff --git a/umd/level_zero_driver/api/ze_context.cpp b/umd/level_zero_driver/api/ze_context.cpp new file mode 100644 index 0000000..085e06d --- /dev/null +++ b/umd/level_zero_driver/api/ze_context.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2022-2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include + +#include "level_zero_driver/core/source/context/context.hpp" +#include "level_zero_driver/core/source/device/device.hpp" +#include "level_zero_driver/core/source/driver/driver_handle.hpp" +#include "level_zero_driver/include/l0_exception.hpp" + +#include +#include + +namespace L0 { +ze_result_t zeContextCreate(ze_driver_handle_t hDriver, + const ze_context_desc_t *desc, + ze_context_handle_t *phContext) { + if (hDriver == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + L0::DriverHandle::fromHandle(hDriver)->createContext(desc, phContext)); +} + +ze_result_t zeContextDestroy(ze_context_handle_t hContext) { + if (hContext == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(L0::Context::fromHandle(hContext)->destroy()); +} + +ze_result_t zeContextGetStatus(ze_context_handle_t hContext) { + if (hContext == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(L0::Context::fromHandle(hContext)->getStatus()); +} + +ze_result_t +zeVirtualMemReserve(ze_context_handle_t hContext, const void *pStart, size_t size, void **pptr) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeVirtualMemFree(ze_context_handle_t hContext, const void *ptr, size_t size) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeVirtualMemQueryPageSize(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + size_t size, + size_t *pagesize) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zePhysicalMemCreate(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + ze_physical_mem_desc_t *desc, + ze_physical_mem_handle_t *phPhysicalMemory) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zePhysicalMemDestroy(ze_context_handle_t hContext, + ze_physical_mem_handle_t hPhysicalMemory) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeVirtualMemMap(ze_context_handle_t hContext, + const void *ptr, + size_t size, + ze_physical_mem_handle_t hPhysicalMemory, + size_t offset, + ze_memory_access_attribute_t access) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeVirtualMemUnmap(ze_context_handle_t hContext, const void *ptr, size_t size) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeVirtualMemSetAccessAttribute(ze_context_handle_t hContext, + const void *ptr, + size_t size, + ze_memory_access_attribute_t access) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeVirtualMemGetAccessAttribute(ze_context_handle_t hContext, + const void *ptr, + size_t size, + ze_memory_access_attribute_t *access, + size_t *outSize) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeContextSystemBarrier(ze_context_handle_t hContext, ze_device_handle_t hDevice) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeContextMakeMemoryResident(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + void *ptr, + size_t size) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeContextEvictMemory(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + void *ptr, + size_t size) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeContextMakeImageResident(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + ze_image_handle_t hImage) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeContextEvictImage(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + ze_image_handle_t hImage) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} +} // namespace L0 + +extern "C" { +ZE_DLLEXPORT ze_result_t ZE_APICALL zeGetContextProcAddrTable(ze_api_version_t version, + ze_context_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnCreate = L0::zeContextCreate; + pDdiTable->pfnDestroy = L0::zeContextDestroy; + pDdiTable->pfnGetStatus = L0::zeContextGetStatus; + pDdiTable->pfnSystemBarrier = L0::zeContextSystemBarrier; + pDdiTable->pfnMakeMemoryResident = L0::zeContextMakeMemoryResident; + pDdiTable->pfnEvictMemory = L0::zeContextEvictMemory; + pDdiTable->pfnMakeImageResident = L0::zeContextMakeImageResident; + pDdiTable->pfnEvictImage = L0::zeContextEvictImage; + return ZE_RESULT_SUCCESS; +} + +ZE_DLLEXPORT ze_result_t ZE_APICALL +zeGetPhysicalMemProcAddrTable(ze_api_version_t version, ze_physical_mem_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnCreate = L0::zePhysicalMemCreate; + pDdiTable->pfnDestroy = L0::zePhysicalMemDestroy; + return ZE_RESULT_SUCCESS; +} + +ZE_DLLEXPORT ze_result_t ZE_APICALL +zeGetVirtualMemProcAddrTable(ze_api_version_t version, ze_virtual_mem_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnReserve = L0::zeVirtualMemReserve; + pDdiTable->pfnFree = L0::zeVirtualMemFree; + pDdiTable->pfnQueryPageSize = L0::zeVirtualMemQueryPageSize; + pDdiTable->pfnMap = L0::zeVirtualMemMap; + pDdiTable->pfnUnmap = L0::zeVirtualMemUnmap; + pDdiTable->pfnSetAccessAttribute = L0::zeVirtualMemSetAccessAttribute; + pDdiTable->pfnGetAccessAttribute = L0::zeVirtualMemGetAccessAttribute; + return ZE_RESULT_SUCCESS; +} +} diff --git a/umd/level_zero_driver/api/core/ze_device.hpp b/umd/level_zero_driver/api/ze_device.cpp similarity index 56% rename from umd/level_zero_driver/api/core/ze_device.hpp rename to umd/level_zero_driver/api/ze_device.cpp index d5372b1..a2d060b 100644 --- a/umd/level_zero_driver/api/core/ze_device.hpp +++ b/umd/level_zero_driver/api/ze_device.cpp @@ -5,12 +5,12 @@ * */ -#pragma once +#include #include "level_zero_driver/core/source/device/device.hpp" -#include "level_zero_driver/core/source/driver/driver.hpp" #include "level_zero_driver/core/source/driver/driver_handle.hpp" #include "level_zero_driver/include/l0_exception.hpp" + #include #include @@ -158,102 +158,30 @@ ze_result_t zeDevicePciGetPropertiesExt(ze_device_handle_t hDevice, } // namespace L0 extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zeDeviceGet(ze_driver_handle_t hDriver, - uint32_t *pCount, - ze_device_handle_t *phDevices) { - return L0::zeDeviceGet(hDriver, pCount, phDevices); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDeviceGetSubDevices(ze_device_handle_t hDevice, - uint32_t *pCount, - ze_device_handle_t *phSubdevices) { - return L0::zeDeviceGetSubDevices(hDevice, pCount, phSubdevices); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetProperties(ze_device_handle_t hDevice, ze_device_properties_t *pDeviceProperties) { - return L0::zeDeviceGetProperties(hDevice, pDeviceProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetComputeProperties(ze_device_handle_t hDevice, - ze_device_compute_properties_t *pComputeProperties) { - return L0::zeDeviceGetComputeProperties(hDevice, pComputeProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetModuleProperties(ze_device_handle_t hDevice, - ze_device_module_properties_t *pKernelProperties) { - return L0::zeDeviceGetModuleProperties(hDevice, pKernelProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetMemoryProperties(ze_device_handle_t hDevice, - uint32_t *pCount, - ze_device_memory_properties_t *pMemProperties) { - return L0::zeDeviceGetMemoryProperties(hDevice, pCount, pMemProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetMemoryAccessProperties(ze_device_handle_t hDevice, - ze_device_memory_access_properties_t *pMemAccessProperties) { - return L0::zeDeviceGetMemoryAccessProperties(hDevice, pMemAccessProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetCacheProperties(ze_device_handle_t hDevice, - uint32_t *pCount, - ze_device_cache_properties_t *pCacheProperties) { - return L0::zeDeviceGetCacheProperties(hDevice, pCount, pCacheProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetImageProperties(ze_device_handle_t hDevice, - ze_device_image_properties_t *pImageProperties) { - return L0::zeDeviceGetImageProperties(hDevice, pImageProperties); +ZE_APIEXPORT ze_result_t ZE_APICALL zeGetDeviceProcAddrTable(ze_api_version_t version, + ze_device_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnGet = L0::zeDeviceGet; + pDdiTable->pfnGetCommandQueueGroupProperties = L0::zeDeviceGetCommandQueueGroupProperties; + pDdiTable->pfnGetSubDevices = L0::zeDeviceGetSubDevices; + pDdiTable->pfnGetProperties = L0::zeDeviceGetProperties; + pDdiTable->pfnGetComputeProperties = L0::zeDeviceGetComputeProperties; + pDdiTable->pfnGetModuleProperties = L0::zeDeviceGetModuleProperties; + pDdiTable->pfnGetMemoryProperties = L0::zeDeviceGetMemoryProperties; + pDdiTable->pfnGetMemoryAccessProperties = L0::zeDeviceGetMemoryAccessProperties; + pDdiTable->pfnGetCacheProperties = L0::zeDeviceGetCacheProperties; + pDdiTable->pfnGetImageProperties = L0::zeDeviceGetImageProperties; + pDdiTable->pfnGetP2PProperties = L0::zeDeviceGetP2PProperties; + pDdiTable->pfnCanAccessPeer = L0::zeDeviceCanAccessPeer; + pDdiTable->pfnGetStatus = L0::zeDeviceGetStatus; + pDdiTable->pfnGetGlobalTimestamps = L0::zeDeviceGetGlobalTimestamps; + pDdiTable->pfnGetExternalMemoryProperties = L0::zeDeviceGetExternalMemoryProperties; + pDdiTable->pfnPciGetPropertiesExt = L0::zeDevicePciGetPropertiesExt; + return ZE_RESULT_SUCCESS; } - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDeviceGetP2PProperties(ze_device_handle_t hDevice, - ze_device_handle_t hPeerDevice, - ze_device_p2p_properties_t *pP2PProperties) { - return L0::zeDeviceGetP2PProperties(hDevice, hPeerDevice, pP2PProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDeviceCanAccessPeer(ze_device_handle_t hDevice, - ze_device_handle_t hPeerDevice, - ze_bool_t *value) { - return L0::zeDeviceCanAccessPeer(hDevice, hPeerDevice, value); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDeviceGetCommandQueueGroupProperties( - ze_device_handle_t hDevice, - uint32_t *pCount, - ze_command_queue_group_properties_t *pCommandQueueGroupProperties) { - return L0::zeDeviceGetCommandQueueGroupProperties(hDevice, - pCount, - pCommandQueueGroupProperties); } - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDeviceGetExternalMemoryProperties( - ze_device_handle_t hDevice, - ze_device_external_memory_properties_t *pExternalMemoryProperties) { - return L0::zeDeviceGetExternalMemoryProperties(hDevice, pExternalMemoryProperties); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDeviceGetStatus(ze_device_handle_t hDevice) { - return L0::zeDeviceGetStatus(hDevice); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeDeviceGetGlobalTimestamps(ze_device_handle_t hDevice, - uint64_t *hostTimestamp, - uint64_t *deviceTimestamp) { - return L0::zeDeviceGetGlobalTimestamps(hDevice, hostTimestamp, deviceTimestamp); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeDevicePciGetPropertiesExt(ze_device_handle_t hDevice, ze_pci_ext_properties_t *pPciProperties) { - return L0::zeDevicePciGetPropertiesExt(hDevice, pPciProperties); -} - -} // extern "C" diff --git a/umd/level_zero_driver/api/ze_driver.cpp b/umd/level_zero_driver/api/ze_driver.cpp new file mode 100644 index 0000000..2966448 --- /dev/null +++ b/umd/level_zero_driver/api/ze_driver.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2022-2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include + +#include "level_zero_driver/api/ext/ze_graph.hpp" +#include "level_zero_driver/api/ext/ze_queue.hpp" +#include "level_zero_driver/core/source/driver/driver.hpp" +#include "level_zero_driver/core/source/driver/driver_handle.hpp" +#include "level_zero_driver/include/l0_exception.hpp" +#include "vpu_driver/source/utilities/log.hpp" + +#include +#include +#include +#include +#include +#include +#include + +namespace L0 { +ze_result_t zeInit(ze_init_flags_t flags) { + L0_HANDLE_EXCEPTION_AND_RETURN(L0::init(flags)); +} + +ze_result_t zeDriverGet(uint32_t *pCount, ze_driver_handle_t *phDrivers) { + L0_HANDLE_EXCEPTION_AND_RETURN(L0::driverHandleGet(pCount, phDrivers)); +} + +ze_result_t zeDriverGetProperties(ze_driver_handle_t hDriver, ze_driver_properties_t *pProperties) { + if (hDriver == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + L0::DriverHandle::fromHandle(hDriver)->getProperties(pProperties)); +} + +ze_result_t zeDriverGetApiVersion(ze_driver_handle_t hDriver, ze_api_version_t *version) { + if (hDriver == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(L0::DriverHandle::fromHandle(hDriver)->getApiVersion(version)); +} + +ze_result_t zeDriverGetIpcProperties(ze_driver_handle_t hDriver, + ze_driver_ipc_properties_t *pIPCProperties) { + if (hDriver == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + L0::DriverHandle::fromHandle(hDriver)->getIPCProperties(pIPCProperties)); +} + +ze_result_t zeDriverGetExtensionProperties(ze_driver_handle_t hDriver, + uint32_t *pCount, + ze_driver_extension_properties_t *pExtensionProperties) { + if (hDriver == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + std::array supportedExts = {{ + {ZE_GRAPH_EXT_NAME, ZE_GRAPH_EXT_VERSION_CURRENT}, + {ZE_PROFILING_DATA_EXT_NAME, ZE_PROFILING_DATA_EXT_VERSION_1_0}, + {ZE_MUTABLE_COMMAND_LIST_EXP_NAME, ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_0}, + {ZE_COMMAND_QUEUE_NPU_EXT_NAME, ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_0}, + {"ZE_extension_graph_1_2", ZE_GRAPH_EXT_VERSION_1_2}, + {"ZE_extension_graph_1_3", ZE_GRAPH_EXT_VERSION_1_3}, + {"ZE_extension_graph_1_4", ZE_GRAPH_EXT_VERSION_1_4}, + {"ZE_extension_graph_1_5", ZE_GRAPH_EXT_VERSION_1_5}, + {"ZE_extension_graph_1_6", ZE_GRAPH_EXT_VERSION_1_6}, + {"ZE_extension_graph_1_7", ZE_GRAPH_EXT_VERSION_1_7}, + {"ZE_extension_graph_1_8", ZE_GRAPH_EXT_VERSION_1_8}, + }}; + + if (pCount == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (*pCount == 0) { + *pCount = supportedExts.size(); + return ZE_RESULT_SUCCESS; + } + + if (*pCount > supportedExts.size()) + *pCount = supportedExts.size(); + + if (pExtensionProperties == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + } + + for (size_t i = 0; i < *pCount; i++) { + *pExtensionProperties = supportedExts[i]; + pExtensionProperties++; + } + + return ZE_RESULT_SUCCESS; +} + +ze_result_t zeDriverGetExtensionFunctionAddress(ze_driver_handle_t hDriver, + const char *name, + void **ppFunctionAddress) { + if (hDriver == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (name == nullptr || ppFunctionAddress == nullptr) { + LOG_E("Invalid name or ppFunctionAddress pointer"); + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (strcmp(name, ZE_PROFILING_DATA_EXT_NAME) == 0) { + static ze_graph_profiling_dditable_ext_t table; + table.pfnProfilingPoolCreate = L0::zeGraphProfilingPoolCreate; + table.pfnProfilingPoolDestroy = L0::zeGraphProfilingPoolDestroy; + table.pfnProfilingQueryCreate = L0::zeGraphProfilingQueryCreate; + table.pfnProfilingQueryDestroy = L0::zeGraphProfilingQueryDestroy; + table.pfnProfilingQueryGetData = L0::zeGraphProfilingQueryGetData; + table.pfnDeviceGetProfilingDataProperties = L0::zeDeviceGetProfilingDataProperties; + table.pfnProfilingLogGetString = L0::zeGraphProfilingLogGetString; + *ppFunctionAddress = reinterpret_cast(&table); + LOG(DRIVER, "Return DDI table for extension: %s", name); + return ZE_RESULT_SUCCESS; + } + + if (strcmp(name, ZE_COMMAND_QUEUE_NPU_EXT_NAME) == 0) { + static ze_command_queue_npu_dditable_ext_1_0_t table; + + table.pfnSetWorkloadType = L0::zeCommandQueueSetWorkloadType; + *ppFunctionAddress = reinterpret_cast(&table); + LOG(DRIVER, "Return DDI table for extension: %s", name); + return ZE_RESULT_SUCCESS; + } + + static ze_graph_dditable_ext_t table; + // version 1.0 + table.pfnCreate = L0::zeGraphCreate; + table.pfnDestroy = L0::zeGraphDestroy; + table.pfnGetNativeBinary = L0::zeGraphGetNativeBinary; + table.pfnGetProperties = L0::zeGraphGetProperties; + table.pfnGetArgumentProperties = L0::zeGraphGetArgumentProperties; + table.pfnSetArgumentValue = L0::zeGraphSetArgumentValue; + table.pfnAppendGraphInitialize = L0::zeAppendGraphInitialize; + table.pfnAppendGraphExecute = L0::zeAppendGraphExecute; + table.pfnDeviceGetGraphProperties = L0::zeDeviceGetGraphProperties; + + // version 1.1 + table.pfnGraphGetArgumentMetadata = L0::zeGraphGetArgumentMetadata; + table.pfnGetArgumentProperties2 = L0::zeGraphGetArgumentProperties2; + + // version 1.2 + table.pfnGetArgumentProperties3 = L0::zeGraphGetArgumentProperties3; + + // version 1.3 + table.pfnQueryNetworkCreate = L0::zeGraphQueryNetworkCreate; + table.pfnQueryNetworkDestroy = L0::zeGraphQueryNetworkDestroy; + table.pfnQueryNetworkGetSupportedLayers = L0::zeGraphQueryNetworkGetSupportedLayers; + + // version 1.4 + table.pfnBuildLogGetString = L0::zeGraphBuildLogGetString; + + // version 1.5 + table.pfnCreate2 = L0::zeGraphCreate2; + table.pfnQueryNetworkCreate2 = L0::zeGraphQueryNetworkCreate2; + table.pfnQueryContextMemory = L0::zeGraphQueryContextMemory; + + // version 1.6 + table.pfnDeviceGetGraphProperties2 = L0::zeDeviceGetGraphProperties2; + + // version 1.7 + table.pfnGetNativeBinary2 = L0::zeGraphGetNativeBinary2; + + // version 1.8 + table.pfnGetProperties2 = L0::zeGraphGetProperties2; + table.pfnGraphInitialize = L0::zeGraphInitialize; + + if (strstr(name, ZE_GRAPH_EXT_NAME) != nullptr) { + *ppFunctionAddress = reinterpret_cast(&table); + LOG(DRIVER, "Return DDI table for extension: %s", name); + return ZE_RESULT_SUCCESS; + } + + LOG_E("The name of extension is unknown: %s", name); + return ZE_RESULT_ERROR_UNKNOWN; +} +} // namespace L0 + +extern "C" { +ZE_APIEXPORT ze_result_t ZE_APICALL zeGetGlobalProcAddrTable(ze_api_version_t version, + ze_global_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnInit = L0::zeInit; + return ZE_RESULT_SUCCESS; +} + +ZE_APIEXPORT ze_result_t ZE_APICALL zeGetDriverProcAddrTable(ze_api_version_t version, + ze_driver_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnGet = L0::zeDriverGet; + pDdiTable->pfnGetApiVersion = L0::zeDriverGetApiVersion; + pDdiTable->pfnGetProperties = L0::zeDriverGetProperties; + pDdiTable->pfnGetIpcProperties = L0::zeDriverGetIpcProperties; + pDdiTable->pfnGetExtensionProperties = L0::zeDriverGetExtensionProperties; + pDdiTable->pfnGetExtensionFunctionAddress = L0::zeDriverGetExtensionFunctionAddress; + return ZE_RESULT_SUCCESS; +} +} diff --git a/umd/level_zero_driver/api/ze_event.cpp b/umd/level_zero_driver/api/ze_event.cpp new file mode 100644 index 0000000..1eea2ff --- /dev/null +++ b/umd/level_zero_driver/api/ze_event.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2022-2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include + +#include "level_zero_driver/core/source/event/event.hpp" +#include "level_zero_driver/core/source/event/eventpool.hpp" +#include "level_zero_driver/include/l0_exception.hpp" + +#include +#include + +namespace L0 { +ze_result_t zeEventPoolCreate(ze_context_handle_t hContext, + const ze_event_pool_desc_t *desc, + uint32_t numDevices, + ze_device_handle_t *phDevices, + ze_event_pool_handle_t *phEventPool) { + if (hContext == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + EventPool::create(hContext, desc, numDevices, phDevices, phEventPool)); +} + +ze_result_t zeEventPoolDestroy(ze_event_pool_handle_t hEventPool) { + if (hEventPool == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(EventPool::fromHandle(hEventPool)->destroy()); +} + +ze_result_t zeEventCreate(ze_event_pool_handle_t hEventPool, + const ze_event_desc_t *desc, + ze_event_handle_t *phEvent) { + if (hEventPool == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(EventPool::fromHandle(hEventPool)->createEvent(desc, phEvent)); +} + +ze_result_t zeEventPoolGetIpcHandle(ze_event_pool_handle_t hEventPool, + ze_ipc_event_pool_handle_t *phIpc) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeEventPoolOpenIpcHandle(ze_context_handle_t hContext, + ze_ipc_event_pool_handle_t hIpc, + ze_event_pool_handle_t *phEventPool) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeEventPoolCloseIpcHandle(ze_event_pool_handle_t hEventPool) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t zeEventDestroy(ze_event_handle_t hEvent) { + if (hEvent == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->destroy()); +} + +ze_result_t zeEventHostSignal(ze_event_handle_t hEvent) { + if (hEvent == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->hostSignal()); +} + +ze_result_t zeEventHostSynchronize(ze_event_handle_t hEvent, uint64_t timeout) { + if (hEvent == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->hostSynchronize(timeout)); +} + +ze_result_t zeEventQueryStatus(ze_event_handle_t hEvent) { + if (hEvent == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->queryStatus()); +} + +ze_result_t zeEventHostReset(ze_event_handle_t hEvent) { + if (hEvent == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN(Event::fromHandle(hEvent)->reset()); +} + +ze_result_t zeEventQueryKernelTimestamp(ze_event_handle_t hEvent, + ze_kernel_timestamp_result_t *timestampType) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} +} // namespace L0 + +extern "C" { +ZE_APIEXPORT ze_result_t ZE_APICALL +zeGetEventPoolProcAddrTable(ze_api_version_t version, ze_event_pool_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnCreate = L0::zeEventPoolCreate; + pDdiTable->pfnDestroy = L0::zeEventPoolDestroy; + pDdiTable->pfnGetIpcHandle = L0::zeEventPoolGetIpcHandle; + pDdiTable->pfnOpenIpcHandle = L0::zeEventPoolOpenIpcHandle; + pDdiTable->pfnCloseIpcHandle = L0::zeEventPoolCloseIpcHandle; + return ZE_RESULT_SUCCESS; +} + +ZE_APIEXPORT ze_result_t ZE_APICALL zeGetEventProcAddrTable(ze_api_version_t version, + ze_event_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnCreate = L0::zeEventCreate; + pDdiTable->pfnDestroy = L0::zeEventDestroy; + pDdiTable->pfnHostSignal = L0::zeEventHostSignal; + pDdiTable->pfnHostSynchronize = L0::zeEventHostSynchronize; + pDdiTable->pfnQueryStatus = L0::zeEventQueryStatus; + pDdiTable->pfnHostReset = L0::zeEventHostReset; + pDdiTable->pfnQueryKernelTimestamp = L0::zeEventQueryKernelTimestamp; + return ZE_RESULT_SUCCESS; +} +} diff --git a/umd/level_zero_driver/api/core/ze_fence.hpp b/umd/level_zero_driver/api/ze_fence.cpp similarity index 63% rename from umd/level_zero_driver/api/core/ze_fence.hpp rename to umd/level_zero_driver/api/ze_fence.cpp index 9881f91..aa7c313 100644 --- a/umd/level_zero_driver/api/core/ze_fence.hpp +++ b/umd/level_zero_driver/api/ze_fence.cpp @@ -5,13 +5,14 @@ * */ -#pragma once +#include #include "level_zero_driver/core/source/cmdqueue/cmdqueue.hpp" #include "level_zero_driver/core/source/fence/fence.hpp" #include "level_zero_driver/include/l0_exception.hpp" #include +#include namespace L0 { ze_result_t zeFenceCreate(ze_command_queue_handle_t hCommandQueue, @@ -49,26 +50,19 @@ ze_result_t zeFenceReset(ze_fence_handle_t hFence) { } // namespace L0 extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zeFenceCreate(ze_command_queue_handle_t hCommandQueue, - const ze_fence_desc_t *desc, - ze_fence_handle_t *phFence) { - return L0::zeFenceCreate(hCommandQueue, desc, phFence); -} +ZE_APIEXPORT ze_result_t ZE_APICALL zeGetFenceProcAddrTable(ze_api_version_t version, + ze_fence_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; -ZE_APIEXPORT ze_result_t ZE_APICALL zeFenceDestroy(ze_fence_handle_t hFence) { - return L0::zeFenceDestroy(hFence); -} + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; -ZE_APIEXPORT ze_result_t ZE_APICALL zeFenceHostSynchronize(ze_fence_handle_t hFence, - uint64_t timeout) { - return L0::zeFenceHostSynchronize(hFence, timeout); + pDdiTable->pfnCreate = L0::zeFenceCreate; + pDdiTable->pfnDestroy = L0::zeFenceDestroy; + pDdiTable->pfnHostSynchronize = L0::zeFenceHostSynchronize; + pDdiTable->pfnQueryStatus = L0::zeFenceQueryStatus; + pDdiTable->pfnReset = L0::zeFenceReset; + return ZE_RESULT_SUCCESS; } - -ZE_APIEXPORT ze_result_t ZE_APICALL zeFenceQueryStatus(ze_fence_handle_t hFence) { - return L0::zeFenceQueryStatus(hFence); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeFenceReset(ze_fence_handle_t hFence) { - return L0::zeFenceReset(hFence); } -} // extern "C" diff --git a/umd/level_zero_driver/api/core/ze_memory.hpp b/umd/level_zero_driver/api/ze_memory.cpp similarity index 70% rename from umd/level_zero_driver/api/core/ze_memory.hpp rename to umd/level_zero_driver/api/ze_memory.cpp index 669f7c8..d4e5b80 100644 --- a/umd/level_zero_driver/api/core/ze_memory.hpp +++ b/umd/level_zero_driver/api/ze_memory.cpp @@ -5,26 +5,29 @@ * */ -#pragma once +#include -#include "level_zero_driver/core/source/driver/driver_handle.hpp" +#include "level_zero_driver/core/source/context/context.hpp" +#include "level_zero_driver/core/source/device/device.hpp" #include "level_zero_driver/include/l0_exception.hpp" +#include "umd_common.hpp" #include "vpu_driver/source/memory/vpu_buffer_object.hpp" + #include +#include namespace L0 { static VPU::VPUBufferObject::Type flagToBufferObjectType(ze_host_mem_alloc_flags_t flag) { - // TODO: Fallback to shave range to fix incorrect address in Dma tasks for kernels (EISW-108894) switch (flag) { case ZE_HOST_MEM_ALLOC_FLAG_BIAS_CACHED: - return VPU::VPUBufferObject::Type::CachedShave; + return VPU::VPUBufferObject::Type::CachedDma; case ZE_HOST_MEM_ALLOC_FLAG_BIAS_UNCACHED: - return VPU::VPUBufferObject::Type::UncachedShave; + return VPU::VPUBufferObject::Type::UncachedDma; case ZE_HOST_MEM_ALLOC_FLAG_BIAS_WRITE_COMBINED: - return VPU::VPUBufferObject::Type::WriteCombineShave; + return VPU::VPUBufferObject::Type::WriteCombineDma; }; - return VPU::VPUBufferObject::Type::CachedShave; + return VPU::VPUBufferObject::Type::CachedDma; } ze_result_t zeMemAllocShared(ze_context_handle_t hContext, @@ -118,7 +121,7 @@ ze_result_t zeMemAllocDevice(ze_context_handle_t hContext, alignment, pptr, VPU::VPUBufferObject::Location::ExternalDevice, - VPU::VPUBufferObject::Type::WriteCombineShave)); + VPU::VPUBufferObject::Type::WriteCombineDma)); } return ZE_RESULT_ERROR_INVALID_ENUMERATION; } @@ -139,7 +142,7 @@ ze_result_t zeMemAllocDevice(ze_context_handle_t hContext, alignment, pptr, VPU::VPUBufferObject::Location::Device, - VPU::VPUBufferObject::Type::WriteCombineShave)); + VPU::VPUBufferObject::Type::WriteCombineDma)); } } @@ -245,68 +248,23 @@ ze_result_t zeMemCloseIpcHandle(ze_context_handle_t hContext, const void *ptr) { } // namespace L0 extern "C" { -ZE_APIEXPORT ze_result_t ZE_APICALL zeMemAllocShared(ze_context_handle_t hContext, - const ze_device_mem_alloc_desc_t *deviceDesc, - const ze_host_mem_alloc_desc_t *hostDesc, - size_t size, - size_t alignment, - ze_device_handle_t hDevice, - void **pptr) { - return L0::zeMemAllocShared(hContext, deviceDesc, hostDesc, size, alignment, hDevice, pptr); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeMemAllocDevice(ze_context_handle_t hContext, - const ze_device_mem_alloc_desc_t *deviceDesc, - size_t size, - size_t alignment, - ze_device_handle_t hDevice, - void **pptr) { - return L0::zeMemAllocDevice(hContext, deviceDesc, size, alignment, hDevice, pptr); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeMemAllocHost(ze_context_handle_t hContext, - const ze_host_mem_alloc_desc_t *hostDesc, - size_t size, - size_t alignment, - void **pptr) { - return L0::zeMemAllocHost(hContext, hostDesc, size, alignment, pptr); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeMemFree(ze_context_handle_t hContext, void *ptr) { - return L0::zeMemFree(hContext, ptr); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL -zeMemGetAllocProperties(ze_context_handle_t hContext, - const void *ptr, - ze_memory_allocation_properties_t *pMemAllocProperties, - ze_device_handle_t *phDevice) { - return L0::zeMemGetAllocProperties(hContext, ptr, pMemAllocProperties, phDevice); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeMemGetAddressRange(ze_context_handle_t hContext, - const void *ptr, - void **pBase, - size_t *pSize) { - return L0::zeMemGetAddressRange(hContext, ptr, pBase, pSize); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeMemGetIpcHandle(ze_context_handle_t hContext, - const void *ptr, - ze_ipc_mem_handle_t *pIpcHandle) { - return L0::zeMemGetIpcHandle(hContext, ptr, pIpcHandle); -} - -ZE_APIEXPORT ze_result_t ZE_APICALL zeMemOpenIpcHandle(ze_context_handle_t hContext, - ze_device_handle_t hDevice, - ze_ipc_mem_handle_t handle, - ze_ipc_memory_flags_t flags, - void **pptr) { - return L0::zeMemOpenIpcHandle(hContext, hDevice, handle, flags, pptr); +ZE_DLLEXPORT ze_result_t ZE_APICALL zeGetMemProcAddrTable(ze_api_version_t version, + ze_mem_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnAllocShared = L0::zeMemAllocShared; + pDdiTable->pfnAllocDevice = L0::zeMemAllocDevice; + pDdiTable->pfnAllocHost = L0::zeMemAllocHost; + pDdiTable->pfnFree = L0::zeMemFree; + pDdiTable->pfnGetAllocProperties = L0::zeMemGetAllocProperties; + pDdiTable->pfnGetAddressRange = L0::zeMemGetAddressRange; + pDdiTable->pfnGetIpcHandle = L0::zeMemGetIpcHandle; + pDdiTable->pfnOpenIpcHandle = L0::zeMemOpenIpcHandle; + pDdiTable->pfnCloseIpcHandle = L0::zeMemCloseIpcHandle; + return ZE_RESULT_SUCCESS; } - -ZE_APIEXPORT ze_result_t ZE_APICALL zeMemCloseIpcHandle(ze_context_handle_t hContext, - const void *ptr) { - return L0::zeMemCloseIpcHandle(hContext, ptr); } -} // extern "C" diff --git a/umd/level_zero_driver/api/ze_misc.cpp b/umd/level_zero_driver/api/ze_misc.cpp new file mode 100644 index 0000000..2ec18d4 --- /dev/null +++ b/umd/level_zero_driver/api/ze_misc.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2022-2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include +#include + +extern "C" { +ZE_APIEXPORT ze_result_t ZE_APICALL zeGetImageProcAddrTable(ze_api_version_t version, + ze_image_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnGetProperties = nullptr; // zeImageGetProperties + pDdiTable->pfnCreate = nullptr; // zeImageCreate + pDdiTable->pfnDestroy = nullptr; // zeImageDestroy + return ZE_RESULT_SUCCESS; +} + +ZE_APIEXPORT ze_result_t ZE_APICALL zeGetModuleProcAddrTable(ze_api_version_t version, + ze_module_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnCreate = nullptr; // zeModuleCreate + pDdiTable->pfnDestroy = nullptr; // zeModuleDestroy + pDdiTable->pfnDynamicLink = nullptr; // zeModuleDynamicLink + pDdiTable->pfnGetNativeBinary = nullptr; // zeModuleGetNativeBinary + pDdiTable->pfnGetGlobalPointer = nullptr; // zeModuleGetGlobalPointer + pDdiTable->pfnGetKernelNames = nullptr; // zeModuleGetKernelNames + pDdiTable->pfnGetFunctionPointer = nullptr; // zeModuleGetFunctionPointer + pDdiTable->pfnGetProperties = nullptr; // zeModuleGetProperties + return ZE_RESULT_SUCCESS; +} + +ZE_APIEXPORT ze_result_t ZE_APICALL +zeGetModuleBuildLogProcAddrTable(ze_api_version_t version, + ze_module_build_log_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnDestroy = nullptr; // zeModuleBuildLogDestroy + pDdiTable->pfnGetString = nullptr; // zeModuleBuildLogGetString + return ZE_RESULT_SUCCESS; +} + +ZE_APIEXPORT ze_result_t ZE_APICALL zeGetKernelProcAddrTable(ze_api_version_t version, + ze_kernel_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnCreate = nullptr; // zeKernelCreate + pDdiTable->pfnDestroy = nullptr; // zeKernelDestroy + pDdiTable->pfnSetGroupSize = nullptr; // zeKernelSetGroupSize + pDdiTable->pfnSuggestGroupSize = nullptr; // zeKernelSuggestGroupSize + pDdiTable->pfnSuggestMaxCooperativeGroupCount = + nullptr; // zeKernelSuggestMaxCooperativeGroupCount + pDdiTable->pfnSetArgumentValue = nullptr; // zeKernelSetArgumentValue + pDdiTable->pfnSetIndirectAccess = nullptr; // zeKernelSetIndirectAccess + pDdiTable->pfnGetIndirectAccess = nullptr; // zeKernelGetIndirectAccess + pDdiTable->pfnGetSourceAttributes = nullptr; // zeKernelGetSourceAttributes + pDdiTable->pfnGetProperties = nullptr; // zeKernelGetProperties + pDdiTable->pfnSetCacheConfig = nullptr; // zeKernelSetCacheConfig + pDdiTable->pfnGetName = nullptr; // zeKernelGetName + return ZE_RESULT_SUCCESS; +} + +ZE_APIEXPORT ze_result_t ZE_APICALL zeGetSamplerProcAddrTable(ze_api_version_t version, + ze_sampler_dditable_t *pDdiTable) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnCreate = nullptr; // zeSamplerCreate + pDdiTable->pfnDestroy = nullptr; // zeSamplerDestroy + return ZE_RESULT_SUCCESS; +} +} diff --git a/umd/level_zero_driver/api/zes_device.cpp b/umd/level_zero_driver/api/zes_device.cpp new file mode 100644 index 0000000..f969f8f --- /dev/null +++ b/umd/level_zero_driver/api/zes_device.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include + +#include "level_zero_driver/core/source/device/device.hpp" +#include "level_zero_driver/core/source/driver/driver_handle.hpp" +#include "level_zero_driver/include/l0_exception.hpp" + +#include +#include +#include + +namespace L0 { + +ze_result_t +zesDeviceGet(zes_driver_handle_t hDriver, uint32_t *pCount, zes_device_handle_t *phDevices) { + if (hDriver == nullptr || pCount == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + L0::DriverHandle::fromHandle(static_cast(hDriver)) + ->getDevice(pCount, static_cast(phDevices))); +} + +ze_result_t zesDeviceGetProperties(zes_device_handle_t hDevice, + zes_device_properties_t *pProperties) { + if (hDevice == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + L0_HANDLE_EXCEPTION_AND_RETURN(L0::Device::fromHandle(static_cast(hDevice)) + ->getProperties(pProperties)); +} + +ze_result_t zesDeviceEnumEngineGroups(zes_device_handle_t hDevice, + uint32_t *pCount, + zes_engine_handle_t *phEngine) { + if (hDevice == nullptr || pCount == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + if (*pCount == 0) { + *pCount = 1; + return ZE_RESULT_SUCCESS; + } else if (phEngine == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + *pCount = 1; + *phEngine = reinterpret_cast(hDevice); + return ZE_RESULT_SUCCESS; +} + +} // namespace L0 + +extern "C" { +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's Device table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetDeviceProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zes_device_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnGetProperties = L0::zesDeviceGetProperties; + + pDdiTable->pfnGetState = nullptr; + + pDdiTable->pfnReset = nullptr; + + pDdiTable->pfnProcessesGetState = nullptr; + + pDdiTable->pfnPciGetProperties = nullptr; + + pDdiTable->pfnPciGetState = nullptr; + + pDdiTable->pfnPciGetBars = nullptr; + + pDdiTable->pfnPciGetStats = nullptr; + + pDdiTable->pfnEnumDiagnosticTestSuites = nullptr; + + pDdiTable->pfnEnumEngineGroups = L0::zesDeviceEnumEngineGroups; + + pDdiTable->pfnEventRegister = nullptr; + + pDdiTable->pfnEnumFabricPorts = nullptr; + + pDdiTable->pfnEnumFans = nullptr; + + pDdiTable->pfnEnumFirmwares = nullptr; + + pDdiTable->pfnEnumFrequencyDomains = nullptr; + + pDdiTable->pfnEnumLeds = nullptr; + + pDdiTable->pfnEnumMemoryModules = nullptr; + + pDdiTable->pfnEnumPerformanceFactorDomains = nullptr; + + pDdiTable->pfnEnumPowerDomains = nullptr; + + pDdiTable->pfnEnumPsus = nullptr; + + pDdiTable->pfnEnumRasErrorSets = nullptr; + + pDdiTable->pfnEnumSchedulers = nullptr; + + pDdiTable->pfnEnumStandbyDomains = nullptr; + + pDdiTable->pfnEnumTemperatureSensors = nullptr; + + pDdiTable->pfnGet = L0::zesDeviceGet; + + return result; +} +} diff --git a/umd/level_zero_driver/api/zes_driver.cpp b/umd/level_zero_driver/api/zes_driver.cpp new file mode 100644 index 0000000..fd28749 --- /dev/null +++ b/umd/level_zero_driver/api/zes_driver.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include + +#include "level_zero_driver/core/source/driver/driver.hpp" +#include "level_zero_driver/include/l0_exception.hpp" + +#include +#include +#include + +namespace L0 { +ze_result_t zesInit(zes_init_flags_t flags) { + L0_HANDLE_EXCEPTION_AND_RETURN(L0::init(flags)); +} + +ze_result_t zesDriverGet(uint32_t *pCount, zes_driver_handle_t *phDrivers) { + if (pCount == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + L0_HANDLE_EXCEPTION_AND_RETURN( + L0::driverHandleGet(pCount, static_cast(phDrivers))); +} + +} // namespace L0 + +extern "C" { +ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetGlobalProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zes_global_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + pDdiTable->pfnInit = L0::zesInit; + + return ZE_RESULT_SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's Driver table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetDriverProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zes_driver_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnGet = L0::zesDriverGet; + + pDdiTable->pfnEventListen = nullptr; + + pDdiTable->pfnEventListenEx = nullptr; + + return result; +} +} diff --git a/umd/level_zero_driver/api/zes_engine.cpp b/umd/level_zero_driver/api/zes_engine.cpp new file mode 100644 index 0000000..9ffc2c7 --- /dev/null +++ b/umd/level_zero_driver/api/zes_engine.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero_driver/core/source/device/device.hpp" +#include "level_zero_driver/include/l0_exception.hpp" + +#include +#include +#include + +namespace L0 { + +ze_result_t zesEngineGetProperties(zes_engine_handle_t hEngine, + zes_engine_properties_t *pProperties) { + if (hEngine == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + L0::Device::fromHandle(reinterpret_cast(hEngine)) + ->engineGetProperties(pProperties)); +} + +ze_result_t zesEngineGetActivity(zes_engine_handle_t hEngine, zes_engine_stats_t *pStats) { + if (hEngine == nullptr) { + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + L0_HANDLE_EXCEPTION_AND_RETURN( + L0::Device::fromHandle(reinterpret_cast(hEngine)) + ->engineGetActivity(pStats)); +} + +} // namespace L0 + +extern "C" { +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's Engine table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetEngineProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zes_engine_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnGetProperties = L0::zesEngineGetProperties; + + pDdiTable->pfnGetActivity = L0::zesEngineGetActivity; + + pDdiTable->pfnGetActivityExt = nullptr; + + return result; +} +} diff --git a/umd/level_zero_driver/api/core/zes_loader.cpp b/umd/level_zero_driver/api/zes_misc.cpp similarity index 76% rename from umd/level_zero_driver/api/core/zes_loader.cpp rename to umd/level_zero_driver/api/zes_misc.cpp index 190e347..22c35ac 100644 --- a/umd/level_zero_driver/api/core/zes_loader.cpp +++ b/umd/level_zero_driver/api/zes_misc.cpp @@ -5,132 +5,10 @@ * */ -#include "zes_device.hpp" -#include "zes_driver.hpp" - #include #include -#if defined(__cplusplus) extern "C" { -#endif -ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetGlobalProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zes_global_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - pDdiTable->pfnInit = L0::zesInit; - - return ZE_RESULT_SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's Device table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetDeviceProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zes_device_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnGetProperties = L0::zesDeviceGetProperties; - - pDdiTable->pfnGetState = nullptr; - - pDdiTable->pfnReset = nullptr; - - pDdiTable->pfnProcessesGetState = nullptr; - - pDdiTable->pfnPciGetProperties = nullptr; - - pDdiTable->pfnPciGetState = nullptr; - - pDdiTable->pfnPciGetBars = nullptr; - - pDdiTable->pfnPciGetStats = nullptr; - - pDdiTable->pfnEnumDiagnosticTestSuites = nullptr; - - pDdiTable->pfnEnumEngineGroups = nullptr; - - pDdiTable->pfnEventRegister = nullptr; - - pDdiTable->pfnEnumFabricPorts = nullptr; - - pDdiTable->pfnEnumFans = nullptr; - - pDdiTable->pfnEnumFirmwares = nullptr; - - pDdiTable->pfnEnumFrequencyDomains = nullptr; - - pDdiTable->pfnEnumLeds = nullptr; - - pDdiTable->pfnEnumMemoryModules = nullptr; - - pDdiTable->pfnEnumPerformanceFactorDomains = nullptr; - - pDdiTable->pfnEnumPowerDomains = nullptr; - - pDdiTable->pfnEnumPsus = nullptr; - - pDdiTable->pfnEnumRasErrorSets = nullptr; - - pDdiTable->pfnEnumSchedulers = nullptr; - - pDdiTable->pfnEnumStandbyDomains = nullptr; - - pDdiTable->pfnEnumTemperatureSensors = nullptr; - - pDdiTable->pfnGet = L0::zesDeviceGet; - - return result; -} - -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's Driver table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetDriverProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zes_driver_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnGet = L0::zesDriverGet; - - pDdiTable->pfnEventListen = nullptr; - - pDdiTable->pfnEventListenEx = nullptr; - - return result; -} - /////////////////////////////////////////////////////////////////////////////// /// @brief Exported function for filling application's Diagnostics table /// with current process' addresses @@ -160,33 +38,6 @@ ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetDiagnosticsProcAddrTable( return result; } -/////////////////////////////////////////////////////////////////////////////// -/// @brief Exported function for filling application's Engine table -/// with current process' addresses -/// -/// @returns -/// - ::ZE_RESULT_SUCCESS -/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER -/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION -ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetEngineProcAddrTable( - ze_api_version_t version, ///< [in] API version requested - zes_engine_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers -) { - if (nullptr == pDdiTable) - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - - if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) - return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; - - ze_result_t result = ZE_RESULT_SUCCESS; - - pDdiTable->pfnGetProperties = nullptr; - - pDdiTable->pfnGetActivity = nullptr; - - return result; -} - /////////////////////////////////////////////////////////////////////////////// /// @brief Exported function for filling application's FabricPort table /// with current process' addresses @@ -622,6 +473,4 @@ ZE_DLLEXPORT ze_result_t ZE_APICALL zesGetTemperatureProcAddrTable( return result; } -#if defined(__cplusplus) } -#endif diff --git a/umd/level_zero_driver/api/tools/zet_metric.hpp b/umd/level_zero_driver/api/zet_metric.cpp similarity index 55% rename from umd/level_zero_driver/api/tools/zet_metric.hpp rename to umd/level_zero_driver/api/zet_metric.cpp index 6df34a3..eb7afac 100644 --- a/umd/level_zero_driver/api/tools/zet_metric.hpp +++ b/umd/level_zero_driver/api/zet_metric.cpp @@ -5,6 +5,9 @@ * */ +#include +#include + #include "level_zero_driver/core/source/cmdlist/cmdlist.hpp" #include "level_zero_driver/core/source/context/context.hpp" #include "level_zero_driver/core/source/device/device.hpp" @@ -13,7 +16,9 @@ #include "level_zero_driver/tools/source/metrics/metric_query.hpp" #include "level_zero_driver/tools/source/metrics/metric_streamer.hpp" +#include #include +#include namespace L0 { ze_result_t zetMetricGroupGet(zet_device_handle_t hDevice, @@ -203,143 +208,204 @@ ze_result_t zetMetricQueryGetData(zet_metric_query_handle_t hMetricQuery, } // namespace L0 extern "C" { -ZE_DLLEXPORT ze_result_t ZE_APICALL zetMetricGroupGet(zet_device_handle_t hDevice, - uint32_t *pCount, - zet_metric_group_handle_t *phMetricGroups) { - return L0::zetMetricGroupGet(hDevice, pCount, phMetricGroups); -} +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's Context table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetContextProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_context_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; -ZE_DLLEXPORT ze_result_t ZE_APICALL -zetMetricGroupGetProperties(zet_metric_group_handle_t hMetricGroup, - zet_metric_group_properties_t *pProperties) { - return L0::zetMetricGroupGetProperties(hMetricGroup, pProperties); -} + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; -ZE_DLLEXPORT ze_result_t ZE_APICALL zetMetricGet(zet_metric_group_handle_t hMetricGroup, - uint32_t *pCount, - zet_metric_handle_t *phMetrics) { - return L0::zetMetricGet(hMetricGroup, pCount, phMetrics); -} + ze_result_t result = ZE_RESULT_SUCCESS; -ZE_DLLEXPORT ze_result_t ZE_APICALL zetMetricGetProperties(zet_metric_handle_t hMetric, - zet_metric_properties_t *pProperties) { - return L0::zetMetricGetProperties(hMetric, pProperties); -} + pDdiTable->pfnActivateMetricGroups = L0::zetContextActivateMetricGroups; -ZE_DLLEXPORT ze_result_t ZE_APICALL -zetMetricGroupCalculateMetricValues(zet_metric_group_handle_t hMetricGroup, - zet_metric_group_calculation_type_t type, - size_t rawDataSize, - const uint8_t *pRawData, - uint32_t *pMetricValueCount, - zet_typed_value_t *pMetricValues) { - return L0::zetMetricGroupCalculateMetricValues(hMetricGroup, - type, - rawDataSize, - pRawData, - pMetricValueCount, - pMetricValues); -} + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's CommandList table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetCommandListProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_command_list_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; -ZE_DLLEXPORT ze_result_t ZE_APICALL -zetContextActivateMetricGroups(zet_context_handle_t hContext, - zet_device_handle_t hDevice, - uint32_t count, - zet_metric_group_handle_t *phMetricGroups) { - return L0::zetContextActivateMetricGroups(hContext, hDevice, count, phMetricGroups); -} + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; -ZE_APIEXPORT ze_result_t ZE_APICALL -zetMetricStreamerOpen(zet_context_handle_t hContext, - zet_device_handle_t hDevice, - zet_metric_group_handle_t hMetricGroup, - zet_metric_streamer_desc_t *pDesc, - ze_event_handle_t hNotificationEvent, - zet_metric_streamer_handle_t *phMetricStreamer) { - return L0::zetMetricStreamerOpen(hContext, - hDevice, - hMetricGroup, - pDesc, - hNotificationEvent, - phMetricStreamer); -} + ze_result_t result = ZE_RESULT_SUCCESS; -ZE_APIEXPORT ze_result_t ZE_APICALL -zetCommandListAppendMetricStreamerMarker(ze_command_list_handle_t hCommandList, - zet_metric_streamer_handle_t hMetricStreamer, - uint32_t value) { - return L0::zetCommandListAppendMetricStreamerMarker(hCommandList, hMetricStreamer, value); -} + pDdiTable->pfnAppendMetricStreamerMarker = L0::zetCommandListAppendMetricStreamerMarker; -ZE_APIEXPORT ze_result_t ZE_APICALL -zetMetricStreamerClose(zet_metric_streamer_handle_t hMetricStreamer) { - return L0::zetMetricStreamerClose(hMetricStreamer); -} + pDdiTable->pfnAppendMetricQueryBegin = L0::zetCommandListAppendMetricQueryBegin; -ZE_APIEXPORT ze_result_t ZE_APICALL -zetMetricStreamerReadData(zet_metric_streamer_handle_t hMetricStreamer, - uint32_t maxReportCount, - size_t *pRawDataSize, - uint8_t *pRawData) { - return L0::zetMetricStreamerReadData(hMetricStreamer, maxReportCount, pRawDataSize, pRawData); -} + pDdiTable->pfnAppendMetricQueryEnd = L0::zetCommandListAppendMetricQueryEnd; -ZE_DLLEXPORT ze_result_t ZE_APICALL -zetMetricQueryPoolCreate(zet_context_handle_t hContext, - zet_device_handle_t hDevice, - zet_metric_group_handle_t hMetricGroup, - const zet_metric_query_pool_desc_t *desc, - zet_metric_query_pool_handle_t *phMetricQueryPool) { - return L0::zetMetricQueryPoolCreate(hContext, hDevice, hMetricGroup, desc, phMetricQueryPool); -} + pDdiTable->pfnAppendMetricMemoryBarrier = L0::zetCommandListAppendMetricMemoryBarrier; -ZE_DLLEXPORT ze_result_t ZE_APICALL -zetMetricQueryPoolDestroy(zet_metric_query_pool_handle_t hMetricQueryPool) { - return L0::zetMetricQueryPoolDestroy(hMetricQueryPool); + return result; } -ZE_DLLEXPORT ze_result_t ZE_APICALL -zetMetricQueryCreate(zet_metric_query_pool_handle_t hMetricQueryPool, - uint32_t index, - zet_metric_query_handle_t *phMetricQuery) { - return L0::zetMetricQueryCreate(hMetricQueryPool, index, phMetricQuery); -} +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's Metric table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_metric_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; -ZE_DLLEXPORT ze_result_t ZE_APICALL zetMetricQueryDestroy(zet_metric_query_handle_t hMetricQuery) { - return L0::zetMetricQueryDestroy(hMetricQuery); -} + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnGet = L0::zetMetricGet; -ZE_DLLEXPORT ze_result_t ZE_APICALL zetMetricQueryReset(zet_metric_query_handle_t hMetricQuery) { - return L0::zetMetricQueryReset(hMetricQuery); + pDdiTable->pfnGetProperties = L0::zetMetricGetProperties; + + return result; } -ZE_DLLEXPORT ze_result_t ZE_APICALL -zetCommandListAppendMetricQueryBegin(zet_command_list_handle_t hCommandList, - zet_metric_query_handle_t hMetricQuery) { - return L0::zetCommandListAppendMetricQueryBegin(hCommandList, hMetricQuery); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's MetricGroup table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricGroupProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_metric_group_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnGet = L0::zetMetricGroupGet; + + pDdiTable->pfnGetProperties = L0::zetMetricGroupGetProperties; + + pDdiTable->pfnCalculateMetricValues = L0::zetMetricGroupCalculateMetricValues; + + return result; } -ZE_DLLEXPORT ze_result_t ZE_APICALL -zetCommandListAppendMetricQueryEnd(zet_command_list_handle_t hCommandList, - zet_metric_query_handle_t hMetricQuery, - ze_event_handle_t hSignalEvent, - uint32_t numWaitEvents, - ze_event_handle_t *phWaitEvents) { - return L0::zetCommandListAppendMetricQueryEnd(hCommandList, - hMetricQuery, - hSignalEvent, - numWaitEvents, - phWaitEvents); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's MetricQuery table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricQueryProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_metric_query_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnCreate = L0::zetMetricQueryCreate; + + pDdiTable->pfnDestroy = L0::zetMetricQueryDestroy; + + pDdiTable->pfnReset = L0::zetMetricQueryReset; + + pDdiTable->pfnGetData = L0::zetMetricQueryGetData; + + return result; } -ZE_DLLEXPORT ze_result_t ZE_APICALL -zetCommandListAppendMetricMemoryBarrier(zet_command_list_handle_t hCommandList) { - return L0::zetCommandListAppendMetricMemoryBarrier(hCommandList); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's MetricQueryPool table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricQueryPoolProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_metric_query_pool_dditable_t + *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnCreate = L0::zetMetricQueryPoolCreate; + + pDdiTable->pfnDestroy = L0::zetMetricQueryPoolDestroy; + + return result; } -ZE_DLLEXPORT ze_result_t ZE_APICALL zetMetricQueryGetData(zet_metric_query_handle_t hMetricQuery, - size_t *pRawDataSize, - uint8_t *pRawData) { - return L0::zetMetricQueryGetData(hMetricQuery, pRawDataSize, pRawData); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's MetricStreamer table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetMetricStreamerProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_metric_streamer_dditable_t + *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnOpen = L0::zetMetricStreamerOpen; + + pDdiTable->pfnClose = L0::zetMetricStreamerClose; + + pDdiTable->pfnReadData = L0::zetMetricStreamerReadData; + + return result; +} } -} // extern "C" diff --git a/umd/level_zero_driver/api/zet_misc.cpp b/umd/level_zero_driver/api/zet_misc.cpp new file mode 100644 index 0000000..4324c7f --- /dev/null +++ b/umd/level_zero_driver/api/zet_misc.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (C) 2022-2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include + +#include "level_zero/loader/ze_loader.h" +#include "vpu_driver/source/utilities/log.hpp" + +#include +#include +#include +#include + +extern "C" { +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's Device table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetDeviceProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_device_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnGetDebugProperties = nullptr; + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's Kernel table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetKernelProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_kernel_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnGetProfileInfo = nullptr; + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's Module table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetModuleProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_module_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnGetDebugInfo = nullptr; + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's Debug table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetDebugProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_debug_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnAttach = nullptr; + + pDdiTable->pfnDetach = nullptr; + + pDdiTable->pfnReadEvent = nullptr; + + pDdiTable->pfnAcknowledgeEvent = nullptr; + + pDdiTable->pfnInterrupt = nullptr; + + pDdiTable->pfnResume = nullptr; + + pDdiTable->pfnReadMemory = nullptr; + + pDdiTable->pfnWriteMemory = nullptr; + + pDdiTable->pfnGetRegisterSetProperties = nullptr; + + pDdiTable->pfnReadRegisters = nullptr; + + pDdiTable->pfnWriteRegisters = nullptr; + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Exported function for filling application's TracerExp table +/// with current process' addresses +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION +ZE_DLLEXPORT ze_result_t ZE_APICALL zetGetTracerExpProcAddrTable( + ze_api_version_t version, ///< [in] API version requested + zet_tracer_exp_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers +) { + if (nullptr == pDdiTable) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(version)) + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + + ze_result_t result = ZE_RESULT_SUCCESS; + + pDdiTable->pfnCreate = nullptr; + + pDdiTable->pfnDestroy = nullptr; + + pDdiTable->pfnSetPrologues = nullptr; + + pDdiTable->pfnSetEpilogues = nullptr; + + pDdiTable->pfnSetEnabled = nullptr; + + return result; +} +} + +namespace L0 { + +void *getLoaderHandle() { + static void *loaderHandle = dlopen("libze_loader.so.1", RTLD_LAZY | RTLD_LOCAL); + return loaderHandle; +} + +std::string getLoaderVersion() { + std::string version = "not available"; + void *loaderHandle = getLoaderHandle(); + + if (loaderHandle == nullptr) { + return version; + } + + static void *functionPointer = dlsym(loaderHandle, "zelLoaderGetVersions"); + if (functionPointer == nullptr) { + return version; + } + + zel_component_version_t loaderVersion; + size_t num = 1; + static auto *pLoaderGetVersions = + reinterpret_cast(functionPointer); + if (pLoaderGetVersions(&num, &loaderVersion) != ZE_RESULT_SUCCESS) { + return version; + } + + version = std::to_string(loaderVersion.component_lib_version.major) + "."; + version += std::to_string(loaderVersion.component_lib_version.minor) + "."; + version += std::to_string(loaderVersion.component_lib_version.patch); + return version; +} + +ze_result_t translateHandle(zel_handle_type_t type, void *handler, void **pHandler) { + void *loaderHandle = getLoaderHandle(); + if (loaderHandle == nullptr) { + LOG_E("Failed to open libze_loader.so.1 library"); + return ZE_RESULT_ERROR_UNKNOWN; + } + + static void *functionPointer = dlsym(loaderHandle, "zelLoaderTranslateHandle"); + if (functionPointer == nullptr) { + LOG_E("Failed to get 'zelLoaderTranslateHandle' from libze_loader.so.1, reason: %s", + dlerror()); + return ZE_RESULT_ERROR_UNKNOWN; + } + + static auto *pLoaderTranslateHandler = + reinterpret_cast(functionPointer); + + auto result = pLoaderTranslateHandler(type, handler, pHandler); + if (result != ZE_RESULT_SUCCESS) + LOG_E("Failed to translate handler of type %i", type); + + return result; +} + +} // namespace L0 diff --git a/umd/level_zero_driver/api/zet_misc.hpp b/umd/level_zero_driver/api/zet_misc.hpp new file mode 100644 index 0000000..9425cd0 --- /dev/null +++ b/umd/level_zero_driver/api/zet_misc.hpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/loader/ze_loader.h" +#include "level_zero/ze_api.h" + +#include + +#pragma once + +namespace L0 { +void *getLoaderHandle(); +std::string getLoaderVersion(); + +ze_result_t translateHandle(zel_handle_type_t type, void *handler, void **pHandler); + +template +static inline ze_result_t translateHandle(zel_handle_type_t type, T handler, T *pHandler) { + return translateHandle(type, handler, reinterpret_cast(pHandler)); +} + +template +static inline ze_result_t translateHandle(zel_handle_type_t type, T &handler) { + return translateHandle(type, handler, &handler); +} +} // namespace L0 diff --git a/umd/level_zero_driver/core/source/CMakeLists.txt b/umd/level_zero_driver/core/source/CMakeLists.txt index f08a04a..f834b46 100644 --- a/umd/level_zero_driver/core/source/CMakeLists.txt +++ b/umd/level_zero_driver/core/source/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT # -target_sources(${TARGET_NAME_L0} PRIVATE +target_sources(${TARGET_NAME_L0_DRV} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cmdlist/cmdlist.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cmdlist/cmdlist.hpp ${CMAKE_CURRENT_SOURCE_DIR}/cmdlist/immediate_cmdlist.cpp diff --git a/umd/level_zero_driver/core/source/cmdlist/cmdlist.cpp b/umd/level_zero_driver/core/source/cmdlist/cmdlist.cpp index 01b67ed..4e82b37 100644 --- a/umd/level_zero_driver/core/source/cmdlist/cmdlist.cpp +++ b/umd/level_zero_driver/core/source/cmdlist/cmdlist.cpp @@ -10,6 +10,7 @@ #include "level_zero_driver/core/source/context/context.hpp" #include "level_zero_driver/core/source/device/device.hpp" #include "level_zero_driver/core/source/event/event.hpp" +#include "level_zero_driver/ext/source/graph/graph.hpp" #include "level_zero_driver/ext/source/graph/profiling_data.hpp" #include "level_zero_driver/include/l0_exception.hpp" #include "level_zero_driver/include/nested_structs_handler.hpp" @@ -30,9 +31,8 @@ namespace L0 { -CommandList::CommandList(Context *pContext, bool isCopyOnly, bool isMutable) +CommandList::CommandList(Context *pContext, bool isMutable) : pContext(pContext) - , isCopyOnlyCmdList(isCopyOnly) , isMutable(isMutable) , ctx(pContext->getDeviceContext()) , vpuJob(std::make_shared(ctx)) {} @@ -56,11 +56,11 @@ ze_result_t CommandList::create(ze_context_handle_t hContext, } if (desc == nullptr) { LOG_E("Invalid desc pointer"); - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; } if (phCommandList == nullptr) { LOG_E("Invalid phCommandList pointer"); - return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; } try { @@ -70,14 +70,13 @@ ze_result_t CommandList::create(ze_context_handle_t hContext, L0_THROW_WHEN(flags == 0, "Invalid group ordinal", ZE_RESULT_ERROR_INVALID_ARGUMENT); Context *pContext = Context::fromHandle(hContext); - bool isCopyOnly = flags == ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY; bool isMutable = false; if (desc->pNext != nullptr) { const ze_structure_type_t stype = *reinterpret_cast(desc->pNext); isMutable = stype == ZE_STRUCTURE_TYPE_MUTABLE_COMMAND_LIST_EXP_DESC; } - auto commandList = std::make_unique(pContext, isCopyOnly, isMutable); + auto commandList = std::make_unique(pContext, isMutable); *phCommandList = commandList.get(); pContext->appendObject(std::move(commandList)); @@ -122,7 +121,6 @@ ze_result_t CommandList::reset() { for (auto &bo : tracedInternalBos) ctx->freeMemAlloc(bo); tracedInternalBos.clear(); - tracedInferences.clear(); vpuJob = std::make_shared(ctx); return ZE_RESULT_SUCCESS; @@ -462,18 +460,7 @@ ze_result_t CommandList::appendGraphExecute(ze_graph_handle_t hGraph, profilingQueryPtr = profilingQuery->getQueryPtr(); } - std::unique_ptr inferenceExecutor; - try { - inferenceExecutor = graph->getGraphExecutor(ctx, profilingQueryPtr); - if (!inferenceExecutor) { - LOG_E("Fail to prepare inference execution!"); - return ZE_RESULT_ERROR_UNINITIALIZED; - } - } catch (const DriverError &err) { - return err.result(); - } - - auto cmd = inferenceExecutor->getExecuteCommand(); + auto cmd = graph->allocateGraphExecuteCommand(ctx, profilingQueryPtr); if (cmd == nullptr) { LOG_E("Graph-Execute Command failed to be initialized!"); return ZE_RESULT_ERROR_UNINITIALIZED; @@ -494,7 +481,6 @@ ze_result_t CommandList::appendGraphExecute(ze_graph_handle_t hGraph, } } - tracedInferences.push_back(std::move(inferenceExecutor)); LOG(CMDLIST, "Successfully appended graph execute command to CommandList"); return postAppend(); } diff --git a/umd/level_zero_driver/core/source/cmdlist/cmdlist.hpp b/umd/level_zero_driver/core/source/cmdlist/cmdlist.hpp index f2f75ff..a139d97 100644 --- a/umd/level_zero_driver/core/source/cmdlist/cmdlist.hpp +++ b/umd/level_zero_driver/core/source/cmdlist/cmdlist.hpp @@ -10,7 +10,6 @@ #include #include -#include "level_zero_driver/ext/source/graph/graph.hpp" #include "level_zero_driver/include/l0_handler.hpp" #include "vpu_driver/source/command/vpu_event_command.hpp" #include "vpu_driver/source/command/vpu_job.hpp" @@ -36,11 +35,9 @@ struct _ze_command_list_handle_t {}; namespace L0 { struct CommandList : _ze_command_list_handle_t, IContextObject { - CommandList(Context *pContext, bool isCopyOnly, bool isMutable); + CommandList(Context *pContext, bool isMutable); virtual ~CommandList(); - bool isCopyOnly() const { return isCopyOnlyCmdList; }; - static ze_result_t create(ze_context_handle_t hContext, ze_device_handle_t hDevice, const ze_command_list_desc_t *desc, @@ -119,12 +116,10 @@ struct CommandList : _ze_command_list_handle_t, IContextObject { Args... args); Context *pContext = nullptr; - bool isCopyOnlyCmdList = false; bool isMutable = false; VPU::VPUDeviceContext *ctx = nullptr; std::shared_ptr vpuJob = nullptr; std::vector tracedInternalBos; - std::vector> tracedInferences; std::unordered_map commandIdMap; }; } // namespace L0 diff --git a/umd/level_zero_driver/core/source/cmdlist/immediate_cmdlist.cpp b/umd/level_zero_driver/core/source/cmdlist/immediate_cmdlist.cpp index 97e0b3e..634bf95 100644 --- a/umd/level_zero_driver/core/source/cmdlist/immediate_cmdlist.cpp +++ b/umd/level_zero_driver/core/source/cmdlist/immediate_cmdlist.cpp @@ -22,7 +22,7 @@ namespace L0 { ImmediateCommandList::ImmediateCommandList(Context *pCtx, CommandQueue *pCmdQueue) - : CommandList(pCtx, pCmdQueue->isCopyOnly(), false) + : CommandList(pCtx, false) , pCommandQueue(pCmdQueue) {} ze_result_t ImmediateCommandList::create(ze_context_handle_t hContext, diff --git a/umd/level_zero_driver/core/source/cmdqueue/cmdqueue.cpp b/umd/level_zero_driver/core/source/cmdqueue/cmdqueue.cpp index d10dc79..4e2531b 100644 --- a/umd/level_zero_driver/core/source/cmdqueue/cmdqueue.cpp +++ b/umd/level_zero_driver/core/source/cmdqueue/cmdqueue.cpp @@ -30,8 +30,9 @@ namespace L0 { -static VPU::VPUCommandBuffer::Priority toDriverPriority(ze_command_queue_priority_t p) { - switch (p) { +static VPU::VPUCommandBuffer::Priority +toDriverPriority(std::atomic &p) { + switch (p.load()) { case ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW: return VPU::VPUCommandBuffer::Priority::IDLE; case ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH: @@ -44,12 +45,11 @@ static VPU::VPUCommandBuffer::Priority toDriverPriority(ze_command_queue_priorit CommandQueue::CommandQueue(Context *context, Device *device, - bool isCopyOnly, - ze_command_queue_priority_t priority) + ze_command_queue_priority_t queuePriority) : pContext(context) , device(device) - , isCopyOnlyCommandQueue(isCopyOnly) - , priority(priority) {} + , priority(queuePriority) + , defaultPriority(queuePriority) {} ze_result_t CommandQueue::create(ze_context_handle_t hContext, ze_device_handle_t hDevice, @@ -79,9 +79,7 @@ ze_result_t CommandQueue::create(ze_context_handle_t hContext, L0_THROW_WHEN(flags == 0, "Invalid group ordinal", ZE_RESULT_ERROR_INVALID_ARGUMENT); Context *pContext = Context::fromHandle(hContext); - bool isCopyOnly = flags == ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY; - auto commandQueue = - std::make_unique(pContext, pDevice, isCopyOnly, desc->priority); + auto commandQueue = std::make_unique(pContext, pDevice, desc->priority); *phCommandQueue = commandQueue.get(); pContext->appendObject(std::move(commandQueue)); @@ -153,11 +151,6 @@ ze_result_t CommandQueue::executeCommandLists(uint32_t nCommandLists, for (auto i = 0u; i < nCommandLists; i++) { auto cmdList = CommandList::fromHandle(phCommandLists[i]); - if (isCopyOnlyCommandQueue && !cmdList->isCopyOnly()) { - LOG_E("Invalid command list type"); - return ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE; - } - if (!cmdList->isCmdListClosed()) { LOG_E("Command List didn't close"); return ZE_RESULT_ERROR_UNINITIALIZED; @@ -248,4 +241,17 @@ ze_result_t CommandQueue::waitForJobs(std::chrono::steady_clock::time_point absT return Device::jobStatusToResult(jobs); } +ze_result_t CommandQueue::setWorkloadType(ze_command_queue_workload_type_t workloadType) { + switch (workloadType) { + case ZE_WORKLOAD_TYPE_DEFAULT: + priority = defaultPriority; + break; + case ZE_WORKLOAD_TYPE_BACKGROUND: + priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW; + break; + default: + return ZE_RESULT_ERROR_INVALID_ENUMERATION; + } + return ZE_RESULT_SUCCESS; +} } // namespace L0 diff --git a/umd/level_zero_driver/core/source/cmdqueue/cmdqueue.hpp b/umd/level_zero_driver/core/source/cmdqueue/cmdqueue.hpp index 5f9f917..e04780c 100644 --- a/umd/level_zero_driver/core/source/cmdqueue/cmdqueue.hpp +++ b/umd/level_zero_driver/core/source/cmdqueue/cmdqueue.hpp @@ -14,18 +14,15 @@ #include "level_zero_driver/core/source/fence/fence.hpp" // IWYU pragma: keep #include "level_zero_driver/include/l0_handler.hpp" +#include #include // IWYU pragma: keep #include +#include #include #include #include #include -namespace L0 { -struct Context; -struct Device; -} // namespace L0 - namespace VPU { class VPUJob; } // namespace VPU @@ -33,12 +30,11 @@ class VPUJob; struct _ze_command_queue_handle_t {}; namespace L0 { +struct Context; +struct Device; struct CommandQueue : _ze_command_queue_handle_t, IContextObject { - CommandQueue(Context *context, - Device *device, - bool isCopyOnly, - ze_command_queue_priority_t priority); + CommandQueue(Context *context, Device *device, ze_command_queue_priority_t queuePriority); ~CommandQueue() = default; static ze_result_t create(ze_context_handle_t hContext, @@ -61,13 +57,13 @@ struct CommandQueue : _ze_command_queue_handle_t, IContextObject { void destroyFence(Fence *pFence); ze_result_t waitForJobs(std::chrono::steady_clock::time_point timeout, const std::vector> &jobs); - bool isCopyOnly() { return isCopyOnlyCommandQueue; } + ze_result_t setWorkloadType(ze_command_queue_workload_type_t workloadType); protected: Context *pContext = nullptr; Device *device = nullptr; - bool isCopyOnlyCommandQueue = false; - ze_command_queue_priority_t priority; + std::atomic priority; + ze_command_queue_priority_t defaultPriority; std::vector> trackedJobs; std::shared_mutex fenceMutex; diff --git a/umd/level_zero_driver/core/source/device/device.cpp b/umd/level_zero_driver/core/source/device/device.cpp index 1d1e715..33a7f7c 100644 --- a/umd/level_zero_driver/core/source/device/device.cpp +++ b/umd/level_zero_driver/core/source/device/device.cpp @@ -28,12 +28,15 @@ #include #include // IWYU pragma: keep +#include #include #include #include +#include #include #include #include +#include #include namespace L0 { @@ -122,7 +125,15 @@ ze_result_t Device::getProperties(ze_device_properties_t *pDeviceProperties) { pDeviceProperties->deviceId = hwInfo.deviceId; pDeviceProperties->subdeviceId = hwInfo.deviceRevision; pDeviceProperties->coreClockRate = hwInfo.coreClockRate; - pDeviceProperties->maxMemAllocSize = hwInfo.maxMemAllocSize; + + struct sysinfo info = {}; + if (sysinfo(&info) < 0) { + pDeviceProperties->maxMemAllocSize = 0; + LOG_W("Failed to get total ram using sysinfo, errno: %i, str: %s", errno, strerror(errno)); + } else { + pDeviceProperties->maxMemAllocSize = info.totalram * info.mem_unit; + } + pDeviceProperties->maxHardwareContexts = hwInfo.maxHardwareContexts; pDeviceProperties->maxCommandQueuePriority = hwInfo.maxCommandQueuePriority; pDeviceProperties->numThreadsPerEU = hwInfo.numThreadsPerEU; @@ -194,6 +205,36 @@ ze_result_t Device::getProperties(zes_device_properties_t *pDeviceProperties) { return ZE_RESULT_SUCCESS; } +ze_result_t Device::engineGetProperties(zes_engine_properties_t *pEngineProperties) { + if (pEngineProperties == nullptr) { + LOG_E("Invalid pEngineProperties pointer"); + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + } + + pEngineProperties->type = ZES_ENGINE_GROUP_COMPUTE_ALL; + pEngineProperties->onSubdevice = false; + pEngineProperties->subdeviceId = 0; + + return ZE_RESULT_SUCCESS; +} + +ze_result_t Device::engineGetActivity(zes_engine_stats_t *pStats) { + if (pStats == nullptr) { + LOG_E("Invalid pStats pointer"); + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (!getVPUDevice()->getActiveTime(pStats->activeTime)) { + return ZE_RESULT_ERROR_UNINITIALIZED; + } + + auto timestampUs = std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()); + pStats->timestamp = static_cast(timestampUs.count()); + + return ZE_RESULT_SUCCESS; +} + ze_result_t Device::getSubDevices(uint32_t *pCount, ze_device_handle_t *phSubdevices) { if (nullptr == pCount) { LOG_E("Invalid pCount pointer"); @@ -232,12 +273,10 @@ ze_result_t Device::getMemoryProperties(uint32_t *pCount, if (nullptr == pMemProperties) { LOG(DEVICE, "Input memory properties pointer is NULL"); } else { - const auto &hwInfo = vpuDevice->getHwInfo(); - pMemProperties->flags = 0u; - pMemProperties->maxClockRate = hwInfo.coreClockRate; - pMemProperties->maxBusWidth = 32u; - pMemProperties->totalSize = hwInfo.maxMemAllocSize; + pMemProperties->maxClockRate = 0; + pMemProperties->maxBusWidth = 0; + pMemProperties->totalSize = 0; strncpy(pMemProperties->name, getDeviceMemoryName(), ZE_MAX_DEVICE_NAME - 1); pMemProperties->name[ZE_MAX_DEVICE_NAME - 1] = '\0'; } @@ -341,13 +380,7 @@ ze_result_t Device::getCommandQueueGroupProperties( return ZE_RESULT_ERROR_INVALID_NULL_POINTER; } - auto vpuDevice = getVPUDevice(); - if (vpuDevice == nullptr) { - LOG_E("Failed to get VPUDevice instance"); - return ZE_RESULT_ERROR_DEVICE_LOST; - } - - uint32_t count = safe_cast(vpuDevice->getNumberOfEngineGroups()); + uint32_t count = 1u; // Set engine group counts. if (*pCount == 0) { *pCount = count; @@ -358,44 +391,22 @@ ze_result_t Device::getCommandQueueGroupProperties( *pCount = count; if (pCommandQueueGroupProperties != nullptr) { - // Set queue group properties. - for (uint32_t i = 0; i < *pCount; i++) { - auto egProp = &(pCommandQueueGroupProperties[i]); - - // Set flags. - egProp->flags = getCommandQeueueGroupFlags(i); - - // Number of engines in the group. - egProp->numQueues = 1u; - - // Maximum memory fill patern size. - egProp->maxMemoryFillPatternSize = vpuDevice->getEngineMaxMemoryFillSize(); - } + auto egProp = &(pCommandQueueGroupProperties[0]); + egProp->flags = getCommandQeueueGroupFlags(0); + egProp->numQueues = 1u; + egProp->maxMemoryFillPatternSize = sizeof(uint32_t); } return ZE_RESULT_SUCCESS; } ze_command_queue_group_property_flags_t Device::getCommandQeueueGroupFlags(uint32_t ordinal) { - auto type = vpuDevice->getEngineType(ordinal); - if (type == VPU::EngineType::INVALID) { - LOG_W("Invalid ordinal"); - return 0; - } - ze_command_queue_group_property_flags_t flags = 0; - if (vpuDevice->engineSupportCompute(type)) { + + if (ordinal == 0u) { flags |= ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE; - } - if (vpuDevice->engineSupportCopy(type)) { flags |= ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY; } - if (vpuDevice->engineSupportCooperativeKernel(type)) { - flags |= ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS; - } - if (vpuDevice->engineSupportMetrics(type)) { - flags |= ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_METRICS; - } return flags; } diff --git a/umd/level_zero_driver/core/source/device/device.hpp b/umd/level_zero_driver/core/source/device/device.hpp index d6d05c6..04f286f 100644 --- a/umd/level_zero_driver/core/source/device/device.hpp +++ b/umd/level_zero_driver/core/source/device/device.hpp @@ -43,6 +43,8 @@ struct Device : _ze_device_handle_t { ze_device_p2p_properties_t *pP2PProperties); ze_result_t getProperties(ze_device_properties_t *pDeviceProperties); ze_result_t getProperties(zes_device_properties_t *pDeviceProperties); + ze_result_t engineGetProperties(zes_engine_properties_t *pEngineProperties); + ze_result_t engineGetActivity(zes_engine_stats_t *pStats); ze_result_t getSubDevices(uint32_t *pCount, ze_device_handle_t *phSubdevices); ze_result_t getMemoryProperties(uint32_t *pCount, ze_device_memory_properties_t *pMemProperties); diff --git a/umd/level_zero_driver/core/source/driver/driver.cpp b/umd/level_zero_driver/core/source/driver/driver.cpp index 9fc9bcd..fef4849 100644 --- a/umd/level_zero_driver/core/source/driver/driver.cpp +++ b/umd/level_zero_driver/core/source/driver/driver.cpp @@ -7,7 +7,6 @@ #include "level_zero_driver/core/source/driver/driver.hpp" -#include "level_zero_driver/api/tools/ze_tools_loader.h" #include "level_zero_driver/core/source/device/device.hpp" #include "level_zero_driver/core/source/driver/driver_handle.hpp" #include "level_zero_driver/ext/source/graph/compiler.hpp" @@ -74,7 +73,6 @@ ze_result_t Driver::getInitStatus() { void Driver::displayComponentVersions() { LOG(MISC, "Driver version: %s", vpu_drv_version_str); - LOG(MISC, "L0 Loader version: %s", getLoaderVersion().c_str()); LOG(MISC, "CiD version: %s", Compiler::getCompilerVersionString().c_str()); if (pGlobalDriverHandle) { for (auto &device : pGlobalDriverHandle->devices) { diff --git a/umd/level_zero_driver/core/source/driver/driver_handle.cpp b/umd/level_zero_driver/core/source/driver/driver_handle.cpp index 638edac..8238d31 100644 --- a/umd/level_zero_driver/core/source/driver/driver_handle.cpp +++ b/umd/level_zero_driver/core/source/driver/driver_handle.cpp @@ -8,10 +8,7 @@ #include "level_zero_driver/core/source/driver/driver_handle.hpp" #include "level_zero/ze_api.h" -#include "level_zero/ze_graph_ext.h" -#include "level_zero/ze_graph_profiling_ext.h" #include "level_zero/ze_intel_npu_uuid.h" -#include "level_zero_driver/api/ext/ze_graph.hpp" #include "level_zero_driver/core/source/context/context.hpp" #include "level_zero_driver/core/source/device/device.hpp" #include "umd_common.hpp" @@ -19,8 +16,6 @@ #include "vpu_driver/source/device/vpu_device_context.hpp" #include "vpu_driver/source/utilities/log.hpp" -#include -#include #include #include @@ -88,45 +83,6 @@ ze_result_t DriverHandle::getIPCProperties(ze_driver_ipc_properties_t *pIPCPrope return ZE_RESULT_SUCCESS; } -ze_result_t -DriverHandle::getExtensionProperties(uint32_t *pCount, - ze_driver_extension_properties_t *pExtensionProperties) { - std::array supportedExts = {{ - {ZE_GRAPH_EXT_NAME, ZE_GRAPH_EXT_VERSION_1_0}, - {ZE_GRAPH_EXT_NAME_1_1, ZE_GRAPH_EXT_VERSION_1_1}, - {ZE_GRAPH_EXT_NAME_1_2, ZE_GRAPH_EXT_VERSION_1_2}, - {ZE_GRAPH_EXT_NAME_1_3, ZE_GRAPH_EXT_VERSION_1_3}, - {ZE_GRAPH_EXT_NAME_1_4, ZE_GRAPH_EXT_VERSION_1_4}, - {ZE_GRAPH_EXT_NAME_1_5, ZE_GRAPH_EXT_VERSION_1_5}, - {ZE_GRAPH_EXT_NAME_1_6, ZE_GRAPH_EXT_VERSION_1_6}, - {ZE_PROFILING_DATA_EXT_NAME, ZE_PROFILING_DATA_EXT_VERSION_1_0}, - {ZE_MUTABLE_COMMAND_LIST_EXP_NAME, ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_0}, - }}; - - if (pCount == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - } - - if (*pCount == 0) { - *pCount = supportedExts.size(); - return ZE_RESULT_SUCCESS; - } - - if (*pCount > supportedExts.size()) - *pCount = supportedExts.size(); - - if (pExtensionProperties == nullptr) { - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - } - - for (size_t i = 0; i < *pCount; i++) { - *pExtensionProperties = supportedExts[i]; - pExtensionProperties++; - } - - return ZE_RESULT_SUCCESS; -} - ze_result_t DriverHandle::getMemAllocProperties(const void *ptr, ze_memory_allocation_properties_t *pMemAllocProperties, @@ -188,72 +144,4 @@ Device *DriverHandle::getPrimaryDevice() { return nullptr; } -ze_result_t DriverHandle::getExtensionFunctionAddress(const char *name, void **ppFunctionAddress) { - if (name == nullptr || ppFunctionAddress == nullptr) { - LOG_E("Invalid name or ppFunctionAddress pointer"); - return ZE_RESULT_ERROR_INVALID_NULL_POINTER; - } - - if (strcmp(name, ZE_PROFILING_DATA_EXT_NAME) == 0) { - static ze_graph_profiling_dditable_ext_t table; - table.pfnProfilingPoolCreate = L0::zeGraphProfilingPoolCreate; - table.pfnProfilingPoolDestroy = L0::zeGraphProfilingPoolDestroy; - table.pfnProfilingQueryCreate = L0::zeGraphProfilingQueryCreate; - table.pfnProfilingQueryDestroy = L0::zeGraphProfilingQueryDestroy; - table.pfnProfilingQueryGetData = L0::zeGraphProfilingQueryGetData; - table.pfnDeviceGetProfilingDataProperties = L0::zeDeviceGetProfilingDataProperties; - table.pfnProfilingLogGetString = L0::zeGraphProfilingLogGetString; - *ppFunctionAddress = reinterpret_cast(&table); - LOG(DRIVER, "Return DDI table for extension: %s", name); - return ZE_RESULT_SUCCESS; - } - - static ze_graph_dditable_ext_1_6_t table; - // version 1.0 - table.pfnCreate = L0::zeGraphCreate; - table.pfnDestroy = L0::zeGraphDestroy; - table.pfnGetNativeBinary = L0::zeGraphGetNativeBinary; - table.pfnGetProperties = L0::zeGraphGetProperties; - table.pfnGetArgumentProperties = L0::zeGraphGetArgumentProperties; - table.pfnSetArgumentValue = L0::zeGraphSetArgumentValue; - table.pfnAppendGraphInitialize = L0::zeAppendGraphInitialize; - table.pfnAppendGraphExecute = L0::zeAppendGraphExecute; - table.pfnDeviceGetGraphProperties = L0::zeDeviceGetGraphProperties; - - // version 1.1 - table.pfnGraphGetArgumentMetadata = L0::zeGraphGetArgumentMetadata; - table.pfnGetArgumentProperties2 = L0::zeGraphGetArgumentProperties2; - - // version 1.2 - table.pfnGetArgumentProperties3 = L0::zeGraphGetArgumentProperties3; - - // version 1.3 - table.pfnQueryNetworkCreate = L0::zeGraphQueryNetworkCreate; - table.pfnQueryNetworkDestroy = L0::zeGraphQueryNetworkDestroy; - table.pfnQueryNetworkGetSupportedLayers = L0::zeGraphQueryNetworkGetSupportedLayers; - - // version 1.4 - table.pfnBuildLogGetString = L0::zeGraphBuildLogGetString; - - // version 1.5 - table.pfnCreate2 = L0::zeGraphCreate2; - table.pfnQueryNetworkCreate2 = L0::zeGraphQueryNetworkCreate2; - table.pfnQueryContextMemory = L0::zeGraphQueryContextMemory; - - // version 1.6 - table.pfnDeviceGetGraphProperties2 = L0::zeDeviceGetGraphProperties2; - - if (strcmp(name, ZE_GRAPH_EXT_NAME) == 0 || strcmp(name, ZE_GRAPH_EXT_NAME_1_1) == 0 || - strcmp(name, ZE_GRAPH_EXT_NAME_1_2) == 0 || strcmp(name, ZE_GRAPH_EXT_NAME_1_3) == 0 || - strcmp(name, ZE_GRAPH_EXT_NAME_1_4) == 0 || strcmp(name, ZE_GRAPH_EXT_NAME_1_5) == 0 || - strcmp(name, ZE_GRAPH_EXT_NAME_1_6) == 0) { - *ppFunctionAddress = reinterpret_cast(&table); - LOG(DRIVER, "Return DDI table for extension: %s", name); - return ZE_RESULT_SUCCESS; - } - - LOG_E("The name of extension is unknown: %s", name); - return ZE_RESULT_ERROR_UNKNOWN; -} - } // namespace L0 diff --git a/umd/level_zero_driver/core/source/driver/driver_handle.hpp b/umd/level_zero_driver/core/source/driver/driver_handle.hpp index 5c3c10d..71ff49a 100644 --- a/umd/level_zero_driver/core/source/driver/driver_handle.hpp +++ b/umd/level_zero_driver/core/source/driver/driver_handle.hpp @@ -31,9 +31,6 @@ struct DriverHandle : _ze_driver_handle_t { ze_result_t getProperties(ze_driver_properties_t *properties); ze_result_t getApiVersion(ze_api_version_t *version); ze_result_t getIPCProperties(ze_driver_ipc_properties_t *pIPCProperties); - ze_result_t getExtensionProperties(uint32_t *pCount, - ze_driver_extension_properties_t *pExtensionProperties); - ze_result_t getExtensionFunctionAddress(const char *name, void **ppFunctionAddress); ze_result_t getMemAllocProperties(const void *ptr, ze_memory_allocation_properties_t *pMemAllocProperties, diff --git a/umd/level_zero_driver/core/source/event/event.cpp b/umd/level_zero_driver/core/source/event/event.cpp index bc6cc97..e0636fb 100644 --- a/umd/level_zero_driver/core/source/event/event.cpp +++ b/umd/level_zero_driver/core/source/event/event.cpp @@ -54,6 +54,9 @@ void Event::trackMetricData(int64_t timeoutNs) { do { size_t dataSize = 0; + if (*eventState >= VPU::VPUEventCommand::STATE_HOST_SIGNAL) { + break; + } if (MetricStreamer::getData(pDevCtx->getDriverApi(), msGroupMask, dataSize, nullptr) == ZE_RESULT_SUCCESS) { if (dataSize >= msExpectedDataSize) { diff --git a/umd/level_zero_driver/ddi/ze_ddi_tables.hpp b/umd/level_zero_driver/ddi/ze_ddi_tables.hpp deleted file mode 100644 index d22bad3..0000000 --- a/umd/level_zero_driver/ddi/ze_ddi_tables.hpp +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (C) 2022 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include -#include -#include -#include -#include -#include diff --git a/umd/level_zero_driver/ext/source/CMakeLists.txt b/umd/level_zero_driver/ext/source/CMakeLists.txt index 2ca6631..736d9be 100644 --- a/umd/level_zero_driver/ext/source/CMakeLists.txt +++ b/umd/level_zero_driver/ext/source/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT # -target_sources(${TARGET_NAME_L0} PRIVATE +target_sources(${TARGET_NAME_L0_DRV} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/graph/compiler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/graph/compiler.hpp ${CMAKE_CURRENT_SOURCE_DIR}/graph/compiler_common.hpp diff --git a/umd/level_zero_driver/ext/source/graph/blob_container.hpp b/umd/level_zero_driver/ext/source/graph/blob_container.hpp new file mode 100644 index 0000000..39757b6 --- /dev/null +++ b/umd/level_zero_driver/ext/source/graph/blob_container.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include +#include + +#include "vpu_driver/source/os_interface/os_interface.hpp" + +#include + +namespace L0 { + +class BlobContainer { + public: + BlobContainer(uint8_t *ptr, size_t size) + : ptr(ptr) + , size(size) {} + virtual ~BlobContainer() = default; + + public: + uint8_t *ptr; + size_t size; +}; + +class BlobFileContainer : public BlobContainer { + public: + BlobFileContainer(uint8_t *ptr, size_t size, std::unique_ptr file) + : BlobContainer(ptr, size) + , file(std::move(file)) {} + + private: + std::unique_ptr file; +}; + +class BlobAllocContainer : public BlobContainer { + public: + BlobAllocContainer(std::unique_ptr buffer, size_t size) + : BlobContainer(buffer.get(), size) + , buffer(std::move(buffer)) {} + + private: + std::unique_ptr buffer; +}; +} // namespace L0 diff --git a/umd/level_zero_driver/ext/source/graph/compiler.cpp b/umd/level_zero_driver/ext/source/graph/compiler.cpp index 4df50a3..a045075 100644 --- a/umd/level_zero_driver/ext/source/graph/compiler.cpp +++ b/umd/level_zero_driver/ext/source/graph/compiler.cpp @@ -7,16 +7,19 @@ #include "level_zero_driver/ext/source/graph/compiler.hpp" +#include + #include "compiler_common.hpp" #include "level_zero/ze_api.h" +#include "level_zero_driver/ext/source/graph/blob_container.hpp" #include "npu_driver_compiler.h" #include "umd_common.hpp" #include "vcl_symbols.hpp" -#include "vpu_driver/source/device/vpu_device_context.hpp" #include "vpu_driver/source/utilities/log.hpp" +#include #include -#include +#include namespace L0 { @@ -82,70 +85,88 @@ static void copyCompilerLog(vcl_log_handle_t logHandle, std::string &buffer) { LOG(GRAPH, "Saved compiler message to log buffer, message: %s", buffer.c_str()); } -static void -addOptionToBuildFlags(std::string_view key, std::string_view value, std::string &buildFlags) { - if (buildFlags.find("--config") == std::string::npos) { - buildFlags += " --config"; - } - - buildFlags += " " + std::string(key) + "=\"" + std::string(value) + "\""; -} - static bool getCompilerExecutable(VPU::VPUDeviceContext *ctx, - vcl_compiler_handle_t &comp, - vcl_executable_handle_t *exec, + vcl_compiler_handle_t &compiler, ze_graph_desc_2_t &desc, - vcl_log_handle_t *logHandle, - std::string &logBuffer) { + std::unique_ptr &blob) { if (!Vcl::sym().ok()) return false; - std::string buildFlags = ""; - - if (desc.pBuildFlags != nullptr && desc.pBuildFlags[0] != '\0') { - buildFlags = std::string(desc.pBuildFlags); - LOG(GRAPH, "Compiler options: %s", buildFlags.c_str()); - } else { - logBuffer = "Invalid pBuildFlags pointer!"; - LOG_E("Invalid pBuildFlags pointer"); + vcl_executable_handle_t executable = nullptr; + vcl_executable_desc_t exeDesc = {desc.pInput, + desc.inputSize, + desc.pBuildFlags, + strlen(desc.pBuildFlags)}; + LOG(GRAPH, "Compiler options: %s", exeDesc.options); + vcl_result_t ret = Vcl::sym().executableCreate(compiler, exeDesc, &executable); + if (ret != VCL_RESULT_SUCCESS) { + LOG_E("Failed to create compiler executable! Result:%x", ret); return false; } - // Stepping and max_tiles are not supported in versions < 5.3 - if (compilerProperties.version.major >= 5 && compilerProperties.version.minor >= 3) { - if (buildFlags.find("STEPPING") == std::string::npos) { - uint32_t deviceRevision = ctx->getDeviceRevision(); - addOptionToBuildFlags("NPU_STEPPING", std::to_string(deviceRevision), buildFlags); - } - - if (buildFlags.find("MAX_TILES") == std::string::npos) { - uint32_t numSlices = ctx->getNumSlices(); - addOptionToBuildFlags("NPU_MAX_TILES", std::to_string(numSlices), buildFlags); - } + size_t blobSize = 0; + ret = Vcl::sym().executableGetSerializableBlob(executable, NULL, &blobSize); + if (ret != VCL_RESULT_SUCCESS || blobSize == 0) { + LOG_E("Failed to get blob size! Result:%x", ret); + Vcl::sym().executableDestroy(executable); + return false; } - if (desc.flags & ZE_GRAPH_FLAG_ENABLE_PROFILING) { - addOptionToBuildFlags("PERF_COUNT", "YES", buildFlags); + auto blobPtr = std::make_unique(blobSize); + ret = Vcl::sym().executableGetSerializableBlob(executable, blobPtr.get(), &blobSize); + if (ret != VCL_RESULT_SUCCESS) { + LOG_E("Failed to get blob! Result:%x", ret); + Vcl::sym().executableDestroy(executable); + return false; } + blob = std::make_unique(std::move(blobPtr), blobSize); + Vcl::sym().executableDestroy(executable); + return true; +} + +static uint8_t *vclAllocate(uint64_t size) { + return new uint8_t[size]; +} + +static void vclDeallocate(uint8_t *ptr) { + delete[] ptr; +} + +static bool getCompilerExecutableAllocation(VPU::VPUDeviceContext *ctx, + vcl_compiler_handle_t &compiler, + ze_graph_desc_2_t &desc, + std::unique_ptr &blob) { + if (!Vcl::sym().ok()) + return false; + vcl_executable_desc_t exeDesc = {desc.pInput, desc.inputSize, - buildFlags.c_str(), - buildFlags.size()}; - vcl_result_t ret = Vcl::sym().executableCreate(comp, exeDesc, exec); + desc.pBuildFlags, + strlen(desc.pBuildFlags)}; + LOG(GRAPH, "Compiler options: %s", exeDesc.options); + + vcl_allocator_t allocator = {.allocate = &vclAllocate, .deallocate = &vclDeallocate}; + + uint8_t *graphBuffer = nullptr; + size_t graphSize = 0; + vcl_result_t ret = Vcl::sym().allocatedExecutableCreate(compiler, + exeDesc, + &allocator, + &graphBuffer, + &graphSize); if (ret != VCL_RESULT_SUCCESS) { - copyCompilerLog(*logHandle, logBuffer); LOG_E("Failed to create compiler executable! Result:%x", ret); return false; } + blob = std::make_unique(std::unique_ptr(graphBuffer), graphSize); return true; } bool Compiler::getCompiledBlob(VPU::VPUDeviceContext *ctx, - size_t &graphSize, - std::vector &graphBlob, ze_graph_desc_2_t &desc, + std::unique_ptr &blob, std::string &logBuffer) { if (!Vcl::sym().ok()) return false; @@ -180,35 +201,22 @@ bool Compiler::getCompiledBlob(VPU::VPUDeviceContext *ctx, return false; } - vcl_executable_handle_t executable; - if (!getCompilerExecutable(ctx, compiler, &executable, desc, &logHandle, logBuffer)) { - LOG_E("Failed to get compiler executable"); - Vcl::sym().compilerDestroy(compiler); - return false; - } - - ret = Vcl::sym().executableGetSerializableBlob(executable, NULL, &graphSize); - if (ret != VCL_RESULT_SUCCESS || graphSize == 0) { - copyCompilerLog(logHandle, logBuffer); - LOG_E("Failed to get blob size! Result:%x", ret); - Vcl::sym().executableDestroy(executable); - Vcl::sym().compilerDestroy(compiler); - return false; - } - - graphBlob.resize(graphSize); - ret = Vcl::sym().executableGetSerializableBlob(executable, graphBlob.data(), &graphSize); - if (ret != VCL_RESULT_SUCCESS) { + if ((getCompilerVersionMajor() == 6 && getCompilerVersionMinor() >= 1) || + getCompilerVersionMajor() > 6) { + if (!getCompilerExecutableAllocation(ctx, compiler, desc, blob)) { + copyCompilerLog(logHandle, logBuffer); + LOG_E("Failed to get compiler executable"); + Vcl::sym().compilerDestroy(compiler); + return false; + } + } else if (!getCompilerExecutable(ctx, compiler, desc, blob)) { copyCompilerLog(logHandle, logBuffer); - LOG_E("Failed to get blob! Result:%x", ret); - Vcl::sym().executableDestroy(executable); + LOG_E("Failed to get compiler executable"); Vcl::sym().compilerDestroy(compiler); return false; } - Vcl::sym().executableDestroy(executable); Vcl::sym().compilerDestroy(compiler); - return true; } @@ -247,7 +255,7 @@ std::string Compiler::getCompilerVersionString() { } ze_result_t Compiler::getDecodedProfilingBuffer(ze_graph_profiling_type_t profilingType, - const struct BlobInfo *blob, + const BlobContainer &blob, const uint8_t *profData, uint64_t profSize, uint32_t *pSize, @@ -257,8 +265,8 @@ ze_result_t Compiler::getDecodedProfilingBuffer(ze_graph_profiling_type_t profil return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; vcl_profiling_handle_t profHandle = NULL; - vcl_profiling_input_t profilingApiInput = {.blobData = blob->ptr, - .blobSize = blob->size, + vcl_profiling_input_t profilingApiInput = {.blobData = blob.ptr, + .blobSize = blob.size, .profData = profData, .profSize = profSize}; vcl_log_handle_t logHandle = NULL; diff --git a/umd/level_zero_driver/ext/source/graph/compiler.hpp b/umd/level_zero_driver/ext/source/graph/compiler.hpp index ea63626..9d00204 100644 --- a/umd/level_zero_driver/ext/source/graph/compiler.hpp +++ b/umd/level_zero_driver/ext/source/graph/compiler.hpp @@ -7,7 +7,6 @@ #pragma once -#include #include #include "npu_driver_compiler.h" @@ -15,10 +14,8 @@ #include #include #include +#include #include -#include - -struct BlobInfo; // IWYU pragma: keep namespace VPU { class VPUDeviceContext; @@ -26,13 +23,14 @@ class VPUDeviceContext; namespace L0 { +class BlobContainer; + class Compiler { public: static bool compilerInit(int compilerPlatformType); static bool getCompiledBlob(VPU::VPUDeviceContext *ctx, - size_t &graphSize, - std::vector &graphBlob, ze_graph_desc_2_t &desc, + std::unique_ptr &graphBlob, std::string &logBuffer); static bool getCompilerProperties(vcl_compiler_properties_t *pProperties); static uint16_t getCompilerVersionMajor(); @@ -40,7 +38,7 @@ class Compiler { static bool checkVersion(uint16_t major); static std::string getCompilerVersionString(); static ze_result_t getDecodedProfilingBuffer(ze_graph_profiling_type_t profilingType, - const struct BlobInfo *blob, + const BlobContainer &blob, const uint8_t *profData, uint64_t profSize, uint32_t *size, diff --git a/umd/level_zero_driver/ext/source/graph/disk_cache.cpp b/umd/level_zero_driver/ext/source/graph/disk_cache.cpp index 0c43467..7a13af4 100644 --- a/umd/level_zero_driver/ext/source/graph/disk_cache.cpp +++ b/umd/level_zero_driver/ext/source/graph/disk_cache.cpp @@ -7,8 +7,11 @@ #include "disk_cache.hpp" +#include + #include "compiler.hpp" #include "hash_function.hpp" +#include "level_zero_driver/ext/source/graph/blob_container.hpp" #include "npu_driver_compiler.h" #include "vpu_driver/source/os_interface/os_interface.hpp" #include "vpu_driver/source/utilities/log.hpp" @@ -106,7 +109,7 @@ DiskCache::Key DiskCache::computeKey(const ze_graph_desc_2_t &desc) { return hash.final(); } -DiskCache::Blob DiskCache::getBlob(const Key &key) { +std::unique_ptr DiskCache::getBlob(const Key &key) { if (cachePath.empty()) return {}; @@ -114,19 +117,15 @@ DiskCache::Blob DiskCache::getBlob(const Key &key) { std::filesystem::path dataPath = cachePath / filename; auto file = osInfc.osiOpenWithSharedLock(dataPath, false); - if (!file) { + if (!file || file->size() == 0 || file->mmap() == nullptr) { LOG(CACHE, "Cache missed using %s key", filename.c_str()); - return {}; - } - - std::vector data(file->size(), 0); - if (!file->read(data.data(), data.size())) { - LOG(CACHE, "Cache missed using %s key", filename.c_str()); - return {}; + return nullptr; } LOG(CACHE, "Cache hit using %s key", filename.c_str()); - return data; + return std::make_unique(static_cast(file->mmap()), + file->size(), + std::move(file)); } static size_t @@ -145,7 +144,7 @@ removeLeastUsedFiles(VPU::OsInterface &osInfc, std::filesystem::path &cachePath, continue; auto fileSize = file->size(); - if (!file->remove()) + if (!osInfc.osiFileRemove(filePath)) continue; LOG(CACHE, @@ -161,13 +160,13 @@ removeLeastUsedFiles(VPU::OsInterface &osInfc, std::filesystem::path &cachePath, return removedSize; } -void DiskCache::setBlob(const Key &key, const Blob &val) { - if (cachePath.empty()) +void DiskCache::setBlob(const Key &key, const std::unique_ptr &blob) { + if (blob == nullptr || cachePath.empty()) return; size_t cacheSize = getCacheSize(osInfc, cachePath); - if (cacheSize + val.size() > maxSize) { - cacheSize -= removeLeastUsedFiles(osInfc, cachePath, cacheSize + val.size() - maxSize); + if (cacheSize + blob->size > maxSize) { + cacheSize -= removeLeastUsedFiles(osInfc, cachePath, cacheSize + blob->size - maxSize); } std::filesystem::path dstPath = cachePath / key; @@ -175,16 +174,16 @@ void DiskCache::setBlob(const Key &key, const Blob &val) { if (!file) return; - if (!file->write(val.data(), val.size())) { - file->remove(); + if (!file->write(blob->ptr, blob->size)) { + osInfc.osiFileRemove(dstPath); return; } - cacheSize += val.size(); + cacheSize += blob->size; LOG(CACHE, "Cache set %s key, data size: %lu, cache size: %lu", key.c_str(), - val.size(), + blob->size, cacheSize); } diff --git a/umd/level_zero_driver/ext/source/graph/disk_cache.hpp b/umd/level_zero_driver/ext/source/graph/disk_cache.hpp index c60f65c..10c7ed5 100644 --- a/umd/level_zero_driver/ext/source/graph/disk_cache.hpp +++ b/umd/level_zero_driver/ext/source/graph/disk_cache.hpp @@ -8,13 +8,13 @@ #pragma once #include -#include #include "level_zero/ze_graph_ext.h" +#include "level_zero_driver/ext/source/graph/blob_container.hpp" #include +#include #include -#include namespace VPU { class OsInterface; @@ -27,11 +27,10 @@ class DiskCache { DiskCache(VPU::OsInterface &osInfc); using Key = std::string; - using Blob = std::vector; Key computeKey(const ze_graph_desc_2_t &desc); - Blob getBlob(const Key &key); - void setBlob(const Key &key, const Blob &val); + std::unique_ptr getBlob(const Key &key); + void setBlob(const Key &key, const std::unique_ptr &blob); private: VPU::OsInterface &osInfc; diff --git a/umd/level_zero_driver/ext/source/graph/elf_parser.cpp b/umd/level_zero_driver/ext/source/graph/elf_parser.cpp index bb935e1..42b7181 100644 --- a/umd/level_zero_driver/ext/source/graph/elf_parser.cpp +++ b/umd/level_zero_driver/ext/source/graph/elf_parser.cpp @@ -12,6 +12,7 @@ #include "level_zero/ze_api.h" #include "level_zero/ze_graph_ext.h" +#include "level_zero_driver/ext/source/graph/blob_container.hpp" #include "level_zero_driver/include/l0_exception.hpp" #include "npu_driver_compiler.h" #include "umd_common.hpp" @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -83,7 +85,7 @@ class DriverBufferManager : public elf::BufferManager { bo->getBasePointer(), bo->getVPUAddr(), bo->getAllocSize()); - return elf::DeviceBuffer(bo->getBasePointer(), bo->getVPUAddr(), size); + return elf::DeviceBuffer(bo->getBasePointer(), bo->getVPUAddr(), buffSpecs.size); } void deallocate(elf::DeviceBuffer &devAddress) override { @@ -158,10 +160,6 @@ class ElfAccessManager : public elf::AccessManager { return buffer; } - if (specs.alignment == 0 || (reinterpret_cast(start) % specs.alignment) == 0) { - return std::make_unique(start, specs); - } - auto dynBuffer = std::make_unique(specs); elf::DeviceBuffer devBuffer = dynBuffer->getBuffer(); memcpy(devBuffer.cpu_addr(), start, devBuffer.size()); @@ -180,8 +178,8 @@ class ElfAccessManager : public elf::AccessManager { private: static bool hasNPUAccess(uint64_t flags) { - return (flags & (elf::SHF_EXECINSTR | elf::VPU_SHF_PROC_DMA | elf::VPU_SHF_PROC_SHAVE)) != - 0; + return (flags & (elf::SHF_EXECINSTR | elf::VPU_SHF_PROC_DMA | elf::VPU_SHF_PROC_SHAVE | + elf::SHF_ALLOC)) != 0; } uint8_t *blob = nullptr; @@ -197,7 +195,7 @@ ElfParser::ElfParser(VPU::VPUDeviceContext *ctx, , accessManager(std::move(access)) , hpi(std::move(hpi)) {} -bool ElfParser::checkMagic(const struct BlobInfo *blob) { +bool ElfParser::checkMagic(const std::unique_ptr &blob) { if (blob->size == 0) return false; @@ -225,9 +223,7 @@ createHostParsedInference(elf::BufferManager *buffer, config.archKind = toArchKind(ctx->getCompilerPlatform()); try { - auto hpi = std::make_shared(buffer, access, config); - hpi->load(); - return hpi; + return std::make_shared(buffer, access, config); } catch (const elf::AllocError &err) { LOG_E("Failed to create elf::HostParsedInference, type: elf::AllocError, reason: %s", err.what()); @@ -280,7 +276,7 @@ copyHostParsedInference(std::shared_ptr &hpi) { } std::unique_ptr ElfParser::getElfParser(VPU::VPUDeviceContext *ctx, - const struct BlobInfo *blob, + const std::unique_ptr &blob, std::string &logBuffer) { auto bufferManager = std::make_unique(ctx); auto accessManager = @@ -685,15 +681,47 @@ bool ElfParser::applyInputOutputs(std::shared_ptr &cmd return true; } +static void loadHostParsedInference(const std::shared_ptr &hpi) { + try { + hpi->load(); + return; + } catch (const elf::AllocError &err) { + LOG_E("Failed to load elf::HostParsedInference, type: elf::AllocError, reason: %s", + err.what()); + throw DriverError(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY); + } catch (elf::VersioningError &err) { + LOG_E("Failed to load elf::HostParsedInference, type: elf::VersioningError, reason: %s", + err.what()); + throw DriverError(ZE_RESULT_ERROR_UNSUPPORTED_VERSION); + } catch (const elf::RuntimeError &err) { + LOG_E("Failed to load elf::HostParsedInference, type: elf::RuntimeError, reason: %s", + err.what()); + } catch (const elf::LogicError &err) { + LOG_E("Failed to load elf::HostParsedInference, type: elf::LogicError, reason: %s", + err.what()); + } catch (const std::exception &err) { + LOG_E("Failed to load elf::HostParsedInference, type: std::exception, reason: %s", + err.what()); + } + throw DriverError(ZE_RESULT_ERROR_UNKNOWN); +} + std::shared_ptr ElfParser::createInferenceExecuteCommand( const std::vector> &inputPtrs, const std::vector> &outputPtrs, - const std::pair &profilingPtr, - std::shared_ptr &execHpi) { + const std::pair &profilingPtr) { uint64_t inferenceId = 0; if (!ctx->getUniqueInferenceId(inferenceId)) return nullptr; + { + std::lock_guard lg(loadMutex); + if (needLoad) { + loadHostParsedInference(hpi); + needLoad = false; + } + } + std::shared_ptr cmdHpi; if (needCopy) { cmdHpi = copyHostParsedInference(hpi); @@ -737,7 +765,6 @@ std::shared_ptr ElfParser::createInferenceExecuteComma if (cmd == nullptr) return nullptr; - execHpi = std::move(cmdHpi); needCopy = true; return cmd; } @@ -761,7 +788,24 @@ ze_result_t ElfParser::parse(std::vector &argu return ZE_RESULT_SUCCESS; } +ze_result_t ElfParser::initialize() { + try { + std::lock_guard lg(loadMutex); + if (needLoad) { + loadHostParsedInference(hpi); + needLoad = false; + } + return ZE_RESULT_SUCCESS; + } catch (const DriverError &e) { + return e.result(); + } + return ZE_RESULT_ERROR_UNKNOWN; +} + std::shared_ptr ElfParser::allocateInitCommand(VPU::VPUDeviceContext *ctx) { + ze_result_t result = initialize(); + if (result != ZE_RESULT_SUCCESS) + return nullptr; /* No initialize command for elf, return empty command that will be ignored */ return std::make_shared(); } @@ -770,12 +814,10 @@ std::shared_ptr ElfParser::allocateExecuteCommand(VPU::VPUDeviceContext *ctx, const std::vector> &inputArgs, const std::vector> &outputArgs, - const std::pair &profilingPtr, - std::shared_ptr &execHpi) { + const std::pair &profilingPtr) { return createInferenceExecuteCommand(inputArgs, outputArgs, - {profilingPtr.first, profilingPtr.second}, - execHpi); + {profilingPtr.first, profilingPtr.second}); } } // namespace L0 diff --git a/umd/level_zero_driver/ext/source/graph/elf_parser.hpp b/umd/level_zero_driver/ext/source/graph/elf_parser.hpp index 66e697f..b12e77d 100644 --- a/umd/level_zero_driver/ext/source/graph/elf_parser.hpp +++ b/umd/level_zero_driver/ext/source/graph/elf_parser.hpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,8 @@ class VPUInferenceExecute; namespace L0 { +class BlobContainer; + class ElfParser : public IParser, public std::enable_shared_from_this { public: ElfParser(VPU::VPUDeviceContext *ctx, @@ -39,9 +42,10 @@ class ElfParser : public IParser, public std::enable_shared_from_this std::unique_ptr access, std::shared_ptr loader); - static bool checkMagic(const struct BlobInfo *blob); - static std::unique_ptr - getElfParser(VPU::VPUDeviceContext *ctx, const struct BlobInfo *blob, std::string &logBuffer); + static bool checkMagic(const std::unique_ptr &blob); + static std::unique_ptr getElfParser(VPU::VPUDeviceContext *ctx, + const std::unique_ptr &blob, + std::string &logBuffer); static elf::VersionsProvider getElfVer(int arch); bool getArgumentProperties(std::vector &props) const; @@ -51,21 +55,21 @@ class ElfParser : public IParser, public std::enable_shared_from_this std::shared_ptr createInferenceExecuteCommand(const std::vector> &inputPtrs, const std::vector> &outputPtrs, - const std::pair &profilingPtr, - std::shared_ptr &execHpi); + const std::pair &profilingPtr); ze_result_t parse(std::vector &argumentProperties, std::vector &argumentMetadata, uint32_t &profilingOutputSize) override; + ze_result_t initialize() override; + std::shared_ptr allocateInitCommand(VPU::VPUDeviceContext *ctx) override; std::shared_ptr allocateExecuteCommand(VPU::VPUDeviceContext *ctx, const std::vector> &inputArgs, const std::vector> &outputArgs, - const std::pair &profilingPtr, - std::shared_ptr &execHpi) override; + const std::pair &profilingPtr) override; bool applyInputOutputs(std::shared_ptr &hpi, const std::vector> &inputs, @@ -79,6 +83,8 @@ class ElfParser : public IParser, public std::enable_shared_from_this std::unique_ptr accessManager; std::shared_ptr hpi; bool needCopy = false; + bool needLoad = true; + std::mutex loadMutex; }; template diff --git a/umd/level_zero_driver/ext/source/graph/graph.cpp b/umd/level_zero_driver/ext/source/graph/graph.cpp index c0dc411..2abac46 100644 --- a/umd/level_zero_driver/ext/source/graph/graph.cpp +++ b/umd/level_zero_driver/ext/source/graph/graph.cpp @@ -12,26 +12,27 @@ #include "level_zero_driver/core/source/context/context.hpp" #include "level_zero_driver/core/source/device/device.hpp" #include "level_zero_driver/core/source/driver/driver.hpp" +#include "level_zero_driver/ext/source/graph/blob_container.hpp" #include "level_zero_driver/ext/source/graph/compiler.hpp" #include "level_zero_driver/ext/source/graph/disk_cache.hpp" #include "level_zero_driver/ext/source/graph/elf_parser.hpp" +#include "level_zero_driver/ext/source/graph/interface_parser.hpp" #include "level_zero_driver/ext/source/graph/profiling_data.hpp" #include "level_zero_driver/include/l0_exception.hpp" #include "npu_driver_compiler.h" #include "umd_common.hpp" #include "vpu_driver/source/device/hw_info.hpp" #include "vpu_driver/source/device/vpu_device.hpp" +#include "vpu_driver/source/device/vpu_device_context.hpp" #include "vpu_driver/source/utilities/log.hpp" #include "vpux_elf/utils/version.hpp" #include "vpux_hpi.hpp" #include +#include #include #include - -namespace VPU { -class VPUDeviceContext; -} // namespace VPU +#include namespace L0 { @@ -40,7 +41,8 @@ static thread_local std::string lastErrorMsg = {}; Graph::Graph(Context *pCtx, const ze_graph_desc_2_t *pDesc) : pContext(pCtx) , ctx(pCtx->getDeviceContext()) - , desc(*pDesc) { + , desc(*pDesc) + , buildFlags(desc.pBuildFlags != nullptr ? desc.pBuildFlags : "") { initialize(); } @@ -89,21 +91,28 @@ ze_result_t Graph::getNativeBinary(size_t *pSize, uint8_t *pGraphNativeBinary) { return ZE_RESULT_ERROR_INVALID_NULL_POINTER; } - if (blob.size == 0) { + if (blob == nullptr || blob->size == 0) { LOG_E("Native binary does not exist for Graph"); return ZE_RESULT_ERROR_UNINITIALIZED; } - if (*pSize == 0 || *pSize > blob.size) { - *pSize = blob.size; + if (*pSize == 0 || *pSize > blob->size) { + *pSize = blob->size; } if (pGraphNativeBinary != nullptr) { - memcpy(pGraphNativeBinary, blob.ptr, *pSize); + memcpy(pGraphNativeBinary, blob->ptr, *pSize); } return ZE_RESULT_SUCCESS; } +ze_result_t Graph::getNativeBinary2(size_t *pSize, const uint8_t **pGraphNativeBinary) { + *pSize = blob->size; + *pGraphNativeBinary = blob->ptr; + + return ZE_RESULT_SUCCESS; +} + ze_result_t Graph::setArgumentValue(uint32_t argIndex, const void *pArgValue) { if (pArgValue == nullptr) return ZE_RESULT_ERROR_INVALID_NULL_POINTER; @@ -128,6 +137,13 @@ ze_result_t Graph::getProperties(ze_graph_properties_t *pGraphProperties) { return ZE_RESULT_SUCCESS; } +ze_result_t Graph::getProperties2(ze_graph_properties_2_t *pGraphProperties) { + pGraphProperties->numGraphArgs = safe_cast(argumentProperties.size()); + pGraphProperties->initStageRequired = ZE_GRAPH_STAGE_INITIALIZE; + + return ZE_RESULT_SUCCESS; +} + ze_result_t Graph::getArgumentProperties(uint32_t argIndex, ze_graph_argument_properties_t *pGraphArgProps) { if (pGraphArgProps == nullptr) { @@ -227,7 +243,7 @@ ze_result_t Graph::createProfilingPool(uint32_t count, std::make_unique(ctx, profilingOutputSize, count, - &blob, + blob.get(), [this](auto *x) { profilingPools.erase(x); }); auto [it, success] = profilingPools.emplace(profilingPool.get(), std::move(profilingPool)); L0_THROW_WHEN(!success, @@ -337,6 +353,35 @@ static uint32_t getArgumentSize(const ze_graph_argument_properties_3_t &prop) { return safe_cast(size); } +static void +addOptionToBuildFlags(std::string_view key, std::string_view value, std::string &buildFlags) { + if (buildFlags.find("--config") == std::string::npos) { + buildFlags += " --config"; + } + + buildFlags += " " + std::string(key) + "=\"" + std::string(value) + "\""; +} + +void Graph::addDeviceConfigToBuildFlags() { + // Stepping and max_tiles are not supported in versions < 5.3 + if (Compiler::getCompilerVersionMajor() > 5 || + (Compiler::getCompilerVersionMajor() == 5 && Compiler::getCompilerVersionMinor() >= 3)) { + if (buildFlags.find("STEPPING") == std::string::npos) { + uint32_t deviceRevision = ctx->getDeviceRevision(); + addOptionToBuildFlags("NPU_STEPPING", std::to_string(deviceRevision), buildFlags); + } + + if (buildFlags.find("MAX_TILES") == std::string::npos) { + uint32_t numSlices = ctx->getNumSlices(); + addOptionToBuildFlags("NPU_MAX_TILES", std::to_string(numSlices), buildFlags); + } + } + + if (desc.flags & ZE_GRAPH_FLAG_ENABLE_PROFILING) { + addOptionToBuildFlags("PERF_COUNT", "YES", buildFlags); + } +} + void Graph::initialize() { L0_THROW_WHEN(desc.pInput == nullptr, "Invalid input pointer", @@ -346,33 +391,39 @@ void Graph::initialize() { DiskCache &cache = Driver::getInstance()->getDiskCache(); DiskCache::Key key; + LOG(GRAPH, + "ze_graph_desc_2_t = format: %#x, pInput: %p, inputSize: %lu, flags: %#x, pBuildFlags: %s", + desc.format, + desc.pInput, + desc.inputSize, + desc.flags, + desc.pBuildFlags); + switch (desc.format) { case ZE_GRAPH_FORMAT_NATIVE: - LOG(GRAPH, "Format: ZE_GRAPH_FORMAT_NATIVE"); - blob.ptr = (uint8_t *)desc.pInput; - blob.size = desc.inputSize; + blob = std::make_unique(const_cast(desc.pInput), desc.inputSize); break; case ZE_GRAPH_FORMAT_NGRAPH_LITE: - LOG(GRAPH, "Format: ZE_GRAPH_FORMAT_NGRAPH_LITE"); + addDeviceConfigToBuildFlags(); if (!(desc.flags & ZE_GRAPH_FLAG_DISABLE_CACHING)) { key = cache.computeKey(desc); - blobCached = cache.getBlob(key); + blob = cache.getBlob(key); } - if (blobCached.empty()) { - if (!Compiler::getCompiledBlob(ctx, desc.inputSize, blobCached, desc, lastErrorMsg)) { + if (blob == nullptr) { + desc.pBuildFlags = buildFlags.c_str(); + + if (!Compiler::getCompiledBlob(ctx, desc, blob, lastErrorMsg)) { LOG_E("Failed to get compiled blob!"); throw DriverError(ZE_RESULT_ERROR_UNKNOWN); } if (!(desc.flags & ZE_GRAPH_FLAG_DISABLE_CACHING)) { - cache.setBlob(key, blobCached); + cache.setBlob(key, blob); } } - blob.ptr = blobCached.data(); - blob.size = blobCached.size(); break; default: LOG_E("Graph desc (ze_graph_desc_2_t) format invalid."); @@ -380,9 +431,9 @@ void Graph::initialize() { throw DriverError(ZE_RESULT_ERROR_INVALID_ARGUMENT); } - if (ElfParser::checkMagic(&blob)) { + if (ElfParser::checkMagic(blob)) { LOG(GRAPH, "Detected Elf format"); - parser = ElfParser::getElfParser(ctx, &blob, lastErrorMsg); + parser = ElfParser::getElfParser(ctx, blob, lastErrorMsg); } else { LOG_E("Failed to recognize blob format"); lastErrorMsg = "Failed to recognize native binary format"; @@ -406,18 +457,20 @@ void Graph::initialize() { } } +ze_result_t Graph::parserInitialize() { + return parser->initialize(); +} + std::shared_ptr Graph::allocateGraphInitCommand(VPU::VPUDeviceContext *ctx) { return parser->allocateInitCommand(ctx); } -std::unique_ptr Graph::getGraphExecutor(VPU::VPUDeviceContext *ctx, - void *profilingQueryPtr) { - return std::make_unique( - parser, - ctx, - inputArgs, - outputArgs, - std::make_pair(profilingQueryPtr, profilingOutputSize)); +std::shared_ptr Graph::allocateGraphExecuteCommand(VPU::VPUDeviceContext *ctx, + void *profilingQueryPtr) { + return parser->allocateExecuteCommand(ctx, + inputArgs, + outputArgs, + std::make_pair(profilingQueryPtr, profilingOutputSize)); } ze_result_t Graph::getLogString(uint32_t *pSize, char *pBuildLog) { diff --git a/umd/level_zero_driver/ext/source/graph/graph.hpp b/umd/level_zero_driver/ext/source/graph/graph.hpp index 80d1f19..e1d75b3 100644 --- a/umd/level_zero_driver/ext/source/graph/graph.hpp +++ b/umd/level_zero_driver/ext/source/graph/graph.hpp @@ -10,15 +10,15 @@ #include #include -#include "level_zero_driver/ext/source/graph/interface_parser.hpp" +#include "level_zero_driver/ext/source/graph/blob_container.hpp" #include "level_zero_driver/include/l0_handler.hpp" -#include "umd_common.hpp" #include "vpu_driver/source/command/vpu_command.hpp" #include #include #include #include +#include #include #include #include @@ -26,38 +26,14 @@ namespace VPU { class VPUDeviceContext; } // namespace VPU -namespace elf { -class HostParsedInference; -} // namespace elf struct _ze_graph_handle_t {}; namespace L0 { +class IParser; struct Context; struct GraphProfilingPool; -struct InferenceExecutor { - public: - InferenceExecutor(std::shared_ptr &p, - VPU::VPUDeviceContext *ctx, - const std::vector> &inputArgs, - const std::vector> &outputArgs, - const std::pair &profilingPtr) { - parser = p; - exeCmd = parser->allocateExecuteCommand(ctx, - inputArgs, - outputArgs, - {profilingPtr.first, profilingPtr.second}, - hpi); - } - std::shared_ptr getExecuteCommand() { return exeCmd; } - - private: - std::shared_ptr parser; - std::shared_ptr hpi; - std::shared_ptr exeCmd; -}; - struct Graph : _ze_graph_handle_t, IContextObject { Graph(Context *pCtx, const ze_graph_desc_2_t *pDesc); ~Graph() = default; @@ -68,8 +44,10 @@ struct Graph : _ze_graph_handle_t, IContextObject { ze_graph_handle_t *phGraph); ze_result_t destroy(); ze_result_t getNativeBinary(size_t *pSize, uint8_t *pGraphNativeBinary); + ze_result_t getNativeBinary2(size_t *pSize, const uint8_t **pGraphNativeBinary); ze_result_t setArgumentValue(uint32_t argIndex, const void *pArgValue); ze_result_t getProperties(ze_graph_properties_t *pGraphProperties); + ze_result_t getProperties2(ze_graph_properties_2_t *pGraphProperties); ze_result_t getArgumentProperties(uint32_t argIndex, ze_graph_argument_properties_t *pGraphArgProps); ze_result_t getArgumentProperties2(uint32_t argIndex, @@ -94,21 +72,24 @@ struct Graph : _ze_graph_handle_t, IContextObject { static Graph *fromHandle(ze_graph_handle_t handle) { return static_cast(handle); } inline ze_graph_handle_t toHandle() { return this; } + ze_result_t parserInitialize(); + std::shared_ptr allocateGraphInitCommand(VPU::VPUDeviceContext *ctx); - std::unique_ptr getGraphExecutor(VPU::VPUDeviceContext *ctx, - void *profilingQueryPtr); + std::shared_ptr allocateGraphExecuteCommand(VPU::VPUDeviceContext *ctx, + void *profilingQueryPtr); static ze_result_t getLogString(uint32_t *pSize, char *pBuildLog); private: void initialize(); + void addDeviceConfigToBuildFlags(); Context *pContext; VPU::VPUDeviceContext *ctx; ze_graph_desc_2_t desc; + std::string buildFlags; - struct BlobInfo blob = {}; - std::vector blobCached; + std::unique_ptr blob; std::vector> inputArgs; std::vector> outputArgs; diff --git a/umd/level_zero_driver/ext/source/graph/interface_parser.hpp b/umd/level_zero_driver/ext/source/graph/interface_parser.hpp index 37ac283..b8ab767 100644 --- a/umd/level_zero_driver/ext/source/graph/interface_parser.hpp +++ b/umd/level_zero_driver/ext/source/graph/interface_parser.hpp @@ -23,13 +23,13 @@ class IParser { virtual ze_result_t parse(std::vector &props, std::vector &args, uint32_t &size) = 0; + virtual ze_result_t initialize() = 0; virtual std::shared_ptr allocateInitCommand(VPU::VPUDeviceContext *ctx) = 0; virtual std::shared_ptr allocateExecuteCommand(VPU::VPUDeviceContext *ctx, const std::vector> &inputArgs, const std::vector> &outputArgs, - const std::pair &profilingPtr, - std::shared_ptr &execHpi) = 0; + const std::pair &profilingPtr) = 0; }; } // namespace L0 diff --git a/umd/level_zero_driver/ext/source/graph/profiling_data.cpp b/umd/level_zero_driver/ext/source/graph/profiling_data.cpp index b47b6ea..b1d7444 100644 --- a/umd/level_zero_driver/ext/source/graph/profiling_data.cpp +++ b/umd/level_zero_driver/ext/source/graph/profiling_data.cpp @@ -27,7 +27,7 @@ static thread_local std::string lastErrorMsg = {}; GraphProfilingPool::GraphProfilingPool(VPU::VPUDeviceContext *ctx, const uint32_t size, const uint32_t count, - const struct BlobInfo *blob, + const BlobContainer *blob, std::function destroyCb) : ctx(ctx) , querySize(size) @@ -47,7 +47,7 @@ GraphProfilingPool::~GraphProfilingPool() { } } -GraphProfilingQuery::GraphProfilingQuery(const struct BlobInfo *blob, +GraphProfilingQuery::GraphProfilingQuery(const BlobContainer *blob, const uint32_t size, void *pData, std::function &&destroyCb) @@ -95,7 +95,7 @@ ze_result_t GraphProfilingQuery::getData(ze_graph_profiling_type_t profilingType if (profilingType == ZE_GRAPH_PROFILING_LAYER_LEVEL || profilingType == ZE_GRAPH_PROFILING_TASK_LEVEL) { return Compiler::getDecodedProfilingBuffer(profilingType, - blob, + *blob, static_cast(data), size, pSize, diff --git a/umd/level_zero_driver/ext/source/graph/profiling_data.hpp b/umd/level_zero_driver/ext/source/graph/profiling_data.hpp index 0a9bc9e..3f23bb3 100644 --- a/umd/level_zero_driver/ext/source/graph/profiling_data.hpp +++ b/umd/level_zero_driver/ext/source/graph/profiling_data.hpp @@ -15,8 +15,6 @@ #include #include -struct BlobInfo; // IWYU pragma: keep - namespace VPU { class VPUBufferObject; class VPUDeviceContext; @@ -27,9 +25,11 @@ struct _ze_graph_profiling_pool_handle_t {}; namespace L0 { +class BlobContainer; + struct GraphProfilingQuery : _ze_graph_profiling_query_handle_t { public: - GraphProfilingQuery(const struct BlobInfo *blob, + GraphProfilingQuery(const BlobContainer *blob, const uint32_t size, void *queryPtrInput, std::function &&destroyCb); @@ -48,7 +48,7 @@ struct GraphProfilingQuery : _ze_graph_profiling_query_handle_t { private: uint32_t size = 0u; void *data = nullptr; - const struct BlobInfo *blob; + const BlobContainer *blob; std::function destroyCb; }; @@ -57,7 +57,7 @@ struct GraphProfilingPool : _ze_graph_profiling_pool_handle_t { GraphProfilingPool(VPU::VPUDeviceContext *ctx, const uint32_t size, const uint32_t count, - const struct BlobInfo *blob, + const BlobContainer *blob, std::function destroyCb); ~GraphProfilingPool(); @@ -74,7 +74,7 @@ struct GraphProfilingPool : _ze_graph_profiling_pool_handle_t { VPU::VPUDeviceContext *ctx = nullptr; uint32_t querySize = 0u; VPU::VPUBufferObject *poolBuffer = nullptr; - const struct BlobInfo *blob; + const BlobContainer *blob; std::vector> queries; std::function destroyCb; diff --git a/umd/level_zero_driver/ext/source/graph/query_network.cpp b/umd/level_zero_driver/ext/source/graph/query_network.cpp index c2c2c81..d7f97f6 100644 --- a/umd/level_zero_driver/ext/source/graph/query_network.cpp +++ b/umd/level_zero_driver/ext/source/graph/query_network.cpp @@ -18,6 +18,8 @@ #include "vpu_driver/source/device/vpu_device_context.hpp" #include "vpu_driver/source/utilities/log.hpp" +#include + namespace L0 { ze_result_t QueryNetwork::create(ze_context_handle_t hContext, @@ -66,10 +68,12 @@ ze_result_t QueryNetwork::create(ze_context_handle_t hContext, } vcl_query_handle_t query = nullptr; - ret = Vcl::sym().queryNetworkCreate(compiler, - const_cast(desc->pInput), - desc->inputSize, - &query); + vcl_query_desc_t queryDesc = {}; + queryDesc.modelIRData = desc->pInput; + queryDesc.modelIRSize = desc->inputSize; + queryDesc.options = desc->pBuildFlags; + queryDesc.optionsSize = strlen(desc->pBuildFlags); + ret = Vcl::sym().queryNetworkCreate(compiler, queryDesc, &query); if (ret != VCL_RESULT_SUCCESS) { LOG_E("Failed to create query network! Result:%x", ret); return ZE_RESULT_ERROR_UNKNOWN; diff --git a/umd/level_zero_driver/ext/source/graph/vcl_symbols.hpp b/umd/level_zero_driver/ext/source/graph/vcl_symbols.hpp index e46d0f9..a10e3a7 100644 --- a/umd/level_zero_driver/ext/source/graph/vcl_symbols.hpp +++ b/umd/level_zero_driver/ext/source/graph/vcl_symbols.hpp @@ -74,6 +74,9 @@ class Vcl { getDecodedProfilingBuffer = getSymbolAddr("vclGetDecodedProfilingBuffer"); logHandleGetString = getSymbolAddr("vclLogHandleGetString"); + + allocatedExecutableCreate = + getSymbolAddr("vclAllocatedExecutableCreate"); } static void closeHandle(void *handle) noexcept { dlclose(handle); } @@ -93,6 +96,7 @@ class Vcl { decltype(vclProfilingGetProperties) *profilingGetProperties = &missingSymbol; decltype(vclGetDecodedProfilingBuffer) *getDecodedProfilingBuffer = &missingSymbol; decltype(vclLogHandleGetString) *logHandleGetString = &missingSymbol; + decltype(vclAllocatedExecutableCreate) *allocatedExecutableCreate = &missingSymbol; private: using VclHandle = std::unique_ptr; diff --git a/umd/level_zero_driver/include/l0_exception.hpp b/umd/level_zero_driver/include/l0_exception.hpp index 56f35ef..92bcb27 100644 --- a/umd/level_zero_driver/include/l0_exception.hpp +++ b/umd/level_zero_driver/include/l0_exception.hpp @@ -28,12 +28,13 @@ namespace L0 { return ZE_RESULT_ERROR_UNKNOWN; \ } -class DriverError : std::exception { +class DriverError : public std::exception { public: DriverError(ze_result_t r) : r(r) {} ze_result_t result() const { return r; } + const char *what() const noexcept override { return "Driver error occurred"; } private: ze_result_t r; diff --git a/umd/level_zero_driver/tools/source/CMakeLists.txt b/umd/level_zero_driver/tools/source/CMakeLists.txt index e9be5bf..ffeca66 100644 --- a/umd/level_zero_driver/tools/source/CMakeLists.txt +++ b/umd/level_zero_driver/tools/source/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT # -target_sources(${TARGET_NAME_L0} PRIVATE +target_sources(${TARGET_NAME_L0_DRV} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/metrics/metric.hpp ${CMAKE_CURRENT_SOURCE_DIR}/metrics/metric.cpp ${CMAKE_CURRENT_SOURCE_DIR}/metrics/metric_query.hpp diff --git a/umd/level_zero_driver/unit_tests/CMakeLists.txt b/umd/level_zero_driver/unit_tests/CMakeLists.txt index fa874f4..e5b46c3 100644 --- a/umd/level_zero_driver/unit_tests/CMakeLists.txt +++ b/umd/level_zero_driver/unit_tests/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2022 Intel Corporation +# Copyright (C) 2022-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -10,12 +10,12 @@ if(SKIP_UNIT_TESTS) return() endif() -set(TARGET_NAME ${TARGET_NAME_L0}_tests) +set(TARGET_NAME ze_intel_vpu_tests) add_executable(${TARGET_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) target_link_libraries( ${TARGET_NAME} - ${TARGET_NAME_L0} + level_zero_driver fw_vpu_api_headers gmock gtest diff --git a/umd/level_zero_driver/unit_tests/fixtures/device_fixture.hpp b/umd/level_zero_driver/unit_tests/fixtures/device_fixture.hpp index eaa23e9..f5e3e54 100644 --- a/umd/level_zero_driver/unit_tests/fixtures/device_fixture.hpp +++ b/umd/level_zero_driver/unit_tests/fixtures/device_fixture.hpp @@ -14,12 +14,12 @@ #include "level_zero_driver/core/source/cmdqueue/cmdqueue.hpp" #include "level_zero_driver/core/source/context/context.hpp" #include "level_zero_driver/core/source/device/device.hpp" +#include "level_zero_driver/core/source/driver/driver.hpp" #include "level_zero_driver/core/source/driver/driver_handle.hpp" #include "level_zero_driver/ext/source/graph/disk_cache.hpp" #include "level_zero_driver/unit_tests/mocks/mock_driver.hpp" #include "vpu_driver/source/device/vpu_device.hpp" #include "vpu_driver/source/device/vpu_device_context.hpp" -#include "vpu_driver/source/utilities/log.hpp" #include "vpu_driver/unit_tests/mocks/mock_os_interface_imp.hpp" #include "vpu_driver/unit_tests/mocks/mock_vpu_device.hpp" @@ -34,7 +34,7 @@ namespace ult { struct DeviceFixture { virtual void SetUp() { driver.setMetrics(enableMetrics); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0)); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::init(0)); driver.diskCache = std::make_unique(osInfc); @@ -130,61 +130,24 @@ struct CommandQueueFixture : ContextFixture { ContextFixture::TearDown(); } - template - uint32_t getQueueOrdinal(F f) { - // Assume cmdQueGrpProps has all properties. - LOG(UTEST, "Number of queue groups: %u", queGrpCnt); - for (uint32_t i = 0; i < queGrpCnt; i++) { - if (f(cmdQueGrpProps[i].flags)) { - LOG(UTEST, "Engine group ordinal: %u (flags: %#x)", i, cmdQueGrpProps[i].flags); - return i; - } - } - LOG(UTEST, "Failed to get matching queue group"); - return 0xffffffff; - } - - uint32_t getComputeQueueOrdinal() { - return getQueueOrdinal([](uint32_t flag) { - if ((flag & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE) && - (flag & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY)) { - return true; - } - return false; - }); - } - - uint32_t getCopyOnlyQueueOrdinal() { - return getQueueOrdinal([](uint32_t flag) { - if ((flag & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE) == 0 && - (flag & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY)) { - return true; - } - return false; - }); - } - - ze_command_list_handle_t createCommandList(uint32_t ordinal) { + ze_command_list_handle_t createCommandList() { ze_command_list_handle_t hCommandList = nullptr; ze_command_list_desc_t desc = {}; - desc.commandQueueGroupOrdinal = ordinal; - ze_result_t result = CommandList::create(context, device, &desc, &hCommandList); + ze_result_t result = L0::CommandList::create(context, device, &desc, &hCommandList); EXPECT_EQ(ZE_RESULT_SUCCESS, result); return hCommandList; } - ze_command_queue_handle_t createCommandQueue(uint32_t ordinal) { + ze_command_queue_handle_t createCommandQueue() { ze_command_queue_handle_t hCommandQueue = nullptr; ze_command_queue_desc_t desc = {}; - desc.ordinal = ordinal; - ze_result_t result = CommandQueue::create(context, device, &desc, &hCommandQueue); + ze_result_t result = L0::CommandQueue::create(context, device, &desc, &hCommandQueue); EXPECT_EQ(ZE_RESULT_SUCCESS, result); return hCommandQueue; } - // 1 NN, 1 Copy queue groups. uint32_t queGrpCnt = 0u; ze_command_queue_group_properties_t *cmdQueGrpProps = nullptr; }; diff --git a/umd/level_zero_driver/unit_tests/source/core/cmdlist/test_cmdlist.cpp b/umd/level_zero_driver/unit_tests/source/core/cmdlist/test_cmdlist.cpp index 52f2846..d43e31f 100644 --- a/umd/level_zero_driver/unit_tests/source/core/cmdlist/test_cmdlist.cpp +++ b/umd/level_zero_driver/unit_tests/source/core/cmdlist/test_cmdlist.cpp @@ -41,42 +41,33 @@ struct CommandListTest : public Test { ze_command_list_handle_t hCommandList1 = nullptr; }; -TEST_F(CommandListTest, whenCreatingCommandListFromNullContextAndDeviceThenFailureIsReturned) { +TEST_F(CommandListTest, createErrors) { ze_command_list_desc_t desc = {}; - desc.commandQueueGroupOrdinal = getComputeQueueOrdinal(); - ze_result_t result = zeCommandListCreate(nullptr, device, &desc, &hCommandList0); + auto result = L0::CommandList::create(context, nullptr, &desc, &hCommandList0); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, result); - result = zeCommandListCreate(context, nullptr, &desc, &hCommandList0); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, result); + result = L0::CommandList::create(context, device, nullptr, &hCommandList0); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, result); + + result = L0::CommandList::create(context, device, &desc, nullptr); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, result); } TEST_F(CommandListTest, commandListErrorsOnInvalidParamsShouldBeProperlyHandled) { ze_command_list_desc_t desc = {}; - desc.commandQueueGroupOrdinal = getComputeQueueOrdinal(); - ze_result_t result = zeCommandListCreate(context, device, &desc, &hCommandList0); + ze_result_t result = L0::CommandList::create(context, device, &desc, &hCommandList0); ASSERT_EQ(ZE_RESULT_SUCCESS, result); - result = zeCommandListClose(nullptr); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, result); - - result = zeCommandListReset(nullptr); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, result); - - result = zeCommandListDestroy(nullptr); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, result); - - result = zeCommandListDestroy(hCommandList0); + result = L0::CommandList::fromHandle(hCommandList0)->destroy(); ASSERT_EQ(ZE_RESULT_SUCCESS, result); } TEST_F(CommandListTest, whenCreatingCommandListFromContextThenSuccessIsReturned) { ze_command_list_desc_t desc = {}; - desc.commandQueueGroupOrdinal = getComputeQueueOrdinal(); - ze_result_t result = zeCommandListCreate(context, device, &desc, &hCommandList0); + ze_result_t result = L0::CommandList::create(context, device, &desc, &hCommandList0); EXPECT_EQ(ZE_RESULT_SUCCESS, result); L0::CommandList *commandList = L0::CommandList::fromHandle(hCommandList0); @@ -86,9 +77,8 @@ TEST_F(CommandListTest, whenCreatingCommandListFromContextThenSuccessIsReturned) TEST_F(CommandListTest, commandListIsIteratable) { ze_command_list_desc_t desc = {}; - desc.commandQueueGroupOrdinal = getComputeQueueOrdinal(); - ze_result_t result = zeCommandListCreate(context, device, &desc, &hCommandList0); + ze_result_t result = L0::CommandList::create(context, device, &desc, &hCommandList0); ASSERT_EQ(ZE_RESULT_SUCCESS, result); auto cmdList = L0::CommandList::fromHandle(hCommandList0); @@ -136,9 +126,8 @@ TEST_F(CommandListTest, commandListIsIteratable) { TEST_F(CommandListTest, whenCalledCommandListResetCommandListVectorIsClearedSuccessfully) { ze_command_list_desc_t desc = {}; - desc.commandQueueGroupOrdinal = getComputeQueueOrdinal(); - ze_result_t result = zeCommandListCreate(context, device, &desc, &hCommandList0); + ze_result_t result = L0::CommandList::create(context, device, &desc, &hCommandList0); ASSERT_EQ(ZE_RESULT_SUCCESS, result); auto cmdList = L0::CommandList::fromHandle(hCommandList0); @@ -182,9 +171,8 @@ TEST_F(CommandListTest, whenCalledCommandListResetCommandListVectorIsClearedSucc TEST_F(CommandListTest, expectCommandListIsDestroyOnContextDestroy) { ze_command_list_desc_t desc = {}; - desc.commandQueueGroupOrdinal = getComputeQueueOrdinal(); - ze_result_t result = zeCommandListCreate(context, device, &desc, &hCommandList0); + ze_result_t result = L0::CommandList::create(context, device, &desc, &hCommandList0); ASSERT_EQ(ZE_RESULT_SUCCESS, result); } @@ -198,21 +186,13 @@ struct CommandListCommitSizeTest : public CommandListTest { // Command list. ze_command_list_desc_t desc = {}; - desc.commandQueueGroupOrdinal = getComputeQueueOrdinal(); - ze_result_t result = zeCommandListCreate(context, device, &desc, &hNNCmdlist); + ze_result_t result = L0::CommandList::create(context, device, &desc, &hNNCmdlist); ASSERT_EQ(ZE_RESULT_SUCCESS, result); nnCmdlist = L0::CommandList::fromHandle(hNNCmdlist); ASSERT_NE(nullptr, nnCmdlist); - desc.commandQueueGroupOrdinal = getCopyOnlyQueueOrdinal(); - result = zeCommandListCreate(context, device, &desc, &hCPCmdlist); - ASSERT_EQ(ZE_RESULT_SUCCESS, result); - - cpCmdlist = L0::CommandList::fromHandle(hCPCmdlist); - ASSERT_NE(nullptr, cpCmdlist); - // Events ze_event_pool_desc_t evPoolDesc = {ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, nullptr, @@ -220,9 +200,9 @@ struct CommandListCommitSizeTest : public CommandListTest { ZE_EVENT_POOL_FLAG_HOST_VISIBLE}; evPoolDesc.count = 3; ASSERT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolCreate(context, &evPoolDesc, 1, &hDevice, &hEvPool)); + L0::EventPool::create(context, &evPoolDesc, 1, &hDevice, &hEvPool)); ASSERT_NE(nullptr, hEvPool); - evPool = EventPool::fromHandle(hEvPool); + evPool = L0::EventPool::fromHandle(hEvPool); ASSERT_NE(nullptr, evPool); ze_event_desc_t evDesc = {ZE_STRUCTURE_TYPE_EVENT_DESC, @@ -264,7 +244,6 @@ struct CommandListCommitSizeTest : public CommandListTest { ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hEvent2)->destroy()); evPool->destroy(); nnCmdlist->destroy(); - cpCmdlist->destroy(); ASSERT_TRUE(ctx->freeMemAlloc(shareMem1)); ASSERT_TRUE(ctx->freeMemAlloc(shareMem2)); @@ -277,11 +256,9 @@ struct CommandListCommitSizeTest : public CommandListTest { size_t allocSize = 1024; ze_device_handle_t hDevice = nullptr; ze_command_list_handle_t hNNCmdlist = nullptr; - ze_command_list_handle_t hCPCmdlist = nullptr; ze_event_pool_handle_t hEvPool = nullptr; - CommandList *nnCmdlist = nullptr; - CommandList *cpCmdlist = nullptr; - EventPool *evPool = nullptr; + L0::CommandList *nnCmdlist = nullptr; + L0::EventPool *evPool = nullptr; ze_event_handle_t hEvent0 = nullptr; ze_event_handle_t hEvent1 = nullptr; ze_event_handle_t hEvent2 = nullptr; @@ -399,115 +376,5 @@ TEST_F(CommandListCommitSizeTest, l2lCopyAndL2SCopyCommandsWithEvents) { EXPECT_EQ(2u, nnCmdlist->getJob()->getCommandBuffers().size()); } -TEST_F(CommandListCommitSizeTest, testingVariousFollowingConditionsForDifferentCommandListTypes) { - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendEventReset(hEvent0)); - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendSignalEvent(hEvent0)); - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendBarrier(nullptr, 0, nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - nnCmdlist->appendMemoryCopy(shareMem2, shareMem1, allocSize, nullptr, 0, nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->close()); - - // NN list. - // reset ev | signal ev | barrier | [L2L] - EXPECT_EQ(4u, nnCmdlist->getCommands().size()); - EXPECT_EQ(2u, nnCmdlist->getJob()->getCommandBuffers().size()); - - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->appendBarrier(nullptr, 0, nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - cpCmdlist->appendMemoryCopy(shareMem2, hostMem1, allocSize, nullptr, 0, nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->appendWaitOnEvents(1, &hEvent1)); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->close()); - - // CP list. - // barrier | [S2L] | wait ev - EXPECT_EQ(3u, cpCmdlist->getCommands().size()); - EXPECT_EQ(1u, cpCmdlist->getJob()->getCommandBuffers().size()); - - // Reset - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->reset()); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->reset()); - ASSERT_EQ(0u, nnCmdlist->getCommands().size()); - ASSERT_EQ(0u, cpCmdlist->getCommands().size()); - - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendBarrier(nullptr, 0, nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - nnCmdlist->appendWriteGlobalTimestamp(static_cast(hostMem2), - nullptr, - 0, - nullptr)); // To Copy Engine, cmdlist#1 - ASSERT_EQ(ZE_RESULT_SUCCESS, - nnCmdlist->appendMemoryCopy(shareMem2, - hostMem1, - allocSize, - nullptr, - 0, - nullptr)); // To Copy Engine, cmdlist#1 - ASSERT_EQ(ZE_RESULT_SUCCESS, - nnCmdlist->appendMemoryCopy(shareMem2, - shareMem1, - allocSize, - nullptr, - 0, - nullptr)); // To Compute Engine, cmdlist#2 - ASSERT_EQ(ZE_RESULT_SUCCESS, - nnCmdlist->appendBarrier(nullptr, 0, nullptr)); // To Compute Engine, cmdlist#2 - ASSERT_EQ(ZE_RESULT_SUCCESS, - nnCmdlist->appendWriteGlobalTimestamp(static_cast(hostMem2), - nullptr, - 0, - nullptr)); // To Copy Engine, cmdlist#3 - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->close()); - - /* Timestamp is split by UMD to two commands aligned TS and copy */ - EXPECT_EQ(8u, nnCmdlist->getCommands().size()); - EXPECT_EQ(1u, nnCmdlist->getJob()->getCommandBuffers().size()); - - // Reset - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->reset()); - ASSERT_EQ(0u, nnCmdlist->getCommands().size()); - EXPECT_EQ(0u, nnCmdlist->getJob()->getCommandBuffers().size()); - - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendBarrier(nullptr, 0, nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - nnCmdlist->appendWriteGlobalTimestamp(static_cast(hostMem2), - nullptr, - 0, - nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendBarrier(nullptr, 0, nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - nnCmdlist->appendWriteGlobalTimestamp(static_cast(hostMem2), - nullptr, - 0, - nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendSignalEvent(hEvent0)); - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendWaitOnEvents(1, &hEvent2)); - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendEventReset(hEvent0)); - ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->close()); - - /* Timestamp is split by UMD to two commands aligned TS and copy */ - EXPECT_EQ(9u, nnCmdlist->getCommands().size()); - EXPECT_EQ(2u, nnCmdlist->getJob()->getCommandBuffers().size()); - - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->appendBarrier(nullptr, 0, nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - cpCmdlist->appendWriteGlobalTimestamp(static_cast(hostMem2), - nullptr, - 0, - nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->appendBarrier(nullptr, 0, nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - cpCmdlist->appendWriteGlobalTimestamp(static_cast(hostMem2), - nullptr, - 0, - nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->appendSignalEvent(hEvent0)); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->appendWaitOnEvents(1, &hEvent2)); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->appendEventReset(hEvent0)); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->close()); - - EXPECT_EQ(9u, cpCmdlist->getCommands().size()); - EXPECT_EQ(2u, cpCmdlist->getJob()->getCommandBuffers().size()); -} - } // namespace ult } // namespace L0 diff --git a/umd/level_zero_driver/unit_tests/source/core/cmdlist/test_cmdlist_api.cpp b/umd/level_zero_driver/unit_tests/source/core/cmdlist/test_cmdlist_api.cpp index ed4ab83..0a4a389 100644 --- a/umd/level_zero_driver/unit_tests/source/core/cmdlist/test_cmdlist_api.cpp +++ b/umd/level_zero_driver/unit_tests/source/core/cmdlist/test_cmdlist_api.cpp @@ -8,11 +8,14 @@ #include #include +#include "api/vpu_jsm_job_cmd_api.h" #include "gtest/gtest.h" #include "level_zero_driver/core/source/cmdlist/cmdlist.hpp" #include "level_zero_driver/core/source/cmdqueue/cmdqueue.hpp" #include "level_zero_driver/core/source/context/context.hpp" #include "level_zero_driver/core/source/device/device.hpp" +#include "level_zero_driver/core/source/event/event.hpp" +#include "level_zero_driver/core/source/event/eventpool.hpp" #include "level_zero_driver/ext/source/graph/graph.hpp" #include "level_zero_driver/tools/source/metrics/metric.hpp" #include "level_zero_driver/tools/source/metrics/metric_query.hpp" @@ -24,7 +27,6 @@ #include "vpu_driver/source/memory/vpu_buffer_object.hpp" #include "vpu_driver/unit_tests/test_macros/test.hpp" -#include #include #include #include @@ -43,10 +45,10 @@ struct CommandListFixture : CommandQueueFixture { CommandQueueFixture::SetUp(); ze_command_list_desc_t cmdListDesc = {}; - cmdListDesc.commandQueueGroupOrdinal = getComputeQueueOrdinal(); + cmdListDesc.commandQueueGroupOrdinal = 0u; ze_command_list_handle_t hCommandList = nullptr; - ze_result_t result = zeCommandListCreate(context, device, &cmdListDesc, &hCommandList); + ze_result_t result = L0::CommandList::create(context, device, &cmdListDesc, &hCommandList); EXPECT_EQ(ZE_RESULT_SUCCESS, result); commandList = L0::CommandList::fromHandle(hCommandList); @@ -67,26 +69,31 @@ struct CommandListFixture : CommandQueueFixture { .count = 5}; auto hDevice = device->toHandle(); ASSERT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolCreate(context, &eventPoolDesc, 1, &hDevice, &eventPool)); + L0::EventPool::create(context, &eventPoolDesc, 1, &hDevice, &eventPool)); ze_event_desc_t eventDesc = {.stype = ZE_STRUCTURE_TYPE_EVENT_DESC, .pNext = nullptr, .index = 0, .signal = ZE_EVENT_POOL_FLAG_HOST_VISIBLE, .wait = ZE_EVENT_POOL_FLAG_HOST_VISIBLE}; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventCreate(eventPool, &eventDesc, &event0)); + ASSERT_EQ(ZE_RESULT_SUCCESS, + L0::EventPool::fromHandle(eventPool)->createEvent(&eventDesc, &event0)); ASSERT_NE(nullptr, event0); eventDesc.index = 1; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventCreate(eventPool, &eventDesc, &event1)); + ASSERT_EQ(ZE_RESULT_SUCCESS, + L0::EventPool::fromHandle(eventPool)->createEvent(&eventDesc, &event1)); ASSERT_NE(nullptr, event1); eventDesc.index = 2; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventCreate(eventPool, &eventDesc, &event2)); + ASSERT_EQ(ZE_RESULT_SUCCESS, + L0::EventPool::fromHandle(eventPool)->createEvent(&eventDesc, &event2)); ASSERT_NE(nullptr, event2); eventDesc.index = 3; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventCreate(eventPool, &eventDesc, &event3)); + ASSERT_EQ(ZE_RESULT_SUCCESS, + L0::EventPool::fromHandle(eventPool)->createEvent(&eventDesc, &event3)); ASSERT_NE(nullptr, event3); eventDesc.index = 4; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventCreate(eventPool, &eventDesc, &event4)); + ASSERT_EQ(ZE_RESULT_SUCCESS, + L0::EventPool::fromHandle(eventPool)->createEvent(&eventDesc, &event4)); ASSERT_NE(nullptr, event4); } @@ -95,12 +102,12 @@ struct CommandListFixture : CommandQueueFixture { EXPECT_EQ(ZE_RESULT_SUCCESS, result); // Events / event pool. - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(event0)); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(event1)); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(event2)); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(event3)); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(event4)); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolDestroy(eventPool)); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(event0)->destroy()); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(event1)->destroy()); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(event2)->destroy()); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(event3)->destroy()); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(event4)->destroy()); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::EventPool::fromHandle(eventPool)->destroy()); // Memory free'ing EXPECT_TRUE(ctx->freeMemAlloc(ptrAlloc)); @@ -183,7 +190,7 @@ struct CommandListMetricFixture : CommandListFixture { ASSERT_NE(hMetricQueryPool, nullptr); ASSERT_EQ( - MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), ZE_RESULT_SUCCESS); ASSERT_NE(hMetricQuery, nullptr); } @@ -191,11 +198,11 @@ struct CommandListMetricFixture : CommandListFixture { void TearDown() override { if (context != nullptr && device != nullptr) { if (hMetricQuery) { - ASSERT_EQ(MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); } if (hMetricQueryPool) { - ASSERT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), + ASSERT_EQ(L0::MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); } @@ -230,13 +237,12 @@ TEST_F(CommandListApiTest, whenCalledCloseSuccessIsReturned) { } TEST_F(CommandListApiTest, whenCalledAppendWriteGlobalTimestampWithInvalidParamsFailureIsReturned) { - auto result = zeCommandListAppendWriteGlobalTimestamp(nullptr, ptrAlloc, nullptr, 0, nullptr); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, result); - - result = zeCommandListAppendWriteGlobalTimestamp(commandList, nullptr, nullptr, 0, nullptr); + auto result = L0::CommandList::fromHandle(commandList) + ->appendWriteGlobalTimestamp(nullptr, nullptr, 0, nullptr); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, result); - result = zeCommandListAppendWriteGlobalTimestamp(commandList, ptrAlloc, nullptr, 1, nullptr); + result = L0::CommandList::fromHandle(commandList) + ->appendWriteGlobalTimestamp(ptrAlloc, nullptr, 1, nullptr); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_SIZE, result); } @@ -302,9 +308,6 @@ TEST_F(CommandListApiTest, eventSyncObjectsAttachedWithTSCommand) { } TEST_F(CommandListApiTest, whenCalledAppendMemoryCopyWithCorrectProgramSequenceSuccessIsReturned) { - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, - zeCommandListAppendMemoryCopy(nullptr, nullptr, nullptr, 0u, nullptr, 0u, nullptr)); - // Testing that appendMemoryCopy will fail due to unallocated srcptr void *srcPtr = nullptr; ze_result_t result = @@ -447,7 +450,7 @@ TEST_F(CommandListGraphApiTest, TEST_F(CommandListGraphApiTest, resetCommandListAfterGraphInitThenAppendingGraphExecAndExecuteReturnsSuccess) { - ze_command_queue_handle_t hCommandQueue = createCommandQueue(0); + ze_command_queue_handle_t hCommandQueue = createCommandQueue(); ASSERT_NE(hCommandQueue, nullptr); auto commandQueue = L0::CommandQueue::fromHandle(hCommandQueue); @@ -499,7 +502,7 @@ struct CommandListEventApiTest : Test { ze_device_handle_t hDevice = device->toHandle(); ASSERT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolCreate(hContext, &evPoolDesc, 1, &(hDevice), &hEvPool)); + L0::EventPool::create(hContext, &evPoolDesc, 1, &(hDevice), &hEvPool)); ASSERT_NE(nullptr, hEvPool); // Event. @@ -509,16 +512,17 @@ struct CommandListEventApiTest : Test { evDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST; evDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventCreate(hEvPool, &evDesc, &hEvent)); + ASSERT_EQ(ZE_RESULT_SUCCESS, + L0::EventPool::fromHandle(hEvPool)->createEvent(&evDesc, &hEvent)); ASSERT_NE(nullptr, hEvent); } void TearDown() override { if (hEvent != nullptr) { - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hEvent)); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hEvent)->destroy()); } if (hEvPool != nullptr) { - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolDestroy(hEvPool)); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::EventPool::fromHandle(hEvPool)->destroy()); } CommandListFixture::TearDown(); @@ -530,34 +534,33 @@ struct CommandListEventApiTest : Test { }; TEST_F(CommandListEventApiTest, givenCallAppendSignalEventSuccessIsReturned) { - EXPECT_EQ(ZE_RESULT_SUCCESS, zeCommandListAppendSignalEvent(commandList->toHandle(), hEvent)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeCommandListClose(commandList->toHandle())); + EXPECT_EQ(ZE_RESULT_SUCCESS, + L0::CommandList::fromHandle(commandList->toHandle()) + ->CommandList::appendSignalEvent(hEvent)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::CommandList::fromHandle(commandList->toHandle())->close()); EXPECT_EQ(1u, commandList->getCommands().size()); EXPECT_EQ(VPU_CMD_FENCE_SIGNAL, commandList->getCommands()[0]->getCommandType()); } TEST_F(CommandListEventApiTest, givenCallAppendSignalEventWithInvalidParamsReturnFiailure) { - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, zeCommandListAppendSignalEvent(nullptr, hEvent)); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, - zeCommandListAppendSignalEvent(commandList->toHandle(), nullptr)); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, - zeCommandListAppendSignalEvent(nullptr, nullptr)); + L0::CommandList::fromHandle(commandList->toHandle()) + ->CommandList::appendSignalEvent(nullptr)); } TEST_F(CommandListEventApiTest, givenCallAppendResetEventSuccessIsReturned) { - EXPECT_EQ(ZE_RESULT_SUCCESS, zeCommandListAppendEventReset(commandList->toHandle(), hEvent)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeCommandListClose(commandList->toHandle())); + EXPECT_EQ(ZE_RESULT_SUCCESS, + L0::CommandList::fromHandle(commandList->toHandle())->appendEventReset(hEvent)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::CommandList::fromHandle(commandList->toHandle())->close()); EXPECT_EQ(1u, commandList->getCommands().size()); EXPECT_EQ(VPU_CMD_FENCE_SIGNAL, commandList->getCommands()[0]->getCommandType()); } TEST_F(CommandListEventApiTest, givenCallAppendResetEventWithInvalidParamsReturnFiailure) { - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, zeCommandListAppendEventReset(nullptr, hEvent)); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, - zeCommandListAppendEventReset(commandList->toHandle(), nullptr)); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, zeCommandListAppendEventReset(nullptr, nullptr)); + L0::CommandList::fromHandle(commandList->toHandle())->appendEventReset(nullptr)); } TEST_F(CommandListEventApiTest, givenCallAppendWaitEventSuccessIsReturned) { @@ -571,27 +574,26 @@ TEST_F(CommandListEventApiTest, givenCallAppendWaitEventSuccessIsReturned) { phEvent[0] = hEvent; for (uint32_t i = 1; i < evPoolCap; ++i) { evDesc.index = i; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventCreate(hEvPool, &evDesc, &phEvent[i])); + ASSERT_EQ(ZE_RESULT_SUCCESS, + L0::EventPool::fromHandle(hEvPool)->createEvent(&evDesc, &phEvent[i])); } EXPECT_EQ(ZE_RESULT_SUCCESS, - zeCommandListAppendWaitOnEvents(commandList->toHandle(), evPoolCap, phEvent)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeCommandListClose(commandList->toHandle())); + L0::CommandList::fromHandle(commandList->toHandle()) + ->CommandList::appendWaitOnEvents(evPoolCap, phEvent)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::CommandList::fromHandle(commandList->toHandle())->close()); EXPECT_EQ(evPoolCap, commandList->getCommands().size()); for (const auto &cmd : commandList->getCommands()) EXPECT_EQ(VPU_CMD_FENCE_WAIT, cmd->getCommandType()); for (uint32_t i = 1; i < evPoolCap; ++i) - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(phEvent[i])); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(phEvent[i])->destroy()); } TEST_F(CommandListEventApiTest, givenCallAppendWaitEventWithInvalidParamsReturnFiailure) { - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, - zeCommandListAppendWaitOnEvents(nullptr, 1, &hEvent)); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, - zeCommandListAppendWaitOnEvents(commandList->toHandle(), 1, nullptr)); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, - zeCommandListAppendWaitOnEvents(nullptr, 1, nullptr)); + L0::CommandList::fromHandle(commandList->toHandle()) + ->CommandList::appendWaitOnEvents(1, nullptr)); } } // namespace ult diff --git a/umd/level_zero_driver/unit_tests/source/core/cmdqueue/test_cmdqueue.cpp b/umd/level_zero_driver/unit_tests/source/core/cmdqueue/test_cmdqueue.cpp index 2c0d0b6..4017000 100644 --- a/umd/level_zero_driver/unit_tests/source/core/cmdqueue/test_cmdqueue.cpp +++ b/umd/level_zero_driver/unit_tests/source/core/cmdqueue/test_cmdqueue.cpp @@ -9,11 +9,12 @@ #include #include "gtest/gtest.h" -#include "level_zero_driver/api/core/ze_cmdlist.hpp" #include "level_zero_driver/core/source/cmdlist/cmdlist.hpp" #include "level_zero_driver/core/source/cmdqueue/cmdqueue.hpp" #include "level_zero_driver/core/source/context/context.hpp" #include "level_zero_driver/core/source/device/device.hpp" +#include "level_zero_driver/core/source/event/event.hpp" +#include "level_zero_driver/core/source/event/eventpool.hpp" #include "level_zero_driver/unit_tests/fixtures/device_fixture.hpp" #include "vpu_driver/source/device/vpu_device_context.hpp" #include "vpu_driver/source/memory/vpu_buffer_object.hpp" @@ -32,42 +33,43 @@ TEST_F(CommandQueueCreate, givenCallGetCommandQueueGroupPropertiesHandleParamete ze_result_t re = device->getCommandQueueGroupProperties(nullptr, nullptr); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, re); - // DeviceFixture assume 1NN, 1Copy engines. uint32_t pCnt = 0; re = device->getCommandQueueGroupProperties(&pCnt, nullptr); EXPECT_EQ(ZE_RESULT_SUCCESS, re); - EXPECT_EQ(2u, pCnt); + EXPECT_EQ(1u, pCnt); - auto queGrpProps = new ze_command_queue_group_properties_t[pCnt]; - re = device->getCommandQueueGroupProperties(&pCnt, queGrpProps); + ze_command_queue_group_properties_t queGrpProps = {}; + re = device->getCommandQueueGroupProperties(&pCnt, &queGrpProps); EXPECT_EQ(ZE_RESULT_SUCCESS, re); - EXPECT_EQ(2u, pCnt); - - // Assume no fixed order of engine groups. - // No engines support cooperative kernel & metrics. - EXPECT_FALSE(queGrpProps[0].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS); - EXPECT_FALSE(queGrpProps[1].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS); - EXPECT_FALSE(queGrpProps[0].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_METRICS); - EXPECT_FALSE(queGrpProps[1].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_METRICS); - // NN/Copy both support copy operations. - EXPECT_TRUE(queGrpProps[0].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); - EXPECT_TRUE(queGrpProps[1].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); - // Each groups has 1 queues. - EXPECT_EQ(1u, queGrpProps[0].numQueues); - EXPECT_EQ(1u, queGrpProps[1].numQueues); - - // Either of it is copy only engine. - if (queGrpProps[0].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE) { - EXPECT_FALSE(queGrpProps[1].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); - } else { - EXPECT_TRUE(queGrpProps[1].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); - } - delete[] queGrpProps; + EXPECT_FALSE(queGrpProps.flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS); + EXPECT_FALSE(queGrpProps.flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_METRICS); + + EXPECT_TRUE(queGrpProps.flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_TRUE(queGrpProps.flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); + + EXPECT_EQ(1u, queGrpProps.numQueues); +} + +TEST_F(CommandQueueCreate, createErrors) { + ze_command_queue_handle_t hCommandQueue = nullptr; + ze_command_queue_desc_t cmdQueueDesc = {}; + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, + L0::CommandQueue::create(nullptr, nullptr, &cmdQueueDesc, &hCommandQueue)); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, + L0::CommandQueue::create(context, nullptr, &cmdQueueDesc, &hCommandQueue)); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, + L0::CommandQueue::create(nullptr, device, &cmdQueueDesc, &hCommandQueue)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, + L0::CommandQueue::create(context, device, nullptr, &hCommandQueue)); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, + L0::CommandQueue::create(context, device, &cmdQueueDesc, nullptr)); } TEST_F(CommandQueueCreate, whenCreatingAndDestroyingCommandQueueUsingContextSuccessIsReturned) { - ze_command_queue_handle_t hCommandQueue = createCommandQueue(getComputeQueueOrdinal()); + ze_command_queue_handle_t hCommandQueue = createCommandQueue(); ASSERT_NE(hCommandQueue, nullptr); L0::CommandQueue *commandQueue = L0::CommandQueue::fromHandle(hCommandQueue); @@ -75,7 +77,7 @@ TEST_F(CommandQueueCreate, whenCreatingAndDestroyingCommandQueueUsingContextSucc } TEST_F(CommandQueueCreate, expectCommandQueueIsDestroyOnContextDestroy) { - ze_command_queue_handle_t hCommandQueue = createCommandQueue(getComputeQueueOrdinal()); + ze_command_queue_handle_t hCommandQueue = createCommandQueue(); ASSERT_NE(hCommandQueue, nullptr); } @@ -84,14 +86,9 @@ struct CommandQueueExecTest : Test { CommandQueueFixture::SetUp(); // NN queue. - ze_command_queue_handle_t hNNCommandQueue = createCommandQueue(getComputeQueueOrdinal()); + ze_command_queue_handle_t hNNCommandQueue = createCommandQueue(); ASSERT_NE(hNNCommandQueue, nullptr); - nnQue = CommandQueue::fromHandle(hNNCommandQueue); - - // Copy queue. - ze_command_queue_handle_t hCPCommandQueue = createCommandQueue(getCopyOnlyQueueOrdinal()); - ASSERT_NE(hCPCommandQueue, nullptr); - cpQue = CommandQueue::fromHandle(hCPCommandQueue); + nnQue = L0::CommandQueue::fromHandle(hNNCommandQueue); // Event. ze_event_pool_desc_t evPoolDesc = {.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, @@ -100,7 +97,7 @@ struct CommandQueueExecTest : Test { .count = 3}; ASSERT_NE(nullptr, device); auto hDevice = device->toHandle(); - zeEventPoolCreate(context, &evPoolDesc, 1, &(hDevice), &eventPool); + L0::EventPool::create(context, &evPoolDesc, 1, &(hDevice), &eventPool); ASSERT_NE(nullptr, eventPool); ze_event_desc_t evDesc = { @@ -112,32 +109,30 @@ struct CommandQueueExecTest : Test { }; evDesc.index = 0; - zeEventCreate(eventPool, &evDesc, &event0); + L0::EventPool::fromHandle(eventPool)->createEvent(&evDesc, &event0); ASSERT_NE(nullptr, event0); evDesc.index = 1; - zeEventCreate(eventPool, &evDesc, &event1); + L0::EventPool::fromHandle(eventPool)->createEvent(&evDesc, &event1); ASSERT_NE(nullptr, event1); evDesc.index = 2; - zeEventCreate(eventPool, &evDesc, &event2); + L0::EventPool::fromHandle(eventPool)->createEvent(&evDesc, &event2); ASSERT_NE(nullptr, event2); } void TearDown() override { - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(event0)); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(event1)); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(event2)); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolDestroy(eventPool)); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(event0)->destroy()); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(event1)->destroy()); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(event2)->destroy()); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::EventPool::fromHandle(eventPool)->destroy()); ASSERT_EQ(ZE_RESULT_SUCCESS, nnQue->destroy()); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpQue->destroy()); + CommandQueueFixture::TearDown(); } - // Command queues. - CommandQueue *nnQue = nullptr; - CommandQueue *cpQue = nullptr; + L0::CommandQueue *nnQue = nullptr; // Event pool. ze_event_pool_handle_t eventPool = nullptr; @@ -148,25 +143,21 @@ struct CommandQueueExecTest : Test { ze_event_handle_t event2 = nullptr; }; -TEST_F( - CommandQueueExecTest, - givenCmdQueueWithBlitCopyWhenExecutingNonCopyBlitCommandListThenWrongCommandListStatusReturned) { - auto hCommandList = createCommandList(getComputeQueueOrdinal()); +TEST_F(CommandQueueExecTest, execErrors) { + auto hCommandList = createCommandList(); ASSERT_NE(nullptr, hCommandList); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, + L0::CommandQueue::fromHandle(nnQue)->executeCommandLists(1, nullptr, nullptr)); - // Execute the queue. - auto status = cpQue->executeCommandLists(1, &hCommandList, nullptr); - EXPECT_EQ(status, ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE); - - L0::zeCommandListDestroy(hCommandList); + L0::CommandList::fromHandle(hCommandList)->destroy(); } TEST_F(CommandQueueExecTest, givenCmdQueueWithBlitCopyWhenExecutingCopyBlitCommandListThenSuccessReturned) { - auto hCommandList = createCommandList(getComputeQueueOrdinal()); + auto hCommandList = createCommandList(); ASSERT_NE(nullptr, hCommandList); - CommandList *nnCmdList = CommandList::fromHandle(hCommandList); + L0::CommandList *nnCmdList = L0::CommandList::fromHandle(hCommandList); // Append a copy command. void *srcPtr = ctx->createMemAlloc(4 * 1024, @@ -196,10 +187,10 @@ TEST_F(CommandQueueExecTest, syncWithoutJobSubmissionReturnsSuccess) { } TEST_F(CommandQueueExecTest, commandListsShouldBeClosedBeforeExecute) { - auto hCommandList = createCommandList(getComputeQueueOrdinal()); + auto hCommandList = createCommandList(); ASSERT_NE(nullptr, hCommandList); - CommandList *cmdList = CommandList::fromHandle(hCommandList); + L0::CommandList *cmdList = L0::CommandList::fromHandle(hCommandList); // Append a TS command. uint64_t *ts = @@ -223,10 +214,10 @@ TEST_F(CommandQueueExecTest, commandListsShouldBeClosedBeforeExecute) { } TEST_F(CommandQueueExecTest, jobAllocationFailureShouldBeHandled) { - auto hCommandList = createCommandList(getComputeQueueOrdinal()); + auto hCommandList = createCommandList(); ASSERT_NE(nullptr, hCommandList); - CommandList *cmdList = CommandList::fromHandle(hCommandList); + L0::CommandList *cmdList = L0::CommandList::fromHandle(hCommandList); // Append a TS command and ready to execute. uint64_t *ts = @@ -248,10 +239,10 @@ TEST_F(CommandQueueExecTest, jobAllocationFailureShouldBeHandled) { TEST_F(CommandQueueExecTest, commandQueueExecutionOnEmptyCommandListShouldCallMapAndUnmapCallForJob) { // Create a command list. - auto hCommandList = createCommandList(getComputeQueueOrdinal()); + auto hCommandList = createCommandList(); ASSERT_NE(nullptr, hCommandList); - CommandList *cmdList = CommandList::fromHandle(hCommandList); + L0::CommandList *cmdList = L0::CommandList::fromHandle(hCommandList); // Resetting previous call counts osInfc.callCntAlloc = 0; @@ -290,16 +281,13 @@ TEST_F(CommandQueueExecTest, eventAttachedToSingleQueuesRespectively) { auto destShareMem = ctx->createMemAlloc(testAllocSize, VPU::VPUBufferObject::Type::CachedFw, VPU::VPUBufferObject::Location::Shared); - auto destHostMem = ctx->createMemAlloc(testAllocSize, - VPU::VPUBufferObject::Type::CachedShave, - VPU::VPUBufferObject::Location::Host); // NN queue event attaching. // Append wait on event 0, L2L copy and signal event 1 to the same NN queue. - auto hNNCmdlist = createCommandList(getComputeQueueOrdinal()); + auto hNNCmdlist = createCommandList(); ASSERT_NE(nullptr, hNNCmdlist); - CommandList *nnCmdlist = CommandList::fromHandle(hNNCmdlist); + L0::CommandList *nnCmdlist = L0::CommandList::fromHandle(hNNCmdlist); ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->appendWaitOnEvents(1, &event0)); ASSERT_EQ(ZE_RESULT_SUCCESS, @@ -316,75 +304,37 @@ TEST_F(CommandQueueExecTest, eventAttachedToSingleQueuesRespectively) { // Make sure a single command buffer was submitted. EXPECT_EQ(1U, osInfc.callCntSubmit); - // COPY queue event attaching. - // Append wait on event 0, L2S copy and signal event 1 to the same COPY queue. - auto hCPCmdlist = createCommandList(getCopyOnlyQueueOrdinal()); - ASSERT_NE(nullptr, hCPCmdlist); - - CommandList *cpCmdlist = CommandList::fromHandle(hCPCmdlist); - - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->appendWaitOnEvents(1, &event0)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - cpCmdlist->appendMemoryCopy((void *)destHostMem, - (void *)srcShareMem, - testAllocSize, - nullptr, - 0, - nullptr)); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->appendSignalEvent(event1)); - ASSERT_EQ(ZE_RESULT_SUCCESS, cpCmdlist->close()); - ASSERT_EQ(cpQue->executeCommandLists(1, &hCPCmdlist, nullptr), ZE_RESULT_SUCCESS); - - // Make sure a single command buffer was submitted. - EXPECT_EQ(2U, osInfc.callCntSubmit); - // Deallocate instances ctx->freeMemAlloc(srcShareMem); ctx->freeMemAlloc(destShareMem); - ctx->freeMemAlloc(destHostMem); nnCmdlist->destroy(); - cpCmdlist->destroy(); } struct CommandQueueJobTest : public Test { void SetUp() override { CommandQueueFixture::SetUp(); - // Create a CP command queue. - ze_command_queue_handle_t hNNCommandQueue = createCommandQueue(getComputeQueueOrdinal()); + // Create a NN command queue. + ze_command_queue_handle_t hNNCommandQueue = createCommandQueue(); ASSERT_NE(hNNCommandQueue, nullptr); nnCmdque = CommandQueue::fromHandle(hNNCommandQueue); - // Create a NN command queue. - ze_command_queue_handle_t hCPCommandQueue = createCommandQueue(getCopyOnlyQueueOrdinal()); - ASSERT_NE(hCPCommandQueue, nullptr); - cpCmdque = CommandQueue::fromHandle(hCPCommandQueue); - - // Command lists. - hNNCmdlist = createCommandList(getComputeQueueOrdinal()); + // Command a NN lists. + hNNCmdlist = createCommandList(); ASSERT_NE(nullptr, hNNCmdlist); nnCmdlist = CommandList::fromHandle(hNNCmdlist); ASSERT_NE(nullptr, nnCmdlist); - - hCPCmdlist = createCommandList(getCopyOnlyQueueOrdinal()); - ASSERT_NE(nullptr, hCPCmdlist); - cpCmdlist = CommandList::fromHandle(hCPCmdlist); } void TearDown() override { if (nnCmdque != nullptr) { nnCmdque->destroy(); } - if (cpCmdque != nullptr) { - cpCmdque->destroy(); - } + if (nnCmdlist != nullptr) { nnCmdlist->destroy(); } - if (cpCmdlist != nullptr) { - cpCmdlist->destroy(); - } CommandQueueFixture::TearDown(); } @@ -392,13 +342,10 @@ struct CommandQueueJobTest : public Test { const size_t memAllocSize = 4 * 1024; // Default memory allocation size. uint64_t syncTimeout = 2e9; // 2seconds default time out. - CommandQueue *nnCmdque = nullptr; - CommandQueue *cpCmdque = nullptr; + L0::CommandQueue *nnCmdque = nullptr; ze_command_list_handle_t hNNCmdlist = nullptr; - ze_command_list_handle_t hCPCmdlist = nullptr; - CommandList *nnCmdlist = nullptr; - CommandList *cpCmdlist = nullptr; + L0::CommandList *nnCmdlist = nullptr; }; TEST_F(CommandQueueJobTest, emptyCommandListDoesNotKeepJob) { @@ -453,9 +400,9 @@ TEST_F(CommandQueueJobTest, multipleJobsMaintainedInSingleSubmitId) { ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist->close()); // Assume 2 more command lists given. - auto hNNCmdlist1 = createCommandList(getComputeQueueOrdinal()); + auto hNNCmdlist1 = createCommandList(); ASSERT_NE(nullptr, hNNCmdlist1); - auto nnCmdlist1 = CommandList::fromHandle(hNNCmdlist1); + auto nnCmdlist1 = L0::CommandList::fromHandle(hNNCmdlist1); ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist1->appendWriteGlobalTimestamp(tsDest, nullptr, 0, nullptr)); @@ -464,9 +411,9 @@ TEST_F(CommandQueueJobTest, multipleJobsMaintainedInSingleSubmitId) { nnCmdlist1->appendMemoryCopy(dstHostMem, srcShareMem, memAllocSize, nullptr, 0, nullptr)); ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist1->close()); - auto hNNCmdlist2 = createCommandList(getComputeQueueOrdinal()); + auto hNNCmdlist2 = createCommandList(); ASSERT_NE(nullptr, hNNCmdlist2); - auto nnCmdlist2 = CommandList::fromHandle(hNNCmdlist2); + auto nnCmdlist2 = L0::CommandList::fromHandle(hNNCmdlist2); ASSERT_EQ(ZE_RESULT_SUCCESS, nnCmdlist2->appendWriteGlobalTimestamp(tsDest, nullptr, 0, nullptr)); diff --git a/umd/level_zero_driver/unit_tests/source/core/context/test_context.cpp b/umd/level_zero_driver/unit_tests/source/core/context/test_context.cpp index 3bdc236..66bd051 100644 --- a/umd/level_zero_driver/unit_tests/source/core/context/test_context.cpp +++ b/umd/level_zero_driver/unit_tests/source/core/context/test_context.cpp @@ -24,14 +24,6 @@ struct ContextTest : public Test { ze_context_desc_t desc = {}; }; -TEST_F(ContextTest, contextReturnsFailureWhenInvalidParamsPassed) { - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, zeContextCreate(nullptr, &desc, &hContext)); - - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, zeContextDestroy(nullptr)); - - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, zeContextGetStatus(nullptr)); -} - TEST_F(ContextTest, contextGetStatusReturned) { ze_result_t res = driverHandle->createContext(&desc, &hContext); ASSERT_EQ(ZE_RESULT_SUCCESS, res); diff --git a/umd/level_zero_driver/unit_tests/source/core/device/test_device.cpp b/umd/level_zero_driver/unit_tests/source/core/device/test_device.cpp index d8ec7e8..efd830a 100644 --- a/umd/level_zero_driver/unit_tests/source/core/device/test_device.cpp +++ b/umd/level_zero_driver/unit_tests/source/core/device/test_device.cpp @@ -103,7 +103,7 @@ TEST_F(SingleDeviceTest, givenCallToDevicePropertiesThenBasicPropertiesCorrectly EXPECT_EQ(l0DevProps.coreClockRate, hwInfo.coreClockRate); // Max mem alloc size. - EXPECT_EQ(l0DevProps.maxMemAllocSize, hwInfo.maxMemAllocSize); + EXPECT_GT(l0DevProps.maxMemAllocSize, 0); // Max hardware contexts. EXPECT_EQ(l0DevProps.maxHardwareContexts, hwInfo.maxHardwareContexts); @@ -167,8 +167,8 @@ TEST_F(SingleDeviceTest, givenCallToGetDeviceMemoryPropertiesExpectedValuesRetur // Checking returned values EXPECT_EQ(memProperties->flags, 0u); EXPECT_EQ(memProperties->maxClockRate, hwInfo.coreClockRate); - EXPECT_EQ(memProperties->maxBusWidth, 32u); - EXPECT_EQ(memProperties->totalSize, hwInfo.maxMemAllocSize); + EXPECT_EQ(memProperties->maxBusWidth, 0); + EXPECT_EQ(memProperties->totalSize, 0); EXPECT_EQ(strncmp(memProperties->name, device->getDeviceMemoryName(), strlen(device->getDeviceMemoryName())), diff --git a/umd/level_zero_driver/unit_tests/source/core/driver/test_driver.cpp b/umd/level_zero_driver/unit_tests/source/core/driver/test_driver.cpp index 31ce9b3..ca92045 100644 --- a/umd/level_zero_driver/unit_tests/source/core/driver/test_driver.cpp +++ b/umd/level_zero_driver/unit_tests/source/core/driver/test_driver.cpp @@ -8,21 +8,18 @@ #include #include "gtest/gtest.h" -#include "level_zero/ze_api.h" -#include "level_zero/ze_graph_ext.h" -#include "level_zero/ze_graph_profiling_ext.h" #include "level_zero/ze_intel_npu_uuid.h" +#include "level_zero_driver/core/source/driver/driver.hpp" #include "level_zero_driver/core/source/driver/driver_handle.hpp" #include "level_zero_driver/unit_tests/fixtures/device_fixture.hpp" #include "level_zero_driver/unit_tests/mocks/mock_driver.hpp" #include "vpu_driver/source/utilities/log.hpp" #include "vpu_driver/unit_tests/test_macros/test.hpp" +#include #include #include #include -#include -#include namespace L0 { namespace ult { @@ -31,7 +28,7 @@ TEST(zeInit, whenCallingZeInitThenInitializeOnDriverIsCalled) { Mock driver; driver.reset(); - auto result = zeInit(0); + auto result = L0::init(0); EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(1u, driver.initCalledCount); } @@ -41,8 +38,8 @@ TEST(zeInit, returnErrorWhenNotInitialized) { driver.reset(1, true); uint32_t drvCnt = 0; - EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zeInit(ZE_INIT_FLAG_GPU_ONLY)); - EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zeDriverGet(&drvCnt, nullptr)); + EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::init(ZE_INIT_FLAG_GPU_ONLY)); + EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::driverHandleGet(&drvCnt, nullptr)); } TEST(zeDriverGet, returnsCorrectNumberOfDriverInstances) { @@ -62,14 +59,14 @@ TEST(zeDriverGet, returnsCorrectNumberOfDriverInstances) { * number of drivers available. */ driver.reset(nMockDrv); - zeInit(0); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, zeDriverGet(nullptr, nullptr)); + L0::init(0); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, L0::driverHandleGet(nullptr, nullptr)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&drvCnt, nullptr)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::driverHandleGet(&drvCnt, nullptr)); EXPECT_EQ(nMockDrv, drvCnt); drvCnt = 100; // should be adjusted. - EXPECT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&drvCnt, &hDriver)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::driverHandleGet(&drvCnt, &hDriver)); EXPECT_EQ(nMockDrv, drvCnt); } @@ -86,190 +83,6 @@ TEST_F(DriverVersionTest, returnsExpectedDriverVersion) { EXPECT_EQ(memcmp(&properties.uuid, &uuid, sizeof(properties.uuid)), 0); } -TEST_F(DriverVersionTest, checkGraphExtensionInDriverExtensionProperties) { - uint32_t count = 0; - EXPECT_EQ(driverHandle->getExtensionProperties(&count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_GT(count, 0); - - std::vector props(count); - EXPECT_EQ(driverHandle->getExtensionProperties(&count, props.data()), ZE_RESULT_SUCCESS); - - EXPECT_EQ(std::string(props[0].name), ZE_GRAPH_EXT_NAME); - EXPECT_EQ(props[0].version, ZE_GRAPH_EXT_VERSION_1_0); -} - -TEST_F(DriverVersionTest, checkGraphExtensionFunctionTable) { - ze_graph_dditable_ext_t *ddi = nullptr; - ze_result_t res = driverHandle->getExtensionFunctionAddress(ZE_GRAPH_EXT_NAME, - reinterpret_cast(&ddi)); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - - EXPECT_NE(ddi->pfnCreate, nullptr); - EXPECT_NE(ddi->pfnDestroy, nullptr); - EXPECT_NE(ddi->pfnGetProperties, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties, nullptr); - EXPECT_NE(ddi->pfnSetArgumentValue, nullptr); - EXPECT_NE(ddi->pfnAppendGraphInitialize, nullptr); - EXPECT_NE(ddi->pfnAppendGraphExecute, nullptr); - EXPECT_NE(ddi->pfnGetNativeBinary, nullptr); - EXPECT_NE(ddi->pfnDeviceGetGraphProperties, nullptr); -} - -TEST_F(DriverVersionTest, checkGraphExtension_1_1_FunctionTable) { - ze_graph_dditable_ext_1_1_t *ddi = nullptr; - ze_result_t res = driverHandle->getExtensionFunctionAddress(ZE_GRAPH_EXT_NAME_1_1, - reinterpret_cast(&ddi)); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - - EXPECT_NE(ddi->pfnCreate, nullptr); - EXPECT_NE(ddi->pfnDestroy, nullptr); - EXPECT_NE(ddi->pfnGetProperties, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties, nullptr); - EXPECT_NE(ddi->pfnSetArgumentValue, nullptr); - EXPECT_NE(ddi->pfnAppendGraphInitialize, nullptr); - EXPECT_NE(ddi->pfnAppendGraphExecute, nullptr); - EXPECT_NE(ddi->pfnGetNativeBinary, nullptr); - EXPECT_NE(ddi->pfnDeviceGetGraphProperties, nullptr); - EXPECT_NE(ddi->pfnGraphGetArgumentMetadata, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties2, nullptr); -} - -TEST_F(DriverVersionTest, checkGraphExtension_1_2_FunctionTable) { - ze_graph_dditable_ext_1_2_t *ddi = nullptr; - ze_result_t res = driverHandle->getExtensionFunctionAddress(ZE_GRAPH_EXT_NAME_1_2, - reinterpret_cast(&ddi)); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - - EXPECT_NE(ddi->pfnCreate, nullptr); - EXPECT_NE(ddi->pfnDestroy, nullptr); - EXPECT_NE(ddi->pfnGetProperties, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties, nullptr); - EXPECT_NE(ddi->pfnSetArgumentValue, nullptr); - EXPECT_NE(ddi->pfnAppendGraphInitialize, nullptr); - EXPECT_NE(ddi->pfnAppendGraphExecute, nullptr); - EXPECT_NE(ddi->pfnGetNativeBinary, nullptr); - EXPECT_NE(ddi->pfnDeviceGetGraphProperties, nullptr); - EXPECT_NE(ddi->pfnGraphGetArgumentMetadata, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties2, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties3, nullptr); -} - -TEST_F(DriverVersionTest, checkGraphExtension_1_3_FunctionTable) { - ze_graph_dditable_ext_1_3_t *ddi = nullptr; - ze_result_t res = driverHandle->getExtensionFunctionAddress(ZE_GRAPH_EXT_NAME_1_3, - reinterpret_cast(&ddi)); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - - EXPECT_NE(ddi->pfnCreate, nullptr); - EXPECT_NE(ddi->pfnDestroy, nullptr); - EXPECT_NE(ddi->pfnGetProperties, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties, nullptr); - EXPECT_NE(ddi->pfnSetArgumentValue, nullptr); - EXPECT_NE(ddi->pfnAppendGraphInitialize, nullptr); - EXPECT_NE(ddi->pfnAppendGraphExecute, nullptr); - EXPECT_NE(ddi->pfnGetNativeBinary, nullptr); - EXPECT_NE(ddi->pfnDeviceGetGraphProperties, nullptr); - EXPECT_NE(ddi->pfnGraphGetArgumentMetadata, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties2, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties3, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkCreate, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkDestroy, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkGetSupportedLayers, nullptr); -} - -TEST_F(DriverVersionTest, checkGraphExtension_1_4_FunctionTable) { - ze_graph_dditable_ext_1_4_t *ddi = nullptr; - ze_result_t res = driverHandle->getExtensionFunctionAddress(ZE_GRAPH_EXT_NAME_1_4, - reinterpret_cast(&ddi)); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - - EXPECT_NE(ddi->pfnCreate, nullptr); - EXPECT_NE(ddi->pfnDestroy, nullptr); - EXPECT_NE(ddi->pfnGetProperties, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties, nullptr); - EXPECT_NE(ddi->pfnSetArgumentValue, nullptr); - EXPECT_NE(ddi->pfnAppendGraphInitialize, nullptr); - EXPECT_NE(ddi->pfnAppendGraphExecute, nullptr); - EXPECT_NE(ddi->pfnGetNativeBinary, nullptr); - EXPECT_NE(ddi->pfnDeviceGetGraphProperties, nullptr); - EXPECT_NE(ddi->pfnGraphGetArgumentMetadata, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties2, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties3, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkCreate, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkDestroy, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkGetSupportedLayers, nullptr); - EXPECT_NE(ddi->pfnBuildLogGetString, nullptr); -} - -TEST_F(DriverVersionTest, checkGraphExtension_1_5_FunctionTable) { - ze_graph_dditable_ext_1_5_t *ddi = nullptr; - ze_result_t res = driverHandle->getExtensionFunctionAddress(ZE_GRAPH_EXT_NAME_1_5, - reinterpret_cast(&ddi)); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - - EXPECT_NE(ddi->pfnCreate, nullptr); - EXPECT_NE(ddi->pfnDestroy, nullptr); - EXPECT_NE(ddi->pfnGetProperties, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties, nullptr); - EXPECT_NE(ddi->pfnSetArgumentValue, nullptr); - EXPECT_NE(ddi->pfnAppendGraphInitialize, nullptr); - EXPECT_NE(ddi->pfnAppendGraphExecute, nullptr); - EXPECT_NE(ddi->pfnGetNativeBinary, nullptr); - EXPECT_NE(ddi->pfnDeviceGetGraphProperties, nullptr); - EXPECT_NE(ddi->pfnGraphGetArgumentMetadata, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties2, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties3, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkCreate, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkDestroy, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkGetSupportedLayers, nullptr); - EXPECT_NE(ddi->pfnBuildLogGetString, nullptr); - EXPECT_NE(ddi->pfnCreate2, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkCreate2, nullptr); - EXPECT_NE(ddi->pfnQueryContextMemory, nullptr); -} - -TEST_F(DriverVersionTest, checkGraphExtension_1_6_FunctionTable) { - ze_graph_dditable_ext_1_6_t *ddi = nullptr; - ze_result_t res = driverHandle->getExtensionFunctionAddress(ZE_GRAPH_EXT_NAME_1_6, - reinterpret_cast(&ddi)); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - - EXPECT_NE(ddi->pfnCreate, nullptr); - EXPECT_NE(ddi->pfnDestroy, nullptr); - EXPECT_NE(ddi->pfnGetProperties, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties, nullptr); - EXPECT_NE(ddi->pfnSetArgumentValue, nullptr); - EXPECT_NE(ddi->pfnAppendGraphInitialize, nullptr); - EXPECT_NE(ddi->pfnAppendGraphExecute, nullptr); - EXPECT_NE(ddi->pfnGetNativeBinary, nullptr); - EXPECT_NE(ddi->pfnDeviceGetGraphProperties, nullptr); - EXPECT_NE(ddi->pfnGraphGetArgumentMetadata, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties2, nullptr); - EXPECT_NE(ddi->pfnGetArgumentProperties3, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkCreate, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkDestroy, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkGetSupportedLayers, nullptr); - EXPECT_NE(ddi->pfnBuildLogGetString, nullptr); - EXPECT_NE(ddi->pfnCreate2, nullptr); - EXPECT_NE(ddi->pfnQueryNetworkCreate2, nullptr); - EXPECT_NE(ddi->pfnQueryContextMemory, nullptr); - EXPECT_NE(ddi->pfnDeviceGetGraphProperties2, nullptr); -} - -TEST_F(DriverVersionTest, checkGraphProfilingDataFunctionTable) { - ze_graph_profiling_dditable_ext_t *ddi = nullptr; - ze_result_t res = driverHandle->getExtensionFunctionAddress(ZE_PROFILING_DATA_EXT_NAME, - reinterpret_cast(&ddi)); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - - EXPECT_NE(ddi->pfnProfilingPoolCreate, nullptr); - EXPECT_NE(ddi->pfnProfilingPoolDestroy, nullptr); - EXPECT_NE(ddi->pfnProfilingQueryCreate, nullptr); - EXPECT_NE(ddi->pfnProfilingQueryDestroy, nullptr); - EXPECT_NE(ddi->pfnProfilingQueryGetData, nullptr); - EXPECT_NE(ddi->pfnDeviceGetProfilingDataProperties, nullptr); -} - TEST_F(DriverVersionTest, returnsExpectedGetDriverPropertiesResultAndIPCPropertyFlagType) { ze_result_t res = driverHandle->getIPCProperties(nullptr); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, res); diff --git a/umd/level_zero_driver/unit_tests/source/core/event/test_event.cpp b/umd/level_zero_driver/unit_tests/source/core/event/test_event.cpp index f4448d6..349eb75 100644 --- a/umd/level_zero_driver/unit_tests/source/core/event/test_event.cpp +++ b/umd/level_zero_driver/unit_tests/source/core/event/test_event.cpp @@ -37,31 +37,34 @@ TEST_F(EventPoolTest, givenCallCreateEventPoolReturnsSuccess) { ASSERT_NE(nullptr, context); EXPECT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolCreate(context, &eventPoolDesc, 0, nullptr, &hEventPool)); + L0::EventPool::create(context, &eventPoolDesc, 0, nullptr, &hEventPool)); EXPECT_NE(nullptr, hEventPool); // Deallocate the event pool. - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventPoolDestroy(hEventPool)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::EventPool::fromHandle(hEventPool)->destroy()); } -TEST_F(EventPoolTest, eventPoolCreateHandleErrors) { +TEST_F(EventPoolTest, createAndDestroyErrors) { ASSERT_NE(nullptr, context); // ZE_RESULT_ERROR_INVALID_NULL_POINTER if desc == nullptr or phEventPool. EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, - zeEventPoolCreate(context, nullptr, 0, nullptr, &hEventPool)); + L0::EventPool::create(context, nullptr, 0, nullptr, &hEventPool)); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, - zeEventPoolCreate(context, &eventPoolDesc, 0, nullptr, nullptr)); + L0::EventPool::create(context, &eventPoolDesc, 0, nullptr, nullptr)); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_SIZE, + L0::EventPool::create(context, &eventPoolDesc, 1, nullptr, &hEventPool)); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, - zeEventPoolCreate(context, nullptr, 0, nullptr, nullptr)); + L0::EventPool::create(context, nullptr, 0, nullptr, nullptr)); eventPoolDesc.count = 0; EXPECT_EQ(ZE_RESULT_ERROR_INVALID_SIZE, - zeEventPoolCreate(context, &eventPoolDesc, 0, nullptr, &hEventPool)); + L0::EventPool::create(context, &eventPoolDesc, 0, nullptr, &hEventPool)); eventPoolDesc.count = 1; EXPECT_EQ(ZE_RESULT_ERROR_INVALID_SIZE, - zeEventPoolCreate(context, &eventPoolDesc, 1, nullptr, &hEventPool)); + L0::EventPool::create(context, &eventPoolDesc, 1, nullptr, &hEventPool)); } TEST_F(EventPoolTest, eventPoolCreateRetunsSuccessForManyEvents) { @@ -69,10 +72,10 @@ TEST_F(EventPoolTest, eventPoolCreateRetunsSuccessForManyEvents) { const uint32_t nEvents = 10; eventPoolDesc.count = nEvents; EXPECT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolCreate(context, &eventPoolDesc, 0, nullptr, &hEventPool)); + L0::EventPool::create(context, &eventPoolDesc, 0, nullptr, &hEventPool)); // Deallocate the event pool. - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventPoolDestroy(hEventPool)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::EventPool::fromHandle(hEventPool)->destroy()); } struct EventTest : public EventPoolTest { @@ -82,19 +85,19 @@ struct EventTest : public EventPoolTest { eventPoolDesc.count = 1; ASSERT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolCreate(context, &eventPoolDesc, 0, nullptr, &hEventPool)); + L0::EventPool::create(context, &eventPoolDesc, 0, nullptr, &hEventPool)); - pEvPool = EventPool::fromHandle(hEventPool); + pEvPool = L0::EventPool::fromHandle(hEventPool); ASSERT_EQ(ZE_RESULT_SUCCESS, pEvPool->createEvent(&eventDesc, &hEvent)); } void TearDown() override { if (hEvent != nullptr) { - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hEvent)); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hEvent)->destroy()); } if (hEventPool != nullptr) { - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolDestroy(hEventPool)); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::EventPool::fromHandle(hEventPool)->destroy()); hEventPool = nullptr; } @@ -110,12 +113,14 @@ struct EventTest : public EventPoolTest { EventPool *pEvPool = nullptr; }; -TEST_F(EventTest, eventStatusChangesAndQuery) { - // Report errors on wrong handles. - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, zeEventQueryStatus(nullptr)); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, zeEventHostSignal(nullptr)); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, zeEventHostReset(nullptr)); +TEST_F(EventTest, createAndDestroyErrors) { + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, + L0::EventPool::fromHandle(pEvPool)->createEvent(nullptr, &hEvent)); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, + L0::EventPool::fromHandle(pEvPool)->createEvent(&eventDesc, nullptr)); +} +TEST_F(EventTest, eventStatusChangesAndQuery) { // Initially the status query returns NOT_READY. auto event = Event::fromHandle(hEvent); ASSERT_NE(nullptr, event); @@ -158,7 +163,7 @@ struct MultipleEventTest : public EventPoolTest { void TearDown() override { if (hEventPool != nullptr) { - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolDestroy(hEventPool)); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::EventPool::fromHandle(hEventPool)->destroy()); hEventPool = nullptr; } @@ -168,7 +173,7 @@ struct MultipleEventTest : public EventPoolTest { void prepareEventPool(uint32_t numEvents) { eventPoolDesc.count = numEvents; ASSERT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolCreate(context, &eventPoolDesc, 0, nullptr, &hEventPool)); + L0::EventPool::create(context, &eventPoolDesc, 0, nullptr, &hEventPool)); } ze_event_desc_t eventDesc = {ZE_STRUCTURE_TYPE_EVENT_DESC, @@ -176,7 +181,7 @@ struct MultipleEventTest : public EventPoolTest { 0, 0, ZE_EVENT_SCOPE_FLAG_HOST}; - EventPool *pEvPool = nullptr; + L0::EventPool *pEvPool = nullptr; ze_event_handle_t hTestEvent0 = nullptr; ze_event_handle_t hTestEvent1 = nullptr; ze_event_handle_t hTestEvent2 = nullptr; @@ -209,9 +214,9 @@ TEST_F(MultipleEventTest, eventPoolAllocatesMultipleEvents) { EXPECT_NE(hTestEvent0, hTestEvent1); // Events should hold properly offsetted pointers. - auto ev0 = Event::fromHandle(hTestEvent0); - auto ev1 = Event::fromHandle(hTestEvent1); - auto ev2 = Event::fromHandle(hTestEvent2); + auto ev0 = L0::Event::fromHandle(hTestEvent0); + auto ev1 = L0::Event::fromHandle(hTestEvent1); + auto ev2 = L0::Event::fromHandle(hTestEvent2); ASSERT_NE(nullptr, ev0); ASSERT_NE(nullptr, ev1); ASSERT_NE(nullptr, ev2); @@ -228,16 +233,16 @@ TEST_F(MultipleEventTest, eventPoolAllocatesMultipleEvents) { reinterpret_cast(static_cast(evPtr1))); // Deallocate - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent0)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent1)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent2)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent0)->destroy()); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent1)->destroy()); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent2)->destroy()); } TEST_F(MultipleEventTest, eventPoolReAllocatesMultipleEvents) { // Maximum 2 allocation capability event pool. const uint32_t nMaxEvents = 2; prepareEventPool(nMaxEvents); - auto evPool = EventPool::fromHandle(hEventPool); + auto evPool = L0::EventPool::fromHandle(hEventPool); ASSERT_NE(nullptr, evPool); // Index 0 in event pool. @@ -249,7 +254,7 @@ TEST_F(MultipleEventTest, eventPoolReAllocatesMultipleEvents) { EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, evPool->createEvent(&eventDesc, &hTestEvent0)); // Destory & re-allocate. - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent0)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent0)->destroy()); EXPECT_EQ(ZE_RESULT_SUCCESS, evPool->createEvent(&eventDesc, &hTestEvent0)); EXPECT_NE(nullptr, hTestEvent0); @@ -262,20 +267,20 @@ TEST_F(MultipleEventTest, eventPoolReAllocatesMultipleEvents) { EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, evPool->createEvent(&eventDesc, &hTestEvent1)); // Destory & re-allocate. - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent1)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent1)->destroy()); EXPECT_EQ(ZE_RESULT_SUCCESS, evPool->createEvent(&eventDesc, &hTestEvent1)); EXPECT_NE(nullptr, hTestEvent1); // Resource deallocation. - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent0)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent1)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent0)->destroy()); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent1)->destroy()); } TEST_F(MultipleEventTest, eventPoolHandleAllocationErrors) { // Maximum 2 allocation capability event pool. const uint32_t nMaxEvents = 2; prepareEventPool(nMaxEvents); - auto evPool = EventPool::fromHandle(hEventPool); + auto evPool = L0::EventPool::fromHandle(hEventPool); // Index 0 in event pool. eventDesc.index = 0; @@ -293,17 +298,17 @@ TEST_F(MultipleEventTest, eventPoolHandleAllocationErrors) { EXPECT_EQ(nullptr, hTestEvent1); // Deallocating index 0 will free the space. - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent0)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent0)->destroy()); eventDesc.index = 0; EXPECT_EQ(ZE_RESULT_SUCCESS, evPool->createEvent(&eventDesc, &hTestEvent0)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent0)); + EXPECT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent0)->destroy()); } TEST_F(MultipleEventTest, memoryPinningHappensOnlyOnceOnMultipleEventCreations) { // A maximum 5 allocation capability event pool. const uint32_t nMaxEvents = 5; prepareEventPool(nMaxEvents); - auto evPool = EventPool::fromHandle(hEventPool); + auto evPool = L0::EventPool::fromHandle(hEventPool); // Allocate events. std::vector evHandles; @@ -320,7 +325,7 @@ TEST_F(MultipleEventTest, memoryPinningHappensOnlyOnceOnMultipleEventCreations) // Deallocate. for (auto &hTestEvent0 : evHandles) { - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventDestroy(hTestEvent0)); + ASSERT_EQ(ZE_RESULT_SUCCESS, L0::Event::fromHandle(hTestEvent0)->destroy()); } } diff --git a/umd/level_zero_driver/unit_tests/source/core/fence/test_fence.cpp b/umd/level_zero_driver/unit_tests/source/core/fence/test_fence.cpp index ee7e014..a83c719 100644 --- a/umd/level_zero_driver/unit_tests/source/core/fence/test_fence.cpp +++ b/umd/level_zero_driver/unit_tests/source/core/fence/test_fence.cpp @@ -27,18 +27,16 @@ struct FenceTest : public Test { void SetUp() override { CommandQueueFixture::SetUp(); - ze_command_queue_handle_t hCommandQueue = createCommandQueue(0); + hCommandQueue = createCommandQueue(); ASSERT_NE(hCommandQueue, nullptr); - cmdQue = CommandQueue::fromHandle(hCommandQueue); + cmdQue = L0::CommandQueue::fromHandle(hCommandQueue); - hCmdList = createCommandList(0); + hCmdList = createCommandList(); ASSERT_NE(nullptr, hCmdList); - cmdList = CommandList::fromHandle(hCmdList); + cmdList = L0::CommandList::fromHandle(hCmdList); - ze_fence_desc_t fenceDesc{.stype = ZE_STRUCTURE_TYPE_FENCE_DESC, - .pNext = nullptr, - .flags = 0}; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeFenceCreate(hCommandQueue, &fenceDesc, &hFence)); + ASSERT_EQ(ZE_RESULT_SUCCESS, + L0::CommandQueue::fromHandle(hCommandQueue)->createFence(&fenceDesc, &hFence)); ASSERT_NE(nullptr, hFence); fence = static_cast(hFence); } @@ -56,15 +54,25 @@ struct FenceTest : public Test { CommandQueueFixture::TearDown(); } - CommandQueue *cmdQue = nullptr; + ze_fence_desc_t fenceDesc{.stype = ZE_STRUCTURE_TYPE_FENCE_DESC, .pNext = nullptr, .flags = 0}; + ze_command_queue_handle_t hCommandQueue = nullptr; + L0::CommandQueue *cmdQue = nullptr; ze_command_list_handle_t hCmdList = nullptr; - CommandList *cmdList = nullptr; + L0::CommandList *cmdList = nullptr; ze_fence_handle_t hFence = nullptr; - Fence *fence = nullptr; + L0::Fence *fence = nullptr; const size_t memAllocSize = 64; }; +TEST_F(FenceTest, createErrors) { + ze_fence_handle_t hFence = nullptr; + ASSERT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, + L0::CommandQueue::fromHandle(hCommandQueue)->createFence(nullptr, &hFence)); + ASSERT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, + L0::CommandQueue::fromHandle(hCommandQueue)->createFence(&fenceDesc, nullptr)); +} + TEST_F(FenceTest, synchornizeAndQueryStatusShouldReturnSameStatus) { EXPECT_EQ(fence->synchronize(0), fence->queryStatus()); } diff --git a/umd/level_zero_driver/unit_tests/source/core/memory/test_memory.cpp b/umd/level_zero_driver/unit_tests/source/core/memory/test_memory.cpp index ed1584d..9b87067 100644 --- a/umd/level_zero_driver/unit_tests/source/core/memory/test_memory.cpp +++ b/umd/level_zero_driver/unit_tests/source/core/memory/test_memory.cpp @@ -9,8 +9,6 @@ #include "gtest/gtest.h" #include "level_zero_driver/core/source/context/context.hpp" -#include "level_zero_driver/core/source/device/device.hpp" -#include "level_zero_driver/core/source/driver/driver_handle.hpp" #include "level_zero_driver/unit_tests/fixtures/device_fixture.hpp" #include "vpu_driver/source/memory/vpu_buffer_object.hpp" #include "vpu_driver/unit_tests/test_macros/test.hpp" @@ -41,10 +39,6 @@ TEST_F(ContextMemoryTest, void *ptr = nullptr; ze_result_t result = ZE_RESULT_SUCCESS; - ze_host_mem_alloc_desc_t hDesc = {}; - result = zeMemAllocHost(nullptr, &hDesc, size, alignment, &ptr); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, result); - result = context->allocMemory(size, alignment, &ptr, @@ -62,18 +56,6 @@ TEST_F(ContextMemoryTest, VPU::VPUBufferObject::Location::Host, VPU::VPUBufferObject::Type::CachedShave); EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT, result); - - // Testing flags - alignment = 1u; - - ze_device_mem_alloc_desc_t dDesc = {}; - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_HANDLE, - zeMemAllocDevice(nullptr, - &dDesc, - size, - alignment, - driverHandle->getPrimaryDevice()->toHandle(), - &ptr)); } class ContextMemoryTestRange : public ContextMemoryTest {}; diff --git a/umd/level_zero_driver/unit_tests/source/ext/graph/test_disk_cache.cpp b/umd/level_zero_driver/unit_tests/source/ext/graph/test_disk_cache.cpp index 1ab7b5b..84b9c00 100644 --- a/umd/level_zero_driver/unit_tests/source/ext/graph/test_disk_cache.cpp +++ b/umd/level_zero_driver/unit_tests/source/ext/graph/test_disk_cache.cpp @@ -5,16 +5,19 @@ * */ +#include #include #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "level_zero/ze_graph_ext.h" +#include "level_zero_driver/ext/source/graph/blob_container.hpp" #include "level_zero_driver/ext/source/graph/disk_cache.hpp" #include "vpu_driver/unit_tests/mocks/gmock_os_interface_imp.hpp" -#include #include #include +#include namespace L0 { @@ -30,7 +33,7 @@ TEST_F(DiskCacheNegTest, UninitializedCachedExpectNoReturn) { ze_graph_desc_2_t desc = {}; EXPECT_EQ(diskCache.computeKey(desc), ""); - EXPECT_EQ(diskCache.getBlob(""), DiskCache::Blob()); + EXPECT_EQ(diskCache.getBlob(""), nullptr); diskCache.setBlob("", {}); } @@ -72,7 +75,36 @@ TEST_F(DiskCacheTest, ComputeKeys) { TEST_F(DiskCacheTest, MissCache) { ze_graph_desc_2_t desc = {}; auto key = cache->computeKey(desc); - EXPECT_EQ(cache->getBlob(key).size(), 0); + EXPECT_EQ(cache->getBlob(key), nullptr); +} + +TEST_F(DiskCacheTest, MissCacheInvalidFileSize) { + auto osFile = std::make_unique(); + EXPECT_CALL(*osFile, size).WillOnce(::testing::Return(0)); + + EXPECT_CALL(osInfc, osiOpenWithSharedLock).WillOnce(::testing::Return(std::move(osFile))); + + ze_graph_desc_2_t desc = {}; + auto key = cache->computeKey(desc); + EXPECT_EQ(cache->getBlob(key), nullptr); +} + +TEST_F(DiskCacheTest, HitCache) { + constexpr size_t fileSize = 64; + + auto osFile = std::make_unique(); + auto mmapPtr = std::make_unique(fileSize); + EXPECT_CALL(*osFile, size).WillRepeatedly(::testing::Return(fileSize)); + EXPECT_CALL(*osFile, mmap).WillRepeatedly(::testing::Return(mmapPtr.get())); + + EXPECT_CALL(osInfc, osiOpenWithSharedLock).WillOnce(::testing::Return(std::move(osFile))); + + ze_graph_desc_2_t desc = {}; + auto key = cache->computeKey(desc); + auto blob = cache->getBlob(key); + EXPECT_NE(blob, nullptr); + EXPECT_EQ(blob->ptr, mmapPtr.get()); + EXPECT_EQ(blob->size, fileSize); } } // namespace L0 diff --git a/umd/level_zero_driver/unit_tests/source/tools/metrics/test_metrics.cpp b/umd/level_zero_driver/unit_tests/source/tools/metrics/test_metrics.cpp index 8b27733..9b9a910 100644 --- a/umd/level_zero_driver/unit_tests/source/tools/metrics/test_metrics.cpp +++ b/umd/level_zero_driver/unit_tests/source/tools/metrics/test_metrics.cpp @@ -101,8 +101,9 @@ struct MetricGroupShared : public ContextFixture { uint32_t metricCount = 0; for (uint8_t i = 0; i < metricGroupCount; i++) { - ASSERT_EQ(MetricGroup::fromHandle(metricGroups[i])->getProperties(&groupProperties[i]), - ZE_RESULT_SUCCESS); + ASSERT_EQ( + L0::MetricGroup::fromHandle(metricGroups[i])->getProperties(&groupProperties[i]), + ZE_RESULT_SUCCESS); if (memcmp(groupProperties[i].name, metricGroupName.c_str(), metricGroupName.length()) == 0) { @@ -121,7 +122,7 @@ struct MetricGroupShared : public ContextFixture { std::vector metrics(metricCount); - ASSERT_EQ(MetricGroup::fromHandle(metricGroups[safe_cast(metricGroupIndex)]) + ASSERT_EQ(L0::MetricGroup::fromHandle(metricGroups[safe_cast(metricGroupIndex)]) ->getMetric(&metricCount, metrics.data()), ZE_RESULT_SUCCESS); ASSERT_EQ(metricCount, metrics.size()); @@ -129,7 +130,7 @@ struct MetricGroupShared : public ContextFixture { std::vector properties(metricCount); for (uint8_t i = 0; i < metricCount; i++) { - EXPECT_EQ(Metric::fromHandle(metrics[i])->getProperties(&properties[i]), + EXPECT_EQ(L0::Metric::fromHandle(metrics[i])->getProperties(&properties[i]), ZE_RESULT_SUCCESS); EXPECT_EQ(memcmp(properties[i].name, metricNames[i].c_str(), metricNames[i].length()), @@ -156,23 +157,23 @@ struct MetricGroupTest : public Test { }; TEST_F(MetricGroupTest, metricGroupGetPropertiesReturnsFailureWithIncorrectInput) { - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0])->getProperties(nullptr), + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0])->getProperties(nullptr), ZE_RESULT_ERROR_INVALID_NULL_POINTER); } TEST_F(MetricGroupTest, metricGettingReturnsExpectedResults) { // Retrieve metrics for metric group #1 - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0])->getMetric(nullptr, nullptr), + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0])->getMetric(nullptr, nullptr), ZE_RESULT_ERROR_INVALID_NULL_POINTER); uint32_t count = 0; - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0])->getMetric(&count, nullptr), + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0])->getMetric(&count, nullptr), ZE_RESULT_SUCCESS); EXPECT_GT(count, 0u); std::vector metrics(count); EXPECT_EQ(*metrics.data(), nullptr); - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0])->getMetric(&count, metrics.data()), + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0])->getMetric(&count, metrics.data()), ZE_RESULT_SUCCESS); EXPECT_NE(*metrics.data(), nullptr); } @@ -245,7 +246,7 @@ TEST_F(MetricGroupTest, activateMetricGroupsReturnsProperExpectedActivatedGroups } TEST_F(MetricGroupTest, multipleContextActivateMetricGroupsIsolationTest) { - Context *context1 = nullptr; + L0::Context *context1 = nullptr; // Creating context1 { ze_context_desc_t desc = {}; @@ -255,7 +256,7 @@ TEST_F(MetricGroupTest, multipleContextActivateMetricGroupsIsolationTest) { ASSERT_NE(nullptr, context1); } - Context *context2 = nullptr; + L0::Context *context2 = nullptr; // Creating context2 { ze_context_desc_t desc = {}; @@ -291,7 +292,7 @@ TEST_F(MetricGroupTest, multipleContextActivateMetricGroupsIsolationTest) { } TEST_F(MetricGroupTest, multipleContextActivateSpecificMetricGroupsHasUniqueControl) { - Context *context1 = nullptr; + L0::Context *context1 = nullptr; // Creating context1 { ze_context_desc_t desc = {}; @@ -301,7 +302,7 @@ TEST_F(MetricGroupTest, multipleContextActivateSpecificMetricGroupsHasUniqueCont ASSERT_NE(nullptr, context1); } - Context *context2 = nullptr; + L0::Context *context2 = nullptr; // Creating context2 { ze_context_desc_t desc = {}; @@ -311,7 +312,7 @@ TEST_F(MetricGroupTest, multipleContextActivateSpecificMetricGroupsHasUniqueCont ASSERT_NE(nullptr, context2); } - Context *context3 = nullptr; + L0::Context *context3 = nullptr; // Creating context3 { ze_context_desc_t desc = {}; @@ -370,7 +371,7 @@ TEST_F(MetricGroupTest, multipleContextActivateSpecificMetricGroupsHasUniqueCont } TEST_F(MetricGroupTest, contextCreateQueryPoolReturnsFailureWithoutProperInitializedParams) { - auto deviceNew = std::make_unique(nullptr, nullptr); + auto deviceNew = std::make_unique(nullptr, nullptr); ASSERT_NE(deviceNew, nullptr); ASSERT_NE(context, nullptr); @@ -434,7 +435,7 @@ TEST_F(MetricGroupTest, contextCreateQueryPoolReturnsExpectedResultsWhenMetricGr &hMetricQueryPool), ZE_RESULT_SUCCESS); - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); + EXPECT_EQ(L0::MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); } TEST_F(MetricGroupTest, createQueryReturnsFailureWithIncorrectParams) { @@ -448,23 +449,26 @@ TEST_F(MetricGroupTest, createQueryReturnsFailureWithIncorrectParams) { &hMetricQueryPool), ZE_RESULT_SUCCESS); - EXPECT_EQ(zetMetricQueryCreate(hMetricQueryPool, 2u, nullptr), + EXPECT_EQ(L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(2u, nullptr), ZE_RESULT_ERROR_INVALID_NULL_POINTER); zet_metric_query_handle_t hMetricQuery; - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(1u, &hMetricQuery), - ZE_RESULT_ERROR_INVALID_ARGUMENT); - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(2u, &hMetricQuery), - ZE_RESULT_ERROR_INVALID_ARGUMENT); + EXPECT_EQ( + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(1u, &hMetricQuery), + ZE_RESULT_ERROR_INVALID_ARGUMENT); + EXPECT_EQ( + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(2u, &hMetricQuery), + ZE_RESULT_ERROR_INVALID_ARGUMENT); // Deactivate metric groups ASSERT_EQ(context->activateMetricGroups(device->toHandle(), 0, nullptr), ZE_RESULT_SUCCESS); // Expect failure as metric group should be activated - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), - ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE); + EXPECT_EQ( + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), + ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE); - ASSERT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); } TEST_F(MetricGroupTest, createQueryReturnsExpectedResults) { @@ -480,30 +484,34 @@ TEST_F(MetricGroupTest, createQueryReturnsExpectedResults) { ZE_RESULT_SUCCESS); zet_metric_query_handle_t hMetricQuery; - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), - ZE_RESULT_SUCCESS); + EXPECT_EQ( + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), + ZE_RESULT_SUCCESS); zet_metric_query_handle_t hMetricQuery2; - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(1u, &hMetricQuery2), - ZE_RESULT_SUCCESS); + EXPECT_EQ( + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(1u, &hMetricQuery2), + ZE_RESULT_SUCCESS); // Creating another query object at the same index should fail. - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), - ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE); + EXPECT_EQ( + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), + ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE); // Attempting to delete pool without first deleting queries, expect failure - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), + EXPECT_EQ(L0::MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE); - EXPECT_EQ(MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); - EXPECT_EQ(MetricQuery::fromHandle(hMetricQuery2)->destroy(), ZE_RESULT_SUCCESS); + EXPECT_EQ(L0::MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); + EXPECT_EQ(L0::MetricQuery::fromHandle(hMetricQuery2)->destroy(), ZE_RESULT_SUCCESS); // Recycling same index for new query once previous query is deleted - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), - ZE_RESULT_SUCCESS); + EXPECT_EQ( + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), + ZE_RESULT_SUCCESS); - ASSERT_EQ(MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); - ASSERT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); } TEST_F(MetricGroupTest, queryGetGroupMaskAndDataAddressReturnsExpectedResults) { @@ -519,17 +527,18 @@ TEST_F(MetricGroupTest, queryGetGroupMaskAndDataAddressReturnsExpectedResults) { ZE_RESULT_SUCCESS); zet_metric_query_handle_t hMetricQuery; - EXPECT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), - ZE_RESULT_SUCCESS); + EXPECT_EQ( + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), + ZE_RESULT_SUCCESS); ASSERT_NE(hMetricQuery, nullptr); - auto metricQuery = MetricQuery::fromHandle(hMetricQuery); + auto metricQuery = L0::MetricQuery::fromHandle(hMetricQuery); EXPECT_EQ(metricQuery->getMetricGroupMask(), 0b1000); EXPECT_EQ(reinterpret_cast(metricQuery->getMetricAddrPtr())[0], 0u); EXPECT_NE(reinterpret_cast(metricQuery->getMetricAddrPtr())[3], 0u); - ASSERT_EQ(MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); - ASSERT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); } TEST_F(MetricGroupTest, queryGetDataAndResetReturnsExpectedResults) { @@ -545,11 +554,12 @@ TEST_F(MetricGroupTest, queryGetDataAndResetReturnsExpectedResults) { ZE_RESULT_SUCCESS); zet_metric_query_handle_t hMetricQuery; - ASSERT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), - ZE_RESULT_SUCCESS); + ASSERT_EQ( + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), + ZE_RESULT_SUCCESS); ASSERT_NE(hMetricQuery, nullptr); - auto metricQuery = MetricQuery::fromHandle(hMetricQuery); + auto metricQuery = L0::MetricQuery::fromHandle(hMetricQuery); // Retrieve size and values of query data size_t rawDataSize = 0u; @@ -588,8 +598,8 @@ TEST_F(MetricGroupTest, queryGetDataAndResetReturnsExpectedResults) { EXPECT_EQ(rawData[i], 0u); } - ASSERT_EQ(MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); - ASSERT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); } struct MetricGroupCalculateTest : public Test { @@ -607,11 +617,11 @@ struct MetricGroupCalculateTest : public Test { ZE_RESULT_SUCCESS); ASSERT_EQ( - MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), + L0::MetricQueryPool::fromHandle(hMetricQueryPool)->createMetricQuery(0u, &hMetricQuery), ZE_RESULT_SUCCESS); ASSERT_NE(hMetricQuery, nullptr); - auto metricQuery = MetricQuery::fromHandle(hMetricQuery); + auto metricQuery = L0::MetricQuery::fromHandle(hMetricQuery); // Retrieve size and values of query data EXPECT_EQ(metricQuery->getData(&rawDataSize, nullptr), ZE_RESULT_SUCCESS); @@ -628,8 +638,8 @@ struct MetricGroupCalculateTest : public Test { } void TearDown() override { - ASSERT_EQ(MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); - ASSERT_EQ(MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQuery::fromHandle(hMetricQuery)->destroy(), ZE_RESULT_SUCCESS); + ASSERT_EQ(L0::MetricQueryPool::fromHandle(hMetricQueryPool)->destroy(), ZE_RESULT_SUCCESS); MetricGroupShared::TearDown(); } @@ -643,7 +653,7 @@ struct MetricGroupCalculateTest : public Test { TEST_F(MetricGroupCalculateTest, calculateMetricValuesReturnsFailureWithIncorrectInput) { uint32_t metricValueCount = 0; // Expect error when rawData is nullptr - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0]) + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0]) ->calculateMetricValues(ZET_METRIC_GROUP_CALCULATION_TYPE_METRIC_VALUES, rawDataSize, nullptr, @@ -652,7 +662,7 @@ TEST_F(MetricGroupCalculateTest, calculateMetricValuesReturnsFailureWithIncorrec ZE_RESULT_ERROR_INVALID_NULL_POINTER); // Expect error when pMetricValueCount is nullptr - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0]) + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0]) ->calculateMetricValues(ZET_METRIC_GROUP_CALCULATION_TYPE_METRIC_VALUES, rawDataSize, reinterpret_cast(rawData.data()), @@ -661,7 +671,7 @@ TEST_F(MetricGroupCalculateTest, calculateMetricValuesReturnsFailureWithIncorrec ZE_RESULT_ERROR_INVALID_NULL_POINTER); // Expect error when metric group calculation type exceeding max - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0]) + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0]) ->calculateMetricValues(ZET_METRIC_GROUP_CALCULATION_TYPE_FORCE_UINT32, rawDataSize, reinterpret_cast(rawData.data()), @@ -673,7 +683,7 @@ TEST_F(MetricGroupCalculateTest, calculateMetricValuesReturnsFailureWithIncorrec // size) metricValueCount = 1; std::vector metricValues(metricValueCount); - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0]) + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0]) ->calculateMetricValues(ZET_METRIC_GROUP_CALCULATION_TYPE_MAX_METRIC_VALUES, rawDataSize, reinterpret_cast(rawData.data()), @@ -684,7 +694,7 @@ TEST_F(MetricGroupCalculateTest, calculateMetricValuesReturnsFailureWithIncorrec TEST_F(MetricGroupCalculateTest, calculateMetricValuesReturnsExpectedResults) { uint32_t metricValueCount = 0; - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0]) + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0]) ->calculateMetricValues(ZET_METRIC_GROUP_CALCULATION_TYPE_METRIC_VALUES, rawDataSize, reinterpret_cast(rawData.data()), @@ -694,7 +704,7 @@ TEST_F(MetricGroupCalculateTest, calculateMetricValuesReturnsExpectedResults) { EXPECT_GT(metricValueCount, 0); std::vector metricValues(metricValueCount); - EXPECT_EQ(MetricGroup::fromHandle(metricGroups[0]) + EXPECT_EQ(L0::MetricGroup::fromHandle(metricGroups[0]) ->calculateMetricValues(ZET_METRIC_GROUP_CALCULATION_TYPE_METRIC_VALUES, rawDataSize, reinterpret_cast(rawData.data()), @@ -728,7 +738,7 @@ TEST_F(MultiDeviceMetricTest, activatingMetricGroupsNotAssociatedWithDeviceRetur ASSERT_EQ(driverHandle->getDevice(&count, phDevices.data()), ZE_RESULT_SUCCESS); } - Context *context = nullptr; + L0::Context *context = nullptr; // Creating context { ze_context_desc_t desc; @@ -738,7 +748,7 @@ TEST_F(MultiDeviceMetricTest, activatingMetricGroupsNotAssociatedWithDeviceRetur ASSERT_NE(nullptr, context); } - auto device1 = Device::fromHandle(phDevices[0]); + auto device1 = L0::Device::fromHandle(phDevices[0]); auto metricContext = device1->getMetricContext(); auto mockMetricContext = reinterpret_cast(metricContext.get()); @@ -746,7 +756,7 @@ TEST_F(MultiDeviceMetricTest, activatingMetricGroupsNotAssociatedWithDeviceRetur uint32_t metricGroupCount = 0u; // Retreiving metric groups for second device { - auto device2 = Device::fromHandle(phDevices[1]); + auto device2 = L0::Device::fromHandle(phDevices[1]); ASSERT_EQ(device2->metricGroupGet(&metricGroupCount, nullptr), ZE_RESULT_SUCCESS); ASSERT_GT(metricGroupCount, 0u); diff --git a/umd/vpu_driver/include/umd_common.hpp b/umd/vpu_driver/include/umd_common.hpp index f293fd6..b5fe37d 100644 --- a/umd/vpu_driver/include/umd_common.hpp +++ b/umd/vpu_driver/include/umd_common.hpp @@ -8,6 +8,7 @@ #pragma once #include + #include #include #include @@ -66,8 +67,3 @@ To safe_cast(From x) { inline size_t getFwDataCacheAlign(size_t a) { return ALIGN(a, 64); } - -struct BlobInfo { - uint8_t *ptr; - size_t size; -}; diff --git a/umd/vpu_driver/source/CMakeLists.txt b/umd/vpu_driver/source/CMakeLists.txt index eb1cc04..60e0606 100644 --- a/umd/vpu_driver/source/CMakeLists.txt +++ b/umd/vpu_driver/source/CMakeLists.txt @@ -9,7 +9,6 @@ set(TARGET_NAME vpu_driver) add_library(${TARGET_NAME} STATIC) set_property(TARGET ${TARGET_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) -target_include_directories(${TARGET_NAME} PRIVATE $) -target_link_libraries(${TARGET_NAME} fw_vpu_api_headers npu_compiler) +target_link_libraries(${TARGET_NAME} fw_vpu_api_headers vpux_elf npu_compiler) add_subdirectories() diff --git a/umd/vpu_driver/source/device/hw_info.hpp b/umd/vpu_driver/source/device/hw_info.hpp index 4294d2c..bbd2cb0 100644 --- a/umd/vpu_driver/source/device/hw_info.hpp +++ b/umd/vpu_driver/source/device/hw_info.hpp @@ -33,7 +33,6 @@ struct VPUHwInfo { uint32_t deviceRevision = 0u; uint32_t subdeviceId = 0u; uint32_t coreClockRate = 0u; - uint64_t maxMemAllocSize = 0x100000000; uint32_t maxHardwareContexts = 1; uint32_t maxCommandQueuePriority = 2; uint32_t numThreadsPerEU = 1; diff --git a/umd/vpu_driver/source/device/vpu_device.cpp b/umd/vpu_driver/source/device/vpu_device.cpp index bdd7421..5f5188a 100644 --- a/umd/vpu_driver/source/device/vpu_device.cpp +++ b/umd/vpu_driver/source/device/vpu_device.cpp @@ -10,19 +10,20 @@ #include "api/vpu_jsm_api.h" #include "vpu_driver/source/device/hw_info.hpp" #include "vpu_driver/source/device/vpu_device_context.hpp" +#include "vpu_driver/source/os_interface/os_interface.hpp" #include "vpu_driver/source/os_interface/vpu_driver_api.hpp" #include "vpu_driver/source/utilities/log.hpp" #include #include #include +#include #include #include #include #include namespace VPU { -class OsInterface; VPUDevice::VPUDevice(std::string devPath, OsInterface &osInfc) : devPath(std::move(devPath)) , osInfc(osInfc) {} @@ -276,38 +277,6 @@ bool VPUDevice::isConnected() { } } -size_t VPUDevice::getNumberOfEngineGroups(void) const { - return engineGroups.size(); -} - -size_t VPUDevice::getEngineMaxMemoryFillSize() { - return sizeof(uint32_t); -} - -EngineType VPUDevice::getEngineType(uint32_t engGrpIdx) { - if (engGrpIdx >= getNumberOfEngineGroups()) { - LOG_E("Engine group with index %u does not exist", engGrpIdx); - return EngineType::INVALID; - } - - return engineGroups[engGrpIdx]; -} - -EngineType VPUDevice::getEngineTypeFromOrdinal(uint32_t engGrpOrdinal, bool &isCopyOnly) { - EngineType engType = getEngineType(engGrpOrdinal); - if (engType == EngineType::INVALID) - return engType; - - isCopyOnly = (engineSupportCopy(engType) && !engineSupportCompute(engType) && - !engineSupportCooperativeKernel(engType) && !engineSupportMetrics(engType)); - - return engType; -} - -bool VPUDevice::engineSupportCompute(EngineType engineType) const { - return engineType == EngineType::COMPUTE; -} - std::unique_ptr VPUDevice::createDeviceContext() { auto drvApi = VPUDriverApi::openDriverApi(devPath, osInfc); if (drvApi == nullptr) { @@ -360,4 +329,25 @@ int VPUDevice::getBDF(uint32_t *domain, uint32_t *bus, uint32_t *dev, uint32_t * return 0; } +bool VPUDevice::getActiveTime(uint64_t &activeTimeUs) { + auto drvApi = VPUDriverApi::openDriverApi(devPath, osInfc); + if (drvApi == nullptr) { + LOG_E("Failed to open openDriverApi"); + return false; + } + std::string devSysPath = drvApi->getSysDeviceAbsolutePath(); + + auto activeTime = osInfc.osiReadFile(devSysPath + "npu_busy_time_us"); + if (activeTime.empty()) + return false; + + auto [ptr, ec] = + std::from_chars(activeTime.data(), activeTime.data() + activeTime.size(), activeTimeUs); + if (ec != std::errc()) { + auto err = std::make_error_condition(ec); + LOG_E("Failed to read active driver time: %s", err.message().c_str()); + return false; + } + return true; +} } // namespace VPU diff --git a/umd/vpu_driver/source/device/vpu_device.hpp b/umd/vpu_driver/source/device/vpu_device.hpp index e553989..390d8f4 100644 --- a/umd/vpu_driver/source/device/vpu_device.hpp +++ b/umd/vpu_driver/source/device/vpu_device.hpp @@ -7,14 +7,12 @@ #pragma once -#include #include #include "vpu_driver/source/device/hw_info.hpp" #include "vpu_driver/source/device/metric_info.hpp" #include "vpu_driver/source/device/vpu_device_context.hpp" -#include #include #include #include @@ -23,8 +21,6 @@ namespace VPU { class OsInterface; class VPUDriverApi; -enum class EngineType { COMPUTE = 0, COPY, INVALID, ENGINE_MAX = INVALID }; - class VPUDevice { public: bool init(bool enableMetrics); @@ -37,15 +33,8 @@ class VPUDevice { bool getCapMetricStreamer() const; virtual std::unique_ptr createDeviceContext(); - size_t getNumberOfEngineGroups(void) const; - size_t getEngineMaxMemoryFillSize(); - EngineType getEngineType(uint32_t engGrpIdx); - EngineType getEngineTypeFromOrdinal(uint32_t engGrpOrdinal, bool &isCopyOnly); - bool engineSupportCompute(EngineType engineType) const; - bool engineSupportCopy(EngineType engineType) const { return true; } - bool engineSupportCooperativeKernel(EngineType engineType) const { return false; } - bool engineSupportMetrics(EngineType engineType) const { return false; } int getBDF(uint32_t *domain, uint32_t *bus, uint32_t *dev, uint32_t *func); + bool getActiveTime(uint64_t &activeTimeUs); /** * Return device's connection status. @@ -65,8 +54,6 @@ class VPUDevice { std::string devPath; OsInterface &osInfc; - static constexpr std::array engineGroups = {EngineType::COMPUTE, - EngineType::COPY}; }; } // namespace VPU diff --git a/umd/vpu_driver/source/os_interface/null_interface_imp.cpp b/umd/vpu_driver/source/os_interface/null_interface_imp.cpp index 628567d..1759f00 100644 --- a/umd/vpu_driver/source/os_interface/null_interface_imp.cpp +++ b/umd/vpu_driver/source/os_interface/null_interface_imp.cpp @@ -207,6 +207,10 @@ size_t NullOsInterfaceImp::osiGetSystemPageSize() { return 4096; } +std::string NullOsInterfaceImp::osiReadFile(const std::filesystem::path &path, size_t maxReadSize) { + return std::string(""); +} + void * NullOsInterfaceImp::osiMmap(void *addr, size_t size, int prot, int flags, int fd, off_t offset) { void *ptr; @@ -240,4 +244,7 @@ void NullOsInterfaceImp::osiScanDir(const std::filesystem::path &path, return; } +bool NullOsInterfaceImp::osiFileRemove(const std::filesystem::path &path) { + return true; +} } // namespace VPU diff --git a/umd/vpu_driver/source/os_interface/null_interface_imp.hpp b/umd/vpu_driver/source/os_interface/null_interface_imp.hpp index b2b0c6f..7e979c6 100644 --- a/umd/vpu_driver/source/os_interface/null_interface_imp.hpp +++ b/umd/vpu_driver/source/os_interface/null_interface_imp.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include struct drm_ivpu_param; @@ -32,17 +33,19 @@ class NullOsInterfaceImp : public OsInterface { int osiIoctl(int fd, unsigned long request, void *arg) override; size_t osiGetSystemPageSize() override; - void *osiMmap(void *addr, size_t size, int prot, int flags, int fd, off_t offset) override; int osiMunmap(void *addr, size_t size) override; + std::string osiReadFile(const std::filesystem::path &path, size_t maxReadSize = 255) override; bool osiCreateDirectories(const std::filesystem::path &path) override; + std::unique_ptr osiOpenWithExclusiveLock(const std::filesystem::path &path, bool writeAccess) override; std::unique_ptr osiOpenWithSharedLock(const std::filesystem::path &path, bool writeAccess) override; void osiScanDir(const std::filesystem::path &path, std::function f) override; + bool osiFileRemove(const std::filesystem::path &path) override; private: VPUHwInfo nullHwInfo; diff --git a/umd/vpu_driver/source/os_interface/os_interface.hpp b/umd/vpu_driver/source/os_interface/os_interface.hpp index 955dae1..d3e719f 100644 --- a/umd/vpu_driver/source/os_interface/os_interface.hpp +++ b/umd/vpu_driver/source/os_interface/os_interface.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include struct stat; @@ -20,9 +21,8 @@ class OsFile { public: virtual ~OsFile() = default; - virtual bool read(void *out, size_t size) = 0; virtual bool write(const void *in, size_t size) = 0; - virtual bool remove() = 0; + virtual void *mmap() = 0; virtual size_t size() = 0; }; @@ -40,6 +40,8 @@ class OsInterface { virtual void *osiMmap(void *addr, size_t size, int prot, int flags, int fd, off_t offset) = 0; virtual int osiMunmap(void *addr, size_t size) = 0; + virtual std::string osiReadFile(const std::filesystem::path &path, + size_t maxReadSize = 255) = 0; virtual bool osiCreateDirectories(const std::filesystem::path &path) = 0; virtual std::unique_ptr osiOpenWithExclusiveLock(const std::filesystem::path &path, bool writeAccess) = 0; @@ -47,6 +49,7 @@ class OsInterface { bool writeAccess) = 0; virtual void osiScanDir(const std::filesystem::path &path, std::function f) = 0; + virtual bool osiFileRemove(const std::filesystem::path &path) = 0; }; OsInterface &getOsInstance(); diff --git a/umd/vpu_driver/source/os_interface/os_interface_imp.cpp b/umd/vpu_driver/source/os_interface/os_interface_imp.cpp index 2b14ba3..e3ddb8b 100644 --- a/umd/vpu_driver/source/os_interface/os_interface_imp.cpp +++ b/umd/vpu_driver/source/os_interface/os_interface_imp.cpp @@ -76,6 +76,22 @@ size_t OsInterfaceImp::osiGetSystemPageSize() { return safe_cast(sysconf(_SC_PAGESIZE)); } +std::string OsInterfaceImp::osiReadFile(const std::filesystem::path &path, size_t maxReadSize) { + std::string out(maxReadSize + 1, 0); + int fd = ::open(path.c_str(), O_CLOEXEC, S_IRUSR | S_IRGRP); + if (fd == -1) { + LOG_E("Failed to open %s, errno: %u (%s)", path.c_str(), errno, strerror(errno)); + return ""; + } + off_t off = ::read(fd, out.data(), maxReadSize); + ::close(fd); + if (off == -1) { + LOG_E("Failed to read, errno: %u (%s)", errno, strerror(errno)); + return ""; + } + return out; +} + void *OsInterfaceImp::osiMmap(void *addr, size_t size, int prot, int flags, int fd, off_t offset) { return mmap(addr, size, prot, flags, fd, offset); } @@ -97,10 +113,19 @@ bool OsInterfaceImp::osiCreateDirectories(const std::filesystem::path &path) { return true; } +bool OsInterfaceImp::osiFileRemove(const std::filesystem::path &path) { + std::error_code ec; + if (!std::filesystem::remove(path, ec)) { + LOG_E("Failed to remove file, ec: %i (%s)", ec.value(), ec.message().c_str()); + return false; + } + return true; +} + class OsFileImp : public OsFile { public: OsFileImp(const std::filesystem::path &path, bool writeAccess) - : path(path) { + : writeAccess(writeAccess) { int flags = O_RDONLY; if (writeAccess) { flags = O_CREAT | O_RDWR; @@ -108,20 +133,30 @@ class OsFileImp : public OsFile { fd = ::open(path.c_str(), flags | O_CLOEXEC, S_IRUSR | S_IRGRP); if (fd == -1) { - LOG(FSYS, "Failed to open file, errno: %u (%s)", errno, strerror(errno)); + LOG(FSYS, + "Failed to open file %s, errno: %u (%s)", + path.c_str(), + errno, + strerror(errno)); return; } struct stat fstatInfo = {}; if (fstat(fd, &fstatInfo) != 0 || !S_ISREG(fstatInfo.st_mode)) { - LOG_E("Invalid file"); + LOG_E("Invalid file %s", path.c_str()); close(fd); fd = -1; return; } + + fileSize = safe_cast(fstatInfo.st_size); + LOG(FSYS, "OsFileImp - path: %p, fd: %i, fileSize: %lu", path.c_str(), fd, fileSize); } ~OsFileImp() override { + if (mmapPtr != MAP_FAILED) + ::munmap(mmapPtr, fileSize); + if (isOpen()) ::close(fd); } @@ -150,31 +185,6 @@ class OsFileImp : public OsFile { return false; } - bool read(void *out, size_t size) override { - if (out == nullptr || size == 0) { - LOG_E("Invalid pointer or size"); - return false; - } - - if (!setOffsetAtZero()) - return false; - - size_t at = 0; - while (at < size) { - off_t off = ::read(fd, static_cast(out) + at, size - at); - if (off == -1 || off == 0) { - LOG_E("Failed to read, errno: %u (%s)", errno, strerror(errno)); - return false; - } - - at += static_cast(off); - } - - if (at != size) - return false; - return true; - } - bool write(const void *in, size_t size) override { if (in == nullptr || size == 0) { LOG_E("Invalid pointer or size"); @@ -195,22 +205,34 @@ class OsFileImp : public OsFile { at += static_cast(off); } + fileSize = at; if (at != size) return false; return true; } - bool remove() override { - std::error_code ec; - std::filesystem::remove(path, ec); - if (ec) { - LOG_E("Failed to remove file, ec: %i (%s)", ec.value(), ec.message().c_str()); - return false; + void *mmap() override { + if (writeAccess) { + LOG(FSYS, "File %d cannot be mapped in write access", fd); + return nullptr; } - return true; + + if (mmapPtr != MAP_FAILED) { + LOG(FSYS, "File %d already mapped, mmapPtr: %p", fd, mmapPtr); + return mmapPtr; + } + + mmapPtr = ::mmap(NULL, fileSize, PROT_READ, MAP_SHARED, fd, 0); + if (mmapPtr == MAP_FAILED) { + LOG_E("Failed to map the file, errno: %u (%s)", errno, strerror(errno)); + return nullptr; + } + + LOG(FSYS, "File %d is mapped, mmapPtr: %p", fd, mmapPtr); + return mmapPtr; } - size_t size() override { return std::filesystem::file_size(path); } + size_t size() override { return fileSize; } private: bool setOffsetAtZero() { @@ -223,8 +245,10 @@ class OsFileImp : public OsFile { return true; } - std::filesystem::path path; + bool writeAccess; int fd; + void *mmapPtr = MAP_FAILED; + size_t fileSize = 0; }; std::unique_ptr OsInterfaceImp::osiOpenWithExclusiveLock(const std::filesystem::path &path, diff --git a/umd/vpu_driver/source/os_interface/os_interface_imp.hpp b/umd/vpu_driver/source/os_interface/os_interface_imp.hpp index 01022b3..c2afc1b 100644 --- a/umd/vpu_driver/source/os_interface/os_interface_imp.hpp +++ b/umd/vpu_driver/source/os_interface/os_interface_imp.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace VPU { @@ -33,6 +34,7 @@ class OsInterfaceImp : public OsInterface { void *osiMmap(void *addr, size_t size, int prot, int flags, int fd, off_t offset) override; int osiMunmap(void *addr, size_t size) override; + std::string osiReadFile(const std::filesystem::path &path, size_t maxReadSize = 255) override; bool osiCreateDirectories(const std::filesystem::path &path) override; std::unique_ptr osiOpenWithExclusiveLock(const std::filesystem::path &path, bool writeAccess) override; @@ -42,6 +44,8 @@ class OsInterfaceImp : public OsInterface { void osiScanDir(const std::filesystem::path &path, std::function f) override; + + bool osiFileRemove(const std::filesystem::path &path) override; }; } // namespace VPU diff --git a/umd/vpu_driver/source/os_interface/vpu_driver_api.cpp b/umd/vpu_driver/source/os_interface/vpu_driver_api.cpp index be309c9..8a02c64 100644 --- a/umd/vpu_driver/source/os_interface/vpu_driver_api.cpp +++ b/umd/vpu_driver/source/os_interface/vpu_driver_api.cpp @@ -369,4 +369,9 @@ std::string VPUDriverApi::getDeviceLink() { return {devLink}; } +std::string VPUDriverApi::getSysDeviceAbsolutePath() { + std::string path("/sys/dev/char/"); + return path + getDeviceLink() + "/../../"; +} + } // namespace VPU diff --git a/umd/vpu_driver/source/os_interface/vpu_driver_api.hpp b/umd/vpu_driver/source/os_interface/vpu_driver_api.hpp index 9c82630..db0ae4e 100644 --- a/umd/vpu_driver/source/os_interface/vpu_driver_api.hpp +++ b/umd/vpu_driver/source/os_interface/vpu_driver_api.hpp @@ -46,6 +46,7 @@ class VPUDriverApi final { bool checkPrimeBuffersCapability() const; size_t getPageSize() const; std::string getDeviceLink(); + std::string getSysDeviceAbsolutePath(); int wait(void *args) const; int closeBuffer(uint32_t handle) const; diff --git a/umd/vpu_driver/unit_tests/job_submission/CMakeLists.txt b/umd/vpu_driver/unit_tests/job_submission/CMakeLists.txt index 0bcb94b..b2d449e 100644 --- a/umd/vpu_driver/unit_tests/job_submission/CMakeLists.txt +++ b/umd/vpu_driver/unit_tests/job_submission/CMakeLists.txt @@ -7,7 +7,6 @@ target_sources( ${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/command_buffer_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/engine_group_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/job_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/vpu_command_test.cpp) diff --git a/umd/vpu_driver/unit_tests/job_submission/engine_group_test.cpp b/umd/vpu_driver/unit_tests/job_submission/engine_group_test.cpp deleted file mode 100644 index 45cfba6..0000000 --- a/umd/vpu_driver/unit_tests/job_submission/engine_group_test.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include - -#include "gtest/gtest.h" -#include "vpu_driver/source/device/vpu_device.hpp" -#include "vpu_driver/unit_tests/mocks/mock_os_interface_imp.hpp" -#include "vpu_driver/unit_tests/mocks/mock_vpu_device.hpp" - -#include -#include - -using namespace VPU; - -struct EngineGroupTest : public ::testing::Test { - void SetUp() { EXPECT_EQ(2u, vpuDevice->getNumberOfEngineGroups()); } - - MockOsInterfaceImp osInfc; - std::unique_ptr vpuDevice = - std::make_unique(FAKE_TEST_DEV_NODE, osInfc); -}; - -/* - * L0 specification defines engine groups' capabilities in ze_command_queue_group_property_flag_t - * - * ///< Command queue group supports enqueing compute commands. - * ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE - * ///< Command queue group supports enqueing copy commands. - * ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY - * ///< Command queue group supports cooperative kernels. - * ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS - * ///< Command queue groups supports metric streamers and queries. - * ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_METRICS - */ -TEST_F(EngineGroupTest, engineGroupsHoldsCapabilities) { - auto nnEngType = vpuDevice->getEngineType(0u); - EXPECT_EQ(nnEngType, EngineType::COMPUTE); - EXPECT_TRUE(vpuDevice->engineSupportCompute(nnEngType)); - EXPECT_TRUE(vpuDevice->engineSupportCopy(nnEngType)); - EXPECT_FALSE(vpuDevice->engineSupportCooperativeKernel(nnEngType)); - EXPECT_FALSE(vpuDevice->engineSupportMetrics(nnEngType)); - - auto copyEngType = vpuDevice->getEngineType(1u); - EXPECT_FALSE(vpuDevice->engineSupportCompute(copyEngType)); - EXPECT_TRUE(vpuDevice->engineSupportCopy(copyEngType)); - EXPECT_FALSE(vpuDevice->engineSupportCooperativeKernel(copyEngType)); - EXPECT_FALSE(vpuDevice->engineSupportMetrics(copyEngType)); -} - -TEST_F(EngineGroupTest, engineGroupsMaxMemFillSizeCheck) { - EXPECT_EQ(sizeof(uint32_t), vpuDevice->getEngineMaxMemoryFillSize()); -} diff --git a/umd/vpu_driver/unit_tests/mocks/gmock_os_interface_imp.hpp b/umd/vpu_driver/unit_tests/mocks/gmock_os_interface_imp.hpp index 3a2c543..cffded4 100644 --- a/umd/vpu_driver/unit_tests/mocks/gmock_os_interface_imp.hpp +++ b/umd/vpu_driver/unit_tests/mocks/gmock_os_interface_imp.hpp @@ -13,7 +13,13 @@ namespace VPU { -// A GMock OS interface implementation. +class GMockOsFileImp : public OsFile { + public: + MOCK_METHOD(bool, write, (const void *, size_t), (override)); + MOCK_METHOD(void *, mmap, (), (override)); + MOCK_METHOD(size_t, size, (), (override)); +}; + class GMockOsInterfaceImp : public OsInterface { public: MOCK_METHOD(int, osiOpen, (const char *, int, mode_t), (override)); @@ -23,6 +29,7 @@ class GMockOsInterfaceImp : public OsInterface { MOCK_METHOD(size_t, osiGetSystemPageSize, (), (override)); MOCK_METHOD(void *, osiMmap, (void *, size_t, int, int, int, off_t), (override)); MOCK_METHOD(int, osiMunmap, (void *, size_t), (override)); + MOCK_METHOD(std::string, osiReadFile, (const std::filesystem::path &, size_t), (override)); MOCK_METHOD(bool, osiCreateDirectories, (const std::filesystem::path &), (override)); MOCK_METHOD(std::unique_ptr, osiOpenWithExclusiveLock, @@ -36,6 +43,7 @@ class GMockOsInterfaceImp : public OsInterface { osiScanDir, (const std::filesystem::path &, std::function), (override)); + MOCK_METHOD(bool, osiFileRemove, (const std::filesystem::path &), (override)); }; } // namespace VPU diff --git a/umd/vpu_driver/unit_tests/mocks/mock_os_interface_imp.cpp b/umd/vpu_driver/unit_tests/mocks/mock_os_interface_imp.cpp index 2723aaa..7e2b371 100644 --- a/umd/vpu_driver/unit_tests/mocks/mock_os_interface_imp.cpp +++ b/umd/vpu_driver/unit_tests/mocks/mock_os_interface_imp.cpp @@ -238,6 +238,10 @@ int MockOsInterfaceImp::osiMunmap(void *addr, size_t size) { return 0; } +std::string MockOsInterfaceImp::osiReadFile(const std::filesystem::path &path, size_t maxReadSize) { + return std::string(""); +} + bool MockOsInterfaceImp::osiCreateDirectories(const std::filesystem::path &path) { return true; } @@ -255,6 +259,10 @@ std::unique_ptr MockOsInterfaceImp::osiOpenWithSharedLock(const std::fil void MockOsInterfaceImp::osiScanDir(const std::filesystem::path &path, std::function f) {} +bool MockOsInterfaceImp::osiFileRemove(const std::filesystem::path &path) { + return false; +} + size_t MockOsInterfaceImp::osiGetSystemPageSize() { return 4u * 1024u; } diff --git a/umd/vpu_driver/unit_tests/mocks/mock_os_interface_imp.hpp b/umd/vpu_driver/unit_tests/mocks/mock_os_interface_imp.hpp index da39369..f8168c5 100644 --- a/umd/vpu_driver/unit_tests/mocks/mock_os_interface_imp.hpp +++ b/umd/vpu_driver/unit_tests/mocks/mock_os_interface_imp.hpp @@ -64,13 +64,16 @@ class MockOsInterfaceImp : public OsInterface { void *osiMmap(void *addr, size_t size, int prot, int flags, int fd, off_t offset) override; int osiMunmap(void *addr, size_t size) override; + std::string osiReadFile(const std::filesystem::path &path, size_t maxReadSize = 255) override; bool osiCreateDirectories(const std::filesystem::path &path) override; + std::unique_ptr osiOpenWithExclusiveLock(const std::filesystem::path &path, bool writeAccess) override; std::unique_ptr osiOpenWithSharedLock(const std::filesystem::path &path, bool writeAccess) override; void osiScanDir(const std::filesystem::path &path, std::function f) override; + bool osiFileRemove(const std::filesystem::path &path) override; void mockFailNextAlloc(); // Fails next call to osiMmap void mockFailNextJobWait(); diff --git a/validation/kmd-test/kmd_test.cpp b/validation/kmd-test/kmd_test.cpp index 1053f63..568ca96 100644 --- a/validation/kmd-test/kmd_test.cpp +++ b/validation/kmd-test/kmd_test.cpp @@ -379,7 +379,7 @@ bool KmdTest::resume() { int ret; /* Always send HB so to update autosuspend timeout */ - ret = get_param(DRM_IVPU_PARAM_ENGINE_HEARTBEAT, &hb, ENGINE_COPY); + ret = get_param(DRM_IVPU_PARAM_ENGINE_HEARTBEAT, &hb, ENGINE_COMPUTE); if (ret) { ADD_FAILURE() << "Failed to send IOCTL Heartbeat: " << ret << "\n"; return false; @@ -941,6 +941,7 @@ void CmdBuffer::add_copy_cmd(MemoryBuffer &desc_buf, size_t length, uint16_t copy_cmd) { auto cmd = add_cmd(copy_cmd); + ASSERT_TRUE(cmd); cmd->desc_start_offset = desc_buf.vpu_addr() + desc_start_offset; cmd->desc_count = 1; diff --git a/validation/kmd-test/kmd_test.h b/validation/kmd-test/kmd_test.h index e011500..247fc7b 100644 --- a/validation/kmd-test/kmd_test.h +++ b/validation/kmd-test/kmd_test.h @@ -7,26 +7,27 @@ #pragma once +#include + +#include "api/vpu_jsm_job_cmd_api.h" +#include "drm/ivpu_accel.h" +#include "drm_helpers.h" +#include "file_helper.h" +#include "linux/dma-heap.h" +#include "perf_counter.h" +#include "test_app.h" + #include +#include +#include +#include #include #include #include -#include #include #include -#include #include -#include -#include -#include - -#include "drm_helpers.h" -#include "file_helper.h" -#include "api/vpu_jsm_job_cmd_api.h" -#include "test_app.h" -#include "perf_counter.h" -#include "drm/ivpu_accel.h" -#include "linux/dma-heap.h" +#include #define SKIP_(msg) \ if (!test_app::run_skipped_tests) \ @@ -80,10 +81,6 @@ if (!dma_heap_is_available()) \ SKIP_("DMA heaps are not available") -#define SKIP_PATCHSET() \ - if (api_version_lt(1, 3)) \ - SKIP_("Not supported by the upstream driver") - #define EXPECT_BYTE_ARR_EQ(arr, size, value) EXPECT_PRED3(byte_array_eq, arr, size, value) #define ALIGN(s, alignment) __ALIGN_KERNEL((s), (alignment)) @@ -505,8 +502,8 @@ struct CmdBuffer : MemoryBuffer { MemoryBuffer &dst_buf, uint32_t dst_offset, size_t length, - uint16_t copy_cmd); - int submit(int engine, int priority = 0, uint32_t timeout_ms = 0); + uint16_t copy_cmd = VPU_CMD_COPY_LOCAL_TO_LOCAL); + int submit(int engine = ENGINE_COMPUTE, int priority = 0, uint32_t timeout_ms = 0); void prepare_bb_hdr(void); void prepare_params(int engine, int priority, drm_ivpu_submit *params); int wait(uint32_t timeout_ms = JOB_SYNC_TIMEOUT_MS); @@ -546,7 +543,8 @@ struct DmaBuffer { size_t size() { return _size; } size_t buffer_fd() { return _dmabuf_fd; } - void *buffer_ptr() { return _buf_ptr; } + void *buffer_ptr(int offset = 0) { return ((uint8_t *)_buf_ptr + offset); } + uint64_t *buffer_ptr64(int offset = 0) { return (uint64_t *)buffer_ptr(offset); } }; bool byte_array_eq(uint8_t *arr, size_t size, uint8_t value); diff --git a/validation/kmd-test/test_copy.cpp b/validation/kmd-test/test_copy.cpp index 5371d5b..e2c9cdd 100644 --- a/validation/kmd-test/test_copy.cpp +++ b/validation/kmd-test/test_copy.cpp @@ -355,7 +355,3 @@ void Copy::CopyDuringCtxCreation(int engine) { TEST_F(Copy, CopyDuringCtxCreationComputeEngine) { CopyDuringCtxCreation(ENGINE_COMPUTE); } - -TEST_F(Copy, CopyDuringCtxCreationCopyEngine) { - CopyDuringCtxCreation(ENGINE_COPY); -} diff --git a/validation/kmd-test/test_device.cpp b/validation/kmd-test/test_device.cpp index 3d99e77..972570e 100644 --- a/validation/kmd-test/test_device.cpp +++ b/validation/kmd-test/test_device.cpp @@ -48,7 +48,7 @@ TEST_F(Device, GroupOwnership) { struct stat fileInfo; std::string expectedGroupName; if (isChromeOs()) { - expectedGroupName = "video"; + expectedGroupName = "ml-core"; } else { expectedGroupName = "render"; } @@ -110,21 +110,6 @@ TEST_F(Device, GetDeviceParams) { EXPECT_EQ(get_param(DRM_IVPU_PARAM_FW_API_VERSION, &value), 0); } -TEST_F(Device, ResetComputeEngine) { - bool hws = is_hws_enabled(); - SKIP_NO_DEBUGFS("reset_engine"); - - if (hws) { - SKIP_NO_DEBUGFS("resume_engine"); - } - - ASSERT_EQ(write_debugfs_file("reset_engine", ENGINE_COMPUTE), 0); - - if (hws) { - ASSERT_EQ(write_debugfs_file("resume_engine", ENGINE_COMPUTE), 0); - } -} - TEST_F(Device, Heartbeat_ComputeEngine) { uint64_t hb; @@ -135,15 +120,20 @@ TEST_F(Device, Heartbeat_ComputeEngine) { void Device::Heartbeat(int thread_id) { PerfCounter counter; uint64_t hb; - int engine = thread_id % 2; + int engine = ENGINE_COMPUTE; + int ret; // First get_param() can be slow as it may nee to wait for VPU boot - ASSERT_EQ(get_param(DRM_IVPU_PARAM_ENGINE_HEARTBEAT, &hb, engine), 0); + EXPECT_EQ(ret = get_param(DRM_IVPU_PARAM_ENGINE_HEARTBEAT, &hb, engine), 0); + if (ret) + return; counter.setTimeout(is_silicon() ? 100 : 10); counter.start(); do { - ASSERT_EQ(get_param(DRM_IVPU_PARAM_ENGINE_HEARTBEAT, &hb, engine), 0); + EXPECT_EQ(ret = get_param(DRM_IVPU_PARAM_ENGINE_HEARTBEAT, &hb, engine), 0); + if (ret) + break; counter.countFrame(); } while (!counter.isTimedOut()); counter.stop(); diff --git a/validation/kmd-test/test_exec.cpp b/validation/kmd-test/test_exec.cpp index 8066358..9453f72 100644 --- a/validation/kmd-test/test_exec.cpp +++ b/validation/kmd-test/test_exec.cpp @@ -118,20 +118,17 @@ void Exec::JobSubmitWithoutWait(int engine) { ASSERT_EQ(cmd_buf.create(), 0); cmd_buf.add_fence_wait_cmd(cmd_buf, 1024); - ASSERT_EQ(cmd_buf.submit(engine), 0); + ASSERT_EQ(cmd_buf.submit(engine, DRM_IVPU_JOB_PRIORITY_NORMAL), 0); cmd_buf.start(2048); cmd_buf.add_fence_signal_cmd(cmd_buf, 2048 + 1024); - ASSERT_EQ(cmd_buf.submit(engine), EBUSY); + ASSERT_EQ(cmd_buf.submit(engine, DRM_IVPU_JOB_PRIORITY_IDLE), EBUSY); CmdBuffer signal_buf(context, 4096); ASSERT_EQ(signal_buf.create(), 0); signal_buf.add_fence_signal_cmd(cmd_buf, 1024); - if (engine == ENGINE_COPY) - ASSERT_EQ(signal_buf.submit(ENGINE_COMPUTE), 0); - else - ASSERT_EQ(signal_buf.submit(ENGINE_COPY), 0); + ASSERT_EQ(signal_buf.submit(engine, DRM_IVPU_JOB_PRIORITY_REALTIME), 0); ASSERT_EQ(signal_buf.wait(), 0); ASSERT_EQ(cmd_buf.wait(), 0); diff --git a/validation/test-app-lib/test_app.cpp b/validation/test-app-lib/test_app.cpp index 360eb78..d8816f5 100644 --- a/validation/test-app-lib/test_app.cpp +++ b/validation/test-app-lib/test_app.cpp @@ -194,6 +194,14 @@ void parse_args(std::unordered_map &extArgs, } } +void append_positive_filter(const std::string &pattern) { + auto &filter = ::testing::GTEST_FLAG(filter); + if (filter == "*") + filter = pattern; + else + filter = pattern + ":" + filter; +} + void append_negative_filter(const char *negative_pattern) { std::string &filter = ::testing::GTEST_FLAG(filter); diff --git a/validation/test-app-lib/test_app.h b/validation/test-app-lib/test_app.h index b24c7ec..9554ea7 100644 --- a/validation/test-app-lib/test_app.h +++ b/validation/test-app-lib/test_app.h @@ -55,6 +55,7 @@ struct Argument { using ArgumentMap = std::unordered_map; void parse_args(ArgumentMap &extArgs, const char *extHelpMsg, int argc, char **argv); +void append_positive_filter(const std::string &pattern); void append_negative_filter(const char *negative_pattern); int run(); diff --git a/validation/umd-test/CMakeLists.txt b/validation/umd-test/CMakeLists.txt index 7cc1ec4..983e372 100644 --- a/validation/umd-test/CMakeLists.txt +++ b/validation/umd-test/CMakeLists.txt @@ -21,6 +21,8 @@ add_executable(${PROJECT_NAME} model_params.cpp main.cpp umd_test.cpp + test_buffers_export.cpp + test_buffers_import.cpp test_buffers_export_gpu.cpp test_commands.cpp test_context.cpp @@ -35,12 +37,12 @@ add_executable(${PROJECT_NAME} test_graph_cid.cpp test_graph_commands.cpp test_graph_inference.cpp + test_graph_query.cpp test_immediate_cmdlist.cpp test_inference_performance.cpp test_memory.cpp test_metric.cpp test_metric_streamer.cpp - test_prime_buffers.cpp test_priority.cpp ) diff --git a/validation/umd-test/blob_params.cpp b/validation/umd-test/blob_params.cpp index 3e7e532..93e0466 100644 --- a/validation/umd-test/blob_params.cpp +++ b/validation/umd-test/blob_params.cpp @@ -13,21 +13,14 @@ #include -bool loadBlobDataFromNode(std::string blobPath, +bool loadBlobDataFromNode(const std::string &blobPath, std::vector inputFiles, std::vector outputFiles, - std::vector &npuBlob, std::vector> &inputBin, std::vector> &outputBin) { std::filesystem::path blobFile(blobPath); std::filesystem::path dataDir = blobFile.parent_path(); - TRACE("Blob: %s\n", blobFile.c_str()); - if (DataHandle::loadFile(blobFile, npuBlob) != 0) { - PRINTF("Failed to load blob from %s\n", blobFile.c_str()); - return false; - } - inputBin.resize(inputFiles.size()); for (size_t i = 0; i < inputBin.size(); i++) { auto inputPath = dataDir / inputFiles[i]; @@ -51,7 +44,7 @@ bool loadBlobDataFromNode(std::string blobPath, return true; } -bool loadBlobFromPath(std::string blobPath, std::vector &npuBlob) { +bool loadBlobFromPath(const std::string &blobPath, std::vector &npuBlob) { std::filesystem::path blobFile(blobPath); TRACE("Blob: %s\n", blobFile.c_str()); diff --git a/validation/umd-test/blob_params.hpp b/validation/umd-test/blob_params.hpp index 12f575a..e2ed337 100644 --- a/validation/umd-test/blob_params.hpp +++ b/validation/umd-test/blob_params.hpp @@ -16,11 +16,10 @@ #include #include -bool loadBlobDataFromNode(std::string blobPath, +bool loadBlobDataFromNode(const std::string &blobPath, std::vector inputFiles, std::vector outputFiles, - std::vector &npuBlob, std::vector> &inputBin, std::vector> &outputBin); -bool loadBlobFromPath(std::string blobPath, std::vector &npuBlob); +bool loadBlobFromPath(const std::string &blobPath, std::vector &npuBlob); diff --git a/validation/umd-test/graph_utilities.hpp b/validation/umd-test/graph_utilities.hpp index 94be696..e261f77 100644 --- a/validation/umd-test/graph_utilities.hpp +++ b/validation/umd-test/graph_utilities.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -83,21 +84,172 @@ class InferenceRequest { zeScope::SharedPtr scopedList; }; +class GraphBuffer { + public: + static std::shared_ptr get(ze_device_handle_t hDevice, + graph_dditable_ext_t *graphDdi, + UmdTest::GlobalConfig &globalConfig, + const YAML::Node &node) { + auto graphBuffer = std::make_shared(); + if (!graphBuffer->loadFromNode(hDevice, graphDdi, globalConfig, node)) { + return nullptr; + } + + return graphBuffer; + } + + static std::shared_ptr get(ze_device_handle_t hDevice, + graph_dditable_ext_t *graphDdi, + const std::filesystem::path &path, + const std::string &buildFlags) { + auto graphBuffer = std::make_shared(); + if (!graphBuffer->loadFromPath(hDevice, graphDdi, path, buildFlags)) { + return nullptr; + } + + return graphBuffer; + } + + GraphBuffer() = default; + GraphBuffer(std::vector &&buf) + : buffer(std::move(buf)) { + desc.stype = ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES; + desc.format = ZE_GRAPH_FORMAT_NATIVE; + desc.inputSize = buffer.size(); + desc.pInput = reinterpret_cast(buffer.data()); + desc.pBuildFlags = nullptr; + desc.flags = ZE_GRAPH_FLAG_NONE; + } + + private: + bool loadFromNode(ze_device_handle_t hDevice, + graph_dditable_ext_t *graphDdi, + UmdTest::GlobalConfig &globalconfig, + const YAML::Node &node) { + std::filesystem::path path = node["path"].as(); + std::string buildFlags = ""; + if (node["flags"].IsDefined()) { + buildFlags = node["flags"].as(); + } + + if (path.extension() == ".xml") { + path = globalconfig.modelDir / path; + } else { + path = globalconfig.blobDir / path; + } + + return loadFromPath(hDevice, graphDdi, path, buildFlags); + } + + bool loadFromPath(ze_device_handle_t hDevice, + graph_dditable_ext_t *graphDdi, + const std::filesystem::path &path_, + const std::string &buildFlags_) { + path = path_; + buildFlags = buildFlags_; + + if (path.extension() == ".xml") { + desc.format = ZE_GRAPH_FORMAT_NGRAPH_LITE; + desc.pBuildFlags = buildFlags.c_str(); + loadNGraphModel(hDevice, graphDdi); + } else { + desc.format = ZE_GRAPH_FORMAT_NATIVE; + desc.pBuildFlags = nullptr; + loadBlobFromPath(path, buffer); + } + + desc.stype = ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES; + desc.flags = ZE_GRAPH_FLAG_NONE; + desc.inputSize = buffer.size(); + desc.pInput = reinterpret_cast(buffer.data()); + return true; + } + + void loadNGraphModel(ze_device_handle_t hDevice, graph_dditable_ext_t *graphDdi) { + std::vector bufferXml, bufferBin; + ze_device_graph_properties_t deviceGraphProp; + + ASSERT_TRUE(getModelFromPath(path, bufferXml, bufferBin)); + ASSERT_EQ(graphDdi->pfnDeviceGetGraphProperties(hDevice, &deviceGraphProp), + ZE_RESULT_SUCCESS); + + ze_graph_compiler_version_info_t version = {.major = deviceGraphProp.compilerVersion.major, + .minor = deviceGraphProp.compilerVersion.minor}; + + uint64_t sizeXml = bufferXml.size(); + uint64_t sizeBin = bufferBin.size(); + uint32_t numInputs = 2; + uint64_t modelSize = sizeof(version) + sizeof(numInputs) + sizeof(sizeXml) + sizeXml + + sizeof(sizeBin) + sizeBin; + + buffer.resize(modelSize); + + uint64_t offset = 0; + memcpy(&buffer[0], &version, sizeof(version)); + offset += sizeof(version); + + memcpy(&buffer[offset], &numInputs, sizeof(numInputs)); + offset += sizeof(numInputs); + + memcpy(&buffer[offset], &sizeXml, sizeof(sizeXml)); + offset += sizeof(sizeXml); + + memcpy(&buffer[offset], bufferXml.data(), sizeXml); + offset += sizeXml; + + memcpy(&buffer[offset], &sizeBin, sizeof(sizeBin)); + offset += sizeof(sizeBin); + + memcpy(&buffer[offset], bufferBin.data(), sizeBin); + } + + public: + std::filesystem::path path; + ze_graph_desc_2_t desc = {}; + + private: + std::vector buffer = {}; + std::string buildFlags = {}; +}; + class Graph { public: - Graph(ze_context_handle_t hContext, ze_device_handle_t hDevice, graph_dditable_ext_t *graphDDI) + Graph(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + graph_dditable_ext_t *graphDDI, + std::shared_ptr buffer) : hContext(hContext) , hDevice(hDevice) - , graphDDI(graphDDI) {} + , graphDDI(graphDDI) + , buffer(std::move(buffer)) {} + + static std::shared_ptr create(ze_context_handle_t hContext, + ze_device_handle_t hDevice, + graph_dditable_ext_t *graphDDI, + std::shared_ptr graphBuffer) { + if (graphBuffer == nullptr) + return nullptr; + + auto graph = std::make_shared(hContext, hDevice, graphDDI, std::move(graphBuffer)); + if (!graph->createGraphHandle()) + return nullptr; + + graph->inputType = RANDOM; + return graph; + } static std::shared_ptr create(ze_context_handle_t hContext, ze_device_handle_t hDevice, graph_dditable_ext_t *graphDDI, const std::filesystem::path &path, - const std::string &buildFlags, - uint32_t graphFlags = ZE_GRAPH_FLAG_NONE) { - auto graph = std::make_shared(hContext, hDevice, graphDDI); - graph->createFromModel(path, buildFlags, graphFlags); + const std::string &buildFlags) { + auto buffer = GraphBuffer::get(hDevice, graphDDI, path, buildFlags); + if (buffer == nullptr) + return nullptr; + + auto graph = std::make_shared(hContext, hDevice, graphDDI, std::move(buffer)); + if (!graph->createGraphHandle()) + return nullptr; return graph; } @@ -108,32 +260,17 @@ class Graph { UmdTest::GlobalConfig &globalConfig, const YAML::Node &node, uint32_t graphFlags = ZE_GRAPH_FLAG_NONE) { - auto graph = std::make_shared(hContext, hDevice, graphDDI); - - EXPECT_GT(node["path"].as().size(), 0); - std::filesystem::path path = node["path"].as(); - - if (path.extension() == ".xml") { - auto buildFlags = node["flags"].as(); - graph->createFromModel(std::move(globalConfig.modelDir / path), buildFlags, graphFlags); + auto buffer = GraphBuffer::get(hDevice, graphDDI, globalConfig, node); + if (buffer == nullptr) + return nullptr; - if (node["in"].IsDefined() && node["class_index"].IsDefined()) { - graph->inputType = InputType::IMAGE; - for (auto &image : node["in"].as>()) { - std::filesystem::path imagePath = globalConfig.imageDir + image; - if (std::filesystem::exists(imagePath)) { - EXPECT_EQ(imagePath.extension(), ".bmp"); - graph->images.push_back(imagePath); - } - } + buffer->desc.flags = graphFlags; - graph->classIndexes = node["class_index"].as>(); - } - } else { - graph->format = GraphFormat::BLOB; - graph->createFromBlob(std::move(globalConfig.blobDir / path), node, graph->npuBlob); - } + auto graph = std::make_shared(hContext, hDevice, graphDDI, std::move(buffer)); + if (!graph->createGraphHandle()) + return nullptr; + graph->loadArguments(globalConfig, node); return graph; } @@ -345,7 +482,55 @@ class Graph { void deallocateAllArguments() { mem.clear(); } + std::shared_ptr getNativeBinaryAsNewBuffer() { + size_t size; + if (graphDDI->pfnGetNativeBinary(handle, &size, nullptr) != ZE_RESULT_SUCCESS) + return nullptr; + + std::vector buffer(size); + if (graphDDI->pfnGetNativeBinary(handle, + &size, + reinterpret_cast(buffer.data())) != + ZE_RESULT_SUCCESS) + return nullptr; + + return std::make_shared(std::move(buffer)); + } + private: + bool createGraphHandle() { + ze_result_t ret = ZE_RESULT_SUCCESS; + scopedGraphHandle = zeScope::graphCreate2(graphDDI, hContext, hDevice, buffer->desc, ret); + if (ret != ZE_RESULT_SUCCESS) + return false; + + handle = scopedGraphHandle.get(); + queryArguments(); + format = buffer->desc.format == ZE_GRAPH_FORMAT_NGRAPH_LITE ? GraphFormat::MODEL + : GraphFormat::BLOB; + return true; + } + + void loadArguments(UmdTest::GlobalConfig &globalConfig, const YAML::Node &node) { + if (format == GraphFormat::MODEL) { + if (node["in"].IsDefined() && node["class_index"].IsDefined()) { + inputType = InputType::IMAGE; + for (auto &image : node["in"].as>()) { + std::filesystem::path imagePath = globalConfig.imageDir + image; + if (std::filesystem::exists(imagePath)) { + EXPECT_EQ(imagePath.extension(), ".bmp"); + images.push_back(imagePath); + } + } + + classIndexes = node["class_index"].as>(); + } + } else { + format = GraphFormat::BLOB; + loadBlobArgumentsFromFilesystem(node); + } + } + void queryArguments() { getArgumentsProperties(); ASSERT_NE(inputSize.size(), 0); @@ -378,111 +563,16 @@ class Graph { } } - std::vector getFlagsFromString(std::string flags) { - std::vector buildFlags; - - for (auto c : flags) - buildFlags.push_back(c); - buildFlags.push_back('\0'); - return buildFlags; - } - - void createGraphDescriptorForModel(const std::string &modelPath, - const char *buildFlags, - uint32_t graphFlags) { - std::vector modelXml, modelBin; - ze_device_graph_properties_t graphProperties; - - ASSERT_TRUE(getModelFromPath(modelPath, modelXml, modelBin)); - - ASSERT_EQ(graphDDI->pfnDeviceGetGraphProperties(hDevice, &graphProperties), - ZE_RESULT_SUCCESS); - - ze_graph_compiler_version_info_t version = {.major = graphProperties.compilerVersion.major, - .minor = graphProperties.compilerVersion.minor}; - - uint64_t xml_len = modelXml.size(); - uint64_t bin_len = modelBin.size(); - uint32_t numInputs = 2; - uint64_t modelSize = sizeof(version) + sizeof(numInputs) + sizeof(xml_len) + xml_len + - sizeof(bin_len) + bin_len; - - modelIR.resize(modelSize); - - uint64_t offset = 0; - memcpy(&modelIR[0], &version, sizeof(version)); - offset += sizeof(version); - - memcpy(&modelIR[offset], &numInputs, sizeof(numInputs)); - offset += sizeof(numInputs); - - memcpy(&modelIR[offset], &xml_len, sizeof(xml_len)); - offset += sizeof(xml_len); - - memcpy(&modelIR[offset], modelXml.data(), xml_len); - offset += xml_len; - - memcpy(&modelIR[offset], &bin_len, sizeof(bin_len)); - offset += sizeof(bin_len); - - memcpy(&modelIR[offset], modelBin.data(), bin_len); - - desc.stype = ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES; - desc.pNext = nullptr; - desc.format = ZE_GRAPH_FORMAT_NGRAPH_LITE; - desc.inputSize = modelIR.size(); - desc.pInput = modelIR.data(); - desc.pBuildFlags = buildFlags; - desc.flags = graphFlags; - } - - void createFromModel(std::string &&path, const std::string &flags, uint32_t graphFlags) { - ASSERT_GT(flags.size(), 0); - - ze_result_t ret = ZE_RESULT_SUCCESS; - - buildFlags = getFlagsFromString(flags); - TRACE("buildFlags: %s\n", std::string(buildFlags.begin(), buildFlags.end()).c_str()); - - createGraphDescriptorForModel(path, buildFlags.data(), graphFlags); - - scopedGraphHandle = zeScope::graphCreate2(graphDDI, hContext, hDevice, desc, ret); - EXPECT_EQ(ret, ZE_RESULT_SUCCESS); - - handle = scopedGraphHandle.get(); - - queryArguments(); - } - - void createFromBlob(std::string &&path, const YAML::Node &node, std::vector &npuBlob) { - ze_result_t ret = ZE_RESULT_SUCCESS; - + void loadBlobArgumentsFromFilesystem(const YAML::Node &node) { if (node["in"].IsDefined() && node["out"].IsDefined()) { - ASSERT_TRUE(loadBlobDataFromNode(std::move(path), + ASSERT_TRUE(loadBlobDataFromNode(buffer->path, node["in"].as>(), node["out"].as>(), - npuBlob, inputBin, outputBin)); } else { - ASSERT_TRUE(loadBlobFromPath(std::move(path), npuBlob)); inputType = InputType::RANDOM; } - - desc = {.stype = ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES, - .pNext = nullptr, - .format = ZE_GRAPH_FORMAT_NATIVE, - .inputSize = npuBlob.size(), - .pInput = reinterpret_cast(npuBlob.data()), - .pBuildFlags = nullptr, - .flags = ZE_GRAPH_FLAG_NONE}; - - scopedGraphHandle = zeScope::graphCreate2(graphDDI, hContext, hDevice, desc, ret); - EXPECT_EQ(ret, ZE_RESULT_SUCCESS); - - handle = scopedGraphHandle.get(); - - queryArguments(); } public: @@ -494,8 +584,6 @@ class Graph { InputType inputType = InputType::BINARY; std::vector> inputBin, outputBin; - std::vector npuBlob; - std::vector images; std::vector classIndexes; uint32_t iterations = 1; @@ -509,11 +597,7 @@ class Graph { std::vector inArgs, outArgs; private: - ze_graph_desc_2_t desc = {}; - std::vector buildFlags = {}; - std::vector modelIR = {}; - + std::shared_ptr buffer; std::vector> mem; - zeScope::SharedPtr scopedGraphHandle = nullptr; }; diff --git a/validation/umd-test/main.cpp b/validation/umd-test/main.cpp index 6306e0a..3c3a449 100644 --- a/validation/umd-test/main.cpp +++ b/validation/umd-test/main.cpp @@ -7,11 +7,13 @@ #include "umd_test.h" +#include #include namespace test_vars { bool test_with_gpu; bool disable_metrics; +bool forceDmaHeap; } // namespace test_vars static void setConfig(const char *optarg) { @@ -21,25 +23,31 @@ static void setConfig(const char *optarg) { } } -static void setQuickFilter(const char *) { - test_app::append_negative_filter("CommandBarrier.*:CommandGraphLong*:" - "*GraphInference*:CompilerInDriverLong*:" - "CompilerInDriverWithProfiling*:CompilerInDriverLayers*"); -} - static void disableMetrics(const char *) { test_vars::disable_metrics = true; test_app::append_negative_filter("Metric*:ImmediateCmdList.MetricQuerryTest"); } -const char *helpMsg = " -q/--quick\n" - " Disable long running tests. Useful for pre-commit testing\n" - " -c/--config [CONFIGURATION_PATH]\n" +static void forceDmaHeap(const char *) { + test_vars::forceDmaHeap = true; + if (::testing::GTEST_FLAG(filter).find("UsingDmaHeap.") == std::string::npos) + test_app::append_positive_filter("*UsingDmaHeap.*"); +} + +static void forceAllTests(const char *) { + test_vars::forceDmaHeap = true; +} + +const char *helpMsg = " -c/--config [CONFIGURATION_PATH]\n" " Test configuration file in yaml format\n" " -G/--test_with_gpu\n" " Enable testing with loaded GPU L0\n" " -M/--disable_metrics\n" - " Disabling metrics. No metric test will be run\n"; + " Disabling metrics. No metric test will be run\n" + " -R/--dma-heap\n" + " Run tests that requires /dev/dma_heap/system\n" + " -A/--all\n" + " Run all conditional tests(includes dma-heap)\n"; int main(int argc, char **argv) { ::testing::AddGlobalTestEnvironment(Environment::getInstance()); @@ -58,9 +66,10 @@ int main(int argc, char **argv) { test_app::ArgumentMap args = { {'c', {"config", required_argument, [](auto) {}}}, - {'q', {"quick", no_argument, &setQuickFilter}}, {'G', {"test_with_gpu", no_argument, [](auto) { test_vars::test_with_gpu = true; }}}, {'M', {"disable_metrics", no_argument, &disableMetrics}}, + {'R', {"dma-heap", no_argument, &forceDmaHeap}}, + {'A', {"all", no_argument, &forceAllTests}}, }; test_app::parse_args(args, helpMsg, argc, argv); diff --git a/validation/umd-test/test_prime_buffers.cpp b/validation/umd-test/test_buffers_export.cpp similarity index 54% rename from validation/umd-test/test_prime_buffers.cpp rename to validation/umd-test/test_buffers_export.cpp index 5a526fb..17acf68 100644 --- a/validation/umd-test/test_prime_buffers.cpp +++ b/validation/umd-test/test_buffers_export.cpp @@ -6,15 +6,11 @@ */ #include "umd_test.h" -#include "umd_prime_buffers.h" -#include -#include -#include +#include -class PrimeBuffers : public UmdTest, public ::testing::WithParamInterface { +class ExportMemory : public UmdTest, public ::testing::WithParamInterface { public: - void TearDown() override { UmdTest::TearDown(); } /* Get allocation properties descriptor */ ze_memory_allocation_properties_t pMemAllocProperties = { .stype = ZE_STRUCTURE_TYPE_MEMORY_ALLOCATION_PROPERTIES, @@ -34,10 +30,21 @@ class PrimeBuffers : public UmdTest, public ::testing::WithParamInterface &cmd) { return memSizeToStr(cmd.param); }); -TEST_P(PrimeBuffers, exportDeviceMemory) { +TEST_P(ExportMemory, AllocDeviceMemory) { ze_result_t ret; uint64_t size = GetParam(); /* Pepare request for external allocation */ - pDeviceMemAllocDesc.pNext = &primeHelper.externalExportDesc; + pDeviceMemAllocDesc.pNext = &externalExportDesc; auto scopedMem = zeScope::memAllocDevice(zeContext, pDeviceMemAllocDesc, size, 0, zeDevice, ret); @@ -70,35 +77,30 @@ TEST_P(PrimeBuffers, exportDeviceMemory) { memcpy(scopedMem.get(), &pattern, sizeof(pattern)); /* Prepare request for map allocation to fd */ - pMemAllocProperties.pNext = &primeHelper.externalExportFdDesc; + pMemAllocProperties.pNext = &externalExportFdDesc; ASSERT_EQ(ZE_RESULT_SUCCESS, zeMemGetAllocProperties(zeContext, scopedMem.get(), &pMemAllocProperties, nullptr)); - ASSERT_GE(primeHelper.externalExportFdDesc.fd, 0); + ASSERT_GE(externalExportFdDesc.fd, 0); EXPECT_EQ(pMemAllocProperties.type, ZE_MEMORY_TYPE_DEVICE); EXPECT_GT(pMemAllocProperties.id, 0u); EXPECT_EQ(pMemAllocProperties.pageSize, size); - EXPECT_EQ(lseek(primeHelper.externalExportFdDesc.fd, 0, SEEK_END), ALLIGN_TO_PAGE(size)); - lseek(primeHelper.externalExportFdDesc.fd, 0, SEEK_CUR); + EXPECT_EQ(lseek(externalExportFdDesc.fd, 0, SEEK_END), ALLIGN_TO_PAGE(size)); + lseek(externalExportFdDesc.fd, 0, SEEK_CUR); /* mmap memory and check pattern */ - void *ptr = mmap(NULL, - size, - PROT_READ | PROT_WRITE, - MAP_SHARED, - primeHelper.externalExportFdDesc.fd, - 0); + void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, externalExportFdDesc.fd, 0); ASSERT_NE(ptr, MAP_FAILED) << "error " << errno; EXPECT_EQ(*static_cast(ptr), pattern); EXPECT_EQ(munmap(ptr, size), 0); - EXPECT_EQ(close(primeHelper.externalExportFdDesc.fd), 0); + EXPECT_EQ(close(externalExportFdDesc.fd), 0); } -TEST_P(PrimeBuffers, exportHostMemory) { +TEST_P(ExportMemory, AllocHostMemory) { ze_result_t ret; uint64_t size = GetParam(); /* Pepare request for external allocation */ - pHostMemAllocDesc.pNext = &primeHelper.externalExportDesc; + pHostMemAllocDesc.pNext = &externalExportDesc; auto scopedMem = zeScope::memAllocHost(zeContext, pHostMemAllocDesc, size, 0, ret); ASSERT_EQ(ret, ZE_RESULT_SUCCESS); @@ -107,35 +109,30 @@ TEST_P(PrimeBuffers, exportHostMemory) { memcpy(scopedMem.get(), &pattern, sizeof(pattern)); /* Prepare request for map allocation to fd */ - pMemAllocProperties.pNext = &primeHelper.externalExportFdDesc; + pMemAllocProperties.pNext = &externalExportFdDesc; ASSERT_EQ(ZE_RESULT_SUCCESS, zeMemGetAllocProperties(zeContext, scopedMem.get(), &pMemAllocProperties, nullptr)); - ASSERT_GE(primeHelper.externalExportFdDesc.fd, 0); + ASSERT_GE(externalExportFdDesc.fd, 0); EXPECT_EQ(pMemAllocProperties.type, ZE_MEMORY_TYPE_HOST); EXPECT_GT(pMemAllocProperties.id, 0u); EXPECT_EQ(pMemAllocProperties.pageSize, size); - EXPECT_EQ(lseek(primeHelper.externalExportFdDesc.fd, 0, SEEK_END), ALLIGN_TO_PAGE(size)); - lseek(primeHelper.externalExportFdDesc.fd, 0, SEEK_CUR); + EXPECT_EQ(lseek(externalExportFdDesc.fd, 0, SEEK_END), ALLIGN_TO_PAGE(size)); + lseek(externalExportFdDesc.fd, 0, SEEK_CUR); /* mmap memory and check pattern */ - void *ptr = mmap(NULL, - size, - PROT_READ | PROT_WRITE, - MAP_SHARED, - primeHelper.externalExportFdDesc.fd, - 0); + void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, externalExportFdDesc.fd, 0); ASSERT_NE(ptr, MAP_FAILED) << "error " << errno; EXPECT_EQ(*static_cast(ptr), pattern); EXPECT_EQ(munmap(ptr, size), 0); - EXPECT_EQ(close(primeHelper.externalExportFdDesc.fd), 0); + EXPECT_EQ(close(externalExportFdDesc.fd), 0); } -TEST_P(PrimeBuffers, exportSharedMemory) { +TEST_P(ExportMemory, AllocSharedMemory) { ze_result_t ret; uint64_t size = GetParam(); /* Pepare request for external allocation */ - pDeviceMemAllocDesc.pNext = &primeHelper.externalExportDesc; + pDeviceMemAllocDesc.pNext = &externalExportDesc; auto scopedMem = zeScope::memAllocShared(zeContext, pDeviceMemAllocDesc, @@ -150,67 +147,20 @@ TEST_P(PrimeBuffers, exportSharedMemory) { memcpy(scopedMem.get(), &pattern, sizeof(pattern)); /* Prepare request for map allocation to fd */ - pMemAllocProperties.pNext = &primeHelper.externalExportFdDesc; + pMemAllocProperties.pNext = &externalExportFdDesc; ASSERT_EQ(ZE_RESULT_SUCCESS, zeMemGetAllocProperties(zeContext, scopedMem.get(), &pMemAllocProperties, nullptr)); - ASSERT_GE(primeHelper.externalExportFdDesc.fd, 0); + ASSERT_GE(externalExportFdDesc.fd, 0); EXPECT_EQ(pMemAllocProperties.type, ZE_MEMORY_TYPE_SHARED); EXPECT_GT(pMemAllocProperties.id, 0u); EXPECT_EQ(pMemAllocProperties.pageSize, size); - EXPECT_EQ(lseek(primeHelper.externalExportFdDesc.fd, 0, SEEK_END), ALLIGN_TO_PAGE(size)); - lseek(primeHelper.externalExportFdDesc.fd, 0, SEEK_CUR); + EXPECT_EQ(lseek(externalExportFdDesc.fd, 0, SEEK_END), ALLIGN_TO_PAGE(size)); + lseek(externalExportFdDesc.fd, 0, SEEK_CUR); /* mmap memory and check pattern */ - void *ptr = mmap(NULL, - size, - PROT_READ | PROT_WRITE, - MAP_SHARED, - primeHelper.externalExportFdDesc.fd, - 0); + void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, externalExportFdDesc.fd, 0); ASSERT_NE(ptr, MAP_FAILED) << "error " << errno; EXPECT_EQ(*static_cast(ptr), pattern); EXPECT_EQ(munmap(ptr, size), 0); - EXPECT_EQ(close(primeHelper.externalExportFdDesc.fd), 0); -} - -TEST_P(PrimeBuffers, importDeviceMemory) { - ze_result_t ret; - size_t dmaBufferSize = GetParam(); - int32_t dmaBufferFd = -1; - - if (!primeHelper.hasDMABufferSupport()) - GTEST_SKIP() << "Missed support or insufficient permissions for" - << " dma buffer allocation in the system. Skip test"; - - ASSERT_TRUE(primeHelper.createDMABuffer(dmaBufferSize, dmaBufferFd)); - - /* Prepare request to import dma buffer as device memory */ - primeHelper.externalImportFromFdDesc.fd = dmaBufferFd; - pDeviceMemAllocDesc.pNext = &primeHelper.externalImportFromFdDesc; - - auto scopedImportedMemory = - zeScope::memAllocDevice(zeContext, pDeviceMemAllocDesc, dmaBufferSize, 0, zeDevice, ret); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - ASSERT_NE(scopedImportedMemory.get(), nullptr); - - /* Check allocation properties */ - pMemAllocProperties.pNext = nullptr; - ASSERT_EQ(ZE_RESULT_SUCCESS, - zeMemGetAllocProperties(zeContext, - scopedImportedMemory.get(), - &pMemAllocProperties, - nullptr)); - ASSERT_EQ(pMemAllocProperties.type, ZE_MEMORY_TYPE_DEVICE); - ASSERT_GT(pMemAllocProperties.id, 0u); - ASSERT_EQ(pMemAllocProperties.pageSize, ALLIGN_TO_PAGE(dmaBufferSize)); - - /* mmap original dma buffer and write pattern to it */ - void *dmaBufferPtr = primeHelper.mmapDmaBuffer(dmaBufferFd); - ASSERT_NE(dmaBufferPtr, MAP_FAILED) << "error " << errno; - const int32_t pattern = 0xDEADAABB; - memcpy(dmaBufferPtr, &pattern, sizeof(pattern)); - - /*check if pattern match on imported buffer*/ - int32_t *importedPtr = static_cast(scopedImportedMemory.get()); - EXPECT_EQ(*importedPtr, pattern); + EXPECT_EQ(close(externalExportFdDesc.fd), 0); } diff --git a/validation/umd-test/test_buffers_export_gpu.cpp b/validation/umd-test/test_buffers_export_gpu.cpp index c438479..ec45689 100644 --- a/validation/umd-test/test_buffers_export_gpu.cpp +++ b/validation/umd-test/test_buffers_export_gpu.cpp @@ -20,7 +20,7 @@ class BuffersExport : public UmdTest { void SetUp() override { UmdTest::SetUp(); - Npu = {.dev = zeDevice, .ctx = zeContext, .ordinal = copyGrpOrdinal}; + Npu = {.dev = zeDevice, .ctx = zeContext, .ordinal = 0u}; Gpu = {.dev = zeDeviceGpu, .ctx = zeContextGpu, .ordinal = copyGrpOrdinalGpu}; } diff --git a/validation/umd-test/test_buffers_import.cpp b/validation/umd-test/test_buffers_import.cpp new file mode 100644 index 0000000..2e38966 --- /dev/null +++ b/validation/umd-test/test_buffers_import.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "umd_dma_heap_system.hpp" +#include "umd_test.h" + +class ImportMemoryUsingDmaHeap : public UmdTest, public ::testing::WithParamInterface { + public: + /* Get allocation properties descriptor */ + ze_memory_allocation_properties_t pMemAllocProperties = { + .stype = ZE_STRUCTURE_TYPE_MEMORY_ALLOCATION_PROPERTIES, + .pNext = nullptr, + .type = ZE_MEMORY_TYPE_UNKNOWN, + .id = 0, + .pageSize = 0}; + + /* Alloc device memory descriptor */ + ze_device_mem_alloc_desc_t pDeviceMemAllocDesc = {.stype = + ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC, + .pNext = nullptr, + .flags = 0, + .ordinal = 0}; + + /* Descriptor to import allocation from fd */ + ze_external_memory_import_fd_t externalImportFromFdDesc = { + .stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMPORT_FD, + .pNext = nullptr, + .flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF, + .fd = -1}; + + DmaHeapSystem dmaHeapSystem; +}; + +INSTANTIATE_TEST_SUITE_P(, + ImportMemoryUsingDmaHeap, + ::testing::Values(2 * KB, 16 * MB, 255 * MB), + [](const testing::TestParamInfo &cmd) { + return memSizeToStr(cmd.param); + }); + +TEST_P(ImportMemoryUsingDmaHeap, AllocDeviceMemory) { + ze_result_t ret; + size_t dmaBufferSize = GetParam(); + + CHECK_DMA_HEAP_SUPPORT(dmaHeapSystem); + + auto dmaBuffer = dmaHeapSystem.allocDmaHeapBuffer(dmaBufferSize); + ASSERT_NE(dmaBuffer, nullptr); + + /* Prepare request to import dma buffer as device memory */ + externalImportFromFdDesc.fd = dmaBuffer->fd; + pDeviceMemAllocDesc.pNext = &externalImportFromFdDesc; + + auto scopedImportedMemory = + zeScope::memAllocDevice(zeContext, pDeviceMemAllocDesc, dmaBufferSize, 0, zeDevice, ret); + ASSERT_EQ(ret, ZE_RESULT_SUCCESS); + ASSERT_NE(scopedImportedMemory.get(), nullptr); + + /* Check allocation properties */ + pMemAllocProperties.pNext = nullptr; + ASSERT_EQ(ZE_RESULT_SUCCESS, + zeMemGetAllocProperties(zeContext, + scopedImportedMemory.get(), + &pMemAllocProperties, + nullptr)); + ASSERT_EQ(pMemAllocProperties.type, ZE_MEMORY_TYPE_DEVICE); + ASSERT_GT(pMemAllocProperties.id, 0u); + ASSERT_EQ(pMemAllocProperties.pageSize, ALLIGN_TO_PAGE(dmaBufferSize)); + + /* mmap original dma buffer and write pattern to it */ + const int32_t pattern = 0xDEADAABB; + memcpy(dmaBuffer->ptr, &pattern, sizeof(pattern)); + + /*check if pattern match on imported buffer*/ + int32_t *importedPtr = static_cast(scopedImportedMemory.get()); + EXPECT_EQ(*importedPtr, pattern); +} diff --git a/validation/umd-test/test_buffers_import_gpu.cpp b/validation/umd-test/test_buffers_import_gpu.cpp index 288e524..fd5f2cd 100644 --- a/validation/umd-test/test_buffers_import_gpu.cpp +++ b/validation/umd-test/test_buffers_import_gpu.cpp @@ -14,14 +14,14 @@ #define CL_TARGET_OPENCL_VERSION 300 #include "level_zero/ze_api.h" -#include "umd_prime_buffers.h" +#include "umd_dma_heap_system.hpp" #include #include static cl_platform_id getIntelOpenCLPlatform(); -using BuffersImport = UmdTest; +using ImportMemoryGPUUsingDmaHeap = UmdTest; // buffer allocated // on dma_heap @@ -31,15 +31,13 @@ using BuffersImport = UmdTest; // | zeInputPtr | // +----------------+ // -TEST_F(BuffersImport, GPUclKernelToNPUzeCopy) { +TEST_F(ImportMemoryGPUUsingDmaHeap, GPUclKernelToNPUzeCopy) { if (!isVPU37xx()) { SKIP_("BuffersImport test is supported on MTL platform only"); } - PrimeBufferHelper primeBufferHelper; - if (!primeBufferHelper.hasDMABufferSupport()) { - SKIP_("Prime buffers support is not available. Probably need root privileges"); - } + DmaHeapSystem dmaHeapSystem; + CHECK_DMA_HEAP_SUPPORT(dmaHeapSystem); // OCL init cl_platform_id platform = getIntelOpenCLPlatform(); @@ -65,7 +63,7 @@ TEST_F(BuffersImport, GPUclKernelToNPUzeCopy) { ASSERT_EQ(CL_SUCCESS, oclResult); // create input buffer - const size_t size = 20; + constexpr size_t size = 20; uint8_t inputBuffer[size]; std::iota(inputBuffer, inputBuffer + size, 1); @@ -76,12 +74,12 @@ TEST_F(BuffersImport, GPUclKernelToNPUzeCopy) { &oclResult); ASSERT_EQ(CL_SUCCESS, oclResult); - int bufferFd = -1; - ASSERT_TRUE(primeBufferHelper.createDMABuffer(size, bufferFd)); + auto dmaBuffer = dmaHeapSystem.allocDmaHeapBuffer(size); + ASSERT_TRUE(dmaBuffer); cl_mem_properties memProps[] = { static_cast(CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR), - static_cast(bufferFd), + static_cast(dmaBuffer->fd), 0}; cl_mem oclOutputMem = clCreateBufferWithProperties(oclContext, memProps, @@ -114,7 +112,7 @@ TEST_F(BuffersImport, GPUclKernelToNPUzeCopy) { ze_command_queue_desc_t commandQueueDesc{ .stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC, .pNext = nullptr, - .ordinal = copyGrpOrdinal, + .ordinal = 0u, .index = 0, .flags = 0, .mode = ZE_COMMAND_QUEUE_MODE_DEFAULT, @@ -127,7 +125,7 @@ TEST_F(BuffersImport, GPUclKernelToNPUzeCopy) { ze_command_list_desc_t commandListDesc{ .stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC, .pNext = nullptr, - .commandQueueGroupOrdinal = copyGrpOrdinal, + .commandQueueGroupOrdinal = 0u, .flags = 0, }; ze_command_list_handle_t zeCommandList; @@ -139,13 +137,13 @@ TEST_F(BuffersImport, GPUclKernelToNPUzeCopy) { .stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMPORT_FD, .pNext = nullptr, .flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF, - .fd = static_cast(bufferFd), + .fd = static_cast(dmaBuffer->fd), }; ze_device_mem_alloc_desc_t deviceMemAllocDescInput{ .stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC, .pNext = &memoryImportDesc, .flags = 0, - .ordinal = 0, + .ordinal = 0u, }; void *zeInputPtr; ASSERT_EQ(zeMemAllocDevice(zeContext, &deviceMemAllocDescInput, size, 0, zeDevice, &zeInputPtr), @@ -155,7 +153,7 @@ TEST_F(BuffersImport, GPUclKernelToNPUzeCopy) { .stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC, .pNext = nullptr, .flags = 0, - .ordinal = 0, + .ordinal = 0u, }; ze_host_mem_alloc_desc_t hostMemAllocDescOutput{ .stype = ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC, @@ -232,7 +230,7 @@ cl_platform_id getIntelOpenCLPlatform() { if (result != CL_SUCCESS) return nullptr; - std::vector platforms(numPlatforms, 0); + std::vector platforms(numPlatforms); result = clGetPlatformIDs(numPlatforms, platforms.data(), nullptr); if (result != CL_SUCCESS) return nullptr; diff --git a/validation/umd-test/test_commands.cpp b/validation/umd-test/test_commands.cpp index b368544..d386e57 100644 --- a/validation/umd-test/test_commands.cpp +++ b/validation/umd-test/test_commands.cpp @@ -226,178 +226,6 @@ TEST_F(Command, MultipleCommandQueueSubmissionStressTest) { } } -TEST_F(Command, NNAndCopyCommandQueueCreationAndMultipleCommandsSubmission) { - ze_result_t ret; - cmdQueueDesc.ordinal = computeGrpOrdinal; - scopedQueueVec.push_back(zeScope::commandQueueCreate(zeContext, zeDevice, cmdQueueDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - queue = scopedQueueVec.back().get(); - - cmdQueueDesc.ordinal = copyGrpOrdinal; - scopedQueueVec.push_back(zeScope::commandQueueCreate(zeContext, zeDevice, cmdQueueDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - auto copyQueue = scopedQueueVec.back().get(); - - cmdListDesc.commandQueueGroupOrdinal = copyGrpOrdinal; - scopedListVec.push_back(zeScope::commandListCreate(zeContext, zeDevice, cmdListDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - auto listCopy = scopedListVec.back().get(); - - auto mem = AllocSharedMemory(size); - uint64_t *ts = static_cast(mem.get()); - ASSERT_TRUE(ts) << "Failed to allocate shared memory"; - ASSERT_EQ(zeCommandListAppendWriteGlobalTimestamp(list, ts, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandListAppendWriteGlobalTimestamp(listCopy, ts, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - - auto mem2 = AllocHostMemory(size); - void *memInputHost = mem2.get(); - ASSERT_NE(memInputHost, nullptr) << "Failed to allocate host memory"; - uint64_t *copyInputHost = static_cast(memInputHost); - *copyInputHost = 0xdeadbeef; - - auto mem3 = AllocDeviceMemory(size); - void *memOutputDev = mem3.get(); - ASSERT_NE(memOutputDev, nullptr) << "Failed to allocate device memory"; - ASSERT_EQ( - zeCommandListAppendMemoryCopy(list, memOutputDev, memInputHost, size, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandListAppendMemoryCopy(listCopy, - memOutputDev, - memInputHost, - size, - nullptr, - 0, - nullptr), - ZE_RESULT_SUCCESS); - - auto mem4 = AllocHostMemory(size); - void *memOutputHost = mem4.get(); - ASSERT_NE(memOutputHost, nullptr) << "Failed to allocate host memory"; - uint64_t *copyOutputHost = static_cast(memOutputHost); - ASSERT_EQ( - zeCommandListAppendMemoryCopy(list, memOutputHost, memOutputDev, size, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandListAppendMemoryCopy(listCopy, - memOutputHost, - memOutputDev, - size, - nullptr, - 0, - nullptr), - ZE_RESULT_SUCCESS); - - auto mem5 = AllocSharedMemory(size); - uint64_t *ts2 = static_cast(mem5.get()); - ASSERT_TRUE(ts2) << "Failed to allocate shared memory"; - ASSERT_EQ(zeCommandListAppendWriteGlobalTimestamp(list, ts2, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandListAppendWriteGlobalTimestamp(listCopy, ts2, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - - ASSERT_EQ(zeCommandListClose(list), ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandListClose(listCopy), ZE_RESULT_SUCCESS); - - ASSERT_EQ(zeCommandQueueExecuteCommandLists(queue, 1, &list, nullptr), ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandQueueExecuteCommandLists(copyQueue, 1, &listCopy, nullptr), - ZE_RESULT_SUCCESS); - - ASSERT_EQ(zeCommandQueueSynchronize(queue, syncTimeout), ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandQueueSynchronize(copyQueue, syncTimeout), ZE_RESULT_SUCCESS); - - EXPECT_NE(*ts, 0llu) << "Timestamp should be different from 0"; - EXPECT_EQ(*copyInputHost, *copyOutputHost) << "Copy failed, numbers should be equal"; - EXPECT_NE(*ts2, 0llu) << "Timestamp should be different from 0"; - EXPECT_NE(*ts, *ts2) << "Timestamp values should be different"; -} - -TEST_F(Command, MultipleCommandQueueCreationAndCommandsSubmissionToBothQueues) { - ze_result_t ret; - cmdQueueDesc.ordinal = computeGrpOrdinal; - scopedQueueVec.push_back(zeScope::commandQueueCreate(zeContext, zeDevice, cmdQueueDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - queue = scopedQueueVec.back().get(); - - cmdListDesc.commandQueueGroupOrdinal = computeGrpOrdinal; - scopedListVec.push_back(zeScope::commandListCreate(zeContext, zeDevice, cmdListDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - list = scopedListVec.back().get(); - - cmdQueueDesc.ordinal = copyGrpOrdinal; - scopedQueueVec.push_back(zeScope::commandQueueCreate(zeContext, zeDevice, cmdQueueDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - auto copyQueue = scopedQueueVec.back().get(); - - cmdListDesc.commandQueueGroupOrdinal = copyGrpOrdinal; - scopedListVec.push_back(zeScope::commandListCreate(zeContext, zeDevice, cmdListDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - auto copyList = scopedListVec.back().get(); - - auto mem = AllocSharedMemory(size); - uint64_t *ts = static_cast(mem.get()); - ASSERT_EQ(zeCommandListAppendWriteGlobalTimestamp(list, ts, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - - auto mem1 = AllocHostMemory(size); - uint64_t *memInputHost = static_cast(mem1.get()); - *memInputHost = 0xdeadbeef; - auto mem2 = AllocDeviceMemory(size); - uint64_t *memOutputDev = static_cast(mem2.get()); - auto mem3 = AllocHostMemory(size); - uint64_t *memOutputHost = static_cast(mem3.get()); - ASSERT_EQ( - zeCommandListAppendMemoryCopy(list, memOutputDev, memInputHost, size, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ( - zeCommandListAppendMemoryCopy(list, memOutputHost, memOutputDev, size, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - - auto mem4 = AllocHostMemory(size); - uint64_t *memInputHost2 = static_cast(mem4.get()); - *memInputHost2 = 0xabcdabcd; - auto mem5 = AllocDeviceMemory(size); - uint64_t *memOutputDev2 = static_cast(mem5.get()); - auto mem6 = AllocHostMemory(size); - uint64_t *memOutputHost2 = static_cast(mem6.get()); - ASSERT_EQ(zeCommandListAppendMemoryCopy(copyList, - memOutputDev2, - memInputHost2, - size, - nullptr, - 0, - nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandListAppendMemoryCopy(copyList, - memOutputHost2, - memOutputDev2, - size, - nullptr, - 0, - nullptr), - ZE_RESULT_SUCCESS); - - auto mem7 = AllocSharedMemory(size); - uint64_t *ts2 = static_cast(mem7.get()); - ASSERT_EQ(zeCommandListAppendWriteGlobalTimestamp(copyList, ts2, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - - ASSERT_EQ(zeCommandListClose(list), ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandListClose(copyList), ZE_RESULT_SUCCESS); - - ASSERT_EQ(zeCommandQueueExecuteCommandLists(queue, 1, &list, nullptr), ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandQueueSynchronize(queue, syncTimeout), ZE_RESULT_SUCCESS); - EXPECT_NE(*ts, 0llu) << "Timestamp should be different from 0"; - EXPECT_EQ(*memInputHost, *memOutputHost) << "Copy failed, numbers should be equal"; - - ASSERT_EQ(zeCommandQueueExecuteCommandLists(copyQueue, 1, ©List, nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandQueueSynchronize(copyQueue, syncTimeout), ZE_RESULT_SUCCESS); - EXPECT_EQ(*memInputHost2, *memOutputHost2) << "Copy failed, numbers should be equal"; - EXPECT_NE(*ts2, 0llu) << "Timestamp should be different from 0"; - EXPECT_NE(*ts, *ts2) << "Timestamp values should be different"; -} - class CommandTimestamp : public Command {}; TEST_F(CommandTimestamp, AppendGlobalTimestampAndSynchronize) { @@ -525,14 +353,13 @@ TEST_F(CommandTimestamp, TwoCommandQueusWithinSameGroupExecuteTimestampAndSynchr EXPECT_LT(*ts, *(ts + 1)) << "Second timestamp should be greater than first"; } -TEST_F(CommandTimestamp, CopyQueueTimestampSubmission) { +TEST_F(CommandTimestamp, ExecuteTimestampCopyAndTimestampCommands) { ze_result_t ret; - cmdQueueDesc.ordinal = copyGrpOrdinal; + scopedQueueVec.push_back(zeScope::commandQueueCreate(zeContext, zeDevice, cmdQueueDesc, ret)); ASSERT_EQ(ret, ZE_RESULT_SUCCESS); queue = scopedQueueVec.back().get(); - cmdListDesc.commandQueueGroupOrdinal = copyGrpOrdinal; scopedListVec.push_back(zeScope::commandListCreate(zeContext, zeDevice, cmdListDesc, ret)); ASSERT_EQ(ret, ZE_RESULT_SUCCESS); list = scopedListVec.back().get(); @@ -608,97 +435,6 @@ TEST_F(CommandTimestamp, TwoCommandQueusWithinSameGroupExecuteTimestampAndSynchr } } -TEST_F(CommandTimestamp, TwoCommandQueusWithDifferentGroupExecuteTimestampAndSynchronize) { - ze_result_t ret; - scopedQueueVec.push_back(zeScope::commandQueueCreate(zeContext, zeDevice, cmdQueueDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - auto queueNN = scopedQueueVec.back().get(); - - cmdQueueDesc.ordinal = copyGrpOrdinal; - scopedQueueVec.push_back(zeScope::commandQueueCreate(zeContext, zeDevice, cmdQueueDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - auto queueCopy = scopedQueueVec.back().get(); - - cmdListDesc.commandQueueGroupOrdinal = computeGrpOrdinal; - scopedListVec.push_back(zeScope::commandListCreate(zeContext, zeDevice, cmdListDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - auto listNN = scopedListVec.back().get(); - - cmdListDesc.commandQueueGroupOrdinal = copyGrpOrdinal; - scopedListVec.push_back(zeScope::commandListCreate(zeContext, zeDevice, cmdListDesc, ret)); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - auto listCopy = scopedListVec.back().get(); - - auto mem = AllocSharedMemory(size * 2); - uint64_t *ts = static_cast(mem.get()); - - ASSERT_EQ(zeCommandListAppendWriteGlobalTimestamp(listNN, ts, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandListClose(listNN), ZE_RESULT_SUCCESS); - - ASSERT_EQ(zeCommandListAppendWriteGlobalTimestamp(listCopy, ts + 1, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandListClose(listCopy), ZE_RESULT_SUCCESS); - - ASSERT_EQ(zeCommandQueueExecuteCommandLists(queueNN, 1, &listNN, nullptr), ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandQueueExecuteCommandLists(queueCopy, 1, &listCopy, nullptr), - ZE_RESULT_SUCCESS); - - ASSERT_EQ(zeCommandQueueSynchronize(queueNN, syncTimeout), ZE_RESULT_SUCCESS); - ASSERT_EQ(zeCommandQueueSynchronize(queueCopy, syncTimeout), ZE_RESULT_SUCCESS); - - EXPECT_NE(*(ts), *(ts + 1)) << "Timestamp values should be different"; -} - -TEST_F(CommandTimestamp, CommandTimestampStressTest) { - auto checkTimestamp = [&]() { - ze_result_t ret; - ze_context_desc_t contextDesc = {.stype = ZE_STRUCTURE_TYPE_CONTEXT_DESC, - .pNext = nullptr, - .flags = 0}; - - auto devContext = zeScope::contextCreate(zeDriver, contextDesc, ret); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - auto cmdQueue = zeScope::commandQueueCreate(devContext.get(), zeDevice, cmdQueueDesc, ret); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - - auto cmdList = zeScope::commandListCreate(devContext.get(), zeDevice, cmdListDesc, ret); - ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - - auto mem = zeMemory::allocShared(devContext.get(), zeDevice, size, 0); - uint64_t *ts = static_cast(mem.get()); - - ASSERT_EQ(zeCommandListAppendWriteGlobalTimestamp(cmdList.get(), ts, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - - ASSERT_EQ(zeCommandListClose(cmdList.get()), ZE_RESULT_SUCCESS); - - auto list = cmdList.get(); - uint32_t iterations; - - if (isSilicon()) - iterations = 5000; - else - iterations = 5; - - for (uint32_t iteration = 0; iteration < iterations; iteration++) { - EXPECT_EQ(zeCommandQueueExecuteCommandLists(cmdQueue.get(), 1, &list, nullptr), - ZE_RESULT_SUCCESS); - EXPECT_EQ(zeCommandQueueSynchronize(cmdQueue.get(), syncTimeout * 2), - ZE_RESULT_SUCCESS); - EXPECT_GT(*ts, 0ULL); - } - }; - - const size_t threadsNum = 20; - std::vector> tasks(threadsNum); - for (auto &task : tasks) { - task = std::async(std::launch::async, checkTimestamp); - } - for (const auto &task : tasks) { - task.wait(); - } -} class CommandCopy : public Command {}; TEST_F(CommandCopy, AppendMemoryCopyLocalToLocalAndSynchronize) { diff --git a/validation/umd-test/test_device.cpp b/validation/umd-test/test_device.cpp index bd10ff2..d5bf88d 100644 --- a/validation/umd-test/test_device.cpp +++ b/validation/umd-test/test_device.cpp @@ -8,6 +8,7 @@ #include "umd_test.h" #include +#include class Device : public UmdTest {}; @@ -30,53 +31,104 @@ TEST_F(Device, GetProperties) { } TEST_F(Device, GetZesDeviceAndProperties) { - uint32_t zesDrvCount = 0u; - uint32_t zesDevCount = 0u; + ASSERT_EQ(zesInit(0), ZE_RESULT_SUCCESS); + + uint32_t driverCount = 0u; + ASSERT_EQ(zesDriverGet(&driverCount, nullptr), ZE_RESULT_SUCCESS); + ASSERT_GE(driverCount, 1); + + std::vector zesDrivers(driverCount); + ASSERT_EQ(zesDriverGet(&driverCount, zesDrivers.data()), ZE_RESULT_SUCCESS); + + bool foundNpu = false; + for (size_t i = 0; i < zesDrivers.size(); i++) { + TRACE("Driver[%lu].Handle: %p\n", i, zesDrivers[i]); + + uint32_t deviceCount = 0u; + ASSERT_EQ(zesDeviceGet(zesDrivers[i], &deviceCount, nullptr), ZE_RESULT_SUCCESS); + ASSERT_GE(deviceCount, 1); + + std::vector zesDevices(deviceCount); + ASSERT_EQ(zesDeviceGet(zesDrivers[i], &deviceCount, zesDevices.data()), ZE_RESULT_SUCCESS); + + for (size_t j = 0; j < zesDevices.size(); j++) { + TRACE("Device[%lu].Handle: %p\n", j, zesDevices[j]); + + zes_device_properties_t devProp = {}; + devProp.stype = ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES; + + ASSERT_EQ(zesDeviceGetProperties(zesDevices[j], &devProp), ZE_RESULT_SUCCESS); + + TRACE("Device[%lu].BrandName: %s\n", j, devProp.brandName); + TRACE("Device[%lu].ModelName: %s\n", j, devProp.modelName); + TRACE("Device[%lu].VendorName: %s\n", j, devProp.vendorName); + TRACE("Device[%lu].DriverVersion: %s\n", j, devProp.driverVersion); + if (std::string(devProp.vendorName) == "INTEL" && + std::string(devProp.brandName) == "NPU") { + EXPECT_NE(std::string(devProp.driverVersion).find("npu-linux-driver"), + std::string::npos); + foundNpu = true; + } + } + } + EXPECT_TRUE(foundNpu) << "Could not find Intel NPU identifier in zesDeviceGetProperties()"; +} + +TEST_F(Device, GetZesEngineGetActivity) { + SKIP_NEEDS_SYSFS_FILE("npu_busy_time_us"); + ASSERT_EQ(zesInit(0), ZE_RESULT_SUCCESS); + + uint32_t zesDrvCount = 0u; ASSERT_EQ(zesDriverGet(&zesDrvCount, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(zesDrvCount, 1); + ASSERT_GE(zesDrvCount, 1); + std::vector zesDrivers(zesDrvCount); - ASSERT_EQ(zeDriverGet(&zesDrvCount, zesDrivers.data()), ZE_RESULT_SUCCESS); + ASSERT_EQ(zesDriverGet(&zesDrvCount, zesDrivers.data()), ZE_RESULT_SUCCESS); + bool foundNpu = false; for (const auto &driver : zesDrivers) { + uint32_t zesDevCount = 0u; ASSERT_EQ(zesDeviceGet(driver, &zesDevCount, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(zesDevCount, 1); - if (zesDevCount != 1) + if (!zesDevCount) continue; - zes_device_handle_t device; - ASSERT_EQ(zesDeviceGet(driver, &zesDevCount, &device), ZE_RESULT_SUCCESS); - zes_device_properties_t devProp = {}; - devProp.stype = ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES; - - ASSERT_EQ(zesDeviceGetProperties(device, &devProp), ZE_RESULT_SUCCESS); - - EXPECT_STREQ(devProp.vendorName, "INTEL"); - EXPECT_STREQ(devProp.brandName, "NPU"); - std::string version(devProp.driverVersion); - EXPECT_NE(version.find("npu-linux-driver"), std::string::npos); - TRACE("BrandName: %s\n", devProp.brandName); - TRACE("ModelName: %s\n", devProp.modelName); - TRACE("VendorName: %s\n", devProp.vendorName); - TRACE("DriverVersion: %s\n", devProp.driverVersion); + std::vector zesDevices(zesDevCount); + ASSERT_EQ(zesDeviceGet(driver, &zesDevCount, zesDevices.data()), ZE_RESULT_SUCCESS); + for (auto &device : zesDevices) { + zes_device_properties_t devProp = {}; + devProp.stype = ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES; + + ASSERT_EQ(zesDeviceGetProperties(device, &devProp), ZE_RESULT_SUCCESS); + + if (std::string(devProp.vendorName) == "INTEL" && + std::string(devProp.brandName) == "NPU") { + foundNpu = true; + uint32_t count = 0; + + ASSERT_EQ(zesDeviceEnumEngineGroups(device, &count, nullptr), ZE_RESULT_SUCCESS); + ASSERT_EQ(count, 1); + std::vector engineHandlers(count); + ASSERT_EQ(zesDeviceEnumEngineGroups(device, &count, engineHandlers.data()), + ZE_RESULT_SUCCESS); + + zes_engine_properties_t engineProperties = {}; + engineProperties.stype = ZES_STRUCTURE_TYPE_ENGINE_PROPERTIES; + ASSERT_EQ(zesEngineGetProperties(engineHandlers[0], &engineProperties), + ZE_RESULT_SUCCESS); + + EXPECT_EQ(engineProperties.type, ZES_ENGINE_GROUP_COMPUTE_ALL); + EXPECT_FALSE(engineProperties.onSubdevice); + + zes_engine_stats_t engineStats; + ASSERT_EQ(zesEngineGetActivity(engineHandlers[0], &engineStats), ZE_RESULT_SUCCESS); + EXPECT_GT(engineStats.timestamp, 0ULL); + TRACE("Device active time: %lu\n", engineStats.activeTime); + TRACE("Device timestamp: %lu\n", engineStats.timestamp); + } + } } -} - -TEST_F(Device, GetZesProperties) { - zes_device_properties_t devProp = {}; - - devProp.stype = ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES; - ASSERT_EQ(zesDeviceGetProperties(static_cast(zeDevice), &devProp), - ZE_RESULT_SUCCESS); - - EXPECT_STREQ(devProp.vendorName, "INTEL"); - EXPECT_STREQ(devProp.brandName, "NPU"); - std::string version(devProp.driverVersion); - EXPECT_NE(version.find("npu-linux-driver"), std::string::npos); - TRACE("BrandName: %s\n", devProp.brandName); - TRACE("ModelName: %s\n", devProp.modelName); - TRACE("VendorName: %s\n", devProp.vendorName); - TRACE("DriverVersion: %s\n", devProp.driverVersion); + EXPECT_TRUE(foundNpu) << "Could not find Intel NPU identifier in zesDeviceGetProperties()"; } TEST_F(Device, GetPropertiesMutableCmdListDeviceIpVersion) { @@ -110,11 +162,6 @@ TEST_F(Device, GetPropertiesMutableCmdListDeviceIpVersion) { } TEST_F(Device, GetGlobalTimestamps) { - SKIP_VPU40XX( - "Ubuntu linux-image-6.8.0-41-generic is missing a support for FW boot param " - "systime_time_us\n" - "Support for it has been added in Kernel patch 00b9151cd4a33040b7f5ae04aaf1650e885ff3e0"); - auto checkTimestamp = [&]() { using namespace std::chrono_literals; uint64_t hostTimestamp1 = 0, deviceTimestamp1 = 0; diff --git a/validation/umd-test/test_driver.cpp b/validation/umd-test/test_driver.cpp index beda895..59020e1 100644 --- a/validation/umd-test/test_driver.cpp +++ b/validation/umd-test/test_driver.cpp @@ -46,18 +46,23 @@ TEST_F(Driver, GetExtensionProperties) { bool has_graph_extension = false; bool has_mutable_cmdlist_extension = false; + bool has_cmd_queue_extension = false; for (auto &v : props) { TRACE("Driver Extension name: %s, version: %i.%i\n", v.name, ZE_MAJOR_VERSION(v.version), ZE_MINOR_VERSION(v.version)); - if (std::string(v.name) == GRAPH_EXT_NAME && v.version == GRAPH_EXT_VERSION) + std::string extName(v.name); + if (extName.find(ZE_GRAPH_EXT_NAME) != std::string::npos && v.version == GRAPH_EXT_VERSION) has_graph_extension = true; - if (std::string(v.name) == ZE_MUTABLE_COMMAND_LIST_EXP_NAME && + if (extName == ZE_MUTABLE_COMMAND_LIST_EXP_NAME && v.version == ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_0) has_mutable_cmdlist_extension = true; + if (extName == COMMAND_QUEUE_EXT_NAME && v.version == COMMAND_QUEUE_NPU_EXT_VERSION) + has_cmd_queue_extension = true; } EXPECT_TRUE(has_graph_extension); EXPECT_TRUE(has_mutable_cmdlist_extension); + EXPECT_TRUE(has_cmd_queue_extension); } diff --git a/validation/umd-test/test_event_sync.cpp b/validation/umd-test/test_event_sync.cpp index e412078..6a5a34b 100644 --- a/validation/umd-test/test_event_sync.cpp +++ b/validation/umd-test/test_event_sync.cpp @@ -14,29 +14,25 @@ struct EventSync : public UmdTest { void SetUp() override { UmdTest::SetUp(); - ASSERT_EQ( - createCommandQueue(computeGrpOrdinal, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, &cmdQueue), - ZE_RESULT_SUCCESS); - ASSERT_EQ(createCommandQueue(computeGrpOrdinal, - ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, - &cmdQueuePrior), + ASSERT_EQ(createCommandQueue(ZE_COMMAND_QUEUE_PRIORITY_NORMAL, &cmdQueue), + ZE_RESULT_SUCCESS); + ASSERT_EQ(createCommandQueue(ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, &cmdQueuePrior), ZE_RESULT_SUCCESS); - ASSERT_EQ(createCommandList(computeGrpOrdinal, &cmdList), ZE_RESULT_SUCCESS); - ASSERT_EQ(createCommandList(computeGrpOrdinal, &cmdListPrior), ZE_RESULT_SUCCESS); + ASSERT_EQ(createCommandList(&cmdList), ZE_RESULT_SUCCESS); + ASSERT_EQ(createCommandList(&cmdListPrior), ZE_RESULT_SUCCESS); ASSERT_EQ(createEventPool(3, &eventPool), ZE_RESULT_SUCCESS); } void TearDown() override { UmdTest::TearDown(); } - ze_result_t createCommandQueue(uint32_t ordinal, - ze_command_queue_priority_t priority, + ze_result_t createCommandQueue(ze_command_queue_priority_t priority, ze_command_queue_handle_t *handle) { ze_result_t ret = ZE_RESULT_SUCCESS; ze_command_queue_desc_t desc = {.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC, .pNext = nullptr, - .ordinal = ordinal, + .ordinal = 0u, .index = 0, .flags = 0, .mode = ZE_COMMAND_QUEUE_MODE_DEFAULT, @@ -47,11 +43,11 @@ struct EventSync : public UmdTest { return ret; } - ze_result_t createCommandList(uint32_t ordinal, ze_command_list_handle_t *handle) { + ze_result_t createCommandList(ze_command_list_handle_t *handle) { ze_result_t ret = ZE_RESULT_SUCCESS; ze_command_list_desc_t desc = {.stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC, .pNext = nullptr, - .commandQueueGroupOrdinal = ordinal, + .commandQueueGroupOrdinal = 0u, .flags = 0}; auto scopedList = zeScope::commandListCreate(zeContext, zeDevice, desc, ret); scopedLists.push_back(std::move(scopedList)); @@ -268,11 +264,11 @@ TEST_F(EventSync, QueueExecuteManyCommandListsThatWaitForEachOther) { memset(srcDevicePtr, testPattern, allocSize); ze_command_list_handle_t cmdList0 = nullptr; - ASSERT_EQ(createCommandList(computeGrpOrdinal, &cmdList0), ZE_RESULT_SUCCESS); + ASSERT_EQ(createCommandList(&cmdList0), ZE_RESULT_SUCCESS); ze_command_list_handle_t cmdList1 = nullptr; - ASSERT_EQ(createCommandList(computeGrpOrdinal, &cmdList1), ZE_RESULT_SUCCESS); + ASSERT_EQ(createCommandList(&cmdList1), ZE_RESULT_SUCCESS); ze_command_list_handle_t cmdList2 = nullptr; - ASSERT_EQ(createCommandList(computeGrpOrdinal, &cmdList2), ZE_RESULT_SUCCESS); + ASSERT_EQ(createCommandList(&cmdList2), ZE_RESULT_SUCCESS); ASSERT_EQ(zeCommandListAppendWaitOnEvents(cmdList0, 1, &event0), ZE_RESULT_SUCCESS); ASSERT_EQ(zeCommandListAppendMemoryCopy(cmdList0, diff --git a/validation/umd-test/test_fence.cpp b/validation/umd-test/test_fence.cpp index 4b6ea08..290371f 100644 --- a/validation/umd-test/test_fence.cpp +++ b/validation/umd-test/test_fence.cpp @@ -18,7 +18,7 @@ class Fence : public UmdTest { ze_command_queue_desc_t cmdQueueDesc{.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC, .pNext = nullptr, - .ordinal = computeGrpOrdinal, + .ordinal = 0u, .index = 0, .flags = 0, .mode = ZE_COMMAND_QUEUE_MODE_DEFAULT, @@ -215,7 +215,7 @@ TEST_F(FenceSync, CallFenceHostSynchronizeTwiceExpectSignaledState) { TEST_F(FenceSync, ExecuteAndSynchronizeMultipleCommandQueuesUsingMultipleFences) { ze_command_queue_desc_t copyCmdQueueDesc{.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC, .pNext = nullptr, - .ordinal = copyGrpOrdinal, + .ordinal = 0u, .index = 0, .flags = 0, .mode = ZE_COMMAND_QUEUE_MODE_DEFAULT, @@ -226,7 +226,7 @@ TEST_F(FenceSync, ExecuteAndSynchronizeMultipleCommandQueuesUsingMultipleFences) ze_command_list_desc_t copycmdListDesc = {.stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC, .pNext = nullptr, - .commandQueueGroupOrdinal = copyGrpOrdinal, + .commandQueueGroupOrdinal = 0u, .flags = 0}; auto scopedList2 = zeScope::commandListCreate(zeContext, zeDevice, copycmdListDesc, ret); ASSERT_EQ(ret, ZE_RESULT_SUCCESS); diff --git a/validation/umd-test/test_graph.cpp b/validation/umd-test/test_graph.cpp index d6b5ccb..4bed10b 100644 --- a/validation/umd-test/test_graph.cpp +++ b/validation/umd-test/test_graph.cpp @@ -9,7 +9,7 @@ #include -class GraphNativeBase : public UmdTest { +class GraphApi : public UmdTest { public: void SetUp() override { UmdTest::SetUp(); @@ -18,97 +18,166 @@ class GraphNativeBase : public UmdTest { GTEST_SKIP() << "No data to perform the test"; const YAML::Node node = Environment::getConfiguration("graph_execution")[0]; - ASSERT_GT(node["path"].as().size(), 0); - std::filesystem::path path = node["path"].as(); - - if (path.extension() == ".blob") { - ASSERT_TRUE( - loadBlobFromPath(globalConfig.blobDir + node["path"].as(), npuBlob)); - - graphDesc = {.stype = ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES, - .pNext = nullptr, - .format = ZE_GRAPH_FORMAT_NATIVE, - .inputSize = npuBlob.size(), - .pInput = reinterpret_cast(npuBlob.data()), - .pBuildFlags = nullptr, - .flags = ZE_GRAPH_FLAG_NONE}; - - } else { - ASSERT_GT(node["flags"].as().size(), 0); - - buildFlags = getFlagsFromString(node["flags"].as()); - createGraphDescriptorForModel(globalConfig.modelDir + node["path"].as(), - buildFlags, - modelIR, - graphDesc); - } + + graphBuffer = GraphBuffer::get(zeDevice, zeGraphDDITableExt, globalConfig, node); + ASSERT_NE(graphBuffer, nullptr); } - void TearDown() override { UmdTest::TearDown(); } + ze_result_t createCommandList(ze_command_list_handle_t *list) { + ze_command_list_desc_t cmdListDesc = {.stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC, + .pNext = nullptr, + .commandQueueGroupOrdinal = 0, + .flags = 0}; + + ze_result_t ret = {}; + auto scopeList = zeScope::commandListCreate(zeContext, zeDevice, cmdListDesc, ret); + lists.push_back(std::move(scopeList)); + *list = lists.back().get(); + return ret; + } - ze_graph_handle_t graphHandle = nullptr; - ze_result_t ret = ZE_RESULT_SUCCESS; - size_t size = 0; + std::shared_ptr graphBuffer; + std::vector> lists; +}; - std::vector npuBlob; +TEST_F(GraphApi, GetProfilingDataPropertiesExpectSuccess) { + ze_device_profiling_data_properties_t profProp = {}; + profProp.stype = ZE_STRUCTURE_TYPE_DEVICE_PROFILING_DATA_PROPERTIES; + EXPECT_EQ(zeGraphProfilingDDITableExt->pfnDeviceGetProfilingDataProperties(zeDevice, &profProp), + ZE_RESULT_SUCCESS); + EXPECT_EQ(profProp.extensionVersion, ZE_PROFILING_DATA_EXT_VERSION_CURRENT); +} - ze_graph_desc_2_t graphDesc = {}; - std::vector modelIR = {}; - std::vector buildFlags = {}; -}; +TEST_F(GraphApi, CreateGraphReturnsCorrectError) { + ze_graph_handle_t handle = nullptr; + EXPECT_EQ(zeGraphDDITableExt->pfnCreate2(zeContext, zeDevice, nullptr, &handle), + ZE_RESULT_ERROR_INVALID_NULL_POINTER); -TEST_F(GraphNativeBase, CreatingGraphWithNullptrInputGraph) { - graphDesc.pInput = nullptr; - EXPECT_EQ(zeGraphDDITableExt->pfnCreate2(zeContext, zeDevice, &graphDesc, &graphHandle), + ze_graph_desc_2_t desc = graphBuffer->desc; + desc.pInput = nullptr; + EXPECT_EQ(zeGraphDDITableExt->pfnCreate2(zeContext, zeDevice, &desc, &handle), ZE_RESULT_ERROR_INVALID_NULL_POINTER); + + desc = graphBuffer->desc; + desc.inputSize = 0u; + EXPECT_EQ(zeGraphDDITableExt->pfnCreate2(zeContext, zeDevice, &desc, &handle), + ZE_RESULT_ERROR_INVALID_SIZE); } -TEST_F(GraphNativeBase, CreatingGraphWithNullPtrDesc) { - const ze_graph_desc_2_t *graphDesc = nullptr; - EXPECT_EQ(zeGraphDDITableExt->pfnCreate2(zeContext, zeDevice, graphDesc, &graphHandle), - ZE_RESULT_ERROR_INVALID_NULL_POINTER); +TEST_F(GraphApi, GetNativeBinaryUsingMemcpy) { + auto graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, graphBuffer); + ASSERT_NE(graph, nullptr); + + size_t size = 0; + EXPECT_EQ(zeGraphDDITableExt->pfnGetNativeBinary(graph->handle, &size, nullptr), + ZE_RESULT_SUCCESS); + EXPECT_GT(size, 0); + + std::vector graphNativeBinary(size, 0); + EXPECT_EQ( + zeGraphDDITableExt->pfnGetNativeBinary(graph->handle, &size, graphNativeBinary.data()), + ZE_RESULT_SUCCESS); } -TEST_F(GraphNativeBase, GetProfilingDataPropertiesExpectSuccess) { - ze_device_profiling_data_properties_t pDeviceProfilingDataProperties; - EXPECT_EQ(zeGraphProfilingDDITableExt->pfnDeviceGetProfilingDataProperties( - zeDevice, - &pDeviceProfilingDataProperties), +TEST_F(GraphApi, GetNativeBinaryWithoutMemcpy) { + auto graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, graphBuffer); + ASSERT_NE(graph, nullptr); + + const uint8_t *graphNativeBinary = nullptr; + size_t size = 0; + EXPECT_EQ(zeGraphDDITableExt->pfnGetNativeBinary2(graph->handle, &size, &graphNativeBinary), ZE_RESULT_SUCCESS); + EXPECT_GT(size, 0); + EXPECT_NE(graphNativeBinary, nullptr); } -class GraphNativeBinary : public UmdTest { - public: - void SetUp() override { - UmdTest::SetUp(); +TEST_F(GraphApi, AppendGraphInitAndExecuteReturnsCorrectError) { + auto graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, graphBuffer); + ASSERT_NE(graph, nullptr); - if (!Environment::getConfiguration("graph_execution").size()) - GTEST_SKIP() << "No data to perform the test"; + ze_command_list_handle_t list = nullptr; + ASSERT_EQ(createCommandList(&list), ZE_RESULT_SUCCESS); + ASSERT_EQ(zeGraphDDITableExt->pfnAppendGraphInitialize(list, nullptr, nullptr, 0, nullptr), + ZE_RESULT_ERROR_UNINITIALIZED); + ASSERT_EQ( + zeGraphDDITableExt->pfnAppendGraphInitialize(list, graph->handle, nullptr, 0, nullptr), + ZE_RESULT_SUCCESS); + ASSERT_EQ(zeGraphDDITableExt + ->pfnAppendGraphExecute(list, graph->handle, nullptr, nullptr, 0, nullptr), + ZE_RESULT_ERROR_UNINITIALIZED); +} - const YAML::Node node = Environment::getConfiguration("graph_execution")[0]; +TEST_F(GraphApi, SetArgumentPropertiesReturnsCorrectError) { + auto graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, graphBuffer); + ASSERT_NE(graph, nullptr); - graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, globalConfig, node); + ze_graph_properties_t prop = {}; + prop.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES; + ASSERT_EQ(zeGraphDDITableExt->pfnGetProperties(graph->handle, &prop), ZE_RESULT_SUCCESS) + << "Failed to get Graph properties"; + + for (size_t index = 0; index < prop.numGraphArgs; index++) { + ASSERT_EQ(graph->setArgumentValue(index, nullptr), ZE_RESULT_ERROR_INVALID_NULL_POINTER); } - void TearDown() override { UmdTest::TearDown(); } + auto mem = AllocSharedMemory(graph->inputSize[0]); + ASSERT_EQ(graph->setArgumentValue(prop.numGraphArgs, mem.get()), + ZE_RESULT_ERROR_INVALID_ARGUMENT); +} - size_t size = 0; - std::shared_ptr graph; -}; +TEST_F(GraphApi, GetArgumentPropertiesReturnsCorrectProperties) { + auto graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, graphBuffer); + ASSERT_NE(graph, nullptr); -TEST_F(GraphNativeBinary, GetGraphNativeBinaryWithoutGraphNativeBinaryPointerExpectSuccess) { - EXPECT_EQ(zeGraphDDITableExt->pfnGetNativeBinary(graph->handle, &size, nullptr), - ZE_RESULT_SUCCESS); + ASSERT_EQ(zeGraphDDITableExt->pfnGetArgumentProperties(graph->handle, 0, nullptr), + ZE_RESULT_ERROR_INVALID_NULL_POINTER); + + ze_graph_properties_t graphProps = {}; + graphProps.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES; + + ASSERT_EQ(zeGraphDDITableExt->pfnGetProperties(graph->handle, &graphProps), ZE_RESULT_SUCCESS) + << "Failed to get Graph properties"; + + ze_graph_argument_properties_t pGraphArgumentProperties = {}; + graphProps.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES; + + for (uint32_t index = 0; index < graphProps.numGraphArgs; index++) { + ASSERT_EQ(zeGraphDDITableExt->pfnGetArgumentProperties(graph->handle, + index, + &pGraphArgumentProperties), + ZE_RESULT_SUCCESS); + if (index == 0) { + ASSERT_EQ(pGraphArgumentProperties.type, ZE_GRAPH_ARGUMENT_TYPE_INPUT); + } else if (index == graphProps.numGraphArgs - 1) { + ASSERT_EQ(pGraphArgumentProperties.type, ZE_GRAPH_ARGUMENT_TYPE_OUTPUT); + } else if (pGraphArgumentProperties.type != ZE_GRAPH_ARGUMENT_TYPE_INPUT && + pGraphArgumentProperties.type != ZE_GRAPH_ARGUMENT_TYPE_OUTPUT) { + FAIL() << "Invalid graph argument type"; + } + + for (int i = 0; i < ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE; i++) + ASSERT_GT(pGraphArgumentProperties.dims[i], 0u); + ASSERT_GE(pGraphArgumentProperties.networkLayout, ZE_GRAPH_ARGUMENT_LAYOUT_ANY); + ASSERT_NE(pGraphArgumentProperties.networkPrecision, ZE_GRAPH_ARGUMENT_PRECISION_UNKNOWN); + ASSERT_NE(pGraphArgumentProperties.networkPrecision, ZE_GRAPH_ARGUMENT_PRECISION_BIN); + ASSERT_GE(pGraphArgumentProperties.deviceLayout, ZE_GRAPH_ARGUMENT_LAYOUT_ANY); + ASSERT_NE(pGraphArgumentProperties.devicePrecision, ZE_GRAPH_ARGUMENT_PRECISION_UNKNOWN); + ASSERT_NE(pGraphArgumentProperties.devicePrecision, ZE_GRAPH_ARGUMENT_PRECISION_BIN); + } + + ASSERT_EQ(zeGraphDDITableExt->pfnGetArgumentProperties(graph->handle, + graphProps.numGraphArgs, + &pGraphArgumentProperties), + ZE_RESULT_ERROR_INVALID_ARGUMENT); } -TEST_F(GraphNativeBinary, GetGraphNativeBinaryWithAndWithoutGraphNativeBinaryPointerExpectSuccess) { - std::vector graphNativeBinary; - EXPECT_EQ(zeGraphDDITableExt->pfnGetNativeBinary(graph->handle, &size, nullptr), - ZE_RESULT_SUCCESS); - graphNativeBinary.resize(size, 0xAA); +TEST_F(GraphApi, GetProperties2) { + auto graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, graphBuffer); + ASSERT_NE(graph, nullptr); - EXPECT_EQ( - zeGraphDDITableExt->pfnGetNativeBinary(graph->handle, &size, graphNativeBinary.data()), - ZE_RESULT_SUCCESS); + ze_graph_properties_2_t graphProps = {}; + graphProps.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES; + ASSERT_EQ(zeGraphDDITableExt->pfnGetProperties2(graph->handle, &graphProps), ZE_RESULT_SUCCESS) + << "Failed to get Graph properties"; } diff --git a/validation/umd-test/test_graph_cid.cpp b/validation/umd-test/test_graph_cid.cpp index c9ac980..1d9c3f9 100644 --- a/validation/umd-test/test_graph_cid.cpp +++ b/validation/umd-test/test_graph_cid.cpp @@ -6,130 +6,18 @@ */ #include "graph_utilities.hpp" -#include "umd_prime_buffers.h" +#include "umd_dma_heap_system.hpp" #include +#include #include #include #include -class CompilerInDriverBase : public UmdTest { - protected: - void SetUp() override { UmdTest::SetUp(); } - - zeScope::SharedPtr scopedGraphHandle = nullptr; - ze_graph_desc_2_t graphDesc = {}; - std::vector modelIR = {}; - std::vector buildFlags = {}; -}; - -class CompilerInDriver : public CompilerInDriverBase { - public: - void SetUp() override { - CompilerInDriverBase::SetUp(); - auto cfgNodes = Environment::getConfiguration("graph_execution"); - - if (cfgNodes.size() == 0) - SKIP_("Missing models for testing"); - - const YAML::Node node = cfgNodes.at(0); - - /* Validate configuration */ - ASSERT_GT(node["path"].as().size(), 0); - ASSERT_GT(node["flags"].as().size(), 0); - - /* Setup */ - buildFlags = getFlagsFromString(node["flags"].as()); - createGraphDescriptorForModel(globalConfig.modelDir + node["path"].as(), - buildFlags, - modelIR, - graphDesc); - } -}; - -TEST_F(CompilerInDriver, CreatingGraphWithNullptrInputGraphExpectFailure) { - ze_graph_handle_t handle = nullptr; - graphDesc.pInput = nullptr; - EXPECT_EQ(zeGraphDDITableExt->pfnCreate2(zeContext, zeDevice, &graphDesc, &handle), - ZE_RESULT_ERROR_INVALID_NULL_POINTER); -} - -TEST_F(CompilerInDriver, CreatingGraphWithZeroGraphSizeExpectFailure) { - ze_graph_handle_t handle = nullptr; - graphDesc.inputSize = 0u; - EXPECT_EQ(zeGraphDDITableExt->pfnCreate2(zeContext, zeDevice, &graphDesc, &handle), - ZE_RESULT_ERROR_INVALID_SIZE); -} - -TEST_F(CompilerInDriver, CreatingGraphCorrectBlobFileAndDescExpectSuccess) { - ze_result_t ret = ZE_RESULT_SUCCESS; - scopedGraphHandle = - zeScope::graphCreate2(zeGraphDDITableExt, zeContext, zeDevice, graphDesc, ret); - EXPECT_EQ(ret, ZE_RESULT_SUCCESS); -} - -class CompilerInDriverLayers : public CompilerInDriverBase, - public ::testing::WithParamInterface { - protected: - void SetUp() override { - CompilerInDriverBase::SetUp(); - - const YAML::Node node = GetParam(); - - /* Validate configuration */ - ASSERT_GT(node["path"].as().size(), 0); - std::filesystem::path path = node["path"].as(); - - if (path.extension() == ".blob") { - SKIP_("The test is not intended for use with a precompiled blob."); - } - - ASSERT_GT(node["flags"].as().size(), 0); - - /* Setup */ - buildFlags = getFlagsFromString(node["flags"].as()); - createGraphDescriptorForModel(globalConfig.modelDir + node["path"].as(), - buildFlags, - modelIR, - graphDesc); - } -}; - -GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CompilerInDriverLayers); - -INSTANTIATE_TEST_SUITE_P(, - CompilerInDriverLayers, - ::testing::ValuesIn(Environment::getConfiguration("graph_execution")), - [](const testing::TestParamInfo &p) { - return generateTestNameFromNode(p.param); - }); - -TEST_P(CompilerInDriverLayers, QueryNetworkLayers) { - ze_graph_query_network_handle_t hQuery = nullptr; - - ASSERT_EQ(zeGraphDDITableExt->pfnQueryNetworkCreate2(zeContext, zeDevice, &graphDesc, &hQuery), - ZE_RESULT_SUCCESS); - - size_t size = 0; - EXPECT_EQ(zeGraphDDITableExt->pfnQueryNetworkGetSupportedLayers(hQuery, &size, nullptr), - ZE_RESULT_SUCCESS); - EXPECT_GT(size, 0); - - std::vector layers(size, '\0'); - EXPECT_EQ(zeGraphDDITableExt->pfnQueryNetworkGetSupportedLayers(hQuery, &size, layers.data()), - ZE_RESULT_SUCCESS); - - EXPECT_GT(layers.size(), 0); - - TRACE("Supported layers: %s\n", layers.data()); - - ASSERT_EQ(zeGraphDDITableExt->pfnQueryNetworkDestroy(hQuery), ZE_RESULT_SUCCESS); -} - -class CompilerInDriverLongT : public CompilerInDriverBase { +class CompilerInDriverLongT : public UmdTest { protected: void SetUp() override { - CompilerInDriverBase::SetUp(); + UmdTest::SetUp(); ze_result_t ret = ZE_RESULT_SUCCESS; scopedQueue = zeScope::commandQueueCreate(zeContext, zeDevice, cmdQueueDesc, ret); @@ -386,12 +274,11 @@ TEST_P(CompilerInDriverLongBmp, CompileModelWithGraphInitAndExecuteThenCheckAccu graph->checkResults(); } -class CompilerInDriverBmpWithPrimeBuffers : public CompilerInDriverLongBmp { +class CompilerInDriverBmpUsingDmaHeap : public CompilerInDriverLongBmp { public: void SetUp() override { - if (!primeHelper.hasDMABufferSupport()) - GTEST_SKIP() << "Missed support or insufficient permissions for" - << " dma buffer allocation in the system. Skip test"; + CHECK_DMA_HEAP_SUPPORT(dmaHeapSystem); + CompilerInDriverLongT::SetUp(); const YAML::Node node = GetParam(); @@ -404,28 +291,34 @@ class CompilerInDriverBmpWithPrimeBuffers : public CompilerInDriverLongBmp { } /* Create list of DMA memory buffers outside driver and use it as network inputs */ + ze_external_memory_import_fd_t externalImportFromFdDesc = { + .stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMPORT_FD, + .pNext = nullptr, + .flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF, + .fd = -1}; ze_device_mem_alloc_desc_t pDeviceMemAllocDesc = { .stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC, - .pNext = &primeHelper.externalImportFromFdDesc, + .pNext = &externalImportFromFdDesc, .flags = 0, .ordinal = 0}; - dmaBuffers.resize(graph->inputSize.size(), nullptr); + + dmaBuffers.resize(graph->inputSize.size()); + uint32_t argIndex = 0; uint32_t bufferIndex = 0; for (auto &dmaBuffer : dmaBuffers) { size_t size = graph->inputSize[bufferIndex++]; ze_result_t ret; - int32_t dmaBufferFd = -1; - ASSERT_TRUE(primeHelper.createDMABuffer(size, dmaBufferFd)); - ASSERT_GE(dmaBufferFd, 0); - dmaBuffer = primeHelper.mmapDmaBuffer(dmaBufferFd); + + dmaBuffer = dmaHeapSystem.allocDmaHeapBuffer(size); + ASSERT_TRUE(dmaBuffer); + /* Import buffer as device memory */ - primeHelper.externalImportFromFdDesc.fd = dmaBufferFd; + externalImportFromFdDesc.fd = dmaBuffer->fd; auto scopedImportedMemory = zeScope::memAllocDevice(zeContext, pDeviceMemAllocDesc, size, 0, zeDevice, ret); ASSERT_EQ(ret, ZE_RESULT_SUCCESS); - ASSERT_NE(scopedImportedMemory.get(), nullptr); /* Set as input imported buffer, alocated by device alloc from dma file descriptor it should consit image loaded above */ @@ -442,20 +335,20 @@ class CompilerInDriverBmpWithPrimeBuffers : public CompilerInDriverLongBmp { UmdTest::TearDown(); } - std::vector dmaBuffers; + std::vector> dmaBuffers; std::vector> importedGraphInput; - PrimeBufferHelper primeHelper; + DmaHeapSystem dmaHeapSystem; }; -GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CompilerInDriverBmpWithPrimeBuffers); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CompilerInDriverBmpUsingDmaHeap); INSTANTIATE_TEST_SUITE_P( , - CompilerInDriverBmpWithPrimeBuffers, + CompilerInDriverBmpUsingDmaHeap, ::testing::ValuesIn(Environment::getConfiguration("image_classification_imagenet")), [](const testing::TestParamInfo &p) { return generateTestNameFromNode(p.param); }); -TEST_P(CompilerInDriverBmpWithPrimeBuffers, CompileInitExecuteUsingPrimeBufferInput) { +TEST_P(CompilerInDriverBmpUsingDmaHeap, CompileInitExecuteUsingPrimeBufferInput) { ASSERT_EQ( zeGraphDDITableExt->pfnAppendGraphInitialize(list, graph->handle, nullptr, 0, nullptr), ZE_RESULT_SUCCESS); @@ -465,7 +358,10 @@ TEST_P(CompilerInDriverBmpWithPrimeBuffers, CompileInitExecuteUsingPrimeBufferIn ASSERT_EQ(zeCommandListReset(list), ZE_RESULT_SUCCESS); - graph->copyInputData(dmaBuffers); + std::vector inputPointers; + for (auto &dmaBuffer : dmaBuffers) + inputPointers.emplace_back(dmaBuffer->ptr); + graph->copyInputData(inputPointers); ASSERT_EQ(zeGraphDDITableExt ->pfnAppendGraphExecute(list, graph->handle, nullptr, nullptr, 0, nullptr), @@ -477,20 +373,42 @@ TEST_P(CompilerInDriverBmpWithPrimeBuffers, CompileInitExecuteUsingPrimeBufferIn graph->checkResults(); } +#define BREAK_ON_FAIL(ret, stats) \ + if (ret != ZE_RESULT_SUCCESS) { \ + EXPECT_EQ(ret, ZE_RESULT_SUCCESS); \ + stats.status = ret; \ + return stats; \ + } + class CompilerInDriverMultiInference : public CompilerInDriverLongT, public ::testing::WithParamInterface { public: - struct localInference { + struct LocalInference { + LocalInference(const YAML::Node &node) + : model(node){}; + const YAML::Node model; std::string modelName; std::shared_ptr graph; - uint32_t time; - uint32_t targetFps; + uint32_t time = 0; + uint32_t targetFps = 0; + double fpsDeviation = 0; ze_command_queue_priority_t priority = ZE_COMMAND_QUEUE_PRIORITY_NORMAL; + ze_command_queue_workload_type_t workloadType = ZE_WORKLOAD_TYPE_FORCE_UINT32; size_t delayInUs = 0; }; - std::vector testInferences = {}; + struct InferenceStats { + ze_result_t status = ZE_RESULT_SUCCESS; + int totalFrames = 0; + int droppedFrames = 0; + double realFPS = 0; + double minExecTimePerFrame = DBL_MAX; + double avgExecTimePerFrame = 0; + double maxExecTimePerFrame = 0; + }; + + std::vector testInferences = {}; void SetUp() override { CompilerInDriverLongT::SetUp(); @@ -501,7 +419,7 @@ class CompilerInDriverMultiInference : public CompilerInDriverLongT, SKIP_("Missing models for testing"); for (auto &model : modelsSet) { - localInference inference; + LocalInference inference(model); if (model["target_fps"].IsDefined()) inference.targetFps = model["target_fps"].as(); @@ -519,6 +437,19 @@ class CompilerInDriverMultiInference : public CompilerInDriverLongT, if (model["delay_in_us"].IsDefined()) inference.delayInUs = model["delay_in_us"].as(); + if (model["workload_type"].IsDefined() && + model["workload_type"].as().size()) { + if (model["workload_type"].as().compare("default") == 0) + inference.workloadType = ZE_WORKLOAD_TYPE_DEFAULT; + else if (model["workload_type"].as().compare("background") == 0) + inference.workloadType = ZE_WORKLOAD_TYPE_BACKGROUND; + else + FAIL() << "Unsupported workload type in configuration"; + } + + if (model["fps_deviation"].IsDefined()) + inference.fpsDeviation = model["fps_deviation"].as(); + std::shared_ptr graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, globalConfig, model); @@ -539,42 +470,12 @@ class CompilerInDriverMultiInference : public CompilerInDriverLongT, } throw std::runtime_error("Invalid priority, should be: high, low or normal"); } -}; - -GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CompilerInDriverMultiInference); - -INSTANTIATE_TEST_SUITE_P(, - CompilerInDriverMultiInference, - ::testing::ValuesIn(Environment::getConfiguration("multi_inference")), - [](const testing::TestParamInfo &p) { - return p.param["name"].as(); - }); - -#define BREAK_ON_FAIL(ret, stats) \ - if (ret != ZE_RESULT_SUCCESS) { \ - EXPECT_EQ(ret, ZE_RESULT_SUCCESS); \ - stats.status = ret; \ - return stats; \ - } - -TEST_P(CompilerInDriverMultiInference, Pipeline) { - struct InferenceStats { - ze_result_t status; - int totalFrames = 0; - int droppedFrames = 0; - double realFPS = 0; - double minExecTimePerFrame; - double avgExecTimePerFrame; - double maxExecTimePerFrame; - }; - auto runInference = - [&](const CompilerInDriverMultiInference::localInference &inference) -> InferenceStats { + InferenceStats runInference(const CompilerInDriverMultiInference::LocalInference &inference) { ze_result_t ret = ZE_RESULT_SUCCESS; InferenceStats stats = {}; - - stats.status = ZE_RESULT_SUCCESS; - stats.minExecTimePerFrame = DBL_MAX; + ze_command_queue_workload_type_t workloadType = inference.workloadType; + auto ddi = Environment::getInstance()->getCommandQueueDDITable(); auto cmdQueueDescInference = cmdQueueDesc; cmdQueueDescInference.priority = inference.priority; @@ -607,6 +508,19 @@ TEST_P(CompilerInDriverMultiInference, Pipeline) { ret = zeCommandQueueSynchronize(queue, graphSyncTimeout); BREAK_ON_FAIL(ret, stats); + /*For the case when config request workload type all inferences are started + as background, the requested workload will be set after first inference loop + */ + if (workloadType != ZE_WORKLOAD_TYPE_FORCE_UINT32) { + ret = ddi->pfnSetWorkloadType(queue, ZE_WORKLOAD_TYPE_BACKGROUND); + BREAK_ON_FAIL(ret, stats); + ret = zeCommandQueueExecuteCommandLists(queue, 1, &list, nullptr); + BREAK_ON_FAIL(ret, stats); + + ret = zeCommandQueueSynchronize(queue, graphSyncTimeout); + BREAK_ON_FAIL(ret, stats); + } + ret = zeCommandListReset(list); BREAK_ON_FAIL(ret, stats); @@ -642,7 +556,11 @@ TEST_P(CompilerInDriverMultiInference, Pipeline) { queue, std::chrono::nanoseconds(std::chrono::seconds(inference.time)).count()); BREAK_ON_FAIL(ret, stats); - + if (workloadType != ZE_WORKLOAD_TYPE_FORCE_UINT32) { + ret = ddi->pfnSetWorkloadType(queue, workloadType); + BREAK_ON_FAIL(ret, stats); + workloadType = ZE_WORKLOAD_TYPE_FORCE_UINT32; + } nextFrameStartPoint = frameBegin + frameTargetTimeUs; std::chrono::duration durationMs = @@ -667,12 +585,30 @@ TEST_P(CompilerInDriverMultiInference, Pipeline) { stats.avgExecTimePerFrame /= stats.totalFrames; return stats; - }; // end of runInference + }; +}; + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CompilerInDriverMultiInference); + +INSTANTIATE_TEST_SUITE_P(, + CompilerInDriverMultiInference, + ::testing::ValuesIn(Environment::getConfiguration("multi_inference")), + [](const testing::TestParamInfo &p) { + return p.param["name"].as(); + }); + +TEST_P(CompilerInDriverMultiInference, Pipeline) { + auto testInference = + [&](const CompilerInDriverMultiInference::LocalInference &inference) -> InferenceStats { + return runInference(inference); + }; std::vector> results; for (size_t i = 0; i < testInferences.size(); i++) - results.push_back(std::async(std::launch::async, runInference, testInferences[i])); + results.push_back(std::async(std::launch::async, testInference, testInferences[i])); + std::pair defaultFPSInferencesRate = {0, 0}; + std::pair backgroundFPSInferencesRate = {0, 0}; for (size_t i = 0; i < results.size(); i++) { InferenceStats stats = results[i].get(); @@ -688,5 +624,33 @@ TEST_P(CompilerInDriverMultiInference, Pipeline) { PRINTF("MinFrameExecTime[ms]: %f \n", stats.minExecTimePerFrame); PRINTF("AvgFrameExecTime[ms]: %f \n", stats.avgExecTimePerFrame); PRINTF("MaxFrameExecTime[ms]: %f \n", stats.maxExecTimePerFrame); + + /*If defined acceptance criteraia for fps rate*/ + if (testInferences[i].fpsDeviation) { + const double minFPS = + testInferences[i].targetFps * (1 - testInferences[i].fpsDeviation); + EXPECT_GE(static_cast(stats.realFPS), minFPS); + } + + if (testInferences[i].workloadType == ZE_WORKLOAD_TYPE_DEFAULT) { + defaultFPSInferencesRate.first += stats.realFPS; + defaultFPSInferencesRate.second++; + } + if (testInferences[i].workloadType == ZE_WORKLOAD_TYPE_BACKGROUND) { + backgroundFPSInferencesRate.first += stats.realFPS; + backgroundFPSInferencesRate.second++; + } + } + + /* For test with dynamic priority change when focus is set on dedicated inference there + is acceptance criteria that focused inference will be min 30% more effective + */ + if (isHwsModeEnabled() && defaultFPSInferencesRate.second != 0 && + backgroundFPSInferencesRate.second != 0) { + const double avgRateDefaultInferences = + defaultFPSInferencesRate.first / defaultFPSInferencesRate.second; + const double avgRateBackgroundInferences = + backgroundFPSInferencesRate.first / backgroundFPSInferencesRate.second; + EXPECT_GE(avgRateDefaultInferences, avgRateBackgroundInferences * 1.30); } } diff --git a/validation/umd-test/test_graph_commands.cpp b/validation/umd-test/test_graph_commands.cpp index e895947..7658a59 100644 --- a/validation/umd-test/test_graph_commands.cpp +++ b/validation/umd-test/test_graph_commands.cpp @@ -5,7 +5,6 @@ * */ -#include "drm_helpers.h" #include "graph_utilities.hpp" #include @@ -85,85 +84,6 @@ class CommandGraph : public CommandGraphBase { } }; -TEST_F(CommandGraph, AppendGraphInitWithNullGraphHandle) { - ASSERT_EQ(zeGraphDDITableExt->pfnAppendGraphInitialize(list, nullptr, nullptr, 0, nullptr), - ZE_RESULT_ERROR_UNINITIALIZED); -} - -TEST_F(CommandGraph, AppendGraphInitExecuteWithoutSettingArgumentForInputOutput) { - ASSERT_EQ( - zeGraphDDITableExt->pfnAppendGraphInitialize(list, graph->handle, nullptr, 0, nullptr), - ZE_RESULT_SUCCESS); - ASSERT_EQ(zeGraphDDITableExt - ->pfnAppendGraphExecute(list, graph->handle, nullptr, nullptr, 0, nullptr), - ZE_RESULT_ERROR_UNINITIALIZED); -} - -TEST_F(CommandGraph, SettingNullArgumentForInputOutput) { - ze_graph_properties_t graphProps = {}; - graphProps.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES; - ASSERT_EQ(zeGraphDDITableExt->pfnGetProperties(graph->handle, &graphProps), ZE_RESULT_SUCCESS) - << "Failed to get Graph properties"; - - for (size_t index = 0; index < graphProps.numGraphArgs; index++) { - ASSERT_EQ(graph->setArgumentValue(index, nullptr), ZE_RESULT_ERROR_INVALID_NULL_POINTER); - } -} - -TEST_F(CommandGraph, SetArgumentIndexGreaterThanExpectedArgumentIndexLimit) { - ze_graph_properties_t graphProps = {}; - graphProps.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES; - ASSERT_EQ(zeGraphDDITableExt->pfnGetProperties(graph->handle, &graphProps), ZE_RESULT_SUCCESS) - << "Failed to get Graph properties"; - - graph->allocateInputArguments(MemType::SHARED_MEMORY); - ASSERT_EQ(graph->setArgumentValue(graphProps.numGraphArgs, graph->inArgs.at(0)), - ZE_RESULT_ERROR_INVALID_ARGUMENT); -} - -TEST_F(CommandGraph, GetArgumentPropertiesReturnsExpectedProperties) { - ASSERT_EQ(zeGraphDDITableExt->pfnGetArgumentProperties(graph->handle, 0, nullptr), - ZE_RESULT_ERROR_INVALID_NULL_POINTER); - - ze_graph_properties_t graphProps = {}; - graphProps.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES; - - ASSERT_EQ(zeGraphDDITableExt->pfnGetProperties(graph->handle, &graphProps), ZE_RESULT_SUCCESS) - << "Failed to get Graph properties"; - - ze_graph_argument_properties_t pGraphArgumentProperties = {}; - graphProps.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES; - - for (uint32_t index = 0; index < graphProps.numGraphArgs; index++) { - ASSERT_EQ(zeGraphDDITableExt->pfnGetArgumentProperties(graph->handle, - index, - &pGraphArgumentProperties), - ZE_RESULT_SUCCESS); - if (index == 0) { - ASSERT_EQ(pGraphArgumentProperties.type, ZE_GRAPH_ARGUMENT_TYPE_INPUT); - } else if (index == graphProps.numGraphArgs - 1) { - ASSERT_EQ(pGraphArgumentProperties.type, ZE_GRAPH_ARGUMENT_TYPE_OUTPUT); - } else if (pGraphArgumentProperties.type != ZE_GRAPH_ARGUMENT_TYPE_INPUT && - pGraphArgumentProperties.type != ZE_GRAPH_ARGUMENT_TYPE_OUTPUT) { - FAIL() << "Invalid graph argument type"; - } - - for (int i = 0; i < ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE; i++) - ASSERT_GT(pGraphArgumentProperties.dims[i], 0u); - ASSERT_GE(pGraphArgumentProperties.networkLayout, ZE_GRAPH_ARGUMENT_LAYOUT_ANY); - ASSERT_NE(pGraphArgumentProperties.networkPrecision, ZE_GRAPH_ARGUMENT_PRECISION_UNKNOWN); - ASSERT_NE(pGraphArgumentProperties.networkPrecision, ZE_GRAPH_ARGUMENT_PRECISION_BIN); - ASSERT_GE(pGraphArgumentProperties.deviceLayout, ZE_GRAPH_ARGUMENT_LAYOUT_ANY); - ASSERT_NE(pGraphArgumentProperties.devicePrecision, ZE_GRAPH_ARGUMENT_PRECISION_UNKNOWN); - ASSERT_NE(pGraphArgumentProperties.devicePrecision, ZE_GRAPH_ARGUMENT_PRECISION_BIN); - } - - ASSERT_EQ(zeGraphDDITableExt->pfnGetArgumentProperties(graph->handle, - graphProps.numGraphArgs, - &pGraphArgumentProperties), - ZE_RESULT_ERROR_INVALID_ARGUMENT); -} - class CommandGraphLong : public CommandGraphBase, public ::testing::WithParamInterface { protected: void SetUp() override { @@ -339,6 +259,21 @@ TEST_P(CommandGraphLong, RunGraphExecuteThreeTimes) { } } +TEST_P(CommandGraphLong, RunInferenceWithGraphInitialize) { + ASSERT_EQ(zeGraphDDITableExt->pfnGraphInitialize(graph->handle), ZE_RESULT_SUCCESS); + + ASSERT_EQ(zeGraphDDITableExt + ->pfnAppendGraphExecute(list, graph->handle, nullptr, nullptr, 0, nullptr), + ZE_RESULT_SUCCESS); + ASSERT_EQ(zeCommandListClose(list), ZE_RESULT_SUCCESS); + + ASSERT_EQ(zeCommandQueueExecuteCommandLists(queue, 1, &list, nullptr), ZE_RESULT_SUCCESS); + ASSERT_EQ(zeCommandQueueSynchronize(queue, graphSyncTimeout), ZE_RESULT_SUCCESS); + + graph->checkResults(); + graph->clearOutput(); +} + TEST_P(CommandGraphLong, SingleListGraphExecutionWithBarrierTest) { std::vector> mem; std::vector inputHostMem, outputHostMem; @@ -540,11 +475,7 @@ TEST_P(CommandGraphLong, GraphInitAndExecWith200msDelay) { } static void resetDevice() { - drm_device_desc desc = drm::open_intel_vpu(); - close(desc.fd); - - std::string path = "/sys/dev/char/" + std::to_string(desc.major_id) + ":" + - std::to_string(desc.minor_id) + "/device/reset"; + std::string path = getDeviceSysFsDirectory() + "/reset"; int fd = open(path.c_str(), O_WRONLY); ASSERT_NE(fd, -1); @@ -593,6 +524,70 @@ TEST_P(CommandGraphLong, InferenceDeviceResetInference) { graph->checkResults(); } +TEST_P(CommandGraphLong, ReleaseNativeBinaryAfterAppendGraphInitializeRunInference) { + // Convert model to native format + auto nativeGraphBuffer = graph->getNativeBinaryAsNewBuffer(); + ASSERT_NE(nativeGraphBuffer, nullptr) << "Unable to get native binary from Graph"; + + // Swap the graph with native format type + graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, nativeGraphBuffer); + ASSERT_NE(graph, nullptr) << "Unable to create new Graph object from native binary"; + + graph->allocateArguments(MemType::SHARED_MEMORY); + graph->copyInputData(); + + ASSERT_EQ( + zeGraphDDITableExt->pfnAppendGraphInitialize(list, graph->handle, nullptr, 0, nullptr), + ZE_RESULT_SUCCESS); + ASSERT_EQ(zeCommandListClose(list), ZE_RESULT_SUCCESS); + ASSERT_EQ(zeCommandQueueExecuteCommandLists(queue, 1, &list, nullptr), ZE_RESULT_SUCCESS); + ASSERT_EQ(zeCommandQueueSynchronize(queue, graphSyncTimeout), ZE_RESULT_SUCCESS); + + // Release the blob container + nativeGraphBuffer.reset(); + + ASSERT_EQ(zeCommandListReset(list), ZE_RESULT_SUCCESS); + ASSERT_EQ(zeGraphDDITableExt + ->pfnAppendGraphExecute(list, graph->handle, nullptr, nullptr, 0, nullptr), + ZE_RESULT_SUCCESS); + ASSERT_EQ(zeCommandListClose(list), ZE_RESULT_SUCCESS); + + ASSERT_EQ(zeCommandQueueExecuteCommandLists(queue, 1, &list, nullptr), ZE_RESULT_SUCCESS); + ASSERT_EQ(zeCommandQueueSynchronize(queue, graphSyncTimeout), ZE_RESULT_SUCCESS); + + // TODO: New graph does not have information about ref input/output. It is forced to random + graph->checkResults(); +} + +TEST_P(CommandGraphLong, ReleaseNativeBinaryAfterGraphInitializeRunInference) { + // Convert model to native format + auto nativeGraphBuffer = graph->getNativeBinaryAsNewBuffer(); + ASSERT_NE(nativeGraphBuffer, nullptr) << "Unable to get native binary from Graph"; + + // Swap the graph with native format type + graph = Graph::create(zeContext, zeDevice, zeGraphDDITableExt, nativeGraphBuffer); + ASSERT_NE(graph, nullptr) << "Unable to create new Graph object from native binary"; + + graph->allocateArguments(MemType::SHARED_MEMORY); + graph->copyInputData(); + + ASSERT_EQ(zeGraphDDITableExt->pfnGraphInitialize(graph->handle), ZE_RESULT_SUCCESS); + + // Release the blob container + nativeGraphBuffer.reset(); + + ASSERT_EQ(zeGraphDDITableExt + ->pfnAppendGraphExecute(list, graph->handle, nullptr, nullptr, 0, nullptr), + ZE_RESULT_SUCCESS); + ASSERT_EQ(zeCommandListClose(list), ZE_RESULT_SUCCESS); + + ASSERT_EQ(zeCommandQueueExecuteCommandLists(queue, 1, &list, nullptr), ZE_RESULT_SUCCESS); + ASSERT_EQ(zeCommandQueueSynchronize(queue, graphSyncTimeout), ZE_RESULT_SUCCESS); + + // TODO: New graph does not have information about ref input/output. It is forced to random + graph->checkResults(); +} + class CommandGraphLongThreaded : public CommandGraphBase, public ::testing::WithParamInterface> {}; @@ -758,7 +753,7 @@ TEST_P(CommandGraphLong, MutableCmdList) { ze_command_list_desc_t commandListDesc{ .stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC, .pNext = &mutableListDesc, - .commandQueueGroupOrdinal = computeGrpOrdinal, + .commandQueueGroupOrdinal = 0u, .flags = 0, }; ze_command_list_handle_t mutableList; diff --git a/validation/umd-test/test_graph_query.cpp b/validation/umd-test/test_graph_query.cpp new file mode 100644 index 0000000..6df7ceb --- /dev/null +++ b/validation/umd-test/test_graph_query.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2022-2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "graph_utilities.hpp" + +class GraphQueryNetwork : public UmdTest, public ::testing::WithParamInterface { + protected: + void SetUp() override { + UmdTest::SetUp(); + + const YAML::Node node = GetParam(); + + /* Validate configuration */ + ASSERT_GT(node["path"].as().size(), 0); + std::filesystem::path path = node["path"].as(); + if (path.extension() == ".blob") { + SKIP_("The test is not intended for use with a precompiled blob."); + } + + ASSERT_GT(node["flags"].as().size(), 0); + + graphBuffer = GraphBuffer::get(zeDevice, zeGraphDDITableExt, globalConfig, node); + ASSERT_NE(graphBuffer, nullptr); + } + + std::shared_ptr graphBuffer; +}; + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphQueryNetwork); + +INSTANTIATE_TEST_SUITE_P(, + GraphQueryNetwork, + ::testing::ValuesIn(Environment::getConfiguration("graph_execution")), + [](const testing::TestParamInfo &p) { + return generateTestNameFromNode(p.param); + }); + +TEST_P(GraphQueryNetwork, GetSupportedLayers) { + ze_graph_query_network_handle_t hQuery = nullptr; + + ASSERT_EQ(zeGraphDDITableExt->pfnQueryNetworkCreate2(zeContext, + zeDevice, + &graphBuffer->desc, + &hQuery), + ZE_RESULT_SUCCESS); + + size_t size = 0; + EXPECT_EQ(zeGraphDDITableExt->pfnQueryNetworkGetSupportedLayers(hQuery, &size, nullptr), + ZE_RESULT_SUCCESS); + EXPECT_GT(size, 0); + + std::vector layers(size, '\0'); + EXPECT_EQ(zeGraphDDITableExt->pfnQueryNetworkGetSupportedLayers(hQuery, &size, layers.data()), + ZE_RESULT_SUCCESS); + + EXPECT_GT(layers.size(), 0); + TRACE("Supported layers: %s\n", layers.data()); + + ASSERT_EQ(zeGraphDDITableExt->pfnQueryNetworkDestroy(hQuery), ZE_RESULT_SUCCESS); +} diff --git a/validation/umd-test/test_metric.cpp b/validation/umd-test/test_metric.cpp index 566bec4..7449d7f 100644 --- a/validation/umd-test/test_metric.cpp +++ b/validation/umd-test/test_metric.cpp @@ -211,7 +211,7 @@ class MetricQuery : public Metric, public ::testing::WithParamInterface queryIndexesCopyEngine = {0}; +std::vector queryIndexes = {0}; -GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MetricQueryCopyEngine); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MetricQueryMemoryCopy); INSTANTIATE_TEST_SUITE_P( , - MetricQueryCopyEngine, - ::testing::ValuesIn(MetricQueryCopyEngine::createCasesForMetricsTest(queryIndexesCopyEngine)), + MetricQueryMemoryCopy, + ::testing::ValuesIn(MetricQueryMemoryCopy::createCasesForMetricsTest(queryIndexes)), [](const testing::TestParamInfo &p) { auto metricGroupName = std::get<1>(p.param); auto queryIndex = std::get<2>(p.param); return metricGroupName + "_OnIndex" + std::to_string(queryIndex); }); -TEST_P(MetricQueryCopyEngine, GetDataValue) { +TEST_P(MetricQueryMemoryCopy, GetDataValue) { auto &[node, metricGroupName, queryIndex] = GetParam(); const size_t allocSize = 2048 * 1024; @@ -480,7 +464,7 @@ TEST_P(MetricQueryCopyEngine, GetDataValue) { dstMem = AllocSharedMemory(allocSize); uint32_t groupIndex = findMetricGroupIndex(metricGroupName); - MetricInitialize(groupIndex, queryIndex, copyGrpOrdinal); + MetricInitialize(groupIndex, queryIndex); ASSERT_EQ(zetCommandListAppendMetricQueryBegin(list, query), ZE_RESULT_SUCCESS); ASSERT_EQ(zeCommandListAppendMemoryCopy(list, diff --git a/validation/umd-test/test_metric_streamer.cpp b/validation/umd-test/test_metric_streamer.cpp index ce3c11b..aac78f0 100644 --- a/validation/umd-test/test_metric_streamer.cpp +++ b/validation/umd-test/test_metric_streamer.cpp @@ -28,9 +28,8 @@ class MetricStreamer : public UmdTest, public ::testing::WithParamInterface createCasesForMetricsTest(std::vector &executionTime) { std::vector combinations; @@ -463,21 +455,21 @@ class MetricStreamerCopyEngine : public MetricStreamer { } }; -std::vector execTimeCopyEngineMs = {20, 100}; +std::vector execTimeMs = {20, 100}; -GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MetricStreamerCopyEngine); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MetricStreamerMemoryCopy); INSTANTIATE_TEST_SUITE_P( , - MetricStreamerCopyEngine, - ::testing::ValuesIn(MetricStreamerCopyEngine::createCasesForMetricsTest(execTimeCopyEngineMs)), + MetricStreamerMemoryCopy, + ::testing::ValuesIn(MetricStreamerMemoryCopy::createCasesForMetricsTest(execTimeMs)), [](const testing::TestParamInfo &p) { std::string groupName = std::get<1>(p.param); uint32_t execTime = std::get<2>(p.param); return groupName + "_" + std::to_string(execTime) + "ms"; }); -TEST_P(MetricStreamerCopyEngine, RunCopyExpectAnyReport) { +TEST_P(MetricStreamerMemoryCopy, RunCopyExpectAnyReport) { auto [node, metricGroupName, execTime] = GetParam(); openMetricStreamer(); diff --git a/validation/umd-test/test_mutable_cmdlist.cpp b/validation/umd-test/test_mutable_cmdlist.cpp index e5e737d..0fe578f 100644 --- a/validation/umd-test/test_mutable_cmdlist.cpp +++ b/validation/umd-test/test_mutable_cmdlist.cpp @@ -137,7 +137,7 @@ class MutableCmdList : public UmdTest { ze_command_queue_desc_t cmdQueueDesc{.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC, .pNext = nullptr, - .ordinal = computeGrpOrdinal, + .ordinal = 0u, .index = 0, .flags = 0, .mode = ZE_COMMAND_QUEUE_MODE_DEFAULT, @@ -159,7 +159,7 @@ class MutableCmdList : public UmdTest { ze_command_list_desc_t commandListDesc{ .stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC, .pNext = &mutableCmdListDesc, - .commandQueueGroupOrdinal = computeGrpOrdinal, + .commandQueueGroupOrdinal = 0u, .flags = 0, }; ze_command_list_handle_t commandList; @@ -748,7 +748,7 @@ TEST_F(MutableCmdList, GetNextCommandIdNotMutableCmdList) { ze_command_list_desc_t commandListDesc{ .stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC, .pNext = nullptr, - .commandQueueGroupOrdinal = computeGrpOrdinal, + .commandQueueGroupOrdinal = 0u, .flags = 0, }; ze_command_list_handle_t commandList; @@ -777,7 +777,7 @@ TEST_F(MutableCmdList, GetNextCommandIdClosedCmdList) { ze_command_list_desc_t commandListDesc{ .stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC, .pNext = &mutableCmdListDesc, - .commandQueueGroupOrdinal = computeGrpOrdinal, + .commandQueueGroupOrdinal = 0u, .flags = 0, }; ze_command_list_handle_t commandList; diff --git a/validation/umd-test/test_ov_inference.cpp b/validation/umd-test/test_ov_inference.cpp index 27f05bd..3094163 100644 --- a/validation/umd-test/test_ov_inference.cpp +++ b/validation/umd-test/test_ov_inference.cpp @@ -98,6 +98,9 @@ class OpenVinoBasic : public UmdTest, public ::testing::WithParamInterface #include -#include #include #include @@ -126,7 +125,7 @@ class Environment : public ::testing::Environment { ASSERT_EQ( zeDriverGetExtensionFunctionAddress(zeDriver, - GRAPH_EXT_NAME, + ZE_GRAPH_EXT_NAME, reinterpret_cast(&zeGraphDDITableExt)), ZE_RESULT_SUCCESS); @@ -136,9 +135,16 @@ class Environment : public ::testing::Environment { reinterpret_cast(&zeGraphProfilingDDITableExt)), ZE_RESULT_SUCCESS); + ASSERT_EQ(zeDriverGetExtensionFunctionAddress( + zeDriver, + ZE_COMMAND_QUEUE_NPU_EXT_NAME, + reinterpret_cast(&zeCommandQueueDDITableExt)), + ZE_RESULT_SUCCESS); + ASSERT_NE(zeGraphDDITableExt, nullptr) << "Failed to find graph DDI table"; ASSERT_NE(zeGraphProfilingDDITableExt, nullptr) << "Failed to find graph profiling DDI table"; + ASSERT_NE(zeCommandQueueDDITableExt, nullptr) << "Failed to find command queue DDI table"; } ze_driver_handle_t getDriver() { return zeDriver; } @@ -147,6 +153,7 @@ class Environment : public ::testing::Environment { ze_graph_profiling_dditable_ext_t *getGraphProfilingDDITable() { return zeGraphProfilingDDITableExt; } + command_queue_dditable_t *getCommandQueueDDITable() { return zeCommandQueueDDITableExt; } uint64_t getMaxMemAllocSize() { return maxMemAllocSize; } uint16_t getPciDevId() { return pciDevId; } uint16_t getPlatformType() { return platformType; } @@ -254,6 +261,8 @@ class Environment : public ::testing::Environment { ze_device_handle_t zeDevice = nullptr; graph_dditable_ext_t *zeGraphDDITableExt = nullptr; ze_graph_profiling_dditable_ext_t *zeGraphProfilingDDITableExt = nullptr; + /** @brief Pointer to the Level Zero API command queue extension DDI table */ + command_queue_dditable_t *zeCommandQueueDDITableExt = nullptr; uint64_t maxMemAllocSize = 0; uint16_t pciDevId = 0; uint32_t platformType = 0; diff --git a/validation/umd-test/umd_dma_heap_system.hpp b/validation/umd-test/umd_dma_heap_system.hpp new file mode 100644 index 0000000..2005249 --- /dev/null +++ b/validation/umd-test/umd_dma_heap_system.hpp @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "umd_test.h" + +#include +#include +#include +#include +#include +#include +#include + +#define CHECK_DMA_HEAP_SUPPORT(x) \ + SKIP_CHROMEOS(); \ + if (!x.checkDmaHeapSystemAvailability()) { \ + const char *msg = "Missed support or insufficient permissions for" \ + " dma buffer allocation in the system."; \ + if (test_vars::forceDmaHeap) { \ + GTEST_FAIL() << msg; \ + } else { \ + GTEST_SKIP() << msg; \ + } \ + } + +namespace test_vars { +extern bool forceDmaHeap; +} + +class DmaHeapBuffer { + public: + DmaHeapBuffer(int fd, void *ptr, size_t size) + : fd(fd) + , ptr(ptr) + , size(size) {} + ~DmaHeapBuffer() { + if (ptr != MAP_FAILED) + ::munmap(ptr, size); + if (fd >= 0) + ::close(fd); + } + + DmaHeapBuffer(const DmaHeapBuffer &obj) = delete; + DmaHeapBuffer(DmaHeapBuffer &&obj) = delete; + DmaHeapBuffer &operator=(const DmaHeapBuffer &obj) = delete; + DmaHeapBuffer &operator=(DmaHeapBuffer &&obj) = delete; + + public: + int fd; + void *ptr; + size_t size; +}; + +class DmaHeapSystem { + public: + DmaHeapSystem() { + fd = open("/dev/dma_heap/system", O_RDWR); + if (fd < 0) { + printf("Failed to open /dev/dma_heap/system, errno: %i, strerror: %s\n", + errno, + strerror(errno)); + } + } + ~DmaHeapSystem() { + if (fd >= 0) + close(fd); + } + + DmaHeapSystem(const DmaHeapSystem &obj) = delete; + DmaHeapSystem(DmaHeapSystem &&obj) = delete; + DmaHeapSystem &operator=(const DmaHeapSystem &obj) = delete; + DmaHeapSystem &operator=(DmaHeapSystem &&obj) = delete; + + bool checkDmaHeapSystemAvailability() { return fd >= 0; } + + std::unique_ptr allocDmaHeapBuffer(size_t size) { + if (!size) { + printf("size has to be greater than 0\n"); + return nullptr; + } + + struct dma_heap_allocation_data heapAlloc = { + .len = ALLIGN_TO_PAGE(size), + .fd = 0, + .fd_flags = O_RDWR | O_CLOEXEC, + .heap_flags = 0, + }; + + int ret = ioctl(fd, DMA_HEAP_IOCTL_ALLOC, &heapAlloc); + if (ret != 0) { + printf("ioctl failed with DMA_HEAP_IOCTL_ALLOC, errno: %u, strerror: %s\n", + errno, + strerror(errno)); + return nullptr; + } + + int bufferFd = heapAlloc.fd; + void *ptr = mmap(NULL, size, PROT_WRITE | PROT_READ, MAP_SHARED, bufferFd, 0); + if (ptr == MAP_FAILED) { + printf("mmap failed on dma_heap buffer, errno: %u, strerror: %s\n", + errno, + strerror(errno)); + return nullptr; + } + + return std::make_unique(bufferFd, ptr, size); + } + + private: + int32_t fd = -1; +}; diff --git a/validation/umd-test/umd_extensions.h b/validation/umd-test/umd_extensions.h index d0e7b71..9462df0 100644 --- a/validation/umd-test/umd_extensions.h +++ b/validation/umd-test/umd_extensions.h @@ -7,9 +7,14 @@ #pragma once +#include +#include #include #include -#define GRAPH_EXT_NAME ZE_GRAPH_EXT_NAME_1_6 -#define GRAPH_EXT_VERSION ZE_GRAPH_EXT_VERSION_1_6 -typedef ze_graph_dditable_ext_1_6_t graph_dditable_ext_t; +#define GRAPH_EXT_VERSION ZE_GRAPH_EXT_VERSION_CURRENT +typedef ze_graph_dditable_ext_t graph_dditable_ext_t; + +#define COMMAND_QUEUE_EXT_NAME ZE_COMMAND_QUEUE_NPU_EXT_NAME +#define COMMAND_QUEUE_NPU_EXT_VERSION ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_0 +typedef ze_command_queue_npu_dditable_ext_1_0_t command_queue_dditable_t; diff --git a/validation/umd-test/umd_prime_buffers.h b/validation/umd-test/umd_prime_buffers.h deleted file mode 100644 index 8c41489..0000000 --- a/validation/umd-test/umd_prime_buffers.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "umd_test.h" - -#include -#include -#include -#include -#include -#include -#include - -#define ALLIGN_TO_PAGE(x) __ALIGN_KERNEL((x), (UmdTest::PAGE_SIZE)) - -class PrimeBufferHelper { - public: - PrimeBufferHelper() { - if (!std::filesystem::exists("/dev/dma_heap/system")) - return; - - fd = open("/dev/dma_heap/system", O_RDWR); - } - PrimeBufferHelper(const PrimeBufferHelper &obj) = delete; - PrimeBufferHelper(PrimeBufferHelper &&obj) = delete; - PrimeBufferHelper &operator=(const PrimeBufferHelper &obj) = delete; - PrimeBufferHelper &operator=(PrimeBufferHelper &&obj) = delete; - - ~PrimeBufferHelper() { - for (const auto &[bufferFd, value] : buffers) { - if (value.second != nullptr && value.second != MAP_FAILED) - munmap(value.second, value.first); - close(bufferFd); - } - if (fd >= 0) - close(fd); - } - - bool hasDMABufferSupport() { - if (fd < 0) - return false; - return true; - } - - bool createDMABuffer(size_t size, int32_t &bufferFd) { - if (!hasDMABufferSupport() || !size) - return false; - - struct dma_heap_allocation_data heapAlloc = { - .len = ALLIGN_TO_PAGE(size), - .fd = 0, - .fd_flags = O_RDWR | O_CLOEXEC, - .heap_flags = 0, - }; - - int ret = ioctl(fd, DMA_HEAP_IOCTL_ALLOC, &heapAlloc); - if (ret != 0) - return false; - - bufferFd = heapAlloc.fd; - buffers.insert({bufferFd, {size, nullptr}}); - return true; - } - - void *mmapDmaBuffer(int32_t &bufferFd) { - if (auto it = buffers.find(bufferFd); it != buffers.end()) { - if (it->second.second == nullptr) - it->second.second = - mmap(NULL, it->second.first, PROT_WRITE | PROT_READ, MAP_SHARED, bufferFd, 0); - return it->second.second; - } - return MAP_FAILED; - } - - /* Descriptor for create exportable memory */ - ze_external_memory_export_desc_t externalExportDesc = { - .stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_DESC, - .pNext = nullptr, - .flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF}; - - /* Descriptor to retrieve Fd through get properties */ - ze_external_memory_export_fd_t externalExportFdDesc = { - .stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD, - .pNext = nullptr, - .flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF, - .fd = -1}; - - /* Descriptor to import allocation from fd */ - ze_external_memory_import_fd_t externalImportFromFdDesc = { - .stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMPORT_FD, - .pNext = nullptr, - .flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF, - .fd = -1}; - - protected: - using BufferFd = int32_t; - using BufferSize = size_t; - using BufferPtr = void *; - std::map> buffers; - int32_t fd = -1; -}; diff --git a/validation/umd-test/umd_test.cpp b/validation/umd-test/umd_test.cpp index fc5af87..e773438 100644 --- a/validation/umd-test/umd_test.cpp +++ b/validation/umd-test/umd_test.cpp @@ -19,9 +19,25 @@ void PrintTo(const ze_result_t &result, std::ostream *os) { *os << ze_result_to_str(result) << " (0x" << std::hex << result << ")" << std::dec; } -void UmdTest::CommandQueueGroupSetUp(ze_device_handle_t dev, - uint32_t &compOrdinal, - uint32_t ©Ordinal) { +void UmdTest::CommandQueueGroupSetUpNpu(ze_device_handle_t dev) { + uint32_t cmdGrpCount = 0; + ASSERT_EQ(zeDeviceGetCommandQueueGroupProperties(dev, &cmdGrpCount, nullptr), + ZE_RESULT_SUCCESS); + + EXPECT_EQ(cmdGrpCount, 1u); + ze_command_queue_group_properties_t cmdGroupProps = {}; + + cmdGroupProps.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_GROUP_PROPERTIES; + + ASSERT_EQ(zeDeviceGetCommandQueueGroupProperties(dev, &cmdGrpCount, &cmdGroupProps), + ZE_RESULT_SUCCESS); + + EXPECT_TRUE(cmdGroupProps.flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); +} + +void UmdTest::CommandQueueGroupSetUpGpu(ze_device_handle_t dev, + uint32_t &compOrdinal, + uint32_t ©Ordinal) { uint32_t cmdGrpCount = 0; ASSERT_EQ(zeDeviceGetCommandQueueGroupProperties(dev, &cmdGrpCount, nullptr), ZE_RESULT_SUCCESS); @@ -66,7 +82,7 @@ void UmdTest::SetUp() { scopedContext = zeScope::contextCreate(zeDriver, contextDesc, ret); ASSERT_EQ(ret, ZE_RESULT_SUCCESS); zeContext = scopedContext.get(); - CommandQueueGroupSetUp(zeDevice, computeGrpOrdinal, copyGrpOrdinal); + CommandQueueGroupSetUpNpu(zeDevice); if (test_vars::test_with_gpu) { zeDriverGpu = testEnv->getDriverGpu(); @@ -74,7 +90,7 @@ void UmdTest::SetUp() { scopedContextGpu = zeScope::contextCreate(zeDriverGpu, contextDesc, ret); ASSERT_EQ(ret, ZE_RESULT_SUCCESS); zeContextGpu = scopedContextGpu.get(); - CommandQueueGroupSetUp(zeDeviceGpu, computeGrpOrdinalGpu, copyGrpOrdinalGpu); + CommandQueueGroupSetUpGpu(zeDeviceGpu, computeGrpOrdinalGpu, copyGrpOrdinalGpu); } if (!isSilicon()) { @@ -128,71 +144,22 @@ std::shared_ptr UmdTest::AllocHostMemory(size_t size, ze_host_mem_alloc_fl return zeMemory::allocHost(zeContext, size, flagsHost); } -std::vector UmdTest::getFlagsFromString(std::string flags) { - std::vector buildFlags; - - for (auto c : flags) - buildFlags.push_back(c); - buildFlags.push_back('\0'); - return buildFlags; -} - -void UmdTest::createGraphDescriptorForModel(const std::string &modelPath, - const std::vector &modelBuildFlags, - std::vector &testModelIR, - ze_graph_desc_2_t &graphDesc) { - std::vector testModelXml, testModelBin; - ze_device_graph_properties_t pDeviceGraphProperties; - - ASSERT_TRUE(getModelFromPath(modelPath, testModelXml, testModelBin)); - - ASSERT_EQ(zeGraphDDITableExt->pfnDeviceGetGraphProperties(zeDevice, &pDeviceGraphProperties), - ZE_RESULT_SUCCESS); - - ze_graph_compiler_version_info_t version = { - .major = pDeviceGraphProperties.compilerVersion.major, - .minor = pDeviceGraphProperties.compilerVersion.minor}; - - uint64_t xml_len = testModelXml.size(); - uint64_t bin_len = testModelBin.size(); - uint32_t numInputs = 2; - uint64_t modelSize = - sizeof(version) + sizeof(numInputs) + sizeof(xml_len) + xml_len + sizeof(bin_len) + bin_len; - - testModelIR.resize(modelSize); - - uint64_t offset = 0; - memcpy(&testModelIR[0], &version, sizeof(version)); - offset += sizeof(version); - - memcpy(&testModelIR[offset], &numInputs, sizeof(numInputs)); - offset += sizeof(numInputs); - - memcpy(&testModelIR[offset], &xml_len, sizeof(xml_len)); - offset += sizeof(xml_len); - - memcpy(&testModelIR[offset], testModelXml.data(), xml_len); - offset += xml_len; - - memcpy(&testModelIR[offset], &bin_len, sizeof(bin_len)); - offset += sizeof(bin_len); - - memcpy(&testModelIR[offset], testModelBin.data(), bin_len); +bool UmdTest::isHwsModeEnabled() { + std::string deviceSysFs = getDeviceSysFsDirectory(); + if (deviceSysFs.empty()) + return false; - graphDesc.stype = ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES; - graphDesc.pNext = nullptr; - graphDesc.format = ZE_GRAPH_FORMAT_NGRAPH_LITE; - graphDesc.inputSize = testModelIR.size(); - graphDesc.pInput = testModelIR.data(); - graphDesc.pBuildFlags = modelBuildFlags.data(); - graphDesc.flags = ZE_GRAPH_FLAG_NONE; -} + std::vector schedMode; + if (DataHandle::loadFile(deviceSysFs + "/sched_mode", schedMode) != 0) + return false; -bool UmdTest::isHwsModeEnabled() { - std::vector out; - if (DataHandle::loadFile("/sys/module/intel_vpu/parameters/sched_mode", out) != 0) + if (schedMode.size() < std::string("HW").size()) return false; - return out.size() > 0 && out[0] == '1'; + + const std::string modeAsString(schedMode.begin(), schedMode.begin() + std::string("HW").size()); + if (modeAsString.compare("HW") == 0) + return true; + return false; } TEST(Umd, ZeDevTypeStr) { diff --git a/validation/umd-test/umd_test.h b/validation/umd-test/umd_test.h index 55c79cf..d35bdd4 100644 --- a/validation/umd-test/umd_test.h +++ b/validation/umd-test/umd_test.h @@ -8,6 +8,7 @@ #pragma once #include "blob_params.hpp" +#include "drm_helpers.h" #include "model_params.hpp" #include "test_app.h" #include "testenv.hpp" @@ -16,6 +17,7 @@ #include "ze_scope.hpp" #include +#include #include #include #include @@ -29,6 +31,11 @@ void PrintTo(const ze_result_t &result, std::ostream *os); GTEST_SKIP_(msg); \ } +#define SKIP_VPU37XX(msg) \ + if (isVPU37xx()) { \ + SKIP_(msg); \ + } + #define SKIP_VPU40XX(msg) \ if (isVPU40xx()) { \ SKIP_(msg); \ @@ -49,9 +56,21 @@ void PrintTo(const ze_result_t &result, std::ostream *os); SKIP_("Needs root privileges") \ } +#define SKIP_CHROMEOS() \ + if (std::filesystem::exists("/etc/chrome_dev.conf")) { \ + SKIP_("Test is not supported in ChromeOS") \ + } + +#define SKIP_NEEDS_SYSFS_FILE(x) \ + if (!isFileAvailableInSysFs(x)) { \ + SKIP_("Test is not supported because " x " is missing in SysFs"); \ + } + #define KB (1024llu) #define MB (1024llu * 1024) +#define ALLIGN_TO_PAGE(x) __ALIGN_KERNEL((x), (UmdTest::PAGE_SIZE)) + inline std::string memSizeToStr(uint64_t size) { std::string str; if (size >= MB) @@ -85,6 +104,25 @@ inline std::string generateTestNameFromNode(const YAML::Node &node) { return testName; } +inline std::string getDeviceSysFsDirectory() { + drm_device_desc desc = drm::open_intel_vpu(); + close(desc.fd); + std::string path = "/sys/dev/char/" + std::to_string(desc.major_id) + ":" + + std::to_string(desc.minor_id) + "/device"; + return path; +} + +inline bool isFileAvailableInSysFs(const std::string &filename) { + std::filesystem::path deviceSysFs = getDeviceSysFsDirectory(); + if (deviceSysFs.empty()) { + TRACE("WARNING: No SysFs available in system\n"); + return false; + } + + std::error_code ec; + return std::filesystem::exists(deviceSysFs / filename, ec); +} + class UmdTest : public ::testing::Test { public: /** @@ -98,9 +136,6 @@ class UmdTest : public ::testing::Test { static constexpr int PAGE_SIZE = 4096; - uint32_t computeGrpOrdinal = std::numeric_limits::max(); - uint32_t copyGrpOrdinal = std::numeric_limits::max(); - uint32_t computeGrpOrdinalGpu = std::numeric_limits::max(); uint32_t copyGrpOrdinalGpu = std::numeric_limits::max(); @@ -117,11 +152,6 @@ class UmdTest : public ::testing::Test { std::shared_ptr AllocSharedMemory(size_t size, ze_host_mem_alloc_flags_t flagsHost = 0); std::shared_ptr AllocDeviceMemory(size_t size); std::shared_ptr AllocHostMemory(size_t size, ze_host_mem_alloc_flags_t flagsHost = 0); - std::vector getFlagsFromString(std::string flags); - void createGraphDescriptorForModel(const std::string &modelPath, - const std::vector &modelBuildFlags, - std::vector &testModelIR, - ze_graph_desc_2_t &graphDesc); bool isSilicon(); bool isHwsModeEnabled(); @@ -139,8 +169,9 @@ class UmdTest : public ::testing::Test { ze_device_handle_t zeDeviceGpu = nullptr; ze_context_handle_t zeContextGpu = nullptr; + void CommandQueueGroupSetUpNpu(ze_device_handle_t dev); void - CommandQueueGroupSetUp(ze_device_handle_t dev, uint32_t &compOrdinal, uint32_t ©Ordinal); + CommandQueueGroupSetUpGpu(ze_device_handle_t dev, uint32_t &compOrdinal, uint32_t ©Ordinal); uint16_t pciDevId = 0u; uint32_t platformType = 0u; diff --git a/validation/umd-test/ze_scope.hpp b/validation/umd-test/ze_scope.hpp index 1cae4b3..eb19b8e 100644 --- a/validation/umd-test/ze_scope.hpp +++ b/validation/umd-test/ze_scope.hpp @@ -7,13 +7,10 @@ #pragma once -#include -#include -#include -#include - #include "umd_extensions.h" +#include + #ifdef VPU_GTEST_APP #include #else