Closed ymeiron closed 3 years ago
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
.
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.
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 https://github.com/ROCm-Developer-Tools/HIPIFY/issues/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.
Closing as answered.
The code I am trying to hipify looks like that
The command I issue is
hipify-clang test.cu --cuda-path=/usr/local/cuda
and the error message is: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.