Math functions when offloading to CUDA devices

Hi,

One of the issues we frequently hit when using the Clang OpenMP implementation on NVIDIA GPUs is the lack of support for many common math functions (e.g. cos/sin). Trying to use them produces errors of the form:

    fatal error: error in backend: Cannot select: 0x47b33a0: f64 = fsin 0x47b2f90

Translating math functions in target regions is listed as a feature that isn’t supported yet, but is this something that is expected to be implemented soon? Failing that, if someone can describe the desired approach to implement this I might be able to take a stab at getting some initial patches together (depending on the complexity).

Some functions such as sqrt work fine, but I assume this is because they map directly to NVVM intrinsics.

Cheers,

James

Hi James,

If you’re installing the compiler from source please use the following version.

This is a mirror of trunk:

https://github.com/clang-ykt

Clone Clang, LLVM and OpenMP runtime.

IMPORTANT: For each repo checkout patched-upstream branch.

The Clang patched-upstream branch contains a patch that fixes your problem.

Thanks,

–Doru

James,

I had the same issue https://bugs.llvm.org/show_bug.cgi?id=41090
Clang-ykt works for me. I get all the math functions I need.

However, when I use clang built from mainstream to build the clang-ykt offload compiler, I got a device library issue when linking my application
My solution is just building a clang using sources from clang-ykt repo with -DOPENMP_ENABLE_LIBOMPTARGET=OFF first and then use it to build clang-ykt with offload on.
Best,

Ye

Gheorghe-Teod Bercea via Openmp-dev <openmp-dev@lists.llvm.org> 于2019年3月19日周二 上午9:22写道:

Hi, Doru,

What’s the underlying problem and how does clang-ykt fix it? Do we have open reviews that resolve this upstream?

I recall that these functions are provided by libdevice.*.bc and that some renaming needs to happen to get this to work. Also, I recall there being some reviews open on this, but I don’t now recall which ones and where.

Thanks again,

Hal

Hi Hal,

Yes we do have an open patch:

https://reviews.llvm.org/D47849

The solution is to do what CUDA does today.

Clang-ykt is now actually upstream if you checkout the patched-upstream branch on Clang, LLVM and OpenMP.

This is a way of enabling people to use any patches which haven’t been upstreamed yet.

Current status summary:
The patched-upstream branch for LLVM is identical to the upstream branch (no patches outstanding).
The patched-upstream branch for OpenMP has a 1 line patch.
The patched-upstream branch for Clang has a few patches: the static linking patch and the math functions patch.

For consistency (and just in case in the future those branches may contain patches) I just point everyone to use the patched-upstream branches.

Thanks,

–Doru