Skip to content

Conversation

@Gasoonjia
Copy link
Contributor

@Gasoonjia Gasoonjia commented Dec 24, 2025

Stack from ghstack (oldest at bottom):

This diff adds the SizesAndStrides class for efficiently storing tensor dimension sizes and strides, along with utility functions for computing element counts and storage requirements.

Key components:

  1. c10/macros/Macros.h - Branch prediction hint macros (SLIMTENSOR_LIKELY/UNLIKELY) for optimizing hot paths

  2. util/ArrayRefUtil.h - Re-exports ExecuTorch's ArrayRef, IntArrayRef, and makeArrayRef; adds toVec() utility for converting ArrayRef to std::vector

  3. c10/core/SizesAndStrides.h - Packed container for tensor sizes and strides:

    • Inline storage for tensors up to 5 dimensions (no heap allocation)
    • Out-of-line heap storage for larger tensors
    • Full copy/move semantics with proper resource management
    • Equality operators and iterators
    • std::initializer_list overloads for convenient initialization
  4. util/SizeUtil.h - Size computation utilities:

    • compute_numel() - compute total number of elements
    • compute_contiguous_strides() - compute row-major contiguous strides
    • compute_storage_nbytes() / compute_storage_nbytes_contiguous() - compute storage byte requirements

Differential Revision: D89749336

…slimtensor usage

This diff adds the `SizesAndStrides` class for efficiently storing tensor dimension sizes and strides, along with utility functions for computing element counts and storage requirements.

**Key components:**

1. **`c10/macros/Macros.h`** - Branch prediction hint macros (`SLIMTENSOR_LIKELY/UNLIKELY`) for optimizing hot paths

2. **`util/ArrayRefUtil.h`** - Re-exports ExecuTorch's `ArrayRef`, `IntArrayRef`, and `makeArrayRef`; adds `toVec()` utility for converting ArrayRef to std::vector

3. **`c10/core/SizesAndStrides.h`** - Packed container for tensor sizes and strides:
   - Inline storage for tensors up to 5 dimensions (no heap allocation)
   - Out-of-line heap storage for larger tensors
   - Full copy/move semantics with proper resource management
   - Equality operators and iterators
   - `std::initializer_list` overloads for convenient initialization

4. **`util/SizeUtil.h`** - Size computation utilities:
   - `compute_numel()` - compute total number of elements
   - `compute_contiguous_strides()` - compute row-major contiguous strides
   - `compute_storage_nbytes()` / `compute_storage_nbytes_contiguous()` - compute storage byte requirements

