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

Add NVCC inability to compile .hip files notice and workaround #3650

Open
wants to merge 4 commits into
base: docs/develop
Choose a base branch
from

Conversation

jamesxu2
Copy link

@jamesxu2 jamesxu2 commented Oct 28, 2024

This docs change serves to clarify an error encountered when attempting to compile .hip files with nvcc, through hipcc.

e.g: As encountered by user in #3582

@jamesxu2
Copy link
Author

This will probably need to be consolidated around a separate FAQ-rewrite PR, once that gets merged: #3596

Comment on lines 286 to 288
## Why can't NVCC compile my .hip files?

NVCC does not recognize files with the `.hip` file extension. You must rename the source file extension to one NVCC supports, like `.cpp`. See [NVCC Supported Input File suffixes](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#supported-input-file-suffixes).
Copy link

Choose a reason for hiding this comment

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

I wouldn't immediately tell the user to rename their files as a solution to this.

  • HIP specifically provides hipcc as a wrapper around nvcc and amdclang++ to avoid these problems, so using hipcc would be one solution to this (even if that might not be desired by everyone, as hipcc also has some weird default settings)
  • If that's not desired, the file extension does not have to be renamed, that sounds more like a last resort. nvcc provides an option like almost every other compiler to specify the language of the file to be compiled (https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#x-c-c-cu-x)
    • specifying cu is most likely going to be the safe bet, as that allows c++ and hip/cuda code, whereas c++ does not allow hip/cuda code afaik

Copy link
Author

@jamesxu2 jamesxu2 Nov 8, 2024

Choose a reason for hiding this comment

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

Okay, I see that I should have been more explicit that this is a hipcc issue. The reason for this amendment is that while hipcc will alias hip* functions to cu* functions, it does not affect the file extension and passes it through to nvcc, resulting in an ambiguous error.

I will do some research to see if that compiler flag (--xcu/--xc++) can be passed through the hipcc interface to nvcc, as an alternative to file renaming. I agree that is a better option.

Here is an example of what a user might encounter attempting to compile a .HIP file with hipcc:

HIP_PLATFORM=nvidia hipcc main.hip -o hello
nvcc fatal   : Don't know what to do with 'main.hip'    <--- this error message thrown by nvcc is ambiguous


[from debug log. Notice that nvcc is invoked with the main.hip source file as input.]
failed to [execute:/usr/local/cuda/bin/nvcc](http://execute/usr/local/cuda/bin/nvcc)  -Wno-deprecated-gpu-targets  -isystem /usr/local/cuda/include -isystem "/opt/rocm-6.2.0/include"  -Wno-deprecated-gpu-targets -lcuda -lcudart -L/usr/local/cuda/lib64  main.hip -o "hello"

Copy link
Contributor

Choose a reason for hiding this comment

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

agree that --xcu seems to be viable solution

Copy link
Author

Choose a reason for hiding this comment

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

Just did some testing, I confirm that we can pass -x cu or --x cu to nvcc through hipcc and nvcc is able to compile the .hip program.

Eg. This works: HIP_PLATFORM=nvidia hipcc hello.hip -o hello -x cu

Also, a sidenote: -xcu and --xcu are not parsed correctly by nvcc and result in
nvcc fatal : Unknown option '[-]-xcu'. This is a bit different than hipcc to amdclang++ which can parse -xhip properly by splitting the single character x flag from its argument.

I will amend this doc change and clarify that it pertains to the HIP_PLATFORM=nvidia hipcc usecase.

James Xu added 2 commits November 8, 2024 14:28
…, and suggest "-x cu" to tell nvcc that a .hip file should be treated as .cu, without renaming.
@jamesxu2 jamesxu2 changed the base branch from amd-staging to docs/staging November 8, 2024 19:30
@jamesxu2 jamesxu2 changed the base branch from docs/staging to docs/develop November 8, 2024 19:33
of single backticks which apparently become italicized.

This is actually a problem in many places in the FAQ but I don't think
if I should fix those as a part of this PR.
@jamesxu2
Copy link
Author

jamesxu2 commented Nov 8, 2024

@MKKnorr I have revised this change per @yxsamliu's and your comments. It has also been rebased to docs/develop instead of amd-staging to account for the moved how-to/faq.md to root/faq.rst.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:docs-only Only run Read the Docs CI on this PR documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants