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>
134 lines
4.0 KiB
C++
134 lines
4.0 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
|
|
{
|
|
if (layout == Layout::Interleaved) {
|
|
return index % channels;
|
|
}
|
|
if (layout == Layout::Planar) {
|
|
return index / frames;
|
|
}
|
|
return index % channels;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|