Page MenuHomePhabricator

[CUDA] Add missing cmath overloads
AbandonedPublic

Authored by jdoerfert on Apr 1 2020, 1:21 PM.

Details

Reviewers
tra
Summary

Some function overloads for floats were missing, found by running a test
suite [0] with the OpenMP overlay.

[0] https://github.com/TApplencourt/OmpVal

Depends on D77239.

Diff Detail

Unit TestsFailed

TimeTest
130 msClang.Headers::Unknown Unit Message ("")
Script: -- : 'RUN: at line 6'; /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/bin/clang -cc1 -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/lib/clang/11.0.0/include -nostdsysteminc -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/Inputs/include -include cmath -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/nvptx_device_cmath_functions.c -o /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/tools/clang/test/Headers/Output/nvptx_device_cmath_functions.c.tmp-ppc-host.bc
200 msClang.Headers::Unknown Unit Message ("")
Script: -- : 'RUN: at line 6'; /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/bin/clang -cc1 -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/lib/clang/11.0.0/include -nostdsysteminc -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/Inputs/include -include cmath -x c++ -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/nvptx_device_cmath_functions.cpp -o /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/tools/clang/test/Headers/Output/nvptx_device_cmath_functions.cpp.tmp-ppc-host.bc
190 msClang.Headers::Unknown Unit Message ("")
Script: -- : 'RUN: at line 6'; /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/bin/clang -cc1 -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/lib/clang/11.0.0/include -nostdsysteminc -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/Inputs/include -include cmath -x c++ -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/nvptx_device_cmath_functions_cxx17.cpp -o /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/tools/clang/test/Headers/Output/nvptx_device_cmath_functions_cxx17.cpp.tmp-ppc-host.bc -std=c++17
190 msClang.Headers::Unknown Unit Message ("")
Script: -- : 'RUN: at line 6'; /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/bin/clang -cc1 -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/lib/clang/11.0.0/include -nostdsysteminc -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/Inputs/include -include math.h -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/nvptx_device_math_functions.c -o /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/tools/clang/test/Headers/Output/nvptx_device_math_functions.c.tmp-ppc-host.bc
240 msClang.Headers::Unknown Unit Message ("")
Script: -- : 'RUN: at line 6'; /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/bin/clang -cc1 -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/lib/clang/11.0.0/include -nostdsysteminc -internal-isystem /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/Inputs/include -include math.h -x c++ -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/clang/test/Headers/nvptx_device_math_functions.cpp -o /mnt/disks/ssd0/agent/workspace/BETA_amd64_debian_testing_clang8/llvm-project/build/tools/clang/test/Headers/Output/nvptx_device_math_functions.cpp.tmp-ppc-host.bc
View Full Test Results (13 Failed)

Event Timeline

jdoerfert created this revision.Apr 1 2020, 1:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2020, 1:21 PM
Herald added subscribers: bollu, yaxunl. · View Herald Transcript
tra added a comment.Apr 1 2020, 2:07 PM

We'll need to make sure that all of these new functions are vailable in all supported CUDA versions.
E.g. acoshf does not seem to be present in CUDA-9.

In D77240#1955678, @tra wrote:

We'll need to make sure that all of these new functions are vailable in all supported CUDA versions.
E.g. acoshf does not seem to be present in CUDA-9.

At least that one is defined in what is "now" __clang_cuda_math.h:

__DEVICE__ float acoshf(float __a) { return __nv_acoshf(__a); }

tra added a comment.Apr 1 2020, 2:47 PM

At least that one is defined in what is "now" __clang_cuda_math.h:

Cool. We may be OK, but we still need to verify it. Math headers are rather fragile and we need to make sure it all still works two different standard libraries and all CUDA versions.
Unfortunately my CUDA build bot has decided to die the day we've started working from home, so it has to be done manually.
Let me try patching in your changes and try them with the CUDA versions I have. Stay tuned.

In D77240#1955755, @tra wrote:

At least that one is defined in what is "now" __clang_cuda_math.h:

Cool. We may be OK, but we still need to verify it. Math headers are rather fragile and we need to make sure it all still works two different standard libraries and all CUDA versions.
Unfortunately my CUDA build bot has decided to die the day we've started working from home, so it has to be done manually.
Let me try patching in your changes and try them with the CUDA versions I have. Stay tuned.

Thank you very much! I (now) know what pain math headers are... These are almost the last infrastructure changes I need, there is a problem with the include path order on some system but for that I first need to write a patch.

tra added a comment.Apr 1 2020, 3:56 PM

We do have a problem. With your patch I see a lot of errors about function redefinitions conflicting with the ones in CUDA's math_functions.hpp:

E.g:

In file included from <built-in>:1:
In file included from /usr/local/google/home/tra/work/llvm/build/release+assert+zapcc/lib/clang/11.0.0/include/__clang_cuda_runtime_wrapper.h:398:
/usr/local/google/home/tra/work/llvm/build/release+assert+zapcc/lib/clang/11.0.0/include/__clang_cuda_cmath.h:60:18: error: redefinition of 'acosh'
__DEVICE__ float acosh(float __x) { return ::acoshf(__x); }
                 ^
/usr/local/google/home/tra/local/cuda-10.0/include/crt/math_functions.hpp:624:31: note: previous definition is here
__MATH_FUNCTIONS_DECL__ float acosh(float a)

Full list of conflicting functions in CUDA 9.0, 10.0, 10.1, 10.2

redefinition of 'acosh'
redefinition of 'asinh'
redefinition of 'atanh'
redefinition of 'cbrt'
redefinition of 'erf'
redefinition of 'erfc'
redefinition of 'exp2'
redefinition of 'expm1'
redefinition of 'fdim'
redefinition of 'hypot'
redefinition of 'ilogb'
redefinition of 'lgamma'
redefinition of 'llrint'
redefinition of 'llround'
redefinition of 'log1p'
redefinition of 'log2'
redefinition of 'logb'
redefinition of 'lrint'
redefinition of 'lround'

I just noticed those as well. I forgot to put the new definitions into the forward declare header. Will do it in a second. The OpenMP math overlay doesn't have one so I forgot :(

tra added a comment.Apr 2 2020, 9:21 AM

I just noticed those as well. I forgot to put the new definitions into the forward declare header. Will do it in a second. The OpenMP math overlay doesn't have one so I forgot :(

I'm not sure how it's going to help. The problem is that the functions are already defined by CUDA headers. Moving the duplicate definition to a different header does not change that.
Bottom line is that the already-existing definitions are not needed for CUDA. If OpenMP needs them, then they should probably go into an OpenMP-specific header.

jdoerfert abandoned this revision.Apr 2 2020, 9:29 AM
In D77240#1957468, @tra wrote:

I just noticed those as well. I forgot to put the new definitions into the forward declare header. Will do it in a second. The OpenMP math overlay doesn't have one so I forgot :(

I'm not sure how it's going to help. The problem is that the functions are already defined by CUDA headers. Moving the duplicate definition to a different header does not change that.
Bottom line is that the already-existing definitions are not needed for CUDA. If OpenMP needs them, then they should probably go into an OpenMP-specific header.

I see. In my CUDA headers float acos(float) is conditionally defined as well but as a __cudart_builtin__.
So it seems we can redefine those but not the float acosh(float) which is a __MATH_FUNCTIONS_DECL__ for some configurations.

I'll move the new functions into an OpenMP only header. I thought they might be needed here too but that was wrong. Thanks for spending the time on this!