tiny.accy.kernel.library.random.base.artifact_product
Defined in kernel.library.random.base.
API (40)
Actions
Public operations.
KernelCallArtifact.scalarArgumentCount: Scalar arguments the entry's kernel takes, runtime and static together.KernelCallDerivedLaunch.geometryKernelCallDerivedLaunchAxis.extentKernelCallRegistry.findKernelCallRegistryIndex.findEntryIndexKernelCallShapeProfile.dimensionKernelCallShapeProfile.runtimeScalarDimensionKernelCallShapeProfile.validatebuildKernelCallRegistryIndexdefaultArtifactFormatdeinitKernelCallRegistryIndexdeinitKernelCallShapeProfileduplicateKernelCallShapeProfilefindPipelinekernelCallShapeProfileEqlvalidateThreadgroup
Types and contracts
Public types and contracts.
ArtifactPlanOptionsElementCountArgumentKernelCallArtifact: Records one prebuilt kernel in a registry, found by the triple of target name, for example "accy.kernel.linalg.matmul5x7x34x2f32", itsversion, and its artifact format, so compiled programs can call it by name.KernelCallDerivedLaunchKernelCallDerivedLaunchAxisKernelCallDerivedLaunchAxis.RuntimeU32CeilDivKernelCallLaunchKernelCallPipeline: An ordered list of stages under one target name and version, so a caller describes a multi-kernel computation and hands it to the loader and launcher.KernelCallRegistryKernelCallRegistryIndexKernelCallRegistryIndexErrorKernelCallRegistryIndexSlotKernelCallShapeProfileKernelCallShapeProfileBoundsKernelCallShapeProfileDimensionOwnedKernelCallPipelinePipelineIntermediatePipelineRuntimeScalarBoundPipelineScalarDerivationPipelineStagePipelineValueRefStandaloneKernelOptions
Namespaces
Public namespaces.
pipelinewire: A byte encoding for a table of prebuilt kernels and the chains of kernels that call them, with a writer that produces the bytes and a reader that checks them and builds the table again.
Source
Source: lib/accy/src/artifact/model/registry.zig:8
pub const ArtifactPlanOptions = struct { format: ?gpu.ArtifactFormat = null, kernel_call_registry: ?*const KernelCallRegistry = null,};Source: lib/accy/src/artifact/model/registry.zig:13
pub const ElementCountArgument = enum { none, scalar_u32, device_buffer_u32,};Source: lib/accy/src/artifact/model/registry.zig:125
/// Records one prebuilt kernel in a registry, found by the triple of target/// name, for example "accy.kernel.linalg.matmul5x7x3_4x2_f32", its `version`,/// and its artifact format, so compiled programs can call it by name. The entry/// also records its entry point name, argument count, required element types,/// device features, code payload, launch rule, static arguments, and optional/// named dimensions. The `version` field stands for what the kernel computes/// and is separate from the byte-layout version of the registry file. A/// maintainer raises `version` before an existing entry changes its math, the/// meaning of its element types or memory layout, its argument list, its static/// arguments, how its launch is derived, what its shape profile means, or its/// schedule. A change that touches only the registry file's byte layout, or/// that keeps behavior unchanged, leaves `version` as it is, because the/// registry file carries its own layout version. A family target names one/// reusable schedule, and sizes that leave that schedule unchanged arrive at/// launch as bounded runtime scalar arguments.pub const KernelCallArtifact = struct { target: []const u8, version: u32, format: gpu.ArtifactFormat, entry_name: []const u8, argument_count: u32, shape_family_fingerprint: ?u64 = null, shape_profile: ?KernelCallShapeProfile = null, required_dtypes: gpu.DTypeSet = .{}, required_features: choir_abi.Features = .{}, required_subgroup: choir_abi.SubgroupRequirements = .{}, /// Layout the emitter gave the entry's push-constant block, if any. push_constants: choir_abi.PushConstants = .{}, payload: gpu.CompilePayload, launch: KernelCallLaunch = .{ .derived = .{} }, element_count_argument: ElementCountArgument = .none, runtime_scalar_argument_count: u32 = 0, static_arguments: []const choir_abi.ScalarArgument = &.{}, /// Scalar arguments the entry's kernel takes, runtime and static /// together. The rest of `argument_count` are buffers. pub fn scalarArgumentCount(self: KernelCallArtifact) gpu.BackendError!u32 { const static_count = std.math.cast(u32, self.static_arguments.len) orelse return error.InvalidArtifact; const count = std.math.add(u32, self.runtime_scalar_argument_count, static_count) catch return error.InvalidArtifact; if (count > self.argument_count) return error.InvalidArtifact; return count; }};Source: lib/accy/src/artifact/model/registry.zig:43
pub const KernelCallDerivedLaunch = struct { grid: [3]KernelCallDerivedLaunchAxis = .{ .{ .fixed = 1 }, .{ .fixed = 1 }, .{ .fixed = 1 }, }, threadgroup: [3]u32 = .{ 1, 1, 1 }, dynamic_shared_memory_bytes: u32 = 0, pub fn geometry( self: KernelCallDerivedLaunch, runtime_scalar_arguments: []const choir_abi.ScalarArgument, ) gpu.BackendError!choir_abi.LaunchGeometry { return .{ .grid = .{ try self.grid[0].extent(runtime_scalar_arguments), try self.grid[1].extent(runtime_scalar_arguments), try self.grid[2].extent(runtime_scalar_arguments), }, .threadgroup = try validateThreadgroup(self.threadgroup), .dynamic_shared_memory_bytes = self.dynamic_shared_memory_bytes, }; }};Source: lib/accy/src/artifact/model/registry.zig:23
pub const KernelCallDerivedLaunchAxis = union(enum) { fixed: u32, runtime_u32_ceil_div: RuntimeU32CeilDiv, pub const RuntimeU32CeilDiv = struct { argument_index: u32, divisor: u32 = 1, }; pub fn extent( self: KernelCallDerivedLaunchAxis, runtime_scalar_arguments: []const choir_abi.ScalarArgument, ) gpu.BackendError!u32 { return switch (self) { .fixed => |value| if (value == 0) error.InvalidArtifact else value, .runtime_u32_ceil_div => |axis| runtimeU32CeilDiv(runtime_scalar_arguments, axis), }; }};Source: lib/accy/src/artifact/model/registry.zig:18
pub const KernelCallLaunch = union(enum) { derived: KernelCallDerivedLaunch, fixed: choir_abi.LaunchGeometry,};Source: lib/accy/src/artifact/model/registry.zig:191
pub const KernelCallRegistry = struct { entries: []const KernelCallArtifact = &.{}, index: ?KernelCallRegistryIndex = null, pub fn find( self: KernelCallRegistry, target: []const u8, version: u32, format: gpu.ArtifactFormat, ) ?KernelCallArtifact { if (self.index) |index| { const entry_index = index.findEntryIndex(target, version, format) orelse return null; if (entry_index >= self.entries.len) return null; return self.entries[entry_index]; } for (self.entries) |entry| { if (entry.version != version) continue; if (entry.format != format) continue; if (!std.mem.eql(u8, entry.target, target)) continue; return entry; } return null; }};Source: lib/accy/src/artifact/model/registry.zig:169
pub const KernelCallRegistryIndex = struct { slots: []const KernelCallRegistryIndexSlot = &.{}, pub fn findEntryIndex( self: KernelCallRegistryIndex, target: []const u8, version: u32, format: gpu.ArtifactFormat, ) ?usize { if (self.slots.len == 0) return null; var slot_index = kernelCallRegistrySlotIndex(self.slots.len, target, version, format); var probe_count: usize = 0; while (probe_count < self.slots.len) : (probe_count += 1) { const slot = self.slots[slot_index]; if (!slot.occupied) return null; if (kernelCallRegistryKeyMatches(slot, target, version, format)) return slot.entry_index; slot_index = (slot_index + 1) & (self.slots.len - 1); } return null; }};Source: lib/accy/src/artifact/model/registry.zig:161
pub const KernelCallRegistryIndexSlot = struct { occupied: bool = false, target: []const u8 = &.{}, version: u32 = 0, format: gpu.ArtifactFormat = .cuda_ptx, entry_index: usize = 0,};Source: lib/accy/src/artifact/model/registry.zig:76
pub const KernelCallShapeProfile = struct { name: []const u8, fingerprint: u64, dimensions: []const KernelCallShapeProfileDimension = &.{}, pub fn validate(self: KernelCallShapeProfile, runtime_scalar_argument_count: u32) gpu.BackendError!void { if (self.name.len == 0) return error.InvalidArtifact; if (self.dimensions.len == 0) return error.InvalidArtifact; for (self.dimensions, 0..) |item, index| { if (item.name.len == 0) return error.InvalidArtifact; if (item.runtime_scalar_argument_index >= runtime_scalar_argument_count) return error.InvalidArtifact; if (!item.bounds.valid()) return error.InvalidArtifact; for (self.dimensions[0..index]) |previous| { if (previous.runtime_scalar_argument_index == item.runtime_scalar_argument_index) return error.InvalidArtifact; if (std.mem.eql(u8, previous.name, item.name)) return error.InvalidArtifact; } } } pub fn dimension(self: KernelCallShapeProfile, name: []const u8) ?KernelCallShapeProfileDimension { for (self.dimensions) |item| { if (std.mem.eql(u8, item.name, name)) return item; } return null; } pub fn runtimeScalarDimension(self: KernelCallShapeProfile, index: u32) ?KernelCallShapeProfileDimension { for (self.dimensions) |item| { if (item.runtime_scalar_argument_index == index) return item; } return null; }};Source: lib/accy/src/artifact/model/registry.zig:70
pub const KernelCallShapeProfileDimension = struct { name: []const u8, runtime_scalar_argument_index: u32, bounds: KernelCallShapeProfileBounds,};Source: lib/accy/src/artifact/model/registry.zig:156
pub const StandaloneKernelOptions = struct { runtime_scalar_argument_count: u32 = 0, static_arguments: []const choir_abi.ScalarArgument = &.{},};Source: lib/accy/src/artifact/model/registry.zig:216
pub const KernelCallRegistryIndexError = error{ DuplicateKernelCallArtifact,} || std.mem.Allocator.Error;Source: lib/accy/src/artifact/model/registry.zig:220
pub fn buildKernelCallRegistryIndex( allocator: std.mem.Allocator, entries: []const KernelCallArtifact,) KernelCallRegistryIndexError!KernelCallRegistryIndex { if (entries.len == 0) return .{}; const slots = try allocator.alloc(KernelCallRegistryIndexSlot, try kernelCallRegistryIndexCapacity(entries.len)); @memset(slots, .{}); const index = KernelCallRegistryIndex{ .slots = slots }; errdefer deinitKernelCallRegistryIndex(allocator, index); for (entries, 0..) |entry, entry_index| try insertKernelCallRegistryIndexEntry(slots, entry, entry_index); return index;}Source: lib/accy/src/artifact/model/registry.zig:432
pub fn defaultArtifactFormat(kind: gpu.BackendKind) ?gpu.ArtifactFormat { return switch (kind) { .cuda => .cuda_ptx, .vulkan => .vulkan_spirv, .metal => .metal_msl, .webgpu => .webgpu_wgsl, .cpu => .cpu_object, .wasm => .webassembly_module, else => null, };}Source: lib/accy/src/artifact/model/registry.zig:233
pub fn deinitKernelCallRegistryIndex( allocator: std.mem.Allocator, index: KernelCallRegistryIndex,) void { if (index.slots.len != 0) allocator.free(@constCast(index.slots));}Source: lib/accy/src/artifact/model/registry.zig:381
pub fn deinitKernelCallShapeProfile( allocator: std.mem.Allocator, profile: KernelCallShapeProfile,) void { allocator.free(profile.name); for (profile.dimensions) |dimension| allocator.free(dimension.name); allocator.free(profile.dimensions);}Source: lib/accy/src/artifact/model/registry.zig:357
pub fn duplicateKernelCallShapeProfile( allocator: std.mem.Allocator, profile: KernelCallShapeProfile,) !KernelCallShapeProfile { const name = try allocator.dupe(u8, profile.name); errdefer allocator.free(name); const dimensions = try allocator.alloc(KernelCallShapeProfileDimension, profile.dimensions.len); var copied_count: usize = 0; errdefer { for (dimensions[0..copied_count]) |dimension| allocator.free(dimension.name); allocator.free(dimensions); } for (profile.dimensions, dimensions) |source, *destination| { destination.* = source; destination.name = try allocator.dupe(u8, source.name); copied_count += 1; } return .{ .name = name, .fingerprint = profile.fingerprint, .dimensions = dimensions, };}Source: lib/accy/src/artifact/model/registry.zig:390
pub fn kernelCallShapeProfileEql(lhs: ?KernelCallShapeProfile, rhs: ?KernelCallShapeProfile) bool { if (lhs == null and rhs == null) return true; if (lhs == null or rhs == null) return false; return kernelCallShapeProfileValueEql(lhs.?, rhs.?);}Source: lib/accy/src/artifact/model/registry.zig:425
pub fn validateThreadgroup(threadgroup: [3]u32) gpu.BackendError![3]u32 { for (threadgroup) |extent| { if (extent == 0) return error.InvalidArtifact; } return threadgroup;}Source: lib/accy/src/artifact/model/registry.zig:68
pub const KernelCallShapeProfileBounds = accy_choir.shape.Bounds;Source: lib/accy/src/artifact/model/root.zig
const registry = @import("registry.zig");pub const pipeline = @import("pipeline.zig");pub const wire = @import("wire.zig");pub const ArtifactPlanOptions = registry.ArtifactPlanOptions;pub const ElementCountArgument = registry.ElementCountArgument;pub const KernelCallLaunch = registry.KernelCallLaunch;pub const KernelCallDerivedLaunchAxis = registry.KernelCallDerivedLaunchAxis;pub const KernelCallDerivedLaunch = registry.KernelCallDerivedLaunch;pub const KernelCallShapeProfileBounds = registry.KernelCallShapeProfileBounds;pub const KernelCallShapeProfileDimension = registry.KernelCallShapeProfileDimension;pub const KernelCallShapeProfile = registry.KernelCallShapeProfile;pub const KernelCallArtifact = registry.KernelCallArtifact;pub const StandaloneKernelOptions = registry.StandaloneKernelOptions;pub const KernelCallRegistryIndexSlot = registry.KernelCallRegistryIndexSlot;pub const KernelCallRegistryIndex = registry.KernelCallRegistryIndex;pub const KernelCallRegistry = registry.KernelCallRegistry;pub const KernelCallRegistryIndexError = registry.KernelCallRegistryIndexError;pub const buildKernelCallRegistryIndex = registry.buildKernelCallRegistryIndex;pub const deinitKernelCallRegistryIndex = registry.deinitKernelCallRegistryIndex;pub const duplicateKernelCallShapeProfile = registry.duplicateKernelCallShapeProfile;pub const deinitKernelCallShapeProfile = registry.deinitKernelCallShapeProfile;pub const kernelCallShapeProfileEql = registry.kernelCallShapeProfileEql;pub const defaultArtifactFormat = registry.defaultArtifactFormat;pub const validateThreadgroup = registry.validateThreadgroup;pub const PipelineValueRef = pipeline.PipelineValueRef;pub const PipelineScalarDerivation = pipeline.PipelineScalarDerivation;pub const PipelineIntermediate = pipeline.PipelineIntermediate;pub const PipelineRuntimeScalarBound = pipeline.PipelineRuntimeScalarBound;pub const PipelineStage = pipeline.PipelineStage;pub const KernelCallPipeline = pipeline.KernelCallPipeline;pub const findPipeline = pipeline.findPipeline;pub const OwnedKernelCallPipeline = pipeline.OwnedKernelCallPipeline;Source: lib/accy/src/kernel/library/random/base.zig:4
pub const artifact_product = @import("../../../artifact/model/root.zig");Audit
| Definitions | 31 |
|---|---|
| Public names | 58 |
| Members | 46 |
| Version | 26.7.0 |
| Revision | daab053ee433 |