lib/accy/src/validation/composition/fixture.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const choir = @import("choir");
3 const accy = @import("accy");
4 const executable = accy.executable;
5 const revision = choir.product.revision;
6 const operation = choir.product.operation;
7
8 pub const configuration = operation.Configuration{
9 .context = choir.ir.Context.Limits.testing,
10 .register = registerContext,
11 .registration = .{ .name = "hybrid-composition-test-context", .version = 1 },
12 .codec = .{ .operations = 1000, .entities = 10000, .fields = 10000, .depth = 64 },
13 .image = .{ .bytes = 1024 * 1024, .entities = 10000, .depth = 64 },
14 .roots = 1,
15 .gate_scratch = 64 * 1024 * 1024,
16 .verify = choir.ir.verify.default_options,
17 };
18
19 pub const artifact_workspace_bytes = 256 * 1024 * 1024;
20
21 fn registerContext(context: *choir.ir.Context) !void {
22 try choir.dialects.registerChoirDialect(context);
23 try accy.choir.registerAccyDialect(context);
24 try choir.backends.gpu.registerTargetDialects(context);
25 }
26
27 pub fn request(source: []const u8, workspace: []u8) executable.FragmentCompilationRequest {
28 return .{
29 .source = source,
30 .work = .{
31 .allowance = revision.WorkVector.uniform(std.math.maxInt(u64)),
32 .workspace = 512 * 1024 * 1024,
33 .events = 256,
34 },
35 .record_bytes = 32 * 1024 * 1024,
36 .artifact_workspace = workspace,
37 };
38 }
39
40 pub fn capture(
41 allocator: std.mem.Allocator,
42 root: *choir.ir.Operation,
43 address: revision.record.Address,
44 ) !operation.Product {
45 const store = try revision.Store.create(allocator, .{
46 .revisions = 1,
47 .kinds = 1,
48 .builders = 1,
49 .compiler_manifests = 2,
50 .record_bytes = 32 * 1024 * 1024,
51 .gate_scratch_bytes = configuration.gate_scratch,
52 .candidate_count = 1,
53 .screening_bytes = 32 * 1024 * 1024,
54 });
55 defer store.release();
56 const kind = try operation.registerKind(allocator, store, configuration, .{
57 .name = "composition-input",
58 .version = 1,
59 }, &.{});
60 store.freeze();
61 const policy = try choir.product.recipe.encode(allocator, .{
62 .arithmetic = root.context.arithmetic_policy,
63 .policy = "composition-input",
64 });
65 defer allocator.free(policy);
66 const builder = try store.begin(.{
67 .kind = kind,
68 .address = address,
69 .inputs = .{
70 .compiler_manifest = try choir.product.compiler.manifest(),
71 .versions = &.{operation.schema_identity},
72 .pipeline = &.{},
73 .options = "",
74 .policy = policy,
75 },
76 }, request(address.source, &.{}).work);
77 var open = true;
78 defer if (open) {
79 if (builder.abort(.rejected)) |failure| {
80 var owned = failure;
81 owned.deinit();
82 }
83 };
84 try operation.capture(builder, &.{.{ .operation = root }}, "", &.{}, configuration);
85 const result = try operation.Product.seal(builder, kind);
86 open = false;
87 return result;
88 }