[Beignet] [PATCH 10/57] Add compiler API to runtime.
junyan.he at inbox.com
junyan.he at inbox.com
Sun Jun 11 05:49:56 UTC 2017
From: Junyan He <junyan.he at intel.com>
The cl_compiler define common APIs for backend compiler.
The OpencL build, compile and link API will call these
APIs to generate the binary.
This is also useful when wen need to unload the compiler.
Signed-off-by: Junyan He <junyan.he at intel.com>
---
runtime/cl_compiler.c | 39 +++++++++++++++++++++++++++++++++++++++
runtime/cl_compiler.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+)
create mode 100644 runtime/cl_compiler.c
create mode 100644 runtime/cl_compiler.h
diff --git a/runtime/cl_compiler.c b/runtime/cl_compiler.c
new file mode 100644
index 0000000..cc7860a
--- /dev/null
+++ b/runtime/cl_compiler.c
@@ -0,0 +1,39 @@
+/*
+ * 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_compiler.h"
+#include "cl_device_id.h"
+
+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 device->api.compiler_unload(device);
+}
diff --git a/runtime/cl_compiler.h b/runtime/cl_compiler.h
new file mode 100644
index 0000000..8e93ce7
--- /dev/null
+++ b/runtime/cl_compiler.h
@@ -0,0 +1,47 @@
+/*
+ * 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>
+ */
+#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,
+ size_t *header_lengths, 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(cl_device_id device);
+
+#endif /* End of __CL_COMPILER_H__ */
--
2.7.4
More information about the Beignet
mailing list