amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

150 lines
4.7 KiB
C++

#include "quant.hpp"
#include <algorithm>
namespace aq {
Status Bank::validate_shape(Layout layout, std::size_t channels, std::size_t frames,
std::size_t block, std::size_t count) const
{
if (layout != Layout::Interleaved && layout != Layout::Planar && layout != Layout::Blocked) {
return Status::Layout;
}
if (channels < 1 || channels > max_channels) {
return Status::Shape;
}
if (frames > 32) {
return Status::Shape;
}
if (layout == Layout::Blocked) {
if (block < 1 || block > 16) {
return Status::Shape;
}
} else {
if (block != 1) {
return Status::Shape;
}
}
if (count != channels * frames) {
return Status::Shape;
}
return Status::Ok;
}
std::size_t Bank::channel_at(Layout layout, std::size_t channels, std::size_t frames,
std::size_t block, std::size_t index) const
{
std::size_t position = 0;
if (layout == Layout::Interleaved) {
for (std::size_t frame = 0; frame < frames; ++frame) {
for (std::size_t channel = 0; channel < channels; ++channel) {
if (position++ == index) {
return channel;
}
}
}
} else {
std::size_t group_size = layout == Layout::Planar ? frames : block;
for (std::size_t first = 0; first < frames; first += group_size) {
for (std::size_t channel = 0; channel < channels; ++channel) {
for (std::size_t frame = first; frame < frames && frame < first + group_size; ++frame) {
if (position++ == index) {
return channel;
}
}
}
}
}
return 0;
}
Status Bank::quantize_many(Layout layout, std::size_t channels, std::size_t frames,
std::size_t block, const Rational* input, std::size_t count,
int* output, std::size_t capacity)
{
Status status = validate_shape(layout, channels, frames, block, count);
if (status != Status::Ok) {
return status;
}
if (capacity < count) {
return Status::Buffer;
}
if (count > 0 && input == nullptr) {
return Status::Buffer;
}
if (count > 0 && output == nullptr) {
return Status::Buffer;
}
if (count == 0) {
return Status::Ok;
}
for (std::size_t channel = 0; channel < channels; ++channel) {
if (!ready_[channel]) {
return Status::NotReady;
}
}
for (std::size_t index = 0; index < count; ++index) {
if (!detail::valid(input[index])) {
return Status::Value;
}
}
std::array<int, max_channels * 32> staged{};
Counters counters = counters_;
for (std::size_t index = 0; index < count; ++index) {
std::size_t channel = channel_at(layout, channels, frames, block, index);
int clipping = 0;
staged[index] = detail::encode(profiles_[channel], input[index], clipping);
++counters.quantized;
record_clip(clipping, counters);
}
for (std::size_t index = 0; index < count; ++index) {
output[index] = staged[index];
}
counters_ = counters;
return Status::Ok;
}
Status Bank::dequantize_many(Layout layout, std::size_t channels, std::size_t frames,
std::size_t block, const int* input, std::size_t count,
Rational* output, std::size_t capacity)
{
Status status = validate_shape(layout, channels, frames, block, count);
if (status != Status::Ok) {
return status;
}
if (capacity < count) {
return Status::Buffer;
}
if (count > 0 && input == nullptr) {
return Status::Buffer;
}
if (count > 0 && output == nullptr) {
return Status::Buffer;
}
if (count == 0) {
return Status::Ok;
}
for (std::size_t channel = 0; channel < channels; ++channel) {
if (!ready_[channel]) {
return Status::NotReady;
}
}
for (std::size_t index = 0; index < count; ++index) {
if (!detail::valid_code(input[index])) {
return Status::Value;
}
}
std::array<Rational, max_channels * 32> staged{};
Counters counters = counters_;
for (std::size_t index = 0; index < count; ++index) {
std::size_t channel = channel_at(layout, channels, frames, block, index);
staged[index] = detail::decode(profiles_[channel], input[index]);
++counters.dequantized;
}
for (std::size_t index = 0; index < count; ++index) {
output[index] = staged[index];
}
counters_ = counters;
return Status::Ok;
}
}