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
6ebbea5d
Commit
6ebbea5d
authored
Sep 14, 2016
by
Tianqi Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[API] Change attr to explicit name set_attr (#46)
parent
d0cc035c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
24 deletions
+24
-24
nnvm/example/src/operator.cc
+18
-18
nnvm/include/nnvm/op.h
+6
-6
No files found.
nnvm/example/src/operator.cc
View file @
6ebbea5d
...
...
@@ -66,7 +66,7 @@ NNVM_REGISTER_OP(reshape)
CHECK
(
is
>>
target
);
attrs
->
parsed
=
std
::
move
(
target
);
})
.
attr
<
FInferShape
>
(
.
set_
attr
<
FInferShape
>
(
"FInferShape"
,
[]
(
const
NodeAttrs
&
attrs
,
std
::
vector
<
TShape
>
*
ishape
,
std
::
vector
<
TShape
>
*
oshape
)
{
...
...
@@ -78,7 +78,7 @@ NNVM_REGISTER_OP(reshape)
<<
"Reshape op: source target shape mismatch"
;
return
true
;
})
.
attr
<
FInplaceOption
>
(
"FInplaceOption"
,
InplaceIn0Out0
);
.
set_
attr
<
FInplaceOption
>
(
"FInplaceOption"
,
InplaceIn0Out0
);
NNVM_REGISTER_OP
(
cast
)
...
...
@@ -92,8 +92,8 @@ NNVM_REGISTER_OP(cast)
CHECK
(
is
>>
dtype
);
attrs
->
parsed
=
std
::
move
(
dtype
);
})
.
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
attr
<
FInferType
>
(
.
set_
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
set_
attr
<
FInferType
>
(
"FInferType"
,
[](
const
NodeAttrs
&
attrs
,
std
::
vector
<
int
>
*
itype
,
std
::
vector
<
int
>
*
otype
)
{
...
...
@@ -104,8 +104,8 @@ NNVM_REGISTER_OP(cast)
NNVM_REGISTER_OP
(
exp
)
.
describe
(
"take exponential"
)
.
set_num_inputs
(
1
)
.
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
attr
<
FGradient
>
(
.
set_
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
set_
attr
<
FGradient
>
(
"FGradient"
,
[](
const
NodePtr
&
n
,
const
std
::
vector
<
NodeEntry
>&
ograds
)
{
return
std
::
vector
<
NodeEntry
>
{
...
...
@@ -117,8 +117,8 @@ NNVM_REGISTER_OP(exp)
NNVM_REGISTER_OP
(
identity
)
.
describe
(
"identity function"
)
.
set_num_inputs
(
1
)
.
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
attr
<
FGradient
>
(
.
set_
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
set_
attr
<
FGradient
>
(
"FGradient"
,
[](
const
NodePtr
&
n
,
const
std
::
vector
<
NodeEntry
>&
ograds
)
{
return
std
::
vector
<
NodeEntry
>
{
ograds
[
0
]};
...
...
@@ -128,9 +128,9 @@ NNVM_REGISTER_OP(add)
.
describe
(
"add two data together"
)
.
set_num_inputs
(
2
)
.
add_alias
(
"__add_symbol__"
)
.
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
attr
<
FInplaceOption
>
(
"FInplaceOption"
,
InplaceIn0Out0
)
.
attr
<
FGradient
>
(
.
set_
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
set_
attr
<
FInplaceOption
>
(
"FInplaceOption"
,
InplaceIn0Out0
)
.
set_
attr
<
FGradient
>
(
"FGradient"
,
[](
const
NodePtr
&
n
,
const
std
::
vector
<
NodeEntry
>&
ograds
){
return
std
::
vector
<
NodeEntry
>
{
ograds
[
0
],
ograds
[
0
]};
...
...
@@ -139,9 +139,9 @@ NNVM_REGISTER_OP(add)
NNVM_REGISTER_OP
(
mul
)
.
describe
(
"multiply two data together"
)
.
set_num_inputs
(
2
)
.
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
attr
<
FInplaceOption
>
(
"FInplaceOption"
,
InplaceIn0Out0
)
.
attr
<
FGradient
>
(
.
set_
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
)
.
set_
attr
<
FInplaceOption
>
(
"FInplaceOption"
,
InplaceIn0Out0
)
.
set_
attr
<
FGradient
>
(
"FGradient"
,
[](
const
NodePtr
&
n
,
const
std
::
vector
<
NodeEntry
>&
ograds
){
return
std
::
vector
<
NodeEntry
>
{
...
...
@@ -167,23 +167,23 @@ NNVM_REGISTER_OP(__one__)
NNVM_REGISTER_OP
(
cross_device_copy
)
.
describe
(
"Copy data across device."
)
.
set_num_inputs
(
1
)
.
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
);
.
set_
attr
<
FInferShape
>
(
"FInferShape"
,
SameShape
);
NNVM_REGISTER_OP
(
conv2d
)
.
describe
(
"take conv of input"
)
.
set_num_inputs
(
2
)
.
attr
<
FListInputNames
>
(
"FListInputNames"
,
[](
const
NodeAttrs
&
attrs
)
{
.
set_
attr
<
FListInputNames
>
(
"FListInputNames"
,
[](
const
NodeAttrs
&
attrs
)
{
return
std
::
vector
<
std
::
string
>
{
"data"
,
"weight"
};
});
NNVM_REGISTER_OP
(
add
)
.
attr
<
std
::
string
>
(
"nick_name"
,
"plus"
);
.
set_
attr
<
std
::
string
>
(
"nick_name"
,
"plus"
);
NNVM_REGISTER_OP
(
assign
)
.
set_num_inputs
(
2
)
.
set_num_outputs
(
1
)
.
attr
<
FMutateInputs
>
(
"FMutateInputs"
,
[](
const
NodeAttrs
&
attrs
)
{
.
set_
attr
<
FMutateInputs
>
(
"FMutateInputs"
,
[](
const
NodeAttrs
&
attrs
)
{
return
std
::
vector
<
uint32_t
>
{
0
};
});
...
...
nnvm/include/nnvm/op.h
View file @
6ebbea5d
...
...
@@ -44,7 +44,7 @@ static const uint32_t kVarg = std::numeric_limits<uint32_t>::max();
* NNVM_REGISTER_OP(add)
* .describe("add two inputs together")
* .set_num_inputs(2)
* .attr<OpKernel>("gpu_kernel", AddKernel);
* .
set_
attr<OpKernel>("gpu_kernel", AddKernel);
*
* NNVM_REGISTER_OP(sub)
* .describe("substract one tensor from another")
...
...
@@ -53,7 +53,7 @@ static const uint32_t kVarg = std::numeric_limits<uint32_t>::max();
* // Can call regster multiple times in different files
* // to register different part of information
* NNVM_REGISTER_OP(sub)
* .attr<OpKernel>("gpu_kernel", SubKernel);
* .
set_
attr<OpKernel>("gpu_kernel", SubKernel);
*
* // get operators from registry.
* void my_function() {
...
...
@@ -213,8 +213,8 @@ class Op {
* \tparam ValueType The type of the value to be set.
*/
template
<
typename
ValueType
>
inline
Op
&
attr
(
const
std
::
string
&
attr_name
,
// NOLINT(*)
const
ValueType
&
value
);
inline
Op
&
set_
attr
(
const
std
::
string
&
attr_name
,
// NOLINT(*)
const
ValueType
&
value
);
/*!
* \brief Get an Op for a given operator name.
* Will raise an error if the op has not been registered.
...
...
@@ -300,7 +300,7 @@ class OpMap {
* NNVM_REGISTER_OP(add)
* .describe("add two inputs together")
* .set_num_inputs(2)
* .attr<OpKernel>("gpu_kernel", AddKernel);
* .
set_
attr<OpKernel>("gpu_kernel", AddKernel);
*
* \endcode
*/
...
...
@@ -329,7 +329,7 @@ inline const OpMap<ValueType>& Op::GetAttr(const std::string& key) {
}
template
<
typename
ValueType
>
inline
Op
&
Op
::
attr
(
// NOLINT(*)
inline
Op
&
Op
::
set_
attr
(
// NOLINT(*)
const
std
::
string
&
attr_name
,
const
ValueType
&
value
)
{
// update the attribute map of the key by creating new empty if needed.
UpdateAttrMap
(
attr_name
,
[
this
,
attr_name
,
value
](
any
*
pmap
)
{
...
...
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