Skip to content

Commit 6b95a84

Browse files
[OS][ww12] - Upstreaming compiler repository (#47)
1 parent 5fd0b93 commit 6b95a84

File tree

2,768 files changed

+61455
-62841
lines changed

Some content is hidden

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

2,768 files changed

+61455
-62841
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ include(cmake/bundle_static_library.cmake)
8888
include(cmake/embed_bin_file.cmake)
8989
include(cmake/add_tool_target.cmake)
9090
include(cmake/coverage.cmake)
91+
include(cmake/log_level.cmake)
9192

9293
if(ENABLE_PRIVATE_TESTS)
9394
enable_testing()
9495
endif()
9596

97+
set_log_level()
98+
9699
print_enabled_npu_features()
97100

98101
#

cmake/embed_bin_file.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2022 Intel Corporation
2+
# Copyright 2022 Intel Corporation.
33
# SPDX-License-Identifier: Apache 2.0
44
#
55

cmake/features.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2022 Intel Corporation.
2+
# Copyright (C) 2022-2025 Intel Corporation.
33
# SPDX-License-Identifier: Apache 2.0
44
#
55

cmake/log_level.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Copyright (C) 2024 Intel Corporation.
3+
# SPDX-License-Identifier: Apache 2.0
4+
#
5+
6+
function(set_log_level)
7+
if(NOT DEFINED BUILD_LOG_LEVEL)
8+
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT ENABLE_DEVELOPER_BUILD)
9+
set(DEFAULT_LOG_LEVEL "LOG_INFO")
10+
else()
11+
set(DEFAULT_LOG_LEVEL "LOG_TRACE")
12+
endif()
13+
set(BUILD_LOG_LEVEL ${DEFAULT_LOG_LEVEL} CACHE STRING "Build log level")
14+
endif()
15+
if(BUILD_LOG_LEVEL STREQUAL "LOG_NONE")
16+
set(LOG_LEVEL_VALUE 0)
17+
elseif(BUILD_LOG_LEVEL STREQUAL "LOG_FATAL")
18+
set(LOG_LEVEL_VALUE 1)
19+
elseif(BUILD_LOG_LEVEL STREQUAL "LOG_ERROR")
20+
set(LOG_LEVEL_VALUE 2)
21+
elseif(BUILD_LOG_LEVEL STREQUAL "LOG_WARNING")
22+
set(LOG_LEVEL_VALUE 3)
23+
elseif(BUILD_LOG_LEVEL STREQUAL "LOG_INFO")
24+
set(LOG_LEVEL_VALUE 4)
25+
elseif(BUILD_LOG_LEVEL STREQUAL "LOG_DEBUG")
26+
set(LOG_LEVEL_VALUE 5)
27+
elseif(BUILD_LOG_LEVEL STREQUAL "LOG_TRACE")
28+
set(LOG_LEVEL_VALUE 6)
29+
else()
30+
message(FATAL_ERROR "Unknown log level: `${BUILD_LOG_LEVEL}`")
31+
endif()
32+
# Add a global definition since logger might be used without explicit cmake dependency
33+
add_compile_definitions(BUILD_LOG_LEVEL=${LOG_LEVEL_VALUE})
34+
endfunction()

scripts/run_all_lit_tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ echo ""
4949
echo "Executing tests on NPU40XX platform: $CMD_NPU40XX_TESTS"
5050
eval "$CMD_NPU40XX_TESTS"; EXIT_CODE=$(($EXIT_CODE + $?))
5151
echo ""
52-
5352
if [ $EXIT_CODE -ne 0 ]
5453
then
5554
echo "FAILURES identified"

src/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@ if(NOT ENABLE_NPU_MONO)
1111
add_definitions(-DOV_BUILD_POSTFIX=${OV_BUILD_POSTFIX_VAR})
1212
endif()
1313

14-
add_subdirectory(vpux_ngraph_transformations)
15-
1614
if(BUILD_COMPILER_FOR_DRIVER)
15+
add_definitions("-DCOMPILER_FOR_DRIVER_ENABLED")
1716
add_subdirectory(vpux_driver_compiler)
1817
endif()
1918

2019
add_subdirectory(vpux_utils)
2120

2221
add_subdirectory(vpux_compiler)
23-
24-
if(BUILD_SHARED_LIBS AND ENABLE_MLIR_COMPILER)
25-
add_subdirectory(vpux_translate_utils)
26-
endif()

src/vpux_compiler/cmake/vpux_tblgen.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2023 Intel Corporation.
2+
# Copyright (C) 2023-2025 Intel Corporation.
33
# SPDX-License-Identifier: Apache 2.0
44
#
55

