[Beignet] [PATCH 57/57 V2] Modify CMakeList.txt to enable new runtime.

junyan.he at inbox.com junyan.he at inbox.com
Fri Jun 23 10:09:13 UTC 2017


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

We default set NEW_RUNTIME option off. And can enable it be set
-DNEW_RUNTIME=1

V2:
  Fix build error for internal kernel.

Signed-off-by: Junyan He <junyan.he at intel.com>
Signed-off-by: Ruiling Song <ruiling.song at intel.com>

---
 CMakeLists.txt             |  16 +++++-
 backend/CMakeLists.txt     |   1 +
 backend/src/CMakeLists.txt |   1 +
 runtime/CMakeLists.txt     |  74 +++++++++++++++++++++++++++
 runtime/OCLConfig.h.in     |   5 ++
 runtime/gen/CMakeLists.txt | 124 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 220 insertions(+), 1 deletion(-)
 create mode 100644 runtime/CMakeLists.txt
 create mode 100644 runtime/OCLConfig.h.in
 create mode 100644 runtime/gen/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7e01688..2cbd9ac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -176,6 +176,14 @@ ENDIF(INVOKE_CMRT)
 # Threads
 Find_Package(Threads)
 
+pkg_check_modules(ELF_LIB REQUIRED libelf)
+IF(ELF_LIB_FOUND)
+	MESSAGE(STATUS "Looking for libelf - found at ${ELF_LIB_PREFIX} ${ELF_LIB_VERSION}")
+	INCLUDE_DIRECTORIES(${ELF_LIB_INCLUDE_DIRS})
+ELSE(ELF_LIB_FOUND)
+	MESSAGE(STATUS "Looking for libelf - not found")
+ENDIF(ELF_LIB_FOUND)
+
 IF(X11_FOUND)
 # Xext
 pkg_check_modules(XEXT REQUIRED xext)
@@ -328,9 +336,15 @@ ENDIF(BUILD_EXAMPLES)
 
 ADD_SUBDIRECTORY(include)
 ADD_SUBDIRECTORY(backend)
-ADD_SUBDIRECTORY(src)
 ADD_SUBDIRECTORY(utests EXCLUDE_FROM_ALL)
 
+OPTION(NEW_RUNTIME "New runtime implementation for OpenCL" OFF)
+IF(NEW_RUNTIME)
+ADD_SUBDIRECTORY(runtime)
+ELSE(NEW_RUNTIME)
+ADD_SUBDIRECTORY(src)
+ENDIF(NEW_RUNTIME)
+
 # compile benchmark only if standalone compiler is not provided
 IF (NOT (USE_STANDALONE_GBE_COMPILER STREQUAL "true"))
   ADD_SUBDIRECTORY(benchmark EXCLUDE_FROM_ALL)
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index d2d8710..dee36ad 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -50,6 +50,7 @@ set(LOCAL_GBE_OBJECT_DIR ${LOCAL_GBE_OBJECT_DIR} PARENT_SCOPE)
 set(LOCAL_INTERP_OBJECT_DIR ${LOCAL_INTERP_OBJECT_DIR} PARENT_SCOPE)
 set(LOCAL_OCL_BITCODE_BIN_20 "${LOCAL_OCL_BITCODE_BIN_20}" PARENT_SCOPE)
 set(LOCAL_OCL_PCH_OBJECT_20 "${LOCAL_OCL_PCH_OBJECT_20}" PARENT_SCOPE)
