tiny.accy.kernel.library.histogram
Defined in kernel.library.
API (28)
Actions
Public operations.
createHistogramFamilyArtifacthistogramBinForValuehistogramBinningPolicyCodehistogramBinningPolicyFromCodehistogramDTypeSupportedhistogramFamilyEntryNamehistogramFamilyFingerprinthistogramFamilySpecializationhistogramFamilyTargethistogramFamilyTuningKeyhistogramInstanceFromSpecializationhistogramInstanceValidhistogramRuntimeArgumentshistogramShapeFamilyhistogramShapeProfileDimensionshistogramThreadCandidatesForCounthistogramThreadsForCounthistogramTuningExtentshistogramTuningOperationresolveHistogramSchedule
Types and contracts
Public types and contracts.
HistogramHistogramBinningPolicyHistogramResolvedScheduleHistogramRuntimeFamilyF32HistogramVariant
Values and defaults
Public values and defaults.
Source
Source: lib/accy/src/kernel/library/histogram/family/model.zig:14
pub const Histogram = struct { bins: u64, count: u64, lo: f32 = 0, width: f32 = 1, dtype: DType = .f32, binning: HistogramBinningPolicy = .lower_inclusive_upper_exclusive, variant: HistogramVariant = .direct, threads: u32 = 256, bin_axis: []const u8 = "b", element_axis: []const u8 = "n",};Source: lib/accy/src/kernel/library/histogram/family/model.zig:9
pub const HistogramVariant = enum { direct, shared_bins,};Source: lib/accy/src/kernel/library/histogram/family/tuning.zig:16
pub const HistogramResolvedSchedule = struct { variant: HistogramVariant, threads: u32,};Source: lib/accy/src/kernel/library/histogram/family/binning.zig:7
pub const policy_parameter_name = "histogram_binning_policy";Source: lib/accy/src/kernel/library/histogram/family/model.zig:51
pub fn histogramBinForValue(instance: Histogram, value: f32) ?usize { return switch (instance.binning) { .lower_inclusive_upper_exclusive => { const relative = (value - instance.lo) / instance.width; const bins_float: f32 = @floatFromInt(instance.bins); if (!(relative >= 0) or !(relative < bins_float)) return null; return @intFromFloat(relative); }, };}Source: lib/accy/src/kernel/library/histogram/family/model.zig:43
pub fn histogramBinningPolicyCode(policy: HistogramBinningPolicy) u64 { return binning.code(policy);}Source: lib/accy/src/kernel/library/histogram/family/model.zig:47
pub fn histogramBinningPolicyFromCode(value: u64) ?HistogramBinningPolicy { return binning.fromCode(value);}Source: lib/accy/src/kernel/library/histogram/family/model.zig:31
pub fn histogramDTypeSupported(dtype: DType) bool { return dtype == .f32;}Source: lib/accy/src/kernel/library/histogram/family/model.zig:35
pub fn histogramInstanceValid(instance: Histogram) bool { if (!histogramDTypeSupported(instance.dtype)) return false; if (instance.bins == 0 or instance.count == 0) return false; if (!(instance.width > 0)) return false; if (instance.variant == .shared_bins and instance.bins > histogram_shared_bins_cap) return false; return instance.threads != 0;}Source: lib/accy/src/kernel/library/histogram/family/model.zig:27
pub const histogram_family_version: u32 = 2;Source: lib/accy/src/kernel/library/histogram/family/model.zig:28
pub const histogram_shared_bins_cap: u64 = 4096;Source: lib/accy/src/kernel/library/histogram/family/naming.zig:22
pub fn histogramFamilyEntryName(allocator: std.mem.Allocator, instance: Histogram) ![]u8 { return switch (instance.variant) { .direct => std.fmt.allocPrint( allocator, "accy_kernel_histogram_histogram_family_{d}_{s}", .{ instance.threads, instance.dtype.name() }, ), .shared_bins => std.fmt.allocPrint( allocator, "accy_kernel_histogram_histogram_family_shared{d}_{d}_{s}", .{ instance.bins, instance.threads, instance.dtype.name() }, ), };}Source: lib/accy/src/kernel/library/histogram/family/naming.zig:7
pub fn histogramFamilyTarget(allocator: std.mem.Allocator, instance: Histogram) ![]u8 { return switch (instance.variant) { .direct => std.fmt.allocPrint( allocator, "accy.kernel.histogram.histogram_family_{d}_{s}", .{ instance.threads, instance.dtype.name() }, ), .shared_bins => std.fmt.allocPrint( allocator, "accy.kernel.histogram.histogram_family_shared{d}_{d}_{s}", .{ instance.bins, instance.threads, instance.dtype.name() }, ), };}Source: lib/accy/src/kernel/library/histogram/family/runtime/arguments.zig:9
pub fn histogramRuntimeArguments(instance: Histogram) ![4]choir_abi.ScalarArgument { return .{ .{ .u32 = try runtimeExtentArgument(instance.bins) }, .{ .u32 = try runtimeExtentArgument(instance.count) }, .{ .f32 = instance.lo }, .{ .f32 = instance.width }, };}Source: lib/accy/src/kernel/library/histogram/family/runtime/artifact.zig:13
pub fn createHistogramFamilyArtifact( allocator: std.mem.Allocator, handle: kernel.BackendHandle, instance: Histogram, options: entry.ArtifactOptions,) !kernel.OwnedKernelCallArtifact { if (!family.histogramInstanceValid(instance)) return error.InvalidKernelLibraryEntry; const target = try family.histogramFamilyTarget(allocator, instance); defer allocator.free(target); const entry_name = try family.histogramFamilyEntryName(allocator, instance); defer allocator.free(entry_name); const family_fingerprint = options.shape_family_fingerprint orelse try family.histogramFamilyFingerprint(allocator, instance); const shape_profile_dimensions = family.histogramShapeProfileDimensions(instance); const shape_profile = options.shape_profile orelse artifact_product.KernelCallShapeProfile{ .name = "histogram", .fingerprint = family_fingerprint, .dimensions = shape_profile_dimensions[0..], }; var graph = switch (instance.dtype) { .f32 => try body.HistogramRuntimeFamilyF32.buildNamed(allocator, options.limits, entry_name, instance), else => return error.UnsupportedDType, }; defer graph.deinit(); return kernel.createKernelCallArtifact(allocator, handle, &graph, .{ .target = target, .version = family.histogram_family_version, .format = options.format, .kernel_plan = options.kernel_plan, .element_count_argument = options.element_count_argument, .shape_family_fingerprint = family_fingerprint, .shape_profile = shape_profile, .launch = options.launch orelse try histogramDerivedLaunch(instance), .runtime_scalar_argument_count = if (options.runtime_scalar_argument_count == 0) 4 else options.runtime_scalar_argument_count, .static_arguments = options.static_arguments, });}Source: lib/accy/src/kernel/library/histogram/family/runtime/body.zig:163
pub const HistogramRuntimeFamilyF32 = histogramRuntimeFamily(.f32);Source: lib/accy/src/kernel/library/histogram/family/shape.zig:33
pub fn histogramFamilyFingerprint(backing_allocator: std.mem.Allocator, instance: Histogram) !u64 { var family = try histogramShapeFamily(backing_allocator, instance); defer family.deinit(); return shape.fingerprint(family);}Source: lib/accy/src/kernel/library/histogram/family/shape.zig:12
pub fn histogramShapeFamily(backing_allocator: std.mem.Allocator, instance: Histogram) !shape.Family { var builder = try shape.Builder.init(backing_allocator, "histogram"); errdefer builder.deinit(); const bin = try builder.symbol(instance.bin_axis); const element = try builder.symbol(instance.element_axis); const bin_expr = try builder.symbolExpression(bin); const element_expr = try builder.symbolExpression(element); _ = try builder.tensor("dst", &.{bin_expr}); _ = try builder.tensor("data", &.{element_expr}); try builder.assumeBounds(bin_expr, histogramRuntimeExtentBounds()); try builder.assumeBounds(element_expr, histogramRuntimeExtentBounds()); return builder.finish();}Source: lib/accy/src/kernel/library/histogram/family/shape.zig:39
pub fn histogramShapeProfileDimensions(instance: Histogram) [2]artifact.KernelCallShapeProfileDimension { const bounds = histogramRuntimeExtentBounds(); return .{ .{ .name = instance.bin_axis, .runtime_scalar_argument_index = 0, .bounds = bounds }, .{ .name = instance.element_axis, .runtime_scalar_argument_index = 1, .bounds = bounds }, };}Source: lib/accy/src/kernel/library/histogram/family/specialization.zig:12
pub fn histogramFamilySpecialization(backing_allocator: std.mem.Allocator, instance: Histogram) !entry.OwnedSpecialization { var owned = entry.OwnedSpecialization.init(backing_allocator); errdefer owned.deinit(); const lifetime_allocator = owned.allocator(); const inputs = try lifetime_allocator.alloc(entry.Shape, 1); inputs[0] = try entry.runtimeShape1D(lifetime_allocator, instance.element_axis, instance.count); const outputs = try lifetime_allocator.alloc(entry.Shape, 1); outputs[0] = try entry.runtimeShape1D(lifetime_allocator, instance.bin_axis, instance.bins); const static_parameters = try lifetime_allocator.alloc(entry.StaticParameter, 1); static_parameters[0] = try entry.runtimeStaticParameter( lifetime_allocator, model.histogram_binning_policy_parameter, model.histogramBinningPolicyCode(instance.binning), ); owned.value = .{ .dtype = instance.dtype, .operation = .{ .indexing = .histogram }, .inputs = inputs, .outputs = outputs, .static_parameters = static_parameters, .schedule = try entry.runtimeThreadBlocks1D(lifetime_allocator, instance.element_axis, instance.count, instance.threads), .structure = @tagName(instance.variant), }; owned.value.launch = owned.value.schedule.?.launch(); var family = try shape.histogramShapeFamily(backing_allocator, instance); errdefer family.deinit(); try owned.takeShapeFamily(&family); return owned;}Source: lib/accy/src/kernel/library/histogram/family/specialization.zig:46
pub fn histogramInstanceFromSpecialization(specialization: entry.Specialization) ?Histogram { if (!specialization.scheduleMatchesLaunch()) return null; if (!specialization.operationIs(.{ .indexing = .histogram })) return null; const dtype = specialization.dtype orelse return null; if (!model.histogramDTypeSupported(dtype)) return null; if (specialization.inputs.len != 1 or specialization.outputs.len != 1) return null; if (specialization.reductions.len != 0) return null; if (specialization.static_parameters.len != 1) return null; const binning = model.histogramBinningPolicyFromCode( specialization.staticParameterValue(model.histogram_binning_policy_parameter) orelse return null, ) orelse return null; const data = specialization.inputs[0]; const bins_shape = specialization.outputs[0]; if (data.axes.len != 1 or bins_shape.axes.len != 1) return null; const launch = specialization.launch orelse return null; if (launch.threadgroup[0] == 0) return null; const structure = specialization.structure orelse return null; const variant = std.meta.stringToEnum(HistogramVariant, structure) orelse return null; const instance = Histogram{ .bins = bins_shape.axes[0].extent, .count = data.axes[0].extent, .dtype = dtype, .binning = binning, .variant = variant, .threads = launch.threadgroup[0], .bin_axis = bins_shape.axes[0].name, .element_axis = data.axes[0].name, }; if (!model.histogramInstanceValid(instance)) return null; return instance;}Source: lib/accy/src/kernel/library/histogram/family/tuning.zig:30
pub fn histogramFamilyTuningKey( backing_allocator: std.mem.Allocator, device_fingerprint: u64, instance: Histogram,) !tuning.FamilyTuningKey { const family_fingerprint = try shape.histogramFamilyFingerprint(backing_allocator, instance); const extents = histogramTuningExtents(instance); return tuning.FamilyTuningKey.init( device_fingerprint, family_fingerprint, entry.operationFingerprint(histogramTuningOperation(instance)), instance.dtype, model.histogram_family_version, extents[0..], ) orelse unreachable;}Source: lib/accy/src/kernel/library/histogram/family/tuning.zig:76
pub fn histogramThreadCandidatesForCount(count: u64) geometry.Thread1DCandidates { return geometry.threadCandidatesForExtent(count, histogram_thread_caps);}Source: lib/accy/src/kernel/library/histogram/family/tuning.zig:72
pub fn histogramThreadsForCount(count: u64) u32 { return geometry.threadsForExtent(count, histogram_thread_caps);}Source: lib/accy/src/kernel/library/histogram/family/tuning.zig:21
pub fn histogramTuningExtents(instance: Histogram) [2]u64 { return .{ instance.bins, instance.count };}Source: lib/accy/src/kernel/library/histogram/family/tuning.zig:25
pub fn histogramTuningOperation(instance: Histogram) entry.Operation { _ = instance; return .{ .indexing = .histogram };}Source: lib/accy/src/kernel/library/histogram/family/tuning.zig:47
pub fn resolveHistogramSchedule( backing_allocator: std.mem.Allocator, reader: tuning.FamilyTuningReader, instance: Histogram,) !?HistogramResolvedSchedule { const key = try histogramFamilyTuningKey(backing_allocator, reader.device_fingerprint, instance); const record = reader.table.find(key) orelse return null; const thread_candidates = histogramThreadCandidatesForCount(instance.count); const variants = [_]HistogramVariant{ .direct, .shared_bins }; for (variants) |variant| { for (thread_candidates.slice()) |threads| { var candidate = instance; candidate.variant = variant; candidate.threads = threads; if (variant == .shared_bins and candidate.bins > model.histogram_shared_bins_cap) continue; const target = try naming.histogramFamilyTarget(backing_allocator, candidate); defer backing_allocator.free(target); if (std.mem.eql(u8, target, record.target)) { return .{ .variant = variant, .threads = threads }; } } } return null;}Source: lib/accy/src/kernel/library/histogram/family/root.zig
const model = @import("model.zig");const naming = @import("naming.zig");const tuning = @import("tuning.zig");const runtime = @import("runtime/root.zig");const shape = @import("shape.zig");const specialization = @import("specialization.zig");pub const HistogramBinningPolicy = model.HistogramBinningPolicy;pub const HistogramVariant = model.HistogramVariant;pub const Histogram = model.Histogram;pub const histogram_family_version = model.histogram_family_version;pub const histogram_shared_bins_cap = model.histogram_shared_bins_cap;pub const histogram_binning_policy_parameter = model.histogram_binning_policy_parameter;pub const histogramDTypeSupported = model.histogramDTypeSupported;pub const histogramInstanceValid = model.histogramInstanceValid;pub const histogramBinningPolicyCode = model.histogramBinningPolicyCode;pub const histogramBinningPolicyFromCode = model.histogramBinningPolicyFromCode;pub const histogramBinForValue = model.histogramBinForValue;pub const histogramFamilyTarget = naming.histogramFamilyTarget;pub const histogramFamilyEntryName = naming.histogramFamilyEntryName;pub const HistogramResolvedSchedule = tuning.HistogramResolvedSchedule;pub const histogramTuningExtents = tuning.histogramTuningExtents;pub const histogramTuningOperation = tuning.histogramTuningOperation;pub const histogramFamilyTuningKey = tuning.histogramFamilyTuningKey;pub const resolveHistogramSchedule = tuning.resolveHistogramSchedule;pub const histogramThreadsForCount = tuning.histogramThreadsForCount;pub const histogramThreadCandidatesForCount = tuning.histogramThreadCandidatesForCount;pub const histogramRuntimeArguments = runtime.histogramRuntimeArguments;pub const HistogramRuntimeFamilyF32 = runtime.HistogramRuntimeFamilyF32;pub const createHistogramFamilyArtifact = runtime.createHistogramFamilyArtifact;pub const histogramShapeFamily = shape.histogramShapeFamily;pub const histogramFamilyFingerprint = shape.histogramFamilyFingerprint;pub const histogramShapeProfileDimensions = shape.histogramShapeProfileDimensions;pub const histogramFamilySpecialization = specialization.histogramFamilySpecialization;pub const histogramInstanceFromSpecialization = specialization.histogramInstanceFromSpecialization;Source: lib/accy/src/kernel/library/root.zig:9
pub const histogram = @import("histogram/family/root.zig");Complete call list for kernel.library.histogram.histogramFamilySpecialization
9 direct calls.
tiny.accy.kernel.library.OwnedSpecialization.allocator[method] atlib/accy/src/kernel/library/entry.zig:616tiny.accy.kernel.library.OwnedSpecialization.deinit[method] atlib/accy/src/kernel/library/entry.zig:620tiny.accy.kernel.library.OwnedSpecialization.init[function] atlib/accy/src/kernel/library/entry.zig:609tiny.accy.kernel.library.OwnedSpecialization.takeShapeFamily[method] atlib/accy/src/kernel/library/entry.zig:626tiny.accy.kernel.library.entry.runtimeShape1D[function] atlib/accy/src/kernel/library/entry.zig:651tiny.accy.kernel.library.entry.runtimeStaticParameter[function] atlib/accy/src/kernel/library/entry.zig:813tiny.accy.kernel.library.entry.runtimeThreadBlocks1D[function] atlib/accy/src/kernel/library/entry.zig:955tiny.accy.kernel.library.histogram.histogramBinningPolicyCode[function] atlib/accy/src/kernel/library/histogram/family/model.zig:43tiny.accy.kernel.library.histogram.histogramShapeFamily[function] atlib/accy/src/kernel/library/histogram/family/shape.zig:12
Audit
| Definitions | 28 |
|---|---|
| Public names | 28 |
| Members | 14 |
| Version | 26.7.0 |
| Revision | daab053ee433 |