Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book/src/puzzle_04/intro.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn kernel[
print(tensor)


def main():
def main() raises:
ctx = DeviceContext()

a = ctx.enqueue_create_buffer[dtype](HEIGHT * WIDTH)
Expand Down
2 changes: 1 addition & 1 deletion problems/p01/p01.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn add_10(
# ANCHOR_END: add_10


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p02/p02.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn add(
# ANCHOR_END: add


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p03/p03.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn add_10_guard(
# ANCHOR_END: add_10_guard


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p04/p04.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn add_10_2d(
# ANCHOR_END: add_10_2d


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE * SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p04/p04_layout_tensor.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn add_10_2d(
# ANCHOR_END: add_10_2d_layout_tensor


def main():
def main() raises:
with DeviceContext() as ctx:
out_buf = ctx.enqueue_create_buffer[dtype](SIZE * SIZE)
out_buf.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p05/p05.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn broadcast_add(


# ANCHOR_END: broadcast_add
def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE * SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p05/p05_layout_tensor.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn broadcast_add[


# ANCHOR_END: broadcast_add_layout_tensor
def main():
def main() raises:
with DeviceContext() as ctx:
out_buf = ctx.enqueue_create_buffer[dtype](SIZE * SIZE)
out_buf.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p06/p06.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn add_10_blocks(
# ANCHOR_END: add_10_blocks


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p07/p07.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn add_10_blocks_2d(
# ANCHOR_END: add_10_blocks_2d


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE * SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p07/p07_layout_tensor.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn add_10_blocks_2d[
# ANCHOR_END: add_10_blocks_2d_layout_tensor


def main():
def main() raises:
with DeviceContext() as ctx:
out_buf = ctx.enqueue_create_buffer[dtype](SIZE * SIZE)
out_buf.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p08/p08.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn add_10_shared(
# ANCHOR_END: add_10_shared


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p08/p08_layout_tensor.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn add_10_shared_layout_tensor[
# ANCHOR_END: add_10_shared_layout_tensor


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p09/p09.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn collaborative_filter(
# ANCHOR_END: third_crash


def main():
def main() raises:
if len(argv()) != 2:
print(
"Usage: pixi run mojo p09 [--first-case | --second-case |"
Expand Down
2 changes: 1 addition & 1 deletion problems/p10/p10.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn add_10_2d(
# ANCHOR_END: add_10_2d_no_guard


def main():
def main() raises:
if len(argv()) != 2:
print(
"Expected one command-line argument: '--memory-bug' or"
Expand Down
2 changes: 1 addition & 1 deletion problems/p11/p11.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn pooling(
# ANCHOR_END: pooling


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p11/p11_layout_tensor.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn pooling[
# ANCHOR_END: pooling_layout_tensor


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p12/p12.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn dot_product(
# ANCHOR_END: dot_product


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](1)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p12/p12_layout_tensor.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn dot_product[
# ANCHOR_END: dot_product_layout_tensor


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](1)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p13/p13.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn conv_1d_block_boundary[
# ANCHOR_END: conv_1d_block_boundary


def main():
def main() raises:
with DeviceContext() as ctx:
size = SIZE_2 if argv()[1] == "--block-boundary" else SIZE
conv = CONV_2 if argv()[1] == "--block-boundary" else CONV
Expand Down
2 changes: 1 addition & 1 deletion problems/p14/p14.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn prefix_sum_block_sum_phase[
# ANCHOR_END: prefix_sum_complete


def main():
def main() raises:
with DeviceContext() as ctx:
if len(argv()) != 2 or argv()[1] not in [
"--simple",
Expand Down
2 changes: 1 addition & 1 deletion problems/p15/p15.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn axis_sum[
# ANCHOR_END: axis_sum


def main():
def main() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[dtype](BATCH)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p16/p16.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn matmul_tiled[
# ANCHOR_END: matmul_tiled


def main():
def main() raises:
with DeviceContext() as ctx:
if len(argv()) != 2 or argv()[1] not in [
"--naive",
Expand Down
4 changes: 2 additions & 2 deletions problems/p18/test/test_softmax.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ comptime BLOCK_DIM_X = 1 << log2_ceil(SIZE)
comptime dtype = DType.float32


def test_softmax():
def test_softmax() raises:
with DeviceContext() as ctx:
out = ctx.enqueue_create_buffer[DType.float32](SIZE)
out.enqueue_fill(0)
Expand Down Expand Up @@ -79,5 +79,5 @@ def test_softmax():
print("All tests passed 🎉")


def main():
def main() raises:
test_softmax()
2 changes: 1 addition & 1 deletion problems/p23/p23.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ fn benchmark_vectorized_parameterized[
bench_ctx.synchronize()


def main():
def main() raises:
ctx = DeviceContext()
out = ctx.enqueue_create_buffer[dtype](SIZE)
out.enqueue_fill(0)
Expand Down
2 changes: 1 addition & 1 deletion problems/p24/p24.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ fn benchmark_traditional_parameterized[
bench_ctx.synchronize()


def main():
def main() raises:
if argv()[1] != "--benchmark":
print("SIZE:", SIZE)
print("WARP_SIZE:", WARP_SIZE)
Expand Down
12 changes: 6 additions & 6 deletions problems/p25/p25.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn conditional_broadcast[
# ANCHOR_END: conditional_broadcast


def test_neighbor_difference():
def test_neighbor_difference() raises:
with DeviceContext() as ctx:
# Create test data: [0, 1, 4, 9, 16, 25, ...] (squares)
input_buf = ctx.enqueue_create_buffer[dtype](SIZE)
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_neighbor_difference():
print("✅ Basic neighbor difference test passed!")


def test_moving_average():
def test_moving_average() raises:
with DeviceContext() as ctx:
# Create test data: [1, 2, 4, 7, 11, 16, 22, 29, ...]
input_buf = ctx.enqueue_create_buffer[dtype](SIZE_2)
Expand Down Expand Up @@ -239,7 +239,7 @@ def test_moving_average():
print("✅ Moving average test passed!")


def test_broadcast_shuffle_coordination():
def test_broadcast_shuffle_coordination() raises:
with DeviceContext() as ctx:
# Create test data: [2, 4, 6, 8, 1, 3, 5, 7, ...]
input_buf = ctx.enqueue_create_buffer[dtype](SIZE)
Expand Down Expand Up @@ -293,7 +293,7 @@ def test_broadcast_shuffle_coordination():
print("✅ Broadcast + Shuffle coordination test passed!")


def test_basic_broadcast():
def test_basic_broadcast() raises:
with DeviceContext() as ctx:
# Create test data: [1, 2, 3, 4, 5, 6, 7, 8, ...]
input_buf = ctx.enqueue_create_buffer[dtype](SIZE)
Expand Down Expand Up @@ -338,7 +338,7 @@ def test_basic_broadcast():
print("✅ Basic broadcast test passed!")


def test_conditional_broadcast():
def test_conditional_broadcast() raises:
with DeviceContext() as ctx:
# Create test data: [3, 1, 7, 2, 9, 4, 6, 8, ...]
input_buf = ctx.enqueue_create_buffer[dtype](SIZE)
Expand Down Expand Up @@ -398,7 +398,7 @@ def test_conditional_broadcast():
print("✅ Conditional broadcast test passed!")


def main():
def main() raises:
print("WARP_SIZE: ", WARP_SIZE)
if len(argv()) < 1 or len(argv()) > 2:
print(
Expand Down
12 changes: 6 additions & 6 deletions problems/p26/p26.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn warp_partition[
# ANCHOR_END: warp_partition


def test_butterfly_pair_swap():
def test_butterfly_pair_swap() raises:
with DeviceContext() as ctx:
input_buf = ctx.enqueue_create_buffer[dtype](SIZE)
input_buf.enqueue_fill(0)
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_butterfly_pair_swap():
print("✅ Butterfly pair swap test passed!")


def test_butterfly_parallel_max():
def test_butterfly_parallel_max() raises:
with DeviceContext() as ctx:
input_buf = ctx.enqueue_create_buffer[dtype](SIZE)
input_buf.enqueue_fill(0)
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_butterfly_parallel_max():
print("✅ Butterfly parallel max test passed!")


def test_butterfly_conditional_max():
def test_butterfly_conditional_max() raises:
with DeviceContext() as ctx:
input_buf = ctx.enqueue_create_buffer[dtype](SIZE_2)
input_buf.enqueue_fill(0)
Expand Down Expand Up @@ -301,7 +301,7 @@ def test_butterfly_conditional_max():
print("✅ Butterfly conditional max test passed!")


def test_warp_inclusive_prefix_sum():
def test_warp_inclusive_prefix_sum() raises:
with DeviceContext() as ctx:
input_buf = ctx.enqueue_create_buffer[dtype](SIZE)
input_buf.enqueue_fill(0)
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_warp_inclusive_prefix_sum():
print("✅ Warp inclusive prefix sum test passed!")


def test_warp_partition():
def test_warp_partition() raises:
with DeviceContext() as ctx:
input_buf = ctx.enqueue_create_buffer[dtype](SIZE)
input_buf.enqueue_fill(0)
Expand Down Expand Up @@ -416,7 +416,7 @@ def test_warp_partition():
print("✅ Warp partition test passed!")


def main():
def main() raises:
print("WARP_SIZE: ", WARP_SIZE)
if len(argv()) < 2:
print(
Expand Down
2 changes: 1 addition & 1 deletion problems/p27/p27.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn block_normalize_vector[
# ANCHOR_END: block_normalize


def main():
def main() raises:
if len(argv()) != 2:
print(
"Usage: --traditional-dot-product | --block-sum-dot-product |"
Expand Down
4 changes: 2 additions & 2 deletions problems/p28/p28.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn async_copy_overlap_convolution[
# ANCHOR_END: async_copy_overlap_convolution


def test_async_copy_overlap_convolution():
def test_async_copy_overlap_convolution() raises:
"""Test async copy overlap with 1D convolution."""
with DeviceContext() as ctx:
input_buf = ctx.enqueue_create_buffer[dtype](VECTOR_SIZE)
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_async_copy_overlap_convolution():
print("Async copy overlap convolution test FAILED!")


def main():
def main() raises:
"""Run memory fence tests based on command line arguments."""
if len(argv()) != 1:
print("Usage: p25.mojo")
Expand Down
Loading