From 6e550430cf24a6324ce22f821181f2cab904d543 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:50:04 -0400 Subject: Error out when constructing tensor views from tensors with 0 stride. (#4516) This avoids a problem with broadcasted tensors. Our tensor-view platform is designed to allow unrestricted access to tensor memory, while broadcasted tensors were designed for 'read-only' use-cases. Trying to write into a broadcasted tensor needs re-allocation, which Slang is not designed to do. For now, we enforce contiguity on tensors with any 0 strides. In the future, we will introduce a ConstTensorView object to allow such tensors to be used as an input. This patch also propagates name-hint information through structs & arrays of tensors, to allow sensible names for the error messages (before this the error messages were temporary inst numbers, which is nearly impossible to debug) --- prelude/slang-torch-prelude.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'prelude') diff --git a/prelude/slang-torch-prelude.h b/prelude/slang-torch-prelude.h index bdba620fe..28548e48e 100644 --- a/prelude/slang-torch-prelude.h +++ b/prelude/slang-torch-prelude.h @@ -140,6 +140,9 @@ TensorView make_tensor_view(torch::Tensor val, const char* name, torch::ScalarTy for (int i = 0; i < val.dim(); ++i) { res.strides[i] = val.stride(i) * elementSize; + if (res.strides[i] == 0) + throw std::runtime_error(std::string(name).append(": tensors with broadcasted dimensions are not supported (use tensor.contiguous() to make tensor whole)").c_str()); + res.sizes[i] = val.size(i); if (res.sizes[i] > 0) isEmpty = false; -- cgit v1.2.3