Skip to content

Commit 5aa47b4

Browse files
UD2025.38 content (#171)
1 parent 5a16ffb commit 5aa47b4

File tree

1,980 files changed

+52316
-30033
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,980 files changed

+52316
-30033
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
[submodule "thirdparty/vpucostmodel"]
1111
path = thirdparty/vpucostmodel
1212
url = https://github.com/intel/npu-nn-cost-model.git
13-
[submodule "thirdparty/yaml-cpp"]
14-
path = thirdparty/yaml-cpp
15-
url = https://github.com/jbeder/yaml-cpp
1613
[submodule "thirdparty/gtest-parallel"]
1714
path = thirdparty/gtest-parallel
1815
url = https://github.com/google/gtest-parallel.git

cmake/compiler_commit_hash.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# Copyright (C) 2025 Intel Corporation.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
execute_process(
7+
COMMAND
8+
git rev-parse HEAD
9+
WORKING_DIRECTORY ${REPO_DIR}
10+
OUTPUT_VARIABLE CURRENT_COMMIT_HASH
11+
OUTPUT_STRIP_TRAILING_WHITESPACE
12+
RESULT_VARIABLE ERROR_CODE
13+
)
14+
15+
if (NOT ${ERROR_CODE} EQUAL 0)
16+
message(FATAL_ERROR "Failed to capture compiler git commit.")
17+
endif()
18+
19+
set(LAST_COMMIT_HASH "")
20+
if (EXISTS ${COMMIT_HASH_CACHE})
21+
file(READ ${COMMIT_HASH_CACHE} LAST_COMMIT_HASH)
22+
endif()
23+
24+
if ("${CURRENT_COMMIT_HASH}" STREQUAL "${LAST_COMMIT_HASH}")
25+
return()
26+
endif()
27+
28+
file(WRITE ${COMMIT_HASH_CACHE} ${CURRENT_COMMIT_HASH})
29+
configure_file(${COMMIT_HASH_PATTERN} ${COMMIT_HASH_FILE} @ONLY)

cmake/prep_ldscript.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def prep_ldscript_header(filename_ld, filename_h, varname):
1717
lines = [line.strip() for line in text.split("\n")]
1818
lines = [line for line in lines if line]
1919

20-
vardef_begin = f'const char* {varname} = R"ldscript(\n'
20+
vardef_begin = f'static const char* {varname} = R"ldscript(\n'
2121
vardef_end = '\n)ldscript";\n'
2222

2323
result = "#pragma once\n\n" + vardef_begin + "\n".join(lines) + vardef_end

scripts/extract_layers_info/obtain_csv_files/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Utility "Extract Layers Info" is python3 scripts (recommended Python 3.6 or high
44
information about layers in neural networks IRs. Later this information could be saved in various formats: csv, html, etc.
55
Current version supports csv-files.
66

7-
### How to obtain cvs-files and upload them into spreadsheet
8-
In this scenario data about IR's layers are written to cvs-files for transformations into spreadsheet.
7+
### How to obtain csv-files and upload them into spreadsheet
8+
In this scenario data about IR's layers are written to csv-files for transformations into spreadsheet.
99
During working process script shows list of directories where it finds IRs and list of corresponding csv-files.
1010

1111
1. Goto script directory:

src/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ endif()
1919
add_subdirectory(vpux_utils)
2020

2121
add_subdirectory(vpux_compiler)
22-
23-
if((BUILD_SHARED_LIBS AND ENABLE_MLIR_COMPILER))
24-
endif()

src/vpux_compiler/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ include(cmake/add_npu_library.cmake)
8888

8989
set(VPUX_COMPILER_VERSION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/compiler_version.cpp)
9090

91+
# compiler repo git commit hash
92+
set(COMMIT_HASH_PATTERN ${CMAKE_CURRENT_SOURCE_DIR}/include/vpux/compiler/compiler_hash.hpp.in)
93+
set(COMMIT_HASH_FILE ${CMAKE_CURRENT_BINARY_DIR}/include/vpux/compiler/compiler_hash.hpp)
94+
set(COMMIT_HASH_CACHE ${CMAKE_CURRENT_BINARY_DIR}/include/vpux/compiler/compiler_hash.hpp.pre)
95+
96+
add_custom_target(update_compiler_hash ALL
97+
COMMAND ${CMAKE_COMMAND}
98+
-D REPO_DIR=${PROJECT_SOURCE_DIR}
99+
-D COMMIT_HASH_PATTERN=${COMMIT_HASH_PATTERN}
100+
-D COMMIT_HASH_FILE=${COMMIT_HASH_FILE}
101+
-D COMMIT_HASH_CACHE=${COMMIT_HASH_CACHE}
102+
-P ${PROJECT_SOURCE_DIR}/cmake/compiler_commit_hash.cmake
103+
COMMENT "Updating compiler commit hash..."
104+
BYPRODUCTS ${COMMIT_HASH_FILE}
105+
)
106+
107+
add_library(compiler_commit_hash INTERFACE)
108+
target_include_directories(compiler_commit_hash INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include/vpux/compiler)
109+
add_dependencies(compiler_commit_hash update_compiler_hash)
110+
91111
# Construct source files after BITCOMPACTOR configuration
92112
add_subdirectory(src)
93113
get_property(VPU_SRC_LIBS GLOBAL PROPERTY NPU_SRC_LIB_LIST)

src/vpux_compiler/cmake/add_npu_library.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ function(add_npu_library name)
6666

6767
update_npu_src_lib_list(${name})
6868
enable_warnings_as_errors(${name} WIN_STRICT)
69+
ov_build_target_faster(${name} PCH_HEADER ${VPU_COMPILER_PCH_FILE})
6970
endfunction(add_npu_library)

src/vpux_compiler/cmake/vpux_tblgen.cmake

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ add_custom_target(MLIRVPUXIncGenList)
77

88
function(add_vpux_dialect dialect_namespace)
99
set(LLVM_TARGET_DEFINITIONS dialect.td)
10-
mlir_tablegen(dialect.hpp.inc -gen-dialect-decls -dialect=${dialect_namespace}
11-
)
12-
mlir_tablegen(dialect.cpp.inc -gen-dialect-defs -dialect=${dialect_namespace}
13-
)
10+
mlir_tablegen(dialect.hpp.inc -gen-dialect-decls -dialect=${dialect_namespace})
11+
mlir_tablegen(dialect.cpp.inc -gen-dialect-defs -dialect=${dialect_namespace})
1412
add_public_tablegen_target(MLIRVPUX${dialect_namespace}DialectIncGen)
1513
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${dialect_namespace}DialectIncGen)
1614
endfunction()
1715

1816
function(add_vpux_ops dialect_namespace arch)
1917
set(LLVM_TARGET_DEFINITIONS ops.td)
20-
mlir_tablegen(ops.hpp.inc -gen-op-decls
21-
)
22-
mlir_tablegen(ops.cpp.inc -gen-op-defs
23-
)
18+
mlir_tablegen(ops.hpp.inc -gen-op-decls)
19+
mlir_tablegen(ops.cpp.inc -gen-op-defs)
2420
add_public_tablegen_target(MLIRVPUX${dialect_namespace}${arch}OpsIncGen)
2521
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${dialect_namespace}${arch}OpsIncGen)
2622
if(arch STREQUAL GENERIC)
@@ -33,51 +29,42 @@ endfunction()
3329
function(add_vpux_ops_granular dialect_namespace arch target_dir ops_target)
3430
set(LLVM_TARGET_DEFINITIONS ${target_dir}/${ops_target}.td)
3531
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${target_dir})
36-
mlir_tablegen(${target_dir}/${ops_target}.hpp.inc -gen-op-decls
37-
)
38-
mlir_tablegen(${target_dir}/${ops_target}.cpp.inc -gen-op-defs
39-
)
32+
mlir_tablegen(${target_dir}/${ops_target}.hpp.inc -gen-op-decls)
33+
mlir_tablegen(${target_dir}/${ops_target}.cpp.inc -gen-op-defs)
4034
add_public_tablegen_target(MLIRVPUX${dialect_namespace}${arch}${ops_target}OpsIncGen)
4135
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${dialect_namespace}${arch}${ops_target}OpsIncGen)
4236
endfunction()
4337

