HIP icon indicating copy to clipboard operation
HIP copied to clipboard

Failed compilation for floating point template parameters

Open Sephirothbahamut opened this issue 2 years ago • 7 comments

Hi, I've reported the same bug on nvcc one year ago, and now that I'm trying HIP the bug is following me. Floating point template parameters are supported as of C++20.

I'm on a Windows machine, compiling via Visual Studio. If I compile the HIP code through nvcc it works properly (Project settings > General > Platform Toolset > AMD HIP for nvcc Compiler), while if I compile the same code with HIP-clang (AMD HIP for clang Compiler) the code fails to compile.

Minimal example:

template <float f>
__global__ void func_template()
    {
    printf("\nValue: %f\n", f);
    }

int main()
    {
    func_template<1.f><<<1, 1, 0>>>();
    HIP_CHECK(hipDeviceSynchronize());
    }
1>main.hip(134,5): error : no matching function for call to 'func_template'
1>main.hip(127,17): note: candidate template ignored: invalid explicitly-specified argument for template parameter 'f'

Sephirothbahamut avatar Sep 26 '23 18:09 Sephirothbahamut

clang by default uses the same C++ standard for C++ and HIP programs. To use C++20 standard you need to add option -std=c++20.

yxsamliu avatar Sep 26 '23 18:09 yxsamliu

@yxsamliu where do I add command line options for Clang in the Visual Studio example solutions? All the specific options I see are labelled as [AMD HIP for nvcc]. I was assuming that using the "AMD HIP for clang Compiler" toolset it would follow the language standard selected in general properties... (which was already set to C++20)

Sephirothbahamut avatar Oct 08 '23 17:10 Sephirothbahamut

you may switch toolset:

image

normally if you have env var HIP_PATH set, this should be auto. https://rocm.docs.amd.com/projects/hip-vs/en/latest/usage.html

yxsamliu avatar Oct 11 '23 15:10 yxsamliu

Additionally, be aware of Configuration (Debug and Release by default). You may change the Platform Toolset only for a single Configuration, or for All configurations, or for Multiple Configurations....

emankov avatar Oct 11 '23 16:10 emankov

Sorry for the late reply; that's not a fix to the issue, I'm already switching toolsets. Maybe my explanation was poor. Compiling the example code I wrote in the previous post with a pure CUDA project, i can make it work. Compiling it from a HIP project (I modified ROCm-Example's hello world) with the "AMD HIP for nvcc Compiler" toolset and the "ISO C++20 Standard (std=c++20)" standard in General settings it compiles and it works without issues. It's only when compiling it from a HIP project with the "AMD HIP for clang Compiler" toolset (same language standard as before) that it doesn't compile. And my only hypothesis is that it's not compiling because of the compiler not following the standard chosen C++20 standard for some reason, as the error doesn't occur when using non-floating template parameters, it only occurs with floating ones that weren't supported before C++20

Sephirothbahamut avatar Oct 23 '23 18:10 Sephirothbahamut

It seems -std=c++20 is correctly passed to clang if you set it in MSVC project settings. However, currently clang does not support floating point as non-type template argument https://godbolt.org/z/hv9K35oPK

yxsamliu avatar Oct 25 '23 14:10 yxsamliu