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] Mojo crashes when invoking a parallel function calling a lambda without @parameter decorator #3578

Open
p88h opened this issue Sep 30, 2024 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@p88h
Copy link

p88h commented Sep 30, 2024

Bug description

Sample code below.

This tries to run a parallel worker with a (badly/non) parametrized lambda, which crashes mojo.
Should probably be detected as an issue at compile time?

Steps to reproduce

from algorithm import parallelize
from os.atomic import Atomic

fn main() raises:
    tiles = List[String]()
    tiles.extend(List[String]("abcde", "fghij", "klmno", "pqrst", "uvwxy"))
    dimx = tiles.size
    dimy = len(tiles[0])
    var mmax = Atomic[DType.int64](0)

    # this doesn't reference any globals so is ok
    fn idx(x: Int32, y: Int32) -> Int32:
        return 220 + ((y + 1) % 2) * 110 + x + 1

    # this references dimx, dimy but is not @parameter bound
    fn bar(i: Int) -> SIMD[DType.int32, 4]:
        return SIMD[DType.int32, 4](dimy, i - 2 * dimx - dimy, -1, 0)

    @parameter
    fn foo(start: SIMD[DType.int32, 4]) -> Int64:
        return int(idx(start[0], start[1]))

    @parameter
    fn step2(i: Int):
        mmax.max(foo(bar(i)))

    @parameter
    fn invoke() -> Int64:
        parallelize[step2](4)
        return mmax.value

    # this works, despite bar not having @parameter decorator
    print(foo(bar(1)))
    # and this causes the whole runtime to crash
    print(invoke())

    print(tiles.size, "tokens", dimx, dimy)

System information

- What OS did you do install Mojo on ?
Windows 11 / WSL 2
- Provide version information for Mojo by pasting the output of `mojo -v`
`mojo 24.5.0 (e8aacb95)`
- Provide Modular CLI version by pasting the output of `magic -V`
`magic 0.2.3`
@p88h p88h added bug Something isn't working mojo-repo Tag all issues with this label labels Sep 30, 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