Skip to content

Conversation

@alexreinking
Copy link
Member

@alexreinking alexreinking commented Aug 2, 2024

This changes the distribution method of GenGen from distributing a .cpp file along with our sources to a static library that should be linked via --whole-archive or equivalent.

Why didn't we do this before?
Prior to CMake 3.24, there was no way to force a static library to be whole-archive linked. Now it's possible.

What benefit does it confer?
We don't have to compile GenGen.cpp so many times!

Why can't we do this with RunGenMain?
We know that GenGen will always be compiled for the same platform as libHalide; after all, it links to it. We can't say the same for RunGenMain, which might get baked into a cross compile.


This PR uncovered a race condition in the generator logic. Two generators in the same directory could try (via a POST_BUILD custom command) to place Halide.dll next to them on Windows. Although this originally used the copy_if_different option, the difference check seemed to hold Halide.dll open and prevent a neighboring generator from launching. The solution was to use Powershell and a system mutex along with timestamp checking to ensure that each Halide.dll is only written to once during a build.

@alexreinking alexreinking added the release_notes For changes that may warrant a note in README for official releases. label Aug 2, 2024
Base automatically changed from build/quick-fixes to main August 2, 2024 18:46
@alexreinking
Copy link
Member Author

This is triggering a race condition between generator executables trying to copy Halide.dll next to them. This is because GenGen.cpp is no longer taking a significant time to compile. Previously, variability in scheduling made this highly unlikely to be observed.

Also use a mutex and timestamp checking to ensure that
multiple generators in the same directory do not race
to place Halide.dll next to them on Windows.
@alexreinking
Copy link
Member Author

Linux worker 1 failing because LLVM build failed.

@alexreinking alexreinking merged commit 37ab461 into main Aug 6, 2024
@alexreinking alexreinking deleted the build/gengen branch August 6, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_notes For changes that may warrant a note in README for official releases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants