5#include <rexlib/core/operation/shape_rule/core_dimensions.hpp>
6#include <rexlib/core/operation/shape_rule/core_placement.hpp>
7#include <rexlib/core/operation/shape_rule/extent_pivot.hpp>
8#include <rexlib/core/operation/shape_rule/extent_slot.hpp>
9#include <rexlib/core/operation/shape_rule/output_batch.hpp>
10#include <rexlib/core/operation/shape_rule/same_extent_transform.hpp>
11#include <rexlib/core/operation/shape_rule/trailing_core.hpp>
13#include <rexlib/core/meta/type_list.hpp>
14#include <rexlib/core/platform/constexpr.hpp>
26template <
bool... Values>
32 shape_rule_bool_pack<true, Values...>,
33 shape_rule_bool_pack<Values..., true>
40 : std::integral_constant<bool, !shape_rule_all_of<(!Values)...>::value>
44template <std::
size_t PivotCount,
typename SlotList>
53template <std::size_t PivotCount, typename Core>
54struct core_names_declared_extents
55 : slots_name_declared_pivots<PivotCount, typename Core::slot_list_type>
59template <std::size_t PivotCount, typename Cores>
60struct cores_name_declared_extents;
62template <std::size_t PivotCount, typename... Cores>
63struct cores_name_declared_extents<PivotCount, type_list<Cores...>>
65 core_names_declared_extents<PivotCount, Cores>::value...
70template <std::size_t Extent, typename SlotList>
71struct slots_bind_extent;
73template <std::size_t Extent, typename... Slots>
74struct slots_bind_extent<Extent, type_list<Slots...>>
76 Slots::pivot_index == Extent &&
78 typename Slots::transform_type,
85template <std::size_t Extent, typename Core>
86struct core_binds_extent
87 : slots_bind_extent<Extent, typename Core::slot_list_type>
91template <std::size_t Extent, typename Cores>
92struct cores_bind_extent;
94template <std::size_t Extent, typename... Cores>
95struct cores_bind_extent<Extent, type_list<Cores...>>
96 : shape_rule_any_of<core_binds_extent<Extent, Cores>::value...>
100template <typename Extents, typename InputCores, typename Indices>
101struct input_extents_bound;
103template <typename... Extents, typename InputCores, std::size_t... Indices>
104struct input_extents_bound<
105 type_list<Extents...>,
107 std::index_sequence<Indices...>
109 : shape_rule_all_of<(
110 Extents::source != extent_pivot_source::inputs ||
111 cores_bind_extent<Indices, InputCores>::value
116template <typename Extents>
117struct extents_from_operation;
119template <typename... Extents>
120struct extents_from_operation<type_list<Extents...>>
121 : shape_rule_any_of<(Extents::source == extent_pivot_source::operation)...>
125template <typename Cores>
126struct cores_without_run;
128template <typename... Cores>
129struct cores_without_run<type_list<Cores...>>
130 : shape_rule_all_of<(!Cores::has_run)...>
134template <typename Cores>
137template <typename... Cores>
138struct cores_empty<type_list<Cores...>>
139 : shape_rule_all_of<(Cores::axis_count == 0 && !Cores::has_run)...>
143template <typename Core>
144struct core_carries_axes
145 : std::integral_constant<bool, (Core::axis_count > 0 || Core::has_run)>
149template <
typename Cores>
152template <
typename...
Cores>
158template <
typename Cores>
164template <
typename First,
typename...
Rest>
167 using type =
typename std::conditional<
174template <std::
size_t AxisCount,
bool HasRun,
typename Cores>
180 (Cores::axis_count == 0 && !Cores::has_run) ||
181 (Cores::axis_count == AxisCount && Cores::has_run == HasRun)
186template <
typename Reference,
typename Inputs,
typename Outputs>
188 : std::integral_constant<
190 cores_empty_or_alike<
191 Reference::axis_count,
195 cores_empty_or_alike<
196 Reference::axis_count,
204template <
typename Inputs,
typename Outputs>
210template <
typename Outputs,
typename Inputs,
typename Indices>
216 typename type_list_element<Indices, Outputs>::type,
217 typename type_list_element<Indices, Inputs>::type
234template <
typename Outputs,
typename Inputs>
239 std::make_index_sequence<type_list_size<Outputs>::value>
244template <
typename Inputs,
typename Outputs>
247 typename first_core_carrying_axes<Inputs>::type,
296 static REXLIB_CONST_CONSTEXPR std::size_t pivot_count =
298 static REXLIB_CONST_CONSTEXPR std::size_t output_count =
300 static REXLIB_CONST_CONSTEXPR std::size_t input_count =
312 "A shape rule declares more extent variables than a resolution can "
313 "hold. Raise max_extent_pivot_count if this is genuinely needed."
319 "A core axis names an extent variable the rule does not declare."
326 std::make_index_sequence<pivot_count>
328 "An extent variable bound by the inputs is not carried untransformed "
329 "by any input axis, so nothing determines it."
338 "A run is as long as the axes the operation instance names, so only "
339 "a rule whose core axes are named may declare one."
345 "A rule whose core axes are named needs an input carrying them."
351 "Under named placement every core carrying the named axes must "
352 "declare as many axes and runs as the others."
362 "Only an operation without core axes may write into outputs larger "
363 "than its inputs broadcast to."
372 "An output accumulating into an input needs core axes that lie last "
373 "and an input at its position declaring the same core."
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
REXLIB_INLINE_CONST_CONSTEXPR std::size_t max_extent_pivot_count
Maximum number of extent variables a shape rule may declare.
Definition extent_pivot.hpp:23
output_batch
Which batch axes an output supplied in advance may have.
Definition output_batch.hpp:12
@ exact
Exactly those the inputs broadcast to.
@ accumulated
Those of the input at the same position, its accumulator.
@ broadcast_target
Any the inputs broadcast to, shared by every output.
@ named
The axes the operation instance names.
@ trailing
The last axes of every operand.
Definition operand_shape_rule.hpp:146
Definition operand_shape_rule.hpp:231
Definition operand_shape_rule.hpp:201
Definition operand_shape_rule.hpp:150
Definition operand_shape_rule.hpp:175
Definition operand_shape_rule.hpp:135
Definition operand_shape_rule.hpp:60
Definition operand_shape_rule.hpp:211
Definition operand_shape_rule.hpp:126
Definition operand_shape_rule.hpp:117
Definition operand_shape_rule.hpp:160
Definition operand_shape_rule.hpp:251
Definition operand_shape_rule.hpp:35
Definition operand_shape_rule.hpp:41
Definition operand_shape_rule.hpp:27
Definition operand_shape_rule.hpp:45
Declarative shape rule for the operands of an operation.
Definition operand_shape_rule.hpp:288
static REXLIB_CONST_CONSTEXPR bool requires_parameters
Whether the rule reads values of the operation instance.
Definition operand_shape_rule.hpp:306
Placement of the core axes at the end of every operand.
Definition trailing_core.hpp:20
Utility class to obtain the size of a type_list.
Definition type_list.hpp:28
Helper class to pass a heterogeneous sequence of types to a function.
Definition type_list.hpp:20