Refactor the autoschedulers to their own directory.#5228
Refactor the autoschedulers to their own directory.#5228steven-johnson merged 38 commits intomasterfrom
Conversation
|
Can you elaborate on the weak linkage thing? I didn't think that was the case. My understanding was that the plugins rely on having their static constructors called at load time, and need to use symbols from the parent library, and that both of these things were normal on Windows. |
steven-johnson
left a comment
There was a problem hiding this comment.
General direction definitely LGTM; obviously we'll need to get this working on non-Windows too. (I guess we're gonna need to add Makefile support too, alas.)
compiling Li2018 against shared Halide results in a ~130KB binary and compiling it against static Halide results in a 20MB binary
I wonder if there might be hidden issues with compiling against a non-shared libHalide; Halide uses globals in various ways and it doesn't seem impossible that having non-shared sets of these could cause amusing issues (e.g. when creating unique names).
src/Util.cpp
Outdated
| << err_msg << "\n"; | ||
| } | ||
|
|
||
| FARPROC as_name = GetProcAddress(library, "AutoschedulerName"); |
There was a problem hiding this comment.
I don't know I should be surprised that the legacy of NEAR/FAR ptrs on x86 lingers on to this day, but somehow I am
| @@ -1,23 +1,14 @@ | |||
| #include "halide_mullapudi2016_export.h" | |||
There was a problem hiding this comment.
Where/how do these _export.h files get created? What do they contain?
|
|
||
| namespace Halide { | ||
| namespace Internal { | ||
| #include <Halide.h> |
There was a problem hiding this comment.
Pretty sure that it should always be "Halide.h" and never <Halide.h>
If a library is shared, all platforms behave similarly at runtime. At build time. the plugin and the executable both link directly to the same shared library. The library gets loaded when the application loads. Then when the plugin gets loaded, its dependency on the library gets resolved to the previously loaded copy. This is only no-compromises, cross-platform way for loadable plugins to work. Referencing symbols from a parent executable is totally different. Because the Windows loader has absolutely no form of dynamic lookup, a plugin referencing symbols in an executable must still link to a But now we can see why trying to reference symbols from a parent static library is unportable. On Windows, the static library just gets completely absorbed into the parent application. Every application has its symbols at different positions, so there's no universal
There probably are. The other consequence of no dynamic symbol lookup is that we can't rely on static initialization to call |
I thought this is what we were already doing.
If this works, it's a side-effect of the current design, not intentional. You should not be statically linking libHalide into a generator binary - that makes every generator binary huge.
I don't understand how the static initialization could be duplicated. The only translation unit it exists in is one that went into the plugin. That code is hidden inside a .cpp file inside the autoscheduler. |
|
Oh you're saying the static in Pipeline::get_autoscheduler_map will be duplicated, not the static initializer itself. So there are multiple ways in which things can't work if we statically link libHalide, but the current design seems like it works fine with a shared libHalide. So why redesign? EDIT: Also that's not the only static hidden inside libHalide that the plugin needs, so just changing things to avoid that one usage isn't going to make a static libHalide work with a plugin. |
It is, for shared libs.
Then why are we using
Correct.
To allow plugins to work with statically linked generator binaries. Or statically linked JIT applications. There's no reason it shouldn't work or we shouldn't allow it. |
|
I don't believe it's possible to get statically linked generator binaries to work with plugins. They can use arbitrary statics inside libHalide. (E.g. the ones in IROperator.cpp) |
|
As far as I can tell, the makefile doesn't use rdynamic for libHalide. It uses it for the tests to make define_extern work when JITting (because shared libHalide needs to resolve a symbol in the test binary). |
|
Maybe the static variant we should support is a static libHalide with static autoschedulers. If you want things to be static, you can link the autoschedulers into the generator binary and still use -s, if not -p. |
|
Then there are three paths forward:
|
This is what I meant by
above. |
|
Ah, I missed that part. I think loading two copies of libHalide is probably a bad idea, no matter what we do with our globals. We should just go with option 1. |
|
People are welcome to also statically link the plugin into the generator binary, but we don't have to support that in the cmake build. They can write their own build config if they want to do that. |
Actually, I misunderstood you. See (2) below.
I played around with doing this, and there are two approaches.
Assuming we want to support a static scenario, I think (2) is probably worth the effort since you don't want to be compiling with whole-archive if you can avoid it, anyway and it would certainly be more convenient, linking-wise. |
|
I was indeed suggesting 1, because of the tricky issues you raise with 2. edit to add: but I also think we should just not support static linkage for now and just let people figure it out themselves if they have some weird need for it. |
That's fine by me and I'm currently re-working this PR to use the static initializers and not build the autoschedulers when building Halide as a static library. |
2f672c8 to
dac3d93
Compare
a58deae to
7fe187c
Compare
|
Rebased on master... removing skip_buildbots to verify that CMake is still working everywhere. Still need support updating the Makefiles. |
I deleted some dead stuff to reclaim space. (The last buildbot update renamed some things but didn't delete old stuff.) |
…alide into refactor/autoschedulers
|
Single failure is due to Hexagon issues upstream. Woot! Please review & we can merge and cut releases |
We can merge, but any 'releases' we cut will need to be labeled as 'we know this is broken, do not use long term' until the upstream issue is fixed. |
Releasing versions 9 and 10 shouldn't be affected |
|
Ah, gotcha. (FYI, the buildbots aren't building LLVM9 at all now, and haven't for a few months. We could add that back, but might be simpler to just build those releases locally somewhere.) |
I have everything at my desk except for ARM hardware. |
|
I don't think there's a pressing need to release a version 9 if it's a pain. |
This PR adjusts all three existing autoschedulers including Mullapudi2016 to be standalone. It reorganizes them into a
src/autoschedulersfolder and also installs them into the release packages.The autoschedulers are also built with hidden symbols by default, so the
HALIDE_EXPORTmacro is now exposed and GCC compatible.The
add_halide_libraryfunction now adds the "auto_schedule=true" parameter to the start of the list when theAUTOSCHEDULERargument is passed. This improves ergonomics somewhat now that there is no default autoscheduler baked into the library.All the autoscheduler tests now take which autoscheduler to use as their first argument. This will enable us (later) to test every autoscheduler against the existing tests.
Fixes #4341
Fixes #4349
Fixes #4053