Repository navigation
Create explicit compiler C API libraries and enable dynamic linking on all platforms - #11285
Conversation
…n all platforms. This is the first step of a multi-part sequence that will: * Rebuild the compiler/API directory into its final form. * Move the compiler python API to its correct location (bindings/python). * Enable dynamic linking project wide of all compiler tools. This first step leaves the following undone: * Python API stays where it is (there are a lot of fiddly path dependencies there and I opted to handle that in isolation). * Sets everything up in an API2 which will eventually be renamed to API. * Just gets the stub of what is needed for a delay loaded embedding API -- the full thing will follow and be integrated into PJRT for Jax and TensorFlow serving on the OSS side. * The project local lld is still building static, even though the API includes it in the shared library. Was just trying to keep the patch size down vs there being a fundamental problem. In the new state, there is a libIREECompiler.so.0 (or IREECompiler.dll on Windows) which contains both the in-process APIs and the tool entry-points. The following tools have been reworked to link against the shared library: * iree-compile * iree-lld (Python side only) * iree-opt * iree-mlir-lsp-server In addition, some API tests which were doing expensive static linking now link dynamically. All said, this saves ~4-5x multi-gigabyte compiler tool linking steps and should be a pretty substantial build iteration improvement. I wasn't originally going to include iree-opt and iree-mlir-lsp-server in the shared build, but based on an experiment, they contribute negligible size (really just a few extra source files when linked together), and the productivity and usability savings (i.e. we can now distribute those at negligible cost) made me decide it was worth it. I don't know what to do about iree-run-mlir. I think I can refactor it into something based on the compiler API that then links the runtime. But that is for later. I took some steps to ensure this will work on Windows and MacOS but haven't finished verifying.
benvanik
left a comment
There was a problem hiding this comment.
This looks great to me! May want to get one more signoff from someone who may be responsible for integrating this into google3 - though because this is largely forked in API2 I suspect things may not break there immediately and there's leeway for iteration.
I am reasonably confident that this improves the google3 integration side as more of the magic bits that were only done there and were done differently on the OSS/CMake side are now unified and guaranteed working at head. Bazel is still static linking tools, and it will continue to do so because it lacks any real facility for managing cross platform dynamic/runtime stuff (and the bug has been open for years without update) -- I have no plans to change Bazel to dynamic linking tools. That would be the big thing that would make it hard to support. I will be slowly extending it in follow-ons to support delay-loading a shared library plugin on that side, which will have some touch points internally but should be in the "new stuff" category enough that it isn't disruptive and can be fixed forward. I ran the basic idea by Geoffrey... |
|
There is a postsubmit Windows test failure on my latest merged PR: https://github.com/iree-org/iree/actions/runs/3549048343 . The log is unhelpful (AFAICS), just says
I wonder if the root cause might be this PR, but it's hard to tell, because the Windows postsubmit is skipped on this PR, and even when I hit "re-run all jobs" it skips it again: |
|
The full Windows build is currently postsubmit only: Line 157 in b35c97f @ScottTodd do you think we could promote it to presubmit now? |
|
As noted on discord, should be a simple fix and I'll fix it forward. Glad we have any CI for it, frankly :) |
Yep. I'd still like to see if we can improve the repository and submodule checkout speed though... 6-10 minutes just to get the code is pretty slow :( |
We can just tack it onto my 20 year old bug "Can you please, please replace NTFS with a modern file system" :) |
|
Fixed Windows: #11298 |
| # "@llvm-project//mlir:IR" -> "MLIRIR" | ||
| # "@llvm-project//mlir:Pass" -> "MLIRPass" | ||
| return ["MLIR" + target.rsplit(":")[-1]] | ||
| # MLIR does not have header-only targets apart from the libraries. Here |
There was a problem hiding this comment.
Let's make an issue with all of these little nits. Should fix them in one go.
| self.cc_test(deps=deps + ["//runtime/src:runtime_defines"], **kwargs) | ||
|
|
||
| def iree_compiler_cc_test(self, deps=[], **kwargs): | ||
| self.cc_test(deps=deps + ["//compiler/src:defs"], **kwargs) |
There was a problem hiding this comment.
Hmmm I think we should be encoding this in the CMake, not the Bazel->CMake (same for the runtime one above)
| "@llvm-project//lld:COFF": ["lldCOFF"], | ||
| "@llvm-project//lld:Common": ["lldCommon"], | ||
| "@llvm-project//lld:ELF": ["lldELF"], | ||
| "@llvm-project//lld:MachO": ["lldMachO"], | ||
| "@llvm-project//lld:Wasm": ["lldWasm"], |
There was a problem hiding this comment.
These look pretty standardized. We should handle it as a function with only lld special cased here (I'm still a bit suspicious of the lld special case also).
| "@llvm-project//mlir:ShapeTransforms": ["MLIRShapeOpsTransforms"], | ||
| "@llvm-project//mlir:ToLLVMIRTranslation": ["MLIRTargetLLVMIRExport"], | ||
| "@llvm-project//mlir:mlir-translate": ["mlir-translate"], | ||
| "@llvm-project//mlir:MlirLspServerLib": ["MLIRLspServerLib"], |
There was a problem hiding this comment.
sigh. We should strip a leading "Mlir" from the Bazel targets in the conversion (and also fix this upstream)
| * `iree-compiler-backend` Python wheel and source distributions, providing | ||
| the `iree.compiler_backend` Python packages. | ||
| * Compiler C-API source and binary tarballs (future), with some CLI tools. | ||
| This directory is being refactored into API2. Currently, it only contains |
There was a problem hiding this comment.
I think we should probably still leave the documentation until it's actually deleted.
There was a problem hiding this comment.
I think we should probably still leave the documentation until it's actually deleted.
Was my thought too. Until I read it and realized it was hopelessly wrong and better deleted.
| # We defer it to the compiler/ directory so that cmake_install.cmake targets | ||
| # are all self contained to the compiler, which is the most common spanning | ||
| # parent. | ||
| cmake_language(EVAL CODE " |
There was a problem hiding this comment.
Yeah. Right reaction. But I copied this from some code that I think Scott wrote, so I can't claim responsibility for this hack

This is the first step of a multi-part sequence that will:
This first step leaves the following undone:
In the new state, there is a libIREECompiler.so.0 (or IREECompiler.dll on Windows) which contains both the in-process APIs and the tool entry-points. The following tools have been reworked to link against the shared library:
In addition, some API tests which were doing expensive static linking now link dynamically. All said, this saves ~4-5x multi-gigabyte compiler tool linking steps and should be a pretty substantial build iteration improvement. I wasn't originally going to include iree-opt and iree-mlir-lsp-server in the shared build, but based on an experiment, they contribute negligible size (really just a few extra source files when linked together), and the productivity and usability savings (i.e. we can now distribute those at negligible cost) made me decide it was worth it.
I don't know what to do about iree-run-mlir. I think I can refactor it into something based on the compiler API that then links the runtime. But that is for later.
I took some steps to ensure this will work on Windows and MacOS but haven't finished verifying.