Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
b0e1e076
Commit
b0e1e076
authored
Aug 28, 2017
by
Scott Cyphers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call -> Op, failing test for pattern match.
parent
db6e3052
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
145 additions
and
95 deletions
+145
-95
node.hpp
src/ngraph/node.hpp
+11
-0
op.hpp
src/ngraph/op.hpp
+84
-76
op.cpp
src/ops/op.cpp
+19
-19
build_graph.cpp
test/build_graph.cpp
+31
-0
No files found.
src/ngraph/node.hpp
View file @
b0e1e076
...
...
@@ -18,6 +18,8 @@
#include <string>
#include <vector>
#include <iostream>
#include "ngraph/type.hpp"
namespace
ngraph
...
...
@@ -62,6 +64,15 @@ namespace ngraph
std
::
string
name
()
const
{
return
m_name
;
}
void
name
(
const
std
::
string
&
name
)
{
m_name
=
name
;
}
/**
** Return true if this has the same implementing class as call. This
** will be used by the pattern matcher when comparing a pattern
** graph against the graph.
** TODO: typeids are Node*, doc says they should be the actual classes.
**/
bool
has_same_op
(
const
Node
::
ptr
&
node
)
{
return
typeid
(
this
)
==
typeid
(
node
.
get
());
}
protected
:
std
::
vector
<
Node
::
ptr
>
m_arguments
;
std
::
multiset
<
Node
*>
m_users
;
...
...
src/ngraph/op.hpp
View file @
b0e1e076
...
...
@@ -65,32 +65,40 @@ namespace ngraph
}
/**
**
Call nodes are nodes whose value is the result of some operation, the op,
** applied to its arguments.
We use the op as a callable to construct the
**
call nodes. For calls to user functions, the op will b
e the user function.
**
Op nodes are nodes whose value is the result of some operation
** applied to its arguments.
For calls to user functions, the op will
**
referenc
e the user function.
**/
class
Call
:
public
Node
class
Op
:
public
Node
{
public
:
Call
(
const
std
::
vector
<
Node
::
ptr
>&
arguments
)
Op
(
const
std
::
vector
<
Node
::
ptr
>&
arguments
)
:
Node
(
arguments
,
nullptr
)
{
}
};
/**
** Return true if this has the same implementing class as call. This
** will be used by the pattern matcher when comparing a pattern
** graph against the graph.
**/
bool
has_same_op
(
Call
&
call
)
{
return
typeid
(
this
)
==
typeid
(
&
call
);
}
virtual
std
::
string
description
()
const
override
{
return
"Call"
;
}
/**
** A FunctionOp invokes a function on node arguments. In addition to the argument
** we need to preserve the function.
**/
class
FunctionOp
:
public
Op
{
virtual
std
::
string
description
()
const
override
{
return
"FunctionOp"
;
}
protected
:
Node
::
ptr
m_function
;
};
class
BuiltinCall
:
public
Call
/**
** The is an operation we handle directly, i.e. all type checking, etc.
** are defined in C++ rather than in terms of ngraph operations.
**/
class
BuiltinOp
:
public
Op
{
public
:
virtual
std
::
string
description
()
const
override
{
return
"Builtin
Call
"
;
}
virtual
std
::
string
description
()
const
override
{
return
"Builtin
Op
"
;
}
/// Name of the builtin op, for debugging and logging.
virtual
std
::
string
op_name
()
const
=
0
;
...
...
@@ -98,17 +106,17 @@ namespace ngraph
virtual
void
propagate_types
()
override
{}
protected
:
Builtin
Call
(
const
std
::
vector
<
Node
::
ptr
>&
args
)
:
Call
(
args
)
Builtin
Op
(
const
std
::
vector
<
Node
::
ptr
>&
args
)
:
Op
(
args
)
{
}
};
class
Abs
Call
:
public
BuiltinCall
class
Abs
Op
:
public
BuiltinOp
{
public
:
Abs
Call
(
const
Node
::
ptr
&
arg0
)
:
Builtin
Call
({
arg0
})
Abs
Op
(
const
Node
::
ptr
&
arg0
)
:
Builtin
Op
({
arg0
})
{
}
...
...
@@ -116,18 +124,18 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Add
Call
:
public
BuiltinCall
class
Add
Op
:
public
BuiltinOp
{
public
:
Add
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Add
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
virtual
std
::
string
op_name
()
const
override
{
return
"add"
;
}
//virtual void propagate_types() override;
};
class
Broadcast
Call
:
public
BuiltinCall
class
Broadcast
Op
:
public
BuiltinOp
{
public
:
/**
...
...
@@ -136,8 +144,8 @@ namespace ngraph
** /param broadcast_axes The axis positions (0-based) in the result that are being broadcast.
** the remaining axes in shape must be the same as the shape of arg.
**/
Broadcast
Call
(
const
Node
::
ptr
&
arg
,
const
Shape
&
shape
,
std
::
vector
<
size_t
>
broadcast_axes
)
:
Builtin
Call
({
arg
})
Broadcast
Op
(
const
Node
::
ptr
&
arg
,
const
Shape
&
shape
,
std
::
vector
<
size_t
>
broadcast_axes
)
:
Builtin
Op
({
arg
})
,
m_shape
(
shape
)
,
m_broadcast_axes
(
broadcast_axes
)
{
...
...
@@ -151,11 +159,11 @@ namespace ngraph
std
::
vector
<
size_t
>
m_broadcast_axes
;
};
class
Ceiling
Call
:
public
BuiltinCall
class
Ceiling
Op
:
public
BuiltinOp
{
public
:
Ceiling
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Ceiling
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -163,11 +171,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Divide
Call
:
public
BuiltinCall
class
Divide
Op
:
public
BuiltinOp
{
public
:
Divide
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Divide
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -175,12 +183,12 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Dot
Call
:
public
BuiltinCall
class
Dot
Op
:
public
BuiltinOp
{
public
:
/// TODO: Semantics of arg0 and arg1 axes wrt reduction.
Dot
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Dot
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -188,11 +196,11 @@ namespace ngraph
virtual
void
propagate_types
()
override
;
};
class
Equal
Call
:
public
BuiltinCall
class
Equal
Op
:
public
BuiltinOp
{
public
:
Equal
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Equal
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -200,11 +208,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Exponential
Call
:
public
BuiltinCall
class
Exponential
Op
:
public
BuiltinOp
{
public
:
Exponential
Call
(
const
Node
::
ptr
&
arg0
)
:
Builtin
Call
({
arg0
})
Exponential
Op
(
const
Node
::
ptr
&
arg0
)
:
Builtin
Op
({
arg0
})
{
}
...
...
@@ -212,11 +220,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Floor
Call
:
public
BuiltinCall
class
Floor
Op
:
public
BuiltinOp
{
public
:
Floor
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Floor
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -224,11 +232,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Greater
Call
:
public
BuiltinCall
class
Greater
Op
:
public
BuiltinOp
{
public
:
Greater
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Greater
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -236,11 +244,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Less
Call
:
public
BuiltinCall
class
Less
Op
:
public
BuiltinOp
{
public
:
Less
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Less
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -248,11 +256,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Log
Call
:
public
BuiltinCall
class
Log
Op
:
public
BuiltinOp
{
public
:
Log
Call
(
const
Node
::
ptr
&
arg0
)
:
Builtin
Call
({
arg0
})
Log
Op
(
const
Node
::
ptr
&
arg0
)
:
Builtin
Op
({
arg0
})
{
}
...
...
@@ -260,11 +268,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Maximum
Call
:
public
BuiltinCall
class
Maximum
Op
:
public
BuiltinOp
{
public
:
Maximum
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Maximum
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -272,11 +280,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Minimum
Call
:
public
BuiltinCall
class
Minimum
Op
:
public
BuiltinOp
{
public
:
Minimum
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Minimum
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -284,11 +292,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Multiply
Call
:
public
BuiltinCall
class
Multiply
Op
:
public
BuiltinOp
{
public
:
Multiply
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Multiply
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -296,11 +304,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Negate
Call
:
public
BuiltinCall
class
Negate
Op
:
public
BuiltinOp
{
public
:
Negate
Call
(
const
Node
::
ptr
&
arg0
)
:
Builtin
Call
({
arg0
})
Negate
Op
(
const
Node
::
ptr
&
arg0
)
:
Builtin
Op
({
arg0
})
{
}
...
...
@@ -308,11 +316,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Power
Call
:
public
BuiltinCall
class
Power
Op
:
public
BuiltinOp
{
public
:
Power
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Power
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -320,11 +328,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Remainder
Call
:
public
BuiltinCall
class
Remainder
Op
:
public
BuiltinOp
{
public
:
Remainder
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Remainder
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
@@ -332,11 +340,11 @@ namespace ngraph
//virtual void propagate_types() override;
};
class
Reshape
Call
:
public
BuiltinCall
class
Reshape
Op
:
public
BuiltinOp
{
public
:
Reshape
Call
(
const
Node
::
ptr
&
arg0
,
const
Shape
&
shape
)
:
Builtin
Call
({
arg0
})
Reshape
Op
(
const
Node
::
ptr
&
arg0
,
const
Shape
&
shape
)
:
Builtin
Op
({
arg0
})
,
m_shape
(
shape
)
{
}
...
...
@@ -347,11 +355,11 @@ namespace ngraph
Shape
m_shape
;
};
class
Subtract
Call
:
public
BuiltinCall
class
Subtract
Op
:
public
BuiltinOp
{
public
:
Subtract
Call
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Call
({
arg0
,
arg1
})
Subtract
Op
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
Builtin
Op
({
arg0
,
arg1
})
{
}
...
...
src/ops/op.cpp
View file @
b0e1e076
...
...
@@ -21,12 +21,12 @@ using namespace std;
Node
::
ptr
ngraph
::
op
::
abs
(
const
Node
::
ptr
&
arg
)
{
return
make_shared
<
Abs
Call
>
(
arg
);
return
make_shared
<
Abs
Op
>
(
arg
);
}
Node
::
ptr
ngraph
::
op
::
add
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Add
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Add
Op
>
(
arg0
,
arg1
);
}
/**
...
...
@@ -39,10 +39,10 @@ Node::ptr ngraph::op::broadcast(const Node::ptr& tensor,
const
Shape
&
shape
,
const
vector
<
size_t
>&
broadcast_axes
)
{
return
make_shared
<
Broadcast
Call
>
(
tensor
,
shape
,
broadcast_axes
);
return
make_shared
<
Broadcast
Op
>
(
tensor
,
shape
,
broadcast_axes
);
}
void
Broadcast
Call
::
propagate_types
()
void
Broadcast
Op
::
propagate_types
()
{
auto
arg_type
=
m_arguments
.
at
(
0
)
->
type
();
if
(
nullptr
==
arg_type
)
...
...
@@ -70,7 +70,7 @@ void BroadcastCall::propagate_types()
Node
::
ptr
ngraph
::
op
::
ceiling
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Ceiling
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Ceiling
Op
>
(
arg0
,
arg1
);
}
// 'concatenate',
...
...
@@ -80,16 +80,16 @@ Node::ptr ngraph::op::ceiling(const Node::ptr& arg0, const Node::ptr& arg1)
Node
::
ptr
ngraph
::
op
::
divide
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Divide
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Divide
Op
>
(
arg0
,
arg1
);
}
/// TODO: Semantics of arg0 and arg1 axes wrt reduction.
Node
::
ptr
ngraph
::
op
::
dot
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Dot
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Dot
Op
>
(
arg0
,
arg1
);
}
void
Dot
Call
::
propagate_types
()
void
Dot
Op
::
propagate_types
()
{
auto
arg0_tensor_type
=
m_arguments
.
at
(
0
)
->
type
()
->
as
<
TensorViewType
*>
();
auto
arg1_tensor_type
=
m_arguments
.
at
(
1
)
->
type
()
->
as
<
TensorViewType
*>
();
...
...
@@ -129,37 +129,37 @@ void DotCall::propagate_types()
Node
::
ptr
ngraph
::
op
::
exponential
(
const
Node
::
ptr
&
arg0
)
{
return
make_shared
<
Exponential
Call
>
(
arg0
);
return
make_shared
<
Exponential
Op
>
(
arg0
);
}
Node
::
ptr
ngraph
::
op
::
floor
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Floor
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Floor
Op
>
(
arg0
,
arg1
);
}
Node
::
ptr
ngraph
::
op
::
log
(
const
Node
::
ptr
&
arg0
)
{
return
make_shared
<
Log
Call
>
(
arg0
);
return
make_shared
<
Log
Op
>
(
arg0
);
}
Node
::
ptr
ngraph
::
op
::
maximum
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Maximum
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Maximum
Op
>
(
arg0
,
arg1
);
}
Node
::
ptr
ngraph
::
op
::
minimum
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Minimum
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Minimum
Op
>
(
arg0
,
arg1
);
}
Node
::
ptr
ngraph
::
op
::
multiply
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Multiply
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Multiply
Op
>
(
arg0
,
arg1
);
}
Node
::
ptr
ngraph
::
op
::
negate
(
const
Node
::
ptr
&
arg0
)
{
return
make_shared
<
Negate
Call
>
(
arg0
);
return
make_shared
<
Negate
Op
>
(
arg0
);
}
// 'pad',
...
...
@@ -167,19 +167,19 @@ Node::ptr ngraph::op::negate(const Node::ptr& arg0)
Node
::
ptr
ngraph
::
op
::
power
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Power
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Power
Op
>
(
arg0
,
arg1
);
}
//'reduce',
Node
::
ptr
ngraph
::
op
::
remainder
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Remainder
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Remainder
Op
>
(
arg0
,
arg1
);
}
Node
::
ptr
ngraph
::
op
::
reshape
(
const
Node
::
ptr
&
arg0
,
const
Shape
&
shape
)
{
return
make_shared
<
Reshape
Call
>
(
arg0
,
shape
);
return
make_shared
<
Reshape
Op
>
(
arg0
,
shape
);
}
//'reverse',
...
...
@@ -189,7 +189,7 @@ Node::ptr ngraph::op::reshape(const Node::ptr& arg0, const Shape& shape)
Node
::
ptr
ngraph
::
op
::
subtract
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Subtract
Call
>
(
arg0
,
arg1
);
return
make_shared
<
Subtract
Op
>
(
arg0
,
arg1
);
}
// 'transpose',
...
...
test/build_graph.cpp
View file @
b0e1e076
...
...
@@ -60,3 +60,34 @@ TEST(build_graph, as_type)
TupleType
*
tp_tp
=
tp_vt
->
as
<
TupleType
*>
();
ASSERT_EQ
(
tp_vt
.
get
(),
tp_tp
);
}
// Check Call comparisons
TEST
(
DISABLED_build_graph
,
call_comparison
)
{
auto
fun
=
make_shared
<
Function
>
(
3
);
fun
->
parameter
(
0
)
->
type
(
element
::
float32_t
,
{
32
,
3
});
fun
->
parameter
(
1
)
->
type
(
element
::
float32_t
,
{
3
});
fun
->
parameter
(
2
)
->
type
(
element
::
float32_t
,
{
32
});
auto
arg0
=
fun
->
parameter
(
0
);
auto
arg1
=
fun
->
parameter
(
1
);
auto
arg2
=
fun
->
parameter
(
2
);
auto
dot
=
op
::
dot
(
arg0
,
arg1
);
auto
add
=
op
::
add
(
dot
,
arg2
);
auto
pattern
=
make_shared
<
Function
>
(
1
);
pattern
->
parameter
(
0
)
->
type
(
element
::
float32_t
,
{});
auto
parg
=
pattern
->
parameter
(
0
);
auto
pattern_dot
=
op
::
dot
(
parg
,
parg
);
ASSERT_TRUE
(
pattern_dot
->
has_same_op
(
dot
));
// TODO This passes because typeid is not behaving as documented.
// Need to figure out what's wrong.
ASSERT_FALSE
(
pattern_dot
->
has_same_op
(
add
));
}
// Check argument inverses
TEST
(
build_graph
,
arg_inverse
)
{
}
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