[Mesa-dev] [PATCH 3/3] clover: add clLinkProgramm (CL 1.2)

EdB edb+mesa at sigluy.net
Sat Jul 18 10:43:55 PDT 2015


---
 src/gallium/state_trackers/clover/api/program.cpp  | 35 ++++++++++++++++++++++
 src/gallium/state_trackers/clover/core/error.hpp   |  7 +++++
 src/gallium/state_trackers/clover/core/program.cpp |  4 +++
 src/gallium/state_trackers/clover/core/program.hpp |  1 +
 .../state_trackers/clover/llvm/invocation.cpp      |  2 +-
 5 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp
index 553bc83..7573933 100644
--- a/src/gallium/state_trackers/clover/api/program.cpp
+++ b/src/gallium/state_trackers/clover/api/program.cpp
@@ -238,6 +238,41 @@ clCompileProgram(cl_program d_prog, cl_uint num_devs,
    return e.get();
 }
 
+CLOVER_API cl_program
+clLinkProgram (cl_context d_ctx, cl_uint num_devs, const cl_device_id *d_devs,
+               const char *p_opts, cl_uint num_progs, const cl_program *d_progs,
+               void (*pfn_notify) (cl_program, void *), void *user_data,
+               cl_int *r_errcode) try {
+   auto &ctx = obj(d_ctx);
+   auto devs = (d_devs ? objs(d_devs, num_devs) :
+                ref_vector<device>(ctx.devices()));
+   auto opts = (p_opts ? p_opts : "");
+   auto progs = objs(d_progs, num_progs);
+
+   if ((!pfn_notify && user_data))
+         throw error(CL_INVALID_VALUE);
+
+   if (any_of([&](const device &dev) {
+            return !count(dev, ctx.devices());
+         }, objs<allow_empty_tag>(d_devs, num_devs)))
+      throw error(CL_INVALID_DEVICE);
+
+   auto prog = create<program>(ctx);
+   try {
+      prog().link(devs, opts, progs);
+      *r_errcode = CL_SUCCESS;
+   } catch (link_options_error &e) {
+      throw;
+   } catch (error &e) {
+      *r_errcode = CL_LINK_PROGRAM_FAILURE;
+   }
+
+   return ret_object(prog);
+} catch (error &e) {
+   ret_error(r_errcode, e);
+   return NULL;
+}
+
 CLOVER_API cl_int
 clUnloadCompiler() {
    return CL_SUCCESS;
diff --git a/src/gallium/state_trackers/clover/core/error.hpp b/src/gallium/state_trackers/clover/core/error.hpp
index 4ec619c..f6c55a3 100644
--- a/src/gallium/state_trackers/clover/core/error.hpp
+++ b/src/gallium/state_trackers/clover/core/error.hpp
@@ -79,6 +79,13 @@ namespace clover {
       }
    };
 
+   class link_options_error : public error {
+   public:
+      link_options_error(const std::string &what = "") :
+         error(CL_INVALID_LINKER_OPTIONS , what) {
+      }
+   };
+
    template<typename O>
    class invalid_object_error;
 
diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp
index 4aa2622..61fb603 100644
--- a/src/gallium/state_trackers/clover/core/program.cpp
+++ b/src/gallium/state_trackers/clover/core/program.cpp
@@ -24,6 +24,10 @@
 
 using namespace clover;
 
+program::program(clover::context &ctx) :
+   has_source(false), context(ctx), _kernel_ref_counter(0) {
+}
+
 program::program(clover::context &ctx, const std::string &source) :
    has_source(true), context(ctx), _source(source), _kernel_ref_counter(0) {
 }
diff --git a/src/gallium/state_trackers/clover/core/program.hpp b/src/gallium/state_trackers/clover/core/program.hpp
index 7d86018..c24ad83 100644
--- a/src/gallium/state_trackers/clover/core/program.hpp
+++ b/src/gallium/state_trackers/clover/core/program.hpp
@@ -37,6 +37,7 @@ namespace clover {
          evals, const std::vector<intrusive_ref<device>> &> device_range;
 
    public:
+      program(clover::context &ctx);
       program(clover::context &ctx,
               const std::string &source);
       program(clover::context &ctx,
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index d115f15..2bf7775 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -782,7 +782,7 @@ clover::link_program_llvm(const std::vector<module> &modules,
    clang::CompilerInstance c;
    if (!create_from_arg_llvm(c, target, options, s_log)) {
       r_log = log;
-      throw error(CL_INVALID_LINKER_OPTIONS);
+      throw link_options_error();
    }
 
    llvm::Module linked_mod("link", llvm_ctx);
-- 
2.5.0.rc2



More information about the mesa-dev mailing list