lib/accy/src/kernel/model/core/limits.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

  1 const choir = @import("choir");
  2 const schedule = @import("schedule/root.zig");
  3 
  4 pub const RawLimits = struct {
  5     context: choir.ir.Context.Limits,
  6     parameters: usize,
  7     kernel_name_bytes: usize,
  8     temporary_values: usize,
  9     temporary_types: usize,
 10 
 11     pub const standard: RawLimits = .{
 12         .context = choir.ir.Context.Limits.standard,
 13         .parameters = 64,
 14         .kernel_name_bytes = 512,
 15         .temporary_values = 64,
 16         .temporary_types = 64,
 17     };
 18 
 19     pub const testing: RawLimits = .{
 20         .context = choir.ir.Context.Limits.testing,
 21         .parameters = 256,
 22         .kernel_name_bytes = 2048,
 23         .temporary_values = 256,
 24         .temporary_types = 256,
 25     };
 26 
 27     pub const borrowed_standard: RawLimits = .{
 28         .context = borrowedContextLimits(false),
 29         .parameters = 64,
 30         .kernel_name_bytes = 512,
 31         .temporary_values = 64,
 32         .temporary_types = 64,
 33     };
 34 
 35     pub const borrowed_testing: RawLimits = .{
 36         .context = borrowedContextLimits(true),
 37         .parameters = 256,
 38         .kernel_name_bytes = 2048,
 39         .temporary_values = 256,
 40         .temporary_types = 256,
 41     };
 42 };
 43 
 44 pub const Limits = struct {
 45     context: choir.ir.Context.Limits,
 46     parameters: usize,
 47     kernel_name_bytes: usize,
 48     temporary_values: usize,
 49     temporary_types: usize,
 50     schedule: schedule.Schedule.Limits,
 51     snapshot: schedule.Snapshot.Limits,
 52 
 53     pub const standard: Limits = fromRaw(
 54         RawLimits.standard,
 55         schedule.Schedule.Limits.standard,
 56         schedule.Snapshot.Limits.standard,
 57     );
 58 
 59     pub const testing: Limits = fromRaw(
 60         RawLimits.testing,
 61         schedule.Schedule.Limits.testing,
 62         schedule.Snapshot.Limits.testing,
 63     );
 64 
 65     pub const borrowed_standard: Limits = fromRaw(
 66         RawLimits.borrowed_standard,
 67         schedule.Schedule.Limits.standard,
 68         schedule.Snapshot.Limits.standard,
 69     );
 70 
 71     pub const borrowed_testing: Limits = fromRaw(
 72         RawLimits.borrowed_testing,
 73         schedule.Schedule.Limits.testing,
 74         schedule.Snapshot.Limits.testing,
 75     );
 76 
 77     pub fn raw(self: Limits) RawLimits {
 78         return .{
 79             .context = self.context,
 80             .parameters = self.parameters,
 81             .kernel_name_bytes = self.kernel_name_bytes,
 82             .temporary_values = self.temporary_values,
 83             .temporary_types = self.temporary_types,
 84         };
 85     }
 86 
 87     fn fromRaw(
 88         raw_limits: RawLimits,
 89         schedule_limits: schedule.Schedule.Limits,
 90         snapshot_limits: schedule.Snapshot.Limits,
 91     ) Limits {
 92         return .{
 93             .context = raw_limits.context,
 94             .parameters = raw_limits.parameters,
 95             .kernel_name_bytes = raw_limits.kernel_name_bytes,
 96             .temporary_values = raw_limits.temporary_values,
 97             .temporary_types = raw_limits.temporary_types,
 98             .schedule = schedule_limits,
 99             .snapshot = snapshot_limits,
100         };
101     }
102 };
103 
104 fn borrowedContextLimits(comptime testing_limits: bool) choir.ir.Context.Limits {
105     const scale: usize = if (testing_limits) 4 else 1;
106     return .{
107         .maximum_alignment = .@"64",
108         .configuration = .{
109             .table_bytes = 16 * 1024 * scale,
110             .name_bytes = 8 * 1024 * scale,
111             .interface_bytes = 16 * 1024 * scale,
112             .transaction_bytes = 8 * 1024 * scale,
113         },
114         .types = .{
115             .table_bytes = 32 * 1024 * scale,
116             .key_bytes = 32 * 1024 * scale,
117             .payload_bytes = 32 * 1024 * scale,
118         },
119         .attributes = .{
120             .table_bytes = 64 * 1024 * scale,
121             .payload_bytes = 64 * 1024 * scale,
122         },
123         .operations = .{
124             .storage_bytes = 512 * 1024 * scale,
125             .nested_bytes = 512 * 1024 * scale,
126         },
127         .diagnostics = .{
128             .handler_bytes = 4 * 1024 * scale,
129             .payload_bytes = 16 * 1024 * scale,
130         },
131         .transient_bytes = 64 * 1024 * scale,
132     };
133 }