[Beignet] [PATCH 2/2] Refine the method to find pch and pcm files.
Sun, Yi
yi.sun at intel.com
Mon Jan 13 01:07:15 PST 2014
Hi Zhigang,
It seems you miss adding file utests/setenv.sh.in?
I failed to build this commit with following error info:
CMake Error: File /home/OpenCL/beignet/utests/setenv.sh.in does not exist.
Thanks
--Sun, Yi
> -----Original Message-----
> From: beignet-bounces at lists.freedesktop.org
> [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of Zhigang Gong
> Sent: Thursday, January 9, 2014 6:15 PM
> To: beignet at lists.freedesktop.org
> Cc: junyan.he at linux.intel.com; Simon.Richter at hogyros.de; Gong, Zhigang
> Subject: [Beignet] [PATCH 2/2] Refine the method to find pch and pcm files.
>
> When compile user kernels, we need to find the precompiled header file and
> the precompiled module file. The previous implementation will find the build
> directory then find the system directory.
>
> This is not elegant when it is packaged to a distro. It doesn't need to search the
> build directory. So I change the default search path to the system directory only.
> And for the deveoper, I change the build script to set a proper environment
> variable and make the gbe bin generator and the utest could find the local pch
> files and pcm files firstly.
>
> The only change is now, after the build process. Before the user run the utests,
> it need to set up the environment firstly. Just invoke
>
> . utest/setenv.sh.
>
> Then everything should be the same as previous. This setenv.sh also set the
> OCL_KERNEL_PATH, so you don't need to set it manually now.
>
> This patch also update the document.
>
> Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
> ---
> backend/CMakeLists.txt | 6 ++++++
> backend/src/CMakeLists.txt | 8 ++++++--
> backend/src/GBEConfig.h.in | 2 +-
> backend/src/backend/program.cpp | 22 +++++++++++++---------
> docs/Beignet.mdwn | 20 ++++++++++++++++++--
> src/CMakeLists.txt | 3 +--
> utests/CMakeLists.txt | 11 ++++++++---
> utests/utest.cpp | 2 --
> 8 files changed, 53 insertions(+), 21 deletions(-)
>
> diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index
> 476c6f2..dd55a4a 100644
> --- a/backend/CMakeLists.txt
> +++ b/backend/CMakeLists.txt
> @@ -91,9 +91,15 @@ elseif (COMPILER STREQUAL "ICC")
> set (CCMAKE_CXX_FLAGS_MINSIZEREL "-Os -DGBE_DEBUG=0")
> set (CMAKE_EXE_LINKER_FLAGS "")
> endif ()
> +
> include_directories (${CMAKE_CURRENT_BINARY_DIR})
> ##############################################################
> # Project source code
> ##############################################################
> 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
> +(GBE_BIN_GENERATER
> + OCL_PCM_PATH=${LOCAL_PCM_OBJECT_DIR}
> OCL_PCH_PATH=${LOCAL_PCH_OBJECT_DIR}
> ${CMAKE_CURRENT_BINARY_DIR}/src/gbe_bin_generater
> + PARENT_SCOPE)
>
> diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt index
> d19cb50..d15e7b7 100644
> --- a/backend/src/CMakeLists.txt
> +++ b/backend/src/CMakeLists.txt
> @@ -195,9 +195,13 @@ TARGET_LINK_LIBRARIES(gbe_bin_generater gbe)
> install (FILES ${ocl_blob_file} DESTINATION lib/beignet) install (FILES
> ${pch_object} DESTINATION lib/beignet) install (FILES
> ${CMAKE_CURRENT_BINARY_DIR}/${pcm_lib} DESTINATION lib/beignet)
> +# 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_path}/ocl_stdlib.h.pch"
> +PARENT_SCOPE) set (LOCAL_PCM_OBJECT_DIR
> +"${CMAKE_CURRENT_BINARY_DIR}/${pcm_lib}:${beignet_install_path}/${pc
> m_l
> +ib}" PARENT_SCOPE)
>
> -set (PCH_OBJECT_DIR
> "${local_pch_object};${beignet_install_path}/ocl_stdlib.h.pch")
> -set (PCM_LIB_DIR
> "${CMAKE_CURRENT_BINARY_DIR}/${pcm_lib};${beignet_install_path}/${pcm
> _lib}")
> +set (PCH_OBJECT_DIR "${beignet_install_path}/ocl_stdlib.h.pch")
> +set (PCM_OBJECT_DIR "${beignet_install_path}/${pcm_lib}")
> configure_file (
> "GBEConfig.h.in"
> "GBEConfig.h"
> diff --git a/backend/src/GBEConfig.h.in b/backend/src/GBEConfig.h.in index
> 9920d25..5bc09b8 100644
> --- a/backend/src/GBEConfig.h.in
> +++ b/backend/src/GBEConfig.h.in
> @@ -2,4 +2,4 @@
> #define LIBGBE_VERSION_MAJOR @LIBGBE_VERSION_MAJOR@ #define
> LIBGBE_VERSION_MINOR @LIBGBE_VERSION_MINOR@ #define
> PCH_OBJECT_DIR "@PCH_OBJECT_DIR@"
> -#define PCM_LIB_DIR "@PCM_LIB_DIR@"
> +#define PCM_OBJECT_DIR "@PCM_OBJECT_DIR@"
> diff --git a/backend/src/backend/program.cpp
> b/backend/src/backend/program.cpp index 3ab1bc2..284a755 100644
> --- a/backend/src/backend/program.cpp
> +++ b/backend/src/backend/program.cpp
> @@ -465,6 +465,9 @@ namespace gbe {
> }
>
> BVAR(OCL_OUTPUT_BUILD_LOG, false);
> + SVAR(OCL_PCH_PATH, PCH_OBJECT_DIR);
> + SVAR(OCL_PCM_PATH, PCM_OBJECT_DIR);
> +
> static bool buildModuleFromSource(const char* input, const char* output,
> std::string options,
> size_t stringSize, char *err,
> size_t *errSize) {
> // Arguments to pass to the clang frontend @@ -582,12 +585,13 @@
> namespace gbe {
> // Create an action and make the compiler instance carry it out
> llvm::OwningPtr<clang::CodeGenAction> Act(new
> clang::EmitLLVMOnlyAction());
>
> - std::string dirs = PCM_LIB_DIR, pcmLib;
> + std::string dirs = OCL_PCM_PATH;
> + std::string pcmFileName;
> std::istringstream idirs(dirs);
> bool findPcm = false;
>
> - while (getline(idirs, pcmLib, ';')) {
> - if(access(pcmLib.c_str(), R_OK) == 0) {
> + while (getline(idirs, pcmFileName, ':')) {
> + if(access(pcmFileName.c_str(), R_OK) == 0) {
> findPcm = true;
> break;
> }
> @@ -595,7 +599,7 @@ namespace gbe {
>
> GBE_ASSERT(findPcm && "Could not find pre compiled module
> library.\n");
>
> - Clang.getCodeGenOpts().LinkBitcodeFile = pcmLib;
> + Clang.getCodeGenOpts().LinkBitcodeFile = pcmFileName;
> auto retVal = Clang.ExecuteAction(*Act);
>
> if (err != NULL) {
> @@ -651,7 +655,6 @@ namespace gbe {
> char clStr[L_tmpnam+1], llStr[L_tmpnam+1];
> const std::string clName = std::string(tmpnam_r(clStr)) + ".cl"; /* unsafe!
> */
> const std::string llName = std::string(tmpnam_r(llStr)) + ".ll"; /* unsafe!
> */
> - std::string pchHeaderName;
> std::string clOpt;
> int optLevel = 1;
>
> @@ -730,11 +733,12 @@ namespace gbe {
> clOpt += options;
> }
>
> - std::string dirs = PCH_OBJECT_DIR;
> + std::string dirs = OCL_PCH_PATH;
> std::istringstream idirs(dirs);
> + std::string pchFileName;
>
> - while (getline(idirs, pchHeaderName, ';')) {
> - if(access(pchHeaderName.c_str(), R_OK) == 0) {
> + while (getline(idirs, pchFileName, ':')) {
> + if(access(pchFileName.c_str(), R_OK) == 0) {
> findPCH = true;
> break;
> }
> @@ -742,7 +746,7 @@ namespace gbe {
>
> if (usePCH && findPCH) {
> clOpt += " -include-pch ";
> - clOpt += pchHeaderName;
> + clOpt += pchFileName;
> clOpt += " ";
> } else
> fwrite(ocl_stdlib_str.c_str(), strlen(ocl_stdlib_str.c_str()), 1, clFile); diff
> --git a/docs/Beignet.mdwn b/docs/Beignet.mdwn index d05950f..e3b4b1b
> 100644
> --- a/docs/Beignet.mdwn
> +++ b/docs/Beignet.mdwn
> @@ -70,8 +70,10 @@ this code also produces various tests to ensure the
> compiler and the run-time consistency. This small test framework uses a
> simple c++ registration system to register all the unit tests.
>
> -You need to set the variable `OCL_KERNEL_PATH` to locate the OCL kernels.
> They -are with the run-time in `./kernels`.
> +You need to call setenv.sh in the utests/ directory to set some
> +environment variables firstly as below:
> +
> +`> . setenv.sh`
>
> Then in `utests/`:
>
> @@ -83,6 +85,20 @@ will run all the unit tests one after the others
>
> will only run `some_unit_test0` and `some_unit_test1` tests
>
> +How to install
> +--------------
> +
> +Simply invoke:
> +`> make install`
> +
> +It installs libcl.so and the precompiled header/module files and the
> +ocl_stdlib.h file into install_prefix/beignet/ direcotry. If the system
> +support ICD, it also installs the intel-beignet.icd to /etc/OpenCL/vendors/.
> +
> +To make beignet support ICD, you need to have the following two packages
> installed:
> +ocl-icd-dev, ocl-icd-libopencl1 (package name for the ubuntu.) before
> +your build beignet.
> +
> Supported Hardware
> ------------------
>
> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cf53a69..7d4d93d
> 100644
> --- a/src/CMakeLists.txt
> +++ b/src/CMakeLists.txt
> @@ -4,7 +4,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
>
> ${CMAKE_CURRENT_SOURCE_DIR}/../backend/src/backend/
> ${CMAKE_CURRENT_SOURCE_DIR}/../include
> ${MESA_SOURCE_INCLUDES})
> -
> macro (MakeKernelBinStr KERNEL_PATH KERNEL_FILES) foreach (KF
> ${KERNEL_FILES})
> set (input_file ${KERNEL_PATH}/${KF}.cl) @@ -13,7 +12,7 @@ foreach (KF
> ${KERNEL_FILES})
> add_custom_command(
> OUTPUT ${output_file}
> COMMAND rm -rf ${output_file}
> - COMMAND
> ${CMAKE_CURRENT_BINARY_DIR}/../backend/src/gbe_bin_generater -s
> ${input_file} -o${output_file}
> + COMMAND ${GBE_BIN_GENERATER} -s ${input_file} -o${output_file}
> DEPENDS ${input_file}
> ${CMAKE_CURRENT_BINARY_DIR}/../backend/src/gbe_bin_generater)
> endforeach (KF)
> endmacro (MakeKernelBinStr)
> diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt index
> b1f0b52..8c64844 100644
> --- a/utests/CMakeLists.txt
> +++ b/utests/CMakeLists.txt
> @@ -12,6 +12,11 @@ string(REGEX REPLACE "generated/([^\ ]*)\\.cpp"
> "${CMAKE_CURRENT_SOURCE_DIR}/../ string(REGEX REPLACE " " ";"
> KERNEL_MATH_LIST ${KERNEL_MATH_LIST})
> set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
> "generated;${KERNEL_MATH_LIST}")
>
> +configure_file (
> + "setenv.sh.in"
> + "setenv.sh"
> + )
> +
> link_directories (${LLVM_LIBRARY_DIR})
> set (utests_sources
> utest_error.c
> @@ -170,7 +175,7 @@ set (utests_sources
> SET (kernel_bin ${CMAKE_CURRENT_SOURCE_DIR}/../kernels/compiler_ceil)
> ADD_CUSTOM_COMMAND(
> OUTPUT ${kernel_bin}.bin
> - COMMAND
> ${CMAKE_CURRENT_BINARY_DIR}/../backend/src/gbe_bin_generater
> ${kernel_bin}.cl -o${kernel_bin}.bin
> + COMMAND ${GBE_BIN_GENERATER} ${kernel_bin}.cl -o${kernel_bin}.bin
> DEPENDS
> ${CMAKE_CURRENT_BINARY_DIR}/../backend/src/gbe_bin_generater
> ${kernel_bin}.cl
> )
>
> @@ -189,8 +194,8 @@ add_custom_target(utest_generator
>
> if (EGL_FOUND AND MESA_SOURCE_FOUND)
> SET(utests_sources ${utests_sources} compiler_fill_gl_image.cpp)
> -SET(CMAKE_CXX_FLAGS "-DHAS_EGL ${CMAKE_CXX_FLAGS}")
> -SET(CMAKE_C_FLAGS "-DHAS_EGL ${CMAKE_C_FLAGS}")
> +SET(CMAKE_CXX_FLAGS "-DHAS_EGL ${CMAKE_CXX_FLAGS}
> +${DEF_OCL_PCH_PCM_PATH}") SET(CMAKE_C_FLAGS "-DHAS_EGL
> ${CMAKE_C_FLAGS}
> +${DEF_OCL_PCH_PCM_PATH}")
> endif (EGL_FOUND AND MESA_SOURCE_FOUND)
>
> ADD_LIBRARY(utests SHARED ${ADDMATHFUNC} ${utests_sources}) diff --git
> a/utests/utest.cpp b/utests/utest.cpp index 6d51598..718916f 100644
> --- a/utests/utest.cpp
> +++ b/utests/utest.cpp
> @@ -41,8 +41,6 @@ UTest::UTest(Function fn, const char *name, bool
> haveIssue, bool needDestroyProg
> utestList->push_back(*this);
> }
>
> -UTest::UTest(void) : fn(NULL), name(NULL), haveIssue(false) {}
> -
> static bool strequal(const char *s1, const char *s2) {
> if (strcmp(s1, s2) == 0) return true;
> return false;
> --
> 1.7.9.5
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list