-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch exposes data types to users. Currently, creation of constant vectors for expoxed types is supported and arithmetic on them. What is not supported yet: 1. Scalar conversion 2. Vector conversion 3. KernelBuffer element type 4. Promotion/Truncation Test output: https://gist.github.com/Groverkss/30d5aaad0ea2b44960ba88b5340463ad
- Loading branch information
Showing
10 changed files
with
257 additions
and
120 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
__all__ = [ | ||
"DataType", | ||
"bool", | ||
"i4", | ||
"i8", | ||
"i16", | ||
"i32", | ||
"i64", | ||
"f16", | ||
"f32", | ||
"f64", | ||
"index", | ||
] | ||
|
||
_INT_TYPES = ["i1", "i4", "i8", "i16", "i32", "i64"] | ||
_FLOAT_TYPES = ["f16", "f32", "f64"] | ||
_INDEX_TYPES = ["index"] | ||
|
||
|
||
class DataType: | ||
_name: str | ||
_ir_type_asm: str | ||
|
||
def __init__(self, name, ir_type_asm=None): | ||
self._name = name | ||
self._ir_type_asm = ir_type_asm if ir_type_asm else name | ||
|
||
def ir_type_asm(self): | ||
return self._ir_type_asm | ||
|
||
def __str__(self): | ||
return self._name | ||
|
||
def __repr__(self): | ||
return f"DataType({self._ir_type_asm})" | ||
|
||
def is_int_asm(self): | ||
return self._name in _INT_TYPES | ||
|
||
def is_float_asm(self): | ||
return self._name in _FLOAT_TYPES | ||
|
||
def is_index_asm(self): | ||
return self._name in _INDEX_TYPES | ||
|
||
|
||
bool = DataType("bool", "i1") | ||
i4 = DataType("i4") | ||
i8 = DataType("i8") | ||
i16 = DataType("i16") | ||
i32 = DataType("i32") | ||
i64 = DataType("i64") | ||
f32 = DataType("f32") | ||
f64 = DataType("f64") | ||
f16 = DataType("f16") | ||
f32 = DataType("f32") | ||
f64 = DataType("f64") | ||
index = DataType("index") |
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.