This is an archive of the discontinued LLVM Phabricator instance.

[libc] Support add_object_library for the GPU build
ClosedPublic

Authored by jhuber6 on Feb 16 2023, 12:50 PM.

Details

Summary

This patch unifies the handling of generating the GPU build targets
between the add_entrypoint_library and the add_object_library
functions. The _build_gpu_objects function will create two targets.
One contains a single object file with several GPU binaries embedded in
it, a so-called fatbinary. The other is a direct compile of the
supported target to be used internally only. This patch pulls out some
of the properties logic so that we can handle both more easily. This
patch also required adding an ovverride NO_GPU_BUILD for cases when
we only want to build the source file as normal.

Diff Detail

Event Timeline

jhuber6 created this revision.Feb 16 2023, 12:50 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptFeb 16 2023, 12:50 PM
jhuber6 requested review of this revision.Feb 16 2023, 12:50 PM
jhuber6 updated this revision to Diff 498132.Feb 16 2023, 1:23 PM

Changing the ENTRYPOINTS name in the CMake argument variable

lntue added inline comments.Feb 16 2023, 4:58 PM
libc/cmake/modules/LLVMLibCObjectRules.cmake
199

Look like NO_GPU_BUILD belongs to optional arguments, i.e. the line above.

jhuber6 updated this revision to Diff 498199.Feb 16 2023, 5:11 PM

Move the NO_GPU_BUILD option to the optional arguments.

jhuber6 marked an inline comment as done.Feb 16 2023, 5:11 PM
lntue added a comment.Feb 16 2023, 5:54 PM

Overall it looks good to me, but let's wait for @sivachandra to comment on the patch.

Also, I just noticed that build_gpu_objects is called after FLAGS expansion (via the chain add_entrypoint_object -> expand_flags_for_entrypoint_object -> create_entrypoint_object -> build_gpu_objects),
so for an entry point object with some FLAGS properties (that are currently used to create multiple targets for different CPU configurations, especially in math functions), redundant GPU targets will be generated.
This is probably not a problem with the current set of entry points enabled for GPU yet.

Anyway since we are going to push CMake version to 3.20 matching LLVM updated requirements, it's probably a good time for me to revise the FLAGS implementations make sure it works well with other use cases.

sivachandra accepted this revision.Feb 16 2023, 10:58 PM

LGTM, but I have left a naming suggestion.

libc/startup/gpu/nvptx/CMakeLists.txt
13

The name NO_GPU_BUILD seems odd when you do have LIBC_GPU_TARGET_ARCHITECTURE. May be name it NO_GPU_BUNDLE?

This revision is now accepted and ready to land.Feb 16 2023, 10:58 PM
This revision was automatically updated to reflect the committed changes.