-
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.
More docs and add
Charms.Intrinsic
(#36)
- Loading branch information
1 parent
798c233
commit b50f197
Showing
14 changed files
with
168 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ locals_without_parens = [ | |
op: 1, | ||
value: 1, | ||
call: 1, | ||
const: 1 | ||
const: 1, | ||
defintrinsic: 1 | ||
] | ||
|
||
[ | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
defmodule AddTwoIntVec do | ||
@moduledoc false | ||
use Charms | ||
alias Charms.{SIMD, Term, Pointer} | ||
|
||
|
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
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
defmodule Charms.Env do | ||
use Beaver | ||
@moduledoc """ | ||
Intrinsic module for BEAM environment's type. | ||
""" | ||
use Charms.Intrinsic | ||
|
||
@impl true | ||
def handle_intrinsic(:t, [], opts) do | ||
Beaver.ENIF.Type.env(opts) | ||
end | ||
|
||
defintrinsic [:t] | ||
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,55 @@ | ||
defmodule Charms.Intrinsic do | ||
@moduledoc """ | ||
Behaviour to define intrinsic functions. | ||
""" | ||
alias Beaver | ||
@type opt :: {:ctx, MLIR.Context.t()} | {:block, MLIR.Block.t()} | ||
@type opts :: [opt | {atom(), term()}] | ||
@type ir_return :: MLIR.Value.t() | MLIR.Operation.t() | ||
@type intrinsic_return :: ir_return() | (any() -> ir_return()) | ||
@doc """ | ||
Callback to implement an intrinsic. | ||
Having different return types, there are two kinds of intrinsic functions: | ||
- Regular: returns a MLIR value or operation. | ||
- Higher-order: returns a function that returns a MLIR value or operation. | ||
## More on higher-order intrinsic | ||
Higher-order intrinsic function can be variadic, which means it a list will be passed as arguments. | ||
""" | ||
@callback handle_intrinsic(atom(), [term()], opts()) :: intrinsic_return() | ||
Module.register_attribute(__MODULE__, :defintrinsic, accumulate: true) | ||
|
||
@doc false | ||
def collect_intrinsics(nil) do | ||
raise ArgumentError, "no intrinsic functions defined" | ||
end | ||
|
||
def collect_intrinsics(attr_list) when length(attr_list) > 0 do | ||
attr_list |> Enum.reverse() |> List.flatten() |> Enum.uniq() | ||
end | ||
|
||
defmacro __using__(_) do | ||
quote do | ||
@behaviour Charms.Intrinsic | ||
use Beaver | ||
@before_compile Charms.Intrinsic | ||
import Charms.Intrinsic, only: :macros | ||
end | ||
end | ||
|
||
defmacro defintrinsic(intrinsic_list) do | ||
quote do | ||
@defintrinsic unquote(intrinsic_list) | ||
end | ||
end | ||
|
||
defmacro __before_compile__(_env) do | ||
quote do | ||
@defintrinsic_list @defintrinsic |> Charms.Intrinsic.collect_intrinsics() | ||
def __intrinsics__() do | ||
@defintrinsic_list | ||
end | ||
end | ||
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
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
defmodule Charms.Term do | ||
use Beaver | ||
@moduledoc """ | ||
Intrinsic module for SIMD type. | ||
""" | ||
use Charms.Intrinsic | ||
|
||
@impl true | ||
def handle_intrinsic(:t, [], opts) do | ||
Beaver.ENIF.Type.term(opts) | ||
end | ||
|
||
defintrinsic [:t] | ||
end |
Oops, something went wrong.