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
1a4cd554
Commit
1a4cd554
authored
Sep 07, 2017
by
Jaikrishnan Menon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CMake: Add MKLDNN as an external project and a testcase
parent
edb5c12a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
138 additions
and
2 deletions
+138
-2
external_mkldnn.cmake
cmake/external_mkldnn.cmake
+55
-0
CMakeLists.txt
test/CMakeLists.txt
+8
-2
mkldnn.cpp
test/mkldnn.cpp
+74
-0
CMakeLists.txt
third-party/CMakeLists.txt
+1
-0
No files found.
cmake/external_mkldnn.cmake
0 → 100644
View file @
1a4cd554
# Copyright 2017 Nervana Systems Inc.
# 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
(
ExternalProject
)
#----------------------------------------------------------------------------------------------------------
# Fetch and install MKL-DNN
#----------------------------------------------------------------------------------------------------------
SET
(
MKLDNN_GIT_REPO_URL https://github.com/01org/mkl-dnn
)
set
(
EXTERNAL_INSTALL_LOCATION
${
CMAKE_BINARY_DIR
}
/external
)
# The 'BUILD_BYPRODUCTS' argument was introduced in CMake 3.2.
if
(
${
CMAKE_VERSION
}
VERSION_LESS 3.2
)
ExternalProject_Add
(
ext_mkldnn
GIT_REPOSITORY
${
MKLDNN_GIT_REPO_URL
}
UPDATE_COMMAND
""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=
${
EXTERNAL_INSTALL_LOCATION
}
)
else
()
ExternalProject_Add
(
ext_mkldnn
GIT_REPOSITORY
${
MKLDNN_GIT_REPO_URL
}
UPDATE_COMMAND
""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=
${
EXTERNAL_INSTALL_LOCATION
}
BUILD_BYPRODUCTS
"
${
EXTERNAL_INSTALL_LOCATION
}
/include/mkldnn.hpp"
)
endif
()
ExternalProject_Get_Property
(
ext_mkldnn source_dir binary_dir
)
ExternalProject_Add_Step
(
ext_mkldnn
PrepareMKL
COMMAND
${
source_dir
}
/scripts/prepare_mkl.sh
DEPENDEES download
DEPENDERS configure
)
#----------------------------------------------------------------------------------------------------------
set
(
MKLDNN_INCLUDE_DIR
"
${
EXTERNAL_INSTALL_LOCATION
}
/include"
PARENT_SCOPE
)
set
(
MKLDNN_LIB_DIR
"
${
EXTERNAL_INSTALL_LOCATION
}
/lib"
PARENT_SCOPE
)
test/CMakeLists.txt
View file @
1a4cd554
...
@@ -15,12 +15,17 @@ include_directories(
...
@@ -15,12 +15,17 @@ include_directories(
SYSTEM
SYSTEM
${
GTEST_INCLUDE_DIR
}
${
GTEST_INCLUDE_DIR
}
${
EIGEN_INCLUDE_DIR
}
${
EIGEN_INCLUDE_DIR
}
${
MKLDNN_INCLUDE_DIR
}
)
)
include_directories
(
include_directories
(
${
NGRAPH_INCLUDE_DIR
}
${
NGRAPH_INCLUDE_DIR
}
)
)
link_directories
(
${
MKLDNN_LIB_DIR
}
)
set
(
SRC
set
(
SRC
main.cpp
main.cpp
build_graph.cpp
build_graph.cpp
...
@@ -32,6 +37,7 @@ set (SRC
...
@@ -32,6 +37,7 @@ set (SRC
type_prop.cpp
type_prop.cpp
op.cpp
op.cpp
eigen.cpp
eigen.cpp
mkldnn.cpp
)
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
...
@@ -39,10 +45,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}
...
@@ -39,10 +45,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}
add_executable
(
unit-test
${
SRC
}
)
add_executable
(
unit-test
${
SRC
}
)
target_link_libraries
(
unit-test ngraph libgtest pthread
)
target_link_libraries
(
unit-test ngraph libgtest
mkldnn
pthread
)
target_link_libraries
(
unit-test
${
CMAKE_DL_LIBS
}
)
target_link_libraries
(
unit-test
${
CMAKE_DL_LIBS
}
)
add_dependencies
(
unit-test ngraph libgtest eigen
)
add_dependencies
(
unit-test ngraph libgtest eigen
ext_mkldnn
)
add_custom_target
(
check
add_custom_target
(
check
COMMAND
${
PROJECT_BINARY_DIR
}
/test/unit-test
COMMAND
${
PROJECT_BINARY_DIR
}
/test/unit-test
...
...
test/mkldnn.cpp
0 → 100644
View file @
1a4cd554
// ----------------------------------------------------------------------------
// Copyright 2017 Nervana Systems Inc.
// 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
// ----------------------------------------------------------------------------
#include <iostream>
#include <vector>
#include <mkldnn.hpp>
#include "gtest/gtest.h"
static
int
tensor_volume
(
const
mkldnn
::
memory
::
dims
&
t
)
{
int
x
=
1
;
for
(
const
auto
i
:
t
)
x
*=
i
;
return
x
;
}
TEST
(
mkldnn
,
engine
)
{
using
namespace
mkldnn
;
#pragma GCC diagnostic ignored "-Wgnu-statement-expression"
EXPECT_NO_THROW
(({
auto
cpu_engine
=
engine
(
engine
::
cpu
,
0
);
const
int
mb
=
2
;
const
int
groups
=
2
;
memory
::
dims
input_tz
=
{
mb
,
256
,
13
,
13
};
memory
::
dims
weights_tz
=
{
groups
,
384
/
groups
,
256
/
groups
,
3
,
3
};
memory
::
dims
bias_tz
=
{
384
};
memory
::
dims
strides
=
{
1
,
1
};
memory
::
dims
padding
=
{
0
,
0
};
memory
::
dims
output_tz
=
{
mb
,
384
,
(
input_tz
[
2
]
+
2
*
padding
[
0
]
-
weights_tz
[
3
])
/
strides
[
0
]
+
1
,
(
input_tz
[
3
]
+
2
*
padding
[
1
]
-
weights_tz
[
4
])
/
strides
[
1
]
+
1
,
};
std
::
vector
<
float
>
input
(
tensor_volume
(
input_tz
),
.0
f
);
std
::
vector
<
float
>
weights
(
tensor_volume
(
weights_tz
),
.0
f
);
std
::
vector
<
float
>
bias
(
tensor_volume
(
bias_tz
),
.0
f
);
std
::
vector
<
float
>
output
(
tensor_volume
(
output_tz
),
.0
f
);
auto
c3_src_desc
=
memory
::
desc
({
input_tz
},
memory
::
data_type
::
f32
,
memory
::
format
::
nchw
);
auto
c3_weights_desc
=
memory
::
desc
({
weights_tz
},
memory
::
data_type
::
f32
,
memory
::
format
::
goihw
);
auto
c3_bias_desc
=
memory
::
desc
({
bias_tz
},
memory
::
data_type
::
f32
,
memory
::
format
::
x
);
auto
c3_dst_desc
=
memory
::
desc
({
output_tz
},
memory
::
data_type
::
f32
,
memory
::
format
::
nchw
);
auto
c3_src
=
memory
({
c3_src_desc
,
cpu_engine
},
input
.
data
());
auto
c3_weights
=
memory
({
c3_weights_desc
,
cpu_engine
},
weights
.
data
());
auto
c3_bias
=
memory
({
c3_bias_desc
,
cpu_engine
},
bias
.
data
());
auto
c3_dst
=
memory
({
c3_dst_desc
,
cpu_engine
},
output
.
data
());
auto
c3
=
convolution_forward
(
convolution_forward
::
primitive_desc
(
convolution_forward
::
desc
(
prop_kind
::
forward
,
algorithm
::
convolution_direct
,
c3_src_desc
,
c3_weights_desc
,
c3_bias_desc
,
c3_dst_desc
,
strides
,
padding
,
padding
,
padding_kind
::
zero
),
cpu_engine
),
c3_src
,
c3_weights
,
c3_bias
,
c3_dst
);
stream
(
stream
::
kind
::
eager
).
submit
({
c3
}).
wait
();
}));
}
third-party/CMakeLists.txt
View file @
1a4cd554
...
@@ -13,3 +13,4 @@
...
@@ -13,3 +13,4 @@
include
(
../cmake/external_gtest.cmake
)
include
(
../cmake/external_gtest.cmake
)
include
(
../cmake/external_eigen.cmake
)
include
(
../cmake/external_eigen.cmake
)
include
(
../cmake/external_mkldnn.cmake
)
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