diff options
author | Junyan He <junyan.he@intel.com> | 2017-06-11 13:50:39 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2017-08-02 17:16:30 +0800 |
commit | 66b91b77b94e1fe9764d0d5342d60742a4c1bcb4 (patch) | |
tree | 0f509efd0a20791c35d31632b6b5fe079745d427 | |
parent | 036a327918c76a9431c3e81f2706286a5d0b3f28 (diff) | |
download | beignet-66b91b77b94e1fe9764d0d5342d60742a4c1bcb4.tar.gz |
Add cl_compiler_gen to use compiler backend.
cl_compiler_gen can find the compiler backend and load it
using dlopen function.
Signed-off-by: Junyan He <junyan.he@intel.com>
-rw-r--r-- | runtime/gen/cl_compiler_gen.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/runtime/gen/cl_compiler_gen.c b/runtime/gen/cl_compiler_gen.c new file mode 100644 index 00000000..00b29c00 --- /dev/null +++ b/runtime/gen/cl_compiler_gen.c @@ -0,0 +1,94 @@ +/* + * 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.he@intel.com> + */ + +#include "cl_gen.h" +#include <dlfcn.h> + +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; + + if (device->compiler.available == CL_TRUE) + return CL_SUCCESS; + + gbePath = getenv("OCL_GBE_PATH"); + if (gbePath == NULL || !strcmp(gbePath, "")) + gbePath = COMPILER_BACKEND_OBJECT; + + 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_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; +} |