Commit cbe6c5c
committed
[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-source-id: 331051343
Pull Request resolved: #163851 parent f6a75a8 commit cbe6c5c
File tree
7 files changed
+1066
-0
lines changed- backends/aoti/slim
- c10/core
- core
- test
7 files changed
+1066
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
57 | 69 | | |
58 | 70 | | |
59 | 71 | | |
60 | 72 | | |
61 | 73 | | |
| 74 | + | |
62 | 75 | | |
63 | 76 | | |
64 | 77 | | |
| |||
0 commit comments