lib/accy/src/kernel/library/histogram/family/shape.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2
3 const accy = @import("../../../../root.zig");
4 const artifact = @import("../../../../artifact/model/root.zig");
5 const library = @import("../../root.zig");
6 const model = @import("model.zig");
7
8 const extent = library.extent;
9 const shape = accy.choir.shape;
10 const Histogram = model.Histogram;
11
12 pub fn histogramShapeFamily(backing_allocator: std.mem.Allocator, instance: Histogram) !shape.Family {
13 var builder = try shape.Builder.init(backing_allocator, "histogram");
14 errdefer builder.deinit();
15
16 const bin = try builder.symbol(instance.bin_axis);
17 const element = try builder.symbol(instance.element_axis);
18 const bin_expr = try builder.symbolExpression(bin);
19 const element_expr = try builder.symbolExpression(element);
20
21 _ = try builder.tensor("dst", &.{bin_expr});
22 _ = try builder.tensor("data", &.{element_expr});
23 try builder.assumeBounds(bin_expr, histogramRuntimeExtentBounds());
24 try builder.assumeBounds(element_expr, histogramRuntimeExtentBounds());
25
26 return builder.finish();
27 }
28
29 pub fn histogramRuntimeExtentBounds() shape.Bounds {
30 return .{ .min = 1, .max = extent.runtime_extent_max };
31 }
32
33 pub fn histogramFamilyFingerprint(backing_allocator: std.mem.Allocator, instance: Histogram) !u64 {
34 var family = try histogramShapeFamily(backing_allocator, instance);
35 defer family.deinit();
36 return shape.fingerprint(family);
37 }
38
39 pub fn histogramShapeProfileDimensions(instance: Histogram) [2]artifact.KernelCallShapeProfileDimension {
40 const bounds = histogramRuntimeExtentBounds();
41 return .{
42 .{ .name = instance.bin_axis, .runtime_scalar_argument_index = 0, .bounds = bounds },
43 .{ .name = instance.element_axis, .runtime_scalar_argument_index = 1, .bounds = bounds },
44 };
45 }