Skip to content

Commit

Permalink
Fix tesnor being destroyed before benchmark finished (modular#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackos authored Sep 1, 2023
1 parent 51d357f commit e7b0504
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 8 additions & 6 deletions examples/mandelbrot.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ fn vectorized():
let cy = min_y + (row + iota[float_type, simd_width]()) * scale_y
let cx = min_x + col * scale_x
let c = ComplexSIMD[float_type, simd_width](cx, cy)
m.simd_store[simd_width](
Index(col, row), mandelbrot_kernel_SIMD[simd_width](c)
m._ptr.simd_store[simd_width](
col * height + row, mandelbrot_kernel_SIMD[simd_width](c)
)

# Vectorize the call to compute_vector where call gets a chunk of pixels.
Expand Down Expand Up @@ -139,8 +139,8 @@ fn parallelized():
let cy = min_y + (row + iota[float_type, simd_width]()) * scale_y
let cx = min_x + col * scale_x
let c = ComplexSIMD[float_type, simd_width](cx, cy)
m.simd_store[simd_width](
Index(col, row), mandelbrot_kernel_SIMD[simd_width](c)
m._ptr.simd_store[simd_width](
col * height + row, mandelbrot_kernel_SIMD[simd_width](c)
)

# Vectorize the call to compute_vector where call gets a chunk of pixels.
Expand Down Expand Up @@ -176,8 +176,8 @@ fn compare():
let cy = min_y + (row + iota[float_type, simd_width]()) * scale_y
let cx = min_x + col * scale_x
let c = ComplexSIMD[float_type, simd_width](cx, cy)
m.simd_store[simd_width](
Index(col, row), mandelbrot_kernel_SIMD[simd_width](c)
m._ptr.simd_store[simd_width](
col * height + row, mandelbrot_kernel_SIMD[simd_width](c)
)

# Vectorize the call to compute_vector where call gets a chunk of pixels.
Expand Down Expand Up @@ -205,6 +205,8 @@ fn compare():
print("Parallelized:", parallelized, "ms")
print("Parallel speedup:", vectorized / parallelized)

_ = m


fn main() raises:
compare()
4 changes: 3 additions & 1 deletion examples/notebooks/Mandelbrot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@
" alias simd_width = simdwidthof[DType.float64]()\n",
" let parallelized = Benchmark().run[bench_parallel[simd_width]]() / 1e6\n",
" print(\"Parallelized:\", parallelized, \"ms\")\n",
" print(\"Parallel speedup:\", vectorized / parallelized)"
" print(\"Parallel speedup:\", vectorized / parallelized)\n",
"\n",
" _ = m"
]
},
{
Expand Down

0 comments on commit e7b0504

Please sign in to comment.