Skip to content

[SM6.10] Convert needs an overload that takes an InterpretedVector #8418

Closed

Description

@hekota

Convert currently does not support packed type vector sizes that are not a multiple of the number of elements per scalar.

For example, if we have packed vector with component type F8_E4M3FN and size 7, it gets loaded to into vector<uint, 2>. When we want to convert it to vector<half, 7>, the Convert function does not support that because it returns vector<half, 8>. It has no way of knowing that the vector<uint, 2> actually contains 7 valid packed element and not 8.

VectorRef<ComponentType::F8_E4M3FN, 7> vecRef = {Buf, 0};
vector<uint, 2> vecPacked = BiasRef.Buf.Load<vector<uint,2>(0);
vector<half, 7> vecConverted = Convert<ComponentType::F16, ComponentType::F8_E4M3FN>(vecPacked);

error: cannot initialize a variable of type 'vector<half, 7>' with an rvalue of type 'vector<half, 8>'

We should add a Convert function that takes an InterpretedVector that would carry the packed element count into Convert and enable returning of the correct vector type.

Once this is fixed, update MultiplyAdd implementations in the linalg.h header that take a VectorRef to use this new overload.

Activity

  1. changed the title [-][SM6.10] Convert need InterpretedVector overload[/-] [+][SM6.10] Convert needs an overload that takes InterpretedVector[/+] on May 1, 2026
  2. changed the title [-][SM6.10] Convert needs an overload that takes InterpretedVector[/-] [+][SM6.10] Convert needs an overload that takes sn InterpretedVector[/+] on May 1, 2026
  3. changed the title [-][SM6.10] Convert needs an overload that takes sn InterpretedVector[/-] [+][SM6.10] Convert needs an overload that takes an InterpretedVector[/+] on May 1, 2026
  4. tex3d commented on May 4, 2026

    @tex3d
    Contributor

    Since an InterpretedVector for the input to Convert won't solve the problem - N is number of HLSL native scalars in the vector rather than packed elements, I have an alternative solution:

    We could add a template argument to Convert which defaults to __detail::DstN<DestTy, OriginTy, N>::Value, but can be overridden to specify a different number for output components when converting from packed to non-packed, and the desired number of output components isn't an even multiple of ElementsPerScalar.

    template <ComponentEnum DestTy, ComponentEnum OriginTy, typename T, int N,
              int DestN = __detail::DstN<DestTy, OriginTy, N>::Value>

    We could constrain the new template argument (say: DestN) to:

    DestN > __detail::DstN<DestTy, OriginTy, N - 1>::Value &&
    DestN <= __detail::DstN<DestTy, OriginTy, N>::Value

    No changes should be required for the DXIL op, since that dimension is explicit in the overload, though it will require testing.

  5. moved this from Planning to Ready in HLSL Supporton Jun 1, 2026
  6. V-FEXrt commented on Aug 19, 2026

    @V-FEXrt
    Collaborator

    This also needs to be fixed for OuterProduct once it's updated to handle packed vectors

    OuterProduct is natively only now

  7. V-FEXrt commented on Sep 25, 2026

    @V-FEXrt
    Collaborator

    This is implemented already :)

    https://godbolt.org/z/3aohe15ah

    The vector<half, 8> gets truncated before going into the MultiplyAdd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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