0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd:🆑:code: Add binary construction.

This commit is contained in:
Jason Volk 2021-03-21 17:46:31 -07:00
parent 7561c3a6e0
commit 6ca5f8b18f
2 changed files with 45 additions and 0 deletions

View file

@ -92,6 +92,7 @@ struct ircd::cl::code
public:
void build(const string_view &opts = {});
explicit code(const vector_view<const const_buffer> &bins, const string_view &opts = {});
code(const vector_view<const string_view> &srcs, const string_view &opts = {});
code(const string_view &src, const string_view &opts = {});
code() = default;

View file

@ -854,6 +854,50 @@ ircd::cl::code::code(const vector_view<const string_view> &srcs,
build(build_opts);
}
ircd::cl::code::code(const vector_view<const const_buffer> &bins,
const string_view &build_opts)
{
static const size_t iov_max
{
64 //TODO: ???
};
if(unlikely(bins.size() > iov_max))
throw error
{
"Maximum number of binaries exceeded: lim:%zu got:%zu",
iov_max,
bins.size(),
};
const size_t count
{
std::min(bins.size(), iov_max)
};
size_t len[iov_max + 1] {0};
const uint8_t *bin[iov_max + 1] {nullptr};
for(size_t i(0); i < count; ++i)
bin[i] = reinterpret_cast<const uint8_t *>(ircd::data(bins[i])),
len[i] = ircd::size(bins[i]);
size_t devs {0};
cl_device_id dev[DEVICE_MAX] {0};
for(size_t i(0); i < platforms; ++i)
for(size_t j(0); j < devices[i]; ++j)
dev[devs++] = device[i][j];
int err {CL_SUCCESS};
int binerr[iov_max + 1] {CL_SUCCESS};
handle = clCreateProgramWithBinary(primary, devs, dev, len, bin, binerr, &err);
throw_on_error(err);
for(size_t i(0); i < count; ++i)
throw_on_error(binerr[i]);
if(!null(build_opts))
build(build_opts);
}
ircd::cl::code::code(code &&o)
noexcept
:handle{std::move(o.handle)}