Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
bda95817
Commit
bda95817
authored
Oct 13, 2016
by
tqchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checkin tensor
parent
fc4ba796
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
3 deletions
+49
-3
python/tvm/__init__.py
+1
-0
python/tvm/expr.py
+2
-2
python/tvm/expr_util.py
+3
-0
python/tvm/tensor.py
+33
-0
tests/python/test_basic.py
+0
-1
tests/python/test_tensor.py
+10
-0
No files found.
python/tvm/__init__.py
View file @
bda95817
...
...
@@ -4,3 +4,4 @@ from __future__ import absolute_import as _abs
from
.op
import
*
from
.expr
import
Var
,
const
from
.expr_util
import
*
from
.tensor
import
Tensor
python/tvm/expr.py
View file @
bda95817
...
...
@@ -79,7 +79,7 @@ class Var(Expr):
optional name to the var.
"""
def
__init__
(
self
,
name
=
None
):
if
name
is
None
:
name
=
'i'
if
name
is
None
:
name
=
'i
ndex
'
self
.
name
=
_name
.
NameManager
.
current
.
get
(
name
)
...
...
@@ -100,7 +100,7 @@ class BinaryOpExpr(Expr):
def
children
(
self
):
return
(
self
.
lhs
,
self
.
rhs
)
class
UnaryOpExpr
(
Expr
):
"""Unary operator expression."""
def
__init__
(
self
,
op
,
src
):
...
...
python/tvm/expr_util.py
View file @
bda95817
...
...
@@ -2,6 +2,7 @@
from
__future__
import
absolute_import
as
_abs
from
.
import
expr
as
_expr
from
.
import
op
as
_op
from
.
import
tensor
as
_tensor
def
expr_with_new_children
(
e
,
children
):
"""Returns same expr as e but with new children
...
...
@@ -75,6 +76,8 @@ def format_str(expr):
return
str
(
e
.
value
)
elif
isinstance
(
e
,
_expr
.
Var
):
return
e
.
name
elif
isinstance
(
e
,
_tensor
.
TensorReadExpr
):
return
"
%
s(
%
s)"
%
(
e
.
tensor
.
name
,
','
.
join
(
result_children
))
else
:
raise
TypeError
(
"Do not know how to handle type "
+
str
(
type
(
e
)))
return
transform
(
expr
,
make_str
)
...
...
python/tvm/tensor.py
0 → 100644
View file @
bda95817
from
__future__
import
absolute_import
as
_abs
from
.
import
expr
as
_expr
class
TensorReadExpr
(
_expr
.
Expr
):
def
__init__
(
self
,
tensor
,
indices
):
self
.
tensor
=
tensor
self
.
indices
=
indices
def
children
(
self
):
return
self
.
indices
class
Tensor
(
object
):
def
__init__
(
self
,
ndim
,
fcompute
=
None
,
name
=
None
):
self
.
ndim
=
ndim
if
fcompute
:
arg_names
=
fcompute
.
func_code
.
co_varnames
assert
(
len
(
arg_names
)
==
ndim
)
self
.
dim_index
=
[
_expr
.
Var
(
n
)
for
n
in
arg_names
]
self
.
expr
=
fcompute
(
*
self
.
dim_index
)
else
:
self
.
expr
=
None
self
.
dim_index
=
None
shape_name
=
'_shape'
if
name
:
shape_name
=
name
+
shape_name
self
.
shape
=
tuple
(
_expr
.
Var
(
"
%
s_
%
d_"
%
(
shape_name
,
i
))
for
i
in
range
(
ndim
))
self
.
name
=
name
if
name
else
"TensorObj"
def
__call__
(
self
,
*
indices
):
if
len
(
indices
)
!=
self
.
ndim
:
raise
ValueError
(
"Need to provide
%
d index in tensor slice"
%
self
.
ndim
)
return
TensorReadExpr
(
self
,
indices
)
tests/python/test_basic.py
View file @
bda95817
import
tvm
from
tvm
import
expr
def
test_bind
():
x
=
tvm
.
Var
(
'x'
)
...
...
tests/python/test_tensor.py
0 → 100644
View file @
bda95817
import
tvm
def
test_tensor
():
A
=
tvm
.
Tensor
(
2
,
name
=
'A'
)
B
=
tvm
.
Tensor
(
2
,
name
=
'B'
)
T
=
tvm
.
Tensor
(
3
,
lambda
i
,
j
,
k
:
A
(
i
,
k
)
*
B
(
j
,
k
))
print
(
tvm
.
format_str
(
T
.
expr
))
if
__name__
==
"__main__"
:
test_tensor
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment