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] Strange segmentation fault when printing a tensor #2666

Open
ltjkoomen opened this issue May 15, 2024 · 2 comments
Open

[BUG] Strange segmentation fault when printing a tensor #2666

ltjkoomen opened this issue May 15, 2024 · 2 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label tensor

Comments

@ltjkoomen
Copy link

ltjkoomen commented May 15, 2024

Bug description

This is a strange one. I get a segmentation fault when trying to print the result of indexing a tensor without providing an index. However, this segfault is dependent on some other stuff in the code being present. For more details see the minimal example.

Steps to reproduce

Include relevant code snippet or link to code that did not work as expected.

I've come to the following minimal example of the issue:

Additional requirements:

  • a file named 'empty_file.txt' located at the same level as the mojo script that can just be empty

Strangely, the segfault seems to be dependent on:

  • The reading of the file (even though these contents are not used afterwards)
  • The for-loops being used (instead of just directly setting the single element of the tensor to False without iterating)
  • The for-loops using range(matrix.shape()[0] instead of just range(1)
  • The printing of matrix[]. Not sure what this is supposed to return normally, but normally this does not segfault and prints True. Also, printing matrix[0] does not segfault.
  • The element type of the tensor being either bool or int8, any other type seems to work fine
from pathlib import Path
from tensor import Tensor, TensorSpec, TensorShape
from utils.index import Index


fn main():
    var p = Path("empty_file.txt")
    var text: String
    try:
        text = p.read_text()
    except Exception:
        print("error")
        return

    var spec = TensorSpec(DType.bool, 1, 1)
    var matrix = Tensor[DType.bool](spec)
    for i in range(matrix.shape()[0]):
        for j in range(matrix.shape()[1]):
            matrix[Index[Int](i, j)] = False

    print(matrix[])

If applicable, add screenshots to help explain the problem.
Not applicable.

If using the Playground, name the pre-existing notebook that failed and the steps that led to failure.
Not applicable.

Include anything else that might help us debug the issue.
I get the following stack dump:

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: mojo crash.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      0x0000573f6d5c1407
1  mojo      0x0000573f6d5bf25e
2  mojo      0x0000573f6d5c1a9f
3  libc.so.6 0x00007a45fbc42520
4  libc.so.6 0x00007a4588001fcd
mojo crashed!
Please file a bug report.
[1]    44861 segmentation fault (core dumped)  mojo crash.mojo

System information

- What OS did you do install Mojo on ?
Linux 6.5.0-28-generic #29~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr 4 14:39:20 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 24.3.0 (9882e19d)
- Provide Modular CLI version by pasting the output of `modular -v`
modular 0.7.4 (df7a9e8b)
@ltjkoomen ltjkoomen added bug Something isn't working mojo-repo Tag all issues with this label labels May 15, 2024
@ematejska
Copy link
Collaborator

Error that is visible is:

0  mojo                     0x0000000102d224b8 llvm_strlcpy + 51480
1  mojo                     0x0000000102d207a4 llvm_strlcpy + 44036
2  mojo                     0x0000000102d22b58 llvm_strlcpy + 53176
3  libsystem_platform.dylib 0x00000001a4876a24 _sigtramp + 56
4  libsystem_platform.dylib 0x0000000280004634 _sigtramp + 3682131016
5  mojo                     0x00000001030b5b90 __jit_debug_register_code + 1037784
6  mojo                     0x0000000102c82e00
7  mojo                     0x0000000102c827f4
8  mojo                     0x0000000102c6b48c
9  dyld                     0x00000001a44eff28 start + 2236
mojo crashed!
Please file a bug report.
[54647:1277002:20240529,145514.581193:WARNING in_range_cast.h:38] value -634136515 out of range
[54647:1277002:20240529,145514.585086:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)

@ematejska
Copy link
Collaborator

Reduced testcase

from tensor import Tensor, TensorSpec, TensorShape
from utils.index import Index

fn main():
    var spec = TensorSpec(DType.bool, 1, 1)
    var matrix = Tensor[DType.bool](spec)
    for i in range(matrix.shape()[0]):
        for j in range(matrix.shape()[1]):
            matrix[Index[Int](i, j)] = False
    print(matrix[])

out of bounds error?

@JoeLoser JoeLoser added the tensor label May 31, 2024 — with Linear
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 tensor
Projects
None yet
Development

No branches or pull requests

3 participants