Charms (charms v0.1.1)
Documentation for Charms
.
defm
and intrinsic
There are two ways to define a function with defm/2
or implement callbacks of Charms.Intrinsic
behavior. The defm/2
is a macro that generates a function definition in Charm. The intrinsic is a behavior that generates a function definition in MLIR.
The intrinsic is more flexible than defm
because:
- Intrinsic can be variadic and its argument can be anything
- Intrinsic is suitable for the cases where directly writing or generating MLIR is more ideal
- An intrinsic should be responsible for its type check while the Charm’s type system is responsible for function call’s type check
The defm
is more suitable for simple functions because it is designed to be as close to vanilla Elixir as possible. As a rule of thumb, use defm
for simple functions and intrinsic for complex functions or higher-order(generic) function with type as argument.
defm
's differences from Beaver.>>>/2
op expressions
- In
Beaver.>>>/2
, MLIR code are expected to mixed with regular Elixir code. While indefm/2
, there is only Elixir code (a subset of Elixir, to be more precise). - In
defm/2
, the extension of the compiler happens at the function level (define your intrinsics ordefm/2
s), while inBeaver.>>>/2
, the extension happens at the op level (define your op expression). - In
Beaver.>>>/2
the management of MLIR context and other resources are done by the user, while indefm/2
, the management of resources are done by theCharms
compiler. - In
defm/2
, there is expected to be extra verifications built-in to theCharms
compiler (both syntax and types), while inBeaver.>>>/2
, there is none.
Caveats and limitations
- We need a explicit
call
in function call because the::
special form has a parser priority that is too low so acall
macro is introduced to ensure proper scope. - Being variadic, intrinsic must be called with the module name.
import
doesn't work with intrinsic functions whilealias
is supported.
Glossary of modules
Charms
: the top level macrosdefm
anduse Charms
Charms.Defm
: thedefm
DSL syntax and special formsCharms.Defm.Definition
: functions to define and compiledefm
functions to MLIRCharms.Intrinsic
: the behavior used to define and compile intrinsic functions
Summary
Functions
define a function that can be JIT compiled
Functions
define a function that can be JIT compiled