ruprim/reduce/routines/blueprint.rs
1use crate::reduce::{BoundChecks, IdleMode, VectorizationMode};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub struct ReduceBlueprint {
5 /// How vectorization was applied.
6 pub vectorization_mode: VectorizationMode,
7 /// The global blueprint for the kernel.
8 pub global: GlobalReduceBlueprint,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub enum GlobalReduceBlueprint {
13 Unit(UnitReduceBlueprint),
14 Plane(PlaneReduceBlueprint),
15 Ruda(RudaBlueprint),
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19/// A single ruda reduces a full vector.
20pub struct RudaBlueprint {
21 /// When too many rudas are spawned, we should put some to idle.
22 ///
23 /// # Notes
24 ///
25 /// This only happens when we hit the hardware limit in spawning rudas on a single axis.
26 pub ruda_idle: IdleMode,
27 /// There are too many units in a ruda causing out-of-bound.
28 ///
29 /// # Notes
30 ///
31 /// There are never too many rudas spawned.
32 pub bound_checks: BoundChecks,
33 /// The number of accumulators in shared memory.
34 pub num_shared_accumulators: usize,
35 /// Whether we use plane instructions to merge accumulators.
36 pub use_planes: bool,
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
40pub enum PlaneMergeStrategy {
41 /// All units in a plane work independently during the reduction
42 /// but merge their accumulators at the end
43 Lazy,
44 /// There is a plane reduction at each iteration
45 Eager,
46}
47
48/// A single plane reduces a full vector.
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
50pub struct PlaneReduceBlueprint {
51 /// Too many planes are spawned, we should put some to idle.
52 pub plane_idle: IdleMode,
53 /// There are too many units in a plane causing out-of-bound.
54 pub bound_checks: BoundChecks,
55 /// Whether we recombine accumulators at each iteration or at the end only
56 pub plane_merge_strategy: PlaneMergeStrategy,
57 /// If true, we ceil the used ruda_dim x to runtime plane_dim
58 pub plane_dim_ceil: bool,
59}
60
61/// A single unit reduces a full vector.
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
63pub struct UnitReduceBlueprint {
64 // Too many units are spawned, we should put some to idle.
65 pub unit_idle: IdleMode,
66}