This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Replace math headers with OpenMP wrapper calls
AcceptedPublic

Authored by jhuber6 on Mar 11 2022, 7:56 AM.

Details

Summary

This patch replaces the math functions when called on the device with an
__omp_ variant that we can use. This will later be turned back into
the regular math call so we can avoid the problems with including math.h
on the device. This patch introduces the -fopenmp-device-libm flag
which enables the new math wrappers by defining MATH_WRAPPERS in the
header.

Diff Detail

Event Timeline

jhuber6 created this revision.Mar 11 2022, 7:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2022, 7:56 AM
jhuber6 requested review of this revision.Mar 11 2022, 7:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2022, 7:56 AM
tianshilei1992 accepted this revision.Mar 11 2022, 8:29 AM

LGTM. Support the header file is actually generated automatically. :-)

This revision is now accepted and ready to land.Mar 11 2022, 8:29 AM
JonChesterfield added a comment.EditedMar 11 2022, 9:16 AM

We've got quite a lot of debt in this area and seem at risk of taking on more. Ideally the cuda and hip and openmp headers would be closer to a single header containing:

double acosh(double);
INSTANTIATE(1, acosh, cuda_acosh, amdgpu_acosh, intel_acosh);

clang/lib/Headers/openmp_wrappers/__clang_openmp_math.h
43

This is not totally good. Can we do something with macros or code generators instead, even in the first instance?

Also wonder if what we actually want to do is map these things onto __gpu_acosh or __llvm_gpu_acosh or similar, there's nothing openmp specific about this and it would be really nice to not end up spinning another copy of this for some other gpu language.

We want one copy of this, yes. s/omp/llvm_gpu/, sure, though gpu might also not the best name. Generators, macros, etc. I'm not sold. Even if we want to do this, let's not conflate that.