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
1 change: 1 addition & 0 deletions src/__init__.mojo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .util import *
from .testing_utils import *
from .level1 import *
from .level2 import *
Expand Down
6 changes: 3 additions & 3 deletions src/level1/asum_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ fn asum_device[
incx: Int,
result: UnsafePointer[Scalar[dtype], MutAnyOrigin]
):
if n < 1 or incx <= 0:
result[0] = 0
return

var local_tid = thread_idx.x

Expand Down Expand Up @@ -65,6 +62,9 @@ fn blas_asum[dtype: DType](
d_res: UnsafePointer[Scalar[dtype], MutAnyOrigin],
ctx: DeviceContext
) raises:
blas_error_if["blas_asum", "n < 0"](n < 0)
blas_error_if["blas_asum", "incx <= 0"](incx <= 0)

comptime kernel = asum_device[TBsize, dtype]
ctx.enqueue_function[kernel, kernel](
n,
Expand Down
14 changes: 8 additions & 6 deletions src/level1/axpy_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ fn axpy_device[dtype: DType](
y: UnsafePointer[Scalar[dtype], MutAnyOrigin],
incy: Int
):
if (n <= 0):
return
if (a == 0):
return
if (incx == 0 or incy == 0):
return

var global_i = global_idx.x
var n_threads = Int(grid_dim.x * block_dim.x)
Expand All @@ -36,6 +30,14 @@ fn blas_axpy[dtype: DType](
incy: Int,
ctx: DeviceContext
) raises:
blas_error_if["blas_axpy", "n < 0"](n < 0)
blas_error_if["blas_axpy", "incx == 0"](incx == 0)
blas_error_if["blas_axpy", "incy == 0"](incy == 0)

# quick return
if(a == 0) :
return

comptime kernel = axpy_device[dtype]
ctx.enqueue_function[kernel, kernel](
n, a,
Expand Down
10 changes: 6 additions & 4 deletions src/level1/copy_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ fn copy_device[dtype: DType](
y: UnsafePointer[Scalar[dtype], MutAnyOrigin],
incy: Int
):
if (n <= 0):
return
if (incx == 0 or incy == 0):
return

var global_i = global_idx.x
var n_threads = Int(grid_dim.x * block_dim.x)
Expand All @@ -34,6 +30,12 @@ fn blas_copy[dtype: DType](
incy: Int,
ctx: DeviceContext
) raises:

blas_error_if["blas_copy", "n < 0"](n < 0)
blas_error_if["blas_copy", "incx == 0"](incx == 0)
blas_error_if["blas_copy", "incy == 0"](incy == 0)


comptime kernel = copy_device[dtype]
ctx.enqueue_function[kernel, kernel](
n,
Expand Down
7 changes: 5 additions & 2 deletions src/level1/dot_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ fn dot_device[
incy: Int,
output: UnsafePointer[Scalar[dtype], MutAnyOrigin],
):
if n < 1:
return

var global_i = block_dim.x * block_idx.x + thread_idx.x
var n_threads = grid_dim.x * block_dim.x
Expand Down Expand Up @@ -59,6 +57,11 @@ fn blas_dot[dtype: DType](
d_out: UnsafePointer[Scalar[dtype], MutAnyOrigin],
ctx: DeviceContext
) raises:

blas_error_if["blas_dot", "n < 0"](n < 0)
blas_error_if["blas_copy", "incx == 0"](incx == 0)
blas_error_if["blas_copy", "incy == 0"](incy == 0)

comptime kernel = dot_device[TBsize, dtype]
ctx.enqueue_function[kernel, kernel](
n, d_x, incx,
Expand Down
6 changes: 4 additions & 2 deletions src/level1/dotc_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ fn dotc_device[
incy: Int,
output: UnsafePointer[Scalar[dtype], MutAnyOrigin],
):
if n < 1:
return

var global_i = block_dim.x * block_idx.x + thread_idx.x
var n_threads = grid_dim.x * block_dim.x
Expand Down Expand Up @@ -70,6 +68,10 @@ fn blas_dotc[dtype: DType](
d_out: UnsafePointer[Scalar[dtype], MutAnyOrigin],
ctx: DeviceContext
) raises:
blas_error_if["blas_dotc", "n < 0"](n < 0)
blas_error_if["blas_dotc", "incx == 0"](incx == 0)
blas_error_if["blas_dotc", "incy == 0"](incy == 0)

comptime kernel = dotc_device[TBsize, dtype]
ctx.enqueue_function[kernel, kernel](
n, d_x, incx,
Expand Down
8 changes: 6 additions & 2 deletions src/level1/dotu_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ fn dotu_device[
incy: Int,
output: UnsafePointer[Scalar[dtype], MutAnyOrigin],
):
if n < 1:
return


var global_i = block_dim.x * block_idx.x + thread_idx.x
var n_threads = grid_dim.x * block_dim.x
Expand Down Expand Up @@ -70,6 +69,11 @@ fn blas_dotu[dtype: DType](
d_out: UnsafePointer[Scalar[dtype], MutAnyOrigin],
ctx: DeviceContext
) raises:

blas_error_if["blas_dotu", "n < 0"](n < 0)
blas_error_if["blas_dotu", "incx == 0"](incx == 0)
blas_error_if["blas_dotu", "incy == 0"](incy == 0)

comptime kernel = dotu_device[TBsize, dtype]
ctx.enqueue_function[kernel, kernel](
n, d_x, incx,
Expand Down
5 changes: 5 additions & 0 deletions src/level1/iamax_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ fn blas_iamax[dtype: DType](
d_res: UnsafePointer[Scalar[DType.int64], MutAnyOrigin],
ctx: DeviceContext
) raises:

blas_error_if["blas_iamax", "n < 0"](n<=0)
blas_error_if["blas_iamax", "incx <= 0"](incx <= 0)


comptime kernel = iamax_device[TBsize, dtype]
ctx.enqueue_function[kernel, kernel](
n, d_v, incx,
Expand Down
3 changes: 3 additions & 0 deletions src/level1/nrm2_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ fn blas_nrm2[dtype: DType](
d_out: UnsafePointer[Scalar[dtype], MutAnyOrigin],
ctx: DeviceContext
) raises:
blas_error_if["blas_nrm2", "n < 0"](n < 0)
blas_error_if["blas_nrm2", "incx <= 0"](incx <= 0)

comptime kernel = nrm2_device[TBsize, dtype]
ctx.enqueue_function[kernel, kernel](
n, d_x, incx, d_out,
Expand Down
12 changes: 10 additions & 2 deletions src/level1/rot_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ fn rot_device[
c: Scalar[dtype],
s: Scalar[dtype]
):
if (n < 1):
return


var global_tid = block_idx.x * block_dim.x + thread_idx.x
var n_threads = grid_dim.x * block_dim.x
Expand All @@ -43,6 +42,15 @@ fn blas_rot[dtype: DType](
s: Scalar[dtype],
ctx: DeviceContext
) raises:
blas_error_if["blas_rot", "n < 0"](n < 0)
blas_error_if["blas_rot", "incx == 0"](incx == 0)
blas_error_if["blas_rot", "incy == 0"](incy == 0)


# quick return
if(n == 0 or (c == 1 and s == 0)) :
return

comptime kernel = rot_device[dtype]
ctx.enqueue_function[kernel, kernel](
n,
Expand Down
8 changes: 6 additions & 2 deletions src/level1/rotm_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ fn rotm_device[
param: UnsafePointer[Scalar[dtype], MutAnyOrigin]
):
var flag = param[0]
if (n < 1):
return

var idx = block_idx.x * block_dim.x + thread_idx.x
var n_threads = grid_dim.x * block_dim.x
Expand Down Expand Up @@ -63,6 +61,12 @@ fn blas_rotm[dtype: DType](
d_param: UnsafePointer[Scalar[dtype], MutAnyOrigin],
ctx: DeviceContext
) raises:
blas_error_if["blas_rotm", "n < 0"](n < 0)
blas_error_if["blas_rotm", "incx == 0"](incx == 0)
blas_error_if["blas_rotm", "incy == 0"](incy == 0)

if(n == 0 ):
return
comptime kernel = rotm_device[dtype]
ctx.enqueue_function[kernel, kernel](
n,
Expand Down
11 changes: 5 additions & 6 deletions src/level1/scal_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ fn scal_device[dtype: DType](
x: UnsafePointer[Scalar[dtype], MutAnyOrigin],
incx: Int,
):
if (n <= 0):
return
if (a == 0):
return
if (incx == 0):
return

var global_i = global_idx.x
var n_threads = Int(grid_dim.x * block_dim.x)
Expand All @@ -32,6 +26,11 @@ fn blas_scal[dtype: DType] (
incx: Int,
ctx: DeviceContext
) raises:

blas_error_if["blas_scal", "n < 0"](n < 0)
blas_error_if["blas_scal", "incx <= 0"](incx <= 0)


comptime kernel = scal_device[dtype]
ctx.enqueue_function[kernel, kernel](
n, a, d_x, incx,
Expand Down
9 changes: 5 additions & 4 deletions src/level1/swap_device.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ fn swap_device[dtype: DType](
y: UnsafePointer[Scalar[dtype], MutAnyOrigin],
incy: Int
):
if (n <= 0):
return
if (incx == 0 or incy == 0):
return


var global_i = global_idx.x
var n_threads = Int(grid_dim.x * block_dim.x)
Expand All @@ -34,6 +31,10 @@ fn blas_swap[dtype: DType](
incy: Int,
ctx: DeviceContext
) raises:
blas_error_if["blas_swap", "n < 0"](n < 0)
blas_error_if["blas_swap", "incx == 0"](incx == 0)
blas_error_if["blas_swap", "incy == 0"](incy == 0)

comptime kernel = swap_device[dtype]
ctx.enqueue_function[kernel, kernel](
n,
Expand Down
8 changes: 8 additions & 0 deletions src/util.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

fn blas_error_if[caller: String, cond_str: String](cond: Bool) raises:
"""
Function raises an error describing the bad paramters passed to caller.
"""
if(cond) :
raise Error("Error: {} in {}".format(cond_str, caller))

Loading