[PATCH] D47849: [OpenMP][Clang][NVPTX] Enable math functions called in an OpenMP NVPTX target device region to be resolved as device-native function calls

Gheorghe-Teodor Bercea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 7 07:19:58 PDT 2018


gtbercea added a comment.

In https://reviews.llvm.org/D47849#1124638, @Hahnfeld wrote:

> IMO this goes into the right direction, we should use the fast implementation in libdevice. If LLVM doesn't lower these calls in the NVPTX backend, I think it's ok to use header wrappers as CUDA already does.
>
> Two questions:
>
> 1. Can you explain where this is important for "correctness"? Yesterday I compiled a code using `sqrt` and it seems to spit out the correct results. Maybe that's relevant for other functions?
> 2. Incidentally I ran into a closely related problem: I can't `#include <math.h>` in translation units compiled for offloading, Clang complains about inline assembly for x86 (see below). Does that work for you?
>
>   ``` In file included from /usr/include/math.h:413: /usr/include/bits/mathinline.h:131:43: error: invalid input constraint 'x' in asm __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x)); ^ /usr/include/bits/mathinline.h:143:43: error: invalid input constraint 'x' in asm __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x)); ^ 2 errors generated. ```


It's precisely the issue which you report here. Since you don't use device specific math functions, you can run into the problem where you may end up calling assembly instructions for a different architecture. I may have mis-classified this as a correctness issue.


Repository:
  rC Clang

https://reviews.llvm.org/D47849





More information about the cfe-commits mailing list