diff --git a/book/src/puzzle_04/intro.mojo b/book/src/puzzle_04/intro.mojo index 6c88703e..8b3aefc9 100644 --- a/book/src/puzzle_04/intro.mojo +++ b/book/src/puzzle_04/intro.mojo @@ -17,7 +17,7 @@ fn kernel[ print(tensor) -def main(): +def main() raises: ctx = DeviceContext() a = ctx.enqueue_create_buffer[dtype](HEIGHT * WIDTH) diff --git a/problems/p01/p01.mojo b/problems/p01/p01.mojo index 62e80613..21b6ddd2 100644 --- a/problems/p01/p01.mojo +++ b/problems/p01/p01.mojo @@ -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) diff --git a/problems/p02/p02.mojo b/problems/p02/p02.mojo index de5692ae..4365dcb8 100644 --- a/problems/p02/p02.mojo +++ b/problems/p02/p02.mojo @@ -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) diff --git a/problems/p03/p03.mojo b/problems/p03/p03.mojo index 12fa7560..c55731e9 100644 --- a/problems/p03/p03.mojo +++ b/problems/p03/p03.mojo @@ -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) diff --git a/problems/p04/p04.mojo b/problems/p04/p04.mojo index 08045d4c..202d3768 100644 --- a/problems/p04/p04.mojo +++ b/problems/p04/p04.mojo @@ -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) diff --git a/problems/p04/p04_layout_tensor.mojo b/problems/p04/p04_layout_tensor.mojo index 1e4a6e7b..543f92a1 100644 --- a/problems/p04/p04_layout_tensor.mojo +++ b/problems/p04/p04_layout_tensor.mojo @@ -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) diff --git a/problems/p05/p05.mojo b/problems/p05/p05.mojo index b5d7b644..c6d9a139 100644 --- a/problems/p05/p05.mojo +++ b/problems/p05/p05.mojo @@ -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) diff --git a/problems/p05/p05_layout_tensor.mojo b/problems/p05/p05_layout_tensor.mojo index d39b9e72..fbbb6f17 100644 --- a/problems/p05/p05_layout_tensor.mojo +++ b/problems/p05/p05_layout_tensor.mojo @@ -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) diff --git a/problems/p06/p06.mojo b/problems/p06/p06.mojo index 03760e63..12dd801b 100644 --- a/problems/p06/p06.mojo +++ b/problems/p06/p06.mojo @@ -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) diff --git a/problems/p07/p07.mojo b/problems/p07/p07.mojo index c5071af5..b765756e 100644 --- a/problems/p07/p07.mojo +++ b/problems/p07/p07.mojo @@ -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) diff --git a/problems/p07/p07_layout_tensor.mojo b/problems/p07/p07_layout_tensor.mojo index 59990dd3..0397b133 100644 --- a/problems/p07/p07_layout_tensor.mojo +++ b/problems/p07/p07_layout_tensor.mojo @@ -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) diff --git a/problems/p08/p08.mojo b/problems/p08/p08.mojo index 2e8657bd..33c750c6 100644 --- a/problems/p08/p08.mojo +++ b/problems/p08/p08.mojo @@ -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) diff --git a/problems/p08/p08_layout_tensor.mojo b/problems/p08/p08_layout_tensor.mojo index 90532a42..ab675e2e 100644 --- a/problems/p08/p08_layout_tensor.mojo +++ b/problems/p08/p08_layout_tensor.mojo @@ -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) diff --git a/problems/p09/p09.mojo b/problems/p09/p09.mojo index 3460e12b..bc42efc5 100644 --- a/problems/p09/p09.mojo +++ b/problems/p09/p09.mojo @@ -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 |" diff --git a/problems/p10/p10.mojo b/problems/p10/p10.mojo index 9ac898ae..f119a298 100644 --- a/problems/p10/p10.mojo +++ b/problems/p10/p10.mojo @@ -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" diff --git a/problems/p11/p11.mojo b/problems/p11/p11.mojo index 2743a0b8..7595ee88 100644 --- a/problems/p11/p11.mojo +++ b/problems/p11/p11.mojo @@ -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) diff --git a/problems/p11/p11_layout_tensor.mojo b/problems/p11/p11_layout_tensor.mojo index 8f9e6f8e..e394fa9c 100644 --- a/problems/p11/p11_layout_tensor.mojo +++ b/problems/p11/p11_layout_tensor.mojo @@ -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) diff --git a/problems/p12/p12.mojo b/problems/p12/p12.mojo index 38a3932e..5ab01850 100644 --- a/problems/p12/p12.mojo +++ b/problems/p12/p12.mojo @@ -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) diff --git a/problems/p12/p12_layout_tensor.mojo b/problems/p12/p12_layout_tensor.mojo index d99e0427..d64df5f9 100644 --- a/problems/p12/p12_layout_tensor.mojo +++ b/problems/p12/p12_layout_tensor.mojo @@ -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) diff --git a/problems/p13/p13.mojo b/problems/p13/p13.mojo index 929b109a..16cfced7 100644 --- a/problems/p13/p13.mojo +++ b/problems/p13/p13.mojo @@ -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 diff --git a/problems/p14/p14.mojo b/problems/p14/p14.mojo index cce933b6..d3c73fab 100644 --- a/problems/p14/p14.mojo +++ b/problems/p14/p14.mojo @@ -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", diff --git a/problems/p15/p15.mojo b/problems/p15/p15.mojo index 1f7e2c8b..2371ca15 100644 --- a/problems/p15/p15.mojo +++ b/problems/p15/p15.mojo @@ -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) diff --git a/problems/p16/p16.mojo b/problems/p16/p16.mojo index 737fc03b..92abe7bc 100644 --- a/problems/p16/p16.mojo +++ b/problems/p16/p16.mojo @@ -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", diff --git a/problems/p18/test/test_softmax.mojo b/problems/p18/test/test_softmax.mojo index 5171d550..4eb16fe7 100644 --- a/problems/p18/test/test_softmax.mojo +++ b/problems/p18/test/test_softmax.mojo @@ -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) @@ -79,5 +79,5 @@ def test_softmax(): print("All tests passed 🎉") -def main(): +def main() raises: test_softmax() diff --git a/problems/p23/p23.mojo b/problems/p23/p23.mojo index c188df32..fa4bb30c 100644 --- a/problems/p23/p23.mojo +++ b/problems/p23/p23.mojo @@ -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) diff --git a/problems/p24/p24.mojo b/problems/p24/p24.mojo index acee7a07..8c44e2cb 100644 --- a/problems/p24/p24.mojo +++ b/problems/p24/p24.mojo @@ -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) diff --git a/problems/p25/p25.mojo b/problems/p25/p25.mojo index 253ffe25..4ba7162f 100644 --- a/problems/p25/p25.mojo +++ b/problems/p25/p25.mojo @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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( diff --git a/problems/p26/p26.mojo b/problems/p26/p26.mojo index dded54af..c35fee33 100644 --- a/problems/p26/p26.mojo +++ b/problems/p26/p26.mojo @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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( diff --git a/problems/p27/p27.mojo b/problems/p27/p27.mojo index 88e35a67..22f8d08f 100644 --- a/problems/p27/p27.mojo +++ b/problems/p27/p27.mojo @@ -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 |" diff --git a/problems/p28/p28.mojo b/problems/p28/p28.mojo index 0eb59014..cff3ca15 100644 --- a/problems/p28/p28.mojo +++ b/problems/p28/p28.mojo @@ -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) @@ -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") diff --git a/problems/p29/p29.mojo b/problems/p29/p29.mojo index f25e87dd..44101ee4 100644 --- a/problems/p29/p29.mojo +++ b/problems/p29/p29.mojo @@ -196,7 +196,7 @@ fn double_buffered_stencil_computation[ # ANCHOR_END: double_buffered_stencil -def test_multi_stage_pipeline(): +def test_multi_stage_pipeline() raises: """Test Puzzle 29A: Multi-Stage Pipeline Coordination.""" with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) @@ -257,7 +257,7 @@ def test_multi_stage_pipeline(): print("✅ Multi-stage pipeline coordination test PASSED!") -def test_double_buffered_stencil(): +def test_double_buffered_stencil() raises: """Test Puzzle 29B: Double-Buffered Stencil Computation.""" with DeviceContext() as ctx: # Test Puzzle 29B: Double-Buffered Stencil Computation @@ -334,7 +334,7 @@ def test_double_buffered_stencil(): print("✅ Double-buffered stencil test PASSED!") -def main(): +def main() raises: """Run GPU synchronization tests based on command line arguments.""" print("Puzzle 29: GPU Synchronization Primitives") print("=" * 50) diff --git a/problems/p30/p30.mojo b/problems/p30/p30.mojo index 8f8749c8..ea5cdce9 100644 --- a/problems/p30/p30.mojo +++ b/problems/p30/p30.mojo @@ -189,7 +189,7 @@ fn benchmark_kernel3_parameterized[test_size: Int](mut b: Bencher) raises: b.iter_custom[kernel3_workflow](bench_ctx) -def test_kernel1(): +def test_kernel1() raises: """Test kernel 1.""" print("Testing kernel 1...") with DeviceContext() as ctx: @@ -232,7 +232,7 @@ def test_kernel1(): print("✅ Kernel 1 test passed") -def test_kernel2(): +def test_kernel2() raises: """Test kernel 2.""" print("Testing kernel 2...") with DeviceContext() as ctx: @@ -278,7 +278,7 @@ def test_kernel2(): print("✅ Kernel 2 test passed,", processed, "elements processed") -def test_kernel3(): +def test_kernel3() raises: """Test kernel 3.""" print("Testing kernel 3...") with DeviceContext() as ctx: @@ -321,7 +321,7 @@ def test_kernel3(): print("✅ Kernel 3 test passed") -def main(): +def main() raises: """Run the memory access pattern tests.""" args = argv() if len(args) < 2: diff --git a/problems/p31/p31.mojo b/problems/p31/p31.mojo index 9ba699a9..3f151327 100644 --- a/problems/p31/p31.mojo +++ b/problems/p31/p31.mojo @@ -297,7 +297,7 @@ fn benchmark_balanced_parameterized[test_size: Int](mut b: Bencher) raises: b.iter_custom[balanced_workflow](bench_ctx) -def test_minimal(): +def test_minimal() raises: """Test minimal kernel.""" print("Testing minimal kernel...") with DeviceContext() as ctx: @@ -340,7 +340,7 @@ def test_minimal(): print("✅ Minimal kernel test passed") -def test_sophisticated(): +def test_sophisticated() raises: """Test sophisticated kernel.""" print("Testing sophisticated kernel...") with DeviceContext() as ctx: @@ -384,7 +384,7 @@ def test_sophisticated(): print("✅ Sophisticated kernel test passed") -def test_balanced(): +def test_balanced() raises: """Test balanced kernel.""" print("Testing balanced kernel...") with DeviceContext() as ctx: @@ -428,7 +428,7 @@ def test_balanced(): print("✅ Balanced kernel test passed") -def main(): +def main() raises: """Run the occupancy efficiency mystery tests.""" args = argv() if len(args) < 2: diff --git a/problems/p33/p33.mojo b/problems/p33/p33.mojo index 90e9274e..66f20302 100644 --- a/problems/p33/p33.mojo +++ b/problems/p33/p33.mojo @@ -241,7 +241,7 @@ fn tensor_core_matrix_multiplication[ # ANCHOR_END: tensor_core_matrix_multiplication -def main(): +def main() raises: print("Puzzle 33: Tensor Core Operations") if len(argv()) < 2: diff --git a/problems/p34/p34.mojo b/problems/p34/p34.mojo index 905efdf1..65e9fd2c 100644 --- a/problems/p34/p34.mojo +++ b/problems/p34/p34.mojo @@ -115,7 +115,7 @@ fn advanced_cluster_patterns[ # ANCHOR_END: advanced_cluster_patterns -def main(): +def main() raises: """Test cluster programming concepts using proper Mojo GPU patterns.""" if len(argv()) < 2: print("Usage: p34.mojo [--coordination | --reduction | --advanced]") diff --git a/solutions/p01/p01.mojo b/solutions/p01/p01.mojo index 66b26f70..0369bcd5 100644 --- a/solutions/p01/p01.mojo +++ b/solutions/p01/p01.mojo @@ -21,7 +21,7 @@ fn add_10( # ANCHOR_END: add_10_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) out.enqueue_fill(0) diff --git a/solutions/p02/p02.mojo b/solutions/p02/p02.mojo index 75558b66..6bcf7acc 100644 --- a/solutions/p02/p02.mojo +++ b/solutions/p02/p02.mojo @@ -22,7 +22,7 @@ fn add( # ANCHOR_END: add_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) out.enqueue_fill(0) diff --git a/solutions/p03/p03.mojo b/solutions/p03/p03.mojo index d16a91d1..de825362 100644 --- a/solutions/p03/p03.mojo +++ b/solutions/p03/p03.mojo @@ -23,7 +23,7 @@ fn add_10_guard( # ANCHOR_END: add_10_guard_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) out.enqueue_fill(0) diff --git a/solutions/p04/p04.mojo b/solutions/p04/p04.mojo index 442bce41..dc097b80 100644 --- a/solutions/p04/p04.mojo +++ b/solutions/p04/p04.mojo @@ -24,7 +24,7 @@ fn add_10_2d( # ANCHOR_END: add_10_2d_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE * SIZE) out.enqueue_fill(0) diff --git a/solutions/p04/p04_layout_tensor.mojo b/solutions/p04/p04_layout_tensor.mojo index 4971ccaf..1eaf5d18 100644 --- a/solutions/p04/p04_layout_tensor.mojo +++ b/solutions/p04/p04_layout_tensor.mojo @@ -25,7 +25,7 @@ fn add_10_2d( # ANCHOR_END: add_10_2d_layout_tensor_solution -def main(): +def main() raises: with DeviceContext() as ctx: out_buf = ctx.enqueue_create_buffer[dtype](SIZE * SIZE) out_buf.enqueue_fill(0) diff --git a/solutions/p05/p05.mojo b/solutions/p05/p05.mojo index 8944cec5..dacb7ec3 100644 --- a/solutions/p05/p05.mojo +++ b/solutions/p05/p05.mojo @@ -25,7 +25,7 @@ fn broadcast_add( # ANCHOR_END: broadcast_add_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE * SIZE) out.enqueue_fill(0) diff --git a/solutions/p05/p05_layout_tensor.mojo b/solutions/p05/p05_layout_tensor.mojo index 7e12f92c..6a5cbe54 100644 --- a/solutions/p05/p05_layout_tensor.mojo +++ b/solutions/p05/p05_layout_tensor.mojo @@ -32,7 +32,7 @@ fn broadcast_add[ # ANCHOR_END: broadcast_add_layout_tensor_solution -def main(): +def main() raises: with DeviceContext() as ctx: out_buf = ctx.enqueue_create_buffer[dtype](SIZE * SIZE) out_buf.enqueue_fill(0) diff --git a/solutions/p06/p06.mojo b/solutions/p06/p06.mojo index c7503b18..e0209502 100644 --- a/solutions/p06/p06.mojo +++ b/solutions/p06/p06.mojo @@ -23,7 +23,7 @@ fn add_10_blocks( # ANCHOR_END: add_10_blocks_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) out.enqueue_fill(0) diff --git a/solutions/p07/p07.mojo b/solutions/p07/p07.mojo index 2a30b08b..6e345079 100644 --- a/solutions/p07/p07.mojo +++ b/solutions/p07/p07.mojo @@ -24,7 +24,7 @@ fn add_10_blocks_2d( # ANCHOR_END: add_10_blocks_2d_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE * SIZE) out.enqueue_fill(0) diff --git a/solutions/p07/p07_layout_tensor.mojo b/solutions/p07/p07_layout_tensor.mojo index 96838216..1d633d8a 100644 --- a/solutions/p07/p07_layout_tensor.mojo +++ b/solutions/p07/p07_layout_tensor.mojo @@ -29,7 +29,7 @@ fn add_10_blocks_2d[ # ANCHOR_END: add_10_blocks_2d_layout_tensor_solution -def main(): +def main() raises: with DeviceContext() as ctx: out_buf = ctx.enqueue_create_buffer[dtype](SIZE * SIZE) out_buf.enqueue_fill(0) diff --git a/solutions/p08/p08.mojo b/solutions/p08/p08.mojo index def0941f..cc877017 100644 --- a/solutions/p08/p08.mojo +++ b/solutions/p08/p08.mojo @@ -43,7 +43,7 @@ fn add_10_shared( # ANCHOR_END: add_10_shared_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) out.enqueue_fill(0) diff --git a/solutions/p08/p08_layout_tensor.mojo b/solutions/p08/p08_layout_tensor.mojo index b9c6fdee..3d075bf4 100644 --- a/solutions/p08/p08_layout_tensor.mojo +++ b/solutions/p08/p08_layout_tensor.mojo @@ -47,7 +47,7 @@ fn add_10_shared_layout_tensor[ # ANCHOR_END: add_10_shared_layout_tensor_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) out.enqueue_fill(0) diff --git a/solutions/p10/p10.mojo b/solutions/p10/p10.mojo index 936b86a8..13286e18 100644 --- a/solutions/p10/p10.mojo +++ b/solutions/p10/p10.mojo @@ -66,7 +66,7 @@ fn add_10_2d( # ANCHOR_END: add_10_2d_solution -def main(): +def main() raises: if len(argv()) != 2: print( "Expected one command-line argument: '--memory-bug' or" diff --git a/solutions/p11/p11.mojo b/solutions/p11/p11.mojo index d40a34ed..69d91460 100644 --- a/solutions/p11/p11.mojo +++ b/solutions/p11/p11.mojo @@ -42,7 +42,7 @@ fn pooling( # ANCHOR_END: pooling_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) out.enqueue_fill(0) diff --git a/solutions/p11/p11_layout_tensor.mojo b/solutions/p11/p11_layout_tensor.mojo index 4f9fafc5..a9e4f929 100644 --- a/solutions/p11/p11_layout_tensor.mojo +++ b/solutions/p11/p11_layout_tensor.mojo @@ -53,7 +53,7 @@ fn pooling[ # ANCHOR_END: pooling_layout_tensor_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) out.enqueue_fill(0) diff --git a/solutions/p12/p12.mojo b/solutions/p12/p12.mojo index 91b1a489..b2ab51e8 100644 --- a/solutions/p12/p12.mojo +++ b/solutions/p12/p12.mojo @@ -56,7 +56,7 @@ fn dot_product( # ANCHOR_END: dot_product_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](1) out.enqueue_fill(0) diff --git a/solutions/p12/p12_layout_tensor.mojo b/solutions/p12/p12_layout_tensor.mojo index 978ed60e..64f6d079 100644 --- a/solutions/p12/p12_layout_tensor.mojo +++ b/solutions/p12/p12_layout_tensor.mojo @@ -55,7 +55,7 @@ fn dot_product[ # ANCHOR_END: dot_product_layout_tensor_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](1) out.enqueue_fill(0) diff --git a/solutions/p13/p13.mojo b/solutions/p13/p13.mojo index ca7e4f22..2f1359a4 100644 --- a/solutions/p13/p13.mojo +++ b/solutions/p13/p13.mojo @@ -141,7 +141,7 @@ fn conv_1d_block_boundary[ # ANCHOR_END: conv_1d_block_boundary_solution -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 diff --git a/solutions/p14/p14.mojo b/solutions/p14/p14.mojo index 23d98554..61145ac1 100644 --- a/solutions/p14/p14.mojo +++ b/solutions/p14/p14.mojo @@ -152,7 +152,7 @@ fn prefix_sum_block_sum_phase[ # ANCHOR_END: prefix_sum_complete_solution -def main(): +def main() raises: with DeviceContext() as ctx: use_simple = argv()[1] == "--simple" size = SIZE if use_simple else SIZE_2 diff --git a/solutions/p15/p15.mojo b/solutions/p15/p15.mojo index 3bdd09f9..2a2f169f 100644 --- a/solutions/p15/p15.mojo +++ b/solutions/p15/p15.mojo @@ -73,7 +73,7 @@ fn axis_sum[ # ANCHOR_END: axis_sum_solution -def main(): +def main() raises: with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](BATCH) out.enqueue_fill(0) diff --git a/solutions/p16/p16.mojo b/solutions/p16/p16.mojo index 453c73b9..c519d26f 100644 --- a/solutions/p16/p16.mojo +++ b/solutions/p16/p16.mojo @@ -228,7 +228,7 @@ fn matmul_idiomatic_tiled[ # ANCHOR_END: matmul_idiomatic_tiled_solution -def main(): +def main() raises: with DeviceContext() as ctx: size = ( SIZE_TILED if argv()[1] == "--idiomatic-tiled" diff --git a/solutions/p18/test/test_softmax.mojo b/solutions/p18/test/test_softmax.mojo index 5171d550..4eb16fe7 100644 --- a/solutions/p18/test/test_softmax.mojo +++ b/solutions/p18/test/test_softmax.mojo @@ -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) @@ -79,5 +79,5 @@ def test_softmax(): print("All tests passed 🎉") -def main(): +def main() raises: test_softmax() diff --git a/solutions/p23/p23.mojo b/solutions/p23/p23.mojo index d8d3a311..c4c9bd25 100644 --- a/solutions/p23/p23.mojo +++ b/solutions/p23/p23.mojo @@ -334,7 +334,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) diff --git a/solutions/p24/p24.mojo b/solutions/p24/p24.mojo index 4044ce75..55750a23 100644 --- a/solutions/p24/p24.mojo +++ b/solutions/p24/p24.mojo @@ -325,7 +325,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) diff --git a/solutions/p25/p25.mojo b/solutions/p25/p25.mojo index 53873da3..ad2ce01e 100644 --- a/solutions/p25/p25.mojo +++ b/solutions/p25/p25.mojo @@ -212,7 +212,7 @@ fn conditional_broadcast[ # ANCHOR_END: conditional_broadcast_solution -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) @@ -256,7 +256,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) @@ -320,7 +320,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) @@ -375,7 +375,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) @@ -421,7 +421,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) @@ -482,7 +482,7 @@ def test_conditional_broadcast(): print("✅ Conditional broadcast test passed!") -def main(): +def main() raises: print("WARP_SIZE: ", WARP_SIZE) if len(argv()) != 2: print( diff --git a/solutions/p26/p26.mojo b/solutions/p26/p26.mojo index 30a57073..cb4eb437 100644 --- a/solutions/p26/p26.mojo +++ b/solutions/p26/p26.mojo @@ -222,7 +222,7 @@ fn warp_partition[ # ANCHOR_END: warp_partition_solution -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) @@ -267,7 +267,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) @@ -307,7 +307,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) @@ -367,7 +367,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) @@ -409,7 +409,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) @@ -484,7 +484,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( diff --git a/solutions/p27/p27.mojo b/solutions/p27/p27.mojo index fb447c52..39b4622a 100644 --- a/solutions/p27/p27.mojo +++ b/solutions/p27/p27.mojo @@ -214,7 +214,7 @@ fn block_normalize_vector[ # ANCHOR_END: block_normalize_solution -def main(): +def main() raises: if len(argv()) != 2: print( "Usage: --traditional-dot-product | --block-sum-dot-product |" diff --git a/solutions/p28/p28.mojo b/solutions/p28/p28.mojo index a7419e93..57c80636 100644 --- a/solutions/p28/p28.mojo +++ b/solutions/p28/p28.mojo @@ -88,7 +88,7 @@ fn async_copy_overlap_convolution[ # ANCHOR_END: async_copy_overlap_convolution_solution -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) @@ -179,7 +179,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") diff --git a/solutions/p29/p29.mojo b/solutions/p29/p29.mojo index 98b0a275..5dee39fa 100644 --- a/solutions/p29/p29.mojo +++ b/solutions/p29/p29.mojo @@ -271,7 +271,7 @@ fn double_buffered_stencil_computation[ # ANCHOR_END: double_buffered_stencil_solution -def test_multi_stage_pipeline(): +def test_multi_stage_pipeline() raises: """Test Puzzle 26A: Multi-Stage Pipeline Coordination.""" with DeviceContext() as ctx: out = ctx.enqueue_create_buffer[dtype](SIZE) @@ -332,7 +332,7 @@ def test_multi_stage_pipeline(): print("✅ Multi-stage pipeline coordination test PASSED!") -def test_double_buffered_stencil(): +def test_double_buffered_stencil() raises: """Test Puzzle 26B: Double-Buffered Stencil Computation.""" with DeviceContext() as ctx: # Test Puzzle 26B: Double-Buffered Stencil Computation @@ -409,7 +409,7 @@ def test_double_buffered_stencil(): print("✅ Double-buffered stencil test PASSED!") -def main(): +def main() raises: """Run GPU synchronization tests based on command line arguments.""" print("Puzzle 26: GPU Synchronization Primitives") print("=" * 50) diff --git a/solutions/p33/p33.mojo b/solutions/p33/p33.mojo index 8e1adddc..19e033aa 100644 --- a/solutions/p33/p33.mojo +++ b/solutions/p33/p33.mojo @@ -256,7 +256,7 @@ fn tensor_core_matrix_multiplication[ # ANCHOR_END: tensor_core_matrix_multiplication_solution -def main(): +def main() raises: print("Puzzle 33: Tensor Core Operations") if len(argv()) < 2: diff --git a/solutions/p34/p34.mojo b/solutions/p34/p34.mojo index cad94e4d..31ca775d 100644 --- a/solutions/p34/p34.mojo +++ b/solutions/p34/p34.mojo @@ -196,7 +196,7 @@ fn advanced_cluster_patterns[ # ANCHOR_END: advanced_cluster_patterns_solution -def main(): +def main() raises: """Test cluster programming concepts using proper Mojo GPU patterns.""" if len(argv()) < 2: print("Usage: p34.mojo [--coordination | --reduction | --advanced]")