[libc-commits] [PATCH] D139839: [libc] Add a loader utility for AMDHSA architectures for testing

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Dec 12 06:12:26 PST 2022


jhuber6 created this revision.
jhuber6 added reviewers: sivachandra, lntue, michaelrj, tianshilei1992, JonChesterfield, tra, jdoerfert, yaxunl.
Herald added subscribers: libc-commits, kosarev, Naghasan, ecnelises, kerbowa, tschuett, Anastasia, tpr, jvesely.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.
Herald added a subscriber: sstefan1.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139839

Files:
  libc/CMakeLists.txt
  libc/test/CMakeLists.txt
  libc/test/utils/tools/CMakeLists.txt
  libc/test/utils/tools/DeviceLoader/CMakeLists.txt
  libc/test/utils/tools/DeviceLoader/DeviceMain.cpp
  libc/utils/CMakeLists.txt
  libc/utils/DeviceLoader/CMakeLists.txt
  libc/utils/DeviceLoader/Loader.h
  libc/utils/DeviceLoader/Main.cpp
  libc/utils/DeviceLoader/amdgpu/CMakeLists.txt
  libc/utils/DeviceLoader/amdgpu/Loader.cpp
  libc/utils/DeviceLoader/amdgpu/Start.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139839.482094.patch
Type: text/x-patch
Size: 24853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221212/1202d5f3/attachment-0001.bin>


More information about the libc-commits mailing list