Open
Description
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