-
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.
feat: add global references and arguments
Add ability to capture global references, including function arguments when parsing kernels. Globals and arguments are directly encoded as KLR terms.
- Loading branch information
Showing
5 changed files
with
206 additions
and
49 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 |
---|---|---|
|
@@ -5,5 +5,6 @@ Authors: Paul Govereau | |
-/ | ||
import NKL.Encode | ||
import NKL.FFI | ||
import NKL.KLR | ||
import NKL.NKI | ||
import NKL.Python |
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,79 @@ | ||
/- | ||
Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Paul Govereau | ||
-/ | ||
|
||
|
||
/-! | ||
# Abstract syntax of Core NKL language | ||
This language is the result of "tracing", and is used as the | ||
portable format, a.k.a. Kernel Language Representation (KLR). | ||
-/ | ||
|
||
namespace NKL.KLR | ||
|
||
inductive Ty where | ||
|
||
inductive Const where | ||
| none | ||
| bool (value : Bool) | ||
| int (value : Int) | ||
| float (value : Float) | ||
| string (value : String) | ||
deriving Repr | ||
|
||
inductive IndexExpr where | ||
| var (name : String) | ||
| int (i : Int) | ||
| neg (expr : IndexExpr) | ||
| add (left right : IndexExpr) | ||
| mul (scalar : Int) (expr : IndexExpr) | ||
| floor (expr : IndexExpr) (scalar : Int) | ||
| ceil (expr : IndexExpr) (scalar : Int) | ||
| mod (expr : IndexExpr) (scalar : Int) | ||
deriving Repr | ||
|
||
inductive Index where | ||
| ellipsis | ||
| coord (e : Option IndexExpr) | ||
| range (l u step : Option IndexExpr) | ||
deriving Repr | ||
|
||
inductive Expr where | ||
| var : String -> Expr | ||
| const : Const -> Expr | ||
| tuple : List Expr -> Expr | ||
| list : List Expr -> Expr | ||
| access : Expr -> List Index -> Expr | ||
| binop (op : String) (left right : Expr) | ||
| unop (op : String) (e : Expr) | ||
| call (f : Expr) (args : List Expr) (keywords : List (String × Expr)) | ||
deriving Repr | ||
|
||
inductive Stmt where | ||
| pass | ||
| expr (v : Expr) | ||
| ret (v : Expr) | ||
| assign (x : String) (e : Expr) | ||
deriving Repr | ||
|
||
|
||
-- Python-like rules for conversion to boolean | ||
def Const.isTrue : Const -> Bool | ||
| .none => false | ||
| .bool b => b | ||
| .int i => i != 0 | ||
| .float f => f != 0.0 | ||
| .string s => s != "" | ||
|
||
-- TODO: Just place-holders for now | ||
def Expr.toAffine : Expr -> Except String IndexExpr | ||
| .var v => return .var v | ||
| .const (.int i) => return .int i | ||
| e => throw s!"toAffine unimp {repr e}" | ||
|
||
def Expr.simplify : Expr -> Expr := | ||
fun x => x | ||
|
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.