4438
function(add_vpux_ops_interface ops_namespace doc_dir)
4539
set(LLVM_TARGET_DEFINITIONS ops_interfaces.td)
46-
mlir_tablegen(ops_interfaces.hpp.inc -gen-op-interface-decls
47-
)
48-
mlir_tablegen(ops_interfaces.cpp.inc -gen-op-interface-defs
49-
)
40+
mlir_tablegen(ops_interfaces.hpp.inc -gen-op-interface-decls)
41+
mlir_tablegen(ops_interfaces.cpp.inc -gen-op-interface-defs)
5042
add_public_tablegen_target(MLIRVPUX${ops_namespace}OpsInterfacesIncGen)
5143
add_mlir_doc(ops_interfaces _${ops_namespace}_ops_interfaces ${doc_dir} -gen-op-interface-docs)
5244
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${ops_namespace}OpsInterfacesIncGen)
5345
endfunction()
5446

5547
function(add_vpux_type_interface ops_namespace doc_dir)
5648
set(LLVM_TARGET_DEFINITIONS type_interfaces.td)
57-
mlir_tablegen(type_interfaces.hpp.inc -gen-type-interface-decls
58-
)
59-
mlir_tablegen(type_interfaces.cpp.inc -gen-type-interface-defs
60-
)
49+
mlir_tablegen(type_interfaces.hpp.inc -gen-type-interface-decls)
50+
mlir_tablegen(type_interfaces.cpp.inc -gen-type-interface-defs)
6151
add_public_tablegen_target(MLIRVPUX${ops_namespace}TypeInterfacesIncGen)
6252
add_mlir_doc(type_interfaces _${ops_namespace}_type_interfaces ${doc_dir} -gen-type-interface-docs)
6353
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${ops_namespace}TypeInterfacesIncGen)
6454
endfunction()
6555

