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