From 87bb0b503544f1b8c6ec818e25c695b31cda24b7 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Fri, 8 Sep 2023 20:12:25 -0400 Subject: Add check for contiguous tensors (#3199) Otherwise, this can lead to undetected scenario where the strides are incorrect for non-scalar types (`float2`, `float3`, etc..) Users must call `tensor = tensor.contiguous()` on the inputs to avoid this error. --- prelude/slang-torch-prelude.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prelude/slang-torch-prelude.h b/prelude/slang-torch-prelude.h index dee116261..8d978642d 100644 --- a/prelude/slang-torch-prelude.h +++ b/prelude/slang-torch-prelude.h @@ -87,6 +87,10 @@ TensorView make_tensor_view(torch::Tensor val, const char* name, torch::ScalarTy if (val.dtype() != targetScalarType) throw std::runtime_error(std::string(name).append(": tensor is not of the expected type.").c_str()); + // Check that the tensor is contiguous + if (!val.is_contiguous()) + throw std::runtime_error(std::string(name).append(": tensor is not contiguous.").c_str()); + TensorView res = {}; res.dimensionCount = val.dim(); res.data = nullptr; -- cgit v1.2.3