From 6ca5f8b18f97f73474d788f853729037a7c6aec1 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 21 Mar 2021 17:46:31 -0700 Subject: [PATCH] ircd::cl::code: Add binary construction. --- include/ircd/cl.h | 1 + ircd/cl.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/ircd/cl.h b/include/ircd/cl.h index 5e92bd88a..a32be0688 100644 --- a/include/ircd/cl.h +++ b/include/ircd/cl.h @@ -92,6 +92,7 @@ struct ircd::cl::code public: void build(const string_view &opts = {}); + explicit code(const vector_view &bins, const string_view &opts = {}); code(const vector_view &srcs, const string_view &opts = {}); code(const string_view &src, const string_view &opts = {}); code() = default; diff --git a/ircd/cl.cc b/ircd/cl.cc index 968cd1afa..7e9316820 100644 --- a/ircd/cl.cc +++ b/ircd/cl.cc @@ -854,6 +854,50 @@ ircd::cl::code::code(const vector_view &srcs, build(build_opts); } +ircd::cl::code::code(const vector_view &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(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)}