[all-commits] [llvm/llvm-project] 533145: [libc] Support 'assert.h' on the GPU

Joseph Huber via All-commits all-commits at lists.llvm.org
Thu Aug 31 13:05:05 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 533145c458fa022ff5b24dfa33e71539747f5c2c
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2023-08-31 (Thu, 31 Aug 2023)

  Changed paths:
    M libc/config/gpu/api.td
    M libc/config/gpu/entrypoints.txt
    M libc/config/gpu/headers.txt
    M libc/docs/gpu/support.rst
    M libc/src/__support/GPU/utils.h
    M libc/src/__support/RPC/rpc.h
    M libc/src/__support/RPC/rpc_util.h
    M libc/src/assert/CMakeLists.txt
    R libc/src/assert/__assert_fail.cpp
    A libc/src/assert/generic/CMakeLists.txt
    A libc/src/assert/generic/__assert_fail.cpp
    A libc/src/assert/gpu/CMakeLists.txt
    A libc/src/assert/gpu/__assert_fail.cpp

  Log Message:
  [libc] Support  'assert.h' on the GPU

This patch adds the necessary support to provide `assert` functionality
through the GPU `libc` implementation. This implementation creates a
special-case GPU implementation rather than relying on the common
version. This is because the GPU has special considerings for printing.
The assertion is printed out in chunks with `write_to_stderr`, however
when combined with the GPU execution model this causes 32+ threads to
all execute in-lock step. Meaning that we'll get a horribly fragmented
message. Furthermore, potentially thousands of threads could hit the
assertion at once and try to print even if we had it all in one

This is solved by having a one-time lock that each thread group / wave /
warp will attempt to claim. We only let one thread group pass through
while the others simply stop executing. Finally only the first thread in
that group will do the printing until we finally abort execution.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D159296

More information about the All-commits mailing list