<div dir="ltr">
<p class=""><span class="">Hi all,</span></p>
<p class=""><span class="">Thanks everyone for engaging in this thread. After a nice long discussion, it’s probably time to capture all the suggestions and produce a summary. </span></p>
<p class=""><span class="">===========================</span></p>
<p class=""><span class="">Things that I understand are settled:</span></p>
<p class=""><span class="">===========================</span></p>
<ul class="">
<li class=""><span class="">The driver implementation has to flexible so as to allow a device toolchain to use macros and headers from the host toolchain and vice-versa.</span></li>
<li class=""><span class="">The driver implementation should be modular and easy to extend to new programing models, each with its own Action dependence graph (I am proposing an implementation for this in the patches I sent in the meantime).</span></li>
<li class=""><span class="">The driver Action should reflect the programming models in use (the patches I sent in the meantime observe this constraint).</span></li>
<li class=""><span class="">File names used by save-temps need to reflect the programming model and contain “host” or “device” because in general the same toolchain can can be used for host and device.</span></li>
<li class=""><span class="">It is important to support separate compilation to prevent users from having to change complex build systems.</span></li>
<li class=""><span class="">When we have code for different devices or different programming models, it is not expected that the tools for a single programming model or device would work well on the resulting binary/file. That doesn’t mean that we should not pursue interoperability for the cases where it can be achieved.</span></li>
<li class=""><span class="">We probably want to adopt a set of unified group options to specify offloading devices, and programming-model-specific options, but that can be discussed separately.</span></li>
</ul>
<p class=""><span class=""></span><br></p>
<p class=""><span class="">==============================</span></p>
<p class=""><span class="">Not settled - intermediate file bundling:</span></p>
<p class=""><span class="">==============================</span></p>
<p class=""><span class="">Bundling is what has generated more discussion and more conflicting opinions. Just to make sure we are all in the same page, for:</span></p>
<p class=""><span class="">a.c -> "clang -c" -> X -> “clang" -> Y</span></p>
<p class="">the issue we need to settle is “what is the format of X?”. I don’t think there is much to discuss about the format of Y — it has to be whatever the programming model implementation needs, usually a bunch of device code in some section whose pointer is passed to some runtime library to be registered and loaded.</p>
<p class=""><span class="">Let me also clarify the terminology I am using (embed vs. bundle) because reading through the previous emails, it may have been misleading:</span></p>
<p class=""><span class="">In Y, the device code is functionally related with the host code because the former is referred to by the latter in the form of some pointer (address of a section) that is registered with the host runtime library. So the process that generates Y is what I am calling “embed”.</span></p>
<p class=""><span class="">In X, the device code does not require to be functionally related with the host. Both device and host code should be however organized in a way (binary sections or some other sort of metadata) that makes the extraction of code for specific devices easy to accomplish. That process that generates X is what I am calling “bundle”.</span></p><p class=""><span class=""><br></span></p>
<p class=""><span class="">So, "what is the *bundle* format of X?”. There are two proposals: “use the host object format - ELF” or “use a target agnostic format”. As far as I know, both would work. </span></p>
<p class=""><span class="">The former seems to be the one that has more supporters in this thread. I’ll try to address the Pros and Cons of each one with some implementation considerations. For “host object format” I am mostly referring to ELF, because it is the format I have more experience with, and the only one I can commit to contribute an implementation.</span></p>
<p class=""><span class="">============</span></p>
<p class=""><span class="">Pros/Cons</span></p>
<p class=""><span class="">============</span></p>
<p class=""><span class="">ELF Pros:</span></p>
<ul class="">
<li class=""><span class="">It is what other compilers are using (except for gcc that uses IR).</span></li>
<li class=""><span class="">A host-device object could be linked by other compilers that may not be aware of how device code is bundled (what sections are used - what symbols should be defined). Therefore, the resulting binary may not be fully functional (the load of CUDA module would fail, the host version of the kernels would be used in OpenMP), but it can be executed.</span></li>
<li class=""><span class="">It is a format that is already handled by the compiler, so we wouldn’t be inventing a new format.</span></li>
</ul>
<p class=""><span class="">ELF Cons:</span></p>
<ul class="">
<li class=""><span class="">Works only for object formats (I don’t think anyone was proposing to use ELF to bundle text/IR formats).</span></li>
<li class=""><span class="">Extraction of device code is not straightforward. A user interested in doing that would have to learn what an ELF file is and what sections are being used.</span></li>
<li class=""><span class="">The bundling implementation has to be aware of the specifics in the programming model (however, adopting a generic ELF bundle format would alleviate this).</span></li>
<li class=""><span class="">Custom code to deal with binary formats other than ELF is required.</span></li></ul>
<p class=""><span class="">---</span></p>
<p class=""><span class="">Target/format agnostic Pros:</span></p>
<ul class="">
<li class=""><span class="">Would work for any OS and target.</span></li>
<li class=""><span class="">Format can be made compatible with some widely used bundling tool (e.g. tar).</span></li>
<li class=""><span class="">Format can be chosen so that the device components can be easily extracted by some widely available tool.</span></li>
<li class=""><span class="">Adding support for a new device wouldn’t require revisiting the bundling implementation.</span></li>
</ul>
<p class=""><span class="">Target/format agnostic Cons:</span></p>
<ul class="">
<li class=""><span class="">Have to invent a new format...</span></li>
<li class=""><span class="">… or use an existent one that may not be portable across OS (having a tool in clang that deals with that format would alleviate this.)</span></li>
<li class=""><span class="">Cannot link the bundled file with other host code as is.</span></li></ul>
<p class=""><span class="">============</span></p>
<p class=""><span class="">Implementation</span></p>
<p class=""><span class="">============</span></p>
<p class=""><span class="">In order to be able to obtain Y from X, the device components of X have to extracted, forwarded to the device linker, and the result is then embedded in the host binary. The embedding can be implemented with a linker script if using ld as the linker. But the extraction from X has to be enabled by a tool — I don’t see a better way to do it. </span></p>
<p class="">ELF: The tool has to know how to navigate ELF files. Possible solutions:<br><span class=""></span></p>
<p class=""><span class="">a) Use something based on libelf - would require changes in the build system to check for that dependency. Not sure if there is some licensing issue here as well. Possibly not a viable solution.</span></p>
<p class=""><span class="">b) Attempt to use the Objects library in LLVM to scan the elf files in a new tool. </span></p>
<p class=""><span class="">c) Add a new mode to llvm-readobj to extract binary sections from the object file. We wouldn’t require an extra tool, llvm-readobj would be *the* tool. </span></p>
<p class="">In any case the ELF bundling would have to use a convention for the name of the sections something like “.clang.offload.<programming-model>.<device-triple>.<architecture>”.</p>
<p class=""><span class="">---</span></p>
<p class=""><span class="">Target/format agnostic: A new tool would have to be implemented for this. We would have to decide which format — that would be the hard part. Then, regardless of the format, this is all about having a header implemented with the bytes in the right place, similarly to what I proposed in <a href="http://reviews.llvm.org/D13909">http://reviews.llvm.org/D13909</a>. The header could be compatible with a widely used tool to enable easy extraction of device components. </span></p>
<p class=""><span class="">==========================</span></p>
<p class=""><span class="">Considerations about embedding</span></p>
<p class=""><span class="">==========================</span></p>
<p class=""><span class="">As I mentioned before, embedding can be controlled with a linker script if using ld. However:</span></p>
<ul class="">
<li class=""><span class="">linker scripts directives are not fully supported by gold.</span></li>
<li class=""><span class="">I don’t know if a linker script can be easily used for link.exe or other linkers people may be interested about.</span></li></ul>
<p class=""><span class=""></span>If, because of these constraints, we end up having a tool for embedding (create host linkable objects with the required symbols device code in the right section), that tool can be the same as the bundling tool under a different mode. The complexity of an embedding tool is low: generate a piece of IR that defines the right symbols and respective initializers and call the right backend to generate an object.<br></p>
<p class=""><br></p>
<p class=""><span class="">==========================</span></p>
<p class=""><span class="">Hope I captured everything, if not let me know.</span></p>
<p class=""><span class="">My opinion:</span></p>
<p class=""><span class="">i) I find it very convenient to have the ability to edit intermediate files and be able to generate a binary from there. Editing a piece of IR or Asm, is something that I and other people I work with use to explore performance improvements and fix bugs. So I don’t see this as minor feature.</span></p>
<p class=""><span class="">ii) Having something that works in all cases and then specialize to some format seems to be a natural way to build things.</span></p>
<p class=""><span class="">iii) If no one else cares about i) and host-obj bundling is the way to go, I can work on the implementation for ELF (I think the solution c) above is the one with more merits) and let someone else contribute support for other object formats. If so, is the section naming I proposed above a good one?</span></p>
<p class=""><span class=""></span><br></p>
<p class=""><span class="">Let me know your thoughts so that we can settle this last pending issue.</span></p>
<p class=""><span class="">Thanks!</span></p>
<p class=""><span class="">Samuel</span></p></div><div class="gmail_extra"><br><div class="gmail_quote">2016-03-15 19:45 GMT-04:00 Justin Lebar via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> I don't have any other tool that would be compatible with a bundle of all four object files, doesn't matter how I do it,<br>
<br>
</span>I think we've given up on letting existing tools (e.g. objdump) work<br>
well on our host+device*n object files, see discussions earlier in the<br>
thread. Even I, probably the loudest supporter of this on thread,<br>
think that it's probably not an important case that cuobjdump work<br>
sensibly when you are embedding two different nvptx bundles into one<br>
object file, since this is an edge case that most people aren't going<br>
to encounter.<br>
<span class=""><br>
> Creating linkable host objects shouldn't be that hard (clang-bundler -embed).<br>
<br>
</span>This seems to be basically the same as embedding the device code into<br>
the object file -- just a different format.<br>
<span class=""><br>
> If the bundler uses a target agnostic format, my example above would just work regardless of the compiler phases -- -S, -emit-ast, -emit-llvm, -emit-ast would work just fine.<br>
<br>
</span>What I believe we do with CUDA compilation is say that all of these<br>
output code just for the host, unless you specify a device<br>
architecture, in which case you can only specify one. It seems to<br>
work OK. I'll grant the "wouldn't it be nice if" we could output a<br>
single file containing .s files for all archs, but I'm not convinced<br>
goes beyond wouldn't-it-be-nice.<br>
<span class=""><br>
> - Extending the bundler to enable compatibility modes can then be discussed on a per-case basis if there are a lot of users asking for that feature.<br>
<br>
</span>There are, on this very thread. :) I don't think in any case that<br>
these compatibility modes can be a second-thought -- they'll need to<br>
be first-class citizens in the design.<br>
<br>
The whole first half of this mail seems quite complicated to me,<br>
frankly. Even if it may be convenient for complex compilation modes<br>
like the openmp + cuda one you described, it may not be convenient for<br>
simpler modes, which I expect will be far more common.<br>
<br>
-Justin<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Mar 15, 2016 at 2:37 PM, Samuel F Antao <<a href="mailto:sfantao@us.ibm.com">sfantao@us.ibm.com</a>> wrote:<br>
> Let me provide a more concrete example of what I had in mind (sorry for the<br>
> long email...):<br>
><br>
> Lets assume I have two source files <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a> and <a href="http://b.cu" rel="noreferrer" target="_blank">b.cu</a>, both with OpenMP and CUDA<br>
> kernels and several device functions. Device functions defined in <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a> are<br>
> used in <a href="http://b.cu" rel="noreferrer" target="_blank">b.cu</a> and vice-versa.<br>
><br>
> I have a system that consists of a ppc64le host, an nvptx64 device and a<br>
> ppc64le accelerator. The exact details of this system are not relevant, I am<br>
> just using this example because it is something supported by the prototype<br>
> we have in github and exemplifies that the same target can be both host and<br>
> device (in general we can have AMD GPUs, DSPs, FPGAs, each with its own<br>
> binary formats).<br>
><br>
> ###<br>
> Case A: We pass all the source files and compile in a single run of clang.<br>
><br>
> A1) clang invocation (the openmp options are just an example, *.cu extension<br>
> tells the driver we should compile for CUDA as well):<br>
> clang -target ppc64le -fopenmp -fomptargets=nvptx64,ppc64le <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a> <a href="http://b.cu" rel="noreferrer" target="_blank">b.cu</a><br>
><br>
> A2) driver commands:<br>
> // Obtain cuda obj for <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a><br>
> clang -cc1 -fcuda-is-device -target nvptx64 -S <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a> -o<br>
> a-device-cuda-nvptx64.s<br>
> ptxas -c a-device-cuda-nvptx64.s -o a-device-cuda-nvptx64.o<br>
><br>
> // Obtain openmp nvptx64 obj for <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a><br>
> clang -cc1 -fopenmp-is-device -target nvptx64 -S <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a> -o<br>
> a-device-openmp-nvptx64.s<br>
> ptxas -c a-device-openmp-nvptx64.s -o a-device-openmp-nvptx64.o<br>
><br>
> // Obtain openmp ppc64le device obj for <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a><br>
> clang -cc1 -fopenmp-is-device -target ppc64le -c <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a> -o<br>
> a-device-openmp-ppc64le.o<br>
><br>
> // Obtain openmp ppc64le host obj for <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a><br>
> clang -cc1 -fopenmp -target ppc64le -c <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a> -o a-host-cuda-openmp.o<br>
><br>
> // Repeat everything for <a href="http://b.cu" rel="noreferrer" target="_blank">b.cu</a><br>
><br>
> // Obtain cuda device image:<br>
> nvlink a-device-cuda-nvptx64.o b-device-cuda-nvptx64.o -o<br>
> a.out-device-cuda-nvptx64<br>
><br>
> // Obtain openmp nvptx device image:<br>
> nvlink a-device-openmp-nvptx64.o b-device-openmp-nvptx64.o -o<br>
> a.out-device-openmp-nvptx64<br>
><br>
> // Obtain openmp ppc64le device image (making it a shared library is just<br>
> easier to load, but not required):<br>
> ld -shared a-device-openmp-ppc64le.o b-device-openmp-ppc64le.o -o<br>
> a.out-device-openmp-ppc64le<br>
><br>
> // Create a host compatible object for each device (this is done at link<br>
> time only, the user is not expected to deal with this tool - the name of the<br>
> tool and commands are just an example).<br>
> // I am calling this "embed-mode" but is not really embedding, is generate<br>
> an host object that solely contains device code...<br>
> clang-bundler -embed -host ppc64le -models=cuda,openmp,openmp<br>
> -targets=nvptx64,nvptx64,ppc64le<br>
> -inputs=a.out-device-cuda-nvptx64,a.out-device-openmp-nvptx64,a.out-device-openmp-ppc64le<br>
> -outputs=a.out-device-cuda-nvptx64.o,a.out-device-openmp-nvptx64.o,a.out-device-openmp-ppc64le.o<br>
><br>
> // Generate the host binary<br>
> ld a-host-cuda-openmp.o a.out-device-cuda-nvptx64.o<br>
> a.out-device-openmp-nvptx64.o a.out-device-openmp-ppc64le.o -o a.out<br>
><br>
> ###<br>
> Case B: We do separate compilation.<br>
> B1) clang invocation (the openmp options are just an example, *.cu extension<br>
> tells the driver we should compile for CUDA as well):<br>
> clang -c -target ppc64le -fopenmp -fomptargets=nvptx64,ppc64le <a href="http://a.cu" rel="noreferrer" target="_blank">a.cu</a> <a href="http://b.cu" rel="noreferrer" target="_blank">b.cu</a><br>
> clang -target ppc64le -fopenmp -fomptargets=nvptx64,ppc64le a.o b.o<br>
><br>
> B2) driver commands - 1st run:<br>
><br>
> // Same thing as in A2) up to the nvlink command<br>
><br>
> // Create the bundles a.o and b.o so that the user sees a single file.<br>
> clang-bundler -bundle -models=host,cuda,openmp,openmp<br>
> -targets=nvptx64,nvptx64,ppc64le<br>
> -inputs=a-host-cuda-openmp.o,a-device-cuda-nvptx64.o,a-device-openmp-nvptx64.o,a-device-openmp-ppc64le.o<br>
> -outputs=a.o<br>
> clang-bundler -bundle -models=host,cuda,openmp,openmp<br>
> -targets=nvptx64,nvptx64,ppc64le<br>
> -inputs=b-host-cuda-openmp.o,b-device-cuda-nvptx64.o,b-device-openmp-nvptx64.o,b-device-openmp-ppc64le.o<br>
> -outputs=b.o<br>
><br>
> B2) driver commands - 2nd run:<br>
> // Attempt to unbundle the inputs because the user is asking for<br>
> offloading support and they are not source files. If the bundler understands<br>
> the file is a bundle it creates the individual files, otherwise create empty<br>
> files for the devices.<br>
> clang-bundler -unbundle -models=host,cuda,openmp,openmp<br>
> -targets=nvptx64,nvptx64,ppc64le -outputs<br>
> =a-host-cuda-openmp.o,a-device-cuda-nvptx64.o,a-device-openmp-nvptx64.o,a-device-openmp-ppc64le.o<br>
> -inputs=a.o<br>
> clang-bundler -unbundle -models=host,cuda,openmp,openmp<br>
> -targets=nvptx64,nvptx64,ppc64le -outputs<br>
> =b-host-cuda-openmp.o,b-device-cuda-nvptx64.o,b-device-openmp-nvptx64.o,b-device-openmp-ppc64le.o<br>
> -inputs=b.o<br>
><br>
> // Same thing in A2 starting from the nvlink commands.<br>
><br>
> ###<br>
> A few more comments/observations:<br>
><br>
> - I don't have any other tool that would be compatible with a bundle of all<br>
> four object files, doesn't matter how I do it, this is just not supported by<br>
> any other compiler and I'm not doing anything wrong as per the programming<br>
> models specification. But, I have tools compatible with each object. That's<br>
> is way I agree we should give the user the ability to extract objects. I<br>
> agree with Justin that extracting stuff from tar is more convenient that<br>
> doing it from ELF (I don't think most users will now how to do it from ELF,<br>
> and it is very likely they don't even know what ELF is, for them is just a<br>
> binary, so not exposing these details is desirable). I am not trying to push<br>
> for a specific format, I just think it should be target agnostic.<br>
><br>
> - Creating linkable host objects shouldn't be that hard (clang-bundler<br>
> -embed). For CUDA I can create an IR file that defines<br>
> "__cuda_fatbin_wrapper" with the bytes coming from the fat binary (that<br>
> global would have to be made external though). For OpenMP it would do<br>
> something similar but for ".omp_offloading.img_start/end.<device>". The<br>
> resulting IR could then be converted into an object by calling the host<br>
> backend. The tool itself wouldn't care about obj formats.<br>
><br>
> - If the bundler uses a target agnostic format, my example above would just<br>
> work regardless of the compiler phases -- -S, -emit-ast, -emit-llvm,<br>
> -emit-ast would work just fine.<br>
><br>
> - Extending the bundler to enable compatibility modes can then be discussed<br>
> on a per-case basis if there are a lot of users asking for that feature. If<br>
> that is to be supported, someone with experience with that format could<br>
> contribute it and there is nothing in the design that prevents it. Expecting<br>
> to have something that works for all formats obj formats and device<br>
> combinations from the very beginning seems not reasonable. My plan of action<br>
> was to contribute something that works and can scale to as many use cases as<br>
> possible, I can't however contribute specific code for every possible<br>
> device, in particular those that are not supported in clang yet.<br>
><br>
> - The user does not have to deal with the bundling tool at any time if we<br>
> adopt a format that makes it easy to extract objects. I don't know if one<br>
> should avoid completely having a tool (again the user doesn't have to use<br>
> it, but it can look it up in the install tree of clang). An alternative is<br>
> supporting something like clang -ccbundle. Maybe other people are aware of<br>
> what are the precedents in clang?<br>
><br>
> About shared libraries: I am not sure what is the concern with shared<br>
> libraries. They would be created as binaries would, and would contain<br>
> bundles on them. Nothing that is proposed here precludes that. Supporting<br>
> device-side shared libraries depends on whether the runtime library<br>
> implements a loader or not. It is very possible I am missing something<br>
> here...<br>
><br>
> Thanks!<br>
> Samuel<br>
><br>
> 2016-03-15 14:36 GMT-04:00 Eric Christopher via cfe-dev<br>
> <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>>:<br>
>><br>
>><br>
>><br>
>> On Tue, Mar 15, 2016 at 12:25 AM C Bergström <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
>> wrote:<br>
>>><br>
>>> Afaik - The way that each vendor *embeds* is a little different and<br>
>>> non-conflicting. (AMD vs NV vs Intel) Embedding for each vendor in a<br>
>>> single object may work. Wouldn't this achieve the desired goal without<br>
>>> the bundling? Bundling is a non-solution - it's just delays dealing<br>
>>> with the offload target code, at which point you have to extract and<br>
>>> jump around to make sure it all magically works (fragile - This side<br>
>>> up)<br>
>>><br>
>><br>
>> I'm somewhat in agreement here. An alternate idea is to just "do what<br>
>> we've always done" and have compatibility modes where we try to do what's<br>
>> expected for the particular end use that we're trying to copy. That would<br>
>> get us maximum flexibility (at the cost of a number of implementations, but<br>
>> abstraction hopefully ftw?).<br>
>><br>
>>><br>
>>> With embedding approach we have all the pieces to at least read/embed<br>
>>> - it's just dealing with elf/macho/pxe objects and data sections.<br>
>>><br>
>><br>
>> Agreed.<br>
>><br>
>>><br>
>>> Also there's the question of how to deal with shared libraries - Even<br>
>>> if initially it's not a concern, eventually someone will request it.<br>
>>> If this isn't ever going to be supported or a concern it's not valid<br>
>>> of course..<br>
>>><br>
>><br>
>> I'm sure someone is going to want it eventually.<br>
>><br>
>> -eric<br>
>><br>
>>><br>
>>> On Tue, Mar 15, 2016 at 2:54 PM, Justin Lebar via cfe-dev<br>
>>> <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br>
>>> >> I agree with Justin when he says that supporting all possible<br>
>>> >> combinations of host-device bundling, each with a custom format adds a lot<br>
>>> >> of complexity and does not necessarily helps the user.<br>
>>> ><br>
>>> > Maybe it would be helpful to speak concretely about this. What is a<br>
>>> > specific case you're concerned about?<br>
>>> ><br>
>>> > Frankly if we try to build a thing that does everything -- both embeds<br>
>>> > and bundles -- I'm concerned that will be much more complex than<br>
>>> > either approach by itself. But maybe there's something about bundling<br>
>>> > code for many different devices that's qualitatively different than<br>
>>> > bundling code for one or just a few devices? For example, are there<br>
>>> > extant formats that we would like to be compatible with that are<br>
>>> > incompatible with each other? Again, I think it would be helpful to<br>
>>> > be concrete.<br>
>>> ><br>
>>> >> Using a header compatible with tar is not something hard to do, having<br>
>>> >> the bundler tool as part of clang ensures that it works across operating<br>
>>> >> systems too.<br>
>>> ><br>
>>> > This is a minor point, but -- without getting myself back into the<br>
>>> > minefield of discussing whether using the tar format is or is not good<br>
>>> > -- if we do use said format, given what I understand at the moment,<br>
>>> > I'm not in favor of building our own user-facing tool, if that's<br>
>>> > possible. If you're on Windows and want to inspect a tar file you<br>
>>> > can, download 7z. It's no different than downloading objdump. But we<br>
>>> > can postpone this discussion until later; I suspect it won't be<br>
>>> > necessary, given the pushback to using tar in the first place.<br>
>>> ><br>
>>> >> this leaves room to have custom-format bundling activated with options<br>
>>> >> for the cases (would have to be evaluated one by one) that would greatly<br>
>>> >> benefit of interoperability.<br>
>>> ><br>
>>> > This is, as I read it, exactly what everyone else has been arguing so<br>
>>> > strenuously against (and what I conceded to).<br>
>>> ><br>
>>> > On Mon, Mar 14, 2016 at 7:25 PM, Samuel F Antao <<a href="mailto:sfantao@us.ibm.com">sfantao@us.ibm.com</a>><br>
>>> > wrote:<br>
>>> >> Hi all,<br>
>>> >><br>
>>> >> I decided a take shot on a possible implementation for the part of<br>
>>> >> this<br>
>>> >> proposal that I think is more consensual (i.e. the part that does not<br>
>>> >> relate<br>
>>> >> with the bundling). I posted three patches<br>
>>> >> (<a href="http://reviews.llvm.org/D18170" rel="noreferrer" target="_blank">http://reviews.llvm.org/D18170</a>,<br>
>>> >> <a href="http://reviews.llvm.org/D18171" rel="noreferrer" target="_blank">http://reviews.llvm.org/D18171</a>, <a href="http://reviews.llvm.org/D18172" rel="noreferrer" target="_blank">http://reviews.llvm.org/D18172</a>) with a<br>
>>> >> possible implementation, so that we have something more concrete to<br>
>>> >> discuss.<br>
>>> >> Let me know your thoughts.<br>
>>> >><br>
>>> >> Going back to the bundling discussion:<br>
>>> >><br>
>>> >> I agree with Justin when he says that supporting all possible<br>
>>> >> combinations<br>
>>> >> of host-device bundling, each with a custom format adds a lot of<br>
>>> >> complexity<br>
>>> >> and does not necessarily helps the user. Therefore, I think reasonable<br>
>>> >> to<br>
>>> >> have intermediate files bundled in some already existent format (say<br>
>>> >> tar)<br>
>>> >> that is agnostic of the programming model. Actually, that was my<br>
>>> >> motivation<br>
>>> >> when I proposed the custom format in the bundler.<br>
>>> >><br>
>>> >> When I look at all the different concerns I think that a possible<br>
>>> >> solution<br>
>>> >> is to have a bundler with three operation modes:<br>
>>> >> i) "Embed": it generates a host object that contains the device image<br>
>>> >> and<br>
>>> >> properly defines the symbols a programming model requires. Therefore<br>
>>> >> it can<br>
>>> >> be linked with host objects successfully. This file is never exposed<br>
>>> >> to the<br>
>>> >> user unless save-temps is used.<br>
>>> >> ii) "Bundle": Combines host and device object using, by default, a<br>
>>> >> format<br>
>>> >> easy to interact with that is agnostic of the programming model.<br>
>>> >> iii) "Unbundle": The inverse of ii), it assumes the input uses that<br>
>>> >> default<br>
>>> >> format.<br>
>>> >><br>
>>> >> Using a header compatible with tar is not something hard to do, having<br>
>>> >> the<br>
>>> >> bundler tool as part of clang ensures that it works across operating<br>
>>> >> systems<br>
>>> >> too. At the same time, this leaves room to have custom-format bundling<br>
>>> >> activated with options for the cases (would have to be evaluated one<br>
>>> >> by one)<br>
>>> >> that would greatly benefit of interoperability.<br>
>>> >><br>
>>> >> Does this sound reasonable?<br>
>>> >><br>
>>> >> Thanks!<br>
>>> >> Samuel<br>
>>> >><br>
>>> >> 2016-03-10 13:59 GMT-05:00 Justin Lebar via cfe-dev<br>
>>> >> <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>>:<br>
>>> >>><br>
>>> >>> > Justin, is this convincing enough?<br>
>>> >>><br>
>>> >>> Okay, okay. Uncle.<br>
>>> >>><br>
>>> >>> There are two things here that I find convincing.<br>
>>> >>><br>
>>> >>> 1) Although we're not going to be compatible with the details of<br>
>>> >>> some,<br>
>>> >>> if not all, other compilers' formats, we can at least be compatible<br>
>>> >>> with the spirit by using object files as opposed to tar.<br>
>>> >>><br>
>>> >>> 2) The postscript in Andrey's e-mail:<br>
>>> >>><br>
>>> >>> > Re: objdump doesn't understand ELF format with code for multiple<br>
>>> >>> > targets. The same is true for fat executable files as well, isn't?<br>
>>> >>> > So if we<br>
>>> >>> > need to teach objdump how to recognize fat files, we already have<br>
>>> >>> > this<br>
>>> >>> > problem.<br>
>>> >>><br>
>>> >>> It's probably much more important that objdump work on executables<br>
>>> >>> than on object files, since if you have object files, you can<br>
>>> >>> probably<br>
>>> >>> recompile with -save-temps, but if you only have an executable, you<br>
>>> >>> don't necessarily have access to intermediate files, or even a<br>
>>> >>> compiler for the relevant architecture, much less the specific<br>
>>> >>> compiler which generated the executable.<br>
>>> >>><br>
>>> >>> Shoving device code into the host *executable* seems unavoidable.<br>
>>> >>> I'm<br>
>>> >>> still not thrilled with doing the same for object files -- it still<br>
>>> >>> feels like we're using ELF when we actually want an archive format --<br>
>>> >>> but (1) makes it less bad.<br>
>>> >>><br>
>>> >>> -Justin<br>
>>> >>><br>
>>> >>> On Wed, Mar 9, 2016 at 5:59 AM, Andrey Bokhanko<br>
>>> >>> <<a href="mailto:andreybokhanko@gmail.com">andreybokhanko@gmail.com</a>> wrote:<br>
>>> >>> > All,<br>
>>> >>> ><br>
>>> >>> > I asked Intel GCC guys who implemented OpenMP offloading support in<br>
>>> >>> > GCC,<br>
>>> >>> > and<br>
>>> >>> > as they told me, GCC also employs option #4 from Hal's list -- it<br>
>>> >>> > puts<br>
>>> >>> > both<br>
>>> >>> > host and target code in a single ELF file. "Code" in GCC case is<br>
>>> >>> > always<br>
>>> >>> > GCC's IR (Gimple), though -- they require GCC invocation from<br>
>>> >>> > linker in<br>
>>> >>> > order to produce a multi-target executable. This makes GCC<br>
>>> >>> > non-interoperable<br>
>>> >>> > with any other offloading compiler and effectively produces its own<br>
>>> >>> > standard.<br>
>>> >>> ><br>
>>> >>> > Thus, prior art from:<br>
>>> >>> > * nvcc<br>
>>> >>> > * Pathscale<br>
>>> >>> > * GCC<br>
>>> >>> > * ICC<br>
>>> >>> ><br>
>>> >>> > indicates only one direction -- compiler driver produces a single<br>
>>> >>> > object<br>
>>> >>> > file with target code embedded in data section.<br>
>>> >>> ><br>
>>> >>> > Justin, is this convincing enough? I don't see any good reasons why<br>
>>> >>> > clang<br>
>>> >>> > should go against what every other compiler on the planet does.<br>
>>> >>> ><br>
>>> >>> > Re: objdump doesn't understand ELF format with code for multiple<br>
>>> >>> > targets.<br>
>>> >>> > The same is true for fat executable files as well, isn't? So if we<br>
>>> >>> > need<br>
>>> >>> > to<br>
>>> >>> > teach objdump how to recognize fat files, we already have this<br>
>>> >>> > problem.<br>
>>> >>> ><br>
>>> >>> > Yours,<br>
>>> >>> > Andrey<br>
>>> >>> > =====<br>
>>> >>> > Software Engineer<br>
>>> >>> > Intel Compiler Team<br>
>>> >>> ><br>
>>> >>> ><br>
>>> >>> _______________________________________________<br>
>>> >>> cfe-dev mailing list<br>
>>> >>> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
>>> >>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
>>> >><br>
>>> >><br>
>>> > _______________________________________________<br>
>>> > cfe-dev mailing list<br>
>>> > <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
>>> > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
>>> _______________________________________________<br>
>>> cfe-dev mailing list<br>
>>> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
>><br>
>><br>
>> _______________________________________________<br>
>> cfe-dev mailing list<br>
>> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
>><br>
><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div>