Commit 0a76d3f
committed
Update base for Update on "[slimtensor] Add SlimTensor class with basic properties and CPU copy 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]1 parent f1b06c7 commit 0a76d3f
1 file changed
+3
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
| 230 | + | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| |||
0 commit comments