forked from nod-ai/SHARK-ModelDev
-
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.
[tk] Implement basic vector and scalar code generation (nod-ai#220)
* Python value/type propagation * Loads/stores between KernelBuffer and vectors * Extended Python integer types * Python scalar operations
- Loading branch information
1 parent
fac744b
commit 0c658bd
Showing
13 changed files
with
610 additions
and
79 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,53 @@ | ||
from typing import Optional, Type, TypeVar | ||
|
||
import threading | ||
|
||
_tls = threading.local() | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def push(context_type: Type[T], instance: T) -> T: | ||
"""Pushes an instance onto a thread-local context stack. | ||
The context type must define an attribute __tk_context_idname__ which is | ||
a valid/unique identifier. | ||
""" | ||
assert isinstance(instance, context_type) | ||
key = context_type.__tk_context_idname__ | ||
try: | ||
stack: list = getattr(_tls, key) | ||
except AttributeError: | ||
stack = [] | ||
setattr(_tls, key, stack) | ||
stack.append(instance) | ||
return instance | ||
|
||
|
||
def pop(context_type: Type[T], expected: Optional[T] = None): | ||
"""Pops the current context off of the stack. | ||
Raises IndexError if no current. | ||
""" | ||
stack: list = getattr(_tls, context_type.__tk_context_idname__) | ||
instance = stack.pop() | ||
assert ( | ||
expected is None or expected is instance | ||
), f"mismatched context push/pop for {context_type}" | ||
|
||
|
||
def current(context_type: Type[T]) -> T: | ||
"""Returns the current context from the stack. | ||
Raises IndexError on failure. | ||
""" | ||
try: | ||
stack: list = getattr(_tls, context_type.__tk_context_idname__) | ||
except AttributeError: | ||
raise IndexError(f"No current context for {context_type}") | ||
try: | ||
instance = stack[-1] | ||
except IndexError: | ||
raise IndexError(f"No current context for {context_type}") | ||
assert isinstance(instance, context_type) | ||
return instance |
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,17 +1,30 @@ | ||
from iree.compiler.ir import ( | ||
AffineConstantExpr, | ||
AffineExpr, | ||
AffineMap, | ||
AffineMapAttr, | ||
Attribute, | ||
Context, | ||
DenseElementsAttr, | ||
F32Type, | ||
FloatAttr, | ||
FunctionType, | ||
IndexType, | ||
InsertionPoint, | ||
IntegerAttr, | ||
IntegerType, | ||
Location, | ||
Operation, | ||
MemRefType, | ||
ShapedType, | ||
Type as IrType, | ||
Value, | ||
VectorType, | ||
) | ||
|
||
from iree.compiler.dialects import ( | ||
arith as arith_d, | ||
builtin as builtin_d, | ||
func as func_d, | ||
vector as vector_d, | ||
) |
Oops, something went wrong.