Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lang] Warn users if ndarray size is out of int32 boundary #6846

Merged
merged 4 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions python/taichi/lang/kernel_impl.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import ast
import functools
import inspect
import operator
import re
import sys
import textwrap
import warnings
import weakref

import numpy as np
Expand Down Expand Up @@ -653,6 +655,11 @@ def func__(*args):
# so that it only holds "real" array shapes.
is_soa = needed.layout == Layout.SOA
array_shape = v.shape
if functools.reduce(operator.mul, array_shape,
1) > np.iinfo(np.int32).max:
warnings.warn(
"Ndarray index might be out of int32 boundary but int64 indexing is not supported yet."
)
if needed.dtype is None or id(
needed.dtype) in primitive_types.type_ids:
element_dim = 0
Expand Down
17 changes: 16 additions & 1 deletion taichi/program/ndarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ Ndarray::Ndarray(Program *prog,
total_shape_.insert(total_shape_.begin(), element_shape.begin(),
element_shape.end());
}

auto total_num_scalar =
std::accumulate(std::begin(total_shape_), std::end(total_shape_), 1LL,
std::multiplies<>());
if (total_num_scalar > std::numeric_limits<int>::max()) {
TI_WARN(
"Ndarray index might be out of int32 boundary but int64 indexing is "
"not supported yet.");
}
ndarray_alloc_ = prog->allocate_memory_ndarray(nelement_ * element_size_,
prog->result_buffer);
}
Expand Down Expand Up @@ -84,6 +91,14 @@ Ndarray::Ndarray(DeviceAllocation &devalloc,
total_shape_.insert(total_shape_.begin(), element_shape.begin(),
element_shape.end());
}
auto total_num_scalar =
std::accumulate(std::begin(total_shape_), std::end(total_shape_), 1LL,
std::multiplies<>());
if (total_num_scalar > std::numeric_limits<int>::max()) {
TI_WARN(
"Ndarray index might be out of int32 boundary but int64 indexing is "
"not supported yet.");
}
}

Ndarray::Ndarray(DeviceAllocation &devalloc,
Expand Down