<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p><br>
</p>
<div class="moz-cite-prefix">On 8/14/19 4:37 AM, Andreas Hommel via Openmp-dev wrote:<br>
</div>
<blockquote type="cite" cite="mid:AM6PR04MB63124162908BDE4D7B12F4A59DAD0@AM6PR04MB6312.eurprd04.prod.outlook.com">
<meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle21
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">In embedded environments it is not uncommon to pair a 64-bit ARM with 32-bit accelerator devices (as in my case).
<o:p></o:p></p>
<p class="MsoNormal">I have just started this, so maybe I am just naïve here, but I can run a lot of examples on our device using this ugly hack:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in">  CharUnits TySz = Ctx.getTypeSizeInChars(Ty);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">  CharUnits PtrSz = CharUnits::fromQuantity(4); // our device pointers are 32-bits wide<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">  if (!IsByRef &&<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">      (TySz > PtrSz ||<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">       Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) {<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">    IsByRef = true;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">  }<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Is it really that hard to support this (I could imagine that things could become messy with mixed host/device endianness))?</p>
</div>
</blockquote>
<p><br>
</p>
<p>One issue in this kind of configuration is that, if the host and accelerator have different data layouts, then sharing any kind of aggregate, in general, will cause problems. Simple cases will work (e.g., you have an array of floats), but it will be fragile
 even if no pointers are involved. Do you work in an environment where you can force the accelerator's structure layout rules (etc.) to match the host's rules?</p>
<p> -Hal</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:AM6PR04MB63124162908BDE4D7B12F4A59DAD0@AM6PR04MB6312.eurprd04.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The much harder 32-bit <-> 64-bit pointer translation problem already seems to work flawlessly in my setup.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-Andreas<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
            1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Alexey Bataev <a class="moz-txt-link-rfc2396E" href="mailto:a.bataev@hotmail.com">
<a.bataev@hotmail.com></a> <br>
<b>Sent:</b> Wednesday, 14 August, 2019 11:00<br>
<b>To:</b> Andreas Hommel <a class="moz-txt-link-rfc2396E" href="mailto:andreas.hommel@nxp.com">
<andreas.hommel@nxp.com></a><br>
<b>Subject:</b> [EXT] Re: [Openmp-dev] 32-bit target device support<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">It is not a big, it is by design. There is an agreement that the basic types must have the same sizes on both the host and the device. Otherwise, the results are unpredictable.<o:p></o:p></p>
<div id="AppleMailSignature">
<p class="MsoNormal">Best regards, <o:p></o:p></p>
<div>
<p class="MsoNormal">Alexey Bataev<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
14 авг. 2019 г., в 4:36, Andreas Hommel via Openmp-dev <<a href="mailto:openmp-dev@lists.llvm.org" moz-do-not-send="true">openmp-dev@lists.llvm.org</a>> написал(а):<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">I am currently adding support for an experimental 32-bit OpenMP target device using x86_64 as a host. There seems to be a bug in<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">bool Sema::Sema::isOpenMPCapturedByRef(…,) {<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">…<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">  if (!IsByRef &&<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">      (Ctx.getTypeSizeInChars(Ty) ><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">           Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) ||<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">       Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) {<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">    IsByRef = true;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">  }<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">  return IsByRef;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">}<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">The above code assumes that the target device’s UIntPtr size is the same as the host’s UIntPtr which is not true in my case. So, if you pass a 64-bit double to a 32-bit device the host compilation pass uses by-value argument passing, because
 the value fits into the 64-bit pointers. However, if you build for the target (-fopenmp-is-device), the 64-bit float does not fit into the 32-bit pointer, so the target assumes that the value is passed by-reference and the device does not pick up the correct
 argument value.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">A possible fix would to use something like this<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">  if (!IsByRef &&<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">      (Ctx.getTypeSizeInChars(Ty) ><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">           DCtx.getTypeSizeInChars(DCtx.getUIntPtrType()) ||<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">       Ctx.getDeclAlign(D) > DCtx.getTypeAlignInChars(DCtx.getUIntPtrType()))) {<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">    IsByRef = true;<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">  }<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">where DCtx is the context of the target device. But that context does not seem to be available in the host’s Sema.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Sema.LangOpts.OMPTargetTriples seems to be the only available starting point to get to a device’s context, or am I missing something?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Andreas<o:p></o:p></p>
</div>
</blockquote>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">_______________________________________________<br>
Openmp-dev mailing list<br>
<a href="mailto:Openmp-dev@lists.llvm.org" moz-do-not-send="true">Openmp-dev@lists.llvm.org</a><br>
<a href="https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fopenmp-dev&data=02%7C01%7Candreas.hommel%40nxp.com%7C32dd8f14c6554381322708d72095c718%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C637013699969308643&sdata=xfb0mOT%2B%2Bd18w3atQK2mMLhIWJJPGCUDDeADjD0x7Eo%3D&reserved=0" moz-do-not-send="true">https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev</a><o:p></o:p></p>
</div>
</blockquote>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Openmp-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Openmp-dev@lists.llvm.org">Openmp-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</body>
</html>