-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21476ed
commit c04abfd
Showing
12 changed files
with
313 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
mod = AddTwoIntVec | ||
Charms.JIT.init(mod) | ||
|
||
Benchee.run( | ||
%{ | ||
"Enum.zip_reduce" => fn {a, b} -> | ||
Enum.zip_reduce(a, b, [], fn x, y, acc -> [x + y | acc] end) |> Enum.reverse() | ||
end, | ||
"AddTwoIntVec.add" => fn {a, b} -> AddTwoIntVec.add(a, b, :err_msg) end, | ||
"AddTwoIntVec.dummy_load_no_make" => fn {a, b} -> | ||
AddTwoIntVec.dummy_load_no_make(a, b, :err_msg) | ||
end, | ||
"AddTwoIntVec.dummy_return" => fn {a, b} -> AddTwoIntVec.dummy_return(a, b, :err_msg) end | ||
}, | ||
inputs: %{ | ||
"array size 8" => 8 | ||
}, | ||
before_scenario: fn i -> | ||
a = Enum.to_list(1..i) |> Enum.shuffle() | ||
b = Enum.to_list(1..i) |> Enum.shuffle() | ||
{a, b} | ||
end | ||
) | ||
|
||
Charms.JIT.destroy(mod) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
defmodule AddTwoIntVec do | ||
use Charms | ||
alias Charms.{SIMD, Term, Pointer} | ||
|
||
defm load_list(env, l :: Term.t()) :: SIMD.t(i32(), 8) do | ||
i_ptr = Pointer.allocate(i32()) | ||
Pointer.store(arith.constant(value: Attribute.integer(i32(), 0)), i_ptr) | ||
init = SIMD.new(i32(), 8).(0, 0, 0, 0, 0, 0, 0, 0) | ||
|
||
Enum.reduce(l, init, fn x, acc -> | ||
v_ptr = Pointer.allocate(i32()) | ||
enif_get_int(env, x, v_ptr) | ||
i = Pointer.load(i32(), i_ptr) | ||
Pointer.store(i + 1, i_ptr) | ||
|
||
Pointer.load(i32(), v_ptr) | ||
|> vector.insertelement(acc, i) | ||
end) | ||
|> func.return() | ||
end | ||
|
||
defm add(env, a, b, error) :: Term.t() do | ||
v1 = call load_list(env, a) :: SIMD.t(i32(), 8) | ||
v2 = call load_list(env, b) :: SIMD.t(i32(), 8) | ||
v = arith.addi(v1, v2) | ||
start = arith.constant(value: Attribute.integer(i32(), 0)) | ||
|
||
ret = | ||
enif_make_list8( | ||
env, | ||
enif_make_int(env, vector.extractelement(v, start)), | ||
enif_make_int(env, vector.extractelement(v, start + 1)), | ||
enif_make_int(env, vector.extractelement(v, start + 2)), | ||
enif_make_int(env, vector.extractelement(v, start + 3)), | ||
enif_make_int(env, vector.extractelement(v, start + 4)), | ||
enif_make_int(env, vector.extractelement(v, start + 5)), | ||
enif_make_int(env, vector.extractelement(v, start + 6)), | ||
enif_make_int(env, vector.extractelement(v, start + 7)) | ||
) | ||
|
||
func.return(ret) | ||
end | ||
|
||
defm dummy_load_no_make(env, a, b, error) :: Term.t() do | ||
v1 = call load_list(env, a) :: SIMD.t(i32(), 8) | ||
v2 = call load_list(env, b) :: SIMD.t(i32(), 8) | ||
func.return(a) | ||
end | ||
|
||
defm dummy_return(env, a, b, error) :: Term.t() do | ||
func.return(a) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Charms.Debug do | ||
@moduledoc false | ||
alias Beaver.MLIR | ||
|
||
def print_ir_pass(op) do | ||
if System.get_env("DEFM_PRINT_IR") == "1" do | ||
MLIR.Transforms.print_ir(op) | ||
else | ||
op | ||
end | ||
end | ||
|
||
def step_print?() do | ||
System.get_env("DEFM_PRINT_IR") == "step" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.