mojo
mojo copied to clipboard
[BUG] Indexing `Tensor` in `struct` gives a segmentation fault
Bug description
I am unable to run/compile a simple struct
that computes the cumulative sum of a tensor.Tensor
.
Hereby the segmentation fault:
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes. Stack dump: 0. Program arguments: /home/user/.modular/pkg/packages.modular.com_mojo/bin/mojo /home/user/mojo-tutorial/index_error.mojo Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var
LLVM_SYMBOLIZER_PATH
to point to it): 0 mojo 0x000057e34a13f407 1 mojo 0x000057e34a13d25e 2 mojo 0x000057e34a13fa9f 3 libc.so.6 0x000077c7b2642990 4 mojo 0x000057e34b90fd34 5 mojo 0x000057e34b90fc9c 6 mojo 0x000057e34b90fbdf 7 mojo 0x000057e34b91afd8 8 mojo 0x000057e34c570378 9 libKGENCompilerRTShared.so.19.0git 0x000077c7aa83b7cc KGEN_CompilerRT_AlignedAlloc + 124 10 libKGENCompilerRTShared.so.19.0git 0x000077c758001546 KGEN_CompilerRT_AlignedAlloc + 18446744072325193206 mojo crashed! Please file a bug report. [1] 24041 segmentation fault (core dumped) '/home/user/.modular/pkg/packages.modular.com_mojo/bin/mojo'
Steps to reproduce
This is a listing of the code to reproduce the error:
from tensor import Tensor
@value
struct CumulativeCache[T: DType]:
var data: Tensor[DType.int32]
fn __init__(inout self, data: Tensor[DType.int32]):
var length = data.shape()[0]
self.data = Tensor[DType.int32](length + 1, 0)
var cumsum: Int32 = 0
for i in range(length):
cumsum += data[i]
self.data[i + 1] = cumsum
print(self.data)
def main():
var m = List[Int32](2, 1, 3)
var m_tensor = Tensor[DType.int32](3, list=m)
var a = CumulativeCache[DType.float64](m_tensor)
Note that when I remove the print statement from the constructor, it no longer crashes.
System information
OS: Ubuntu 23.10
`mojo -v`: mojo 24.3.0 (9882e19d)
`modular -v`: modular 0.7.4 (df7a9e8b)