6656
function(add_vpux_attr_interface ops_namespace doc_dir)
6757
set(LLVM_TARGET_DEFINITIONS attr_interfaces.td)
68-
mlir_tablegen(attr_interfaces.hpp.inc -gen-attr-interface-decls
69-
)
70-
mlir_tablegen(attr_interfaces.cpp.inc -gen-attr-interface-defs
71-
)
58+
mlir_tablegen(attr_interfaces.hpp.inc -gen-attr-interface-decls)
59+
mlir_tablegen(attr_interfaces.cpp.inc -gen-attr-interface-defs)
7260
add_public_tablegen_target(MLIRVPUX${ops_namespace}AttrInterfacesIncGen)
7361
add_mlir_doc(attr_interfaces _${ops_namespace}_attr_interfaces ${doc_dir} -gen-attr-interface-docs)
7462
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${ops_namespace}AttrInterfacesIncGen)
7563
endfunction()
7664

7765
function(add_vpux_pass ops_namespace doc_prefix doc_dir)
7866
set(LLVM_TARGET_DEFINITIONS passes.td)
79-
mlir_tablegen(passes.hpp.inc -gen-pass-decls -name=${ops_namespace}
80-
)
67+
mlir_tablegen(passes.hpp.inc -gen-pass-decls -name=${ops_namespace})
8168
add_public_tablegen_target(MLIRVPUX${doc_prefix}PassesIncGen)
8269
add_mlir_doc(passes _${doc_prefix}_passes ${doc_dir} -gen-pass-doc)
8370
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${doc_prefix}PassesIncGen)
@@ -88,27 +75,21 @@ function(add_vpux_attribute ops_namespace)
8875
cmake_parse_arguments(ARG "${options}" "" "" ${ARGN})
8976
set(LLVM_TARGET_DEFINITIONS attributes.td)
9077
if(ARG_ENABLE_VPUX_ENUMS)
91-
mlir_tablegen(enums.hpp.inc -gen-enum-decls
92-
)
93-
mlir_tablegen(enums.cpp.inc -gen-enum-defs
94-
)
78+
mlir_tablegen(enums.hpp.inc -gen-enum-decls)
79+
mlir_tablegen(enums.cpp.inc -gen-enum-defs)
9580
endif()
9681
if(ARG_ENABLE_VPUX_ATTR)
97-
mlir_tablegen(attributes.hpp.inc -gen-attrdef-decls
98-
)
99-
mlir_tablegen(attributes.cpp.inc -gen-attrdef-defs
100-
)
82+
mlir_tablegen(attributes.hpp.inc -gen-attrdef-decls)
83+
mlir_tablegen(attributes.cpp.inc -gen-attrdef-defs)
10184
endif()
10285
add_public_tablegen_target(MLIRVPUX${ops_namespace}AttrIncGen)
10386
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${ops_namespace}AttrIncGen)
10487
endfunction()
10588

10689
function(add_vpux_type ops_namespace)
10790
set(LLVM_TARGET_DEFINITIONS types.td)
108-
mlir_tablegen(types.hpp.inc -gen-typedef-decls --typedefs-dialect=${ops_namespace}
109-
)
110-
mlir_tablegen(types.cpp.inc -gen-typedef-defs --typedefs-dialect=${ops_namespace}
111-
)
91+
mlir_tablegen(types.hpp.inc -gen-typedef-decls --typedefs-dialect=${ops_namespace})
92+
mlir_tablegen(types.cpp.inc -gen-typedef-defs --typedefs-dialect=${ops_namespace})
11293
add_public_tablegen_target(MLIRVPUX${ops_namespace}TypesIncGen)
11394
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${ops_namespace}TypesIncGen)
11495
endfunction()
@@ -131,8 +112,7 @@ endfunction()
131112

