This is an archive of the discontinued LLVM Phabricator instance.

[libc] Enable running libc unit tests on AMDGPU
ClosedPublic

Authored by jhuber6 on Apr 29 2023, 7:36 AM.

Details

Summary

The previous patches added the necessary support for global constructors
used to register tests. This patch enables the AMDGPU target to build
and run the unit tests on the GPU. Currently this only tests the ctype
tests, but adding more should be straightforward from here on.

Diff Detail

Event Timeline

jhuber6 created this revision.Apr 29 2023, 7:36 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 29 2023, 7:36 AM
jhuber6 requested review of this revision.Apr 29 2023, 7:36 AM
sivachandra added inline comments.Apr 29 2023, 4:48 PM
libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
51

Why was this moved?

libc/cmake/modules/LLVMLibCTestRules.cmake
74 ↗(On Diff #518164)

Do we ever want to run unit tests the GPU? If no, then I think the right thing to do is to convert the unit test targets to add_libc_test targets which will then do the right thing.

libc/test/src/CMakeLists.txt
13

Why do you need this? If you don't include math tests in entrypoints.txt, this will not become active anyway, correct?

jhuber6 added inline comments.Apr 29 2023, 5:55 PM
libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
51

Previously it prevented the above functions from being defined which are queried in the test setup.

libc/cmake/modules/LLVMLibCTestRules.cmake
74 ↗(On Diff #518164)

I mostly did this because it was much less noise than converting everything to the new format. Since I figured that would be dependent on the rest of the libc project contributors to transition to the new test framework. This was the easy stopgap.

libc/test/src/CMakeLists.txt
13

It was active when I tested it, I don't have any math entrypoints in the GPU entrypoint file. It built fine, but it spammed like 30 of these warnings about MPFR into the terminal so I just wanted to silence that.

sivachandra added inline comments.Apr 30 2023, 1:30 AM
libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
51

Ah! This is not ideal but I think doing it correctly is beyond the scope of this patch.

libc/cmake/modules/LLVMLibCTestRules.cmake
74 ↗(On Diff #518164)

What we should be doing is, when adding an entrypoint to the GPU's entrypoints.txt, convert the entrypoint's unit tests to add_libc_test.

libc/test/src/CMakeLists.txt
12

If it is just this annoying warning, you can modify this to:

message(VERBOSE "Math test ...")

Then, that warning will only be displayed if --log-level is set to VERBOSE or lower.

jhuber6 added inline comments.Apr 30 2023, 5:17 AM
libc/cmake/modules/LLVMLibCTestRules.cmake
74 ↗(On Diff #518164)

Alright, this would require reordering the add_subdirectory() calls in the test CMake and exiting early for GPU builds.

sivachandra added inline comments.Apr 30 2023, 7:47 AM
libc/cmake/modules/LLVMLibCTestRules.cmake
74 ↗(On Diff #518164)

The goal was that it should not require such reordering. If you are requiring it, then it is a bug somewhere. Can you share the error messages you are seeing?

jhuber6 added inline comments.Apr 30 2023, 7:52 AM
libc/cmake/modules/LLVMLibCTestRules.cmake
74 ↗(On Diff #518164)

Various ones, right now I see the build fail because I don't have stdio configured so we get undefined references to _IOBUF. Also some others fail because stdio.h goes to the host version which has the traditional failure mode.

sivachandra added inline comments.May 1 2023, 12:59 AM
libc/cmake/modules/LLVMLibCTestRules.cmake
74 ↗(On Diff #518164)

Can you give repro instructions that I can use to see what you are seeing?

jhuber6 added inline comments.May 1 2023, 4:24 AM
libc/cmake/modules/LLVMLibCTestRules.cmake
74 ↗(On Diff #518164)

Try configuring CMake with with -DLLVM_ENABLE_RUNTIMES=libc -DLIBC_GPU_ARCHITECTURES=gfx90a -DLIBC_GPU_TEST_ARCHITECTURE=gfx90a. That should allow you to build the tests. Then remove the guard at line libc/test/CMakeLists.txt:25 below. You will need lld.

jhuber6 updated this revision to Diff 518557.May 1 2023, 2:04 PM

Changing to specifically disable tests for the targets we have in the
entrypoints but don't support hermetic tests. These can be removed as more of
the test suite is brought over to the new format.

jhuber6 updated this revision to Diff 519232.May 3 2023, 1:38 PM

Update to support more entrypoints. This gets rid of the string conversion
entrypoints until we can figure out how to make the errno asserts work. Also I
had to somewhat hack around weird compiler behaviour. It's not ideal but since
it still tests the functionality I think it should be sufficient for now as I
prepare a bug report.

sivachandra added inline comments.May 3 2023, 2:09 PM
libc/config/gpu/entrypoints.txt
71

You can keep the entrypoints but skip the tests with a detailed comment. Up to you.

libc/test/src/__support/File/CMakeLists.txt
4

May the actual reason is that we don't yet support files on the GPU? If yes, then may be just say that?

libc/test/src/__support/blockstore_test.cpp
95

Without the context of this patch, the word "these" becomes vague. Can you may be say:

Combing this test with the above test makes the AMDGPU backend
generate code which hangs.
TODO: Investigate why the AMDGPU backend is generating such code.
libc/test/src/stdio/CMakeLists.txt
6

Those tests which depend on entrypoints will not be included. I think you want to return() on line 326?

jhuber6 updated this revision to Diff 519307.May 3 2023, 5:05 PM

Addressing comments.

sivachandra accepted this revision.May 3 2023, 8:22 PM
This revision is now accepted and ready to land.May 3 2023, 8:22 PM
This revision was automatically updated to reflect the committed changes.