Skip to content

Commit 84d4ad8

Browse files
BradLarsonrajuptvs
andauthored
Make Int <-> UInt conversions explicit. (#149)
Co-authored-by: raju <raju.ptvs@gmail.com>
1 parent 4dc8e07 commit 84d4ad8

Some content is hidden

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

62 files changed

+279
-275
lines changed

problems/p03/p03.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ alias dtype = DType.float32
1313
fn add_10_guard(
1414
output: UnsafePointer[Scalar[dtype], MutAnyOrigin],
1515
a: UnsafePointer[Scalar[dtype], MutAnyOrigin],
16-
size: Int,
16+
size: UInt,
1717
):
1818
i = thread_idx.x
1919
# FILL ME IN (roughly 2 lines)
@@ -35,7 +35,7 @@ def main():
3535
ctx.enqueue_function_checked[add_10_guard, add_10_guard](
3636
out,
3737
a,
38-
SIZE,
38+
UInt(SIZE),
3939
grid_dim=BLOCKS_PER_GRID,
4040
block_dim=THREADS_PER_BLOCK,
4141
)

problems/p04/p04.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ alias dtype = DType.float32
1313
fn add_10_2d(
1414
output: UnsafePointer[Scalar[dtype], MutAnyOrigin],
1515
a: UnsafePointer[Scalar[dtype], MutAnyOrigin],
16-
size: Int,
16+
size: UInt,
1717
):
1818
row = thread_idx.y
1919
col = thread_idx.x
@@ -41,7 +41,7 @@ def main():
4141
ctx.enqueue_function_checked[add_10_2d, add_10_2d](
4242
out,
4343
a,
44-
SIZE,
44+
UInt(SIZE),
4545
grid_dim=BLOCKS_PER_GRID,
4646
block_dim=THREADS_PER_BLOCK,
4747
)

problems/p04/p04_layout_tensor.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ alias layout = Layout.row_major(SIZE, SIZE)
1414
fn add_10_2d(
1515
output: LayoutTensor[dtype, layout, MutAnyOrigin],
1616
a: LayoutTensor[dtype, layout, MutAnyOrigin],
17-
size: Int,
17+
size: UInt,
1818
):
1919
row = thread_idx.y
2020
col = thread_idx.x
@@ -46,7 +46,7 @@ def main():
4646
ctx.enqueue_function_checked[add_10_2d, add_10_2d](
4747
out_tensor,
4848
a_tensor,
49-
SIZE,
49+
UInt(SIZE),
5050
grid_dim=BLOCKS_PER_GRID,
5151
block_dim=THREADS_PER_BLOCK,
5252
)

problems/p05/p05.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn broadcast_add(
1414
output: UnsafePointer[Scalar[dtype], MutAnyOrigin],
1515
a: UnsafePointer[Scalar[dtype], MutAnyOrigin],
1616
b: UnsafePointer[Scalar[dtype], MutAnyOrigin],
17-
size: Int,
17+
size: UInt,
1818
):
1919
row = thread_idx.y
2020
col = thread_idx.x
@@ -45,7 +45,7 @@ def main():
4545
out,
4646
a,
4747
b,
48-
SIZE,
48+
UInt(SIZE),
4949
grid_dim=BLOCKS_PER_GRID,
5050
block_dim=THREADS_PER_BLOCK,
5151
)

problems/p05/p05_layout_tensor.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn broadcast_add[
2121
output: LayoutTensor[dtype, out_layout, MutAnyOrigin],
2222
a: LayoutTensor[dtype, a_layout, ImmutAnyOrigin],
2323
b: LayoutTensor[dtype, b_layout, ImmutAnyOrigin],
24-
size: Int,
24+
size: UInt,
2525
):
2626
row = thread_idx.y
2727
col = thread_idx.x
@@ -63,7 +63,7 @@ def main():
6363
out_tensor,
6464
a_tensor,
6565
b_tensor,
66-
SIZE,
66+
UInt(SIZE),
6767
grid_dim=BLOCKS_PER_GRID,
6868
block_dim=THREADS_PER_BLOCK,
6969
)

