perf!: inline TensorView metadata storage - #38
Merged
Conversation
voltjia
force-pushed
the
perf/inline-tensor-view-metadata
branch
2 times, most recently
from
July 28, 2026 06:46
4ccf6a8 to
1824269
Compare
TensorView metadata storage
19 tasks
voltjia
force-pushed
the
perf/inline-tensor-view-metadata
branch
from
August 4, 2026 03:30
0b721cc to
425c770
Compare
Ziminli
requested changes
Aug 4, 2026
Ziminli
approved these changes
Aug 4, 2026
19 tasks
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.
Summary
TensorView::ShapeandTensorView::Stridesstd::vectoraliases with boundedSmallVectorinputs and store both arrays in oneShapeStridesStorageowner. Ranks 0 through 8 stay inline; rank 9 and above use owned heap fallback.shape()/strides()accessors while preserving owning results for rvalues and common vector-like construction, including(count, value)metadata construction.Motivation
PR #33 removed redundant
TensorViewmetadata copies, but each ordinary non-empty tensor still required one heap allocation for shape and another for strides.TensorViewis passed through framework-neutral operator and cache-key paths, so those allocations are significant relative to the work performed by this thin metadata object.The selected capacity-8 combined representation removes metadata allocations for the rank range used by most deep-learning tensors while retaining owned fallback for larger ranks. The benchmark section below records the explicit object-footprint and rank-4 trade-off.
No issue is closed by this PR; this is the next optimization stage after #33.
Type of Change
feat- new feature / new backend capability / new public APIfix- bug fixperf- performance improvement without behavior changerefactor- code restructuring without behavior changetest- adding or fixing tests onlydocs- documentation onlybuild/ci- build system or CI configurationchore- tooling, formatting, or other non-code changes!in the Conventional Commits prefix or aBREAKING CHANGE:footer)Platforms Affected
WITH_CPU)WITH_NVIDIA)WITH_ILUVATAR)WITH_HYGON)WITH_METAX)WITH_MOORE)WITH_CAMBRICON)WITH_ASCEND)Smoke Build and Test Result
Final commit:
3a4bb7a91fa291876c5886b119ff894f42e96c30. Full validation commit:425c770457ce590917a30549a2284a8889ad47bd. The final review follow-up only moves the shared noinline macro into the existing performance-test helper.Environment:
accelerator-dev/nvidia:latest(sha256:dd94fce2f83a180e2271f02f69713de5360aaf916b01e1f7f54173519fd54efd), GCC 13.3.0, CMake 3.31.6, Python 3.12.3. NVIDIA validation used an 8 x A100-SXM4-80GB host, driver 580.105.08, and CUDA 13.1.80.Both suites include
test_install_consumer; the build directories were reconfigured at the validation SHA so generated public headers were not reused from an earlier checkout.Test Results on Supported Platforms
The repository has no
CODEOWNERSmapping from which to identify individual backend reviewers. T-Head is also affected through the shared public type but is not represented in the current PR template; no T-Head SDK/runner was available. Please assign maintainers with access to the untested backends.Full `ctest` summaries
Additional checks:
--dry-run --Werror: passed in GitHub Actions for both the branch push and the pull-request synthetic merge at the final SHA.git diff --check origin/master...HEAD: passed at the final SHA.3a4bb7a: remote CPU and NVIDIA builds ofperf_tensor_viewandperf_tensor_view_footprintpassed2/2in each configuration.detail/common/shape_strides_storage.h, do not contain the obsoletedetail/common/tensor_metadata.h, and generatetensor_view.hwith the new include path;test_install_consumerpassed on CPU and NVIDIA.test_core, the storage test now namedtest_shape_strides_storage, and the fill-construction regression passed on patch-equivalent pre-rename commits. The later rename, accessor-inlining, and style-only commits do not change storage ownership or destruction logic.Benchmark / Performance Impact
Harness:
perf_tensor_view_footprint.cache_key_build_hit. Each sample hashes each input, copies it into a temporary non-reserved vector, compares against a prebuilt key, and destroys it. Each key processes 262,144TensorViewvisits. The results are medians from 15 paired round-robin process groups with seven in-process samples per key, pinned to CPU 0 on an AMD Ryzen 9 8945HS under WSL2, GCC 13.3.0, C++17,-O3 -DNDEBUG.Layout changes from
sizeof(TensorView) == 72bytes withstd::vectorto 160 bytes with combined capacity 8 (Shape/Strides: 24 to 80 bytes). Capacity 8 wins every measured key against the shipping vector baseline and both rank-8 keys against capacity 4. The known trade-off is the small rank-4 / count-8 key, where cap8 is 7.275% slower than cap4 while still 36.887% faster than baseline.Measurements were captured at pre-rebase commit
7eb07233d9767e127f8614a7a22174607212dc2b.git range-diffmaps that patch unchanged to8ba2501in the rebased branch;d113995adds the downstream-required(count, value)constructor and regression coverage,b5f5154applies CI-equivalent formatting,2d94f2eremoves process documents,4cdfb51renames the internal shape/strides owner and its files,181474cinlines metadata accessors,425c770aligns the code with repository style, and3a4bb7amoves the duplicated noinline macro intoperf_common.h. These follow-up commits do not change the selected capacity or object layout.Notes for Reviewers
ShapeandStridesare no longer exactstd::vectoraliases,TensorViewlayout changes, and lvalue accessors return borrowed views by value. Consumers must rebuild against matching InfiniRT headers andlibinfinirt.so.TensorView. Rvalue accessors return owning metadata to avoid dangling from temporaries.SOVERSIONchanges are included because InfiniRT has not had a formal release.01f63f4beaa1ca0e178c9b728c1706a4065657cfrequires explicit owning metadata at five exact-std::vector/ pybind boundaries. With that separate downstream patch, InfiniRT1824269fc72a69d9a6276a28af41034661960588built and installed into a self-contained consumer prefix, and the official CPU smoke command reports51 passed, 7 skipped, 3991 deselected, including both C++ installed-consumer tests. The smoke run uses a recorded compiler wrapper only to demote existing deprecated generated-header warnings from-Werror.17743133d674fdb1c2569d96d0f2af3be6517d6frequires a test-only borrowed-view-to-vector conversion. Current InfiniRT master also added T-Head after that torch-infini pin, so a separate T-Head capability-policy update is required before the downstream wheel can build. With those two independent downstream adaptations, the wheel built against InfiniRT1824269fc72a69d9a6276a28af41034661960588(SHA-25644b08cf0731221bfdb5d72cb7259753add25d22f525d0398d521245a2bf53dc5), imported outside the source tree, and its focused suite reported29 passed, 2 skipped.readelf -dshowslibinfiniops.soandlibinfinirt.soasDT_NEEDEDentries and no source/build RPATH.