This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add code for detecting NVIDIA GPUs as well
ClosedPublic

Authored by jhuber6 on Jan 27 2023, 11:06 AM.

Details

Summary

Recently the nvptx-arch tool was added to address the lack of a
similar tool for detecting locally installed NVIDIA GPUs. This patch
adds similar functionality for the already existing amdgpu-arch tool
in libc. These will be used to run tests on the user's system in the
future. On a system with both GPUs installed we will just go with the
first GPU detected. In the future we may want to configure the tests to
run on both of them.

Diff Detail

Event Timeline

jhuber6 created this revision.Jan 27 2023, 11:06 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 27 2023, 11:06 AM
jhuber6 requested review of this revision.Jan 27 2023, 11:06 AM
lntue accepted this revision.Jan 27 2023, 11:30 AM
This revision is now accepted and ready to land.Jan 27 2023, 11:30 AM
sivachandra added a comment.EditedJan 27 2023, 11:41 AM
This comment has been deleted.
libc/cmake/modules/prepare_libc_gpu_build.cmake
53

How can one pick between AMD or Nvidia GPUs?

jhuber6 added inline comments.Jan 27 2023, 11:44 AM
libc/cmake/modules/prepare_libc_gpu_build.cmake
53

I wasn't sure if it warranted a special case right now. Since this is a contingency for a system with both an Nvidia and AMD GPU installed, which is uncommon but not unheard of. Right now I wasn't sure how much effort it would be to support testing multiple builds at the same time, so I figured it would be easier to just stick with one for now.

I could maybe make an override flag. Maybe that would also be useful for ensuring the tests get built even without a GPU installed (as would be the case if someone build LLVM on a cluster's home node and then switched to a compute node).

sivachandra accepted this revision.Jan 27 2023, 11:46 AM
sivachandra added inline comments.
libc/cmake/modules/prepare_libc_gpu_build.cmake
53

Maybe that would also be useful for ensuring the tests get built even without a GPU installed (as would be the case if someone build LLVM on a cluster's home node and then switched to a compute node).

You don't need to address this in this patch but I had this exact use case in mind.

jhuber6 added inline comments.Jan 27 2023, 11:52 AM
libc/cmake/modules/prepare_libc_gpu_build.cmake
53

Yes, I think it would be best to focus on getting the tests up and running first. Right now my plans are

  • Implement a new 'loader' like https://reviews.llvm.org/D139839. Right now I'll probably implement it via the OpenMP runtime to make it more common
  • Add a very simple integration test that ensures we can call a main function on the GPU.
  • Start working on an RPC mechanism to enable printf and exit like features and then use those to implement the unit test suite.

Once we have that we can probably start thinking about wrapping the existing unit tests into integration tests as well. Do you have any suggestions for how that support should look? I see there have been a few changes in libc since I last looked so I want to make sure I'm up-to-date.

Basically the next patches would be like

libc/startup/gpu/amdgpu/start.cpp
libc/startup/gpu/nvptx/start.cpp

Then

libc/utils/gpu/Loader/openmp/Loader.cpp

and finally

libc/utils/gpu/RPC/Server.h
This revision was automatically updated to reflect the committed changes.