problems/p06/p06.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ alias dtype = DType.float32
1313
fn add_10_blocks(
1414
output: UnsafePointer[Scalar[dtype], MutAnyOrigin],
1515
a: UnsafePointer[Scalar[dtype], MutAnyOrigin],
16-
size: Int,
16+
size: UInt,
1717
):
1818
i = block_dim.x * block_idx.x + thread_idx.x
1919
# FILL ME IN (roughly 2 lines)
@@ -35,7 +35,7 @@ def main():
3535
ctx.enqueue_function_checked[add_10_blocks, add_10_blocks](
3636
out,
3737
a,
38-
SIZE,
38+
UInt(SIZE),
3939
grid_dim=BLOCKS_PER_GRID,
4040
block_dim=THREADS_PER_BLOCK,
4141
)

problems/p07/p07.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ alias dtype = DType.float32
1313
fn add_10_blocks_2d(
1414
output: UnsafePointer[Scalar[dtype], MutAnyOrigin],
1515
a: UnsafePointer[Scalar[dtype], MutAnyOrigin],
16-
size: Int,
16+
size: UInt,
1717
):
1818
row = block_dim.y * block_idx.y + thread_idx.y
1919
col = block_dim.x * block_idx.x + thread_idx.x
@@ -42,7 +42,7 @@ def main():
4242
ctx.enqueue_function_checked[add_10_blocks_2d, add_10_blocks_2d](
4343
out,
4444
a,
45-
SIZE,
45+
UInt(SIZE),
4646
grid_dim=BLOCKS_PER_GRID,
4747
block_dim=THREADS_PER_BLOCK,
4848
)

problems/p07/p07_layout_tensor.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn add_10_blocks_2d[
1818
](
1919
output: LayoutTensor[dtype, out_layout, MutAnyOrigin],
2020
a: LayoutTensor[dtype, a_layout, ImmutAnyOrigin],
21-
size: Int,
21+
size: UInt,
2222
):
2323
row = block_dim.y * block_idx.y + thread_idx.y
2424
col = block_dim.x * block_idx.x + thread_idx.x
@@ -53,7 +53,7 @@ def main():
5353
ctx.enqueue_function_checked[kernel, kernel](
5454
out_tensor,
5555
a_tensor,
56-
SIZE,
56+
UInt(SIZE),
5757
grid_dim=BLOCKS_PER_GRID,
5858
block_dim=THREADS_PER_BLOCK,
5959
)

problems/p08/p08.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ alias dtype = DType.float32
1616
fn add_10_shared(
1717
output: UnsafePointer[Scalar[dtype], MutAnyOrigin],
1818
a: UnsafePointer[Scalar[dtype], MutAnyOrigin],
19-
size: Int,
19+
size: UInt,
2020
):
2121
shared = stack_allocation[
2222
TPB,
@@ -48,7 +48,7 @@ def main():
4848
ctx.enqueue_function_checked[add_10_shared, add_10_shared](
4949
out,
5050
a,
51-
SIZE,
51+
UInt(SIZE),
5252
grid_dim=BLOCKS_PER_GRID,
5353
block_dim=THREADS_PER_BLOCK,
5454
)

problems/p08/p08_layout_tensor.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn add_10_shared_layout_tensor[
1919
](
2020
output: LayoutTensor[dtype, layout, MutAnyOrigin],
2121
a: LayoutTensor[dtype, layout, ImmutAnyOrigin],
22-
size: Int,
22+
size: UInt,
2323
):
2424
# Allocate shared memory using LayoutTensor with explicit address_space
2525
shared = LayoutTensor[
@@ -57,7 +57,7 @@ def main():
5757
ctx.enqueue_function_checked[kernel, kernel](
5858
out_tensor,
5959
a_tensor,
60-
SIZE,
60+
UInt(SIZE),
6161
grid_dim=BLOCKS_PER_GRID,
6262
block_dim=THREADS_PER_BLOCK,
6363
)

0 commit comments

Comments
 (0)