132113
function(add_vpux_rewrite td_file ops_namespace)
133114
set(LLVM_TARGET_DEFINITIONS rewriters/${td_file}.td)
134-
mlir_tablegen(${td_file}.hpp.inc -gen-rewriters
135-
)
115+
mlir_tablegen(${td_file}.hpp.inc -gen-rewriters)
136116
add_public_tablegen_target(MLIRVPUX${ops_namespace}RewriterIncGen)
137117
add_dependencies(MLIRVPUXIncGenList MLIRVPUX${ops_namespace}RewriterIncGen)
138118
endfunction()

src/vpux_compiler/docs/code_style.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,51 @@ Example:
369369
#include "vpux/compiler/init.hpp"
370370
```
371371

372+
### Forward declarations
373+
374+
Some headers can grow very large in time, which can negatively affect the build time of the project. During the project build, the headers need to be processed for all of the files that include them. As a consequence, if the headers are large, a significant amount of time will be spent processing the same header. One way to prevent this is to avoid having large headers included in other headers, by using forward declarations where possible. For example:
375+
376+
```cpp
377+
// BAD: `VPUIP/IR/ops.hpp` contains the definitions of all of the operations in the VPUIP dialect,
378+
// which can result in tens of thousands of lines included in the file, while this header only needs to know that VPUIP::NCEClusterTaskOp exists
379+
#include "vpux/compiler/dialect/VPUIP/IR/ops.hpp"
380+
vpux::VPUIP::NCEClusterTaskOp processNCEOp(vpux::VPUIP::NCEClusterTaskOp);
381+
382+
// OK: the `vpux::VPUIP::NCEClusterTaskOp` symbol is forward-declared, so it is known to the rest of the header; the large `VPUIP/IR/ops.hpp` does not need to be included
383+
namespace vpux::VPUIP {
384+
class NCEClusterTaskOp;
385+
}
386+
vpux::VPUIP::NCEClusterTaskOp processNCEOp(vpux::VPUIP::NCEClusterTaskOp);
387+
```
388+
389+
By using forward declarations, the definition of a symbol is no longer known to the file. The declaration is sufficient for simple cases like the one above, where the symbol is used in the signature of a function (as an argument or a return value). Forward declaration however is not usable in case the definition of a symbol is necessary, such as when the size of the object or its internal details (e.g. methods) must be known. Examples:
390+
391+
```cpp
392+
// The `getInput` method of `vpux::VPUIP::NCEClusterTaskOp` is accessed, so its definition must be known
393+
// Note: the function is inline, so it can be defined in a header file
394+
inline mlir::Value getNCEInput(vpux::VPUIP::NCEClusterTaskOp nceOp) {
395+
return nceOp.getInput();
396+
}
397+
398+
// The definitions of `mlir::IntegerAttr` and `mlir::MLIRContext` must be known
399+
// Note: the function is a template one, so it can be defined in a header file
400+
template <typename T>
401+
mlir::IntegerAttr getIntAttr(mlir::MLIRContext* ctx, T val) {
402+
return mlir::IntegerAttr::get(mlir::IntegerType::get(ctx, 64), val);
403+
}
404+
405+
// The definition of `vpux::VPUIP::NCEClusterTaskOp` must be known, for it to have a default value
406+
void processNCEOp(vpux::VPUIP::NCEClusterTaskOp = nullptr);
407+
```
408+
409+
Based on these examples, it should be clear when it is feasible to use forward declarations. In case the definition of a symbol is necessary because it is used in template / inline functions or because it has a default value, consideration should be given to refactoring this code. It is possible under many circumstances to move such function definitions to source files or to avoid default arguments, especially when the build time of the project might negatively suffer.
410+
411+
When using forward declaration for a symbol, its definition will likely be necessary in the source file(s) that use it. For the first example above, the source file that defines the `processNCEOp` method will need to include the `VPUIP/IR/ops.hpp` header. The benefit of this approach is that only this source file will have to process `VPUIP/IR/ops.hpp` during the project build, instead of all of the sources which include the header that declares `processNCEOp`.
412+
413+
**Note:** The forward declaration of a symbol must be the identical to the definition. For example, if an enum is defined as `enum class MyEnum : uint64_t {...}`, its forward declaration must reflect this type as well: `enum class MyEnum : uint64_t;`. Otherwise, the project will fail to build with an error.
414+
415+
**Note:** In case the definition of a symbol is necessary, but a translation unit only has access to its declaration, an incomplete type error will appear during build. To solve this, the header which contains the symbol's definition should be included in the source that requires it.
416+
372417
## Patterns
373418

374419
### Return Early Pattern
@@ -525,6 +570,13 @@ const auto newType = callOnShapeOf(type, [&](const auto& shape) {
525570

526571
<u>Note:</u> The return type of the callable must be the same regardless of the input shape type.
527572

573+
<u>Note:</u> It is recommended to use the `getBoundedShape/getBoundedMemShape` helper functions instead of `getShape/getMemShape` whenever static or dynamic shapes are possible.
574+
* Prefer `getBoundedShape/getBoundedMemShape` if shapes might be dynamic, and logic should operate on upper bounds in that case.
575+
`getBoundedShape/getBoundedMemShape` returns the upper bounds of the shape if it is bounded, otherwise returns the shape itself.
576+
* Use `getShape/getMemShape` when you specifically need to know which dimensions are dynamic. Be aware that for dynamic dimensions, `getShape/getMemShape` will return `mlir::ShapedType::kDynamic` as the value. Ensure your logic correctly handles this case and works with IR as expected.
577+
* Use `getShape/getMemShape` if you are certain that the operation will only ever encounter static shapes. In this case, all dimensions are known at compile time, and `getShape` will return concrete values for each dimension.
578+
579+
This helps ensure that any logic relying on shape information is robust to both static and dynamic cases and avoids unexpected behavior when working with tensors or arrays whose dimensions may not be fully known at compile time.
528580
### Using method 'llvm::make_early_inc_range'
529581

530582
This method is useful when you iterate through a list of objects and you need to change this range at the same time. From the description:
@@ -850,7 +902,7 @@ void implementPattern(IE::ConvolutionOp origOp) {
850902
However, `mlir::UnknownLoc` and `mlir::NameLoc` can be used in cases, where operation does not originate from original nGraph network or represents compiler internals. Usually such operations belongs to top-level module op. PSS tests and mapped-inference related passes are also an exception.
851903
852904
```cpp
853-
innerBuilder.create<IE::MemoryResourceOp>(mlir::UnknownLoc::get(ctx), memSpace.getLeafReference(), byteSizeAttr, nullptr); // OK, memory reservation is not a real operation
905+
innerBuilder.create<config::MemoryResourceOp>(mlir::UnknownLoc::get(ctx), memSpace.getLeafReference(), byteSizeAttr, nullptr); // OK, memory reservation is not a real operation
854906
855907
auto newFuncOp = innerModuleBuilder.create<mlir::func::FuncOp>(mlir::UnknownLoc::get(ctx), functionName, funcType); // OK, funcOp here is external shave function
856908

