[Beignet] [PATCH] Move compiler load/unload logic to gen specific file.
junyan.he at inbox.com
junyan.he at inbox.com
Thu Mar 2 10:53:16 UTC 2017
From: Junyan He <junyan.he at intel.com>
Signed-off-by: Junyan He <junyan.he at intel.com>
---
src/cl_compiler.c | 77 +-------------------------------------
src/gen/cl_compiler_gen.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+), 76 deletions(-)
create mode 100644 src/gen/cl_compiler_gen.c
diff --git a/src/cl_compiler.c b/src/cl_compiler.c
index d7eccb2..cc7860a 100644
--- a/src/cl_compiler.c
+++ b/src/cl_compiler.c
@@ -18,83 +18,8 @@
*/
#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)
{
@@ -110,5 +35,5 @@ cl_compiler_unload(cl_device_id device)
if (device->compiler.available == CL_FALSE)
return CL_SUCCESS;
- return cl_compiler_unload_gen(device);
+ return device->api.compiler_unload(device);
}
diff --git a/src/gen/cl_compiler_gen.c b/src/gen/cl_compiler_gen.c
new file mode 100644
index 0000000..aaff512
--- /dev/null
+++ b/src/gen/cl_compiler_gen.c
@@ -0,0 +1,95 @@
+/*
+ * 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 at intel.com>
+ */
+
+#include "cl_gen.h"
+#include "backend/src/GBEConfig.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 = 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_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;
+}
--
2.7.4
More information about the Beignet
mailing list