[Beignet] [PATCH 01/18] Add the ocl header file and dir for bitcode library.

junyan.he at inbox.com junyan.he at inbox.com
Tue Aug 12 00:31:08 PDT 2014


From: Junyan He <junyan.he at linux.intel.com>

The first step for seperating the defination from the ocl
huge header file. The ocl.h will include all the header
files which will be used. All the bit code will be compiled
as a bitcode lib named beignet.bc.

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/CMakeLists.txt                     |   3 +
 backend/src/CMakeLists.txt                 |  20 ++++++
 backend/src/GBEConfig.h.in                 |   2 +
 backend/src/libocl/Makefile.in             |  39 +++++++++++
 backend/src/libocl/include/ocl.h           |   7 ++
 backend/src/libocl/include/ocl_defines.inh |  23 +++++++
 backend/src/libocl/include/ocl_types.h     | 104 +++++++++++++++++++++++++++++
 backend/src/libocl/lib/beignet.bc          |   0
 9 files changed, 199 insertions(+), 1 deletion(-)
 create mode 100644 backend/src/libocl/Makefile.in
 create mode 100644 backend/src/libocl/include/ocl.h
 create mode 100644 backend/src/libocl/include/ocl_defines.inh
 create mode 100644 backend/src/libocl/include/ocl_types.h
 create mode 100644 backend/src/libocl/lib/beignet.bc

diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index ca674cf..8734c2a 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -101,6 +101,9 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR})
 add_subdirectory (src)
 set(LOCAL_PCH_OBJECT_DIR ${LOCAL_PCH_OBJECT_DIR} PARENT_SCOPE)
 set(LOCAL_PCM_OBJECT_DIR ${LOCAL_PCM_OBJECT_DIR} PARENT_SCOPE)
+set(LOCAL_OCL_BITCODE_BIN "${LOCAL_OCL_BITCODE_BIN}" PARENT_SCOPE)
+set(LOCAL_OCL_HEADER_DIR "${LOCAL_OCL_HEADER_DIR}" PARENT_SCOPE)
+
 set(LOCAL_GBE_OBJECT_DIR ${LOCAL_GBE_OBJECT_DIR} PARENT_SCOPE)
 set(LOCAL_INTERP_OBJECT_DIR ${LOCAL_INTERP_OBJECT_DIR} PARENT_SCOPE)
 
diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt
index 85b5e21..63eb0f0 100644
--- a/backend/src/CMakeLists.txt
+++ b/backend/src/CMakeLists.txt
@@ -1,3 +1,6 @@
+set (OCL_BITCODE_BIN "${BEIGNET_INSTALL_DIR}beignet.bc")
+set (OCL_BITCODE_DIR "${BEIGNET_INSTALL_DIR}")
+set (OCL_HEADER_DIR "${CMAKE_INSTALL_PREFIX}/include/CL/ocl/")
 set (ocl_vector_spec_file ${GBE_SOURCE_DIR}/src/builtin_vector_proto.def)
 set (ocl_vector_file ${GBE_SOURCE_DIR}/src/ocl_vector.h)
 set (ocl_as_file ${GBE_SOURCE_DIR}/src/ocl_as.h)
@@ -60,6 +63,14 @@ add_custom_command(
      DEPENDS ${ocl_blob_file}
      )
 
+add_custom_command (
+    OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/libocl/lib/beignet.bc
+    COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/libocl && make
+    )
+
+add_custom_target(beignet_bitcode ALL
+    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libocl/lib/beignet.bc
+    )
 add_custom_target(pch_object
                   DEPENDS ${pch_object})
 
@@ -201,6 +212,8 @@ target_link_libraries(
 
 add_library(gbeinterp SHARED gbe_bin_interpreter.cpp)
 
+add_dependencies(gbe beignet_bitcode)
+
 if (LLVM_VERSION_NODOT VERSION_EQUAL 34)
   find_library(TERMINFO NAMES tinfo ncurses)
   if (${TERMINFO} STREQUAL TERMINFO-NOTFOUND)
@@ -221,6 +234,9 @@ install (TARGETS gbeinterp LIBRARY DESTINATION ${BEIGNET_INSTALL_DIR})
 install (FILES ${ocl_blob_file} DESTINATION ${BEIGNET_INSTALL_DIR})
 install (FILES ${pch_object} DESTINATION ${BEIGNET_INSTALL_DIR})
 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${pcm_lib} DESTINATION ${BEIGNET_INSTALL_DIR})
+install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/libocl/lib/beignet.bc DESTINATION ${OCL_BITCODE_DIR})
+install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libocl/include/ DESTINATION ${OCL_HEADER_DIR} PATTERN *.h)
+
 # When build beignet itself, we need to export the local precompiled header file and precompiled module
 # file to libcl and utests.
 set (LOCAL_PCH_OBJECT_DIR "${local_pch_object}:${BEIGNET_INSTALL_DIR}/ocl_stdlib.h.pch" PARENT_SCOPE)
