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

[Language Request] Mojo by Modular #3815

Open
robert-j-webb opened this issue Jul 26, 2024 · 1 comment
Open

[Language Request] Mojo by Modular #3815

robert-j-webb opened this issue Jul 26, 2024 · 1 comment

Comments

@robert-j-webb
Copy link

Language

I'd like to add support for Mojo formally to Prism. I'm the lead frontend engineer at Modular and we already have a Prism definition we've been using.

We use Prism on our docsite, so you can see it in action here. We'd like to add it to upstream.

It's also supported in github too!

fn run_mandelbrot(parallel: Bool) raises -> Float64:
    var matrix = Matrix[int_type, height, width]()

    @parameter
    fn worker(row: Int):
        var scale_x = (max_x - min_x) / width
        var scale_y = (max_y - min_y) / height

        @parameter
        fn compute_vector[simd_width: Int](col: Int):
            """Each time we operate on a `simd_width` vector of pixels."""
            var cx = min_x + (col + iota[float_type, simd_width]()) * scale_x
            var cy = min_y + row * scale_y
            var c = ComplexSIMD[float_type, simd_width](cx, cy)
            matrix.store(row, col, mandelbrot_kernel_SIMD[simd_width](c))

        # Vectorize the call to compute_vector where call gets a chunk of pixels.
        vectorize[compute_vector, simd_width](width)

    @parameter
    fn bench():
        for row in range(height):
            worker(row)

    @parameter
    fn bench_parallel():
        parallelize[worker](height, height)

    var time: Float64 = 0
    if parallel:
        time = benchmark.run[bench_parallel](max_runtime_secs=0.5).mean(unit)
    else:
        time = benchmark.run[bench](max_runtime_secs=0.5).mean(unit)

    show_plot(matrix)
    matrix.data.free()
    return time

vectorized = run_mandelbrot(parallel=False)
print("Vectorized:", vectorized, unit)

Additional resources

Brief Intro Site

Mojo Manual

@guidorice
Copy link

building a docusaurus blog, would be great to have mojo hiliting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants