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
10 changes: 5 additions & 5 deletions recipes/mojmelo/recipe.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
context:
version: "0.0.8"
version: "0.0.9"

package:
name: "mojmelo"
version: ${{ version }}

source:
- git: https://github.com/yetalit/mojmelo.git
rev: 04f2b8b4c2a8e495b8e05ad7d7554e1b644df66d
rev: dd4c87ee4d28d242ce57006182b248c6f95ad37a

build:
number: 0
Expand All @@ -16,9 +16,9 @@ build:
- mojo package pixi/mojmelo -o ${{ PREFIX }}/lib/mojo/mojmelo.mojopkg
requirements:
host:
- max =25.5
- mojo-compiler =0.25.6
run:
- ${{ pin_compatible('max') }}
- ${{ pin_compatible('mojo-compiler') }}

tests:
- script:
Expand All @@ -27,7 +27,7 @@ tests:
- mojo tests/setup.mojo
requirements:
run:
- max =25.5
- mojo-compiler =0.25.6
files:
recipe:
- tests/setup.mojo
Expand Down
8 changes: 4 additions & 4 deletions recipes/mojmelo/tests/mojmelo/utils/Matrix.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from .mojmelo_matmul import matmul
from memory import memcpy, memset_zero
import random

struct Matrix(Copyable, Movable, Sized):
struct Matrix(Copyable, Movable, ImplicitlyCopyable, Sized):
var height: Int
var width: Int
var size: Int
Expand Down Expand Up @@ -37,7 +37,7 @@ struct Matrix(Copyable, Movable, Sized):
self.order = other.order
memcpy(self.data, other.data, self.size)

fn __moveinit__(out self, var existing: Self):
fn __moveinit__(out self, deinit existing: Self):
self.height = existing.height
self.width = existing.width
self.size = existing.size
Expand All @@ -55,12 +55,12 @@ struct Matrix(Copyable, Movable, Sized):
loc = (row * self.width) + column
else:
loc = (column * self.height) + row
if loc > self.size - 1:
if loc > self.size - 1 or loc < 0:
raise Error("Error: Location is out of range!")
return self.data[loc]

@always_inline
fn __del__(var self):
fn __del__(deinit self):
if self.data:
self.data.free()

Expand Down
34 changes: 17 additions & 17 deletions recipes/mojmelo/tests/mojmelo/utils/mojmelo_matmul/matmul.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from algorithm import vectorize, parallelize
from memory.memory import _malloc, stack_allocation
from sys import CompilationTarget, num_performance_cores, simdwidthof, sizeof
from sys import CompilationTarget, num_performance_cores, simd_width_of, size_of
import benchmark
from testing import assert_equal
from utils import IndexList
Expand Down Expand Up @@ -163,7 +163,7 @@ fn pack_A[
](Ac.stride[0]()),
)

vectorize[pack_col, simdwidthof[Type]()](min(Ac.shape[0]() - i, mr))
vectorize[pack_col, simd_width_of[Type]()](min(Ac.shape[0]() - i, mr))

for l in range(min(Ac.shape[0]() - i, mr), mr):
dst_ptr[l] = Scalar[Type](0)
Expand Down Expand Up @@ -193,15 +193,15 @@ fn pack_B[
@parameter
fn pack_row[width: Int](l: Int):
(dst_ptr + l).store[
alignment = sizeof[Type]() * simdwidthof[Type]()
alignment = size_of[Type]() * simd_width_of[Type]()
](
(src_ptr + l).load[width=width](),
)

vectorize[
pack_row,
simdwidthof[Type](),
unroll_factor = nr // simdwidthof[Type](),
simd_width_of[Type](),
unroll_factor = nr // simd_width_of[Type](),
](min(Bc.shape[1]() - i, nr))

for l in range(min(Bc.shape[1]() - i, nr), nr):
Expand All @@ -223,8 +223,8 @@ fn matmul_impl[
mr: Int,
nr: Int,
](mc: Int, nc: Int, mut C: Matrix[Type], A: Matrix[Type], B: Matrix[Type]):
var Ac_buffer = _malloc[Scalar[Type], alignment=64](
mc * kc * sizeof[Type]()
var Ac_buffer = _malloc[Scalar[Type]](
mc * kc * size_of[Type](), alignment=64
)

var M = C.shape[0]()
Expand Down Expand Up @@ -268,8 +268,8 @@ fn loop_n[
@parameter
fn parallelize_balanced_part(idx: Int):
var Bc_buffer = UnsafePointer[Scalar[Type]](
_malloc[Scalar[Type], alignment=64](
kc * nc_per_thread * sizeof[Type]()
_malloc[Scalar[Type]](
kc * nc_per_thread * size_of[Type](), alignment=64
)
)

Expand All @@ -291,8 +291,8 @@ fn loop_n[
@parameter
fn parallelize_remainder(idx: Int):
var Bc_buffer = UnsafePointer[Scalar[Type]](
_malloc[Scalar[Type], alignment=64](
kc * remainder_per_thread * sizeof[Type]()
_malloc[Scalar[Type]](
kc * remainder_per_thread * size_of[Type](), alignment=64
)
)
var j = balanced_part + idx * remainder_per_thread
Expand Down Expand Up @@ -348,7 +348,7 @@ fn macro_kernel[
fn micro_kernel[
Type: DType, //, mr: Int, nr: Int, padding: Bool
](mut Cr: Matrix[Type], Ar: Matrix[Type], Br: Matrix[Type]):
alias simd_width = simdwidthof[Type]()
alias simd_width = simd_width_of[Type]()
constrained[nr % simd_width == 0, "nr must be multiple of simd_width"]()

var Ar_ptr = Ar.data
Expand Down Expand Up @@ -391,7 +391,7 @@ fn micro_kernel[
@parameter
for j in range(0, nr, simd_width):
br[j // simd_width] = (Br_ptr + j).load[
width=simd_width, alignment = sizeof[Type]() * simdwidthof[Type]()
width=simd_width, alignment = size_of[Type]() * simd_width_of[Type]()
]()

@parameter
Expand Down Expand Up @@ -440,15 +440,15 @@ fn micro_kernel[

@always_inline
fn matmul_params[Type: DType]() -> IndexList[5]:
alias mc = 8192 // sizeof[Type]() # fix this for simplicity
alias N = simdwidthof[Type]()
alias mc = 8192 // size_of[Type]() # fix this for simplicity
alias N = simd_width_of[Type]()

alias Vectors = 32 if CompilationTarget.has_avx512f() else 16

@parameter
fn compute_kc[mr: Int, nr: Int]() -> Int:
alias CBr = Int((L1_ASSOCIATIVITY - 1) / (1 + mr / nr))
return (CBr * L1_CACHE_SIZE) // (nr * sizeof[Type]() * L1_ASSOCIATIVITY)
return (CBr * L1_CACHE_SIZE) // (nr * size_of[Type]() * L1_ASSOCIATIVITY)

@parameter
fn compute_params[C: Int]() -> IndexList[5]:
Expand All @@ -458,7 +458,7 @@ fn matmul_params[Type: DType]() -> IndexList[5]:
alias CBr = Int((L1_ASSOCIATIVITY - 1) / (1 + mr / nr))
alias kc = compute_kc[mr, nr]()
alias nc = (L2_ASSOCIATIVITY - 1) * L2_CACHE_SIZE // (
kc * sizeof[Type]() * L2_ASSOCIATIVITY
kc * size_of[Type]() * L2_ASSOCIATIVITY
) - mr
return IndexList[5](mc, nc, kc, mr, nr)

Expand Down