[PATCH] D24666: [OpenCL] Allow half type kernel argument when cl_khr_fp16 is enabled
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 16 07:32:40 PDT 2016
yaxunl created this revision.
yaxunl added reviewers: Anastasia, bader.
yaxunl added subscribers: cfe-commits, nhaustov, rampitec.
Herald added a subscriber: yaxunl.
https://reviews.llvm.org/D24666
Files:
lib/Sema/SemaDecl.cpp
test/SemaOpenCL/half.cl
test/SemaOpenCL/invalid-kernel-parameters.cl
Index: test/SemaOpenCL/invalid-kernel-parameters.cl
===================================================================
--- test/SemaOpenCL/invalid-kernel-parameters.cl
+++ test/SemaOpenCL/invalid-kernel-parameters.cl
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s -triple spir-unknown-unknown
+kernel void half_arg(half x) { } // expected-error{{'half' cannot be used as the type of a kernel parameter}} // expected-error{{declaring function parameter of type 'half' is not allowed; did you forget * ?}}
+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
@@ -11,7 +13,8 @@
kernel void bool_arg(bool x) { } // expected-error{{'bool' cannot be used as the type of a kernel parameter}}
-kernel void half_arg(half x) { } // expected-error{{'half' cannot be used as the type of a kernel parameter}}
+// half kernel argument is allowed when cl_khr_fp16 is enabled.
+kernel void half_arg(half x) { }
typedef struct ContainsBool // expected-note{{within field of type 'ContainsBool' declared here}}
{
Index: test/SemaOpenCL/half.cl
===================================================================
--- test/SemaOpenCL/half.cl
+++ test/SemaOpenCL/half.cl
@@ -25,6 +25,9 @@
return h;
}
+kernel void half_disabled_kernel(global half *p,
+ half h); // expected-error{{'half' cannot be used as the type of a kernel parameter}} // expected-error{{declaring function parameter of type 'half' is not allowed; did you forget * ?}}
+
// Exactly the same as above but with the cl_khr_fp16 extension enabled.
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
constant half a = 1.0h;
@@ -48,3 +51,7 @@
return h;
}
+
+kernel void half_enabled_kernel(global half *p,
+ half h);
+
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -7524,7 +7524,7 @@
RecordKernelParam
};
-static OpenCLParamType getOpenCLKernelParameterType(QualType PT) {
+static OpenCLParamType getOpenCLKernelParameterType(Sema &S, QualType PT) {
if (PT->isPointerType()) {
QualType PointeeType = PT->getPointeeType();
if (PointeeType->isPointerType())
@@ -7545,7 +7545,10 @@
if (PT->isEventT())
return InvalidKernelParam;
- if (PT->isHalfType())
+ // OpenCL extension spec v1.2 s9.5:
+ // This extension adds support for half scalar and vector types as built-in
+ // types that can be used for arithmetic operations, conversions etc.
+ if (!S.getOpenCLOptions().cl_khr_fp16 && PT->isHalfType())
return InvalidKernelParam;
if (PT->isRecordType())
@@ -7566,7 +7569,7 @@
if (ValidTypes.count(PT.getTypePtr()))
return;
- switch (getOpenCLKernelParameterType(PT)) {
+ switch (getOpenCLKernelParameterType(S, PT)) {
case PtrPtrKernelParam:
// OpenCL v1.2 s6.9.a:
// A kernel function argument cannot be declared as a
@@ -7649,7 +7652,7 @@
if (ValidTypes.count(QT.getTypePtr()))
continue;
- OpenCLParamType ParamType = getOpenCLKernelParameterType(QT);
+ OpenCLParamType ParamType = getOpenCLKernelParameterType(S, QT);
if (ParamType == ValidKernelParam)
continue;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24666.71642.patch
Type: text/x-patch
Size: 3226 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160916/c92f14bd/attachment-0001.bin>
More information about the cfe-commits
mailing list