-
Notifications
You must be signed in to change notification settings - Fork 370
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
LLVM 16 and 17 support #1730
LLVM 16 and 17 support #1730
Conversation
* Bump minimum supported LLVM version to 16. * Rename `makeArrayRef` to `toArrayRef` to avoid `llvm::makeArrayRef` deprecation warnings. * Minor required changes related to `llvm::Align`. * Disable `initializeInstrumentation` and `createPruneEHPass` which were remove and appear to serve no purpose now. * Add assert when using default optimization levels with legacy pass manager, which is no longer supported. This depends on both opaque pointers and new pass manager support. Signed-off-by: Brecht Van Lommel <brecht@blender.org>
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
If it helps you, this little patch will modify the CI to run the bleeding edge test on llvm 16: --------------------------- .github/workflows/ci.yml ---------------------------
index c9b8470c..be7778c7 100644
@@ -343,7 +343,7 @@ jobs:
python_ver: "3.10"
simd: avx2,f16c
batched: b8_AVX2,b8_AVX512,b16_AVX512
- setenvs: export LLVM_VERSION=14.0.0
+ setenvs: export LLVM_VERSION=15.0.6
LLVM_DISTRO_NAME=ubuntu-18.04
OPENCOLORIO_VERSION=v2.2.0
PUGIXML_VERSION=v1.13
@@ -359,8 +359,8 @@ jobs:
python_ver: "3.10"
simd: avx2,f16c
batched: b8_AVX2,b8_AVX512,b16_AVX512
- setenvs: export LLVM_VERSION=15.0.6
- LLVM_DISTRO_NAME=ubuntu-18.04
+ setenvs: export LLVM_VERSION=16.0.4
+ LLVM_DISTRO_NAME=ubuntu-22.04
OPENCOLORIO_VERSION=main
PUGIXML_VERSION=master
- desc: clang14/C++17 llvm14 boost1.71 exr3.1 py3.8 avx2 batch-b16avx512 |
Co-authored-by: Larry Gritz <lg@larrygritz.com> Signed-off-by: Brecht Van Lommel <brecht@blender.org>
Thanks. It's going to fail to build with LLVM 16 right now, but once the other PRs are merged I can try it. |
LLVM 17 (just released) actually works as well, I needed to do a minor change the new pass manager PR. |
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
i128:128 was already in the NVPTX backend since LLVM 6, the docs this was taken from seem outdated. Unclear it started failing now, but the data layout seems clearly incomplete without this. Signed-off-by: Brecht Van Lommel <brecht@blender.org>
b01aac8
to
dee0540
Compare
OptiX almost works with LLVM 16 but there is one problem,
What seems to happen is that LLVM is now generating an intrinsic that OptiX does not support. A custom LLVM 16 build with the following commit reverted works: llvm/llvm-project@2c3f82b @tgrant-nv, what would be the solution here? A fix in the OptiX driver? Somehow patching the generated ptx in OSL to avoid this instruction? |
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
I found a workaround, though it doesn't seem like a great long term solution. |
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
I encountered a problem with the
I couldn't spot anything suspicious relating to |
Thanks, Brecht. If there is a variable named Regarding the |
Ah, it's not actually using that The My understanding is that this type of target specific codegen pass should be done in |
This is what it looks like in PTX, there's not actually a
|
I've built your branch and confirmed that the issue is not in
We will need to somehow convince LLVM to generate valid names, or perhaps write a small pass to sanitize invalid names. |
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
And revert previous workaround. Signed-off-by: Brecht Van Lommel <brecht@blender.org>
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
It occurred to me that there should be no strings in the ptx code in the first place, there should only be string hashes. And it appears that there is nothing strictly requiring the hash to be evaluated at compile time. So I implemented a fix based on this: The issue of JIT potentially generating invalid global variable names remains. But I suspect it's not new and we've just been lucky that the optimizer decided to evaluate the hash at compile time in earlier LLVM versions. With this latest fix I think this PR is ready, |
@brechtvl , what is the minimum CUDA version required? I thought constexpr might have problems compiling with CUDA < 12? |
This fix should only use C++14, which has been supported since CUDA 9 (released in 2017). I couldn't find a minimum CUDA version in the OSL code, but that seems old enough. Maybe you are thinking of I have been testing with CUDA 11.8. |
I think we use 11.6 currently at SPI? (I think, I'm not in front of it at the moment.) The INSTALL.md says that OSL supports Cuda >= 8.0, but (a) we definitely don't test it, so I don't know what the actual oldest version is that works properly, and (b) I have no particular objection to picking a higher minimum, though I don't have a lot of data about how high we can go before people will be inconvenienced. (Anecdotal evidence: according to the vfx industry build matrix, the major studios are all on 9.2 and higher and the DCCs say they want 10 or higher.) |
I ran some tests:
I'm not sure what is going on with that failing test, if that's a real problem that someone using CUDA 9 or 10 might encounter in production. But for this PR at least, the usage of C++14 seems ok since it's already using |
Regarding the invalid variable name issue, I'm not sure if there is a way to trigger the existing pass ( diff --git a/src/liboslexec/llvm_instance.cpp b/src/liboslexec/llvm_instance.cpp
index 532ba40b..82a0857d 100644
--- a/src/liboslexec/llvm_instance.cpp
+++ b/src/liboslexec/llvm_instance.cpp
@@ -1871,12 +1871,28 @@ BackendLLVM::run()
fn.addFnAttr("osl-lib-function", "true");
}
+ auto cleanupName = [&](llvm::StringRef Name) {
+ std::string ValidName;
+ llvm::raw_string_ostream ValidNameStream(ValidName);
+ for (char C : Name) {
+ if (C == '.' || C == '@') {
+ ValidNameStream << "_$_";
+ } else {
+ ValidNameStream << C;
+ }
+ }
+ return ValidNameStream.str();
+ };
+
// Mark all global variables extern and discard their initializers.
// Global variables are defined in the shadeops PTX file.
for (llvm::GlobalVariable& global : ll.module()->globals()) {
global.setLinkage(llvm::GlobalValue::ExternalLinkage);
global.setExternallyInitialized(true);
global.setInitializer(nullptr);
+ std::string validName = cleanupName(global.getName());
+ if(validName != global.getName())
+ global.setName(validName);
}
}
OSL_ASSERT(ll.module()); |
https://developer.nvidia.com/blog/programming-efficiently-with-the-cuda-11-3-compiler-toolchain/ |
Thanks for checking on the Cuda versions, Brecht. It sounds like we should change the advertised set of versions for Cuda to be 9.0 minimum and 11.0+ recommended. I'm happy to quickly whip that up and submit it. |
Patch by Tim with minor code style changes. Co-authored-by: Tim Grant <tgrant@nvidia.com> Signed-off-by: Brecht Van Lommel <brecht@blender.org>
I can confirm this also fixes the issue. So included it, in case such global variables are generated for a good reason in the future. |
Sounds good. |
Signed-off-by: Brecht Van Lommel <brecht@blender.org>
Is this ready to merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and passes CI except for the Intel compiler tests which are broken for other reasons (on their end).
Yes, it's ready. |
Hi, just wanted to let you know that OSL is currently disabled on Archlinux's blender since it was waiting for LLVM 16 support. This PR seems to indicate that it is now ready, but I don't know if there's some work left on the blender side. I've emailed the arch package mantainers, haven't heard back yet. @brechtvl If I compile the latest blender from source with the same cmake command as arch's without the disable osl flag, should it work? I was relying on OSL for this. Thanks |
It does not work currently. The OSL API is still undergoing changes in the main branch, only when there is a stable OSL release can we really ensure it's compatible. I suggest to use either the Blender binary download or the build instructions from blender.org, instead of the Arch package. |
This won't be picked up by the platforms yet, they are still using 1.13.5.x for 2023.10 (as well as still OIIO 2.6.0.x, which is too old for this OSL release). So really the only client for this build is likely Arnold. Highlights: * Raise OpenImageIO to 2.6.1.0. * RS::get_texture_info make robust to empty shaderglobals param (AcademySoftwareFoundation#1731) * LLVM opaque pointers support (AcademySoftwareFoundation#1728) * LLVM new pass manager support (AcademySoftwareFoundation#1729) * LLVM 16 and 17 support (AcademySoftwareFoundation#1730) * fix: SymOverrideInfo bitfields should be the same type (AcademySoftwareFoundation#1745) * fix: batched pointcloud if "index" is not passed (AcademySoftwareFoundation#1753) * api: Ustringhash phase 3 (AcademySoftwareFoundation#1732) * fix: Fix NVPTX TargetMachine leak, etc. (AcademySoftwareFoundation#1763) * feat(api): Add API for building interpolated getter free functions. (AcademySoftwareFoundation#1765) * build: add options to use static Cuda libraries (AcademySoftwareFoundation#1772) * build(deps): Initial support for LLVM-18 (AcademySoftwareFoundation#1773) * fix: Mute partio error prints (AcademySoftwareFoundation#1774) * fix: calculatenormal needs fliphandedness (AcademySoftwareFoundation#1783) * fix: Print closure missing error message at compile time instead of run time. (AcademySoftwareFoundation#1781) * fix: GPU interpolated param initialization (AcademySoftwareFoundation#1791) * oslquery: Simplify include and link needs (AcademySoftwareFoundation#1787) * Make isconnected() work with downstream renderer "connections." (AcademySoftwareFoundation#1782) Also along for the ride: * Remove the `blah-platform/=1.0` preamble, no longer needed. * Stop building for deprecated Nuke 12 and 13 platforms. * Raise cmake build version to 3.24 See merge request spi/dev/3rd-party/osl-feedstock!57
Description
makeArrayRef
totoArrayRef
to avoidllvm::makeArrayRef
deprecation warnings.llvm::Align
.initializeInstrumentation
, which was removed and appears to serve no purpose now.i128
to OptiX data layout. This was already in the NVPTX backend since LLVM 6, the docs this was taken from seem outdated. Unclear why it started failing now, but the data layout seems clearly incomplete without this.FRem
generates anoptix.ptx.testp.infinite.f32
intrinsic that OptiX does not currently implement. Work around with custom implementation.NVPTXAssignValidGlobalNames
LLVM pass.This depends on both opaque pointers (#1728) and new pass manager support (#1729), and should not be merged before them.
Tests
CI jobs updated to use LLVM 16 for bleeding edge.
Checklist: