feat(cutile): add raw-offset memory ops with generic forwarding support - #229
Open
lucifer1004 wants to merge 2 commits into
Open
feat(cutile): add raw-offset memory ops with generic forwarding support#229lucifer1004 wants to merge 2 commits into
lucifer1004 wants to merge 2 commits into
Conversation
Add zero-cost load_offset/load_offset_as/store_offset helpers that build pointer tiles from a raw base pointer and an integer offset tile, for packed layouts whose values and metadata live outside any tensor view. The wrappers forward ordering/scope/latency marker arguments by value, which requires the compiler to resolve forwarded ZST type names, variable-held Latency const generics, inlined Option payloads, explicit None::<T> annotations, and tuple element-wise generic inference. Move the Latency marker into the core module proper so the DSL name resolver indexes it for single-segment paths. Also cover F32-to-E8M0 conversion with positive-infinity rounding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Packed layouts (e.g. sparse/quantized weight formats) keep values and metadata at independent byte offsets from a raw base pointer, outside any
Tensorview. Today expressing that access pattern in the DSL requires manually composingpointer_to_tile/reshape_ptr/broadcast_ptr/addptr_tileat every call site.What this adds
Zero-cost raw-offset memory helpers in
cutile::core, built entirely on existing pointer-tile primitives:load_offset(base, offsets, ...)— loadbase + offsets(offsets in elements ofB)load_offset_as(base, offsets, ...)— same addressing, then reinterpret each address asE; a*mut u8base gives byte-addressed access to packed values with independently placed metadatastore_offset(base, offsets, value, ...)— store tobase + offsetsAll three are
variadic_opwrappers forwarding ordering / scope / mask / padding / token / latency through toload_ptr_tko/store_ptr_tko, so they carry no lowering cost of their own (verified in the test: nomake_gather_scatter_view, plainoffset+load_ptr_tko/store_ptr_tkoin the MLIR).Compiler support required
Because the wrappers receive marker arguments (ordering, scope,
Latency<N>) by value and forward them, the compiler previously could not resolve them — primitives likeload_ptr_tkoonly accepted literal type paths at the call site. This PR teaches the compiler to:extract_forwarded_zst_type_name);Latency<N>cycle counts from a variable's type, including const-generic values;Somepayloads and explicitly typedNone::<T>arguments;Option<T>as resolvable/fully-known when its payload is, and infer tuple types element-wise.It also moves the
Latencymarker intocoreproper (previously a top-level struct re-exported intocore) so the DSL name resolver indexes it for single-segment paths likeLatency::<4>— a re-export alone is invisible to the resolver.Tests
cutile/tests/raw_memory.rs(new): compiles kernels using the helpers and asserts the lowered MLIR (offset arithmetic, ordering/scope/latency forwarding, token threading, no gather/scatter view materialization).cutile/tests/type_conversion_ops.rs: F32→E8M0 conversion coverage with positive-infinity rounding (compile-time MLIR check + GPU execution roundtrip).Full
cutile+cutile-compilertest suites pass locally on an SM120 GPU. (Note: the pre-existingcuda_tile_runtime_utils::tests::selects_bytecode_version_from_toolkit_cuda_his sensitive to theCUTILE_BYTECODE_VERSIONenv var and fails in shells where it is set — unrelated to this change.)