Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
./sw_runtime_kernels/kernels/prebuild/act_shave_bin/* filter=lfs diff=lfs merge=lfs -text
./sw_runtime_kernels/kernels/prebuild/*.elf filter=lfs diff=lfs merge=lfs -text
./sw_runtime_kernels/kernels/prebuild/*.xdat filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.svg filter=lfs diff=lfs merge=lfs -text
*.vsdx filter=lfs diff=lfs merge=lfs -text
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "thirdparty/flatbuffers"]
path = thirdparty/flatbuffers
url = https://github.com/google/flatbuffers.git
[submodule "thirdparty/elf"]
path = thirdparty/elf
url = https://github.com/openvinotoolkit/npu_plugin_elf.git
Expand Down
32 changes: 17 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ endif()
include(cmake/flatbuffers.cmake)
include(cmake/bundle_static_library.cmake)
include(cmake/embed_bin_file.cmake)
include(cmake/add_native_exec_target.cmake)
include(cmake/add_tool_target.cmake)
include(cmake/coverage.cmake)
include(cmake/log_level.cmake)
Expand Down Expand Up @@ -115,28 +116,29 @@ if(ENABLE_PREBUILT_LLVM_MLIR_LIBS)
list(APPEND CMAKE_PREFIX_PATH ${MLIR_BINARY_PKG_DIR}/lib/cmake/mlir)
else()
message(STATUS "Include LLVM by source files")
# When vpux-plugin is built independently, MLIRConfig.cmake is under this dir
list(APPEND CMAKE_PREFIX_PATH ${PROJECT_BINARY_DIR}/lib/cmake/mlir)
# When vpux-plugin is added as OPENVINO_EXTRA_MODULES, MLIRConfig.cmake is under this dir
list(APPEND CMAKE_PREFIX_PATH ${OpenVINO_BINARY_DIR}/lib/cmake/mlir)
# When vpux-plugin is added in monorepo, MLIRConfig.cmake is under this dir
if(ENABLE_NPU_MONO)
if(NOT DEFINED NPU_MONO_BUILD_DIR)
message(FATAL_ERROR "Cannot find `npu_mono` build directory")
if (ANDROID)
# To find MLIR/LLVM packages in Android build, we have to set the paths manually
# because Android NDK set CMAKE_FIND_ROOT_PATH that is appended to CMAKE_PREFIX_PATH
set(MLIR_DIR ${CMAKE_BINARY_DIR}/lib/cmake/mlir)
set(LLVM_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty/llvm-project/llvm/lib/cmake/llvm)
else()
# When vpux-plugin is built independently, MLIRConfig.cmake is under this dir
list(APPEND CMAKE_PREFIX_PATH ${PROJECT_BINARY_DIR}/lib/cmake/mlir)
# When vpux-plugin is added as OPENVINO_EXTRA_MODULES, MLIRConfig.cmake is under this dir
list(APPEND CMAKE_PREFIX_PATH ${OpenVINO_BINARY_DIR}/lib/cmake/mlir)
# When vpux-plugin is added in monorepo, MLIRConfig.cmake is under this dir
if(ENABLE_NPU_MONO)
if(NOT DEFINED NPU_MONO_BUILD_DIR)
message(FATAL_ERROR "Cannot find `npu_mono` build directory")
endif()
list(APPEND CMAKE_PREFIX_PATH ${NPU_MONO_BUILD_DIR}/lib/cmake/mlir)
endif()
list(APPEND CMAKE_PREFIX_PATH ${NPU_MONO_BUILD_DIR}/lib/cmake/mlir)
endif()
endif()

add_subdirectory(thirdparty EXCLUDE_FROM_ALL)

set(VPUNN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/vpucostmodel")
set(VPUNN_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/thirdparty/vpucostmodel")

set(VPUNN_INCLUDE_DIRS
"${VPUNN_SOURCE_DIR}/include"
"${VPUNN_BINARY_DIR}/include"
)

if(ENABLE_DEVELOPER_BUILD)
add_compile_definitions(VPUX_DEVELOPER_BUILD)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[![ubuntu_22](https://github.com/openvinotoolkit/npu_compiler/actions/workflows/ubuntu_22.yml/badge.svg?branch=develop&event=push)](https://github.com/openvinotoolkit/npu_compiler/actions/workflows/ubuntu_22.yml?query=event%3Apush)
[![ubuntu_24](https://github.com/openvinotoolkit/npu_compiler/actions/workflows/ubuntu_24.yml/badge.svg?branch=develop&event=push)](https://github.com/openvinotoolkit/npu_compiler/actions/workflows/ubuntu_24.yml?query=event%3Apush)
[![Windows (2022)](https://github.com/openvinotoolkit/npu_compiler/actions/workflows/windows_2022.yml/badge.svg?branch=develop&event=push)](https://github.com/openvinotoolkit/npu_compiler/actions/workflows/windows_2022.yml)
[![Windows (2022)](https://github.com/openvinotoolkit/npu_compiler/actions/workflows/windows_2022.yml/badge.svg?branch=develop&event=push)](https://github.com/openvinotoolkit/npu_compiler/actions/workflows/windows_2022.yml?query=event%3Apush)

[![OpenVINO Docs](https://img.shields.io/badge/OpenVINO-documentation-blue)](https://docs.openvino.ai/)
[![OpenVINO Downloads](https://img.shields.io/badge/OpenVINO-downloads-blue)](https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit/download.html)
Expand Down
19 changes: 19 additions & 0 deletions cmake/add_native_exec_target.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (C) 2025 Intel Corporation.
# SPDX-License-Identifier: Apache-2.0
#

# For Android, we use the native tools from the prebuilt binaries.
function(add_native_exec_target NATIVE_TARGET_NAME)
# Tools must be built for the host machine in Release mode
set(NATIVE_EXEC_TOOL_DIR "${OUTPUT_ROOT}/bin/intel64/Release")
find_program(NATIVE_TOOL_EXEC ${NATIVE_TARGET_NAME} PATHS ${NATIVE_EXEC_TOOL_DIR} NO_DEFAULT_PATH NO_CACHE)
if(NOT NATIVE_TOOL_EXEC)
message(FATAL_ERROR "${NATIVE_TARGET_NAME} executable not found in ${NATIVE_EXEC_TOOL_DIR}. "
"Please build the native tools first.")
endif()

add_executable(${NATIVE_TARGET_NAME} IMPORTED GLOBAL)
set_target_properties(${NATIVE_TARGET_NAME} PROPERTIES IMPORTED_LOCATION "${NATIVE_TOOL_EXEC}")
message(STATUS "native ${NATIVE_TARGET_NAME} executable found: ${NATIVE_TOOL_EXEC}")
endfunction()
7 changes: 7 additions & 0 deletions cmake/compile_options_llvm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ macro(set_llvm_flags)
set(LLVM_BUILD_UTILS ON CACHE BOOL "" FORCE)
set(LLVM_INSTALL_UTILS ON CACHE BOOL "" FORCE)
set(LLVM_ABI_BREAKING_CHECKS "FORCE_OFF" CACHE STRING "" FORCE)

if(ANDROID)
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "" FORCE)
set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "" FORCE)
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "" FORCE)
set(LLVM_USE_HOST_TOOLS ON CACHE BOOL "" FORCE)
endif()
endmacro()
57 changes: 22 additions & 35 deletions cmake/embed_bin_file.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,41 @@
# SPDX-License-Identifier: Apache-2.0
#

function(vpux_embed_bin_file)
function(npu_embed_bin_file)
set(options)
set(oneValueArgs SOURCE_FILE HEADER_FILE VARIABLE_NAME)
set(oneValueArgs TARGET SOURCE_FILE HEADER_FILE VARIABLE_NAME)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT ARG_TARGET)
message(FATAL_ERROR "Missing TARGET argument in npu_embed_bin_file")
endif()
if(NOT ARG_SOURCE_FILE)
message(FATAL_ERROR "Missing SOURCE_FILE argument in vpux_embed_bin_file")
message(FATAL_ERROR "Missing SOURCE_FILE argument in npu_embed_bin_file")
endif()
if(NOT ARG_HEADER_FILE)
message(FATAL_ERROR "Missing HEADER_FILE argument in vpux_embed_bin_file")
message(FATAL_ERROR "Missing HEADER_FILE argument in npu_embed_bin_file")
endif()
if(NOT ARG_VARIABLE_NAME)
message(FATAL_ERROR "Missing VARIABLE_NAME argument in vpux_embed_bin_file")
message(FATAL_ERROR "Missing VARIABLE_NAME argument in npu_embed_bin_file")
endif()

if(NOT EXISTS ${ARG_SOURCE_FILE})
message(FATAL_ERROR "File '${ARG_SOURCE_FILE}' does not exist")
endif()

file(READ ${ARG_SOURCE_FILE} hex_string HEX)
string(LENGTH "${hex_string}" hex_string_length)

string(REGEX REPLACE "([0-9a-f][0-9a-f])" "static_cast<char>(0x\\1), " hex_array "${hex_string}")
math(EXPR hex_array_size "${hex_string_length} / 2")

if (hex_array_size LESS "1000")
message(FATAL_ERROR "File '${ARG_SOURCE_FILE}' too small, check that git-lfs pull step has been done.")
endif()

set(content "
const char ${ARG_VARIABLE_NAME}[] = { ${hex_array} };
const size_t ${ARG_VARIABLE_NAME}_SIZE = ${hex_array_size};
")

# tracking of rewrite is required to avoid rebuild of the whole MLIR compiler
# in case of cmake rerun. Need to rebuild only if content of SOURCE_FILE is changed
set(rewrite_file ON)
if(EXISTS ${ARG_HEADER_FILE})
file(READ ${ARG_HEADER_FILE} current_content)
string(SHA256 current_hash "${current_content}")
string(SHA256 new_hash "${content}")
if(current_hash STREQUAL new_hash)
set(rewrite_file OFF)
endif()
endif()

if(rewrite_file)
file(WRITE ${ARG_HEADER_FILE} "${content}")
endif()
add_custom_command(
OUTPUT ${ARG_HEADER_FILE}
DEPENDS ${ARG_SOURCE_FILE}
COMMAND ${CMAKE_COMMAND}
-DSOURCE_FILE=${ARG_SOURCE_FILE}
-DHEADER_FILE=${ARG_HEADER_FILE}
-DVARIABLE_NAME=${ARG_VARIABLE_NAME}
-P ${PROJECT_SOURCE_DIR}/cmake/prepare_cost_model_binary.cmake
COMMENT "Generating VPUNN header '${ARG_HEADER_FILE}'"
VERBATIM)

add_custom_target(
${ARG_TARGET} ALL
DEPENDS ${ARG_HEADER_FILE})
endfunction()
49 changes: 0 additions & 49 deletions cmake/flatbuffers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,53 +62,4 @@ function(vpux_add_flatc_target FLATC_TARGET_NAME)
${FLATC_DST_DIR}
)

vpux_gf_version_generate(${FLATC_SRC_DIR} "${FLATC_DST_DIR}/schema")

endfunction()

find_package(Git REQUIRED)
function(vpux_gf_version_generate SRC_DIR DST_DIR)

execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if ("${GIT_DESCRIBE_DIRTY}" STREQUAL "")
message(WARNING "ELF version cannot be read from ${SRC_DIR}")
set(GIT_DESCRIBE_DIRTY "v3.35.2")
endif()

string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}")

set(content "
#ifndef GF_VERSION_H
#define GF_VERSION_H
#define MVCNN_VERSION_MAJOR ${VERSION_MAJOR}
#define MVCNN_VERSION_MINOR ${VERSION_MINOR}
#define MVCNN_VERSION_PATCH ${VERSION_PATCH}
#endif")
set(dst_file "${DST_DIR}/gf_version.h")

# tracking of rewrite is required to avoid rebuild of big part of the product
# in case of cmake rerun. Need to rebuild only if GF version is changed
set(rewrite_file ON)
if(EXISTS ${dst_file})
file(READ ${dst_file} current_content)
string(SHA256 current_hash "${current_content}")
string(SHA256 new_hash "${content}")
if(current_hash STREQUAL new_hash)
set(rewrite_file OFF)
endif()
endif()

if(rewrite_file)
file(WRITE ${dst_file} "${content}")
endif()
endfunction()
58 changes: 58 additions & 0 deletions cmake/prepare_cost_model_binary.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# Copyright (C) 2025 Intel Corporation.
# SPDX-License-Identifier: Apache-2.0
#

function(prepare_cost_model_binary SOURCE_FILE HEADER_FILE VARIABLE_NAME)
if(NOT SOURCE_FILE)
message(FATAL_ERROR "Missing SOURCE_FILE argument in prepare_cost_model_binary")
endif()
if(NOT HEADER_FILE)
message(FATAL_ERROR "Missing HEADER_FILE argument in prepare_cost_model_binary")
endif()
if(NOT VARIABLE_NAME)
message(FATAL_ERROR "Missing VARIABLE_NAME argument in prepare_cost_model_binary")
endif()

if(NOT EXISTS ${SOURCE_FILE})
message(FATAL_ERROR "File '${SOURCE_FILE}' does not exist")
endif()

find_package(Git QUIET REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} lfs pull
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/thirdparty/vpucostmodel")

file(READ ${SOURCE_FILE} hex_string HEX)
string(LENGTH "${hex_string}" hex_string_length)

string(REGEX REPLACE "([0-9a-f][0-9a-f])" "static_cast<char>(0x\\1), " hex_array "${hex_string}")
math(EXPR hex_array_size "${hex_string_length} / 2")

if (hex_array_size LESS "1000")
message(FATAL_ERROR "File '${SOURCE_FILE}' too small, check that git-lfs pull step has been done.")
endif()

set(content "
const char ${VARIABLE_NAME}[] = { ${hex_array} };
const size_t ${VARIABLE_NAME}_SIZE = ${hex_array_size};
")

# tracking of rewrite is required to avoid rebuild of the whole MLIR compiler
# in case of cmake rerun. Need to rebuild only if content of SOURCE_FILE is changed
set(rewrite_file ON)
if(EXISTS ${HEADER_FILE})
file(READ ${HEADER_FILE} current_content)
string(SHA256 current_hash "${current_content}")
string(SHA256 new_hash "${content}")
if(current_hash STREQUAL new_hash)
set(rewrite_file OFF)
endif()
endif()

if(rewrite_file)
file(WRITE ${HEADER_FILE} "${content}")
endif()
endfunction()

prepare_cost_model_binary(${SOURCE_FILE} ${HEADER_FILE} ${VARIABLE_NAME})
1 change: 0 additions & 1 deletion docs/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ The compiler is based on the MLIR project. There are two different ways for the

An engine backend is an abstraction layer on top of underlying APIs used to execute models. It is meant to include all the required functionality and infrastructure required to execute multiple models in parallel on one or multiple devices. Multiple engine backends are supported by the plugin:
* L0 (Level Zero) backend
* IMD backend

&nbsp;
## Model Compilation
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if(BUILD_COMPILER_FOR_DRIVER)
add_subdirectory(vpux_driver_compiler)
endif()


add_subdirectory(vpux_utils)

add_subdirectory(vpux_compiler)
29 changes: 4 additions & 25 deletions src/vpux_compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,10 @@ if(ENABLE_LTO)
endif()

set(TARGET_NAME "npu_mlir_compiler")
set(SCHEMA_TARGET_NAME "${TARGET_NAME}_schema")
set(OBJ_TARGET_NAME "${TARGET_NAME}_obj")
set(STATIC_TARGET_NAME "${TARGET_NAME}_static")
set(gen_base_dst_include_dir "src/vpux_compiler/include/vpux/compiler")

#
# SCHEMA target
#
if(ENABLE_NPU_MONO)
if(NOT DEFINED ELF_SUBMODULE_PATH)
message(FATAL_ERROR "ELF submodule path is not set while `npu_mono` was activated")
endif()
set(SCHEMA_SOURCE_DIR ${ELF_SUBMODULE_PATH}/src/schema)
else()
set(SCHEMA_SOURCE_DIR ${PROJECT_SOURCE_DIR}/thirdparty/elf/src/schema) # Legacy path
endif(ENABLE_NPU_MONO)


vpux_add_flatc_target(${SCHEMA_TARGET_NAME}
SRC_DIR "${SCHEMA_SOURCE_DIR}"
DST_DIR "${PROJECT_BINARY_DIR}/${gen_base_dst_include_dir}/dialect/VPUIP/generated"
ARGS "--gen-name-strings")
set_target_properties(${SCHEMA_TARGET_NAME} PROPERTIES FOLDER "src")

# These headers are needed by Unit tests even if ENABLE_MLIR_COMPILER=OFF
add_subdirectory(include/vpux/compiler/NPU37XX/dialect/NPUReg37XX/firmware_headers)
add_subdirectory(include/vpux/compiler/NPU40XX/dialect/NPUReg40XX/firmware_headers)
Expand Down Expand Up @@ -77,7 +57,7 @@ add_subdirectory(tblgen)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(SYSTEM ${CMAKE_CURRENT_BINARY_DIR}/include)
# Elf schema is used in tblgen and therefore in entire compiler
# ELF schema is used in tblgen and therefore in entire compiler
include_directories(
${PROJECT_BINARY_DIR}/${gen_base_dst_include_dir}/dialect/VPUIP/generated
$<TARGET_PROPERTY:flatbuffers,INTERFACE_INCLUDE_DIRECTORIES>
Expand All @@ -91,7 +71,7 @@ set(VPUX_COMPILER_VERSION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/compiler_version.
# compiler repo git commit hash
set(COMMIT_HASH_PATTERN ${CMAKE_CURRENT_SOURCE_DIR}/include/vpux/compiler/compiler_hash.hpp.in)
set(COMMIT_HASH_FILE ${CMAKE_CURRENT_BINARY_DIR}/include/vpux/compiler/compiler_hash.hpp)
set(COMMIT_HASH_CACHE ${CMAKE_CURRENT_BINARY_DIR}/include/vpux/compiler/compiler_hash.hpp.pre)
set(COMMIT_HASH_CACHE ${CMAKE_CURRENT_BINARY_DIR}/include/vpux/compiler/compiler_hash_cache)

add_custom_target(update_compiler_hash ALL
COMMAND ${CMAKE_COMMAND}
Expand Down Expand Up @@ -122,8 +102,7 @@ target_link_libraries(mlir-dependencies
MLIROptLib)
target_include_directories(mlir-dependencies
SYSTEM INTERFACE
${MLIR_INCLUDE_DIRS}
${VPUNN_INCLUDE_DIRS})
${MLIR_INCLUDE_DIRS})

if(BUILD_SHARED_LIBS)
set(COMPILER_TARGET ${OBJ_TARGET_NAME})
Expand Down Expand Up @@ -223,7 +202,7 @@ if(BUILD_SHARED_LIBS)
# Link the same to propagate dependencies
target_link_libraries(${STATIC_TARGET_NAME} PUBLIC ${OBJ_TARGET_NAME})
else()
bundle_static_library(${COMPILER_TARGET} inferenceStatic)
bundle_static_library(${COMPILER_TARGET} npu_costmodel)
add_library(${STATIC_TARGET_NAME} ALIAS ${COMPILER_TARGET})
endif()

Expand Down
6 changes: 1 addition & 5 deletions src/vpux_compiler/cmake/add_npu_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,12 @@ function(add_npu_library name)
set_property(GLOBAL APPEND PROPERTY MLIR_DIALECT_LIBS ${name})
endif()

# The npu_mlir_compiler_schema and cpp_schema targets are added as dependencies to ensure
# that the following generated headers are built before the compiler code:
# - elf/schema.hpp
# - vpunn_generated.h
add_mlir_library(${name}
STATIC ${SRC_FILES}
EXCLUDE_FROM_LIBMLIR
DISABLE_INSTALL
LINK_LIBS ${ARG_LINK_LIBS}
DEPENDS MLIRVPUXIncGenList npu_mlir_compiler_schema cpp_schema ${ARG_DEPENDS})
DEPENDS MLIRVPUXIncGenList ${ARG_DEPENDS})

target_include_directories(${name} SYSTEM PRIVATE
$<BUILD_INTERFACE:${MLIR_INCLUDE_DIRS}>
Expand Down
Loading