forked from apache/tvm
-
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.
- Loading branch information
Showing
30 changed files
with
1,351 additions
and
387 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
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,3 +1,13 @@ | ||
from typing import Callable, Any, Union | ||
|
||
backend: Union[str, Callable[..., Any]] = "inductor" | ||
CONFIG = { | ||
"backend": "inductor", # Union[str, Callable[..., Any]] | ||
} | ||
|
||
|
||
def set_config(key: str, value: Any) -> None: | ||
CONFIG[key] = value | ||
|
||
|
||
def get_config(key: str) -> Any: | ||
return CONFIG[key] |
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,60 @@ | ||
import dataclasses | ||
from typing import Any, Optional | ||
import torch | ||
from .store_pos import StorePos | ||
|
||
|
||
@dataclasses.dataclass | ||
class LoopPosMap: | ||
input_only_pos: list[tuple[str, StorePos]] | ||
joint_pos: list[tuple[str, StorePos]] | ||
output_only_pos: list[tuple[str, StorePos]] | ||
|
||
|
||
class LoopModule(torch.nn.Module): #type: ignore | ||
body: torch.fx.GraphModule | ||
num_read_only_param: int | ||
num_iter: int | ||
|
||
def __init__(self, body: torch.fx.GraphModule, num_read_only_param: int, | ||
num_iter: int): | ||
super(LoopModule, self).__init__() | ||
self.body = body | ||
self.num_read_only_param = num_read_only_param | ||
self.num_iter = num_iter | ||
|
||
# def forward(self, num_iter: Optional[int], cond: torch.Tensor, *values: | ||
# Any) -> Any: | ||
def forward(self, *values: Any) -> Any: | ||
iter_num = 0 | ||
# assert cond.dtype == torch.bool | ||
read_only = values[:self.num_read_only_param] | ||
loop_carry = values[self.num_read_only_param:] | ||
while iter_num < self.num_iter: | ||
# and cond.item(): | ||
loop_carry = self.body(iter_num, *read_only, *loop_carry) | ||
# cond, *loop_carry = self.body(iter_num, cond, *read_only, | ||
# *loop_carry) | ||
iter_num += 1 | ||
return loop_carry | ||
|
||
|
||
class ControlFlowInfo: | ||
start_pc: int | ||
end_pc: int | ||
|
||
def __init__(self, start_pc: int, end_pc: int) -> None: | ||
self.start_pc = start_pc | ||
self.end_pc = end_pc | ||
|
||
|
||
class ForLoopInfo(ControlFlowInfo): | ||
num_iter: int | ||
cur_iter: int | ||
pos_map: Optional[LoopPosMap] | ||
inner_graph: Optional[torch.fx.Graph] | ||
|
||
def __init__(self, start_pc: int, end_pc: int, num_iter: int) -> None: | ||
super().__init__(start_pc, end_pc) | ||
self.num_iter = num_iter | ||
self.cur_iter = 0 |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <Python.h> | ||
#include <object.h> | ||
|
||
namespace frontend_csrc { | ||
|
||
typedef struct { | ||
PyObject_HEAD long index; | ||
long start; | ||
long step; | ||
long len; | ||
} rangeiterobject; | ||
|
||
PyObject *parse_rangeiterobject(PyObject *self, PyObject *args) { | ||
PyObject *obj; | ||
if (!PyArg_ParseTuple(args, "O", &obj)) { | ||
return NULL; | ||
} | ||
if (Py_TYPE(obj) != &PyRangeIter_Type) { | ||
PyErr_SetString(PyExc_TypeError, "Expected rangeiterobject"); | ||
return NULL; | ||
} | ||
rangeiterobject *robj = (rangeiterobject *)obj; | ||
return PyTuple_Pack( | ||
4, PyLong_FromLong(robj->index), PyLong_FromLong(robj->start), | ||
PyLong_FromLong(robj->step), PyLong_FromLong(robj->len)); | ||
} | ||
|
||
PyObject *make_rangeiterobject(PyObject *self, PyObject *args) { | ||
long index, start, step, len; | ||
if (!PyArg_ParseTuple(args, "llll", &index, &start, &step, &len)) { | ||
return NULL; | ||
} | ||
rangeiterobject *robj = PyObject_New(rangeiterobject, &PyRangeIter_Type); | ||
robj->index = index; | ||
robj->start = start; | ||
robj->step = step; | ||
robj->len = len; | ||
return (PyObject *)robj; | ||
} | ||
|
||
} // namespace frontend_csrc |
Oops, something went wrong.