This is an archive of the discontinued LLVM Phabricator instance.

[Clang][Bundler] Do not require host triple for extracting device bundles
ClosedPublic

Authored by sdmitriev on Aug 22 2019, 10:17 AM.

Details

Summary

Bundler currently requires host triple to be provided no matter if you are performing bundling or unbundling, but for unbundling operation such requirement is too restrictive. You may for example want to examine device part of the object for a particular offload target, but you have to extract host part as well even though you do not need it. Host triple isn't really needed for unbundling, so this patch removes that requirement.

Diff Detail

Repository
rL LLVM

Event Timeline

sdmitriev created this revision.Aug 22 2019, 10:17 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: cfe-commits. · View Herald Transcript
ABataev added inline comments.Aug 26 2019, 2:09 PM
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
888 ↗(On Diff #217234)

I believe, for unbundling we also must check for != 1 rather than > 1. Zero host targets also is not allowed.

sdmitriev marked an inline comment as done.Aug 26 2019, 2:22 PM
sdmitriev added inline comments.
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
888 ↗(On Diff #217234)

But the whole idea of this change is to remove requirement to provide host triple for unbundling operation. Target bundle(s) can always be extracted without extracting host, so host bundle is optional. Therefore zero host targets should not be considered as error for unbundling.

ABataev added inline comments.Aug 26 2019, 2:37 PM
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
888 ↗(On Diff #217234)

And why do we need this? I think it would be better to check that the requested host triple matches the bundled one using this parameter rather than removing it.

sdmitriev marked an inline comment as done.Aug 26 2019, 3:04 PM
sdmitriev added inline comments.
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
888 ↗(On Diff #217234)

And why do we need this?

As I wrote in the summary it is a usability issue. You may for example want to extract device object for a particular offload target to examine its contents (symbols, sections, etc..), but currently you also have to extract host bundle as well even if you do not need it.

I think it would be better to check that the requested host triple matches the bundled one using this parameter rather than removing it.

So you suggest to check that host bundle name that exists in the fat image matches the host bundle name provided it command line if it was provided? Should it be an error if names do not match?

sdmitriev updated this revision to Diff 217259.Aug 26 2019, 4:06 PM
sdmitriev marked an inline comment as done.Aug 26 2019, 4:09 PM
sdmitriev added inline comments.
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
888 ↗(On Diff #217234)

I have updated patch to do error checking if host bundle name was provided in command line.

sdmitriev marked an inline comment as done.Aug 27 2019, 11:05 AM
sdmitriev added inline comments.
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
888 ↗(On Diff #217234)

@ABataev I believe the host bundle name is now being checked as you suggested. Can you please confirm that it matches your expectations?

ABataev added inline comments.Aug 27 2019, 11:20 AM
clang/test/Driver/clang-offload-bundler.c
228–231 ↗(On Diff #217259)

What about tests for other kinds of elements like preprocessed code, IR, objects, etc.?

clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
795 ↗(On Diff #217259)

There must be a test for this change. better to implement it in a different patch, I think.

888 ↗(On Diff #217234)

Ok, I got the idea of the patch. BTW, will happen if I request the device code for the triple, which is correct, but bundled container does not have the device code for this triple?

sdmitriev marked an inline comment as done.Aug 27 2019, 11:31 AM
sdmitriev added inline comments.
clang/test/Driver/clang-offload-bundler.c
228–231 ↗(On Diff #217259)

Ok, I can add more tests for reprocessed code, IR, etc. I have added one test per file handler type so far, but I can do it per file type. BTW, test for object type is already there on line 264.

sdmitriev marked an inline comment as done.Aug 27 2019, 11:45 AM
sdmitriev added inline comments.
clang/test/Driver/clang-offload-bundler.c
228–231 ↗(On Diff #217259)

One note that adding more tests for binary file handler would most probably require this fix https://reviews.llvm.org/D66598. Can you please take a look at this patch?

sdmitriev updated this revision to Diff 217522.Aug 27 2019, 4:06 PM
sdmitriev marked an inline comment as done.

Added tests for each file type.

ABataev added inline comments.Aug 27 2019, 4:33 PM
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
888 ↗(On Diff #217234)

What about this?

sdmitriev marked an inline comment as done.Aug 27 2019, 4:41 PM
sdmitriev added inline comments.
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
888 ↗(On Diff #217234)

Based on the comments on lines 775-776 and 801 in ClangOffloadBundler.cpp bundler will create empty files for missing device bundles.

This revision is now accepted and ready to land.Aug 27 2019, 4:49 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 27 2019, 6:29 PM