lib/accy/src/kernel/library/random/squares/artifact.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const random = @import("../root.zig");
2 const model = @import("model.zig");
3 const runtime = @import("runtime.zig");
4
5 const base = random.base;
6 const std = base.std;
7 const artifact_product = base.artifact_product;
8 const entry = base.entry;
9 const kernel = base.kernel;
10
11 const Squares = model.Squares;
12 const SquaresRuntimeFamilyF32 = runtime.SquaresRuntimeFamilyF32;
13 const SquaresRuntimeFamilyI32 = runtime.SquaresRuntimeFamilyI32;
14 const squares_family_version = model.squares_family_version;
15 const squaresFamilyTarget = model.squaresFamilyTarget;
16 const squaresFamilyEntryName = model.squaresFamilyEntryName;
17 const squaresFamilyFingerprint = model.squaresFamilyFingerprint;
18 const squaresShapeProfileDimensions = model.squaresShapeProfileDimensions;
19 const randomFoldDerivedLaunch = base.randomFoldDerivedLaunch;
20
21 pub fn createSquaresFamilyArtifact(
22 allocator: std.mem.Allocator,
23 handle: kernel.BackendHandle,
24 instance: Squares,
25 options: entry.ArtifactOptions,
26 ) !kernel.OwnedKernelCallArtifact {
27 const target = try squaresFamilyTarget(allocator, instance);
28 defer allocator.free(target);
29 const entry_name = try squaresFamilyEntryName(allocator, instance);
30 defer allocator.free(entry_name);
31 const family_fingerprint = options.shape_family_fingerprint orelse try squaresFamilyFingerprint(allocator, instance);
32 const shape_profile_dimensions = squaresShapeProfileDimensions(instance);
33 const shape_profile = options.shape_profile orelse artifact_product.KernelCallShapeProfile{
34 .name = "squares",
35 .fingerprint = family_fingerprint,
36 .dimensions = shape_profile_dimensions[0..],
37 };
38
39 var graph = switch (instance.dtype) {
40 .f32 => try SquaresRuntimeFamilyF32.buildNamed(allocator, options.limits, entry_name, instance),
41 .i32 => try SquaresRuntimeFamilyI32.buildNamed(allocator, options.limits, entry_name, instance),
42 else => return error.UnsupportedDType,
43 };
44 defer graph.deinit();
45 return kernel.createKernelCallArtifact(allocator, handle, &graph, .{
46 .target = target,
47 .version = squares_family_version,
48 .format = options.format,
49 .kernel_plan = options.kernel_plan,
50 .element_count_argument = options.element_count_argument,
51 .shape_family_fingerprint = family_fingerprint,
52 .shape_profile = shape_profile,
53 .launch = options.launch orelse try randomFoldDerivedLaunch(instance.threads),
54 .runtime_scalar_argument_count = if (options.runtime_scalar_argument_count == 0) 3 else options.runtime_scalar_argument_count,
55 .static_arguments = options.static_arguments,
56 });
57 }