[all-commits] [llvm/llvm-project] 67d78e: [libc] Add a loader utility for AMDHSA architectur...

Joseph Huber via All-commits all-commits at lists.llvm.org
Mon Feb 13 11:49:22 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 67d78e3c6fe51ad045ebeef9b68293a3c3d61d42
      https://github.com/llvm/llvm-project/commit/67d78e3c6fe51ad045ebeef9b68293a3c3d61d42
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2023-02-13 (Mon, 13 Feb 2023)

  Changed paths:
    M libc/utils/CMakeLists.txt
    A libc/utils/gpu/CMakeLists.txt
    A libc/utils/gpu/loader/CMakeLists.txt
    A libc/utils/gpu/loader/Loader.h
    A libc/utils/gpu/loader/Main.cpp
    A libc/utils/gpu/loader/amdgpu/CMakeLists.txt
    A libc/utils/gpu/loader/amdgpu/Loader.cpp

  Log Message:
  -----------
  [libc] Add a loader utility for AMDHSA architectures for testing

This is the first attempt to get some testing support for GPUs in LLVM's
libc. We want to be able to compile for and call generic code while on
the device. This is difficult as most GPU applications also require the
support of large runtimes that may contain their own bugs (e.g. CUDA /
HIP / OpenMP / OpenCL / SYCL). The proposed solution is to provide a
"loader" utility that allows us to execute a "main" function on the GPU.

This patch implements a simple loader utility targeting the AMDHSA
runtime called `amdhsa_loader` that takes a GPU program as its first
argument. It will then attempt to load a predetermined `_start` kernel
inside that image and launch execution. The `_start` symbol is provided
by a `start` utility function that will be linked alongside the
application. Thus, this should allow us to run arbitrary code on the
user's GPU with the following steps for testing.

```
clang++ Start.cpp --target=amdgcn-amd-amdhsa -mcpu=<arch> -ffreestanding -nogpulib -nostdinc -nostdlib -c
clang++ Main.cpp --target=amdgcn-amd-amdhsa -mcpu=<arch> -nogpulib -nostdinc -nostdlib -c
clang++ Start.o Main.o --target=amdgcn-amd-amdhsa -o image
amdhsa_loader image <args, ...>
```

We determine the `-mcpu` value using the `amdgpu-arch` utility provided
either by `clang` or `rocm`. If `amdgpu-arch` isn't found or returns an
error we shouldn't run the tests as the machine does not have a valid
HSA compatible GPU. Alternatively we could make this utility in-source
to avoid the external dependency.

This patch provides a single test for this untility that simply checks
to see if we can compile an application containing a simple `main`
function and execute it.

The proposed solution in the future is to create an alternate
implementation of the LibcTest.cpp source that can be compiled and
launched using this utility. This approach should allow us to use the
same test sources as the other applications.

This is primarily a prototype, suggestions for how to better integrate
this with the existing LibC infastructure would be greatly appreciated.
The loader code should also be cleaned up somewhat. An implementation
for NVPTX will need to be written as well.

Reviewed By: sivachandra, JonChesterfield

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




More information about the All-commits mailing list