[triton-ext] Allow plugin tests with static LLVM#9549
Conversation
e0cbeb1 to
47be941
Compare
|
This PR reverses #3879, which seems to have caused problems in the past with conflicts on LLVM symbols. If that is still an issue, it may warrant further discussion on the right path forward for plugins. |
ebf88e8 to
22731e7
Compare
Thanks for the heads up. We'll perform early testing to check for any issues with this change and will update this thread if we encounter any problems. |
22731e7 to
4dfb7ee
Compare
|
Excellent so when this merges I’ll take my pr for triton-opt out of draft then. Thanks @neildhar |
|
Exporting all LLVM symbols seems like a bad practice. That means that if any library that if anybody that use Triton and has a different LLVM library linked with it will have a linker error right? |
|
@ThomasRaoux My consideration here focused on the case where I agree that if someone either puts both Triton and some other copy of LLVM on the link line, or loads multiple copies of LLVM/Triton with Since the plugins need access to MLIR and need to agree on the global data structures in LLVM, exporting at least some portion of LLVM symbols seems necessary for the current plugin design to work. In terms of potential alternative approaches:
|
How likely is this to happen? I thought we explored this scenario when we chose not to pursue the LLVM dylib route. |
|
@plotfi I think this is orthogonal to having a separate LLVM dylib. An LLVM dylib would also have to export all of the LLVM symbols, which presents a similar set of challenges. |
Ah, thanks for clarifying. |
isn't that also the case with LLVM proper though? It's not uncommon to run into link issues if you start mixing and matching LLVM libraries for a project built on top of/using LLVM as library. |
right, I thought that's why hiding the symbols was important? Maybe I'm missing something |
|
@ThomasRaoux You're right that exporting the LLVM symbols could cause problems if there are multiple copies of LLVM and one of them ends up in the global symbol namespace. I believe for the purposes of loading this into Python, exporting the symbols should be safe because the library is opened with Are there other ways to consume |
@neildhar Some Questions: From what I gather, it seems invoking symbols from a Q1: So then is it the case that global symbols can cause problems mainly because something the Q2: Could we use an lld linker flag like |
| # Only build plugins when building libtriton since they depend on libtriton. | ||
| add_subdirectory(examples/plugins) | ||
| endif() | ||
|
|
There was a problem hiding this comment.
If --Bsymbolic is a workable solution, I think we could use it here:
if (UNIX AND NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--Bsymbolic")
endif()We need to disable the example plugins on Windows in preparation for merging triton-lang/triton#9549 into our repo. Prior to triton-lang/triton#9549, the example plugin libraries build successfully with LLVM/MLIR's static libraries and the example plugin tests are guarded by not building against shared libs. Enabling Triton extensions/plugins on Windows is difficult: #6248 (comment). This patch adds a CMake option `TRITON_ENABLE_PLUGINS` to enable/disable building the plugin libraries in `example/plugins`. It also adds a LIT config feature that reads the option to guard LIT tests that require the example plugin libraries. If the option is on, the example plugin libraries are built and the example plugin tests are enabled. If the option is off, the example plugin libraries are not built and the example plugin tests are skipped. We require that `TRITON_ENABLE_PLUGINS` is set off to build on Windows. The default value of the option is OFF for Windows and ON otherwise.
That is one failure mode. Note that this is primarily a concern for the plugin library. If there is some other library exporting LLVM, the plugins may resolve symbols from those libraries instead of libtriton. The other failure mode (which is what I think Thomas is alluding to) is if we are not using
I agree that we should be building with If we are concerned about the case where LLVM symbols may be introduced to the global namespace for dynamic symbol resolution (either by us or some other library), I think the solution will have to be built around not exporting the symbols. The other possible concern here is around binary size. Exporting everything also means we cannot analyze which symbols are dead. |
|
I think there is another alternative to this approach, exporting all the symbols; the alternative is to build a big LLVM shared library, a mega-library (
Hopefully that helps lay out the decision here. For me, the more conventional shared library approach carries a bit of weight, but if I were told that the only reasonable way to distribute things was with a single library, I would lean back towards exporting all the symbols. If we decide to export all the symbols, then this PR is definitely needed. |
|
Superseded by #9783 |
This PR performs a minimal change to export all Triton and LLVM symbols from
libtriton.so, and have the plugin resolve symbols directly from it, instead of depending on having both of them link separately against LLVM dynamic libraries. This allows us to run the Triton plugin Python tests without any special build configuration.This is intended to be a minimal incremental step to get the existing tests working. There are at least two remaining considerations:
libtriton, since we will only pull in the object files containing symbols thatlibtritonitself uses. This may be good enough in practice, otherwise, we may have to link withwhole-archive, which will have a binary size cost.triton-optworking with the new setup. Since the plugin now takes a direct dependency onlibtriton, it must be available when the plugin is loaded. We could either:triton-optalso get its symbols fromlibtriton. This is potentially invasive, and makes it less convenient to copy aroundtriton-optexecutables since they will have a dependency on the dynamic library.triton-opt. Then create a fake emptylibtriton.so, and maketriton-optdlopen it before loading a plugin. This "hack" ensures that the plugin's dependency is satisfied, but the symbols are actually resolved fromtriton-opt.