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
5a7a056c
Commit
5a7a056c
authored
Jun 30, 2017
by
Tianqi Chen
Committed by
GitHub
Jun 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[LANG/BUFFER] Change buffer arguments to match DLPack order, add scope (#203)
parent
7b821851
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
37 deletions
+58
-37
HalideIR
+1
-1
include/tvm/buffer.h
+26
-15
python/tvm/api.py
+8
-2
src/api/api_lang.cc
+2
-1
src/lang/buffer.cc
+20
-17
src/pass/storage_flatten.cc
+1
-1
No files found.
HalideIR
@
e42653d7
Subproject commit
41fe60a76fe6e5669540acf1ef3595bc38025157
Subproject commit
e42653d7c3a604eb9f6ee1b5f989ddadd1cea69c
include/tvm/buffer.h
View file @
5a7a056c
...
...
@@ -26,12 +26,6 @@ class Buffer : public NodeRef {
Buffer
()
{}
explicit
Buffer
(
std
::
shared_ptr
<
Node
>
n
)
:
NodeRef
(
n
)
{}
/*!
* \brief construct a new buffer based on shape and strides.
*/
explicit
Buffer
(
Array
<
Expr
>
shape
,
Type
dtype
=
Float
(
32
),
std
::
string
name
=
"buffer"
);
/*!
* \brief Generate a load expression loading the index location of buffer.
* \param index The index to the buffer.
* \return The load expression.
...
...
@@ -57,10 +51,11 @@ class Buffer : public NodeRef {
/*! \brief Node to represent a buffer */
class
BufferNode
:
public
Node
{
public
:
/*! \brief optional name of the buffer */
std
::
string
name
;
// Data fields.
/*! \brief The pointer to the head of the data */
Var
data
;
/*! \brief data type in the content of the tensor */
Type
dtype
;
/*! \brief The shape of the buffer */
Array
<
Expr
>
shape
;
/*!
...
...
@@ -68,34 +63,39 @@ class BufferNode : public Node {
* This can be an empty array, indicating array is contiguous
*/
Array
<
Expr
>
strides
;
/*! \brief data type in the content of the tensor */
Type
dtype
;
/*!
* \brief The offset in bytes to the beginning pointer to data
* Can be undefined, indicating this must be zero.
*/
Expr
byte_offset
;
// Meta data
/*! \brief optional name of the buffer */
std
::
string
name
;
/*! \brief storage scope of the buffer, if other than global */
std
::
string
scope
;
/*! \brief Alignment bytes size of byte_offset */
int
offset_alignment
;
/*! \brief constructor */
BufferNode
()
{}
void
VisitAttrs
(
AttrVisitor
*
v
)
final
{
v
->
Visit
(
"name"
,
&
name
);
v
->
Visit
(
"data"
,
&
data
);
v
->
Visit
(
"dtype"
,
&
dtype
);
v
->
Visit
(
"shape"
,
&
shape
);
v
->
Visit
(
"strides"
,
&
strides
);
v
->
Visit
(
"dtype"
,
&
dtype
);
v
->
Visit
(
"byte_offset"
,
&
byte_offset
);
v
->
Visit
(
"name"
,
&
name
);
v
->
Visit
(
"scope"
,
&
scope
);
v
->
Visit
(
"offset_alignment"
,
&
offset_alignment
);
}
static
Buffer
make
(
std
::
string
name
,
Var
ptr
,
static
Buffer
make
(
Var
ptr
,
Type
dtype
,
Array
<
Expr
>
shape
,
Array
<
Expr
>
strides
,
Type
dtype
,
Expr
byte_offset
,
std
::
string
name
,
std
::
string
scope
,
int
offset_alignment
);
static
constexpr
const
char
*
_type_key
=
"Buffer"
;
...
...
@@ -106,5 +106,16 @@ inline const BufferNode* Buffer::operator->() const {
return
static_cast
<
const
BufferNode
*>
(
node_
.
get
());
}
/*!
* \brief Construct a new buffer given shape, and dtype.
* \param shape The shape of the buffer,
* \param dtype The content data type.
* \param name The name of the buffer
* \return The created buffer.
* \sa BufferNode::make for complete constructor.
*/
Buffer
decl_buffer
(
Array
<
Expr
>
shape
,
Type
dtype
=
Float
(
32
),
std
::
string
name
=
"buffer"
);
}
// namespace tvm
#endif // TVM_BUFFER_H_
python/tvm/api.py
View file @
5a7a056c
...
...
@@ -369,11 +369,13 @@ def extern(shape, inputs, fcompute,
return
res
[
0
]
if
len
(
res
)
==
1
else
res
def
decl_buffer
(
shape
,
dtype
=
None
,
def
decl_buffer
(
shape
,
dtype
=
None
,
name
=
"buffer"
,
data
=
None
,
strides
=
None
,
byte_offset
=
None
,
scope
=
""
,
offset_alignment
=
0
):
"""Decleare a new symbolic buffer.
...
...
@@ -402,6 +404,10 @@ def decl_buffer(shape, dtype=None,
byte_offset: Expr, optional
The offset in bytes to data pointer.
scope: str, optional
The storage scope of the buffer, if not global.
If scope equals empty string, it means it is global memory.
offset_alignment: int, optional
The alignment of offset
...
...
@@ -430,7 +436,7 @@ def decl_buffer(shape, dtype=None,
data
=
var
(
name
,
"handle"
)
return
_api_internal
.
_Buffer
(
name
,
data
,
shape
,
strides
,
dtype
,
byte_offset
,
offset_alignment
)
data
,
dtype
,
shape
,
strides
,
byte_offset
,
name
,
scope
,
offset_alignment
)
def
_IterVar
(
dom
,
name
,
iter_type
,
thread_tag
=
''
):
...
...
src/api/api_lang.cc
View file @
5a7a056c
...
...
@@ -151,7 +151,8 @@ TVM_REGISTER_API("_Buffer")
args
[
3
],
args
[
4
],
args
[
5
],
args
[
6
]);
args
[
6
],
args
[
7
]);
});
TVM_REGISTER_API
(
"_Tensor"
)
...
...
src/lang/buffer.cc
View file @
5a7a056c
...
...
@@ -16,14 +16,16 @@ Array<Expr> GetStrides(Array<Expr> shape) {
return
Array
<
Expr
>
(
vec
.
rbegin
(),
vec
.
rend
());
}
Buffer
::
Buffer
(
Array
<
Expr
>
shape
,
Type
dtype
,
std
::
string
name
)
:
Buffer
(
BufferNode
::
make
(
name
,
Var
(
name
,
Type
(
Type
::
Handle
,
0
,
0
)),
shape
,
Array
<
Expr
>
(),
dtype
,
Expr
(),
0
))
{
Buffer
decl_buffer
(
Array
<
Expr
>
shape
,
Type
dtype
,
std
::
string
name
)
{
return
BufferNode
::
make
(
Var
(
name
,
Handle
()),
dtype
,
shape
,
Array
<
Expr
>
(),
Expr
(),
name
,
""
,
0
);
}
inline
Expr
BufferOffset
(
const
BufferNode
*
n
,
Array
<
Expr
>
index
)
{
...
...
@@ -61,22 +63,23 @@ Stmt Buffer::MakeStore(Array<Expr> index, Expr value) const {
const_true
(
n
->
dtype
.
lanes
()));
}
Buffer
BufferNode
::
make
(
std
::
string
name
,
Var
data
,
Buffer
BufferNode
::
make
(
Var
data
,
Type
dtype
,
Array
<
Expr
>
shape
,
Array
<
Expr
>
strides
,
Type
dtype
,
Expr
byte_offset
,
std
::
string
name
,
std
::
string
scope
,
int
offset_alignment
)
{
auto
n
=
std
::
make_shared
<
BufferNode
>
();
n
->
name
=
name
;
n
->
data
=
data
;
n
->
shape
=
shape
;
n
->
strides
=
strides
;
n
->
data
=
std
::
move
(
data
);
n
->
dtype
=
dtype
;
n
->
shape
=
std
::
move
(
shape
);
n
->
strides
=
std
::
move
(
strides
);
n
->
name
=
std
::
move
(
name
);
n
->
scope
=
std
::
move
(
scope
);
if
(
!
byte_offset
.
defined
())
{
byte_offset
=
make_const
(
shape
[
0
].
type
(),
0
);
byte_offset
=
make_const
(
n
->
shape
[
0
].
type
(),
0
);
}
if
(
offset_alignment
!=
0
)
{
CHECK_EQ
(
offset_alignment
%
dtype
.
bytes
(),
0
)
...
...
src/pass/storage_flatten.cc
View file @
5a7a056c
...
...
@@ -83,7 +83,7 @@ class StorageFlattener : public IRMutator {
for
(
auto
r
:
e
.
bounds
)
{
shape
.
push_back
(
r
->
extent
);
}
e
.
buffer
=
B
uffer
(
shape
,
op
->
type
,
key
.
GetName
());
e
.
buffer
=
decl_b
uffer
(
shape
,
op
->
type
,
key
.
GetName
());
buf_map_
[
key
]
=
e
;
Stmt
body
=
this
->
Mutate
(
op
->
body
);
...
...
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