From: Junyan He <junyan...@intel.com> This struct will play a important role to call the build/compile APIs provided by backend compiler. And can implement the unload compiler API of CL spec.
Signed-off-by: Junyan He <junyan...@intel.com> --- src/cl_compiler.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cl_compiler.h | 48 +++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 src/cl_compiler.c create mode 100644 src/cl_compiler.h diff --git a/src/cl_compiler.c b/src/cl_compiler.c new file mode 100644 index 0000000..d7eccb2 --- /dev/null +++ b/src/cl_compiler.c @@ -0,0 +1,114 @@ +/* + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + * Author: He Junyan <junyan...@intel.com> + */ + +#include "cl_compiler.h" +#include "cl_device_data.h" +#include "backend/src/GBEConfig.h" +#include "cl_device_id.h" + +#include <string.h> +#include <dlfcn.h> + +LOCAL cl_int +cl_compiler_unload_gen(cl_device_id device) +{ + assert(device->compiler.available); + assert(device->compiler.opaque); + + dlclose(device->compiler.opaque); + + device->compiler.available = CL_FALSE; + device->compiler.opaque = NULL; + device->compiler.compiler_name = NULL; + device->compiler.check_Compiler_option = NULL; + device->compiler.build_program = NULL; + device->compiler.compile_program = NULL; + device->compiler.link_program = NULL; + return CL_SUCCESS; +} + +LOCAL cl_int +cl_compiler_load_gen(cl_device_id device) +{ + const char *gbePath = NULL; + void *dlhCompiler = NULL; + void *genBuildProgram = NULL; + void *genLinkProgram = NULL; + void *genCompileProgram = NULL; + void *genCheckCompilerOption = NULL; + + gbePath = getenv("OCL_GBE_PATH"); + if (gbePath == NULL || !strcmp(gbePath, "")) + gbePath = GBE_OBJECT_DIR; + + dlhCompiler = dlopen(gbePath, RTLD_LAZY | RTLD_LOCAL); + if (dlhCompiler == NULL) + return CL_COMPILER_NOT_AVAILABLE; + + genBuildProgram = dlsym(dlhCompiler, "GenBuildProgram"); + if (genBuildProgram == NULL) { + dlclose(dlhCompiler); + return CL_COMPILER_NOT_AVAILABLE; + } + + genCompileProgram = dlsym(dlhCompiler, "GenCompileProgram"); + if (genCompileProgram == NULL) { + dlclose(dlhCompiler); + return CL_COMPILER_NOT_AVAILABLE; + } + + genLinkProgram = dlsym(dlhCompiler, "GenLinkProgram"); + if (genLinkProgram == NULL) { + dlclose(dlhCompiler); + return CL_COMPILER_NOT_AVAILABLE; + } + + genCheckCompilerOption = dlsym(dlhCompiler, "GenCheckCompilerOption"); + if (genCheckCompilerOption == NULL) { + dlclose(dlhCompiler); + return CL_COMPILER_NOT_AVAILABLE; + } + + device->compiler.opaque = dlhCompiler; + device->compiler.available = CL_TRUE; + device->compiler.compiler_name = "libgbe.so"; + device->compiler.check_Compiler_option = genCheckCompilerOption; + device->compiler.build_program = genBuildProgram; + device->compiler.compile_program = genCompileProgram; + device->compiler.link_program = genLinkProgram; + return CL_SUCCESS; +} + +LOCAL cl_int +cl_compiler_check_available(cl_device_id device) +{ + if (device->compiler.available) + return CL_SUCCESS; + + return CL_COMPILER_NOT_AVAILABLE; +} + +LOCAL cl_int +cl_compiler_unload(cl_device_id device) +{ + if (device->compiler.available == CL_FALSE) + return CL_SUCCESS; + + return cl_compiler_unload_gen(device); +} diff --git a/src/cl_compiler.h b/src/cl_compiler.h new file mode 100644 index 0000000..d7c5a97 --- /dev/null +++ b/src/cl_compiler.h @@ -0,0 +1,48 @@ +/* + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + * Author: He Junyan <junyan...@intel.com> + */ +#ifndef __CL_COMPILER_H__ +#define __CL_COMPILER_H__ + +#include "cl_utils.h" +#include "CL/cl.h" + +typedef struct _cl_compiler { + void *opaque; + cl_bool available; + char *compiler_name; + + cl_bool (*check_Compiler_option)(const char *option); + cl_bool (*build_program)(cl_uint device_id, const char *source, size_t src_length, + const char *options, size_t err_buf_size, char *err, + size_t *err_ret_size, char **binary, size_t *binary_size); + cl_bool (*compile_program)(cl_uint device_id, const char *source, size_t src_length, const char **headers, + const char **header_names, int header_num, const char *options, size_t err_buf_size, + char *err, size_t *err_ret_size, char **binary, size_t *binary_size); + cl_bool (*link_program)(cl_uint device_id, int binary_num, char **binaries, size_t *bin_sizes, + const char *options, size_t err_buf_size, char *err, size_t *err_ret_size, + char **ret_binary, size_t *ret_binary_size); +} _cl_compiler; +typedef _cl_compiler *cl_compiler; + +extern cl_int cl_compiler_check_available(cl_device_id device); +extern cl_int cl_compiler_unload_gen(cl_device_id device); +extern cl_int cl_compiler_load_gen(cl_device_id device); +extern cl_int cl_compiler_unload(cl_device_id device); + +#endif /* End of __CL_COMPILER_H__ */ -- 2.7.4 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/beignet