[Beignet] [PATCH 09/19] OCL20: Add __OPENCL_VERSION__ and CL_VERSION_2_0 define.
Yang Rong
rong.r.yang at intel.com
Mon Nov 28 11:32:35 UTC 2016
Because spir and spir64's data layout is different, so copy the ll files
and change data layout and triple to spir64.
Also correct ocl2.0 include typo.
Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
backend/src/libocl/include/ocl.h | 3 +-
backend/src/libocl/include/ocl_types.h | 8 +++-
backend/src/libocl/src/ocl_barrier_20.ll | 25 +++++++++++
backend/src/libocl/src/ocl_clz_20.ll | 65 +++++++++++++++++++++++++++++
backend/src/libocl/src/ocl_geometric.cl | 4 ++
backend/src/libocl/src/ocl_image.cl | 4 ++
backend/src/libocl/tmpl/ocl_defines.tmpl.h | 7 +++-
backend/src/libocl/tmpl/ocl_math_20.tmpl.cl | 2 +-
backend/src/libocl/tmpl/ocl_math_20.tmpl.h | 4 +-
9 files changed, 115 insertions(+), 7 deletions(-)
create mode 100644 backend/src/libocl/src/ocl_barrier_20.ll
create mode 100644 backend/src/libocl/src/ocl_clz_20.ll
diff --git a/backend/src/libocl/include/ocl.h b/backend/src/libocl/include/ocl.h
index e6f2567..677d2d4 100644
--- a/backend/src/libocl/include/ocl.h
+++ b/backend/src/libocl/include/ocl.h
@@ -89,7 +89,6 @@
#include "ocl_geometric.h"
#include "ocl_image.h"
#include "ocl_integer.h"
-#include "ocl_math.h"
#include "ocl_memcpy.h"
#include "ocl_memset.h"
#include "ocl_misc.h"
@@ -100,9 +99,11 @@
#include "ocl_vload_20.h"
#include "ocl_atom_20.h"
#include "ocl_pipe.h"
+#include "ocl_math_20.h"
#else
#include "ocl_vload.h"
#include "ocl_atom.h"
+#include "ocl_math.h"
#endif
#include "ocl_workitem.h"
#include "ocl_simd.h"
diff --git a/backend/src/libocl/include/ocl_types.h b/backend/src/libocl/include/ocl_types.h
index 824262d..327624b 100644
--- a/backend/src/libocl/include/ocl_types.h
+++ b/backend/src/libocl/include/ocl_types.h
@@ -47,8 +47,12 @@ typedef unsigned int uint;
typedef unsigned long ulong;
typedef __typeof__(sizeof(int)) size_t;
typedef __typeof__((int *)0-(int *)0) ptrdiff_t;
-typedef signed int intptr_t;
-typedef unsigned int uintptr_t;
+#define __int_t_type(a,b,c) a##b##c
+#define __int_type(type,n) __int_t_type(type,n,_TYPE__)
+typedef __int_type(__INT,__INTPTR_WIDTH__) intptr_t;
+typedef __int_type(__UINT,__INTPTR_WIDTH__) uintptr_t;
+#undef __int_type
+#undef __int_t_type
/////////////////////////////////////////////////////////////////////////////
// OpenCL address space
diff --git a/backend/src/libocl/src/ocl_barrier_20.ll b/backend/src/libocl/src/ocl_barrier_20.ll
new file mode 100644
index 0000000..8935076
--- /dev/null
+++ b/backend/src/libocl/src/ocl_barrier_20.ll
@@ -0,0 +1,25 @@
+;XXX FIXME as llvm can't use macros, we hardcoded 3, 1, 2
+;here, we may need to use a more grace way to handle this type
+;of values latter.
+;#define CLK_LOCAL_MEM_FENCE (1 << 0)
+;#define CLK_GLOBAL_MEM_FENCE (1 << 1)
+
+target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
+target triple = "spir64"
+
+declare i32 @_get_local_mem_fence() nounwind alwaysinline
+declare i32 @_get_global_mem_fence() nounwind alwaysinline
+declare void @__gen_ocl_barrier_local() nounwind alwaysinline noduplicate
+declare void @__gen_ocl_barrier_global() nounwind alwaysinline noduplicate
+declare void @__gen_ocl_debugwait() nounwind alwaysinline noduplicate
+declare void @__gen_ocl_barrier(i32) nounwind alwaysinline noduplicate
+
+define void @_Z7barrierj(i32 %flags) nounwind noduplicate alwaysinline {
+ call void @__gen_ocl_barrier(i32 %flags)
+ ret void
+}
+
+define void @_Z9debugwaitv() nounwind noduplicate alwaysinline {
+ call void @__gen_ocl_debugwait()
+ ret void
+}
diff --git a/backend/src/libocl/src/ocl_clz_20.ll b/backend/src/libocl/src/ocl_clz_20.ll
new file mode 100644
index 0000000..19f4e35
--- /dev/null
+++ b/backend/src/libocl/src/ocl_clz_20.ll
@@ -0,0 +1,65 @@
+target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
+target triple = "spir64"
+
+declare i8 @llvm.ctlz.i8(i8, i1)
+declare i16 @llvm.ctlz.i16(i16, i1)
+declare i32 @llvm.ctlz.i32(i32, i1)
+declare i64 @llvm.ctlz.i64(i64, i1)
+
+define i8 @clz_s8(i8 %x) nounwind readnone alwaysinline {
+ %call = call i8 @llvm.ctlz.i8(i8 %x, i1 0)
+ ret i8 %call
+}
+
+define i8 @clz_u8(i8 %x) nounwind readnone alwaysinline {
+ %call = call i8 @llvm.ctlz.i8(i8 %x, i1 0)
+ ret i8 %call
+}
+
+define i16 @clz_s16(i16 %x) nounwind readnone alwaysinline {
+ %call = call i16 @llvm.ctlz.i16(i16 %x, i1 0)
+ ret i16 %call
+}
+
+define i16 @clz_u16(i16 %x) nounwind readnone alwaysinline {
+ %call = call i16 @llvm.ctlz.i16(i16 %x, i1 0)
+ ret i16 %call
+}
+
+define i32 @clz_s32(i32 %x) nounwind readnone alwaysinline {
+ %call = call i32 @llvm.ctlz.i32(i32 %x, i1 0)
+ ret i32 %call
+}
+
+define i32 @clz_u32(i32 %x) nounwind readnone alwaysinline {
+ %call = call i32 @llvm.ctlz.i32(i32 %x, i1 0)
+ ret i32 %call
+}
+
+define i64 @clz_s64(i64 %x) nounwind readnone alwaysinline {
+ %1 = bitcast i64 %x to <2 x i32>
+ %2 = extractelement <2 x i32> %1, i32 0
+ %3 = extractelement <2 x i32> %1, i32 1
+ %call1 = call i32 @llvm.ctlz.i32(i32 %2, i1 0)
+ %call2 = call i32 @llvm.ctlz.i32(i32 %3, i1 0)
+ %cmp = icmp ult i32 %call2, 32
+ %4 = add i32 %call1, 32
+ %5 = select i1 %cmp, i32 %call2, i32 %4
+ %6 = insertelement <2 x i32> undef, i32 %5, i32 0
+ %call = bitcast <2 x i32> %6 to i64
+ ret i64 %call
+}
+
+define i64 @clz_u64(i64 %x) nounwind readnone alwaysinline {
+ %1 = bitcast i64 %x to <2 x i32>
+ %2 = extractelement <2 x i32> %1, i32 0
+ %3 = extractelement <2 x i32> %1, i32 1
+ %call1 = call i32 @llvm.ctlz.i32(i32 %2, i1 0)
+ %call2 = call i32 @llvm.ctlz.i32(i32 %3, i1 0)
+ %cmp = icmp ult i32 %call2, 32
+ %4 = add i32 %call1, 32
+ %5 = select i1 %cmp, i32 %call2, i32 %4
+ %6 = insertelement <2 x i32> undef, i32 %5, i32 0
+ %call = bitcast <2 x i32> %6 to i64
+ ret i64 %call
+}
diff --git a/backend/src/libocl/src/ocl_geometric.cl b/backend/src/libocl/src/ocl_geometric.cl
index cf98503..af39ed3 100644
--- a/backend/src/libocl/src/ocl_geometric.cl
+++ b/backend/src/libocl/src/ocl_geometric.cl
@@ -18,7 +18,11 @@
#include "ocl_geometric.h"
#include "ocl_common.h"
#include "ocl_relational.h"
+#if (__OPENCL_C_VERSION__ >= 200)
+#include "ocl_math_20.h"
+#else
#include "ocl_math.h"
+#endif
#include "ocl_float.h"
CONST float __gen_ocl_fabs(float x) __asm("llvm.fabs" ".f32");
diff --git a/backend/src/libocl/src/ocl_image.cl b/backend/src/libocl/src/ocl_image.cl
index b06f7a7..2febfda 100644
--- a/backend/src/libocl/src/ocl_image.cl
+++ b/backend/src/libocl/src/ocl_image.cl
@@ -16,7 +16,11 @@
*
*/
#include "ocl_image.h"
+#if (__OPENCL_C_VERSION__ >= 200)
+#include "ocl_math_20.h"
+#else
#include "ocl_math.h"
+#endif
#include "ocl_integer.h"
#include "ocl_common.h"
#include "ocl_convert.h"
diff --git a/backend/src/libocl/tmpl/ocl_defines.tmpl.h b/backend/src/libocl/tmpl/ocl_defines.tmpl.h
index f5c65df..c16a99f 100644
--- a/backend/src/libocl/tmpl/ocl_defines.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_defines.tmpl.h
@@ -18,13 +18,18 @@
#ifndef __OCL_COMMON_DEF_H__
#define __OCL_COMMON_DEF_H__
-#define __OPENCL_VERSION__ 120
#define __CL_VERSION_1_0__ 100
#define __CL_VERSION_1_1__ 110
#define __CL_VERSION_1_2__ 120
#define CL_VERSION_1_0 100
#define CL_VERSION_1_1 110
#define CL_VERSION_1_2 120
+#if (__OPENCL_C_VERSION__ >= 200)
+#define __OPENCL_VERSION__ 200
+#define CL_VERSION_2_0 200
+#else
+#define __OPENCL_VERSION__ 120
+#endif
#define __ENDIAN_LITTLE__ 1
#define __IMAGE_SUPPORT__ 1
#define __kernel_exec(X, TYPE) __kernel __attribute__((work_group_size_hint(X,1,1))) \
diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
index 717fc7a..d47e0a2 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
@@ -15,7 +15,7 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
-#include "ocl_math.h"
+#include "ocl_math_20.h"
#include "ocl_float.h"
#include "ocl_relational.h"
#include "ocl_common.h"
diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
index ca8c02a..271075c 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
@@ -15,8 +15,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
-#ifndef __OCL_MATH_H__
-#define __OCL_MATH_H__
+#ifndef __OCL_MATH_20_H__
+#define __OCL_MATH_20_H__
#include "ocl_types.h"
--
2.1.4
More information about the Beignet
mailing list