This is an archive of the discontinued LLVM Phabricator instance.

[mlir][spirv] Support sub-byte integer types in type conversion
ClosedPublic

Authored by antiagainst on May 11 2023, 12:50 PM.

Details

Summary

Typically GPUs cannot access memory in sub-byte manner. So for
sub-byte integer type values, we need to either expand them to
full bytes or tightly pack them. This commit adds support for
tightly packed power-of-two sub-byte types.

Sub-byte types aren't allowed in SPIR-V spec, so there are no
compute/storage capability for them like other supported integer
types. So we don't recognize sub-byte types in spirv::ScalarType.
We just special case them in type converter and always convert
to use i32 under the hood.

Diff Detail

Event Timeline

antiagainst created this revision.May 11 2023, 12:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2023, 12:50 PM
antiagainst requested review of this revision.May 11 2023, 12:50 PM
kuhar accepted this revision.May 11 2023, 1:18 PM

Looks good

mlir/include/mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h
32

ubernit: s/Packing/Packed?

mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
446

nit: spell out the type? It's not obvious to me if the result is signed or not.

462–464

This should assert if you dereference it and the value is not present: int64_t arrayElemSize = *getTypeNumBytes(...);

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716/27?u=kuhar

This revision is now accepted and ready to land.May 11 2023, 1:18 PM
antiagainst marked 3 inline comments as done.May 11 2023, 3:17 PM