<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">> In any case, it seems like your examples argue for disallowing a return-type mismatch between host and device overloads, not disallowing observing the type?</div><div dir="ltr"><br></div><div>Oh no, we have to allow return-type mismatches between host and device overloads, that is a common thing in CUDA code I've seen.  You can safely observe this difference *so long as you're inside of a function*.  This is because we have this caller-sensitive function parsing thing.  When parsing a __host__ __device__ function, we look at the caller to understand what context we're in.</div><div><br></div><div>What I think you can't do is observe the return-type mismatch between host and device overloads *from outside of a function*, e.g. from within a trailing return type.</div><div><br></div><div>But perhaps rsmith or another expert can take my attempt at a contract above and trap me in a Faustian contradiction.</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 2, 2019 at 7:47 PM Finkel, Hal J. <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thanks, Justin. It sees like we have the standard set of options: We can disallow the mismatch. We can allow it with a warning. We can allow it without a warning. We can say that if the mismatch contributes to the type of a kernel function, that's illformed
 (NDR).</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
In any case, it seems like your examples argue for disallowing a return-type mismatch between host and device overloads, not disallowing observing the type? Or maybe disallowing observing the type only when there's a mismatch?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
 -Hal</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div id="gmail-m_-3941697715883276625Signature">
<div class="gmail-m_-3941697715883276625BodyFragment"><font size="2"><span style="font-size:10pt">
<div class="gmail-m_-3941697715883276625PlainText">Hal Finkel<br>
Lead, Compiler Technology and Programming Languages<br>
Leadership Computing Facility<br>
Argonne National Laboratory</div>
</span></font></div>
<div>
<div id="gmail-m_-3941697715883276625appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-3941697715883276625divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Justin Lebar <<a href="mailto:jlebar@google.com" target="_blank">jlebar@google.com</a>><br>
<b>Sent:</b> Thursday, May 2, 2019 9:16 PM<br>
<b>To:</b> <a href="mailto:reviews%2BD61458%2Bpublic%2Bf6ea501465ad52d2@reviews.llvm.org" target="_blank">reviews+D61458+public+f6ea501465ad52d2@reviews.llvm.org</a><br>
<b>Cc:</b> <a href="mailto:michael.hliao@gmail.com" target="_blank">michael.hliao@gmail.com</a>; Artem Belevich; John McCall; Liu, Yaxun (Sam); Finkel, Hal J.; Richard Smith; Clang Commits; <a href="mailto:mlekena@skidmore.edu" target="_blank">mlekena@skidmore.edu</a>; <a href="mailto:blitzrakete@gmail.com" target="_blank">blitzrakete@gmail.com</a>; Han Shen<br>
<b>Subject:</b> Re: [PATCH] D61458: [hip] Relax CUDA call restriction within `decltype` context.</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">> So, actually, I wonder if that's not the right answer. We generally allow different overloads to have different return types. What if, for example, the return type on the host is __float128 and on the device it's `MyLongFloatTy`?
<div></div>
</div>
<div dir="ltr"><br>
</div>
<div>The problem is that conceptually compiling for host/device does not create a new set of overloads.</div>
<div><br>
</div>
<div>When we compile for (say) host, we build a full AST for all functions, including device functions, and that AST must pass sema checks.  This is significant for example because when compiling for device we need to know which kernel templates were instantiated
 on the host side, so we know which kernels to emit.</div>
<div><br>
</div>
<div>Here's a contrived example.</div>
<div><br>
</div>
<div>```</div>
<div><span style="color:rgb(80,0,80)"> __host__ int8 bar();</span><br style="color:rgb(80,0,80)">
<span style="color:rgb(80,0,80)">__device__ int16 bar();</span><br style="color:rgb(80,0,80)">
<span style="color:rgb(80,0,80)">__host__ __device__ auto foo() -> decltype(bar()) {}</span><br>
</div>
<div><span style="color:rgb(80,0,80)"><br>
</span></div>
<div><span style="color:rgb(80,0,80)">template <int N> </span><span style="color:rgb(80,0,80)">__global__ kernel();</span></div>
<div><span style="color:rgb(80,0,80)"><br>
</span></div>
<div><span style="color:rgb(80,0,80)">void launch_kernel() {</span></div>
<div><span style="color:rgb(80,0,80)">  kernel<sizeof(decltype(foo()))><<<...>>>();<br>
}</span></div>
<div>```</div>
<div><br>
</div>
<div>This template instantiation had better be the same when compiling for host and device.</div>
<div><br>
</div>
<div>That's contrived, but consider this much simpler case:</div>
<div><br>
</div>
<div>```</div>
<div>void host_fn() {</div>
<div>  static_assert(sizeof(decltype(foo())) == sizeof(int8));</div>
<div>}</div>
<div>```</div>
<div><br>
</div>
<div>If we let foo return int16 in device mode, this static_assert will fail when compiling in *device* mode even though host_fn is never called on the device.  <a href="https://gcc.godbolt.org/z/gYq901" target="_blank">https://gcc.godbolt.org/z/gYq901</a></div>
<div><br>
</div>
<div>Why are we doing sema checks on the host code when compiling for device?  See contrived example above, we need quite a bit of info about the host code to infer those templates.</div>
</div>
</div>
<br>
<div class="gmail-m_-3941697715883276625x_gmail_quote">
<div dir="ltr" class="gmail-m_-3941697715883276625x_gmail_attr">On Thu, May 2, 2019 at 7:05 PM Hal Finkel via Phabricator <<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>> wrote:<br>
</div>
<blockquote class="gmail-m_-3941697715883276625x_gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
hfinkel added a comment.<br>
<br>
In D61458#1488970 <<a href="https://reviews.llvm.org/D61458#1488970" rel="noreferrer" target="_blank">https://reviews.llvm.org/D61458#1488970</a>>, @jlebar wrote:<br>
<br>
> Here's one for you:<br>
><br>
>   __host__ float bar();<br>
>   __device__ int bar();<br>
>   __host__ __device__ auto foo() -> decltype(bar()) {}<br>
><br>
><br>
> What is the return type of `foo`?  :)<br>
><br>
> I don't believe the right answer is, "float when compiling for host, int when compiling for device."<br>
<br>
<br>
So, actually, I wonder if that's not the right answer. We generally allow different overloads to have different return types. What if, for example, the return type on the host is __float128 and on the device it's `MyLongFloatTy`?<br>
<br>
> I'd be happy if we said this was an error, so long as it's well-defined what exactly we're disallowing.  But I bet @rsmith can come up with substantially more evil testcases than this.<br>
<br>
<br>
<br>
<br>
Repository:<br>
  rG LLVM Github Monorepo<br>
<br>
CHANGES SINCE LAST ACTION<br>
  <a href="https://reviews.llvm.org/D61458/new/" rel="noreferrer" target="_blank">
https://reviews.llvm.org/D61458/new/</a><br>
<br>
<a href="https://reviews.llvm.org/D61458" rel="noreferrer" target="_blank">https://reviews.llvm.org/D61458</a><br>
<br>
<br>
<br>
</blockquote>
</div>
</div>
</div>
</div>
</div>

</blockquote></div>