[Mesa-dev] [PATCHv3 1/2] clover: Add CL_PROGRAM_BINARY_TYPE support (CL1.2).
Francisco Jerez
currojerez at riseup.net
Mon Oct 31 00:21:15 UTC 2016
From: Serge Martin <edb+mesa at sigluy.net>
v3 [Francisco Jerez]: Loosely based on Serge's v1 of this patch in
order to avoid CL-specific enums in the clover module binary
format. In addition to other changes made in v2: Represent the CL
program binary type as the section type instead of adding a CL
API-specific enum, check that the binary types of the input objects
are valid during clLinkProgram(), pass section type as argument to
build_module_library() instead of using separate function.
Reviewed-by: Francisco Jerez <currojerez at riseup.net>
---
src/gallium/state_trackers/clover/api/program.cpp | 8 +++++++-
src/gallium/state_trackers/clover/core/kernel.cpp | 2 +-
src/gallium/state_trackers/clover/core/module.hpp | 6 ++++--
src/gallium/state_trackers/clover/core/program.cpp | 12 ++++++++++++
src/gallium/state_trackers/clover/core/program.hpp | 1 +
src/gallium/state_trackers/clover/llvm/codegen.hpp | 3 ++-
src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp | 5 +++--
src/gallium/state_trackers/clover/llvm/codegen/common.cpp | 3 ++-
src/gallium/state_trackers/clover/llvm/invocation.cpp | 4 ++--
src/gallium/state_trackers/clover/tgsi/compiler.cpp | 2 +-
10 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp
index ba4ce7a..9d59668 100644
--- a/src/gallium/state_trackers/clover/api/program.cpp
+++ b/src/gallium/state_trackers/clover/api/program.cpp
@@ -248,7 +248,9 @@ namespace {
for (auto &dev : all_devs) {
const auto has_binary = [&](const program &prog) {
- return !prog.build(dev).binary.secs.empty();
+ const auto t = prog.build(dev).binary_type();
+ return t == CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT ||
+ t == CL_PROGRAM_BINARY_TYPE_LIBRARY;
};
// According to the CL 1.2 spec, when "all programs specified [..]
@@ -405,6 +407,10 @@ 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_type();
+ break;
+
default:
throw error(CL_INVALID_VALUE);
}
diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp
index 962f555..4716705 100644
--- a/src/gallium/state_trackers/clover/core/kernel.cpp
+++ b/src/gallium/state_trackers/clover/core/kernel.cpp
@@ -162,7 +162,7 @@ kernel::exec_context::bind(intrusive_ptr<command_queue> _q,
// Bind kernel arguments.
auto &m = kern.program().build(q->device()).binary;
auto margs = find(name_equals(kern.name()), m.syms).args;
- auto msec = find(type_equals(module::section::text), m.secs);
+ auto msec = find(type_equals(module::section::text_executable), m.secs);
auto explicit_arg = kern._args.begin();
for (auto &marg : margs) {
diff --git a/src/gallium/state_trackers/clover/core/module.hpp b/src/gallium/state_trackers/clover/core/module.hpp
index 5db0548..2ddd264 100644
--- a/src/gallium/state_trackers/clover/core/module.hpp
+++ b/src/gallium/state_trackers/clover/core/module.hpp
@@ -33,7 +33,9 @@ namespace clover {
struct section {
enum type {
- text,
+ text_intermediate,
+ text_library,
+ text_executable,
data_constant,
data_global,
data_local,
@@ -43,7 +45,7 @@ namespace clover {
section(resource_id id, enum type type, size_t size,
const std::vector<char> &data) :
id(id), type(type), size(size), data(data) { }
- section() : id(0), type(text), size(0), data() { }
+ section() : id(0), type(text_intermediate), size(0), data() { }
resource_id id;
type type;
diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp
index 79ac851..ae4b50a 100644
--- a/src/gallium/state_trackers/clover/core/program.cpp
+++ b/src/gallium/state_trackers/clover/core/program.cpp
@@ -108,6 +108,18 @@ program::build::status() const {
return CL_BUILD_NONE;
}
+cl_program_binary_type
+program::build::binary_type() const {
+ if (any_of(type_equals(module::section::text_intermediate), binary.secs))
+ return CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
+ else if (any_of(type_equals(module::section::text_library), binary.secs))
+ return CL_PROGRAM_BINARY_TYPE_LIBRARY;
+ else if (any_of(type_equals(module::section::text_executable), binary.secs))
+ return CL_PROGRAM_BINARY_TYPE_EXECUTABLE;
+ else
+ return CL_PROGRAM_BINARY_TYPE_NONE;
+}
+
const struct program::build &
program::build(const device &dev) const {
static const struct build null;
diff --git a/src/gallium/state_trackers/clover/core/program.hpp b/src/gallium/state_trackers/clover/core/program.hpp
index 76f16d2..05964e7 100644
--- a/src/gallium/state_trackers/clover/core/program.hpp
+++ b/src/gallium/state_trackers/clover/core/program.hpp
@@ -63,6 +63,7 @@ namespace clover {
const std::string &log = {}) : binary(m), opts(opts), log(log) {}
cl_build_status status() const;
+ cl_program_binary_type binary_type() const;
module binary;
std::string opts;
diff --git a/src/gallium/state_trackers/clover/llvm/codegen.hpp b/src/gallium/state_trackers/clover/llvm/codegen.hpp
index e0e9901..44971ad 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen.hpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen.hpp
@@ -46,7 +46,8 @@ namespace clover {
print_module_bitcode(const ::llvm::Module &mod);
module
- build_module_library(const ::llvm::Module &mod);
+ build_module_library(const ::llvm::Module &mod,
+ enum module::section::type section_type);
std::unique_ptr<::llvm::Module>
parse_module_library(const module &m, ::llvm::LLVMContext &ctx,
diff --git a/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
index 658cce9..108f8d5 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
@@ -80,10 +80,11 @@ clover::llvm::print_module_bitcode(const ::llvm::Module &mod) {
}
module
-clover::llvm::build_module_library(const ::llvm::Module &mod) {
+clover::llvm::build_module_library(const ::llvm::Module &mod,
+ enum module::section::type section_type) {
module m;
const auto code = emit_code(mod);
- m.secs.emplace_back(0, module::section::text, code.size(), code);
+ m.secs.emplace_back(0, section_type, code.size(), code);
return m;
}
diff --git a/src/gallium/state_trackers/clover/llvm/codegen/common.cpp b/src/gallium/state_trackers/clover/llvm/codegen/common.cpp
index 834b06a..13ccd59 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen/common.cpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen/common.cpp
@@ -179,7 +179,8 @@ namespace {
module::section
make_text_section(const std::vector<char> &code) {
const pipe_llvm_program_header header { uint32_t(code.size()) };
- module::section text { 0, module::section::text, header.num_bytes, {} };
+ module::section text { 0, module::section::text_executable,
+ header.num_bytes, {} };
text.data.insert(text.data.end(), reinterpret_cast<const char *>(&header),
reinterpret_cast<const char *>(&header) + sizeof(header));
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index b5e8b52..675cf19 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_library(*mod, module::section::text_intermediate);
}
namespace {
@@ -280,7 +280,7 @@ clover::llvm::link_program(const std::vector<module> &modules,
debug::log(".ll", print_module_bitcode(*mod));
if (create_library) {
- return build_module_library(*mod);
+ return build_module_library(*mod, module::section::text_library);
} else if (ir == PIPE_SHADER_IR_LLVM) {
return build_module_bitcode(*mod, *c);
diff --git a/src/gallium/state_trackers/clover/tgsi/compiler.cpp b/src/gallium/state_trackers/clover/tgsi/compiler.cpp
index 9bbd454..e165311 100644
--- a/src/gallium/state_trackers/clover/tgsi/compiler.cpp
+++ b/src/gallium/state_trackers/clover/tgsi/compiler.cpp
@@ -91,7 +91,7 @@ namespace {
unsigned sz = tgsi_num_tokens(prog) * sizeof(tgsi_token);
std::vector<char> data( (char *)prog, (char *)prog + sz );
- m.secs.push_back({ 0, module::section::text, sz, data });
+ m.secs.push_back({ 0, module::section::text_executable, sz, data });
}
}
--
2.10.1
More information about the mesa-dev
mailing list