-
Notifications
You must be signed in to change notification settings - Fork 796
[slimtensor] Add SizesAndStrides and dimension utility functions for slimtensor usage #16549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…inimal support Pull Request resolved: #16382 This diff introduces the foundational c10 core headers for SlimTensor, a lightweight tensor implementation used by torchnative, to cuda backend runtime and further it will be used by all aoti-driven backends like MPS. We add: - DeviceType.h - Device type enum (CPU only for now) - Device.h - Device class representing compute device location - ScalarType.h - Scalar type enum with elementSize() helper (Float only for now) These headers are modeled after PyTorch's c10 but simplified for our needs. The enum values are kept compatible with PyTorch for serialization compatibility. This is the first step in migrating SlimTensor to replace ETensor as the internal tensor representation in CUDA backend. Future diffs will add Storage, SlimTensor class, and additional dtypes/devices incrementally. ghstack-source-id: 332983719 @exported-using-ghexport Differential Revision: [D89747061](https://our.internmc.facebook.com/intern/diff/D89747061/)
Pull Request resolved: #16383 This diff introduces the foundation for tensor storage management in the SlimTensor migration: - util/SharedPtr.h - A lightweight, non-thread-safe shared pointer optimized for single-threaded tensor operations. - core/Storage.h - The MaybeOwningStorage class that manages tensor data memory: - DeviceTraits<CPU> specialization with allocate(), free(), memcpy() using malloc/free - Owning mode for CPU device (CUDA and non-owning mode added later) - Storage type alias as SharedPtr<MaybeOwningStorage> - Move semantics for efficient resource transfer - clone() and copy_() methods for data management ghstack-source-id: 332983720 @exported-using-ghexport Differential Revision: [D89747980](https://our.internmc.facebook.com/intern/diff/D89747980/)
…slimtensor usage Pull Request resolved: #16384 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 ghstack-source-id: 332983721 @exported-using-ghexport Differential Revision: [D89749336](https://our.internmc.facebook.com/intern/diff/D89749336/)
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/16549
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 94 PendingAs of commit d0c0c0a with merge base 3c10c89 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
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
@diff-train-skip-merge