[cfe-dev] [OpenCL patch] Half type as native when OpenCL's cl_khr_fp16 extension is enabled

Anton Lokhmotov Anton.Lokhmotov at arm.com
Wed Aug 15 04:42:53 PDT 2012


Hi Doug,

> > While the conformance tests are not sacred, it can be argued that the
> > composition of '&' and '[]' should result in half*, so should not be
> > rejected.  Unfortunately, we found no obvious way to implement this 
> > in Clang, so leave this case as TODO.
> 
> One way to handle the "storage-only" version is for buffer[index] to
> produce a non-modifiable lvalue (so you can't write it) and to ban the
> lvalue-to-rvalue conversion for such a value (for the latter, see
> Sema::DefaultLValueConversion).

We've tried to implement your proposal, but ended up with putting
OpenCLOptions into ASTContext, which is not the cleanest of solutions.  If
it's the only problem with this patch, would it be possible to commit it
as-is?  Meanwhile, we'll try to come up with a better solution (fixing the
FIXMEs).

Many thanks,
Anton.


> -----Original Message-----
> From: Douglas Gregor [mailto:dgregor at apple.com]
> Sent: 31 July 2012 19:25
> To: Anton Lokhmotov
> Cc: 'John Garvin'; cfe-dev at cs.uiuc.edu; Anton Korobeynikov
> Subject: Re: [cfe-dev] [OpenCL patch] Half type as native when OpenCL's
> cl_khr_fp16 extension is enabled
> 
> 
> On Jul 24, 2012, at 3:03 AM, Anton Lokhmotov <Anton.Lokhmotov at arm.com>
> wrote:
> 
> > Hi John,
> >
> >> It looks like we have four possibilities. Is this right?
> >> 1. half is completely unsupported (C, C++ default)
> >> 2. half is storage-only, support half* but no operations on half
> >> (OpenCL without cl_khr_fp16)
> >> 3. half is storage-only, operations on half automatically promoted
> to
> >> float (__fp16 NEON)
> >> 4. half is completely supported (OpenCL with cl_khr_fp16)
> >>
> >> HalfTypeNative (or PromoteHalfToFloat) would differentiate between
> the
> >> last two cases in CodeGen; the first two cases are irrelevant in
> >> CodeGen because in those cases it should be impossible to pass a
> half
> >> type to EmitScalarConversion.
> >
> > I agree.
> >
> > We found a problem with our solution addressing your previous comment
> [1].
> > One of the OpenCL conformance tests attempts to do something like
> this:
> >
> > __global half * buffer;
> > size_t index;
> > ...
> > vstore_half(
> >    /* float data = */ 1.0f,
> >    /* size_t offset = */ 0,
> >    /* __global half *p = */ &buffer[index]
> > );
> >
> > Disallowing 'buffer[index]' as in [2] results in:
> > error: dereferencing half pointer ('half *') is not allowed.
> >
> > While the conformance tests are not sacred, it can be argued that the
> > composition of '&' and '[]' should result in half*, so should not be
> > rejected.  Unfortunately, we found no obvious way to implement this
> in
> > Clang, so leave this case as TODO.
> 
> 
> One way to handle the "storage-only" version is for buffer[index] to
> produce a non-modifiable lvalue (so you can't write it) and to ban the
> lvalue-to-rvalue conversion for such a value (for the latter, see
> Sema::DefaultLValueConversion).
> 
> 	- Doug
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: half_type.patch
Type: application/octet-stream
Size: 18452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120815/a296c161/attachment.obj>


More information about the cfe-dev mailing list