Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use le32/le64 #8344

Merged
merged 41 commits into from
Jul 26, 2024
Merged

Don't use le32/le64 #8344

merged 41 commits into from
Jul 26, 2024

Conversation

steven-johnson
Copy link
Contributor

@steven-johnson steven-johnson commented Jul 15, 2024

le32/le64 is being removed from LLVM19, which is bad for Halide. This uses i386/x86-64 and wasm32/wasm64 targets instead, with a modification to clang flags.

NOTE that if we go in this direction, it means that LLVM used for building Halide must have WebAssembly codegen enabled.

le32/le64 has been removed from LLVM19, which is bad for Halide. This attempts to use wasm32/wasm64 targets instead.
@steven-johnson
Copy link
Contributor Author

steven-johnson commented Jul 15, 2024

Oddly, it seems to work here, but inside google3 it fails massively, with every runtime call reported as missing

@mcourteaux
Copy link
Contributor

Ah, this is the fix for #8333 I guess?

steven-johnson and others added 4 commits July 16, 2024 09:20
The 64-bit atomics were all on amounts of memory, so a uintptr_t should
be safe. One bit of dodginess is that memory_total could possibly exceed
32-bits while there never being more than 32-bits of memory allocated at
any one time.
// On 32-bit platforms we don't want to use 64-bit
// atomics. Fortunately on these platforms memory usage fits into
// 32-bit integers.
sync_compare_max_and_swap((uintptr_t *)(&(instance->funcs[i]).stack_peak),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't safe or correct. stack_peak is a uint64, so the result will be incorrect on 32-bit platforms.

Copy link
Member

Choose a reason for hiding this comment

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

This assumes little-endian. It will just update the low 32 bits of stack_peak. The high bits will be zero on 32-bit targets anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch.. pretty hacky, needs better documentation. I think the warnings here are a bit of a red herring; I'd like to deal with them but as a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't it be cleaner to just change stack_peak to be a uintptr_t?

Copy link
Member

Choose a reason for hiding this comment

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

I was worried about breaking existing users of the profiler stats.

@steven-johnson steven-johnson changed the title Use wasm32/wasm64 instead of le32/le64 Don't use le32/le64 Jul 17, 2024
@steven-johnson
Copy link
Contributor Author

Mac-specific failures appear to be due to a transitory bug in top-of-tree Clang that was improperly coalescing literal strings (!)

@steven-johnson steven-johnson marked this pull request as ready for review July 17, 2024 16:37
Comment on lines 220 to 225
if (LLVM_PACKAGE_VERSION VERSION_LESS 19.0)
set(TARGET "le64-unknown-windows-unknown")
else ()
# TODO: was le64 here, not sure if this is correct or not
set(TARGET "aarch64-unknown-windows-unknown")
endif ()
Copy link
Member

Choose a reason for hiding this comment

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

What prevents us from just using aarch64/arm on all LLVM versions? I'm a bit worried about bugs in Halide 19 that appear only with LLVM 19 and not LLVM 18.

Also, does this introduce a requirement that LLVM be built with ARM and AArch64 backends? We will need to check that, if so. #2282 will rear its head again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What prevents us from just using aarch64/arm on all LLVM versions?

Nothing AFAICT. I'll make the change.

Also, does this introduce a requirement that LLVM be built with ARM and AArch64 backends

Yes.

@steven-johnson
Copy link
Contributor Author

I think this needs to be discussed at the dev meeting because of the impact it has on target-subsetted builds.

Agreed

Copy link
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

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

LGTM. We have a few alternatives if this change becomes a problem, such as working with package maintainers to include these backends.

@steven-johnson
Copy link
Contributor Author

OK, I think this combination finally works, going to land it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev_meeting Topic to be discussed at the next dev meeting 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.

5 participants