summaryrefslogtreecommitdiffstats
path: root/prelude
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2024-07-01 14:50:04 -0400
committerGitHub <noreply@github.com>2024-07-01 14:50:04 -0400
commit6e550430cf24a6324ce22f821181f2cab904d543 (patch)
treef0552bbbb4a4f3c2cb503355d842baf6a7b8753d /prelude
parent0e71a6d40d2ccdc9e6bb861e7bbdb9479dbec636 (diff)
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)
Diffstat (limited to 'prelude')
-rw-r--r--prelude/slang-torch-prelude.h3
1 files changed, 3 insertions, 0 deletions
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;