src/vpux_compiler/docs/guides/project_structure.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ where `strategy` is `IGreedilyPassStrategy` and it can be implemented in differe
139139
// 37XX
140140
void UnrollDistributedOpsStrategy::addPatterns(mlir::RewritePatternSet& patterns) {
141141
auto module = _func->getParentOfType<mlir::ModuleOp>();
142-
auto dmaOp = IE::getAvailableExecutor(module, VPU::ExecutorKind::DMA_NN);
142+
auto dmaOp = config::getAvailableExecutor(module, VPU::ExecutorKind::DMA_NN);
143143
auto dmaPortCount = dmaOp.getCount();
144144

145145
patterns.add<VPUIP::ClusterDMARewriter>(&_ctx, dmaPortCount, _log);
@@ -150,7 +150,7 @@ void UnrollDistributedOpsStrategy::addPatterns(mlir::RewritePatternSet& patterns
150150
// 40XX
151151
void UnrollDistributedOpsStrategy::addPatterns(mlir::RewritePatternSet& patterns) {
152152
auto module = _func->getParentOfType<mlir::ModuleOp>();
153-
auto dmaOp = IE::getAvailableExecutor(module, VPU::ExecutorKind::DMA_NN);
153+
auto dmaOp = config::getAvailableExecutor(module, VPU::ExecutorKind::DMA_NN);
154154
auto dmaPortCount = dmaOp.getCount();
155155

156156
patterns.add<VPUIP::ClusterDMARewriter>(&_ctx, dmaPortCount, _log);

0 commit comments

Comments
 (0)