21 #include "context.hpp" 32 using complex_t = std::complex<float>;
35 template <
typename ElemTy, direction Dir = none>
38 std::shared_ptr<buffer_binding> _buffer_binding;
41 : _buffer_binding(nullptr) {}
43 blob(ElemTy* ptr,
size_t size)
44 : _buffer_binding(std::make_shared<buffer_binding>(ptr, size * sizeof_t<ElemTy>(), Dir))
47 blob(
const std::shared_ptr<buffer>& buffer,
size_t size = 0)
48 : _buffer_binding(std::make_shared<buffer_binding>(buffer, Dir, size))
53 : _buffer_binding(std::make_shared<buffer_binding>(ptr, 0, Dir))
56 std::shared_ptr<buffer_binding>
get()
const {
return _buffer_binding; }
58 operator ElemTy*()
const {
return reinterpret_cast<ElemTy*
>(_buffer_binding->get_host_ptr()); }
59 operator std::shared_ptr<buffer_binding>()
const {
return get(); }
60 operator bool()
const {
return _buffer_binding && _buffer_binding->is_defined(); }
66 using implementations_list = std::vector<std::shared_ptr<typename Func::impl>>;
69 using scored_impls_list = std::vector<std::pair<float, std::shared_ptr<typename Func::impl>>>;
72 implementations_list<Func> get_implementations(
const std::shared_ptr<context>& ctx) =
delete;
83 using array_type = std::array<float, N>;
87 array_type& as_array() {
return _data; }
88 const array_type& as_array()
const {
return _data; }
94 using event = std::shared_ptr<iclgpu::event>;
98 template <
typename Func>
101 typedef Func func_type;
102 using holder::holder;
105 virtual const char* name()
const = 0;
108 virtual const char* full_name()
const = 0;
114 virtual bool accept(
const typename Func::params&,
typename Func::score&) {
return false; }
119 template <
typename Func>
128 virtual event execute(
const typename Func::params& params,
const std::vector<event>& dep_events) = 0;
134 template <
typename Func>
140 using command_builder = std::function<std::shared_ptr<command>(
const typename Func::params& params)>;
148 template <
class Func>
151 using holder::holder;
167 auto& scores = score.as_array();
169 return std::accumulate(std::begin(scores), std::end(scores), 0.f);
182 template <
class Func,
class ScoreCalculator = score_builder_dot_product<Func>>
187 , _score_calculator(ctx->get<ScoreCalculator>()) {}
192 scored_impls_list<Func>
select(
const typename Func::params& params)
194 auto impls = functions::get_implementations<Func>(
context());
200 scored_impls_list<Func> result;
202 for (
auto& impl : impls)
205 typename Func::score score;
208 if (impl->accept(params, score))
210 float calculated_score = _score_calculator->calculate_score_value(score);
211 result.push_back({calculated_score, impl});
220 std::sort(result.begin(), result.end(), [](
const auto& a,
const auto& b) {
return a.first > b.first; });
226 std::shared_ptr<ScoreCalculator> _score_calculator;
Helper class to select function implementation by calling accept() method for each implementation...
Function implementation with 2-step execution.
Function implementation base class.
std::function< std::shared_ptr< command >(const typename Func::params ¶ms)> command_builder
Functor creates command which executes function implementation.
Global library context provides access to all library objects.
Exception type indicates that provided actual function parameters are not supported.
virtual bool accept(const typename Func::params &, typename Func::score &)
Check if the implementation supports actual function parameters values.
base class for function score structures
Function implementation supporting direct execution.
float calculate_score_value(const typename Func::score &score)
Calculates implementation score scalar based on function_score structure filled by implementation...
Helper class to calculate implementation score based on 'dot-product'.
scored_impls_list< Func > select(const typename Func::params ¶ms)
Creates the list of function implementations which accept specified function parameters.
Exception type indicates that function has no any implementation.