rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
operand_type_rule.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include <rexlib/core/operation/type_rule/type_pivot.hpp>
6#include <rexlib/core/operation/type_rule/type_slot.hpp>
7
8#include <rexlib/core/meta/type_list.hpp>
9#include <rexlib/core/platform/constexpr.hpp>
10
11#include <cstddef>
12#include <type_traits>
13
14namespace rexlib
15{
16
17namespace detail
18{
19
20template <std::size_t PivotCount, typename Slots>
22
23template <std::size_t PivotCount>
25 : std::true_type
26{
27};
28
29template <std::size_t PivotCount, typename Head, typename... Tail>
31 : std::integral_constant<
32 bool,
33 (Head::pivot_index < PivotCount) &&
34 slots_reference_valid_pivots<
35 PivotCount,
36 type_list<Tail...>
37 >::value
38 >
39{
40};
41
42template <typename PivotList>
43struct rule_has_operation_pivot;
44
45template <>
46struct rule_has_operation_pivot<type_list<>>
47 : std::false_type
48{
49};
50
51template <typename Head, typename... Tail>
52struct rule_has_operation_pivot<type_list<Head, Tail...>>
53 : std::integral_constant<
54 bool,
55 Head::source == type_pivot_source::operation ||
56 rule_has_operation_pivot<type_list<Tail...>>::value
57 >
58{
59};
60
61} // namespace detail
62
94template <typename Pivots, typename Outputs, typename Inputs>
95struct operand_type_rule
96{
97 using pivot_list_type = Pivots;
98 using output_slot_list_type = Outputs;
99 using input_slot_list_type = Inputs;
100
101 static REXLIB_CONST_CONSTEXPR std::size_t pivot_count =
102 type_list_size<Pivots>::value;
103 static REXLIB_CONST_CONSTEXPR std::size_t output_count =
104 type_list_size<Outputs>::value;
105 static REXLIB_CONST_CONSTEXPR std::size_t input_count =
106 type_list_size<Inputs>::value;
107
111 static REXLIB_CONST_CONSTEXPR bool requires_parameters =
112 detail::rule_has_operation_pivot<Pivots>::value;
113
114 static_assert(
115 pivot_count > 0,
116 "An operand type rule must declare at least one pivot. With no free "
117 "variable there is nothing for the backend to dispatch on."
118 );
119
121 pivot_count <= max_type_pivot_count,
122 "An operand type rule declares more pivots than a resolution can "
123 "hold. Raise max_type_pivot_count if this is genuinely "
124 "needed."
125 );
126
127 static_assert(
128 detail::slots_reference_valid_pivots<pivot_count, Outputs>::value,
129 "An output slot refers to a pivot the rule does not declare."
130 );
131
132 static_assert(
133 detail::slots_reference_valid_pivots<pivot_count, Inputs>::value,
134 "An input slot refers to a pivot the rule does not declare."
135 );
136};
137
138} // namespace rexlib
Container for multidimensional numeric data.
Definition array.hpp:31
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10
Definition operand_type_rule.hpp:21
Helper class to pass a heterogeneous sequence of types to a function.
Definition type_list.hpp:20