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

Hal Finkel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 7 05:34:06 PDT 2018


hfinkel 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. ```


Hrmm. I thought that we had fixed that already.

In case it's helpful, in an out-of-tree experimental target I have I ran into a similar problem, and to fix that I wrote the following code in the target's getTargetDefines function (in lib/Basic/Targets):

  // If used as an OpenMP target on x86, x86 target feature macros are defined. math.h
  // and other system headers will include inline asm if these are defined.
  Builder.undefineMacro("__SSE2_MATH__");
  Builder.undefineMacro("__SSE_MATH__");


Repository:
  rC Clang

https://reviews.llvm.org/D47849





More information about the cfe-commits mailing list