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
fe413386
Commit
fe413386
authored
Mar 02, 2018
by
Scott Cyphers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the example.
parent
b9841863
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
15 deletions
+89
-15
CMakeLists.txt
doc/CMakeLists.txt
+3
-1
CMakeLists.txt
doc/examples/CMakeLists.txt
+39
-0
abc.cpp
doc/examples/abc.cpp
+47
-14
No files found.
doc/CMakeLists.txt
View file @
fe413386
...
...
@@ -13,7 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
add_subdirectory
(
examples
)
if
(
"
${
NGRAPH_BUILD_DOCS
}
"
MATCHES
"^ON$"
)
add_custom_target
(
docs
COMMENT
"Build all of the documentation types selected during CMake configuration."
...
...
doc/examples/CMakeLists.txt
0 → 100644
View file @
fe413386
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
if
(
MKLDNN_INCLUDE_DIR
)
link_directories
(
${
MKLDNN_LIB_DIR
}
)
endif
()
if
(
NGRAPH_CPU_ENABLE
)
set
(
SRC
abc.cpp
${
PROJECT_SOURCE_DIR
}
/doc/examples/abc.cpp
)
add_executable
(
abc
${
SRC
}
)
add_dependencies
(
abc ngraph
)
set
(
HEADER_SEARCH_DEFINES
"NGRAPH_HEADERS_PATH=
\"
${
NGRAPH_INCLUDE_PATH
}
\"
"
)
target_link_libraries
(
abc ngraph
)
include_directories
(
SYSTEM
${
JSON_INCLUDE_DIR
}
)
set_source_files_properties
(
abc.cpp PROPERTIES COMPILE_DEFINITIONS
"
${
HEADER_SEARCH_DEFINES
}
"
)
endif
()
doc/examples/abc.cpp
View file @
fe413386
/*******************************************************************************
* Copyright 2017-2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#include <iostream>
#include <ngraph.hpp>
#include <ngraph
/ngraph
.hpp>
using
namespace
ngraph
;
void
main
()
int
main
()
{
// Build the graph
Shape
s
{
2
,
3
};
...
...
@@ -13,10 +29,10 @@ void main()
auto
c
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
s
);
auto
t0
=
std
::
make_shared
<
op
::
Add
>
(
a
,
b
);
auto
t1
=
std
::
make_shared
<
op
::
Multiply
(
t0
,
c
);
auto
t1
=
std
::
make_shared
<
op
::
Multiply
>
(
t0
,
c
);
// Make the function
auto
f
=
make_shared
<
Function
>
(
NodeVector
{
t1
},
ParameterVector
{
a
,
b
,
c
});
auto
f
=
std
::
make_shared
<
Function
>
(
NodeVector
{
t1
},
op
::
ParameterVector
{
a
,
b
,
c
});
// Get the backend
auto
manager
=
runtime
::
Manager
::
get
(
"CPU"
);
...
...
@@ -27,20 +43,38 @@ void main()
auto
cf
=
backend
->
make_call_frame
(
external
);
// Allocate tensors
auto
t_a
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
s
hape
);
auto
t_b
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
s
hape
);
auto
t_c
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
s
hape
);
auto
t_result
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
s
hape
);
auto
t_a
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
s
);
auto
t_b
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
s
);
auto
t_c
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
s
);
auto
t_result
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
s
);
// Initialize tensors
copy_data
(
t_a
,
test
::
NDArray
<
float
,
2
>
({{
1
,
2
,
3
},
{
4
,
5
,
6
}}).
get_vector
());
copy_data
(
t_b
,
test
::
NDArray
<
float
,
2
>
({{
7
,
8
,
9
},
{
10
,
11
,
12
}}).
get_vector
());
copy_data
(
t_c
,
test
::
NDArray
<
float
,
2
>
({{
1
,
0
,
-
1
},
{
-
1
,
1
,
2
}}).
get_vector
());
float
v_a
[
2
][
3
]
=
{{
1
,
2
,
3
},
{
4
,
5
,
6
}};
float
v_b
[
2
][
3
]
=
{{
7
,
8
,
9
},
{
10
,
11
,
12
}};
float
v_c
[
2
][
3
]
=
{{
1
,
0
,
-
1
},
{
-
1
,
1
,
2
}};
t_a
->
write
(
&
v_a
,
0
,
sizeof
(
v_a
));
t_b
->
write
(
&
v_b
,
0
,
sizeof
(
v_b
));
t_c
->
write
(
&
v_c
,
0
,
sizeof
(
v_c
));
// Invoke the function
cf
->
call
({
t_a
,
t_b
,
t_c
},
{
t_result
});
// Get the result
float
r
[
2
,
3
];
float
r
[
2
][
3
];
t_result
->
read
(
&
r
,
0
,
sizeof
(
r
));
}
\ No newline at end of file
std
::
cout
<<
"["
<<
std
::
endl
;
for
(
size_t
i
=
0
;
i
<
s
[
0
];
++
i
)
{
std
::
cout
<<
" ["
;
for
(
size_t
j
=
0
;
j
<
s
[
1
];
++
j
)
{
std
::
cout
<<
r
[
i
][
j
]
<<
' '
;
}
std
::
cout
<<
']'
<<
std
::
endl
;
}
std
::
cout
<<
']'
<<
std
::
endl
;
return
0
;
}
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