This is an archive of the discontinued LLVM Phabricator instance.

Triple: Add opencl environment type
ClosedPublic

Authored by tstellarAMD on Sep 19 2016, 10:35 AM.

Details

Summary

For AMDGPU, we have been using the operating system component of the triple
for specifying the low-level runtime that is being used. The rationale for
this is that the host operating system (e.g. Linux) is irrelevant for GPU code,
since its execution enviroment will be mostly controled by the low-level runtime
being used to execute the code.

In most cases, higher level languages have their own runtime which is
implemented on top of the low-level runtime. The kernel ABIs of each
language mostly depend on the low-level runtime, but there may be some
slight differences between languages. OpenCL for example, may append
additional arguments to the kernel in order to pass values like global
offsets or buffers for printf. OpenMP, HCC, or other languages may want
to add their own values which differ from OpenCL.

The reason for adding a new opencl environment type is to make it possible for the backend
to distinguish between the ABIs of the higher-level languages and handle them correctly.
It seems cleaner to use the enviroment component for this rather than creating a new
OS type for every combination of low-level runtime / high-level language.

Diff Detail

Repository
rL LLVM

Event Timeline

tstellarAMD retitled this revision from to Triple: Add opencl environment type.
tstellarAMD updated this object.
tstellarAMD added a subscriber: llvm-commits.

Makes sense to me. How to differentiate between OpenCL implementations? With the OS setting?

Makes sense to me. How to differentiate between OpenCL implementations? With the OS setting?

I was thinking the vendor field could be used for this. So, for example, if pocl used the hsa runtime, the triple would be: amdgcn-pocl-amdhsa-opencl.

Anastasia edited edge metadata.Sep 21 2016, 12:43 PM

Could we add a clang driver test too checking new triple?

include/llvm/ADT/Triple.h
194 ↗(On Diff #71846)

What would be the difference to AMDOpenCL item above?

include/llvm/ADT/Triple.h
194 ↗(On Diff #71846)

AMDOpenCL was used with the X86 arch only. I wanted to add something that would be more extensible and would make sense for other vendors.

Could we add a clang driver test too checking new triple?

https://reviews.llvm.org/D24813

chandlerc accepted this revision.Sep 21 2016, 5:04 PM
chandlerc edited edge metadata.

Makes sense to me. How to differentiate between OpenCL implementations? With the OS setting?

I was thinking the vendor field could be used for this. So, for example, if pocl used the hsa runtime, the triple would be: amdgcn-pocl-amdhsa-opencl.

Just as an FYI:

Generally the vendor shouldn't be used to control *semantics* anywhere. It should just be used to find tools or label things.

If you have a different ABI, you want a different environment entry typically.

In that sense this seems like a nice improvement.

This revision is now accepted and ready to land.Sep 21 2016, 5:04 PM
This revision was automatically updated to reflect the committed changes.
Anastasia added inline comments.Sep 27 2016, 10:14 AM
include/llvm/ADT/Triple.h
194 ↗(On Diff #71846)

I see. Could AMDOpenCL be replaced by OpenCL as more generic item then?