src/vpux_compiler/docs/code_style.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,35 @@ TEST_F(MLIR_IndexedSymbolAttr, CheckNestedAttr) {
595595

596596
## Pipelines and passes
597597

598+
### Pass implementation
599+
600+
Passes that are defined in Tablegen have their base class auto-generated in the
601+
associated dialect's `passes.hpp.inc` file. Each pass class has its own macros:
602+
- `GEN_PASS_DEF_MYPASSNAME`: when defined, including the corresponding `passes.hpp.inc`
603+
results in the base class definition being included without including the rest of the file
604+
- `GEN_PASS_DECL_MYPASSNAME`: passes which have options also have a structure generated
605+
with said options; when this macro is defined, including the corresponding `passes.hpp.inc`
606+
results in the structure being included
607+
- the base class usually contains a constructor which receives this structure as a parameter;
608+
it is often a good idea to specify both macros
609+
610+
When creating the implementation of a pass, you can make its base class available
611+
by including it explicitly in the source file. For example, for a pass in IE dialect:
612+
```C++
613+
namespace vpux::IE {
614+
#define GEN_PASS_DECL_MYPASSNAME
615+
#define GEN_PASS_DEF_MYPASSNAME
616+
#include "vpux/compiler/dialect/IE/passes.hpp.inc"
617+
} // namespace vpux::IE
618+
```
619+
620+
Then, the base class can be found in `vpux::IE::impl::MyPassNameBase`, which
621+
you can use as the parent class for the pass implementation.
622+
623+
*Note:* When including the base class of a pass using `passes.hpp.inc`, you
624+
might also need to include the dependencies used in this class. For example,
625+
the dialect headers for the dependent dialects (e.g. `IE/IR/dialect.hpp`).
626+
598627
### Adding rewriter to a pass
599628
600629
The IR traversal within a pass usually follows a specific direction: it is

src/vpux_compiler/docs/guides/how_to_debug.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ The tools can be used to perform a full compilation of a model:
146146
./vpux-translate --vpu-arch=NPU37XX --import-IE <path to OV IR> -o net.mlir
147147

148148
# Call the DefaultHWMode pipeline over the imported IR
149-
./vpux-opt --vpu-arch=NPU37XX --default-hw-mode net.mlir -o net_out.mlir
149+
./vpux-opt --vpu-arch=NPU37XX --default-hw-mode --lower-VPUIP-to-ELF net.mlir -o net_out.mlir
150150

151151
# Export the final IR into an ELF file
152152
./vpux-translate --vpu-arch=NPU37XX --export-ELF net_out.mlir > net.blob
@@ -171,6 +171,41 @@ The compiler contains a pass which can generate a Dot Graph representation of th
171171
- Using the compiler pipeline, by manually adding the `PrintDot` pass where desired and rebuilding the project
172172
- example: `pm.addPass(createPrintDot(<FileName>, <Options>));`
173173

174+
## Debugging barrier dependencies
175+
176+
At several stages of compilation the structure of the control graph may change due to adding new tasks,
177+
reordering tasks, optimizing tasks dependencies etc. It is possible to check what exactly has changed after applying some
178+
transformations either across several passes, within single pass or some individual routine. BarrierInfo class
179+
offers methods to dump actual state of barrier dependencies at any stage of compilation where the concept of barriers is defined (i.e. in the VPUIP and VPURT dialects). This is typically done
180+
as follows:
181+
182+
```cpp
183+
auto& barrierInfo = getAnalysis<BarrierInfo>();
184+
barrierInfo.dumpBarriers("beforeTransformation"); // dump state before barrier optimization
185+
barrierInfo.optimizeBarriers(/* checkValidSlotCount */ false, _considerTaskFifoDependency);
186+
barrierInfo.dumpBarriers("afterTransformation"); // dump state after barrier optimization
187+
```
188+
189+
The subsequent compilation will generate a set of files prefixed "beforeTransformation" and "afterTransformation" respectively, containing the corresponding states of the graph.
190+
Extensions of the dumped files are as follows:
191+
- taskUpdateBarriers - contains list of indexes of update barriers for each task in the graph. Each row starts with a unique task index.
192+
- taskWaitBarriers - contains list of indexes of wait barriers for each task in the graph. Each row starts with a unique task index.
193+
- barrierProducerMap - contains list of indexes of producers for each barrier in the graph. Each row starts with a unique barrier index.
194+
- barrierConsumerMap - contains list of indexes of consumers for each barrier in the graph. Each row starts with a unique barrier index.
195+
- slots - contains number of slots occupied by a task when it waits or updates a barrier. Each row starts with a unique task index.
196+
- taskQueueTypeMap - contains list task indexes in each queue. Each row starts with queue name, followed by a number tasks in the queue (provided within parentheses), followed by a colon.
197+
198+
At times, it is also handy to print out the `module` or the main function, in order to make a connection between tasks/barriers indexes from the dump files and their IR representation. Tracing graph changes is not limited to methods of the BarrierInfo class, but an object of that class needs to be created in order to dump the graph dependencies with the actual state of the IR.
199+
200+
Quick investigation of the dependencies from the dump files can be easier than browsing the IR. A plotting tool (located in `tools/barrier-plotter`) can process the dump files and generate `dot` graphs, ready for viewing with e.g. `xdot`. It also exports the `dot` files to `PDF`.
201+
202+
Example usage:
203+
204+
```python
205+
plot_barriers.py beforeTransformation -o beforeTransformation
206+
```
207+
This command will read dump files `beforeTransformation.taskUpdateBarriers`, `beforeTransformation.taskWaitBarriers`, `beforeTransformation.slots` and `beforeTransformation.taskQueueTypeMap` and will produce `beforeTransformation.dot` and `beforeTransformation.dot.pdf`. The output file prefix need not be identical with the dump files prefix and can be adjusted to indicate the dump point and/or compilation configuration.
208+
174209
**Notes**
175210
- By default, declarations and constants are not included. To include them, add `print-declarations=true and print-const=true` to the pass options.
176211
- The `xdot` application can be used to visualize the dot graph. For big networks however, the application may fail to show the graph. The size of the graph can be reduced by specifying which operations should be included, with the `start-after` & `stop-before` pass options. They should be configured with the exact names of the operation from the compiler IR.

src/vpux_compiler/docs/guides/project_structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ HW-specific passes must also be registered in [vpux-opt](../../../../tools/vpux-
6767
6868
```C++
6969
// ...
70-
vpux::IE::arch37xx::registerIEPasses();
70+
vpux::IE::arch37xx::registerPasses();
7171
// ...
7272
```
7373

0 commit comments

Comments
 (0)