Differential Revision: [D89749336](https://our.internmc.facebook.com/intern/diff/D89749336/)

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Dec 24, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/16384

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 5 Unrelated Failures

As of commit 48843e7 with merge base 9ba1b5d (image):

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

…ctions for slimtensor usage"

This diff adds the `SizesAndStrides` class for efficiently storing tensor dimension sizes and strides, along with utility functions for computing element counts and storage requirements.

**Key components:**

1. **`c10/macros/Macros.h`** - Branch prediction hint macros (`SLIMTENSOR_LIKELY/UNLIKELY`) for optimizing hot paths

2. **`util/ArrayRefUtil.h`** - Re-exports ExecuTorch's `ArrayRef`, `IntArrayRef`, and `makeArrayRef`; adds `toVec()` utility for converting ArrayRef to std::vector

3. **`c10/core/SizesAndStrides.h`** - Packed container for tensor sizes and strides:
   - Inline storage for tensors up to 5 dimensions (no heap allocation)
   - Out-of-line heap storage for larger tensors
   - Full copy/move semantics with proper resource management
   - Equality operators and iterators
   - `std::initializer_list` overloads for convenient initialization

4. **`util/SizeUtil.h`** - Size computation utilities:
   - `compute_numel()` - compute total number of elements
   - `compute_contiguous_strides()` - compute row-major contiguous strides
   - `compute_storage_nbytes()` / `compute_storage_nbytes_contiguous()` - compute storage byte requirements

Differential Revision: [D89749336](https://our.internmc.facebook.com/intern/diff/D89749336/)

[ghstack-poisoned]
…ctions for slimtensor usage"

This diff adds the `SizesAndStrides` class for efficiently storing tensor dimension sizes and strides, along with utility functions for computing element counts and storage requirements.

**Key components:**

1. **`c10/macros/Macros.h`** - Branch prediction hint macros (`SLIMTENSOR_LIKELY/UNLIKELY`) for optimizing hot paths

2. **`util/ArrayRefUtil.h`** - Re-exports ExecuTorch's `ArrayRef`, `IntArrayRef`, and `makeArrayRef`; adds `toVec()` utility for converting ArrayRef to std::vector

3. **`c10/core/SizesAndStrides.h`** - Packed container for tensor sizes and strides:
   - Inline storage for tensors up to 5 dimensions (no heap allocation)
   - Out-of-line heap storage for larger tensors
   - Full copy/move semantics with proper resource management
   - Equality operators and iterators
   - `std::initializer_list` overloads for convenient initialization

4. **`util/SizeUtil.h`** - Size computation utilities:
   - `compute_numel()` - compute total number of elements
   - `compute_contiguous_strides()` - compute row-major contiguous strides
   - `compute_storage_nbytes()` / `compute_storage_nbytes_contiguous()` - compute storage byte requirements

Differential Revision: [D89749336](https://our.internmc.facebook.com/intern/diff/D89749336/)

[ghstack-poisoned]
Copy link
Contributor

@manuelcandales manuelcandales left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you need a test_array_ref_util.cpp as well?

…ctions for slimtensor usage"

This diff adds the `SizesAndStrides` class for efficiently storing tensor dimension sizes and strides, along with utility functions for computing element counts and storage requirements.

**Key components:**

1. **`c10/macros/Macros.h`** - Branch prediction hint macros (`SLIMTENSOR_LIKELY/UNLIKELY`) for optimizing hot paths

2. **`util/ArrayRefUtil.h`** - Re-exports ExecuTorch's `ArrayRef`, `IntArrayRef`, and `makeArrayRef`; adds `toVec()` utility for converting ArrayRef to std::vector

3. **`c10/core/SizesAndStrides.h`** - Packed container for tensor sizes and strides:
   - Inline storage for tensors up to 5 dimensions (no heap allocation)
   - Out-of-line heap storage for larger tensors
   - Full copy/move semantics with proper resource management
   - Equality operators and iterators
   - `std::initializer_list` overloads for convenient initialization

4. **`util/SizeUtil.h`** - Size computation utilities:
   - `compute_numel()` - compute total number of elements
   - `compute_contiguous_strides()` - compute row-major contiguous strides
   - `compute_storage_nbytes()` / `compute_storage_nbytes_contiguous()` - compute storage byte requirements

Differential Revision: [D89749336](https://our.internmc.facebook.com/intern/diff/D89749336/)

[ghstack-poisoned]
…ctions for slimtensor usage"

This diff adds the `SizesAndStrides` class for efficiently storing tensor dimension sizes and strides, along with utility functions for computing element counts and storage requirements.

**Key components:**

1. **`c10/macros/Macros.h`** - Branch prediction hint macros (`SLIMTENSOR_LIKELY/UNLIKELY`) for optimizing hot paths

2. **`util/ArrayRefUtil.h`** - Re-exports ExecuTorch's `ArrayRef`, `IntArrayRef`, and `makeArrayRef`; adds `toVec()` utility for converting ArrayRef to std::vector

3. **`c10/core/SizesAndStrides.h`** - Packed container for tensor sizes and strides:
   - Inline storage for tensors up to 5 dimensions (no heap allocation)
   - Out-of-line heap storage for larger tensors
   - Full copy/move semantics with proper resource management
   - Equality operators and iterators
   - `std::initializer_list` overloads for convenient initialization

4. **`util/SizeUtil.h`** - Size computation utilities:
   - `compute_numel()` - compute total number of elements
   - `compute_contiguous_strides()` - compute row-major contiguous strides
   - `compute_storage_nbytes()` / `compute_storage_nbytes_contiguous()` - compute storage byte requirements

Differential Revision: [D89749336](https://our.internmc.facebook.com/intern/diff/D89749336/)

[ghstack-poisoned]
…ctions for slimtensor usage"

This diff adds the `SizesAndStrides` class for efficiently storing tensor dimension sizes and strides, along with utility functions for computing element counts and storage requirements.

**Key components:**

1. **`c10/macros/Macros.h`** - Branch prediction hint macros (`SLIMTENSOR_LIKELY/UNLIKELY`) for optimizing hot paths

2. **`util/ArrayRefUtil.h`** - Re-exports ExecuTorch's `ArrayRef`, `IntArrayRef`, and `makeArrayRef`; adds `toVec()` utility for converting ArrayRef to std::vector

3. **`c10/core/SizesAndStrides.h`** - Packed container for tensor sizes and strides:
   - Inline storage for tensors up to 5 dimensions (no heap allocation)
   - Out-of-line heap storage for larger tensors
   - Full copy/move semantics with proper resource management
   - Equality operators and iterators
   - `std::initializer_list` overloads for convenient initialization

4. **`util/SizeUtil.h`** - Size computation utilities:
   - `compute_numel()` - compute total number of elements
   - `compute_contiguous_strides()` - compute row-major contiguous strides
   - `compute_storage_nbytes()` / `compute_storage_nbytes_contiguous()` - compute storage byte requirements

Differential Revision: [D89749336](https://our.internmc.facebook.com/intern/diff/D89749336/)

[ghstack-poisoned]
@meta-codesync meta-codesync bot merged commit 946cab4 into gh/gasoonjia/75/base Jan 12, 2026
167 of 175 checks passed
@meta-codesync meta-codesync bot deleted the gh/gasoonjia/75/head branch January 12, 2026 22:23
Gasoonjia added a commit that referenced this pull request Jan 12, 2026
…slimtensor usage (#16549)

This PR was created by the merge bot to help merge the original PR into
the main branch.
ghstack PR number: #16384 by
@Gasoonjia
^ Please use this as the source of truth for the PR details, comments,
and reviews
ghstack PR base:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/75/base
ghstack PR head:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/75/head
Merge bot PR base:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/74/orig
Merge bot PR head:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/75/orig
Differential Revision:
[D89749336](https://our.internmc.facebook.com/intern/diff/D89749336/)
@diff-train-skip-merge

---------

Co-authored-by: gasoonjia <[email protected]>
Co-authored-by: Gasoonjia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants