diff options
author | Andrzej Janik <[email protected]> | 2024-11-02 16:07:44 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-11-02 16:07:44 +0100 |
commit | 970ba5aa25b8f21b97176650bd3b6c034407e843 (patch) | |
tree | ed4ceea07824d5aa9d3d4e16e6b1d05e439d4793 | |
parent | b4cb3ade63af94ccb709f2c0858253b13125fcc6 (diff) | |
download | ZLUDA-970ba5aa25b8f21b97176650bd3b6c034407e843.tar.gz ZLUDA-970ba5aa25b8f21b97176650bd3b6c034407e843.zip |
Fix linking of AMD device libraries (#296)
It's weird that it fails without `-mno-link-builtin-bitcode-postopt`. I've tested it only on ROCm 6.2, might be broken on older or newer ROCm
-rw-r--r-- | comgr/src/lib.rs | 25 | ||||
-rw-r--r-- | ptx/lib/zluda_ptx_impl.cpp | 4 |
2 files changed, 16 insertions, 13 deletions
diff --git a/comgr/src/lib.rs b/comgr/src/lib.rs index 129dc14..94ba6ef 100644 --- a/comgr/src/lib.rs +++ b/comgr/src/lib.rs @@ -127,24 +127,27 @@ pub fn compile_bitcode( ptx_impl,
)?;
bitcode_data_set.add(&stdlib_bitcode_data)?;
- let lang_action_info = ActionInfo::new()?;
- lang_action_info.set_isa_name(gcn_arch)?;
- lang_action_info.set_language(amd_comgr_language_t::AMD_COMGR_LANGUAGE_LLVM_IR)?;
- let with_device_libs = do_action(
- &bitcode_data_set,
- &lang_action_info,
- amd_comgr_action_kind_t::AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC,
- )?;
+ let linking_info = ActionInfo::new()?;
let linked_data_set = do_action(
- &with_device_libs,
- &lang_action_info,
+ &bitcode_data_set,
+ &linking_info,
amd_comgr_action_kind_t::AMD_COMGR_ACTION_LINK_BC_TO_BC,
)?;
+ let link_with_device_libs_info = ActionInfo::new()?;
+ link_with_device_libs_info.set_isa_name(gcn_arch)?;
+ link_with_device_libs_info.set_language(amd_comgr_language_t::AMD_COMGR_LANGUAGE_LLVM_IR)?;
+ // This makes no sense, but it makes ockl linking work
+ link_with_device_libs_info.set_options([c"-Xclang", c"-mno-link-builtin-bitcode-postopt"].into_iter())?;
+ let with_device_libs = do_action(
+ &linked_data_set,
+ &link_with_device_libs_info,
+ amd_comgr_action_kind_t::AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC,
+ )?;
let compile_action_info = ActionInfo::new()?;
compile_action_info.set_isa_name(gcn_arch)?;
compile_action_info.set_options(iter::once(c"-O3"))?;
let reloc_data_set = do_action(
- &linked_data_set,
+ &with_device_libs,
&compile_action_info,
amd_comgr_action_kind_t::AMD_COMGR_ACTION_CODEGEN_BC_TO_RELOCATABLE,
)?;
diff --git a/ptx/lib/zluda_ptx_impl.cpp b/ptx/lib/zluda_ptx_impl.cpp index f1b416d..d0ec853 100644 --- a/ptx/lib/zluda_ptx_impl.cpp +++ b/ptx/lib/zluda_ptx_impl.cpp @@ -1,5 +1,5 @@ -// Every time this file changes it must te rebuilt, you need llvm-17:
-// /opt/rocm/llvm/bin/clang -Wall -Wextra -Wsign-compare -Wconversion -x hip zluda_ptx_impl.cpp -nogpulib -O3 -mno-wavefrontsize64 -o zluda_ptx_impl.bc -emit-llvm -c --offload-device-only --offload-arch=gfx1010 && llvm-dis-17 zluda_ptx_impl.bc -o - | sed '/@llvm.used/d' | sed '/wchar_size/d' | sed '/llvm.module.flags/d' | sed 's/define hidden/define linkonce_odr/g' | sed 's/\"target-cpu\"=\"gfx1010\"//g' | sed -E 's/\"target-features\"=\"[^\"]+\"//g' | llvm-as-17 - -o zluda_ptx_impl.bc && llvm-dis-17 zluda_ptx_impl.bc
+// Every time this file changes it must te rebuilt, you need `rocm-llvm-dev` and `llvm-17`:
+// /opt/rocm/llvm/bin/clang -Wall -Wextra -Wsign-compare -Wconversion -x hip zluda_ptx_impl.cpp -nogpulib -O3 -mno-wavefrontsize64 -o zluda_ptx_impl.bc -emit-llvm -c --offload-device-only --offload-arch=gfx1010 && /opt/rocm/llvm/bin/llvm-dis zluda_ptx_impl.bc -o - | sed '/@llvm.used/d' | sed '/wchar_size/d' | sed '/llvm.module.flags/d' | sed 's/define hidden/define linkonce_odr/g' | sed 's/\"target-cpu\"=\"gfx1010\"//g' | sed -E 's/\"target-features\"=\"[^\"]+\"//g' | sed 's/ nneg / /g' | sed 's/ disjoint / /g' | llvm-as-17 - -o zluda_ptx_impl.bc && /opt/rocm/llvm/bin/llvm-dis zluda_ptx_impl.bc
#include <cstddef>
#include <cstdint>
|