Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions cmake/onnxruntime_providers_iree.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ target_link_libraries(onnxruntime_providers_iree PRIVATE
onnx
protobuf::libprotobuf
)
if ( CMAKE_COMPILER_IS_GNUCC )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable appears to be deprecated in newer releases of CMake, so we might want to replace it with some newer alternative like CMAKE_C_COMPILER_ID.

Would you want this code to run only for GCC? Is there a reason for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the flags here aren't recognized on windows cl. I'll look for a modern alternative to this.

target_compile_options(
onnxruntime_providers_iree PRIVATE
# IREE's runtime headers are written in the C style and need some tweaks.
-Wno-missing-field-initializers
# We're not going to fix this.
-Wno-unused-function
)

target_compile_options(
onnxruntime_providers_iree PRIVATE
# IREE's runtime headers are written in the C style and need some tweaks.
-Wno-missing-field-initializers
# We're not going to fix this.
-Wno-unused-function
)

# Torch-mlir warnings disable warnings on external sources.
# TODO: Fix these at the source.
set_source_files_properties(
${onnxruntime_providers_iree_jit_compiler_srcs}
PROPERTIES
COMPILE_FLAGS
"-Wno-unused-parameter -Wno-shorten-64-to-32"
)
# Torch-mlir warnings disable warnings on external sources.
# TODO: Fix these at the source.
set_source_files_properties(
${onnxruntime_providers_iree_jit_compiler_srcs}
PROPERTIES
COMPILE_FLAGS
"-Wno-unused-parameter -Wno-shorten-64-to-32"
)
endif()

# Note that these will fail if IREECompilerConfig.cmake and IREERuntime.cmake are not on the search path.
# There are multiple ways to ensure this, but typically (as will be called out in the error message):
Expand Down
46 changes: 46 additions & 0 deletions onnxruntime/core/providers/iree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,51 @@ Explanations:
Once the build has been initially done, you can work in the `build/Linux/RelWithDebInfo` directory if that is more
comfortable.

## Building on Windows

Instructions for setting up IREE-EP on windows is similar to linux.

1. Make sure you have the appropriate C++ development environment setup. E.g. install Visual Studio Build Tools 2022 and start "x64 Native Tools Command Prompt for Visual Studio 2022" as administrator to get access to a compiler and linker. It is useful to check that you have registry edit permissions (try running regedit), since successful initialization of this environment requires such access. If you don't already have cmake and ninja, install them with winget (or your preferred method). Once you have the development environment setup, it is helpful to run
```powershell
powershell
Set-ExecutionPolicy Bypass -Scope Process
cd <your development directory>
```

2. Build IREE from source. After cloning the repository and updating submodules, you can use a build command like the following to get an IREE build that will work with IREE-EP for llvm-cpu:
```powershell
cmake -S . -B build -G "Ninja" -DCMAKE_BUILD_TYPE=Release `
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DIREE_ENABLE_ASSERTIONS=ON `
-DLLVM_ENABLE_ASSERTIONS=ON -UIREE_DEFAULT_CPU_LLVM_TARGETS `
-DIREE_BUILD_SAMPLES=OFF -DIREE_BUILD_PYTHON_BINDINGS=OFF `
-DIREE_BUILD_BINDINGS_TFLITE=OFF -DIREE_HAL_DRIVER_DEFAULTS=OFF `
-DIREE_HAL_DRIVER_LOCAL_SYNC=ON -DIREE_HAL_DRIVER_LOCAL_TASK=ON `
-DIREE_TARGET_BACKEND_DEFAULTS=OFF -DIREE_TARGET_BACKEND_LLVM_CPU=ON `
-DIREE_INPUT_TOSA=OFF -DIREE_INPUT_STABLEHLO=OFF -DIREE_ENABLE_CPUINFO=OFF
```
Importantly, `-DIREE_ENABLE_CPUINFO=OFF` is required to work properly with IREE-EP.

3. Add iree-compile and iree-run-module to PATH:
```powershell
$env:path += ";<abs path to IREE build dir>\tools"
```
This is an important step, otherwise onnxruntime executable files won't be able to find `ireeCompiler.dll` and will just silently fail.

4. Clone this repo and run the following build command from your onnxruntime directory:
```powershell
.\build.bat --config=RelWithDebInfo --cmake_generator=Ninja `
--build_shared_lib `
--compile_no_warning_as_error `
--parallel `
--use_iree `
--cmake_extra_defines "IREECompiler_DIR=C:/z/iree/build/lib/cmake/IREE" `
--cmake_extra_defines "IREERuntime_DIR=C:/z/iree/build/lib/cmake/IREE" `
--use_full_protobuf `
--enable_symbolic_shape_infer_tests `
--update `
--build
```

## Build from released IREE

IMPORTANT: This will currently not work with stock IREE builds because of the cpuinfo issue listed above.
Expand All @@ -82,6 +127,7 @@ packaging==23.2
protobuf==4.25.1
sympy==1.12
```
Note: the following commands also work with windows powershell, but you'll need to change the forward to back slashes in file paths, and use backtick instead of backslash to seperate a command into multiple lines.

```
# From build dir.
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/core/providers/iree/compiler/jit_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ CompilerInvocation::CompilerInvocation(CompilerSession& session, const char* mod
CompilerInvocation* self = static_cast<CompilerInvocation*>(userData);
self->diagnostics.emplace_back(DiagnosticRecord{severity, std::string(message, messageSize)});
// VLOG it.
VLOGS(session.logger, INFO) << self->diagnostics.back().ToString();
VLOGS(self->session.logger, INFO) << self->diagnostics.back().ToString();
},
static_cast<void*>(this));

Expand All @@ -120,7 +120,7 @@ CompilerInvocation::CompilerInvocation(CompilerSession& session, const char* mod
auto* self = static_cast<CompilerInvocation*>(userdata);
// TODO: We need to have better configuration for how to dump such reproducers.
auto output_path = std::filesystem::temp_directory_path() / "ort_iree_reproducer.mlir";
std::string output_path_str = output_path;
std::string output_path_str = output_path.string();
LOGS(self->session.logger, ERROR) << "IREE compiler crash. Writing reproducer to: " << output_path_str;
return ireeCompilerOutputOpenFile(output_path_str.c_str(), out_output);
},
Expand Down