[all-commits] [llvm/llvm-project] 630037: [libc] Partially implement 'rand' for the GPU (#66...

Joseph Huber via All-commits all-commits at lists.llvm.org
Thu Oct 19 14:01:56 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 630037ede4cec8870764bed27c1289388ac33097
      https://github.com/llvm/llvm-project/commit/630037ede4cec8870764bed27c1289388ac33097
  Author: Joseph Huber <35342157+jhuber6 at users.noreply.github.com>
  Date:   2023-10-19 (Thu, 19 Oct 2023)

  Changed paths:
    M libc/config/gpu/entrypoints.txt
    M libc/src/stdlib/rand.cpp
    M libc/src/stdlib/rand_util.cpp
    M libc/src/stdlib/rand_util.h
    M libc/test/src/stdlib/rand_test.cpp

  Log Message:
  -----------
  [libc] Partially implement 'rand' for the GPU (#66167)

Summary:
This patch partially implements the `rand` function on the GPU. This is
partial because the GPU currently doesn't support thread local storage
or static initializers. To implement this on the GPU. I use 1/8th of the
local / shared memory quota to treak the shared memory as thread local
storage. This is done by simply allocating enough storage for each
thread in the block and indexing into this based off of the thread id.
The downside to this is that it does not initialize `srand` correctly to
be `1` as the standard says, it is also wasteful. In the future we
should figure out a way to support TLS on the GPU so that this can be
completely common and less resource intensive.




More information about the All-commits mailing list