clover: Rename module -> binary, because C++20 makes module a keyword
Reviewed-by: Karol Herbst <kherbst@redhat.com> Reviewed-by: Francisco Jerez <currojerez@riseup.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12273>
This commit is contained in:
@@ -57,7 +57,7 @@ clCreateKernelsInProgram(cl_program d_prog, cl_uint count,
|
||||
throw error(CL_INVALID_VALUE);
|
||||
|
||||
if (rd_kerns)
|
||||
copy(map([&](const module::symbol &sym) {
|
||||
copy(map([&](const binary::symbol &sym) {
|
||||
return desc(new kernel(prog,
|
||||
std::string(sym.name.begin(),
|
||||
sym.name.end()),
|
||||
@@ -257,9 +257,9 @@ namespace {
|
||||
throw error(CL_INVALID_KERNEL_ARGS);
|
||||
|
||||
// If the command queue's device is not associated to the program, we get
|
||||
// a module, with no sections, which will also fail the following test.
|
||||
auto &m = kern.program().build(q.device()).binary;
|
||||
if (!any_of(type_equals(module::section::text_executable), m.secs))
|
||||
// a binary, with no sections, which will also fail the following test.
|
||||
auto &b = kern.program().build(q.device()).bin;
|
||||
if (!any_of(type_equals(binary::section::text_executable), b.secs))
|
||||
throw error(CL_INVALID_PROGRAM_EXECUTABLE);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,8 +143,8 @@ clCreateProgramWithBinary(cl_context d_ctx, cl_uint n,
|
||||
throw error(CL_INVALID_DEVICE);
|
||||
|
||||
// Deserialize the provided binaries,
|
||||
std::vector<std::pair<cl_int, module>> result = map(
|
||||
[](const unsigned char *p, size_t l) -> std::pair<cl_int, module> {
|
||||
std::vector<std::pair<cl_int, binary>> result = map(
|
||||
[](const unsigned char *p, size_t l) -> std::pair<cl_int, binary> {
|
||||
if (!p || !l)
|
||||
return { CL_INVALID_VALUE, {} };
|
||||
|
||||
@@ -152,7 +152,7 @@ clCreateProgramWithBinary(cl_context d_ctx, cl_uint n,
|
||||
std::stringbuf bin( std::string{ (char*)p, l } );
|
||||
std::istream s(&bin);
|
||||
|
||||
return { CL_SUCCESS, module::deserialize(s) };
|
||||
return { CL_SUCCESS, binary::deserialize(s) };
|
||||
|
||||
} catch (std::istream::failure &) {
|
||||
return { CL_INVALID_BINARY, {} };
|
||||
@@ -507,7 +507,7 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param,
|
||||
|
||||
case CL_PROGRAM_BINARY_SIZES:
|
||||
buf.as_vector<size_t>() = map([&](const device &dev) {
|
||||
return prog.build(dev).binary.size();
|
||||
return prog.build(dev).bin.size();
|
||||
},
|
||||
prog.devices());
|
||||
break;
|
||||
@@ -516,7 +516,7 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param,
|
||||
buf.as_matrix<unsigned char>() = map([&](const device &dev) {
|
||||
std::stringbuf bin;
|
||||
std::ostream s(&bin);
|
||||
prog.build(dev).binary.serialize(s);
|
||||
prog.build(dev).bin.serialize(s);
|
||||
return bin.str();
|
||||
},
|
||||
prog.devices());
|
||||
@@ -527,7 +527,7 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param,
|
||||
break;
|
||||
|
||||
case CL_PROGRAM_KERNEL_NAMES:
|
||||
buf.as_string() = fold([](const std::string &a, const module::symbol &s) {
|
||||
buf.as_string() = fold([](const std::string &a, const binary::symbol &s) {
|
||||
return ((a.empty() ? "" : a + ";") + s.name);
|
||||
}, std::string(), prog.symbols());
|
||||
break;
|
||||
|
||||
+21
-21
@@ -23,7 +23,7 @@
|
||||
#include <type_traits>
|
||||
#include <iostream>
|
||||
|
||||
#include "core/module.hpp"
|
||||
#include "core/binary.hpp"
|
||||
|
||||
using namespace clover;
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace {
|
||||
/// Calculate the size of the specified object.
|
||||
template<typename T>
|
||||
void
|
||||
_proc(module::size_t &sz, const T &x) {
|
||||
_proc(binary::size_t &sz, const T &x) {
|
||||
_serializer<T>::proc(sz, x);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace {
|
||||
}
|
||||
|
||||
static void
|
||||
proc(module::size_t &sz, const T &x) {
|
||||
proc(binary::size_t &sz, const T &x) {
|
||||
sz += sizeof(x);
|
||||
}
|
||||
};
|
||||
@@ -102,7 +102,7 @@ namespace {
|
||||
}
|
||||
|
||||
static void
|
||||
proc(module::size_t &sz, const std::vector<T> &v) {
|
||||
proc(binary::size_t &sz, const std::vector<T> &v) {
|
||||
sz += sizeof(uint32_t);
|
||||
|
||||
for (size_t i = 0; i < v.size(); i++)
|
||||
@@ -129,7 +129,7 @@ namespace {
|
||||
}
|
||||
|
||||
static void
|
||||
proc(module::size_t &sz, const std::vector<T> &v) {
|
||||
proc(binary::size_t &sz, const std::vector<T> &v) {
|
||||
sz += sizeof(uint32_t) + sizeof(T) * v.size();
|
||||
}
|
||||
};
|
||||
@@ -150,14 +150,14 @@ namespace {
|
||||
}
|
||||
|
||||
static void
|
||||
proc(module::size_t &sz, const std::string &s) {
|
||||
proc(binary::size_t &sz, const std::string &s) {
|
||||
sz += sizeof(uint32_t) + sizeof(std::string::value_type) * s.size();
|
||||
}
|
||||
};
|
||||
|
||||
/// (De)serialize a printf format
|
||||
template<>
|
||||
struct _serializer<module::printf_info> {
|
||||
struct _serializer<binary::printf_info> {
|
||||
template<typename S, typename QT>
|
||||
static void
|
||||
proc(S & s, QT &x) {
|
||||
@@ -166,9 +166,9 @@ namespace {
|
||||
}
|
||||
};
|
||||
|
||||
/// (De)serialize a module::section.
|
||||
/// (De)serialize a binary::section.
|
||||
template<>
|
||||
struct _serializer<module::section> {
|
||||
struct _serializer<binary::section> {
|
||||
template<typename S, typename QT>
|
||||
static void
|
||||
proc(S &s, QT &x) {
|
||||
@@ -179,9 +179,9 @@ namespace {
|
||||
}
|
||||
};
|
||||
|
||||
/// (De)serialize a module::argument.
|
||||
/// (De)serialize a binary::argument.
|
||||
template<>
|
||||
struct _serializer<module::argument> {
|
||||
struct _serializer<binary::argument> {
|
||||
template<typename S, typename QT>
|
||||
static void
|
||||
proc(S &s, QT &x) {
|
||||
@@ -194,9 +194,9 @@ namespace {
|
||||
}
|
||||
};
|
||||
|
||||
/// (De)serialize a module::symbol.
|
||||
/// (De)serialize a binary::symbol.
|
||||
template<>
|
||||
struct _serializer<module::symbol> {
|
||||
struct _serializer<binary::symbol> {
|
||||
template<typename S, typename QT>
|
||||
static void
|
||||
proc(S &s, QT &x) {
|
||||
@@ -209,9 +209,9 @@ namespace {
|
||||
}
|
||||
};
|
||||
|
||||
/// (De)serialize a module.
|
||||
/// (De)serialize a binary.
|
||||
template<>
|
||||
struct _serializer<module> {
|
||||
struct _serializer<binary> {
|
||||
template<typename S, typename QT>
|
||||
static void
|
||||
proc(S &s, QT &x) {
|
||||
@@ -225,17 +225,17 @@ namespace {
|
||||
|
||||
namespace clover {
|
||||
void
|
||||
module::serialize(std::ostream &os) const {
|
||||
binary::serialize(std::ostream &os) const {
|
||||
_proc(os, *this);
|
||||
}
|
||||
|
||||
module
|
||||
module::deserialize(std::istream &is) {
|
||||
return _proc<module>(is);
|
||||
binary
|
||||
binary::deserialize(std::istream &is) {
|
||||
return _proc<binary>(is);
|
||||
}
|
||||
|
||||
module::size_t
|
||||
module::size() const {
|
||||
binary::size_t
|
||||
binary::size() const {
|
||||
size_t sz = 0;
|
||||
_proc(sz, *this);
|
||||
return sz;
|
||||
+5
-5
@@ -20,8 +20,8 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef CLOVER_CORE_MODULE_HPP
|
||||
#define CLOVER_CORE_MODULE_HPP
|
||||
#ifndef CLOVER_CORE_BINARY_HPP
|
||||
#define CLOVER_CORE_BINARY_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "CL/cl.h"
|
||||
|
||||
namespace clover {
|
||||
struct module {
|
||||
struct binary {
|
||||
typedef uint32_t resource_id;
|
||||
typedef uint32_t size_t;
|
||||
|
||||
@@ -153,9 +153,9 @@ namespace clover {
|
||||
std::vector<argument> args;
|
||||
};
|
||||
|
||||
module() : printf_strings_in_buffer(0) { }
|
||||
binary() : printf_strings_in_buffer(0) { }
|
||||
void serialize(std::ostream &os) const;
|
||||
static module deserialize(std::istream &is);
|
||||
static binary deserialize(std::istream &is);
|
||||
size_t size() const;
|
||||
|
||||
std::vector<symbol> syms;
|
||||
@@ -24,14 +24,14 @@
|
||||
#define CLOVER_CORE_COMPILER_HPP
|
||||
|
||||
#include "core/device.hpp"
|
||||
#include "core/module.hpp"
|
||||
#include "core/binary.hpp"
|
||||
#include "llvm/invocation.hpp"
|
||||
#include "nir/invocation.hpp"
|
||||
#include "spirv/invocation.hpp"
|
||||
|
||||
namespace clover {
|
||||
namespace compiler {
|
||||
static inline module
|
||||
static inline binary
|
||||
compile_program(const program &prog, const header_map &headers,
|
||||
const device &dev, const std::string &opts,
|
||||
std::string &log) {
|
||||
@@ -59,21 +59,21 @@ namespace clover {
|
||||
}
|
||||
}
|
||||
|
||||
static inline module
|
||||
link_program(const std::vector<module> &ms, const device &dev,
|
||||
static inline binary
|
||||
link_program(const std::vector<binary> &bs, const device &dev,
|
||||
const std::string &opts, std::string &log) {
|
||||
const bool create_library =
|
||||
opts.find("-create-library") != std::string::npos;
|
||||
switch (dev.ir_format()) {
|
||||
case PIPE_SHADER_IR_NIR_SERIALIZED: {
|
||||
auto spirv_linked_module = spirv::link_program(ms, dev, opts, log);
|
||||
auto spirv_linked_module = spirv::link_program(bs, dev, opts, log);
|
||||
if (create_library)
|
||||
return spirv_linked_module;
|
||||
return nir::spirv_to_nir(spirv_linked_module,
|
||||
dev, log);
|
||||
}
|
||||
case PIPE_SHADER_IR_NATIVE:
|
||||
return llvm::link_program(ms, dev, opts, log);
|
||||
return llvm::link_program(bs, dev, opts, log);
|
||||
default:
|
||||
unreachable("device with unsupported IR");
|
||||
throw error(CL_INVALID_VALUE);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include "core/object.hpp"
|
||||
#include "core/format.hpp"
|
||||
#include "core/module.hpp"
|
||||
#include "core/binary.hpp"
|
||||
#include "util/lazy.hpp"
|
||||
#include "pipe-loader/pipe_loader.h"
|
||||
|
||||
|
||||
@@ -29,21 +29,21 @@
|
||||
using namespace clover;
|
||||
|
||||
kernel::kernel(clover::program &prog, const std::string &name,
|
||||
const std::vector<module::argument> &margs) :
|
||||
const std::vector<binary::argument> &bargs) :
|
||||
program(prog), _name(name), exec(*this),
|
||||
program_ref(prog._kernel_ref_counter) {
|
||||
for (auto &marg : margs) {
|
||||
if (marg.semantic == module::argument::general)
|
||||
_args.emplace_back(argument::create(marg));
|
||||
for (auto &barg : bargs) {
|
||||
if (barg.semantic == binary::argument::general)
|
||||
_args.emplace_back(argument::create(barg));
|
||||
}
|
||||
for (auto &dev : prog.devices()) {
|
||||
auto &m = prog.build(dev).binary;
|
||||
auto msym = find(name_equals(name), m.syms);
|
||||
const auto f = id_type_equals(msym.section, module::section::data_constant);
|
||||
if (!any_of(f, m.secs))
|
||||
auto &b = prog.build(dev).bin;
|
||||
auto bsym = find(name_equals(name), b.syms);
|
||||
const auto f = id_type_equals(bsym.section, binary::section::data_constant);
|
||||
if (!any_of(f, b.secs))
|
||||
continue;
|
||||
|
||||
auto mconst = find(f, m.secs);
|
||||
auto mconst = find(f, b.secs);
|
||||
auto rb = std::make_unique<root_buffer>(prog.context(), std::vector<cl_mem_properties>(),
|
||||
CL_MEM_COPY_HOST_PTR | CL_MEM_READ_ONLY,
|
||||
mconst.size, mconst.data.data());
|
||||
@@ -64,7 +64,7 @@ kernel::launch(command_queue &q,
|
||||
const std::vector<size_t> &grid_offset,
|
||||
const std::vector<size_t> &grid_size,
|
||||
const std::vector<size_t> &block_size) {
|
||||
const auto m = program().build(q.device()).binary;
|
||||
const auto b = program().build(q.device()).bin;
|
||||
const auto reduced_grid_size =
|
||||
map(divides(), grid_size, block_size);
|
||||
|
||||
@@ -98,7 +98,7 @@ kernel::launch(command_queue &q,
|
||||
info.work_dim = grid_size.size();
|
||||
copy(pad_vector(q, block_size, 1), info.block);
|
||||
copy(pad_vector(q, reduced_grid_size, 1), info.grid);
|
||||
info.pc = find(name_equals(_name), m.syms).offset;
|
||||
info.pc = find(name_equals(_name), b.syms).offset;
|
||||
info.input = exec.input.data();
|
||||
|
||||
q.pipe->launch_grid(q.pipe, &info);
|
||||
@@ -164,19 +164,19 @@ kernel::args() const {
|
||||
return map(derefs(), _args);
|
||||
}
|
||||
|
||||
std::vector<clover::module::arg_info>
|
||||
std::vector<clover::binary::arg_info>
|
||||
kernel::args_infos() {
|
||||
std::vector<clover::module::arg_info> infos;
|
||||
for (auto &marg: find(name_equals(_name), program().symbols()).args)
|
||||
if (marg.semantic == clover::module::argument::general)
|
||||
infos.emplace_back(marg.info);
|
||||
std::vector<clover::binary::arg_info> infos;
|
||||
for (auto &barg: find(name_equals(_name), program().symbols()).args)
|
||||
if (barg.semantic == clover::binary::argument::general)
|
||||
infos.emplace_back(barg.info);
|
||||
|
||||
return infos;
|
||||
}
|
||||
|
||||
const module &
|
||||
kernel::module(const command_queue &q) const {
|
||||
return program().build(q.device()).binary;
|
||||
const binary &
|
||||
kernel::binary(const command_queue &q) const {
|
||||
return program().build(q.device()).bin;
|
||||
}
|
||||
|
||||
kernel::exec_context::exec_context(kernel &kern) :
|
||||
@@ -194,79 +194,79 @@ kernel::exec_context::bind(intrusive_ptr<command_queue> _q,
|
||||
std::swap(q, _q);
|
||||
|
||||
// Bind kernel arguments.
|
||||
auto &m = kern.program().build(q->device()).binary;
|
||||
auto msym = find(name_equals(kern.name()), m.syms);
|
||||
auto margs = msym.args;
|
||||
auto msec = find(id_type_equals(msym.section, module::section::text_executable), m.secs);
|
||||
auto &b = kern.program().build(q->device()).bin;
|
||||
auto bsym = find(name_equals(kern.name()), b.syms);
|
||||
auto bargs = bsym.args;
|
||||
auto msec = find(id_type_equals(bsym.section, binary::section::text_executable), b.secs);
|
||||
auto explicit_arg = kern._args.begin();
|
||||
|
||||
for (auto &marg : margs) {
|
||||
switch (marg.semantic) {
|
||||
case module::argument::general:
|
||||
(*(explicit_arg++))->bind(*this, marg);
|
||||
for (auto &barg : bargs) {
|
||||
switch (barg.semantic) {
|
||||
case binary::argument::general:
|
||||
(*(explicit_arg++))->bind(*this, barg);
|
||||
break;
|
||||
|
||||
case module::argument::grid_dimension: {
|
||||
case binary::argument::grid_dimension: {
|
||||
const cl_uint dimension = grid_offset.size();
|
||||
auto arg = argument::create(marg);
|
||||
auto arg = argument::create(barg);
|
||||
|
||||
arg->set(sizeof(dimension), &dimension);
|
||||
arg->bind(*this, marg);
|
||||
arg->bind(*this, barg);
|
||||
break;
|
||||
}
|
||||
case module::argument::grid_offset: {
|
||||
case binary::argument::grid_offset: {
|
||||
for (cl_uint x : pad_vector(*q, grid_offset, 0)) {
|
||||
auto arg = argument::create(marg);
|
||||
auto arg = argument::create(barg);
|
||||
|
||||
arg->set(sizeof(x), &x);
|
||||
arg->bind(*this, marg);
|
||||
arg->bind(*this, barg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case module::argument::image_size: {
|
||||
case binary::argument::image_size: {
|
||||
auto img = dynamic_cast<image_argument &>(**(explicit_arg - 1)).get();
|
||||
std::vector<cl_uint> image_size{
|
||||
static_cast<cl_uint>(img->width()),
|
||||
static_cast<cl_uint>(img->height()),
|
||||
static_cast<cl_uint>(img->depth())};
|
||||
for (auto x : image_size) {
|
||||
auto arg = argument::create(marg);
|
||||
auto arg = argument::create(barg);
|
||||
|
||||
arg->set(sizeof(x), &x);
|
||||
arg->bind(*this, marg);
|
||||
arg->bind(*this, barg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case module::argument::image_format: {
|
||||
case binary::argument::image_format: {
|
||||
auto img = dynamic_cast<image_argument &>(**(explicit_arg - 1)).get();
|
||||
cl_image_format fmt = img->format();
|
||||
std::vector<cl_uint> image_format{
|
||||
static_cast<cl_uint>(fmt.image_channel_data_type),
|
||||
static_cast<cl_uint>(fmt.image_channel_order)};
|
||||
for (auto x : image_format) {
|
||||
auto arg = argument::create(marg);
|
||||
auto arg = argument::create(barg);
|
||||
|
||||
arg->set(sizeof(x), &x);
|
||||
arg->bind(*this, marg);
|
||||
arg->bind(*this, barg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case module::argument::constant_buffer: {
|
||||
auto arg = argument::create(marg);
|
||||
case binary::argument::constant_buffer: {
|
||||
auto arg = argument::create(barg);
|
||||
cl_mem buf = kern._constant_buffers.at(&q->device()).get();
|
||||
arg->set(sizeof(buf), &buf);
|
||||
arg->bind(*this, marg);
|
||||
arg->bind(*this, barg);
|
||||
break;
|
||||
}
|
||||
case module::argument::printf_buffer: {
|
||||
print_handler = printf_handler::create(q, m.printf_infos,
|
||||
m.printf_strings_in_buffer,
|
||||
case binary::argument::printf_buffer: {
|
||||
print_handler = printf_handler::create(q, b.printf_infos,
|
||||
b.printf_strings_in_buffer,
|
||||
q->device().max_printf_buffer_size());
|
||||
cl_mem print_mem = print_handler->get_mem();
|
||||
|
||||
auto arg = argument::create(marg);
|
||||
auto arg = argument::create(barg);
|
||||
arg->set(sizeof(cl_mem), &print_mem);
|
||||
arg->bind(*this, marg);
|
||||
arg->bind(*this, barg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -352,9 +352,9 @@ namespace {
|
||||
///
|
||||
template<typename T>
|
||||
void
|
||||
extend(T &v, enum module::argument::ext_type ext, size_t n) {
|
||||
extend(T &v, enum binary::argument::ext_type ext, size_t n) {
|
||||
const size_t m = std::min(v.size(), n);
|
||||
const bool sign_ext = (ext == module::argument::sign_ext);
|
||||
const bool sign_ext = (ext == binary::argument::sign_ext);
|
||||
const uint8_t fill = (sign_ext && msb(v) ? ~0 : 0);
|
||||
T w(n, fill);
|
||||
|
||||
@@ -388,27 +388,27 @@ namespace {
|
||||
}
|
||||
|
||||
std::unique_ptr<kernel::argument>
|
||||
kernel::argument::create(const module::argument &marg) {
|
||||
switch (marg.type) {
|
||||
case module::argument::scalar:
|
||||
return std::unique_ptr<kernel::argument>(new scalar_argument(marg.size));
|
||||
kernel::argument::create(const binary::argument &barg) {
|
||||
switch (barg.type) {
|
||||
case binary::argument::scalar:
|
||||
return std::unique_ptr<kernel::argument>(new scalar_argument(barg.size));
|
||||
|
||||
case module::argument::global:
|
||||
case binary::argument::global:
|
||||
return std::unique_ptr<kernel::argument>(new global_argument);
|
||||
|
||||
case module::argument::local:
|
||||
case binary::argument::local:
|
||||
return std::unique_ptr<kernel::argument>(new local_argument);
|
||||
|
||||
case module::argument::constant:
|
||||
case binary::argument::constant:
|
||||
return std::unique_ptr<kernel::argument>(new constant_argument);
|
||||
|
||||
case module::argument::image_rd:
|
||||
case binary::argument::image_rd:
|
||||
return std::unique_ptr<kernel::argument>(new image_rd_argument);
|
||||
|
||||
case module::argument::image_wr:
|
||||
case binary::argument::image_wr:
|
||||
return std::unique_ptr<kernel::argument>(new image_wr_argument);
|
||||
|
||||
case module::argument::sampler:
|
||||
case binary::argument::sampler:
|
||||
return std::unique_ptr<kernel::argument>(new sampler_argument);
|
||||
|
||||
}
|
||||
@@ -445,12 +445,12 @@ kernel::scalar_argument::set(size_t size, const void *value) {
|
||||
|
||||
void
|
||||
kernel::scalar_argument::bind(exec_context &ctx,
|
||||
const module::argument &marg) {
|
||||
const binary::argument &barg) {
|
||||
auto w = v;
|
||||
|
||||
extend(w, marg.ext_type, marg.target_size);
|
||||
extend(w, barg.ext_type, barg.target_size);
|
||||
byteswap(w, ctx.q->device().endianness());
|
||||
align(ctx.input, marg.target_align);
|
||||
align(ctx.input, barg.target_align);
|
||||
insert(ctx.input, w);
|
||||
}
|
||||
|
||||
@@ -480,8 +480,8 @@ kernel::global_argument::set_svm(const void *value) {
|
||||
|
||||
void
|
||||
kernel::global_argument::bind(exec_context &ctx,
|
||||
const module::argument &marg) {
|
||||
align(ctx.input, marg.target_align);
|
||||
const binary::argument &barg) {
|
||||
align(ctx.input, barg.target_align);
|
||||
|
||||
if (buf) {
|
||||
const resource &r = buf->resource_in(*ctx.q);
|
||||
@@ -492,17 +492,17 @@ kernel::global_argument::bind(exec_context &ctx,
|
||||
// We don't need to. Buffer offsets are always
|
||||
// one-dimensional.
|
||||
auto v = bytes(r.offset[0]);
|
||||
extend(v, marg.ext_type, marg.target_size);
|
||||
extend(v, barg.ext_type, barg.target_size);
|
||||
byteswap(v, ctx.q->device().endianness());
|
||||
insert(ctx.input, v);
|
||||
} else if (svm) {
|
||||
auto v = bytes(svm);
|
||||
extend(v, marg.ext_type, marg.target_size);
|
||||
extend(v, barg.ext_type, barg.target_size);
|
||||
byteswap(v, ctx.q->device().endianness());
|
||||
insert(ctx.input, v);
|
||||
} else {
|
||||
// Null pointer.
|
||||
allocate(ctx.input, marg.target_size);
|
||||
allocate(ctx.input, barg.target_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,11 +529,11 @@ kernel::local_argument::set(size_t size, const void *value) {
|
||||
|
||||
void
|
||||
kernel::local_argument::bind(exec_context &ctx,
|
||||
const module::argument &marg) {
|
||||
ctx.mem_local = ::align(ctx.mem_local, marg.target_align);
|
||||
const binary::argument &barg) {
|
||||
ctx.mem_local = ::align(ctx.mem_local, barg.target_align);
|
||||
auto v = bytes(ctx.mem_local);
|
||||
|
||||
extend(v, module::argument::zero_ext, marg.target_size);
|
||||
extend(v, binary::argument::zero_ext, barg.target_size);
|
||||
byteswap(v, ctx.q->device().endianness());
|
||||
align(ctx.input, ctx.q->device().address_bits() / 8);
|
||||
insert(ctx.input, v);
|
||||
@@ -559,14 +559,14 @@ kernel::constant_argument::set(size_t size, const void *value) {
|
||||
|
||||
void
|
||||
kernel::constant_argument::bind(exec_context &ctx,
|
||||
const module::argument &marg) {
|
||||
align(ctx.input, marg.target_align);
|
||||
const binary::argument &barg) {
|
||||
align(ctx.input, barg.target_align);
|
||||
|
||||
if (buf) {
|
||||
resource &r = buf->resource_in(*ctx.q);
|
||||
auto v = bytes(ctx.resources.size() << 24 | r.offset[0]);
|
||||
|
||||
extend(v, module::argument::zero_ext, marg.target_size);
|
||||
extend(v, binary::argument::zero_ext, barg.target_size);
|
||||
byteswap(v, ctx.q->device().endianness());
|
||||
insert(ctx.input, v);
|
||||
|
||||
@@ -574,7 +574,7 @@ kernel::constant_argument::bind(exec_context &ctx,
|
||||
ctx.resources.push_back(st);
|
||||
} else {
|
||||
// Null pointer.
|
||||
allocate(ctx.input, marg.target_size);
|
||||
allocate(ctx.input, barg.target_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,12 +598,12 @@ kernel::image_rd_argument::set(size_t size, const void *value) {
|
||||
|
||||
void
|
||||
kernel::image_rd_argument::bind(exec_context &ctx,
|
||||
const module::argument &marg) {
|
||||
const binary::argument &barg) {
|
||||
auto v = bytes(ctx.sviews.size());
|
||||
|
||||
extend(v, module::argument::zero_ext, marg.target_size);
|
||||
extend(v, binary::argument::zero_ext, barg.target_size);
|
||||
byteswap(v, ctx.q->device().endianness());
|
||||
align(ctx.input, marg.target_align);
|
||||
align(ctx.input, barg.target_align);
|
||||
insert(ctx.input, v);
|
||||
|
||||
st = img->resource_in(*ctx.q).bind_sampler_view(*ctx.q);
|
||||
@@ -629,12 +629,12 @@ kernel::image_wr_argument::set(size_t size, const void *value) {
|
||||
|
||||
void
|
||||
kernel::image_wr_argument::bind(exec_context &ctx,
|
||||
const module::argument &marg) {
|
||||
const binary::argument &barg) {
|
||||
auto v = bytes(ctx.iviews.size());
|
||||
|
||||
extend(v, module::argument::zero_ext, marg.target_size);
|
||||
extend(v, binary::argument::zero_ext, barg.target_size);
|
||||
byteswap(v, ctx.q->device().endianness());
|
||||
align(ctx.input, marg.target_align);
|
||||
align(ctx.input, barg.target_align);
|
||||
insert(ctx.input, v);
|
||||
ctx.iviews.push_back(img->resource_in(*ctx.q).create_image_view(*ctx.q));
|
||||
}
|
||||
@@ -660,7 +660,7 @@ kernel::sampler_argument::set(size_t size, const void *value) {
|
||||
|
||||
void
|
||||
kernel::sampler_argument::bind(exec_context &ctx,
|
||||
const module::argument &marg) {
|
||||
const binary::argument &barg) {
|
||||
st = s->bind(*ctx.q);
|
||||
ctx.samplers.push_back(st);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace clover {
|
||||
class argument {
|
||||
public:
|
||||
static std::unique_ptr<argument>
|
||||
create(const module::argument &marg);
|
||||
create(const binary::argument &barg);
|
||||
|
||||
argument(const argument &arg) = delete;
|
||||
argument &
|
||||
@@ -97,7 +97,7 @@ namespace clover {
|
||||
/// Allocate the necessary resources to bind the specified
|
||||
/// object to this argument, and update \a ctx accordingly.
|
||||
virtual void bind(exec_context &ctx,
|
||||
const module::argument &marg) = 0;
|
||||
const binary::argument &barg) = 0;
|
||||
|
||||
/// Free any resources that were allocated in bind().
|
||||
virtual void unbind(exec_context &ctx) = 0;
|
||||
@@ -120,7 +120,7 @@ namespace clover {
|
||||
|
||||
public:
|
||||
kernel(clover::program &prog, const std::string &name,
|
||||
const std::vector<clover::module::argument> &margs);
|
||||
const std::vector<clover::binary::argument> &bargs);
|
||||
|
||||
kernel(const kernel &kern) = delete;
|
||||
kernel &
|
||||
@@ -144,12 +144,12 @@ namespace clover {
|
||||
|
||||
argument_range args();
|
||||
const_argument_range args() const;
|
||||
std::vector<clover::module::arg_info> args_infos();
|
||||
std::vector<clover::binary::arg_info> args_infos();
|
||||
|
||||
const intrusive_ref<clover::program> program;
|
||||
|
||||
private:
|
||||
const clover::module &module(const command_queue &q) const;
|
||||
const clover::binary &binary(const command_queue &q) const;
|
||||
|
||||
class scalar_argument : public argument {
|
||||
public:
|
||||
@@ -157,7 +157,7 @@ namespace clover {
|
||||
|
||||
virtual void set(size_t size, const void *value);
|
||||
virtual void bind(exec_context &ctx,
|
||||
const module::argument &marg);
|
||||
const binary::argument &barg);
|
||||
virtual void unbind(exec_context &ctx);
|
||||
|
||||
private:
|
||||
@@ -172,7 +172,7 @@ namespace clover {
|
||||
virtual void set(size_t size, const void *value);
|
||||
virtual void set_svm(const void *value);
|
||||
virtual void bind(exec_context &ctx,
|
||||
const module::argument &marg);
|
||||
const binary::argument &barg);
|
||||
virtual void unbind(exec_context &ctx);
|
||||
|
||||
private:
|
||||
@@ -186,7 +186,7 @@ namespace clover {
|
||||
|
||||
virtual void set(size_t size, const void *value);
|
||||
virtual void bind(exec_context &ctx,
|
||||
const module::argument &marg);
|
||||
const binary::argument &barg);
|
||||
virtual void unbind(exec_context &ctx);
|
||||
|
||||
private:
|
||||
@@ -199,7 +199,7 @@ namespace clover {
|
||||
|
||||
virtual void set(size_t size, const void *value);
|
||||
virtual void bind(exec_context &ctx,
|
||||
const module::argument &marg);
|
||||
const binary::argument &barg);
|
||||
virtual void unbind(exec_context &ctx);
|
||||
|
||||
private:
|
||||
@@ -220,7 +220,7 @@ namespace clover {
|
||||
public:
|
||||
virtual void set(size_t size, const void *value);
|
||||
virtual void bind(exec_context &ctx,
|
||||
const module::argument &marg);
|
||||
const binary::argument &barg);
|
||||
virtual void unbind(exec_context &ctx);
|
||||
|
||||
private:
|
||||
@@ -231,7 +231,7 @@ namespace clover {
|
||||
public:
|
||||
virtual void set(size_t size, const void *value);
|
||||
virtual void bind(exec_context &ctx,
|
||||
const module::argument &marg);
|
||||
const binary::argument &barg);
|
||||
virtual void unbind(exec_context &ctx);
|
||||
};
|
||||
|
||||
@@ -241,7 +241,7 @@ namespace clover {
|
||||
|
||||
virtual void set(size_t size, const void *value);
|
||||
virtual void bind(exec_context &ctx,
|
||||
const module::argument &marg);
|
||||
const binary::argument &barg);
|
||||
virtual void unbind(exec_context &ctx);
|
||||
|
||||
private:
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace {
|
||||
const std::string clc_printf_whitelist = "%0123456789-+ #.AacdeEfFgGhilopsuvxX";
|
||||
|
||||
void
|
||||
print_formatted(const std::vector<module::printf_info> &formatters,
|
||||
print_formatted(const std::vector<binary::printf_info> &formatters,
|
||||
bool _strings_in_buffer,
|
||||
const std::vector<char> &buffer) {
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace {
|
||||
for (size_t buf_pos = 0; buf_pos < buffer.size(); ) {
|
||||
cl_uint fmt_idx = *(cl_uint*)&buffer[buf_pos];
|
||||
assert(fmt_idx > 0);
|
||||
module::printf_info fmt = formatters[fmt_idx-1];
|
||||
binary::printf_info fmt = formatters[fmt_idx-1];
|
||||
|
||||
std::string format = (char *)fmt.strings.data();
|
||||
buf_pos += sizeof(cl_uint);
|
||||
@@ -175,7 +175,7 @@ namespace {
|
||||
|
||||
std::unique_ptr<printf_handler>
|
||||
printf_handler::create(const intrusive_ptr<command_queue> &q,
|
||||
const std::vector<module::printf_info> &infos,
|
||||
const std::vector<binary::printf_info> &infos,
|
||||
bool strings_in_buffer,
|
||||
cl_uint size) {
|
||||
return std::unique_ptr<printf_handler>(
|
||||
@@ -183,7 +183,7 @@ printf_handler::create(const intrusive_ptr<command_queue> &q,
|
||||
}
|
||||
|
||||
printf_handler::printf_handler(const intrusive_ptr<command_queue> &q,
|
||||
const std::vector<module::printf_info> &infos,
|
||||
const std::vector<binary::printf_info> &infos,
|
||||
bool strings_in_buffer,
|
||||
cl_uint size) :
|
||||
_q(q), _formatters(infos), _strings_in_buffer(strings_in_buffer), _size(size), _buffer() {
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace clover {
|
||||
public:
|
||||
static std::unique_ptr<printf_handler>
|
||||
create(const intrusive_ptr<command_queue> &q,
|
||||
const std::vector<module::printf_info> &info,
|
||||
const std::vector<binary::printf_info> &info,
|
||||
bool strings_in_buffer, cl_uint size);
|
||||
|
||||
printf_handler(const printf_handler &arg) = delete;
|
||||
@@ -46,11 +46,11 @@ namespace clover {
|
||||
|
||||
private:
|
||||
printf_handler(const intrusive_ptr<command_queue> &q,
|
||||
const std::vector<module::printf_info> &infos,
|
||||
const std::vector<binary::printf_info> &infos,
|
||||
bool strings_in_buffer, cl_uint size);
|
||||
|
||||
intrusive_ptr<command_queue> _q;
|
||||
std::vector<module::printf_info> _formatters;
|
||||
std::vector<binary::printf_info> _formatters;
|
||||
bool _strings_in_buffer;
|
||||
cl_uint _size;
|
||||
std::unique_ptr<root_buffer> _buffer;
|
||||
|
||||
@@ -33,10 +33,10 @@ program::program(clover::context &ctx, std::string &&source,
|
||||
|
||||
program::program(clover::context &ctx,
|
||||
const ref_vector<device> &devs,
|
||||
const std::vector<module> &binaries) :
|
||||
const std::vector<binary> &binaries) :
|
||||
context(ctx), _devices(devs), _kernel_ref_counter(0),
|
||||
_il_type(il_type::none) {
|
||||
for_each([&](device &dev, const module &bin) {
|
||||
for_each([&](device &dev, const binary &bin) {
|
||||
_builds[&dev] = { bin };
|
||||
},
|
||||
devs, binaries);
|
||||
@@ -52,11 +52,11 @@ program::compile(const ref_vector<device> &devs, const std::string &opts,
|
||||
std::string log;
|
||||
|
||||
try {
|
||||
const module m =
|
||||
const binary b =
|
||||
compiler::compile_program(*this, headers, dev, opts, log);
|
||||
_builds[&dev] = { m, opts, log };
|
||||
_builds[&dev] = { b, opts, log };
|
||||
} catch (...) {
|
||||
_builds[&dev] = { module(), opts, log };
|
||||
_builds[&dev] = { binary(), opts, log };
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -69,16 +69,16 @@ program::link(const ref_vector<device> &devs, const std::string &opts,
|
||||
_devices = devs;
|
||||
|
||||
for (auto &dev : devs) {
|
||||
const std::vector<module> ms = map([&](const program &prog) {
|
||||
return prog.build(dev).binary;
|
||||
const std::vector<binary> bs = map([&](const program &prog) {
|
||||
return prog.build(dev).bin;
|
||||
}, progs);
|
||||
std::string log = _builds[&dev].log;
|
||||
|
||||
try {
|
||||
const module m = compiler::link_program(ms, dev, opts, log);
|
||||
_builds[&dev] = { m, opts, log };
|
||||
const binary b = compiler::link_program(bs, dev, opts, log);
|
||||
_builds[&dev] = { b, opts, log };
|
||||
} catch (...) {
|
||||
_builds[&dev] = { module(), opts, log };
|
||||
_builds[&dev] = { binary(), opts, log };
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ program::devices() const {
|
||||
|
||||
cl_build_status
|
||||
program::build::status() const {
|
||||
if (!binary.secs.empty())
|
||||
if (!bin.secs.empty())
|
||||
return CL_BUILD_SUCCESS;
|
||||
else if (log.size())
|
||||
return CL_BUILD_ERROR;
|
||||
@@ -111,11 +111,11 @@ program::build::status() const {
|
||||
|
||||
cl_program_binary_type
|
||||
program::build::binary_type() const {
|
||||
if (any_of(type_equals(module::section::text_intermediate), binary.secs))
|
||||
if (any_of(type_equals(binary::section::text_intermediate), bin.secs))
|
||||
return CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
|
||||
else if (any_of(type_equals(module::section::text_library), binary.secs))
|
||||
else if (any_of(type_equals(binary::section::text_library), bin.secs))
|
||||
return CL_PROGRAM_BINARY_TYPE_LIBRARY;
|
||||
else if (any_of(type_equals(module::section::text_executable), binary.secs))
|
||||
else if (any_of(type_equals(binary::section::text_executable), bin.secs))
|
||||
return CL_PROGRAM_BINARY_TYPE_EXECUTABLE;
|
||||
else
|
||||
return CL_PROGRAM_BINARY_TYPE_NONE;
|
||||
@@ -127,12 +127,12 @@ program::build(const device &dev) const {
|
||||
return _builds.count(&dev) ? _builds.find(&dev)->second : null;
|
||||
}
|
||||
|
||||
const std::vector<module::symbol> &
|
||||
const std::vector<binary::symbol> &
|
||||
program::symbols() const {
|
||||
if (_builds.empty())
|
||||
throw error(CL_INVALID_PROGRAM_EXECUTABLE);
|
||||
|
||||
return _builds.begin()->second.binary.syms;
|
||||
return _builds.begin()->second.bin.syms;
|
||||
}
|
||||
|
||||
unsigned
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "core/object.hpp"
|
||||
#include "core/context.hpp"
|
||||
#include "core/module.hpp"
|
||||
#include "core/binary.hpp"
|
||||
|
||||
namespace clover {
|
||||
typedef std::vector<std::pair<std::string, std::string>> header_map;
|
||||
@@ -45,7 +45,7 @@ namespace clover {
|
||||
enum il_type il_type);
|
||||
program(clover::context &ctx,
|
||||
const ref_vector<device> &devs = {},
|
||||
const std::vector<module> &binaries = {});
|
||||
const std::vector<binary> &binaries = {});
|
||||
|
||||
program(const program &prog) = delete;
|
||||
program &
|
||||
@@ -62,20 +62,20 @@ namespace clover {
|
||||
device_range devices() const;
|
||||
|
||||
struct build {
|
||||
build(const module &m = {}, const std::string &opts = {},
|
||||
const std::string &log = {}) : binary(m), opts(opts), log(log) {}
|
||||
build(const binary &b = {}, const std::string &opts = {},
|
||||
const std::string &log = {}) : bin(b), opts(opts), log(log) {}
|
||||
|
||||
cl_build_status status() const;
|
||||
cl_program_binary_type binary_type() const;
|
||||
|
||||
module binary;
|
||||
binary bin;
|
||||
std::string opts;
|
||||
std::string log;
|
||||
};
|
||||
|
||||
const build &build(const device &dev) const;
|
||||
|
||||
const std::vector<module::symbol> &symbols() const;
|
||||
const std::vector<binary::symbol> &symbols() const;
|
||||
|
||||
unsigned kernel_ref_count() const;
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ resource::add_map(command_queue &q, cl_map_flags flags, bool blocking,
|
||||
|
||||
void
|
||||
resource::del_map(void *p) {
|
||||
erase_if([&](const mapping &m) {
|
||||
return static_cast<void *>(m) == p;
|
||||
erase_if([&](const mapping &b) {
|
||||
return static_cast<void *>(b) == p;
|
||||
}, maps);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
///
|
||||
/// \file
|
||||
/// Tools to generate various forms of binary code from existing LLVM IR in
|
||||
/// the given llvm::Module object and output the result as a clover::module.
|
||||
/// the given llvm::Module object and output the result as a clover::binary.
|
||||
///
|
||||
|
||||
#ifndef CLOVER_LLVM_CODEGEN_HPP
|
||||
#define CLOVER_LLVM_CODEGEN_HPP
|
||||
|
||||
#include "llvm/util.hpp"
|
||||
#include "core/module.hpp"
|
||||
#include "core/binary.hpp"
|
||||
|
||||
#include <llvm/IR/Module.h>
|
||||
|
||||
@@ -41,15 +41,15 @@ namespace clover {
|
||||
std::string
|
||||
print_module_bitcode(const ::llvm::Module &mod);
|
||||
|
||||
module
|
||||
binary
|
||||
build_module_library(const ::llvm::Module &mod,
|
||||
enum module::section::type section_type);
|
||||
enum binary::section::type section_type);
|
||||
|
||||
std::unique_ptr< ::llvm::Module>
|
||||
parse_module_library(const module &m, ::llvm::LLVMContext &ctx,
|
||||
parse_module_library(const binary &b, ::llvm::LLVMContext &ctx,
|
||||
std::string &r_log);
|
||||
|
||||
module
|
||||
binary
|
||||
build_module_native(::llvm::Module &mod, const target &target,
|
||||
const clang::CompilerInstance &c,
|
||||
std::string &r_log);
|
||||
@@ -57,7 +57,7 @@ namespace clover {
|
||||
std::string
|
||||
print_module_native(const ::llvm::Module &mod, const target &target);
|
||||
|
||||
module
|
||||
binary
|
||||
build_module_common(const ::llvm::Module &mod,
|
||||
const std::vector<char> &code,
|
||||
const std::map<std::string, unsigned> &offsets,
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
#endif
|
||||
#include <llvm/Support/raw_ostream.h>
|
||||
|
||||
using clover::module;
|
||||
using clover::binary;
|
||||
using namespace clover::llvm;
|
||||
|
||||
namespace {
|
||||
@@ -70,20 +70,20 @@ clover::llvm::print_module_bitcode(const ::llvm::Module &mod) {
|
||||
return os.str();
|
||||
}
|
||||
|
||||
module
|
||||
binary
|
||||
clover::llvm::build_module_library(const ::llvm::Module &mod,
|
||||
enum module::section::type section_type) {
|
||||
module m;
|
||||
enum binary::section::type section_type) {
|
||||
binary b;
|
||||
const auto code = emit_code(mod);
|
||||
m.secs.emplace_back(0, section_type, code.size(), code);
|
||||
return m;
|
||||
b.secs.emplace_back(0, section_type, code.size(), code);
|
||||
return b;
|
||||
}
|
||||
|
||||
std::unique_ptr< ::llvm::Module>
|
||||
clover::llvm::parse_module_library(const module &m, ::llvm::LLVMContext &ctx,
|
||||
clover::llvm::parse_module_library(const binary &b, ::llvm::LLVMContext &ctx,
|
||||
std::string &r_log) {
|
||||
auto mod = ::llvm::parseBitcodeFile(::llvm::MemoryBufferRef(
|
||||
as_string(m.secs[0].data), " "), ctx);
|
||||
as_string(b.secs[0].data), " "), ctx);
|
||||
|
||||
if (::llvm::Error err = mod.takeError()) {
|
||||
::llvm::handleAllErrors(std::move(err), [&](::llvm::ErrorInfoBase &eib) {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
///
|
||||
/// \file
|
||||
/// Codegen back-end-independent part of the construction of an executable
|
||||
/// clover::module, including kernel argument metadata extraction and
|
||||
/// clover::binary, including kernel argument metadata extraction and
|
||||
/// formatting of the pre-generated binary code in a form that can be
|
||||
/// understood by pipe drivers.
|
||||
///
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
#include <clang/Basic/TargetInfo.h>
|
||||
|
||||
using clover::module;
|
||||
using clover::binary;
|
||||
using clover::detokenize;
|
||||
using namespace clover::llvm;
|
||||
|
||||
@@ -54,20 +54,20 @@ using ::llvm::cast;
|
||||
using ::llvm::dyn_cast;
|
||||
|
||||
namespace {
|
||||
enum module::argument::type
|
||||
enum binary::argument::type
|
||||
get_image_type(const std::string &type,
|
||||
const std::string &qual) {
|
||||
if (type == "image1d_t" || type == "image2d_t" || type == "image3d_t") {
|
||||
if (qual == "read_only")
|
||||
return module::argument::image_rd;
|
||||
return binary::argument::image_rd;
|
||||
else if (qual == "write_only")
|
||||
return module::argument::image_wr;
|
||||
return binary::argument::image_wr;
|
||||
}
|
||||
|
||||
unreachable("Unsupported image type");
|
||||
}
|
||||
|
||||
module::arg_info create_arg_info(const std::string &arg_name,
|
||||
binary::arg_info create_arg_info(const std::string &arg_name,
|
||||
const std::string &type_name,
|
||||
const std::string &type_qualifier,
|
||||
const uint64_t address_qualifier,
|
||||
@@ -100,7 +100,7 @@ namespace {
|
||||
else if (access_qualifier == "read_write")
|
||||
cl_access_qualifier = CL_KERNEL_ARG_ACCESS_READ_WRITE;
|
||||
|
||||
return module::arg_info(arg_name, type_name, cl_type_qualifier,
|
||||
return binary::arg_info(arg_name, type_name, cl_type_qualifier,
|
||||
cl_address_qualifier, cl_access_qualifier);
|
||||
}
|
||||
|
||||
@@ -147,10 +147,10 @@ namespace {
|
||||
return detokenize(attributes, " ");
|
||||
}
|
||||
|
||||
std::vector<module::argument>
|
||||
std::vector<binary::argument>
|
||||
make_kernel_args(const Module &mod, const std::string &kernel_name,
|
||||
const clang::CompilerInstance &c) {
|
||||
std::vector<module::argument> args;
|
||||
std::vector<binary::argument> args;
|
||||
const Function &f = *mod.getFunction(kernel_name);
|
||||
::llvm::DataLayout dl(&mod);
|
||||
const auto size_type =
|
||||
@@ -176,28 +176,28 @@ namespace {
|
||||
f, arg, "kernel_arg_access_qual");
|
||||
args.emplace_back(get_image_type(type_name, access_qual),
|
||||
target_size, target_size,
|
||||
target_align, module::argument::zero_ext);
|
||||
target_align, binary::argument::zero_ext);
|
||||
|
||||
} else if (type_name == "sampler_t") {
|
||||
args.emplace_back(module::argument::sampler, arg_api_size,
|
||||
args.emplace_back(binary::argument::sampler, arg_api_size,
|
||||
target_size, target_align,
|
||||
module::argument::zero_ext);
|
||||
binary::argument::zero_ext);
|
||||
|
||||
} else if (type_name == "__llvm_image_size") {
|
||||
// Image size implicit argument.
|
||||
args.emplace_back(module::argument::scalar, sizeof(cl_uint),
|
||||
args.emplace_back(binary::argument::scalar, sizeof(cl_uint),
|
||||
dl.getTypeStoreSize(size_type),
|
||||
dl.getABITypeAlignment(size_type),
|
||||
module::argument::zero_ext,
|
||||
module::argument::image_size);
|
||||
binary::argument::zero_ext,
|
||||
binary::argument::image_size);
|
||||
|
||||
} else if (type_name == "__llvm_image_format") {
|
||||
// Image format implicit argument.
|
||||
args.emplace_back(module::argument::scalar, sizeof(cl_uint),
|
||||
args.emplace_back(binary::argument::scalar, sizeof(cl_uint),
|
||||
dl.getTypeStoreSize(size_type),
|
||||
dl.getABITypeAlignment(size_type),
|
||||
module::argument::zero_ext,
|
||||
module::argument::image_format);
|
||||
binary::argument::zero_ext,
|
||||
binary::argument::image_format);
|
||||
|
||||
} else {
|
||||
// Other types.
|
||||
@@ -215,10 +215,10 @@ namespace {
|
||||
if (address_space == map[offset]) {
|
||||
const auto pointee_type = cast<
|
||||
::llvm::PointerType>(actual_type)->getElementType();
|
||||
args.emplace_back(module::argument::local, arg_api_size,
|
||||
args.emplace_back(binary::argument::local, arg_api_size,
|
||||
target_size,
|
||||
dl.getABITypeAlignment(pointee_type),
|
||||
module::argument::zero_ext);
|
||||
binary::argument::zero_ext);
|
||||
} else {
|
||||
// XXX: Correctly handle constant address space. There is no
|
||||
// way for r600g to pass a handle for constant buffers back
|
||||
@@ -227,19 +227,19 @@ namespace {
|
||||
// continue treating constant buffers as global buffers
|
||||
// until we can come up with a way to create handles for
|
||||
// constant buffers.
|
||||
args.emplace_back(module::argument::global, arg_api_size,
|
||||
args.emplace_back(binary::argument::global, arg_api_size,
|
||||
target_size, target_align,
|
||||
module::argument::zero_ext);
|
||||
binary::argument::zero_ext);
|
||||
}
|
||||
|
||||
} else {
|
||||
const bool needs_sign_ext = f.getAttributes().hasParamAttr(
|
||||
arg.getArgNo(), ::llvm::Attribute::SExt);
|
||||
|
||||
args.emplace_back(module::argument::scalar, arg_api_size,
|
||||
args.emplace_back(binary::argument::scalar, arg_api_size,
|
||||
target_size, target_align,
|
||||
(needs_sign_ext ? module::argument::sign_ext :
|
||||
module::argument::zero_ext));
|
||||
(needs_sign_ext ? binary::argument::sign_ext :
|
||||
binary::argument::zero_ext));
|
||||
}
|
||||
|
||||
// Add kernel argument infos if built with -cl-kernel-arg-info.
|
||||
@@ -257,25 +257,25 @@ namespace {
|
||||
// Append implicit arguments. XXX - The types, ordering and
|
||||
// vector size of the implicit arguments should depend on the
|
||||
// target according to the selected calling convention.
|
||||
args.emplace_back(module::argument::scalar, sizeof(cl_uint),
|
||||
args.emplace_back(binary::argument::scalar, sizeof(cl_uint),
|
||||
dl.getTypeStoreSize(size_type),
|
||||
dl.getABITypeAlignment(size_type),
|
||||
module::argument::zero_ext,
|
||||
module::argument::grid_dimension);
|
||||
binary::argument::zero_ext,
|
||||
binary::argument::grid_dimension);
|
||||
|
||||
args.emplace_back(module::argument::scalar, sizeof(cl_uint),
|
||||
args.emplace_back(binary::argument::scalar, sizeof(cl_uint),
|
||||
dl.getTypeStoreSize(size_type),
|
||||
dl.getABITypeAlignment(size_type),
|
||||
module::argument::zero_ext,
|
||||
module::argument::grid_offset);
|
||||
binary::argument::zero_ext,
|
||||
binary::argument::grid_offset);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
module::section
|
||||
binary::section
|
||||
make_text_section(const std::vector<char> &code) {
|
||||
const pipe_binary_program_header header { uint32_t(code.size()) };
|
||||
module::section text { 0, module::section::text_executable,
|
||||
binary::section text { 0, binary::section::text_executable,
|
||||
header.num_bytes, {} };
|
||||
|
||||
text.data.insert(text.data.end(), reinterpret_cast<const char *>(&header),
|
||||
@@ -286,24 +286,24 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
module
|
||||
binary
|
||||
clover::llvm::build_module_common(const Module &mod,
|
||||
const std::vector<char> &code,
|
||||
const std::map<std::string,
|
||||
unsigned> &offsets,
|
||||
const clang::CompilerInstance &c) {
|
||||
module m;
|
||||
binary b;
|
||||
|
||||
for (const auto &llvm_name : map(std::mem_fn(&Function::getName),
|
||||
get_kernels(mod))) {
|
||||
const ::std::string name(llvm_name);
|
||||
if (offsets.count(name))
|
||||
m.syms.emplace_back(name, kernel_attributes(mod, name),
|
||||
b.syms.emplace_back(name, kernel_attributes(mod, name),
|
||||
get_reqd_work_group_size(mod, name),
|
||||
0, offsets.at(name),
|
||||
make_kernel_args(mod, name, c));
|
||||
}
|
||||
|
||||
m.secs.push_back(make_text_section(code));
|
||||
return m;
|
||||
b.secs.push_back(make_text_section(code));
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "llvm/util.hpp"
|
||||
#include "core/error.hpp"
|
||||
|
||||
using clover::module;
|
||||
using clover::binary;
|
||||
using clover::build_error;
|
||||
using namespace clover::llvm;
|
||||
using ::llvm::TargetMachine;
|
||||
@@ -143,7 +143,7 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
module
|
||||
binary
|
||||
clover::llvm::build_module_native(::llvm::Module &mod, const target &target,
|
||||
const clang::CompilerInstance &c,
|
||||
std::string &r_log) {
|
||||
@@ -167,7 +167,7 @@ clover::llvm::print_module_native(const ::llvm::Module &mod,
|
||||
|
||||
#else
|
||||
|
||||
module
|
||||
binary
|
||||
clover::llvm::build_module_native(::llvm::Module &mod, const target &target,
|
||||
const clang::CompilerInstance &c,
|
||||
std::string &r_log) {
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
#include "util/algorithm.hpp"
|
||||
|
||||
|
||||
using clover::module;
|
||||
using clover::binary;
|
||||
using clover::device;
|
||||
using clover::build_error;
|
||||
using clover::invalid_build_options_error;
|
||||
@@ -389,7 +389,7 @@ namespace {
|
||||
#endif
|
||||
}
|
||||
|
||||
module
|
||||
binary
|
||||
clover::llvm::compile_program(const std::string &source,
|
||||
const header_map &headers,
|
||||
const device &dev,
|
||||
@@ -407,7 +407,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, module::section::text_intermediate);
|
||||
return build_module_library(*mod, binary::section::text_intermediate);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -421,10 +421,10 @@ namespace {
|
||||
// functions as internal enables the optimizer to perform optimizations
|
||||
// like function inlining and global dead-code elimination.
|
||||
//
|
||||
// When there is no "main" function in a module, the internalize pass will
|
||||
// treat the module like a library, and it won't internalize any functions.
|
||||
// When there is no "main" function in a binary, the internalize pass will
|
||||
// treat the binary like a library, and it won't internalize any functions.
|
||||
// Since there is no "main" function in our kernels, we need to tell
|
||||
// the internalizer pass that this module is not a library by passing a
|
||||
// the internalizer pass that this binary is not a library by passing a
|
||||
// list of kernel functions to the internalizer. The internalizer will
|
||||
// treat the functions in the list as "main" functions and internalize
|
||||
// all of the other functions.
|
||||
@@ -448,12 +448,12 @@ namespace {
|
||||
|
||||
std::unique_ptr<Module>
|
||||
link(LLVMContext &ctx, const clang::CompilerInstance &c,
|
||||
const std::vector<module> &modules, std::string &r_log) {
|
||||
const std::vector<binary> &binaries, std::string &r_log) {
|
||||
std::unique_ptr<Module> mod { new Module("link", ctx) };
|
||||
std::unique_ptr< ::llvm::Linker> linker { new ::llvm::Linker(*mod) };
|
||||
|
||||
for (auto &m : modules) {
|
||||
if (linker->linkInModule(parse_module_library(m, ctx, r_log)))
|
||||
for (auto &b : binaries) {
|
||||
if (linker->linkInModule(parse_module_library(b, ctx, r_log)))
|
||||
throw build_error();
|
||||
}
|
||||
|
||||
@@ -461,8 +461,8 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
module
|
||||
clover::llvm::link_program(const std::vector<module> &modules,
|
||||
binary
|
||||
clover::llvm::link_program(const std::vector<binary> &binaries,
|
||||
const device &dev, const std::string &opts,
|
||||
std::string &r_log) {
|
||||
std::vector<std::string> options = tokenize(opts + " input.cl");
|
||||
@@ -471,7 +471,7 @@ clover::llvm::link_program(const std::vector<module> &modules,
|
||||
|
||||
auto ctx = create_context(r_log);
|
||||
auto c = create_compiler_instance(dev, dev.ir_target(), options, r_log);
|
||||
auto mod = link(*ctx, *c, modules, r_log);
|
||||
auto mod = link(*ctx, *c, binaries, r_log);
|
||||
|
||||
optimize(*mod, c->getCodeGenOpts().OptimizationLevel, !create_library);
|
||||
|
||||
@@ -483,7 +483,7 @@ clover::llvm::link_program(const std::vector<module> &modules,
|
||||
debug::log(id + ".ll", print_module_bitcode(*mod));
|
||||
|
||||
if (create_library) {
|
||||
return build_module_library(*mod, module::section::text_library);
|
||||
return build_module_library(*mod, binary::section::text_library);
|
||||
|
||||
} else if (dev.ir_format() == PIPE_SHADER_IR_NATIVE) {
|
||||
if (has_flag(debug::native))
|
||||
@@ -497,7 +497,7 @@ clover::llvm::link_program(const std::vector<module> &modules,
|
||||
}
|
||||
|
||||
#ifdef HAVE_CLOVER_SPIRV
|
||||
module
|
||||
binary
|
||||
clover::llvm::compile_to_spirv(const std::string &source,
|
||||
const header_map &headers,
|
||||
const device &dev,
|
||||
|
||||
@@ -24,25 +24,25 @@
|
||||
#define CLOVER_LLVM_INVOCATION_HPP
|
||||
|
||||
#include "core/error.hpp"
|
||||
#include "core/module.hpp"
|
||||
#include "core/binary.hpp"
|
||||
#include "core/program.hpp"
|
||||
#include "pipe/p_defines.h"
|
||||
|
||||
namespace clover {
|
||||
namespace llvm {
|
||||
module compile_program(const std::string &source,
|
||||
binary compile_program(const std::string &source,
|
||||
const header_map &headers,
|
||||
const device &device,
|
||||
const std::string &opts,
|
||||
std::string &r_log);
|
||||
|
||||
module link_program(const std::vector<module> &modules,
|
||||
binary link_program(const std::vector<binary> &binaries,
|
||||
const device &device,
|
||||
const std::string &opts,
|
||||
std::string &r_log);
|
||||
|
||||
#ifdef HAVE_CLOVER_SPIRV
|
||||
module compile_to_spirv(const std::string &source,
|
||||
binary compile_to_spirv(const std::string &source,
|
||||
const header_map &headers,
|
||||
const device &dev,
|
||||
const std::string &opts,
|
||||
|
||||
@@ -113,6 +113,8 @@ clover_files = files(
|
||||
'api/sampler.cpp',
|
||||
'api/transfer.cpp',
|
||||
'api/util.hpp',
|
||||
'core/binary.cpp',
|
||||
'core/binary.hpp',
|
||||
'core/compiler.hpp',
|
||||
'core/context.cpp',
|
||||
'core/context.hpp',
|
||||
@@ -127,8 +129,6 @@ clover_files = files(
|
||||
'core/kernel.hpp',
|
||||
'core/memory.cpp',
|
||||
'core/memory.hpp',
|
||||
'core/module.cpp',
|
||||
'core/module.hpp',
|
||||
'core/object.hpp',
|
||||
'core/platform.cpp',
|
||||
'core/platform.hpp',
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "core/device.hpp"
|
||||
#include "core/error.hpp"
|
||||
#include "core/module.hpp"
|
||||
#include "core/binary.hpp"
|
||||
#include "pipe/p_state.h"
|
||||
#include "util/algorithm.hpp"
|
||||
#include "util/functional.hpp"
|
||||
@@ -238,7 +238,7 @@ clover_nir_lower_images(nir_shader *shader)
|
||||
}
|
||||
|
||||
struct clover_lower_nir_state {
|
||||
std::vector<module::argument> &args;
|
||||
std::vector<binary::argument> &args;
|
||||
uint32_t global_dims;
|
||||
nir_variable *constant_var;
|
||||
nir_variable *printf_buffer;
|
||||
@@ -261,9 +261,9 @@ clover_lower_nir_instr(nir_builder *b, nir_instr *instr, void *_state)
|
||||
case nir_intrinsic_load_printf_buffer_address: {
|
||||
if (!state->printf_buffer) {
|
||||
unsigned location = state->args.size();
|
||||
state->args.emplace_back(module::argument::global, sizeof(size_t),
|
||||
8, 8, module::argument::zero_ext,
|
||||
module::argument::printf_buffer);
|
||||
state->args.emplace_back(binary::argument::global, sizeof(size_t),
|
||||
8, 8, binary::argument::zero_ext,
|
||||
binary::argument::printf_buffer);
|
||||
|
||||
const glsl_type *type = glsl_uint64_t_type();
|
||||
state->printf_buffer = nir_variable_create(b->shader, nir_var_uniform,
|
||||
@@ -282,9 +282,9 @@ clover_lower_nir_instr(nir_builder *b, nir_instr *instr, void *_state)
|
||||
* three 32 bit values
|
||||
*/
|
||||
unsigned location = state->args.size();
|
||||
state->args.emplace_back(module::argument::scalar, 4, 4, 4,
|
||||
module::argument::zero_ext,
|
||||
module::argument::grid_offset);
|
||||
state->args.emplace_back(binary::argument::scalar, 4, 4, 4,
|
||||
binary::argument::zero_ext,
|
||||
binary::argument::grid_offset);
|
||||
|
||||
const glsl_type *type = glsl_uint_type();
|
||||
for (uint32_t i = 0; i < 3; i++) {
|
||||
@@ -313,7 +313,7 @@ clover_lower_nir_instr(nir_builder *b, nir_instr *instr, void *_state)
|
||||
}
|
||||
|
||||
static bool
|
||||
clover_lower_nir(nir_shader *nir, std::vector<module::argument> &args,
|
||||
clover_lower_nir(nir_shader *nir, std::vector<binary::argument> &args,
|
||||
uint32_t dims, uint32_t pointer_bit_size)
|
||||
{
|
||||
nir_variable *constant_var = NULL;
|
||||
@@ -324,10 +324,10 @@ clover_lower_nir(nir_shader *nir, std::vector<module::argument> &args,
|
||||
"constant_buffer_addr");
|
||||
constant_var->data.location = args.size();
|
||||
|
||||
args.emplace_back(module::argument::global, sizeof(cl_mem),
|
||||
args.emplace_back(binary::argument::global, sizeof(cl_mem),
|
||||
pointer_bit_size / 8, pointer_bit_size / 8,
|
||||
module::argument::zero_ext,
|
||||
module::argument::constant_buffer);
|
||||
binary::argument::zero_ext,
|
||||
binary::argument::constant_buffer);
|
||||
}
|
||||
|
||||
clover_lower_nir_state state = { args, dims, constant_var };
|
||||
@@ -402,19 +402,19 @@ can_remove_var(nir_variable *var, void *data)
|
||||
return !(var->type->is_sampler() || var->type->is_image());
|
||||
}
|
||||
|
||||
module clover::nir::spirv_to_nir(const module &mod, const device &dev,
|
||||
binary clover::nir::spirv_to_nir(const binary &mod, const device &dev,
|
||||
std::string &r_log)
|
||||
{
|
||||
spirv_to_nir_options spirv_options = create_spirv_options(dev, r_log);
|
||||
std::shared_ptr<nir_shader> nir = dev.clc_nir;
|
||||
spirv_options.clc_shader = nir.get();
|
||||
|
||||
module m;
|
||||
binary b;
|
||||
// We only insert one section.
|
||||
assert(mod.secs.size() == 1);
|
||||
auto §ion = mod.secs[0];
|
||||
|
||||
module::resource_id section_id = 0;
|
||||
binary::resource_id section_id = 0;
|
||||
for (const auto &sym : mod.syms) {
|
||||
assert(sym.section == 0);
|
||||
|
||||
@@ -543,15 +543,15 @@ module clover::nir::spirv_to_nir(const module &mod, const device &dev,
|
||||
|
||||
if (nir->constant_data_size) {
|
||||
const char *ptr = reinterpret_cast<const char *>(nir->constant_data);
|
||||
const module::section constants {
|
||||
const binary::section constants {
|
||||
section_id,
|
||||
module::section::data_constant,
|
||||
binary::section::data_constant,
|
||||
nir->constant_data_size,
|
||||
{ ptr, ptr + nir->constant_data_size }
|
||||
};
|
||||
nir->constant_data = NULL;
|
||||
nir->constant_data_size = 0;
|
||||
m.secs.push_back(constants);
|
||||
b.secs.push_back(constants);
|
||||
}
|
||||
|
||||
void *mem_ctx = ralloc_context(NULL);
|
||||
@@ -567,17 +567,17 @@ module clover::nir::spirv_to_nir(const module &mod, const device &dev,
|
||||
ralloc_free(nir);
|
||||
|
||||
const pipe_binary_program_header header { uint32_t(blob.size) };
|
||||
module::section text { section_id, module::section::text_executable, header.num_bytes, {} };
|
||||
binary::section text { section_id, binary::section::text_executable, header.num_bytes, {} };
|
||||
text.data.insert(text.data.end(), reinterpret_cast<const char *>(&header),
|
||||
reinterpret_cast<const char *>(&header) + sizeof(header));
|
||||
text.data.insert(text.data.end(), blob.data, blob.data + blob.size);
|
||||
|
||||
free(blob.data);
|
||||
|
||||
m.printf_strings_in_buffer = false;
|
||||
m.printf_infos.reserve(printf_info_count);
|
||||
b.printf_strings_in_buffer = false;
|
||||
b.printf_infos.reserve(printf_info_count);
|
||||
for (unsigned i = 0; i < printf_info_count; i++) {
|
||||
module::printf_info info;
|
||||
binary::printf_info info;
|
||||
|
||||
info.arg_sizes.reserve(printf_infos[i].num_args);
|
||||
for (unsigned j = 0; j < printf_infos[i].num_args; j++)
|
||||
@@ -585,20 +585,20 @@ module clover::nir::spirv_to_nir(const module &mod, const device &dev,
|
||||
|
||||
info.strings.resize(printf_infos[i].string_size);
|
||||
memcpy(info.strings.data(), printf_infos[i].strings, printf_infos[i].string_size);
|
||||
m.printf_infos.push_back(info);
|
||||
b.printf_infos.push_back(info);
|
||||
}
|
||||
|
||||
ralloc_free(mem_ctx);
|
||||
|
||||
m.syms.emplace_back(sym.name, sym.attributes,
|
||||
b.syms.emplace_back(sym.name, sym.attributes,
|
||||
sym.reqd_work_group_size, section_id, 0, args);
|
||||
m.secs.push_back(text);
|
||||
b.secs.push_back(text);
|
||||
section_id++;
|
||||
}
|
||||
return m;
|
||||
return b;
|
||||
}
|
||||
#else
|
||||
module clover::nir::spirv_to_nir(const module &mod, const device &dev, std::string &r_log)
|
||||
binary clover::nir::spirv_to_nir(const binary &mod, const device &dev, std::string &r_log)
|
||||
{
|
||||
r_log += "SPIR-V support in clover is not enabled.\n";
|
||||
throw error(CL_LINKER_NOT_AVAILABLE);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#ifndef CLOVER_NIR_INVOCATION_HPP
|
||||
#define CLOVER_NIR_INVOCATION_HPP
|
||||
|
||||
#include "core/module.hpp"
|
||||
#include "core/binary.hpp"
|
||||
#include <util/disk_cache.h>
|
||||
|
||||
struct nir_shader;
|
||||
@@ -38,8 +38,8 @@ namespace clover {
|
||||
|
||||
struct disk_cache *create_clc_disk_cache(void);
|
||||
|
||||
// converts a given spirv module to nir
|
||||
module spirv_to_nir(const module &mod, const device &dev, std::string &r_log);
|
||||
// converts a given spirv binary to nir
|
||||
binary spirv_to_nir(const binary &bin, const device &dev, std::string &r_log);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,17 +62,17 @@ namespace {
|
||||
return static_cast<T>(word_ptr[index]);
|
||||
}
|
||||
|
||||
enum module::argument::type
|
||||
enum binary::argument::type
|
||||
convert_storage_class(SpvStorageClass storage_class, std::string &err) {
|
||||
switch (storage_class) {
|
||||
case SpvStorageClassFunction:
|
||||
return module::argument::scalar;
|
||||
return binary::argument::scalar;
|
||||
case SpvStorageClassUniformConstant:
|
||||
return module::argument::global;
|
||||
return binary::argument::global;
|
||||
case SpvStorageClassWorkgroup:
|
||||
return module::argument::local;
|
||||
return binary::argument::local;
|
||||
case SpvStorageClassCrossWorkgroup:
|
||||
return module::argument::global;
|
||||
return binary::argument::global;
|
||||
default:
|
||||
err += "Invalid storage type " + std::to_string(storage_class) + "\n";
|
||||
throw build_error();
|
||||
@@ -94,7 +94,7 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
enum module::argument::type
|
||||
enum binary::argument::type
|
||||
convert_image_type(SpvId id, SpvDim dim, SpvAccessQualifier access,
|
||||
std::string &err) {
|
||||
switch (dim) {
|
||||
@@ -104,9 +104,9 @@ namespace {
|
||||
case SpvDimBuffer:
|
||||
switch (access) {
|
||||
case SpvAccessQualifierReadOnly:
|
||||
return module::argument::image_rd;
|
||||
return binary::argument::image_rd;
|
||||
case SpvAccessQualifierWriteOnly:
|
||||
return module::argument::image_wr;
|
||||
return binary::argument::image_wr;
|
||||
default:
|
||||
err += "Unknown access qualifier " + std::to_string(access) + " for image "
|
||||
+ std::to_string(id) + ".\n";
|
||||
@@ -119,11 +119,11 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
module::section
|
||||
binary::section
|
||||
make_text_section(const std::string &code,
|
||||
enum module::section::type section_type) {
|
||||
enum binary::section::type section_type) {
|
||||
const pipe_binary_program_header header { uint32_t(code.size()) };
|
||||
module::section text { 0, section_type, header.num_bytes, {} };
|
||||
binary::section text { 0, section_type, header.num_bytes, {} };
|
||||
|
||||
text.data.insert(text.data.end(), reinterpret_cast<const char *>(&header),
|
||||
reinterpret_cast<const char *>(&header) + sizeof(header));
|
||||
@@ -132,8 +132,8 @@ namespace {
|
||||
return text;
|
||||
}
|
||||
|
||||
module
|
||||
create_module_from_spirv(const std::string &source,
|
||||
binary
|
||||
create_binary_from_spirv(const std::string &source,
|
||||
size_t pointer_byte_size,
|
||||
std::string &err) {
|
||||
const size_t length = source.size() / sizeof(uint32_t);
|
||||
@@ -141,15 +141,15 @@ namespace {
|
||||
|
||||
std::string kernel_name;
|
||||
size_t kernel_nb = 0u;
|
||||
std::vector<module::argument> args;
|
||||
std::vector<binary::argument> args;
|
||||
std::vector<size_t> req_local_size;
|
||||
|
||||
module m;
|
||||
binary b;
|
||||
|
||||
std::vector<std::string> attributes;
|
||||
std::unordered_map<SpvId, std::vector<size_t> > req_local_sizes;
|
||||
std::unordered_map<SpvId, std::string> kernels;
|
||||
std::unordered_map<SpvId, module::argument> types;
|
||||
std::unordered_map<SpvId, binary::argument> types;
|
||||
std::unordered_map<SpvId, SpvId> pointer_types;
|
||||
std::unordered_map<SpvId, unsigned int> constants;
|
||||
std::unordered_set<SpvId> packed_structures;
|
||||
@@ -291,7 +291,7 @@ namespace {
|
||||
case SpvOpConstant:
|
||||
// We only care about constants that represent the size of arrays.
|
||||
// If they are passed as argument, they will never be more than
|
||||
// 4GB-wide, and even if they did, a clover::module::argument size
|
||||
// 4GB-wide, and even if they did, a clover::binary::argument size
|
||||
// is represented by an int.
|
||||
constants[get<SpvId>(inst, 2)] = get<unsigned int>(inst, 3u);
|
||||
break;
|
||||
@@ -300,8 +300,8 @@ namespace {
|
||||
case SpvOpTypeFloat: {
|
||||
const auto size = get<uint32_t>(inst, 2) / 8u;
|
||||
const auto id = get<SpvId>(inst, 1);
|
||||
types[id] = { module::argument::scalar, size, size, size,
|
||||
module::argument::zero_ext };
|
||||
types[id] = { binary::argument::scalar, size, size, size,
|
||||
binary::argument::zero_ext };
|
||||
types[id].info.address_qualifier = CL_KERNEL_ARG_ADDRESS_PRIVATE;
|
||||
break;
|
||||
}
|
||||
@@ -323,9 +323,9 @@ namespace {
|
||||
const auto elem_size = types_iter->second.size;
|
||||
const auto elem_nbs = constants_iter->second;
|
||||
const auto size = elem_size * elem_nbs;
|
||||
types[id] = { module::argument::scalar, size, size,
|
||||
types[id] = { binary::argument::scalar, size, size,
|
||||
types_iter->second.target_align,
|
||||
module::argument::zero_ext };
|
||||
binary::argument::zero_ext };
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ namespace {
|
||||
const auto types_iter = types.find(type_id);
|
||||
|
||||
// If a type was not found, that means it is not one of the
|
||||
// types allowed as kernel arguments. And since the module has
|
||||
// types allowed as kernel arguments. And since the binary has
|
||||
// been validated, this means this type is not used for kernel
|
||||
// arguments, and therefore can be ignored.
|
||||
if (types_iter == types.end())
|
||||
@@ -353,8 +353,8 @@ namespace {
|
||||
struct_align = std::max(struct_align, alignment);
|
||||
}
|
||||
struct_size += (-struct_size) & (struct_align - 1u);
|
||||
types[id] = { module::argument::scalar, struct_size, struct_size,
|
||||
struct_align, module::argument::zero_ext };
|
||||
types[id] = { binary::argument::scalar, struct_size, struct_size,
|
||||
struct_align, binary::argument::zero_ext };
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -364,7 +364,7 @@ namespace {
|
||||
const auto types_iter = types.find(type_id);
|
||||
|
||||
// If a type was not found, that means it is not one of the
|
||||
// types allowed as kernel arguments. And since the module has
|
||||
// types allowed as kernel arguments. And since the binary has
|
||||
// been validated, this means this type is not used for kernel
|
||||
// arguments, and therefore can be ignored.
|
||||
if (types_iter == types.end())
|
||||
@@ -373,8 +373,8 @@ namespace {
|
||||
const auto elem_size = types_iter->second.size;
|
||||
const auto elem_nbs = get<uint32_t>(inst, 3);
|
||||
const auto size = elem_size * (elem_nbs != 3 ? elem_nbs : 4);
|
||||
types[id] = { module::argument::scalar, size, size, size,
|
||||
module::argument::zero_ext };
|
||||
types[id] = { binary::argument::scalar, size, size, size,
|
||||
binary::argument::zero_ext };
|
||||
types[id].info.address_qualifier = CL_KERNEL_ARG_ADDRESS_PRIVATE;
|
||||
break;
|
||||
}
|
||||
@@ -391,7 +391,7 @@ namespace {
|
||||
if (opcode == SpvOpTypePointer)
|
||||
pointer_types[id] = get<SpvId>(inst, 3);
|
||||
|
||||
module::size_t alignment;
|
||||
binary::size_t alignment;
|
||||
if (storage_class == SpvStorageClassWorkgroup)
|
||||
alignment = opcode == SpvOpTypePointer ? types[pointer_types[id]].target_align : 0;
|
||||
else
|
||||
@@ -399,15 +399,15 @@ namespace {
|
||||
|
||||
types[id] = { convert_storage_class(storage_class, err),
|
||||
sizeof(cl_mem),
|
||||
static_cast<module::size_t>(pointer_byte_size),
|
||||
static_cast<binary::size_t>(pointer_byte_size),
|
||||
alignment,
|
||||
module::argument::zero_ext };
|
||||
binary::argument::zero_ext };
|
||||
types[id].info.address_qualifier = convert_storage_class_to_cl(storage_class);
|
||||
break;
|
||||
}
|
||||
|
||||
case SpvOpTypeSampler:
|
||||
types[get<SpvId>(inst, 1)] = { module::argument::sampler,
|
||||
types[get<SpvId>(inst, 1)] = { binary::argument::sampler,
|
||||
sizeof(cl_sampler) };
|
||||
break;
|
||||
|
||||
@@ -417,7 +417,7 @@ namespace {
|
||||
const auto access = get<SpvAccessQualifier>(inst, 9);
|
||||
types[id] = { convert_image_type(id, dim, access, err),
|
||||
sizeof(cl_mem), sizeof(cl_mem), sizeof(cl_mem),
|
||||
module::argument::zero_ext };
|
||||
binary::argument::zero_ext };
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -457,10 +457,10 @@ namespace {
|
||||
for (auto &i : func_param_attr_iter->second) {
|
||||
switch (i) {
|
||||
case SpvFunctionParameterAttributeSext:
|
||||
arg.ext_type = module::argument::sign_ext;
|
||||
arg.ext_type = binary::argument::sign_ext;
|
||||
break;
|
||||
case SpvFunctionParameterAttributeZext:
|
||||
arg.ext_type = module::argument::zero_ext;
|
||||
arg.ext_type = binary::argument::zero_ext;
|
||||
break;
|
||||
case SpvFunctionParameterAttributeByVal: {
|
||||
const SpvId ptr_type_id =
|
||||
@@ -498,7 +498,7 @@ namespace {
|
||||
for (size_t i = 0; i < param_type_names[kernel_name].size(); i++)
|
||||
args[i].info.type_name = param_type_names[kernel_name][i];
|
||||
|
||||
m.syms.emplace_back(kernel_name, detokenize(attributes, " "),
|
||||
b.syms.emplace_back(kernel_name, detokenize(attributes, " "),
|
||||
req_local_size, 0, kernel_nb, args);
|
||||
++kernel_nb;
|
||||
kernel_name.clear();
|
||||
@@ -513,9 +513,9 @@ namespace {
|
||||
i += num_operands;
|
||||
}
|
||||
|
||||
m.secs.push_back(make_text_section(source,
|
||||
module::section::text_intermediate));
|
||||
return m;
|
||||
b.secs.push_back(make_text_section(source,
|
||||
binary::section::text_intermediate));
|
||||
return b;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -773,7 +773,7 @@ clover::spirv::version_to_string(uint32_t version) {
|
||||
std::to_string(minor_version);
|
||||
}
|
||||
|
||||
module
|
||||
binary
|
||||
clover::spirv::compile_program(const std::string &binary,
|
||||
const device &dev, std::string &r_log,
|
||||
bool validate) {
|
||||
@@ -791,12 +791,12 @@ clover::spirv::compile_program(const std::string &binary,
|
||||
if (!check_memory_model(dev, source, r_log))
|
||||
throw build_error();
|
||||
|
||||
return create_module_from_spirv(source,
|
||||
return create_binary_from_spirv(source,
|
||||
dev.address_bits() == 32 ? 4u : 8u, r_log);
|
||||
}
|
||||
|
||||
module
|
||||
clover::spirv::link_program(const std::vector<module> &modules,
|
||||
binary
|
||||
clover::spirv::link_program(const std::vector<binary> &binaries,
|
||||
const device &dev, const std::string &opts,
|
||||
std::string &r_log) {
|
||||
std::vector<std::string> options = tokenize(opts);
|
||||
@@ -819,15 +819,15 @@ clover::spirv::link_program(const std::vector<module> &modules,
|
||||
spvtools::LinkerOptions linker_options;
|
||||
linker_options.SetCreateLibrary(create_library);
|
||||
|
||||
module m;
|
||||
binary b;
|
||||
|
||||
const auto section_type = create_library ? module::section::text_library :
|
||||
module::section::text_executable;
|
||||
const auto section_type = create_library ? binary::section::text_library :
|
||||
binary::section::text_executable;
|
||||
|
||||
std::vector<const uint32_t *> sections;
|
||||
sections.reserve(modules.size());
|
||||
sections.reserve(binaries.size());
|
||||
std::vector<size_t> lengths;
|
||||
lengths.reserve(modules.size());
|
||||
lengths.reserve(binaries.size());
|
||||
|
||||
auto const validator_consumer = [&r_log](spv_message_level_t level,
|
||||
const char *source,
|
||||
@@ -836,14 +836,14 @@ clover::spirv::link_program(const std::vector<module> &modules,
|
||||
r_log += format_validator_msg(level, source, position, message);
|
||||
};
|
||||
|
||||
for (const auto &mod : modules) {
|
||||
const auto &msec = find([](const module::section &sec) {
|
||||
return sec.type == module::section::text_intermediate ||
|
||||
sec.type == module::section::text_library;
|
||||
}, mod.secs);
|
||||
for (const auto &bin : binaries) {
|
||||
const auto &bsec = find([](const binary::section &sec) {
|
||||
return sec.type == binary::section::text_intermediate ||
|
||||
sec.type == binary::section::text_library;
|
||||
}, bin.secs);
|
||||
|
||||
const auto c_il = ((struct pipe_binary_program_header*)msec.data.data())->blob;
|
||||
const auto length = msec.size;
|
||||
const auto c_il = ((struct pipe_binary_program_header*)bsec.data.data())->blob;
|
||||
const auto length = bsec.size;
|
||||
|
||||
if (!check_spirv_version(dev, c_il, r_log))
|
||||
throw error(CL_LINK_PROGRAM_FAILURE);
|
||||
@@ -876,12 +876,12 @@ clover::spirv::link_program(const std::vector<module> &modules,
|
||||
if (has_flag(llvm::debug::spirv))
|
||||
llvm::debug::log(".spvasm", spirv::print_module(final_binary, dev.device_version()));
|
||||
|
||||
for (const auto &mod : modules)
|
||||
m.syms.insert(m.syms.end(), mod.syms.begin(), mod.syms.end());
|
||||
for (const auto &bin : binaries)
|
||||
b.syms.insert(b.syms.end(), bin.syms.begin(), bin.syms.end());
|
||||
|
||||
m.secs.emplace_back(make_text_section(final_binary, section_type));
|
||||
b.secs.emplace_back(make_text_section(final_binary, section_type));
|
||||
|
||||
return m;
|
||||
return b;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -915,7 +915,7 @@ clover::spirv::print_module(const std::string &binary,
|
||||
spvtools::SpirvTools spvTool(target_env);
|
||||
spv_context spvContext = spvContextCreate(target_env);
|
||||
if (!spvContext)
|
||||
return "Failed to create an spv_context for disassembling the module.";
|
||||
return "Failed to create an spv_context for disassembling the binary.";
|
||||
|
||||
spv_text disassembly;
|
||||
spvBinaryToText(spvContext,
|
||||
@@ -974,7 +974,7 @@ clover::spirv::version_to_string(uint32_t version) {
|
||||
return "";
|
||||
}
|
||||
|
||||
module
|
||||
binary
|
||||
clover::spirv::compile_program(const std::string &binary,
|
||||
const device &dev, std::string &r_log,
|
||||
bool validate) {
|
||||
@@ -982,8 +982,8 @@ clover::spirv::compile_program(const std::string &binary,
|
||||
throw build_error();
|
||||
}
|
||||
|
||||
module
|
||||
clover::spirv::link_program(const std::vector<module> &/*modules*/,
|
||||
binary
|
||||
clover::spirv::link_program(const std::vector<binary> &/*binaries*/,
|
||||
const device &/*dev*/, const std::string &/*opts*/,
|
||||
std::string &r_log) {
|
||||
r_log += "SPIR-V support in clover is not enabled.\n";
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <unordered_set>
|
||||
|
||||
#include "core/context.hpp"
|
||||
#include "core/module.hpp"
|
||||
#include "core/binary.hpp"
|
||||
#include "core/program.hpp"
|
||||
|
||||
namespace clover {
|
||||
@@ -49,14 +49,14 @@ namespace clover {
|
||||
// Converts an integer SPIR-V version into its textual representation.
|
||||
std::string version_to_string(uint32_t version);
|
||||
|
||||
// Creates a clover module out of the given SPIR-V binary.
|
||||
module compile_program(const std::string &binary,
|
||||
// Creates a clover binary out of the given SPIR-V binary.
|
||||
binary compile_program(const std::string &binary,
|
||||
const device &dev, std::string &r_log,
|
||||
bool validate = true);
|
||||
|
||||
// Combines multiple clover modules into a single one, resolving
|
||||
// Combines multiple clover objects into a single one, resolving
|
||||
// link dependencies between them.
|
||||
module link_program(const std::vector<module> &modules, const device &dev,
|
||||
binary link_program(const std::vector<binary> &objects, const device &dev,
|
||||
const std::string &opts, std::string &r_log);
|
||||
|
||||
// Returns a textual representation of the given binary.
|
||||
|
||||
Reference in New Issue
Block a user