+set(GBE_OBJECT_FULL_PATH ${GBE_OBJECT_FULL_PATH} PARENT_SCOPE)
 
 set (GBE_BIN_GENERATER
      env OCL_BITCODE_LIB_PATH=${LOCAL_OCL_BITCODE_BIN} OCL_HEADER_FILE_DIR=${LOCAL_OCL_HEADER_DIR} OCL_PCH_PATH=${LOCAL_OCL_PCH_OBJECT}
diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt
index cccf8a8..c44d29a 100644
--- a/backend/src/CMakeLists.txt
+++ b/backend/src/CMakeLists.txt
@@ -27,6 +27,7 @@ if (ENABLE_OPENCL_20)
 set (LOCAL_OCL_BITCODE_BIN_20 "${OCL_OBJECT_DIR}/beignet_20.bc" PARENT_SCOPE)
 set (LOCAL_OCL_PCH_OBJECT_20 "${OCL_OBJECT_DIR}/beignet_20.local.pch" PARENT_SCOPE)
 endif (ENABLE_OPENCL_20)
+set (GBE_OBJECT_FULL_PATH "${GBE_OBJECT_DIR}" PARENT_SCOPE)
 
 set (GBE_SRC
     ${ocl_blob_file}
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
new file mode 100644
index 0000000..b0bd721
--- /dev/null
+++ b/runtime/CMakeLists.txt
@@ -0,0 +1,74 @@
+configure_file("OCLConfig.h.in" "OCLConfig.h")
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+	${CMAKE_CURRENT_BINARY_DIR}
+	${DRM_INCLUDE_DIRS}
+	${CMAKE_CURRENT_SOURCE_DIR}/../include
+	)
+
+set(OPENCL_SRC
+	cl_alloc.c
+	cl_api_command_queue.c
+	cl_api_context.c
+	cl_api_device_id.c
+	cl_api_event.c
+	cl_api_kernel.c
+	cl_api_mem.c
+	cl_api_platform_id.c
+	cl_api_program.c
+	cl_api_sampler.c
+	cl_base_object.c
+	cl_command_queue.c
+	cl_compiler.c
+	cl_context.c
+	cl_device_id.c
+	cl_enqueue.c
+	cl_event.c
+	cl_extensions.c
+	cl_image.c
+	cl_kernel.c
+	cl_mem.c
+	cl_platform_id.c
+	cl_program.c
+	cl_sampler.c
+	cl_utils.c
+	)
+
+if (OCLIcd_FOUND)
+	set(OPENCL_SRC ${OPENCL_SRC} cl_khr_icd.c)
+	SET(CMAKE_CXX_FLAGS "-DHAS_OCLIcd ${CMAKE_CXX_FLAGS}")
+	SET(CMAKE_C_FLAGS "-DHAS_OCLIcd ${CMAKE_C_FLAGS}")
+endif (OCLIcd_FOUND)
+
+set(GIT_SHA1 "git_sha1.h")
+add_custom_target(${GIT_SHA1} ALL
+	COMMAND chmod +x ${CMAKE_CURRENT_SOURCE_DIR}/git_sha1.sh
+	COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/git_sha1.sh ${CMAKE_CURRENT_SOURCE_DIR} ${GIT_SHA1}
+	)
+
+SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic,--allow-shlib-undefined")
+
+add_subdirectory(gen)
+
+add_library(cl SHARED ${OPENCL_SRC})
+ADD_DEPENDENCIES(cl ${GIT_SHA1})
+
+link_directories(${LLVM_LIBRARY_DIR} ${DRM_LIBDIR} ${OPENGL_LIBDIR} ${EGL_LIBDIR})
+
+target_link_libraries(
+	cl
+	rt
+	cl_gen
+	m
+	${X11_LIBRARIES}
+	${ELF_LIB_LIBRARIES}
+	${XEXT_LIBRARIES}
+	${XFIXES_LIBRARIES}
+	${DRM_INTEL_LIBRARIES}
+	${ELF_LIB_LIBRARIES}
+	${DRM_LIBRARIES}
+	${CMAKE_THREAD_LIBS_INIT}
+	${CMAKE_DL_LIBS}
+	${OPENGL_LIBRARIES}
+	${EGL_LIBRARIES})
+install (TARGETS cl LIBRARY DESTINATION ${BEIGNET_INSTALL_DIR})
diff --git a/runtime/OCLConfig.h.in b/runtime/OCLConfig.h.in
new file mode 100644
index 0000000..8662584
--- /dev/null
+++ b/runtime/OCLConfig.h.in
@@ -0,0 +1,5 @@
+// the configured options and settings for LIBCL
+#define LIBCL_DRIVER_VERSION_MAJOR @LIBCL_DRIVER_VERSION_MAJOR@
+#define LIBCL_DRIVER_VERSION_MINOR @LIBCL_DRIVER_VERSION_MINOR@
+#define LIBCL_C_VERSION_MAJOR @LIBCL_C_VERSION_MAJOR@
+#define LIBCL_C_VERSION_MINOR @LIBCL_C_VERSION_MINOR@
diff --git a/runtime/gen/CMakeLists.txt b/runtime/gen/CMakeLists.txt
new file mode 100644
index 0000000..83ed0c6
--- /dev/null
+++ b/runtime/gen/CMakeLists.txt
@@ -0,0 +1,124 @@
+ADD_EXECUTABLE(gen_bin_generater kernels/gen_bin_generater.c)
+ADD_DEPENDENCIES(gen_bin_generater gbe)
+set_target_properties(gen_bin_generater PROPERTIES COMPILE_DEFINITIONS COMPILER_BACKEND_OBJECT="${LOCAL_GBE_OBJECT_DIR}")
+TARGET_LINK_LIBRARIES(gen_bin_generater dl ${ELF_LIB_LIBRARIES})
+set(GEN_BIN_GENERATER
+	env OCL_BITCODE_LIB_PATH=${LOCAL_OCL_BITCODE_BIN} OCL_HEADER_FILE_DIR=${LOCAL_OCL_HEADER_DIR} OCL_PCH_PATH=${LOCAL_OCL_PCH_OBJECT}
+	OCL_BITCODE_LIB_20_PATH=${LOCAL_OCL_BITCODE_BIN_20} OCL_PCH_20_PATH=${LOCAL_OCL_PCH_OBJECT_20})
+set(GEN_BIN_GENERATER ${GEN_BIN_GENERATER} ${CMAKE_CURRENT_BINARY_DIR}/gen_bin_generater)
+
+macro (MakeKernelBinStr KERNEL_DIST KERNEL_SOURCE KERNEL_FILES)
+	foreach (KF ${KERNEL_FILES})
+		set (input_file ${KERNEL_SOURCE}/${KF}.cl)
+		set (output_file ${KERNEL_DIST}/${KF}_str.c)
+		list (APPEND KERNEL_STR_FILES ${output_file})
+		if(GEN_PCI_ID)
+			add_custom_command(
+				OUTPUT ${output_file}
+				COMMAND rm -rf ${output_file}
+				COMMAND ${GEN_BIN_GENERATER} -o${output_file} -p${GEN_PCI_ID} -i${input_file}
+				DEPENDS ${input_file})
+		else(GEN_PCI_ID)
+			add_custom_command(
+				OUTPUT ${output_file}
+				COMMAND rm -rf ${output_file}
+				COMMAND ${GEN_BIN_GENERATER} -o${output_file} -i${input_file}
+				DEPENDS ${input_file})
+		endif(GEN_PCI_ID)
+	endforeach (KF)
+endmacro (MakeKernelBinStr)
+
+macro (MakeBuiltInKernelStr KERNEL_PATH KERNEL_FILES)
+	set (output_file ${KERNEL_PATH}/${BUILT_IN_NAME}.cl)
+	set (file_content)
+	file (REMOVE ${output_file})
+	foreach (KF ${KERNEL_NAMES})
+		set (input_file ${CMAKE_CURRENT_SOURCE_DIR}/kernels/${KF}.cl)
+		file(READ ${input_file} file_content )
+		STRING(REGEX REPLACE ";" "\\\\;" file_content "${file_content}")
+		file(APPEND ${output_file} ${file_content})
+	endforeach (KF)
+endmacro (MakeBuiltInKernelStr)
+
+set (KERNEL_STR_FILES)
+set (KERNEL_NAMES cl_internal_copy_buf_align4
+	cl_internal_copy_buf_align16 cl_internal_copy_buf_unalign_same_offset
+	cl_internal_copy_buf_unalign_dst_offset cl_internal_copy_buf_unalign_src_offset
+	cl_internal_copy_buf_rect cl_internal_copy_buf_rect_align4
+	cl_internal_copy_image_1d_to_1d cl_internal_copy_image_2d_to_2d
+	cl_internal_copy_image_3d_to_2d cl_internal_copy_image_2d_to_3d cl_internal_copy_image_3d_to_3d
+	cl_internal_copy_image_2d_to_2d_array cl_internal_copy_image_1d_array_to_1d_array
+	cl_internal_copy_image_2d_array_to_2d_array cl_internal_copy_image_2d_array_to_2d
+	cl_internal_copy_image_2d_array_to_3d cl_internal_copy_image_3d_to_2d_array
+	cl_internal_copy_image_2d_to_buffer cl_internal_copy_image_2d_to_buffer_align16 cl_internal_copy_image_3d_to_buffer
+	cl_internal_copy_buffer_to_image_2d cl_internal_copy_buffer_to_image_2d_align16 cl_internal_copy_buffer_to_image_3d
+	cl_internal_fill_buf_align8 cl_internal_fill_buf_align4
+	cl_internal_fill_buf_align2 cl_internal_fill_buf_unalign
+	cl_internal_fill_buf_align128 cl_internal_fill_image_1d
+	cl_internal_fill_image_1d_array cl_internal_fill_image_2d
+	cl_internal_fill_image_2d_array cl_internal_fill_image_3d
+	cl_internal_block_motion_estimate_intel)
+set(BUILT_IN_NAME  cl_internal_built_in_kernel)
+MakeBuiltInKernelStr ("${CMAKE_CURRENT_BINARY_DIR}/kernels/" "${KERNEL_NAMES}")
+MakeKernelBinStr ("${CMAKE_CURRENT_BINARY_DIR}/kernels/" "${CMAKE_CURRENT_SOURCE_DIR}/kernels/" "${KERNEL_NAMES}")
+MakeKernelBinStr ("${CMAKE_CURRENT_BINARY_DIR}/kernels/" "${CMAKE_CURRENT_BINARY_DIR}/kernels/" "${BUILT_IN_NAME}")
+
+
+set(OPENCL_GEN_SRC
+	${KERNEL_STR_FILES}
+	intel_batchbuffer.c
+	intel_driver.c
+	cl_device_id_gen.c
+	cl_kernel_gen.c
+	cl_program_gen.c
+	cl_context_gen.c
+	cl_command_queue_gen.c
+	cl_mem_gen.c
+	cl_image_gen.c
+	cl_compiler_gen.c
+	cl_event_gen.c
+	cl_sampler_gen.c
+	)
+
+if (X11_FOUND)
+	set(CMAKE_CXX_FLAGS "-DHAS_X11 ${CMAKE_CXX_FLAGS}")
+	set(CMAKE_C_FLAGS "-DHAS_X11 ${CMAKE_C_FLAGS}")
+	set(OPENCL_GEN_SRC
+		${OPENCL_GEN_SRC}
+		x11/dricommon.c
+		x11/va_dri2.c)
+endif (X11_FOUND)
+
+if (HAVE_DRM_INTEL_USERPTR)
+	SET(CMAKE_CXX_FLAGS "-DHAS_USERPTR ${CMAKE_CXX_FLAGS}")
+	SET(CMAKE_C_FLAGS "-DHAS_USERPTR ${CMAKE_C_FLAGS}")
+endif (HAVE_DRM_INTEL_USERPTR)
+
+if (HAVE_DRM_INTEL_EU_TOTAL)
+	SET(CMAKE_CXX_FLAGS "-DHAS_EU_TOTAL ${CMAKE_CXX_FLAGS}")
+	SET(CMAKE_C_FLAGS "-DHAS_EU_TOTAL ${CMAKE_C_FLAGS}")
+endif (HAVE_DRM_INTEL_EU_TOTAL)
+
+if (HAVE_DRM_INTEL_SUBSLICE_TOTAL)
+	SET(CMAKE_CXX_FLAGS "-DHAS_SUBSLICE_TOTAL ${CMAKE_CXX_FLAGS}")
+	SET(CMAKE_C_FLAGS "-DHAS_SUBSLICE_TOTAL ${CMAKE_C_FLAGS}")
+endif (HAVE_DRM_INTEL_SUBSLICE_TOTAL)
+
+if (HAVE_DRM_INTEL_POOLED_EU)
+	SET(CMAKE_CXX_FLAGS "-DHAS_POOLED_EU ${CMAKE_CXX_FLAGS}")
+	SET(CMAKE_C_FLAGS "-DHAS_POOLED_EU ${CMAKE_C_FLAGS}")
+endif (HAVE_DRM_INTEL_POOLED_EU)
+
+if (HAVE_DRM_INTEL_MIN_EU_IN_POOL)
+	SET(CMAKE_CXX_FLAGS "-DHAS_MIN_EU_IN_POOL ${CMAKE_CXX_FLAGS}")
+	SET(CMAKE_C_FLAGS "-DHAS_MIN_EU_IN_POOL ${CMAKE_C_FLAGS}")
+endif (HAVE_DRM_INTEL_MIN_EU_IN_POOL)
+
+if (HAVE_DRM_INTEL_BO_SET_SOFTPIN)
+	SET(CMAKE_CXX_FLAGS "-DHAS_BO_SET_SOFTPIN ${CMAKE_CXX_FLAGS}")
+	SET(CMAKE_C_FLAGS "-DHAS_BO_SET_SOFTPIN ${CMAKE_C_FLAGS}")
+endif (HAVE_DRM_INTEL_BO_SET_SOFTPIN)
+
+add_library(cl_gen STATIC ${OPENCL_GEN_SRC})
+set_target_properties(cl_gen PROPERTIES COMPILE_DEFINITIONS COMPILER_BACKEND_OBJECT="${GBE_OBJECT_FULL_PATH}")
+ADD_DEPENDENCIES(cl_gen gen_bin_generater)
-- 
2.7.4



More information about the Beignet mailing list