@@ -236,3 +252,7 @@ configure_file (
   "GBEConfig.h.in"
   "GBEConfig.h"
 )
+configure_file (
+    "libocl/Makefile.in"
+    "libocl/Makefile"
+    )
diff --git a/backend/src/GBEConfig.h.in b/backend/src/GBEConfig.h.in
index f5c69c6..6f9d57f 100644
--- a/backend/src/GBEConfig.h.in
+++ b/backend/src/GBEConfig.h.in
@@ -5,3 +5,5 @@
 #define PCM_OBJECT_DIR "@PCM_OBJECT_DIR@"
 #define GBE_OBJECT_DIR "@GBE_OBJECT_DIR@"
 #define INTERP_OBJECT_DIR "@INTERP_OBJECT_DIR@"
+#define OCL_BITCODE_BIN "@OCL_BITCODE_BIN@"
+#define OCL_HEADER_DIR "@OCL_HEADER_DIR@"
diff --git a/backend/src/libocl/Makefile.in b/backend/src/libocl/Makefile.in
new file mode 100644
index 0000000..628d6c0
--- /dev/null
+++ b/backend/src/libocl/Makefile.in
@@ -0,0 +1,39 @@
+.PHONY: all install clean
+
+HEADER_INSTALL_PREFIX=@OCL_HEADER_DIR@
+BITCODE_INSTALL_PREFIX=@OCL_BITCODE_DIR@
+
+GENERATED_FILES=
+GENERATED_HEADERS=ocl_defines.h
+GENERATED_CL_SRCS=$(addprefix lib/, $(GENERATED_FILES))
+GENERATED_CL_HEADERS=$(addprefix include/, $(GENERATED_HEADERS))
+CL_FILE_NAMES= $(GENERATED_FILES)
+LL_FILE_NAMES=
+CL_SRCS=$(addprefix lib/, $(CL_FILE_NAMES))
+LL_SRCS=$(addprefix lib/, $(LL_FILE_NAMES))
+CL_BITCODES=$(patsubst %.cl, %.bc, $(CL_SRCS))
+LL_BITCODES=$(patsubst %.ll, %.bc, $(LL_SRCS))
+CL_DEPENDS=$(patsubst %.cl, %.d, $(CL_SRCS))
+
+CLANG_OCL_FLAGS=-I./include -fno-builtin -Dcl_khr_fp64 -ffp-contract=off
+
+all:$(GENERATED_CL_HEADERS) $(GENERATED_CL_SRCS) lib/beignet.bc
+
+lib/beignet.bc:$(GENERATED_CL_HEADERS) $(GENERATED_CL_SRCS) $(CL_BITCODES) $(LL_BITCODES)
+	touch $@
+
+include/ocl_defines.h:include/ocl_defines.inh
+	@echo "Generate the header:  $@"
+	@rm -f $@
+	@cat $< > $@
+	@cat ../ocl_common_defines.h >> $@
+
+install:all
+	mkdir -p $(HEADER_INSTALL_PREFIX)
+	mkdir -p $(BITCODE_INSTALL_PREFIX)
+	cp lib/beignet.bc $(BITCODE_INSTALL_PREFIX)
+	cp include/*.h $(HEADER_INSTALL_PREFIX)
+
+
+clean:
+	rm -fr lib/beignet.bc
diff --git a/backend/src/libocl/include/ocl.h b/backend/src/libocl/include/ocl.h
new file mode 100644
index 0000000..ef8b40a
--- /dev/null
+++ b/backend/src/libocl/include/ocl.h
@@ -0,0 +1,7 @@
+#ifndef __OCL_H__
+#define __OCL_H__
+
+//#include "ocl_defines.h"
+//#include "ocl_types.h"
+
+#endif
diff --git a/backend/src/libocl/include/ocl_defines.inh b/backend/src/libocl/include/ocl_defines.inh
new file mode 100644
index 0000000..a03e9cc
--- /dev/null
+++ b/backend/src/libocl/include/ocl_defines.inh
@@ -0,0 +1,23 @@
+#ifndef __OCL_COMMON_DEF_H__
+#define __OCL_COMMON_DEF_H__
+
+#define __OPENCL_VERSION__ 110
+#define __CL_VERSION_1_0__ 100
+#define __CL_VERSION_1_1__ 110
+#define __ENDIAN_LITTLE__ 1
+#define __IMAGE_SUPPORT__ 1
+#define __kernel_exec(X, TYPE) __kernel __attribute__((work_group_size_hint(X,1,1))) \
+                                        __attribute__((vec_type_hint(TYPE)))
+#define kernel_exec(X, TYPE) __kernel_exec(X, TYPE)
+#define cl_khr_global_int32_base_atomics
+#define cl_khr_global_int32_extended_atomics
+#define cl_khr_local_int32_base_atomics
+#define cl_khr_local_int32_extended_atomics
+#define cl_khr_byte_addressable_store
+#define cl_khr_icd
+#define cl_khr_gl_sharing
+
+#endif /* end of __OCL_COMMON_DEF_H__ */
+
+
+
diff --git a/backend/src/libocl/include/ocl_types.h b/backend/src/libocl/include/ocl_types.h
new file mode 100644
index 0000000..05a2dae
--- /dev/null
+++ b/backend/src/libocl/include/ocl_types.h
@@ -0,0 +1,104 @@
+#ifndef __OCL_TYPES_H__
+#define __OCL_TYPES_H__
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#endif
+
+#include "ocl_defines.h"
+
+#define NULL ((void*)0)
+
+/////////////////////////////////////////////////////////////////////////////
+// OpenCL Common Defines
+/////////////////////////////////////////////////////////////////////////////
+#define INLINE inline __attribute__((always_inline))
+#define OVERLOADABLE __attribute__((overloadable))
+#define PURE __attribute__((pure))
+#define CONST __attribute__((const))
+#define INLINE_OVERLOADABLE inline __attribute__((overloadable,always_inline))
+// FIXME, clang's opencl FE doesn't support static.
+#define static
+
+/////////////////////////////////////////////////////////////////////////////
+// OpenCL built-in scalar data types
+/////////////////////////////////////////////////////////////////////////////
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+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;
+
+/////////////////////////////////////////////////////////////////////////////
+// OpenCL address space
+/////////////////////////////////////////////////////////////////////////////
+// These are built-ins in LLVM 3.3.
+#if 100*__clang_major__ + __clang_minor__ <= 302
+#define __private __attribute__((address_space(0)))
+#define __global __attribute__((address_space(1)))
+#define __constant __attribute__((address_space(2)))
+#define __local __attribute__((address_space(3)))
+#define global __global
+#define local __local
+#define constant __constant
+#define private __private
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// OpenCL built-in vector data types
+/////////////////////////////////////////////////////////////////////////////
+#define DEF(type) typedef type type##2 __attribute__((ext_vector_type(2)));\
+                  typedef type type##3 __attribute__((ext_vector_type(3)));\
+                  typedef type type##4 __attribute__((ext_vector_type(4)));\
+                  typedef type type##8 __attribute__((ext_vector_type(8)));\
+                  typedef type type##16 __attribute__((ext_vector_type(16)));
+DEF(char);
+DEF(uchar);
+DEF(short);
+DEF(ushort);
+DEF(int);
+DEF(uint);
+DEF(long);
+DEF(ulong);
+DEF(float);
+DEF(double);
+#undef DEF
+
+/////////////////////////////////////////////////////////////////////////////
+// OpenCL built-in image types
+/////////////////////////////////////////////////////////////////////////////
+// FIXME:
+// This is a transitional hack to bypass the LLVM 3.3 built-in types.
+// See the Khronos SPIR specification for handling of these types.
+#define __texture __attribute__((address_space(4)))
+struct _image1d_t;
+typedef __texture struct _image1d_t* __image1d_t;
+struct _image1d_buffer_t;
+typedef __texture struct _image1d_buffer_t* __image1d_buffer_t;
+struct _image1d_array_t;
+typedef __texture struct _image1d_array_t* __image1d_array_t;
+struct _image2d_t;
+typedef __texture struct _image2d_t* __image2d_t;
+struct _image2d_array_t;
+typedef __texture struct _image2d_array_t* __image2d_array_t;
+struct _image3d_t;
+typedef __texture struct _image3d_t* __image3d_t;
+typedef const ushort __sampler_t;
+#define image1d_t __image1d_t
+#define image1d_buffer_t __image1d_buffer_t
+#define image1d_array_t __image1d_array_t
+#define image2d_t __image2d_t
+#define image2d_array_t __image2d_array_t
+#define image3d_t __image3d_t
+#define sampler_t __sampler_t
+
+/////////////////////////////////////////////////////////////////////////////
+// OpenCL built-in event types
+/////////////////////////////////////////////////////////////////////////////
+typedef size_t __event_t;
+#define event_t __event_t
+
+#endif /* __OCL_TYPES_H__ */
diff --git a/backend/src/libocl/lib/beignet.bc b/backend/src/libocl/lib/beignet.bc
new file mode 100644
index 0000000..e69de29
-- 
1.8.3.2



More information about the Beignet mailing list