Skip to content

Commit ca891d3

Browse files
Switch starter.mojo kernels and solve functions from fn to def (#240)
Mojo 26.2 deprecates the `fn` keyword. Per the RFC "Remove fn from Mojo" (accepted 23 Feb 2026), `def` is becoming Mojo's single function declaration keyword: - `def foo(...)` — non-raising (matches old `fn`) - `def foo(...) raises` — raising form (replaces old `fn ... raises` and the old implicitly-raising `def`) `fn` will be removed before 1.0. Starters emit a deprecation warning on every compile today; refactor to the new form now so users don't learn the dead keyword. Kernels become `def` without `raises` (they don't raise). `solve` becomes `def ... raises` since it calls DeviceContext, compile_function, enqueue_function, and synchronize — all of which raise. Verified against Mojo 26.2 on a Tesla T4: the transformed vector_add starter compiles cleanly and produces a valid shared library. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0dd4aca commit ca891d3

78 files changed

Lines changed: 97 additions & 97 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

challenges/easy/19_reverse_array/starter/starter.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn reverse_array_kernel(input: UnsafePointer[Float32, MutExternalOrigin], N: Int32):
7+
def reverse_array_kernel(input: UnsafePointer[Float32, MutExternalOrigin], N: Int32):
88
pass
99

1010

1111
# input is a device pointer (i.e. pointer to memory on the GPU)
1212
@export
13-
fn solve(input: UnsafePointer[Float32, MutExternalOrigin], N: Int32) raises:
13+
def solve(input: UnsafePointer[Float32, MutExternalOrigin], N: Int32) raises:
1414
var threadsPerBlock: Int32 = 256
1515
var ctx = DeviceContext()
1616

challenges/easy/1_vector_add/starter/starter.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn vector_add_kernel(
7+
def vector_add_kernel(
88
A: UnsafePointer[Float32, MutExternalOrigin],
99
B: UnsafePointer[Float32, MutExternalOrigin],
1010
C: UnsafePointer[Float32, MutExternalOrigin],
@@ -15,7 +15,7 @@ fn vector_add_kernel(
1515

1616
# A, B, C are device pointers (i.e. pointers to memory on the GPU)
1717
@export
18-
fn solve(
18+
def solve(
1919
A: UnsafePointer[Float32, MutExternalOrigin],
2020
B: UnsafePointer[Float32, MutExternalOrigin],
2121
C: UnsafePointer[Float32, MutExternalOrigin],

challenges/easy/21_relu/starter/starter.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn relu_kernel(
7+
def relu_kernel(
88
input: UnsafePointer[Float32, MutExternalOrigin],
99
output: UnsafePointer[Float32, MutExternalOrigin],
1010
N: Int32,
@@ -14,7 +14,7 @@ fn relu_kernel(
1414

1515
# input, output are device pointers (i.e. pointers to memory on the GPU)
1616
@export
17-
fn solve(
17+
def solve(
1818
input: UnsafePointer[Float32, MutExternalOrigin],
1919
output: UnsafePointer[Float32, MutExternalOrigin],
2020
N: Int32,

challenges/easy/23_leaky_relu/starter/starter.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn leaky_relu_kernel(
7+
def leaky_relu_kernel(
88
input: UnsafePointer[Float32, MutExternalOrigin],
99
output: UnsafePointer[Float32, MutExternalOrigin],
1010
N: Int32,
@@ -14,7 +14,7 @@ fn leaky_relu_kernel(
1414

1515
# input, output are device pointers (i.e. pointers to memory on the GPU)
1616
@export
17-
fn solve(
17+
def solve(
1818
input: UnsafePointer[Float32, MutExternalOrigin],
1919
output: UnsafePointer[Float32, MutExternalOrigin],
2020
N: Int32,

challenges/easy/24_rainbow_table/starter/starter.mojo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn fnv1a_hash(input: Int32) -> UInt32:
7+
def fnv1a_hash(input: Int32) -> UInt32:
88
alias FNV_PRIME: UInt32 = 16777619
99
alias OFFSET_BASIS: UInt32 = 2166136261
1010

@@ -17,7 +17,7 @@ fn fnv1a_hash(input: Int32) -> UInt32:
1717
return hash
1818

1919

20-
fn fnv1a_hash_kernel(
20+
def fnv1a_hash_kernel(
2121
input: UnsafePointer[Int32, MutExternalOrigin],
2222
output: UnsafePointer[UInt32, MutExternalOrigin],
2323
N: Int32,
@@ -28,7 +28,7 @@ fn fnv1a_hash_kernel(
2828

2929
# input, output are device pointers (i.e. pointers to memory on the GPU)
3030
@export
31-
fn solve(
31+
def solve(
3232
input: UnsafePointer[Int32, MutExternalOrigin],
3333
output: UnsafePointer[UInt32, MutExternalOrigin],
3434
N: Int32,

challenges/easy/2_matrix_multiplication/starter/starter.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn matrix_multiplication_kernel(
7+
def matrix_multiplication_kernel(
88
A: UnsafePointer[Float32, MutExternalOrigin],
99
B: UnsafePointer[Float32, MutExternalOrigin],
1010
C: UnsafePointer[Float32, MutExternalOrigin],
@@ -17,7 +17,7 @@ fn matrix_multiplication_kernel(
1717

1818
# A, B, C are device pointers (i.e. pointers to memory on the GPU)
1919
@export
20-
fn solve(
20+
def solve(
2121
A: UnsafePointer[Float32, MutExternalOrigin],
2222
B: UnsafePointer[Float32, MutExternalOrigin],
2323
C: UnsafePointer[Float32, MutExternalOrigin],

challenges/easy/31_matrix_copy/starter/starter.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn copy_matrix_kernel(
7+
def copy_matrix_kernel(
88
A: UnsafePointer[Float32, MutExternalOrigin],
99
B: UnsafePointer[Float32, MutExternalOrigin],
1010
N: Int32,
@@ -14,7 +14,7 @@ fn copy_matrix_kernel(
1414

1515
# A, B are device pointers (i.e. pointers to memory on the GPU)
1616
@export
17-
fn solve(
17+
def solve(
1818
A: UnsafePointer[Float32, MutExternalOrigin],
1919
B: UnsafePointer[Float32, MutExternalOrigin],
2020
N: Int32,

challenges/easy/3_matrix_transpose/starter/starter.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn matrix_transpose_kernel(
7+
def matrix_transpose_kernel(
88
input: UnsafePointer[Float32, MutExternalOrigin],
99
output: UnsafePointer[Float32, MutExternalOrigin],
1010
rows: Int32,
@@ -15,7 +15,7 @@ fn matrix_transpose_kernel(
1515

1616
# input, output are device pointers (i.e. pointers to memory on the GPU)
1717
@export
18-
fn solve(
18+
def solve(
1919
input: UnsafePointer[Float32, MutExternalOrigin],
2020
output: UnsafePointer[Float32, MutExternalOrigin],
2121
rows: Int32,

challenges/easy/52_silu/starter/starter.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn silu_kernel(
7+
def silu_kernel(
88
input: UnsafePointer[Float32, MutExternalOrigin],
99
output: UnsafePointer[Float32, MutExternalOrigin],
1010
N: Int32,
@@ -14,7 +14,7 @@ fn silu_kernel(
1414

1515
# input, output are device pointers
1616
@export
17-
fn solve(
17+
def solve(
1818
input: UnsafePointer[Float32, MutExternalOrigin],
1919
output: UnsafePointer[Float32, MutExternalOrigin],
2020
N: Int32,

challenges/easy/54_swiglu/starter/starter.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from std.memory import UnsafePointer
44
from std.math import ceildiv
55

66

7-
fn swiglu_kernel(
7+
def swiglu_kernel(
88
input: UnsafePointer[Float32, MutExternalOrigin],
99
output: UnsafePointer[Float32, MutExternalOrigin],
1010
N: Int32,
@@ -14,7 +14,7 @@ fn swiglu_kernel(
1414

1515
# input, output are device pointers
1616
@export
17-
fn solve(
17+
def solve(
1818
input: UnsafePointer[Float32, MutExternalOrigin],
1919
output: UnsafePointer[Float32, MutExternalOrigin],
2020
N: Int32,

0 commit comments

Comments
 (0)