This is an archive of the discontinued LLVM Phabricator instance.

[HIP] Start document HIP support by clang
ClosedPublic

Authored by yaxunl on Jun 29 2023, 11:05 AM.

Details

Summary

start with example usage, predefined macros, and path setting.

Diff Detail

Event Timeline

yaxunl created this revision.Jun 29 2023, 11:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2023, 11:05 AM
yaxunl requested review of this revision.Jun 29 2023, 11:05 AM
b-sumner added inline comments.Jun 29 2023, 11:37 AM
clang/docs/HIPSupport.rst
105

Should we include the gfxNNN or GFXN macros here? What about wave size, and CU mode? And what about unsafe FP atomics macro?

yaxunl added inline comments.Jun 29 2023, 11:39 AM
clang/docs/HIPSupport.rst
105

Those are not only for HIP but for all languages targeting amdgpu. I am thinking we probably need a separate page for amdgpu support by clang.

scchan added inline comments.Jun 29 2023, 12:44 PM
clang/docs/HIPSupport.rst
34

can we add -xhip to enable HIP for files without the .hip file ext?

57

I'd suggest adding a section to cover compiler options to pass various hip/rocm related paths and that using the compiler options would be a much more preferable alternative.

88

I think this macro is essentially an alias to HIP?

100

It might be helpful to provide more context here as to how a HIP source file gets compiled (once for the host and then once for each device arch). Also I'd suggest moving this up closer to HIP given they are related.

yaxunl marked 5 inline comments as done.Jun 30 2023, 7:14 AM
yaxunl added inline comments.
clang/docs/HIPSupport.rst
34

will do

57

It may be clearer to put the options and environment vars for setting dependency paths side by side since they are connected

88

Yes. will change the description

100

will do

yaxunl updated this revision to Diff 536231.Jun 30 2023, 7:18 AM
yaxunl marked 4 inline comments as done.

revised by comments

scchan added inline comments.Jul 7 2023, 9:50 AM
clang/docs/HIPSupport.rst
83

I think it would be easier to understand by explicitly calling out the order of precedence:

  • For HIP path:
      • --hip-path option
      • HIP_PATH env var
      • --rocm-path option
    • ROCM_PATH env var
    • default automatic detection
  • For device lib:
    • --hip-device-lib-path option
    • HIP_DEVICE_LIB_PATH env var
    • --rocm-path option
    • ROCM_PATH env var
    • default automatic detection
yaxunl marked an inline comment as done.Jul 7 2023, 10:40 AM
yaxunl added inline comments.
clang/docs/HIPSupport.rst
83

wil do

yaxunl updated this revision to Diff 538201.Jul 7 2023, 10:41 AM
yaxunl marked an inline comment as done.

revised by comments

arsenm added inline comments.Jul 7 2023, 1:13 PM
clang/docs/HIPSupport.rst
50

s/architecture/architectures

100

We should really not have the environment variables I wouldn't go out of the way to advertise them, just mark as deprecated

yaxunl updated this revision to Diff 540430.Jul 14 2023, 8:13 AM

revised by comments

yaxunl marked 2 inline comments as done.Jul 14 2023, 8:14 AM
yaxunl added inline comments.
clang/docs/HIPSupport.rst
50

done

100

added warnings to discourage use of env vars

arsenm added inline comments.Jul 14 2023, 10:21 AM
clang/docs/HIPSupport.rst
34

Aren't you supposed to use clang++? Also, could show that .hip is recognized?

yaxunl marked 3 inline comments as done.Jul 14 2023, 10:31 AM
yaxunl added inline comments.
clang/docs/HIPSupport.rst
34

good point. will fix

yaxunl updated this revision to Diff 540485.Jul 14 2023, 10:32 AM
yaxunl marked an inline comment as done.
yaxunl edited the summary of this revision. (Show Details)

revised by comments

keryell added inline comments.
clang/docs/HIPSupport.rst
24

