-
Notifications
You must be signed in to change notification settings - Fork 776
[slimtensor] Add SlimTensor class with basic properties and CPU copy operation #16385
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
base: gh/gasoonjia/76/base
Are you sure you want to change the base?
Conversation
…operation
**Key components:**
1. **`c10/core/Contiguity.h`** - Contiguity checking utility:
- `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)
2. **`core/SlimTensor.h`** - Main SlimTensor class with:
- **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset
- **Property accessors**:
- `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support
- `strides()`, `stride(dim)` - get tensor strides with negative indexing support
- `dtype()`, `device()`, `device_type()`, `device_index()`
- `numel()`, `dim()`, `nbytes()`, `itemsize()`
- `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset)
- `storage_offset()`, `storage()`
- **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()`
- **Copy operation**: `copy_(other)` - copies data from another tensor
- Fast path: uses memcpy for both-contiguous tensors
- Slow path: element-wise copy respecting strides for non-contiguous tensors
- **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()`
**Curretnt constraints:**
- Only CPU device supported
- Only Float32 dtype tested
- copy_() only supports CPU-to-CPU copy
Those contraints will be further improved in the following diffs
Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/16385
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 1 Unrelated FailureAs of commit 4af5078 with merge base 210047b ( NEW FAILURES - The following jobs have failed:
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. |
…operation
**Key components:**
1. **`c10/core/Contiguity.h`** - Contiguity checking utility:
- `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)
2. **`core/SlimTensor.h`** - Main SlimTensor class with:
- **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset
- **Property accessors**:
- `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support
- `strides()`, `stride(dim)` - get tensor strides with negative indexing support
- `dtype()`, `device()`, `device_type()`, `device_index()`
- `numel()`, `dim()`, `nbytes()`, `itemsize()`
- `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset)
- `storage_offset()`, `storage()`
- **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()`
- **Copy operation**: `copy_(other)` - copies data from another tensor
- Fast path: uses memcpy for both-contiguous tensors
- Slow path: element-wise copy respecting strides for non-contiguous tensors
- **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()`
**Curretnt constraints:**
- Only CPU device supported
- Only Float32 dtype tested
- copy_() only supports CPU-to-CPU copy
Those contraints will be further improved in the following diffs
Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
ghstack-source-id: 331051343
Pull Request resolved: #16385
This PR needs a
|
Stack from ghstack (oldest at bottom):
Key components:
c10/core/Contiguity.h- Contiguity checking utility:_compute_contiguous<T>()- computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)core/SlimTensor.h- Main SlimTensor class with:sizes(),size(dim)- get tensor dimensions with negative indexing supportstrides(),stride(dim)- get tensor strides with negative indexing supportdtype(),device(),device_type(),device_index()numel(),dim(),nbytes(),itemsize()data_ptr()- returns pointer to tensor data (adjusted for storage_offset)storage_offset(),storage()defined(),is_cpu(),is_contiguous(),is_empty()copy_(other)- copies data from another tensorreset(),set_storage(),set_sizes_and_strides()Curretnt constraints:
Those contraints will be further improved in the following diffs
Differential Revision: D89750150