Skip to content

Restricted numeric types inherit fallback arithmetic methods #240

Description

@AntonOresten

Noticed broadcasting operations over narrow precision tiles will inherit any generic upstream methods with implicit up-casting to Float32 at e.g.:

https://github.com/chengchingwen/DLFP8Types.jl/blob/dcd9135cbe44cef45394a9c5cb6417a91beab7b9/src/DLFP8Types.jl#L162-L166

Going against the notion of the narrow precision types being restricted, non-arithmetic, numeric-only types, like TFloat32 (which doesn't have such methods). DLFP8TypesExt and MicrofloatsExt could register FP8/FP4 as restricted

"""
Restricted floats — types whose op coverage is intentionally limited
(no general arithmetic, reductions, scans, …). Currently `TFloat32`;
future FP8/FP4 dtypes will join this union. Mirrors cuTile Python's
`NumericDTypeCategories.RestrictedFloat`.
"""
const RestrictedFloat = Union{TFloat32}
"""
is_restricted_float(::Type) -> Bool
True if `T` is a restricted float. Used by `reduce` / `scan` (and other
arithmetic-requiring ops) to reject unsupported element types early
with a clear error rather than letting tileiras fail downstream.
"""
@inline is_restricted_float(::Type{T}) where {T} = T <: RestrictedFloat

and then we can have broadcasting honor it to explicitly disallow this implicit up-casting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions