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

[BUG] Indexing Tensor in struct gives a segmentation fault #2596

Open
hylkedonker opened this issue May 9, 2024 · 0 comments
Open

[BUG] Indexing Tensor in struct gives a segmentation fault #2596

hylkedonker opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@hylkedonker
Copy link

hylkedonker commented May 9, 2024

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)
@hylkedonker hylkedonker added bug Something isn't working mojo-repo Tag all issues with this label labels May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

1 participant