<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hi Brian,<br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Generally, all builtin types are configurable in Clang based on the target (incl int or float). We have a way to enforce the language specific settings using <span>TargetInfo::adjust</span>. We currently already force
the half width to 2 bytes there.<br>
</p>
<p style="margin-top:0;margin-bottom:0">However, subclass targets can still override this logic. Not something we recommend to do though.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Anastasia<br>
</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> Sumner, Brian <Brian.Sumner@amd.com><br>
<b>Sent:</b> 23 October 2018 00:25<br>
<b>To:</b> Anastasia Stulova; Liu, Yaxun (Sam); Bader, Alexey; cfe-dev (cfe-dev@lists.llvm.org)<br>
<b>Cc:</b> nd<br>
<b>Subject:</b> RE: [OpenCL] Representing OpenCL half type by _Float16 type</font>
<div> </div>
</div>
<meta content="text/html; charset=Windows-1252">
<meta name="x_Generator" content="Microsoft Word 15 (filtered medium)">
<div link="blue" vlink="purple" lang="EN-US">
<div class="x_WordSection1">
<p class="x_MsoNormal">Hi,</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">The doc Sam referenced seems to be implying that sizeof(_Float16) is allowed to be 4 if the target doesn’t support “native” half precision operations. Is that correct? That would be a showstopper for OpenCL where sizeof(half) must be
2.</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Brian</p>
<p class="x_MsoNormal"> </p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b>From:</b> Anastasia Stulova <Anastasia.Stulova@arm.com>
<br>
<b>Sent:</b> Monday, October 22, 2018 3:42 PM<br>
<b>To:</b> Liu, Yaxun (Sam) <Yaxun.Liu@amd.com>; Bader, Alexey <alexey.bader@intel.com>; Sumner, Brian <Brian.Sumner@amd.com>; cfe-dev (cfe-dev@lists.llvm.org) <cfe-dev@lists.llvm.org><br>
<b>Cc:</b> nd <nd@arm.com><br>
<b>Subject:</b> Re: [OpenCL] Representing OpenCL half type by _Float16 type</p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div id="x_divtagdefaultwrapper">
<p><span style="font-size:12.0pt; color:black">Hi Sam,</span></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black">I would disagree regarding the requirements on the half implementation. Section 6.1.1 explicitly says:</span></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black">"The half data type must conform to the IEEE 754-2008 half precision storage format."</span></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black">Do you suggest to change the spec to refer to ISO standard instead of IEEE for half type? I am a bit concerned about backwards compatibility though in case current implementations are relying on the higher precision
arithmetic. Do you know the implications on the precision and ulp bounds?</span></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black">Cheers,</span></p>
<p><span style="font-size:12.0pt; color:black">Anastasia</span></p>
<p class="x_MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:12.0pt; color:black"> </span></p>
<div>
<div class="x_MsoNormal" style="text-align:center" align="center"><span style="font-size:12.0pt; color:black">
<hr size="3" align="center" width="98%">
</span></div>
<div id="x_divRplyFwdMsg">
<p class="x_MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com">Yaxun.Liu@amd.com</a>><br>
<b>Sent:</b> 22 October 2018 15:35<br>
<b>To:</b> Bader, Alexey; Anastasia Stulova; Sumner, Brian; cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>)<br>
<b>Subject:</b> RE: [OpenCL] Representing OpenCL half type by _Float16 type</span><span style="font-size:12.0pt; color:black">
</span></p>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
</div>
<div>
<div>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Right.</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Sam</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_xmsonormal"><b><span style="font-size:12.0pt; color:black">From:</span></b><span style="font-size:12.0pt; color:black"> Bader, Alexey <<a href="mailto:alexey.bader@intel.com">alexey.bader@intel.com</a>>
<br>
<b>Sent:</b> Monday, October 22, 2018 4:53 AM<br>
<b>To:</b> Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com">Yaxun.Liu@amd.com</a>>; 'anastasia.stulova@arm.com' <<a href="mailto:anastasia.stulova@arm.com">anastasia.stulova@arm.com</a>>; Sumner, Brian <<a href="mailto:Brian.Sumner@amd.com">Brian.Sumner@amd.com</a>>;
cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>) <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Subject:</b> RE: [OpenCL] Representing OpenCL half type by _Float16 type</span></p>
</div>
</div>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D">The proposal sounds good to me.</span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D">I assume that by changing OpenCL half data type representation from __fp16 to _Float16, we align it with cl_khr_fp16 extension. There should be no functional changes for programs not using
this extension. Right?</span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_xmsonormal"><a name="x_x______replyseparator"></a><b><span style="font-size:12.0pt; color:black">From:</span></b><span style="font-size:12.0pt; color:black"> Liu, Yaxun (Sam) [<a href="mailto:Yaxun.Liu@amd.com">mailto:Yaxun.Liu@amd.com</a>]
<br>
<b>Sent:</b> Friday, October 19, 2018 6:30 PM<br>
<b>To:</b> Bader, Alexey <<a href="mailto:alexey.bader@intel.com">alexey.bader@intel.com</a>>; 'anastasia.stulova@arm.com' <<a href="mailto:anastasia.stulova@arm.com">anastasia.stulova@arm.com</a>>; Sumner, Brian <<a href="mailto:Brian.Sumner@amd.com">Brian.Sumner@amd.com</a>>;
cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>) <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Subject:</b> RE: [OpenCL] Representing OpenCL half type by _Float16 type</span></p>
</div>
</div>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Hi Alexey,</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">We have semantic checks to enforce the restrictions on half type when cl_khr_fp16 is not enabled. We could keep these checks if we switch to _Float16.</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Sam</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_xmsonormal"><b><span style="font-size:12.0pt; color:black">From:</span></b><span style="font-size:12.0pt; color:black"> Bader, Alexey <<a href="mailto:alexey.bader@intel.com">alexey.bader@intel.com</a>>
<br>
<b>Sent:</b> Friday, October 19, 2018 9:16 AM<br>
<b>To:</b> Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com">Yaxun.Liu@amd.com</a>>; 'anastasia.stulova@arm.com' <<a href="mailto:anastasia.stulova@arm.com">anastasia.stulova@arm.com</a>>; Sumner, Brian <<a href="mailto:Brian.Sumner@amd.com">Brian.Sumner@amd.com</a>>;
cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>) <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Subject:</b> RE: [OpenCL] Representing OpenCL half type by _Float16 type</span></p>
</div>
</div>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D">Hi Sam,</span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D"> </span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D">I assume OpenCL half type mapped to __fp16 as OpenCL specification defines it as “A 16-bit floating-point conforming to the IEEE 754-2008 half precision storage format”. This aligned with
__fp16 description from clang documentation.</span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D"> </span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D">OpenCL cl_khr_fp16 extension enables arithmetic operations on ‘half’ data types and I think it’s reasonable to map ‘half’ data type to _Float16 if cl_khr_fp16 is enabled.</span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D"> </span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D">Is it possible to map ‘half’ data type to _Float16 and keep the restrictions of OpenCL core specification?</span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D"> </span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D">Thanks,</span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D">Alexey</span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:#1F497D"> </span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_xmsonormal"><b><span style="font-size:12.0pt; color:black">From:</span></b><span style="font-size:12.0pt; color:black"> Liu, Yaxun (Sam) [<a href="mailto:Yaxun.Liu@amd.com">mailto:Yaxun.Liu@amd.com</a>]
<br>
<b>Sent:</b> Wednesday, October 17, 2018 7:31 PM<br>
<b>To:</b> 'anastasia.stulova@arm.com' <<a href="mailto:anastasia.stulova@arm.com">anastasia.stulova@arm.com</a>>; Bader, Alexey <<a href="mailto:alexey.bader@intel.com">alexey.bader@intel.com</a>>; Sumner, Brian <<a href="mailto:Brian.Sumner@amd.com">Brian.Sumner@amd.com</a>>;
cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>) <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Subject:</b> [OpenCL] Representing OpenCL half type by _Float16 type</span></p>
</div>
</div>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Hi,</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Clang supports two 16 bit floating point builtin types: __fp16 and _Float16. Their differences are here</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"><a href="https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point">https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point</a></span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Currently clang supports OpenCL half type as __fp16, one significant disadvantage of which is that arithmetic operations are emitted as fp32 instead of fp16 instructions in LLVM IR. Another
disadvantage is interoperability with C++ programs, which uses _Float16 mostly since it is an ISO standard whereas __fp16 is not.</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">OpenCL spec v 2.0 s 6.1.1.1 (<a href="https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf">https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf</a> ) defines
half type. There is no requirement that it has to be __fp16 or _Float16 type in clang. Actually, it seems both __fp16 and _Float16 can be used to represent OpenCL half type.</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Considering the advantages of _Float16 type, I am wondering whether we should consider using _Float16 to represent OpenCL half type.</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Any comments are welcome.</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Thanks.</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">Yaxun (Sam) Liu</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black">AMD</span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p class="x_xmsonormal"><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black"><br>
--------------------------------------------------------------------<br>
Joint Stock Company Intel A/O<br>
Registered legal address: Krylatsky Hills Business Park, <br>
17 Krylatskaya Str., Bldg 4, Moscow 121614, <br>
Russian Federation</span></p>
<p><span style="font-size:12.0pt; color:black">This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</span></p>
<p><span style="font-size:12.0pt; color:black"><br>
--------------------------------------------------------------------<br>
Joint Stock Company Intel A/O<br>
Registered legal address: Krylatsky Hills Business Park, <br>
17 Krylatskaya Str., Bldg 4, Moscow 121614, <br>
Russian Federation</span></p>
<p><span style="font-size:12.0pt; color:black">This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>