ROCm / HIPIFY

HIPIFY: Convert CUDA to Portable C++ Code
https://rocm.docs.amd.com/projects/HIPIFY/en/latest/
MIT License
524 stars 75 forks source link

[HIPIFY] Errors when convert CUDA sample to HIP? #562

Closed xianwujie closed 2 years ago

xianwujie commented 2 years ago

Hello,everyone. when I use hipify-clang to convert cuda code to hip . it produce the following error: /tmp/bcht.hpp-89daf2.hip:49:11: error: use of undeclared identifier 'cuda' cuda::thread_scope Scope = cuda::thread_scope_device, code link: https://github.com/owensgroup/BGHT/blob/main/include/bcht.hpp

Any ideas would be greatly appreciated. looking forward to your reply.

emankov commented 2 years ago

Hello @xianwujie,

Could you please provide your hipification command line and the whole hipification log? Also, add verbose support: -v option. I've tried to hipify by hipify-clang and was faced with clang compilation errors which need some changes in the header files included to bcht.hpp.

xianwujie commented 2 years ago

Hi @emankov ,thanks for your replay. I have the same problem(clang compilation errors which need some changes in the header files included to bcht.hpp.) as you。So I just converted this sentence cuda::thread_scope Scope = cuda::thread_scope_device; the whole hipification log: root@ubuntu:/home/user/pim-workspace/BGHT_wu/BGHT_xing/BGHT# ../HIPIFY/dist/hipify-clang test_hipify.cpp -v clang version 9.0.1 Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0 Candidate multilib: .;@m64 Selected multilib: .;@m64 Found CUDA installation: /usr/local/cuda-10.1, version 10.1 clang Invocation: "/home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist/clang-tool" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-target-sdk-version=10.1" "-aux-triple" "nvptx64-nvidia-cuda" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test_hipify.cpp-5dda82.hip" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-v" "-resource-dir" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/llvm-project-9.0.1/dist/lib/clang/9.0.1" "-internal-isystem" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/llvm-project-9.0.1/dist/lib/clang/9.0.1/include/cuda_wrappers" "-internal-isystem" "/usr/local/cuda-10.1/include" "-include" "__clang_cuda_runtime_wrapper.h" "-I" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/BGHT" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/llvm-project-9.0.1/dist/lib/clang/9.0.1/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/llvm-project-9.0.1/dist/lib/clang/9.0.1/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-Wno-pragma-once-outside-header" "-std=c++14" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/BGHT" "-ferror-limit" "19" "-fmessage-length" "0" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-internal-isystem" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist/../include/hipify/cuda_wrappers" "-internal-isystem" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist/../include/hipify" "-internal-isystem" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist/include/cuda_wrappers" "-internal-isystem" "/home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist/include" "-faddrsig" "-x" "cuda" "/tmp/test_hipify.cpp-5dda82.hip"

clang -cc1 version 9.0.1 based upon LLVM 9.0.1 default target x86_64-unknown-linux-gnu ignoring nonexistent directory "/include" ignoring nonexistent directory "/include" ignoring nonexistent directory "/home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist/../include/hipify/cuda_wrappers" ignoring nonexistent directory "/home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist/../include/hipify" ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0" ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward" ignoring duplicate directory "/usr/local/include" ignoring duplicate directory "/home/user/pim-workspace/BGHT_wu/BGHT_xing/llvm-project-9.0.1/dist/lib/clang/9.0.1/include" ignoring duplicate directory "/usr/include/x86_64-linux-gnu" ignoring duplicate directory "/usr/include"

include "..." search starts here:

include <...> search starts here:

/home/user/pim-workspace/BGHT_wu/BGHT_xing/BGHT /home/user/pim-workspace/BGHT_wu/BGHT_xing/llvm-project-9.0.1/dist/lib/clang/9.0.1/include/cuda_wrappers /usr/local/cuda-10.1/include /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward /usr/local/include /home/user/pim-workspace/BGHT_wu/BGHT_xing/llvm-project-9.0.1/dist/lib/clang/9.0.1/include /usr/include/x86_64-linux-gnu /usr/include /home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist/include/cuda_wrappers /home/user/pim-workspace/BGHT_wu/BGHT_xing/HIPIFY/dist/include End of search list. /tmp/test_hipify.cpp-5dda82.hip:1:1: error: use of undeclared identifier 'cuda' cuda::thread_scope Scope = cuda::thread_scope_device; ^ /tmp/test_hipify.cpp-5dda82.hip:1:28: error: use of undeclared identifier 'cuda' cuda::thread_scope Scope = cuda::thread_scope_device; ^ 2 errors generated when compiling for host. Error while processing /tmp/test_hipify.cpp-5dda82.hip.

emankov commented 2 years ago

Hello @xianwujie,

Wow, you are using very old hipify, or have you just built it against the LLVM 9.0.1? Actually, I have different, but compilation errors, not hipification errors.

xianwujie commented 2 years ago

Hi @emankov . Yes, I built HIPIFY based on ROCm4.0 + LLVM 9.0.1. Do I need to install a higher version of hipify to fix this?

emankov commented 2 years ago

Do you mean, the latest hipify-clang built from sources against LLVM from ROCm 4.0?

xianwujie commented 2 years ago

Yes, Should I choose LLVM version based on cuda version?

emankov commented 2 years ago

If you build hipify-clang from sources it always conforms to the latest ROCm HIP (5.2.0 currently). It means that the hipification by hipify-clang will be based on the latest ROCm HIP APIs (supported, unsupported, deprecated, experimental, or removed). So, in your case, it looks like you are targeting ROCm 4.0.0, but hipify is targeting ROCm 5.2.0. As for the LLVM version, if 9.0.1 suits your needs, it's ok. You have CUDA 10.1 installed it is also ok.

As for the clang compilation error you have, I think an additional #include to the CUDA include file, where cuda::thread_scope is declared, should be added to your bcht.hpp. You know, the CUDA nvcc compiler knows about the majority of its own header files and includes them implicitly (it's a tricky inconvenient way for the compilers), whereas clang doesn't know about them.

xianwujie commented 2 years ago

Hi @emankov thanks for your reply. You are right. cuda::thread_scope is declared in <cuda/atomic> . and like <hip/atomic> is not implemented in hip. Now my understanding is that HIPIFY cannot convert cuda::thread_scope from CUDA to HIP, I can only do it manually myself. Is it right?

emankov commented 2 years ago

Well, it looks like thread_scope is not provided even in ROCm HIP 5.2.0, so, without changing the sources it won't be working on the ROCm HIP platform.

xianwujie commented 2 years ago

Okay,I got it. Thanks again for your reply and have a nice weekend.

emankov commented 2 years ago

Closed as answered.