[Mesa-dev] [PATCH v2 1/2] clover: add CL_PROGRAM_BINARY_TYPE support (CL1.2)

Serge Martin edb+mesa at sigluy.net
Sat Oct 1 16:51:10 UTC 2016


CL_PROGRAM_BINARY_TYPE have been added to clGetProgramBuildInfo in CL1.2
---
 src/gallium/state_trackers/clover/api/program.cpp          |  5 +++++
 src/gallium/state_trackers/clover/core/module.cpp          |  1 +
 src/gallium/state_trackers/clover/core/module.hpp          |  5 +++++
 src/gallium/state_trackers/clover/llvm/codegen.hpp         |  3 +++
 src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp | 11 +++++++++--
 src/gallium/state_trackers/clover/llvm/codegen/common.cpp  |  2 +-
 src/gallium/state_trackers/clover/llvm/invocation.cpp      |  2 +-
 src/gallium/state_trackers/clover/tgsi/compiler.cpp        |  2 +-
 8 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp
index c3f9cb9..543eeb6 100644
--- a/src/gallium/state_trackers/clover/api/program.cpp
+++ b/src/gallium/state_trackers/clover/api/program.cpp
@@ -401,6 +401,11 @@ clGetProgramBuildInfo(cl_program d_prog, cl_device_id d_dev,
       buf.as_string() = prog.build(dev).log;
       break;
 
+   case CL_PROGRAM_BINARY_TYPE:
+      buf.as_scalar<cl_program_binary_type>() =
+                                          prog.build(dev).binary.binary_type;
+      break;
+
    default:
       throw error(CL_INVALID_VALUE);
    }
diff --git a/src/gallium/state_trackers/clover/core/module.cpp b/src/gallium/state_trackers/clover/core/module.cpp
index a6c5b98..cc24a2b 100644
--- a/src/gallium/state_trackers/clover/core/module.cpp
+++ b/src/gallium/state_trackers/clover/core/module.cpp
@@ -202,6 +202,7 @@ namespace {
       template<typename S, typename QT>
       static void
       proc(S &s, QT &x) {
+         _proc(s, x.binary_type);
          _proc(s, x.syms);
          _proc(s, x.secs);
       }
diff --git a/src/gallium/state_trackers/clover/core/module.hpp b/src/gallium/state_trackers/clover/core/module.hpp
index 5db0548..bcf2a29 100644
--- a/src/gallium/state_trackers/clover/core/module.hpp
+++ b/src/gallium/state_trackers/clover/core/module.hpp
@@ -114,10 +114,15 @@ namespace clover {
          std::vector<argument> args;
       };
 
+      module() : binary_type(0), syms(), secs() { }
+      module(size_t binary_type) :
+             binary_type(binary_type), syms(), secs() { }
+
       void serialize(std::ostream &os) const;
       static module deserialize(std::istream &is);
       size_t size() const;
 
+      size_t binary_type;
       std::vector<symbol> syms;
       std::vector<section> secs;
    };
diff --git a/src/gallium/state_trackers/clover/llvm/codegen.hpp b/src/gallium/state_trackers/clover/llvm/codegen.hpp
index e0e9901..49de79d 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen.hpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen.hpp
@@ -46,6 +46,9 @@ namespace clover {
       print_module_bitcode(const ::llvm::Module &mod);
 
       module
+      build_module_compiled(const ::llvm::Module &mod);
+
+      module
       build_module_library(const ::llvm::Module &mod);
 
       std::unique_ptr<::llvm::Module>
diff --git a/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
index 658cce9..c75514b 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
@@ -80,13 +80,20 @@ clover::llvm::print_module_bitcode(const ::llvm::Module &mod) {
 }
 
 module
-clover::llvm::build_module_library(const ::llvm::Module &mod) {
-   module m;
+clover::llvm::build_module_compiled(const ::llvm::Module &mod) {
+   module m(CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT);
    const auto code = emit_code(mod);
    m.secs.emplace_back(0, module::section::text, code.size(), code);
    return m;
 }
 
+module
+clover::llvm::build_module_library(const ::llvm::Module &mod) {
+   module m = build_module_compiled(mod);
+   m.binary_type = CL_PROGRAM_BINARY_TYPE_LIBRARY;
+   return m;
+}
+
 std::unique_ptr<::llvm::Module>
 clover::llvm::parse_module_library(const module &m, ::llvm::LLVMContext &ctx,
                                    std::string &r_log) {
diff --git a/src/gallium/state_trackers/clover/llvm/codegen/common.cpp b/src/gallium/state_trackers/clover/llvm/codegen/common.cpp
index 834b06a..bd7207f 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen/common.cpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen/common.cpp
@@ -195,7 +195,7 @@ clover::llvm::build_module_common(const Module &mod,
                                   const std::map<std::string,
                                                  unsigned> &offsets,
                                   const clang::CompilerInstance &c) {
-   module m;
+   module m(CL_PROGRAM_BINARY_TYPE_EXECUTABLE);
 
    for (const auto &name : map(std::mem_fn(&Function::getName),
                                get_kernels(mod))) {
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index b5e8b52..fe10b78 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -211,7 +211,7 @@ clover::llvm::compile_program(const std::string &source,
    if (has_flag(debug::llvm))
       debug::log(".ll", print_module_bitcode(*mod));
 
-   return build_module_library(*mod);
+   return build_module_compiled(*mod);
 }
 
 namespace {
diff --git a/src/gallium/state_trackers/clover/tgsi/compiler.cpp b/src/gallium/state_trackers/clover/tgsi/compiler.cpp
index 9bbd454..a4d0355 100644
--- a/src/gallium/state_trackers/clover/tgsi/compiler.cpp
+++ b/src/gallium/state_trackers/clover/tgsi/compiler.cpp
@@ -104,7 +104,7 @@ clover::tgsi::compile_program(const std::string &source, std::string &r_log) {
    }
 
    const char *body = &source[body_pos];
-   module m;
+   module m(CL_PROGRAM_BINARY_TYPE_EXECUTABLE);
 
    read_header({ source.begin(), source.begin() + body_pos }, m, r_log);
    read_body(body, m, r_log);
-- 
2.5.5



More information about the mesa-dev mailing list