<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/15/19 9:22 AM, Andreas Hommel via Openmp-dev wrote:<br>
</div>
<blockquote type="cite" cite="mid:AM6PR04MB631274C8CDA411D9B70A1F499DAC0@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;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 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;
color:black;}
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;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
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;
color:black;}
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;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;
color:black;}
span.EmailStyle24
{mso-style-type:personal-reply;
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"><span style="color:windowtext">You can make structure layouts compatible by using <stdint> types, e.g., int32_t in the common definitions and (worst case) add some alignment attributes. But that would have to be done even if you are not
usingOpenMP.</span></p>
</div>
</blockquote>
<p><br>
</p>
<p>That maybe true, but from a programming-model perspective, that's pretty fragile. The frontend knows if the layouts won't match, and maybe a good set of warnings (or similar) would make all of this work well. It's unclear to me, but I'm certainly interested
in your experience. We should understand what it takes to make this kind of configuration work well.<br>
</p>
<p> -Hal<br>
</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:AM6PR04MB631274C8CDA411D9B70A1F499DAC0@AM6PR04MB6312.eurprd04.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:windowtext"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext">Structure with embedded pointers will need special attention, but they will not work anyway unless you have a host/device unified shared memory model.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext">I have just started this internal experiment, but I was able to resolve all issues (except for that byval/byref capture issue in clang) in my omptarget plugin and I am able to run some simple examples that
target our 32-bit device from an x86_64 host.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext">-Andreas<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="color:windowtext">From:</span></b><span style="color:windowtext"> Finkel, Hal J.
<a class="moz-txt-link-rfc2396E" href="mailto:hfinkel@anl.gov"><hfinkel@anl.gov></a>
<br>
<b>Sent:</b> Thursday, 15 August, 2019 2:07<br>
<b>To:</b> Andreas Hommel <a class="moz-txt-link-rfc2396E" href="mailto:andreas.hommel@nxp.com">
<andreas.hommel@nxp.com></a>; <a class="moz-txt-link-abbreviated" href="mailto:openmp-dev@lists.llvm.org">
openmp-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [Openmp-dev] [EXT] Re: 32-bit target device support<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p><b><span style="color:white;background:darkred">Caution: </span></b><span style="color:white;background:darkred">EXT Email
</span><o:p></o:p></p>
<div>
<p><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 8/14/19 4:37 AM, Andreas Hommel via Openmp-dev wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<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))?<o:p></o:p></p>
</blockquote>
<p><o:p> </o:p></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?<o:p></o:p></p>
<p> -Hal<o:p></o:p></p>
<p><o:p> </o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<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 href="mailto:a.bataev@hotmail.com" moz-do-not-send="true">
<a.bataev@hotmail.com></a> <br>
<b>Sent:</b> Wednesday, 14 August, 2019 11:00<br>
<b>To:</b> Andreas Hommel <a href="mailto:andreas.hommel@nxp.com" moz-do-not-send="true">
<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%7C977179e68f5243428bd008d721148470%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637014244335712888&sdata=19zJr9SXBHeZ5%2ByZkL1T4DbesbRhq%2F0i2UQCaQtFfvo%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>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>Openmp-dev mailing list<o:p></o:p></pre>
<pre><a href="mailto:Openmp-dev@lists.llvm.org" moz-do-not-send="true">Openmp-dev@lists.llvm.org</a><o:p></o:p></pre>
<pre><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%7C977179e68f5243428bd008d721148470%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637014244335722882&sdata=M6JiDMMl6vpda93I14Cj5Fc%2BDLsKqJYzn3NZTGTYJ24%3D&reserved=0" moz-do-not-send="true">https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev</a><o:p></o:p></pre>
</blockquote>
<pre>-- <o:p></o:p></pre>
<pre>Hal Finkel<o:p></o:p></pre>
<pre>Lead, Compiler Technology and Programming Languages<o:p></o:p></pre>
<pre>Leadership Computing Facility<o:p></o:p></pre>
<pre>Argonne National Laboratory<o:p></o:p></pre>
</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>