Skip to content

Commit 0a76d3f

Browse files
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

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

backends/aoti/slim/core/test/test_storage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ TEST(StorageSharedPtrTest, SharedOwnership) {
190190
Storage storage1(new MaybeOwningStorage(CPU_DEVICE, kNbytes));
191191
void* data_ptr = storage1->data();
192192

193-
Storage storage2 = storage1; // Copy, not reference - increments ref count
193+
Storage storage2 = storage1; // Copy, not reference - increments ref count
194194

195195
EXPECT_EQ(storage1.use_count(), 2);
196196
EXPECT_EQ(storage2.use_count(), 2);
@@ -227,9 +227,9 @@ TEST(StorageSharedPtrTest, ReferenceCountDecrement) {
227227
EXPECT_EQ(storage1.use_count(), 1);
228228

229229
{
230-
Storage storage2 = storage1; // Copy increments ref count
230+
Storage storage2 = storage1; // Copy increments ref count
231231
EXPECT_EQ(storage1.use_count(), 2);
232-
} // storage2 destroyed, ref count decrements
232+
} // storage2 destroyed, ref count decrements
233233

234234
EXPECT_EQ(storage1.use_count(), 1);
235235
}

0 commit comments

Comments
 (0)