Livt packages

Livt.ML

Version 1.6.1

Fixed-size quantized inference, tensor storage, attention, and transformer building blocks for Livt.

Published files (132)

src/linear/Int8BroadcastMac64x8.lvt

namespace Livt.ML.Linear

/**
 * Pipelined 64-output broadcast MAC with eight signed 16x8 multiplier lanes.
 *
 * Each AccumulateRow call captures one activation and one packed row of 64
 * signed-int8 weights. The engine updates eight int32 accumulators per cycle.
 */
component Int8BroadcastMac64x8
{
	// Request toggle paired with the native worker acknowledgment.
	request: logic

	// Owned arithmetic worker used by serialized operations.
	primitive: Int8BroadcastMac64x8Primitive

	/**
	 * Owns one native eight-lane worker in the caller clock/reset context; serialize calls
	 * sharing this instance.
	 */
	new()
	{
		primitive = new Int8BroadcastMac64x8Primitive()
	}

	/**
	 * Submits the configured operation by toggling the request and waits for matching
	 * acknowledgment. Operands must already be stable; reset cancels the pending operation.
	 */
	fn Submit(resetValue: logic)
	{
		primitive.clear = resetValue
		request = !request
		primitive.request = request

		while (primitive.acknowledge != request) {
			state {
			}
		}
	}

	/**
	 * Clears all 64 int32 output accumulators.
	 */
	public fn Reset()
	{
		Submit(0b1)
	}

	/**
	 * Accumulates one activation against a packed row of 64 signed-int8 weights.
	 */
	public fn AccumulateRow(activation: int, weights: logic[512])
	{
		state {
			primitive.activation = activation
			primitive.weights = weights
		}

		Submit(0b0)
	}

	/**
	 * Returns one int32 output accumulator, or zero for an invalid index.
	 */
	public fn GetResult(index: int) int
	{
		if (index < 0 || index >= 64) {
			return 0
		}

		primitive.resultIndex = index as logic[6]

		state {
		}

		return primitive.result
	}
}