Skip to content

sgns::sgprocmanagerdiff

Classes

Name
struct sgns::sgprocmanagerdiff::ElementDiffStats

Types

Name
enum class ChunkElementType

Functions

Name
int64_t OrderedFloatBits(float f)
int64_t UlpDistanceFloat(float a, float b)
Extracted verbatim from capture_diff.cpp.
ElementDiffStats ComputeFloat32Diff(const std::vector< uint8_t > & a, const std::vector< uint8_t > & b)
ElementDiffStats ComputeUint8Diff(const std::vector< uint8_t > & a, const std::vector< uint8_t > & b)
ChunkElementType ResolveChunkElementTypeHint(const std::vector< sgns::Parameter > * parameters)
bool IsFloatChunkWithinTolerance(const std::vector< uint8_t > & a, const std::vector< uint8_t > & b, const std::vector< sgns::Parameter > * parameters, ElementDiffStats & statsOut)
bool IsByteChunkWithinTolerance(const std::vector< uint8_t > & a, const std::vector< uint8_t > & b, const std::vector< sgns::Parameter > * parameters, ElementDiffStats & statsOut)
bool IsByteChunkWithinToleranceForMode(const std::vector< uint8_t > & a, const std::vector< uint8_t > & b, int byteQuantMode, ElementDiffStats & statsOut)

Attributes

Name
constexpr float kRelativeDeltaEpsilonFloor
constexpr double kDefaultFloatRelativeThreshold
constexpr int kDefaultByteAbsoluteThreshold

Types Documentation

enum ChunkElementType

Enumerator Value Description
FLOAT32
UINT8

Element-type hint for a chunk's raw output data, used to decide which tolerance-derivation function (float vs. byte) applies.

Functions Documentation

function OrderedFloatBits

int64_t OrderedFloatBits(
    float f
)

Standard ordered-integer bit-reinterpretation technique for float ULP distance. Extracted verbatim from capture_diff.cpp.

function UlpDistanceFloat

int64_t UlpDistanceFloat(
    float a,
    float b
)

Extracted verbatim from capture_diff.cpp.

function ComputeFloat32Diff

ElementDiffStats ComputeFloat32Diff(
    const std::vector< uint8_t > & a,
    const std::vector< uint8_t > & b
)

