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
2e420183
Commit
2e420183
authored
Aug 25, 2017
by
Scott Cyphers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Calls will be the focus of op behavior; shrink op to an identifier.
update broadcast op args
parent
5817c0a7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
31 deletions
+100
-31
function.hpp
src/ngraph/function.hpp
+9
-0
node.hpp
src/ngraph/node.hpp
+15
-0
op.hpp
src/ngraph/op.hpp
+67
-25
function.cpp
src/ops/function.cpp
+1
-0
op.cpp
src/ops/op.cpp
+7
-5
build_graph.cpp
test/build_graph.cpp
+1
-1
No files found.
src/ngraph/function.hpp
View file @
2e420183
...
...
@@ -33,6 +33,12 @@ namespace ngraph
Parameter
(
Function
&
function
,
size_t
index
);
const
std
::
string
&
description
()
const
override
{
static
std
::
string
name
{
"Parameter"
};
return
name
;
}
protected
:
Function
&
m_function
;
size_t
m_index
;
...
...
@@ -66,8 +72,11 @@ namespace ngraph
Parameter
::
ptr
parameter
(
size_t
i
)
{
return
m_parameters
[
i
];
}
const
std
::
string
&
name
()
const
override
{
return
m_name
;
}
protected
:
std
::
vector
<
Parameter
::
ptr
>
m_parameters
;
Result
m_result
;
std
::
string
m_name
;
};
}
src/ngraph/node.hpp
View file @
2e420183
...
...
@@ -15,6 +15,7 @@
#pragma once
#include <set>
#include <string>
#include <vector>
#include "ngraph/type.hpp"
...
...
@@ -33,6 +34,7 @@ namespace ngraph
public
:
using
ptr
=
std
::
shared_ptr
<
Node
>
;
protected
:
Node
(
const
std
::
vector
<
Node
::
ptr
>&
arguments
,
ValueType
::
ptr
type
=
nullptr
)
:
TypedValueMixin
(
type
)
,
m_arguments
(
arguments
)
...
...
@@ -44,14 +46,27 @@ namespace ngraph
}
}
virtual
~
Node
()
{}
public
:
/// A "one-liner" describing this node.
virtual
const
std
::
string
&
description
()
const
=
0
;
/// Propagate types and check arguments for consistency
// virtual void propagate_types() = 0;
const
std
::
vector
<
Node
::
ptr
>
arguments
()
const
{
return
m_arguments
;
}
std
::
vector
<
Node
::
ptr
>
arguments
()
{
return
m_arguments
;
}
const
std
::
multiset
<
Node
*>
users
()
const
{
return
m_users
;
}
std
::
multiset
<
Node
*>
users
()
{
return
m_users
;
}
const
std
::
string
&
name
()
const
{
return
m_name
;
}
void
name
(
const
std
::
string
&
name
)
{
m_name
=
name
;
}
protected
:
std
::
vector
<
Node
::
ptr
>
m_arguments
;
std
::
multiset
<
Node
*>
m_users
;
std
::
string
m_name
;
};
}
src/ngraph/op.hpp
View file @
2e420183
...
...
@@ -21,7 +21,17 @@
namespace
ngraph
{
class
Op
;
/**
** Every instance of Op corresponds to a unique defined operation.
**/
class
Op
{
protected
:
virtual
~
Op
()
{}
public
:
virtual
const
std
::
string
&
name
()
const
=
0
;
};
/**
** Call nodes are nodes whose value is the result of some operation, the op,
...
...
@@ -39,43 +49,69 @@ namespace ngraph
{
}
const
std
::
string
&
description
()
const
override
{
return
m_op
->
name
();
}
protected
:
std
::
shared_ptr
<
Op
>
m_op
;
};
/**
** The
Op class provides the behavior for a Call
.
** The
re is exactly one instance of builtin op for each pre-defined operation
.
**/
class
Op
class
BuiltinOp
:
public
Op
{
}
;
friend
class
Call
;
namespace
op
{
std
::
shared_ptr
<
Node
>
broadcast
(
const
Node
::
ptr
&
tensor
,
size_t
axis
);
}
public
:
BuiltinOp
(
const
std
::
string
&
name
)
:
m_name
(
name
)
{
}
public
:
const
std
::
string
&
name
()
const
override
{
return
m_name
;
}
protected
:
std
::
string
m_name
;
};
class
B
roadcast
:
public
Op
,
public
std
::
enable_shared_from_this
<
Broadcast
>
class
B
uiltinCall
:
public
Call
{
friend
std
::
shared_ptr
<
Node
>
op
::
broadcast
(
const
Node
::
ptr
&
tensor
,
size_t
axis
);
public
:
const
std
::
string
&
description
()
const
override
{
static
std
::
string
name
{
"BuiltinCall "
};
return
name
;
}
protected
:
class
BroadcastCall
:
public
Call
BuiltinCall
(
const
std
::
shared_ptr
<
Op
>&
op
,
const
std
::
vector
<
Node
::
ptr
>&
args
)
:
Call
(
op
,
args
)
{
friend
class
Broadcast
;
}
};
public
:
BroadcastCall
(
const
std
::
shared_ptr
<
Op
>&
op
,
const
Node
::
ptr
&
arg
,
size_t
axis
)
:
Call
(
op
,
{
arg
})
,
m_axis
(
axis
)
{
}
namespace
op
{
std
::
shared_ptr
<
Node
>
broadcast
(
const
Node
::
ptr
&
tensor
,
const
Shape
&
shape
,
const
std
::
vector
<
size_t
>&
broadcast_axes
);
}
protected
:
size_t
m_axis
;
};
class
BroadcastCall
:
public
BuiltinCall
{
public
:
BroadcastCall
(
const
Node
::
ptr
&
arg
,
const
Shape
&
shape
,
std
::
vector
<
size_t
>
broadcast_axes
)
:
BuiltinCall
(
s_op
,
{
arg
})
,
m_shape
(
shape
)
,
m_broadcast_axes
(
broadcast_axes
)
{
}
Shape
m_shape
;
std
::
vector
<
size_t
>
m_broadcast_axes
;
static
std
::
shared_ptr
<
Broadcast
>
s_op
;
protected
:
static
std
::
shared_ptr
<
BuiltinOp
>
s_op
;
};
namespace
op
...
...
@@ -83,9 +119,15 @@ namespace ngraph
std
::
shared_ptr
<
Node
>
dot
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
);
}
class
Dot
:
public
Op
,
public
std
::
enable_shared_from_this
<
Dot
>
class
Dot
Call
:
public
BuiltinCall
{
friend
std
::
shared_ptr
<
Node
>
op
::
dot
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
);
static
std
::
shared_ptr
<
Dot
>
s_op
;
public
:
DotCall
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
:
BuiltinCall
(
s_op
,
{
arg0
,
arg1
})
{
}
protected
:
static
std
::
shared_ptr
<
BuiltinOp
>
s_op
;
};
}
src/ops/function.cpp
View file @
2e420183
...
...
@@ -26,6 +26,7 @@ Parameter::Parameter(Function& function, size_t index)
Function
::
Function
(
size_t
n_parameters
)
:
m_parameters
(
n_parameters
)
,
m_name
(
"Function"
)
{
for
(
int
i
=
0
;
i
<
n_parameters
;
i
++
)
{
...
...
src/ops/op.cpp
View file @
2e420183
...
...
@@ -17,16 +17,18 @@
using
namespace
ngraph
;
using
namespace
std
;
s
hared_ptr
<
Broadcast
>
ngraph
::
Broadcast
::
s_op
=
make_shared
<
ngraph
::
Broadcast
>
(
);
s
td
::
shared_ptr
<
BuiltinOp
>
BroadcastCall
::
s_op
=
make_shared
<
BuiltinOp
>
(
"broadcast"
);
shared_ptr
<
Node
>
ngraph
::
op
::
broadcast
(
const
Node
::
ptr
&
tensor
,
size_t
axis
)
shared_ptr
<
Node
>
ngraph
::
op
::
broadcast
(
const
Node
::
ptr
&
tensor
,
const
Shape
&
shape
,
const
vector
<
size_t
>&
broadcast_axes
)
{
return
make_shared
<
Broadcast
::
BroadcastCall
>
(
Broadcast
::
s_op
->
shared_from_this
(),
tensor
,
axi
s
);
return
make_shared
<
Broadcast
Call
>
(
tensor
,
shape
,
broadcast_axe
s
);
}
s
hared_ptr
<
Dot
>
ngraph
::
Dot
::
s_op
=
make_shared
<
ngraph
::
Dot
>
(
);
s
td
::
shared_ptr
<
BuiltinOp
>
DotCall
::
s_op
=
make_shared
<
BuiltinOp
>
(
"dot"
);
shared_ptr
<
Node
>
ngraph
::
op
::
dot
(
const
Node
::
ptr
&
arg0
,
const
Node
::
ptr
&
arg1
)
{
return
make_shared
<
Call
>
(
Dot
::
s_op
->
shared_from_this
(),
std
::
vector
<
Node
::
ptr
>
{
arg0
,
arg1
}
);
return
make_shared
<
DotCall
>
(
arg0
,
arg1
);
}
test/build_graph.cpp
View file @
2e420183
...
...
@@ -30,7 +30,7 @@ TEST(graph, build_simple)
cluster_0
->
parameter
(
3
)
->
type
(
element_type_float
,
{
32
,
7
});
auto
arg3
=
cluster_0
->
parameter
(
3
);
// call broadcast op on arg3, broadcasting on axis 1.
auto
broadcast_1
=
op
::
broadcast
(
arg3
,
1
);
auto
broadcast_1
=
op
::
broadcast
(
arg3
,
{
10
,
32
,
7
},
{
0
}
);
auto
arg2
=
cluster_0
->
parameter
(
2
);
auto
arg0
=
cluster_0
->
parameter
(
0
);
// call dot op
...
...
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