I thought the idea of HIP was to also target Nvidia GPU? Otherwise I do not understand "portable applications for GPUs" above.

33

I suggest giving also a simpler example without -c to generate directly an executable without split compile and link.
Also avoid using test as an example as it is confusing as it is also a shell builtin on Unix and it might take sometime to understand why the test does not use the GPU. :-)

35–37
141

Should this one be with underscores too?

keryell added inline comments.Jul 14 2023, 2:11 PM
clang/docs/HIPSupport.rst
24

Thinking to the fact this is used by other projects like https://github.com/CHIP-SPV/chipStar this is even wider but at the same time that project is not up-streamed.

yaxunl marked 5 inline comments as done.Jul 17 2023, 7:26 AM
yaxunl added inline comments.
clang/docs/HIPSupport.rst
24

will add a brief description of HIP support on other devices.

33

will do

35–37

will fix

141

This is due to design inconsistency. The same with __HIP_NO_IMAGE_SUPPORT.

Since these two macros are new and not widely used, renaming them won't cause significant interruptions. I will let clang emit __HIP_NO_IMAGE_SUPPORT__ and __HIP_API_PER_THREAD_DEFAULT_STREAM__ and make the current ones alias and document them as deprecated.

The macros for HIP memory scope were designed by following the naming convention of clang atomic macros e.g. __ATOMIC_RELAXED, __OPENCL_MEMORY_SCOPE_WORK_ITEM, therefore they will not be changed.

yaxunl updated this revision to Diff 541028.Jul 17 2023, 7:41 AM
yaxunl marked 4 inline comments as done.

revised by comments

scchan added inline comments.Jul 24 2023, 10:45 AM
clang/docs/HIPSupport.rst
66

missing --hip-link

78

missing --hip-link

arsenm added inline comments.Jul 24 2023, 10:52 AM
clang/docs/HIPSupport.rst
66

What does hip-link do? Why is it needed? I never use it and it works

yaxunl marked 2 inline comments as done.Jul 24 2023, 11:04 AM
yaxunl added inline comments.
clang/docs/HIPSupport.rst
66

It indicates HIP offloading at the linking stage and creates the HIP toolchain.

For -fno-gpu-rdc mode, it locates the HIP runtime library and links it.

For -fgpu-rdc mode, it unbundles object files and does device linking and embedding.

yaxunl updated this revision to Diff 543652.Jul 24 2023, 11:12 AM
yaxunl marked an inline comment as done.

revised by comments

scchan accepted this revision.Jul 24 2023, 11:58 AM

LGTM thanks

This revision is now accepted and ready to land.Jul 24 2023, 11:58 AM
keryell added inline comments.Jul 24 2023, 4:41 PM
clang/docs/HIPSupport.rst
31

Fix the spelling when we talk about the Khronos SPIR-V standard, by opposition to tool names.
Perhaps you can split the line in shorter ones so the diff are more obvious.

66

I am a little lost here.
I have the feeling that the newbie syntax (compile+link in one invocation) should be

clang++ --offload-arch=gfx906 -xhip sample.cpp -o sample

since it should be obvious to the Driver that we want to produce a working program for a GPU.
Or does this work producing a working program with another meaning?

yaxunl marked 3 inline comments as done.Jul 25 2023, 5:39 AM
yaxunl added inline comments.
clang/docs/HIPSupport.rst
31

Fix the spelling when we talk about the Khronos SPIR-V standard, by opposition to tool names.
Perhaps you can split the line in shorter ones so the diff are more obvious.

will do

66

Currently, the linker will only link HIP runtime library when --hip-link is specified.

The linker does not see -xhip sample.cpp. It only sees the intermediate obj files passed to it, therefore it does not know it is for HIP.

This could be improved by letting the clang driver add an implicit --hip-link option to the linker when the driver sees the linking of HIP input files. However, this needs a separate patch.

This revision was automatically updated to reflect the committed changes.
yaxunl marked 2 inline comments as done.
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 6:41 AM