Computes per-element float32 divergence stats between two raw byte buffers (each buffer's size must be a multiple of sizeof(float)). Extracted verbatim from capture_diff.cpp's former unnamed-namespace function of the same name – behavior-neutral relocation, byte-for-byte identical output to the pre-extraction version on the same inputs.

function ComputeUint8Diff

ElementDiffStats ComputeUint8Diff(
    const std::vector< uint8_t > & a,
    const std::vector< uint8_t > & b
)

Computes per-element uint8 divergence stats between two raw byte buffers. Extracted verbatim from capture_diff.cpp's former unnamed-namespace function of the same name.

function ResolveChunkElementTypeHint

ChunkElementType ResolveChunkElementTypeHint(
    const std::vector< sgns::Parameter > * parameters
)

Parameters:

  • parameters Job schema's generic parameters array, or nullptr.

Return: UINT8 only when byteQuantMode is validly declared with a value > 0; FLOAT32 otherwise.

Phase 15 (XNODE-02): resolves whether a chunk's raw output data should be treated as float32 or uint8 for tolerance-comparison purposes.

Returns UINT8 only when a job schema-declares "byteQuantMode" (INT type, integer value in [0, 8]) with a value greater than 0 – i.e. the byte-quantization path is actually active for this job. Returns FLOAT32 in every other case: "quantScale" declared instead, a "byteQuantMode" of exactly 0 declared (the byte-identity no-op case, per quantization.hpp's own doc comments), or neither declared. This is a documented, deliberate default – float32 is the more general/common MNN numeric case, and the render byte path has historically been a no-op per Phase 12/14's own doc comments – not an attempt to solve per-output element-type inference generally.

function IsFloatChunkWithinTolerance

bool IsFloatChunkWithinTolerance(
    const std::vector< uint8_t > & a,
    const std::vector< uint8_t > & b,
    const std::vector< sgns::Parameter > * parameters,
    ElementDiffStats & statsOut
)

Parameters:

  • a First chunk's raw float32 bytes.
  • b Second chunk's raw float32 bytes.
  • parameters Job schema's generic parameters array, or nullptr.
  • statsOut Populated with ComputeFloat32Diff's full stats, regardless of the boolean result.

Return: false immediately (statsOut.sizeMismatch=true) if a/b differ in length; otherwise true iff within the D-03/D-04 tolerance.

Phase 15 (XNODE-02, D-03/D-04): determines whether two float32 chunk buffers are numerically "close enough" to be treated as a tolerant match rather than a genuine cross-node divergence.

D-03: when the job validly declares "quantScale" = S, the bound is derived from the quantization grid step (2/S, two grid steps of margin – the same "one full step of margin" philosophy quantization.cpp's own S=2^15-over-2^14 derivation history documents) and compared against ComputeFloat32Diff's maxAbsDelta.

D-04: when no valid "quantScale" is declared, falls back to capture_diff's existing kDefaultFloatRelativeThreshold (1e-4, relative), via ComputeFloat32Diff's own percentExceedingThreshold stat (zero-elements-may-exceed policy, not a percentage-based bar).

function IsByteChunkWithinTolerance

bool IsByteChunkWithinTolerance(
    const std::vector< uint8_t > & a,
    const std::vector< uint8_t > & b,
    const std::vector< sgns::Parameter > * parameters,
    ElementDiffStats & statsOut
)

Parameters:

  • a First chunk's raw uint8 bytes.
  • b Second chunk's raw uint8 bytes.
  • parameters Job schema's generic parameters array, or nullptr.
  • statsOut Populated with ComputeUint8Diff's full stats, regardless of the boolean result.

Return: false immediately (statsOut.sizeMismatch=true) if a/b differ in length; otherwise true iff within the D-03/D-04 tolerance.

Phase 15 (XNODE-02, D-03/D-04): determines whether two uint8 chunk buffers are numerically "close enough" to be treated as a tolerant match rather than a genuine cross-node divergence.

D-03: when the job validly declares "byteQuantMode" = N, the bound is derived from the quantization mask width ((1<<N)-1, the maximum raw delta two values masking to the same quantized value can have) and compared against ComputeUint8Diff's maxAbsDelta.

D-04: when no valid "byteQuantMode" is declared, falls back to capture_diff's existing kDefaultByteAbsoluteThreshold (1, absolute), via ComputeUint8Diff's own percentExceedingThreshold stat (zero-elements-may-exceed policy, not a percentage-based bar).

function IsByteChunkWithinToleranceForMode

bool IsByteChunkWithinToleranceForMode(
    const std::vector< uint8_t > & a,
    const std::vector< uint8_t > & b,
    int byteQuantMode,
    ElementDiffStats & statsOut
)

Parameters:

  • a First chunk's raw uint8 bytes.
  • b Second chunk's raw uint8 bytes.
  • byteQuantMode Mask-bit count in [0, 8], as supplied by the caller (e.g. a CLI flag) – not validated here; callers must validate range themselves (mirrors TryGetDeclaredByteQuantMode's own [0,8] bound).
  • statsOut Populated with ComputeUint8Diff's full stats, regardless of the boolean result.

Return: Identical result to calling IsByteChunkWithinTolerance with a Parameter array declaring byteQuantMode=byteQuantMode.

Phase 17-09 (RENDTOL-02 gap closure, D-11): convenience wrapper for CLI/tool callers (capture_diff) that already know a numeric byteQuantMode directly from a command-line flag and have no job Parameter array on hand to build IsByteChunkWithinTolerance's existing parameters argument from.

Builds a single-entry std::vector declaring "byteQuantMode" (INT type, the given value) and delegates to IsByteChunkWithinTolerance unmodified – this is a pure additive wrapper, not a refactor. IsByteChunkWithinTolerance's own body and TryGetDeclaredByteQuantMode's validation logic are untouched by this function.

Attributes Documentation

variable kRelativeDeltaEpsilonFloor

constexpr float kRelativeDeltaEpsilonFloor = 1e-6f;

Relative-delta denominator floor – avoids divide-by-zero near zero-valued float elements. Extracted verbatim from capture_diff.cpp's former unnamed-namespace constant (Phase 10, Plan 10-05) so both the CLI tool and this shared library read the identical value.

variable kDefaultFloatRelativeThreshold

constexpr double kDefaultFloatRelativeThreshold = 1e-4;

D-04 fallback: fixed float relative-delta threshold used by ComputeFloat32Diff's exceeding-count check and by IsFloatChunkWithinTolerance when no valid "quantScale" is declared. Exported (not file-local) so capture_diff.cpp and any runtime validator consumer read the exact same symbol – guarantees zero behavioral drift between the offline CLI tool and Plan 15-02's runtime comparison.

variable kDefaultByteAbsoluteThreshold

constexpr int kDefaultByteAbsoluteThreshold = 1;

D-04 fallback: fixed byte absolute-delta threshold used by ComputeUint8Diff's exceeding-count check and by IsByteChunkWithinTolerance when no valid "byteQuantMode" is declared.


Updated on 2026-09-17 at 06:29:14 +0000