<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - [NVPTX] Wrong results or hang on GPU when using lastprivate() on SPMD construct with full runtime"
   href="https://bugs.llvm.org/show_bug.cgi?id=39172">39172</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[NVPTX] Wrong results or hang on GPU when using lastprivate() on SPMD construct with full runtime
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>OpenMP
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Clang Compiler Support
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>hahnjo@hahnjo.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following program uses an SPMD construct with lastprivate() clause and the
runtime has to be initialized because of schedule(dynamic):
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  int last;

  #pragma omp target teams distribute parallel for map(from: last)
lastprivate(last) schedule(dynamic)
  for (int i = 0; i < 10000; i++) {
    last = i;
  }

  printf("last = %d\n", last);

  return EXIT_SUCCESS;
}

Compiled with current Clang trunk the application delivers wrong results (last
= 0) with -O0 and -O1 and hangs with -O2 and -O3. I think this is due to the
same problem: The generated code calls __kmpc_data_sharing_push_stack() to get
memory for storing "int last;" to implement lastprivate(). This works if the
runtime is uninitialized because there is a special case in libomptarget-nvptx
which returns the *same memory location for all threads* (see
<a href="https://reviews.llvm.org/D51875">https://reviews.llvm.org/D51875</a>).
However the original contract of __kmpc_data_sharing_push_stack() was to return
*unique memory for each thread* which explains the wrong result. For higher
optimization levels I'd guess that LLVM exploits undefined behaviour somewhere
which makes the application hang?

The only solution I can think of is to introduce new entry points in
libomptarget-nvptx with the required contract: Return the same memory location
for all calling threads in the same thread block. Opinions?</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>