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
1a7fb9f9
Commit
1a7fb9f9
authored
Oct 18, 2016
by
tqchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix c api
parent
35277c2f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
28 deletions
+47
-28
include/tvm/base.h
+3
-3
include/tvm/expr_node.h
+1
-0
python/tvm/cpp/_ctypes/_api.py
+21
-21
python/tvm/cpp/function.py
+17
-0
src/c_api/c_api_function.cc
+3
-2
tests/python/test_cpp.py
+2
-2
No files found.
include/tvm/base.h
View file @
1a7fb9f9
...
...
@@ -24,9 +24,9 @@ class BinaryOp;
/*! \brief list of all supported data types */
enum
DataType
{
kUnknown
,
kInt32
,
kFloat32
kUnknown
=
0
,
kInt32
=
1
,
kFloat32
=
2
};
/*!
...
...
include/tvm/expr_node.h
View file @
1a7fb9f9
...
...
@@ -27,6 +27,7 @@ class VarNode : public ExprNode {
}
void
VisitAttrs
(
AttrVisitor
*
visitor
)
override
{
visitor
->
Visit
(
"name"
,
&
name
);
visitor
->
Visit
(
"dtype"
,
&
dtype_
);
}
};
...
...
python/tvm/cpp/_ctypes/_api.py
View file @
1a7fb9f9
...
...
@@ -25,7 +25,26 @@ kDouble = 2
kStr
=
3
kNodeHandle
=
4
RET_SWITCH
=
None
def
_type_key
(
handle
):
ret_val
=
ArgVariant
()
ret_typeid
=
ctypes
.
c_int
()
check_call
(
_LIB
.
TVMNodeGetAttr
(
handle
,
c_str
(
"type_key"
),
ctypes
.
byref
(
ret_val
),
ctypes
.
byref
(
ret_typeid
)))
return
py_str
(
ret_val
.
v_str
)
NODE_TYPE
=
{
}
RET_SWITCH
=
{
kNull
:
lambda
x
:
None
,
kLong
:
lambda
x
:
x
.
v_long
,
kDouble
:
lambda
x
:
x
.
v_double
,
kStr
:
lambda
x
:
py_str
(
x
.
v_str
),
kNodeHandle
:
lambda
x
:
NODE_TYPE
.
get
(
_type_key
(
x
),
NodeBase
)(
x
.
v_handle
)
}
class
NodeBase
(
object
):
"""Symbol is symbolic graph."""
...
...
@@ -50,27 +69,8 @@ class NodeBase(object):
check_call
(
_LIB
.
TVMNodeGetAttr
(
self
.
handle
,
c_str
(
name
),
ctypes
.
byref
(
ret_val
),
ctypes
.
byref
(
ret_typeid
)))
ret
=
RET_SWITCH
[
ret_typeid
.
value
](
ret_val
)
def
_type_key
(
handle
):
ret_val
=
ArgVariant
()
ret_typeid
=
ctypes
.
c_int
()
check_call
(
_LIB
.
TVMNodeGetAttr
(
handle
,
c_str
(
"type_key"
),
ctypes
.
byref
(
ret_val
),
ctypes
.
byref
(
ret_typeid
)))
return
py_str
(
ret_val
.
v_str
)
NODE_TYPE
=
{
}
return
RET_SWITCH
[
ret_typeid
.
value
](
ret_val
)
RET_SWITCH
=
{
kNull
:
lambda
x
:
None
,
kLong
:
lambda
x
:
x
.
v_long
.
value
,
kDouble
:
lambda
x
:
x
.
v_double
.
value
,
kStr
:
lambda
x
:
py_str
(
x
.
v_str
),
kNodeHandle
:
lambda
x
:
NODE_TYPE
.
get
(
_type_key
(
x
),
NodeBase
)(
x
.
v_handle
)
}
def
_push_arg
(
arg
):
a
=
ArgVariant
()
...
...
python/tvm/cpp/function.py
View file @
1a7fb9f9
from
._ctypes._api
import
_init_function_module
import
_function_internal
int32
=
1
float32
=
2
def
Var
(
name
=
"tindex"
,
dtype
=
int32
):
"""Create a new variable with specified name and dtype
Parameters
----------
name : str
The name
dtype : int
The data type
"""
return
_function_internal
.
_Var
(
name
,
dtype
)
_init_function_module
(
"tvm.cpp"
)
src/c_api/c_api_function.cc
View file @
1a7fb9f9
...
...
@@ -16,9 +16,10 @@ namespace tvm {
using
ArgStack
=
const
std
::
vector
<
APIVariantValue
>
;
using
RetValue
=
APIVariantValue
;
TVM_REGISTER_API
(
Var
)
TVM_REGISTER_API
(
_
Var
)
.
set_body
([](
const
ArgStack
&
args
,
RetValue
*
ret
)
{
*
ret
=
Var
(
args
.
at
(
0
),
static_cast
<
DataType
>
(
static_cast
<
int
>
(
args
.
at
(
1
))));
*
ret
=
Var
(
args
.
at
(
0
),
static_cast
<
DataType
>
(
static_cast
<
int
>
(
args
.
at
(
1
))));
})
.
add_argument
(
"name"
,
"str"
,
"name of the var"
)
.
add_argument
(
"dtype"
,
"int"
,
"data type of var"
);
...
...
tests/python/test_cpp.py
View file @
1a7fb9f9
from
tvm
import
cpp
as
tvm
def
test_basic
():
a
=
tvm
.
Var
(
'a'
,
0
)
b
=
tvm
.
Var
(
'b'
,
0
)
a
=
tvm
.
Var
(
'a'
)
b
=
tvm
.
Var
(
'b'
)
z
=
tvm
.
max
(
a
,
b
)
assert
tvm
.
format_str
(
z
)
==
'max(
%
s,
%
s)'
%
(
a
.
name
,
b
.
name
)
...
...
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