diff --git a/python/taichi/lang/kernel_impl.py b/python/taichi/lang/kernel_impl.py index cad3a9f734c03..d4e21eb7b848a 100644 --- a/python/taichi/lang/kernel_impl.py +++ b/python/taichi/lang/kernel_impl.py @@ -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 @@ -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 diff --git a/taichi/program/ndarray.cpp b/taichi/program/ndarray.cpp index 4c9a6ab65c2f9..1a78cd4c2c467 100644 --- a/taichi/program/ndarray.cpp +++ b/taichi/program/ndarray.cpp @@ -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::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); } @@ -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::max()) { + TI_WARN( + "Ndarray index might be out of int32 boundary but int64 indexing is " + "not supported yet."); + } } Ndarray::Ndarray(DeviceAllocation &devalloc,