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