<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Cuda Nested lambda (lambda inside a device function) requires __device__ annotation"
href="https://llvm.org/bugs/show_bug.cgi?id=30567">30567</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Cuda Nested lambda (lambda inside a device function) requires __device__ annotation
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>CUDA
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>crtrott@sandia.gov
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=17381" name="attach_17381" title="Reproducer example">attachment 17381</a> <a href="attachment.cgi?id=17381&action=edit" title="Reproducer example">[details]</a></span>
Reproducer example
With NVCC lambdas which are declared inside a __device__ (or __host__
__device__ ) function automatically get promoted to __device__ or __host__
__device__. In fact one is not even allowed to mark the operator. In clang one
must mark it though. This situation makes me write a lot of ifdefs.
Would it be possible to make lambda operators inherit the the attribute from
its scope if not explicitly specified? I am attaching a reproducer
demonstrating what I currently need to do to make it work.
Here are the error messages from NVCC if I use "[=] (const int& i) __device__"
main.cpp(14): warning: a __host__ function("lambda []::operator()") redeclared
with __device__, hence treated as a __host__ __device__ function
main.cpp(16): error: The operator() function for a lambda cannot be explicitly
annotated with execution space annotations (__host__/__device__/__global__),
the annotations are derived from its closure class
1 error detected in the compilation of
"/tmp/tmpxft_0001e52a_00000000-9_main.cpp1.ii".
and if I use "[=] __device__ (const int& i)":
main.cpp(14): error: An explicit __device__ lambda must be defined inside a
__host__ or __host__ __device__ function
1 error detected in the compilation of
"/tmp/tmpxft_0001e53a_00000000-9_main.cpp1.ii".</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>