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

[HIPIFY] Macros not evaluated #281

Closed
ymeiron opened this issue Feb 11, 2021 · 4 comments
Closed

[HIPIFY] Macros not evaluated #281

ymeiron opened this issue Feb 11, 2021 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@ymeiron
Copy link

ymeiron commented Feb 11, 2021

The code I am trying to hipify looks like that

// test.cu
void func()
{
#if 0
    int var;
#else
    int var;
#endif
}

The command I issue is hipify-clang test.cu --cuda-path=/usr/local/cuda and the error message is:

/tmp/test.cu-d6adf8.hip:6:9: error: redefinition of 'var'
    int var;
        ^
/tmp/test.cu-d6adf8.hip:4:9: note: previous definition is here
    int var;
        ^
1 error generated when compiling for host.
Error while processing /tmp/test.cu-d6adf8.hip.

Obviously clang tries to evaluate the #if 0 code block, which is incorrect. I installed version 12.0.0 from the ROCm repository on Centos 7.

@emankov emankov changed the title Macros not evaluated [HIPIFY] Macros not evaluated Feb 11, 2021
@emankov emankov self-assigned this Feb 11, 2021
@emankov
Copy link
Collaborator

emankov commented Feb 11, 2021

It is intentionally so; the point is to hipify all preprocessor conditional branches presented in the source CUDA code, and it is the default (hipify-clang's, not clang's) behaviour. To switch to the compiler's default behaviour, when blocks under false conditional branches are removed by the preprocessor from the further compilation, the hipify-clang's option --skip-excluded-preprocessor-conditional-blocks should be specified. Please, run hipify-clang --help for more information.

P.S.
The above functionality in clang's preprocessor was specially implemented under RetainExcludedConditionalBlocks option, which is just the opposite to the hipify-clang's --skip-excluded-preprocessor-conditional-blocks.

@emankov emankov added the question Further information is requested label Feb 11, 2021
@ymeiron
Copy link
Author

ymeiron commented Feb 11, 2021

Thanks for the explanation. Of course it would have been much nicer if all preprocessor conditional branches were evaluated separately such that redefining a variable in the #else block wouldn't cause an error, it is valid C++ after all. But for my needs choosing a branch and using --skip-excluded-preprocessor-conditional-blocks did the job.

@emankov
Copy link
Collaborator

emankov commented Feb 11, 2021

Hipify-clang is not actually a compiler even it is based on clang's FE. It is a converter and its main task is to convert as much as possible from one source code written in CUDA to another, written in HIP, including the code under conditional macros.

But you're right, that this aspect is not obvious, when you get a compilation error on a valid C++ code. After implementing #1 the issue you reported will go away regardless of either --skip-excluded-preprocessor-conditional-blocks option is set or not. Btw, your case is mentioned in #1 among three main cases.

@emankov
Copy link
Collaborator

emankov commented Feb 13, 2021

Closing as answered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants