Page MenuHomePhabricator

[OpenCL] Support half precision floating point type literal
ClosedPublic

Authored by yaxunl on Feb 3 2016, 12:29 PM.

Details

Summary

OpenCL allows half precision floating point type literals with suffices h or H when cl_khr_fp16 extension is enabled. This change supports that.

Differential Revision: http://reviews.llvm.org/D16865

Diff Detail

Repository
rL LLVM

Event Timeline

yaxunl updated this revision to Diff 46816.Feb 3 2016, 12:29 PM
yaxunl retitled this revision from to [OpenCL] Support half precision floating point type literal.
yaxunl updated this object.
yaxunl added a subscriber: tstellarAMD.
pxli168 added inline comments.Feb 3 2016, 7:50 PM
lib/Sema/SemaCast.cpp
2397 ↗(On Diff #46816)

In the context there is a SrcType you can just use it as you used below.

test/Lexer/opencl-half-literal.cl
5 ↗(On Diff #46816)

Did the tests need the constant here?
I think constant is address space in OpenCL, maybe you could remove them.

yaxunl marked 2 inline comments as done.Feb 4 2016, 5:42 AM
yaxunl added inline comments.
test/Lexer/opencl-half-literal.cl
5 ↗(On Diff #46816)

In OpenCL 1.2 and below program scope variable must be in constant address space.
I tried to remove the constant and I got error:
opencl-half-literal.cl Line 5: program scope variable must reside in constant address space

yaxunl updated this revision to Diff 46903.Feb 4 2016, 5:48 AM
yaxunl updated this object.
yaxunl marked an inline comment as done.

Revised as Xiuli Suggested.

yaxunl updated this revision to Diff 46905.Feb 4 2016, 6:09 AM

re-update diff. Accidentally dropped a line in test/SemaOpenCL/half.cl in the last update.

Anastasia edited edge metadata.Feb 4 2016, 10:54 AM

I think a reference to Spec section would be nice somewhere either in code or test.

Thanks!

lib/Lex/LiteralSupport.cpp
578 ↗(On Diff #46905)

I think the full diff would have been better here. Otherwise, too many fragments without context around makes it hard to review.

test/Lexer/opencl-half-literal.cl
6 ↗(On Diff #46905)

That's right, we can only declare program scope variables in a constant AS in OpenCL earlier than v2.0. So it's fine.

yaxunl updated this revision to Diff 46943.Feb 4 2016, 12:09 PM
yaxunl edited edge metadata.
yaxunl marked an inline comment as done.

Add reference to OpenCL extension spec in comments.
Update with full diff.

pxli168 accepted this revision.Feb 4 2016, 6:54 PM
pxli168 edited edge metadata.

LGTM!
Thanks.

This revision is now accepted and ready to land.Feb 4 2016, 6:54 PM
Anastasia added inline comments.Feb 5 2016, 8:28 AM
test/Lexer/opencl-half-literal.cl
10 ↗(On Diff #46943)

Could we disable cl_khr_fp16 here and check that we get an error when using half literals.

yaxunl updated this revision to Diff 47238.Feb 8 2016, 12:11 PM
yaxunl edited edge metadata.
yaxunl marked 2 inline comments as done.

Revised according to Anastasia's comments.

I got difficulty diagnosing half literal as lexical error since the preprocessor and lexer do not know whether OpenCL extension cl_khr_fp16 is enabled or not, so I diagnose half literal used without cl_khr_fp16 enabled as semantic error and added tests to SemaOpenCL.

Also I removed diagnostic for casting from half type since it is unnecessary. If half type value is created when cl_khr_fp16 is not enabled, it will be diagnosed before the cast expression is reached.

@pekka, do you have any additional comments here? I believe we are about to complete this work.

Thanks!

lib/Lex/LiteralSupport.cpp
559 ↗(On Diff #47238)

. missing

561 ↗(On Diff #47238)

. missing

test/SemaOpenCL/half.cl
49 ↗(On Diff #47238)

I think you already test this in line 4?

yaxunl marked 4 inline comments as done.Feb 11 2016, 11:42 AM
yaxunl added inline comments.
test/SemaOpenCL/half.cl
49 ↗(On Diff #47238)

I want to check after cl_khr_fp16 is enabled then disabled the behavior is expected. Do you think this is unnecessary?

yaxunl updated this revision to Diff 47711.Feb 11 2016, 1:06 PM
yaxunl marked an inline comment as done.

Revised as Anastasia suggested.

Changed comments.
Removed unnecessary tests.

Can you add a test that tries to use half precision constants in non OpenCL C mode? Otherwise LGTM.

yaxunl updated this revision to Diff 47805.Feb 12 2016, 8:01 AM
yaxunl edited edge metadata.

Added a test for half literal in non-OpenCL language as Pekka suggested.

Anastasia accepted this revision.Feb 12 2016, 9:55 AM
Anastasia edited edge metadata.

LGTM!

pekka.jaaskelainen edited edge metadata.

LGTM!

This revision was automatically updated to reflect the committed changes.