<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Nick, Jean,<br>
<br>
Thanks for bringing this topic up. I must confess that I am not an expert in target and device handling in OpenMP and we have not yet finalized the approach for handling target regions. <br>
<br>
But here is what I can share, <span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">the GPU folks from Nvidia/AMD and Johannes (who implemented this in Clang) can correct me here.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">Vendors provide device libraries (</span><a href="https://docs.nvidia.com/cuda/libdevice-users-guide/__nv_sin.html" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">https://docs.nvidia.com/cuda/libdevice-users-guide/__nv_sin.html</a><span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">)
 with math function support. The compiler can/should convert calls to the math library functions in a target region with calls to the device library functions. OpenMP provides the declare variant directive with which specialized variants of functions and the
 context in which these functions should be used can be specified. This mechanism can be used in a header file and each vendor can declare variants (with calls to their device library) for each math function. If the frontend supports OpenMP declare variant
 handling then the calls to math library functions are automatically converted to calls to device library functions.<br>
<br>
For e.g: Clang has the following,<br>
<br>
1) clang/lib/Headers/openmp_wrappers/math.h<br>
#pragma omp begin declare variant match(                                       \
<div>    device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})</div>
<div><br>
</div>
<div>#define __CUDA__</div>
<div>#define __OPENMP_NVPTX__</div>
<div>#include <__clang_cuda_math.h></div>
<div>#undef __OPENMP_NVPTX__</div>
<div>#undef __CUDA__</div>
<div><br>
</div>
#pragma omp end declare variant<br>
<br>
2) clang/lib/Headers/__clang_cuda_math.h<br>
__DEVICE__ double sin(double __a) { return __nv_sin(__a); }<br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
Thanks,<br>
--Kiran</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Jean Perier <jperier@nvidia.com><br>
<b>Sent:</b> 27 July 2020 10:59<br>
<b>To:</b> Romero, Nichols A. <naromero@anl.gov>; flang-dev@lists.llvm.org <flang-dev@lists.llvm.org><br>
<b>Cc:</b> Kiran Chandramohan <Kiran.Chandramohan@arm.com><br>
<b>Subject:</b> RE: [flang-dev] OpenMP target regions and intrinsic Fortran math functions</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Verdana}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif}
.x_MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
-->
</style>
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="x_WordSection1">
<p class="x_MsoNormal"><span style="font-size:11.0pt">Hi,</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Kiran Chandramohan is working on OpenMP lowering and might have a plan here. Math intrinsics are currently lowered in mlir to a mix of inlined code,  calls to llvm intrinsics, and calls to runtime when the
 first two options are not possible. Attributes are added to these runtime calls so that they can easily be identified as intrinsic calls and later rewrote if needed. These attributes could be adapted based on what the team working on OpenMP lowering needs
 here.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Jean</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b><span style="font-size:11.0pt">From:</span></b><span style="font-size:11.0pt"> flang-dev <flang-dev-bounces@lists.llvm.org>
<b>On Behalf Of </b>Romero, Nichols A. via flang-dev<br>
<b>Sent:</b> Wednesday, July 22, 2020 8:26 PM<br>
<b>To:</b> flang-dev@lists.llvm.org<br>
<b>Subject:</b> [flang-dev] OpenMP target regions and intrinsic Fortran math functions</span></p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<table class="x_MsoNormalTable" border="1" cellspacing="3" cellpadding="0" style="background:#FFEB9C">
<tbody>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="x_MsoNormal"><b><span style="font-size:7.5pt; font-family:"Verdana",sans-serif; color:black">External email: Use caution opening links or attachments</span></b><span style="font-size:7.5pt; font-family:"Verdana",sans-serif; color:black">
</span><span style="font-size:11.0pt"></span></p>
</td>
</tr>
</tbody>
</table>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<div>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Hi,</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">I am bringing this up because it seems that OpenMP development is really ramping up now and I want to bring up a common use case that does not seem to be supported with other vendor compilers.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">It is a common use case to call the Fortran intrinsic Math functions in an openmp target region. I am not sure how this in implemented in the Fortran + OpenMP compilers for the vendors who do support it.
 I suspect this is done by inlining, but it appears that other vendors have their Fortran math functions in a backend runtime library which somehow prevents these functions from being called in an OpenMP target region.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">-- </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Nichols A. Romero, Ph.D.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Computational Science Division</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Argonne Leadership Computing Facility<br>
Argonne National Laboratory<br>
Building 240 Room 2-127<br>
9700 South Cass Avenue<br>
Lemont, IL 60439<br>
(630) 252-3441</span></p>
<p class="x_MsoNormal"> </p>
</div>
</div>
</div>
</body>
</html>