Skip to content

Commit 7baa09f

Browse files
committed
Update on "make aoti_torch_empty_strided support creating incontiguous tensor"
This diff modifies the `aoti_torch_empty_strided` function to support the creation of incontiguous tensors. To achieve it, this diff: 1. update the way to calculate the memory size by using both tensor size and the stride 2. skip stride check in ETensor by adding and checking cmake macro `USE_CUDA_BACKEND` when building with CUDA backend support. we will soon bring the ETensor check back for every backend after migrating to use slimtensor. Differential Revision: [D84938258](https://our.internmc.facebook.com/intern/diff/D84938258/) [ghstack-poisoned]
2 parents 58da91d + 4858d42 commit 7baa09f

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

backends/cuda/runtime/shims/memory.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,9 @@ AOTITorchError aoti_torch_empty_strided(
234234
}
235235
// For each dimension, add stride[i] * (size[i] - 1)
236236
// This gives us the maximum offset in that dimension
237-
int64_t stride_i = (strides_ptr != nullptr) ? strides_ptr[i] : 0;
237+
int64_t stride_i = (strides_ptr != nullptr) ? strides_ptr[i] : 1;
238238
if (strides_ptr == nullptr) {
239239
// Calculate contiguous stride if not provided
240-
stride_i = 1;
241240
for (int64_t j = i + 1; j < ndim; j++) {
242241
stride_i *= sizes_ptr[j];
243242
}

0 commit comments

Comments
 (0)