Commit cea849f7 authored by LS Cook's avatar LS Cook

Merge branch 'master' into cyphers/dochow

parents 91a835eb aeee2039
......@@ -97,15 +97,16 @@ endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
if(DEFINED ENV{NGRAPH_WARNINGS_AS_ERRORS})
if($ENV{NGRAPH_WARNINGS_AS_ERRORS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
message(STATUS "Warnings as errors")
endif()
endif()
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
if ("${NGRAPH_WARNINGS_AS_ERRORS}" MATCHES "^ON$")
message(STATUS "Enabling warnings as errors")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()
# Set true if CPU backend is built by default
if (NOT DEFINED NGRAPH_CPU_ENABLE)
set(NGRAPH_CPU_ENABLE TRUE)
......
# ******************************************************************************
# 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.
# ******************************************************************************
# Enable ExternalProject CMake module
include(ExternalProject)
#------------------------------------------------------------------------------
# Download json
#------------------------------------------------------------------------------
SET(JSON_GIT_REPO_URL https://github.com/nlohmann/json)
SET(JSON_GIT_LABEL v3.1.1)
# The 'BUILD_BYPRODUCTS' argument was introduced in CMake 3.2.
if (${CMAKE_VERSION} VERSION_LESS 3.2)
ExternalProject_Add(
ext_json
GIT_REPOSITORY ${JSON_GIT_REPO_URL}
GIT_TAG ${JSON_GIT_LABEL}
# Disable install step
BUILD_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND ""
)
else()
ExternalProject_Add(
ext_json
GIT_REPOSITORY ${JSON_GIT_REPO_URL}
GIT_TAG ${JSON_GIT_LABEL}
# Disable install step
BUILD_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND ""
)
endif()
#------------------------------------------------------------------------------
get_filename_component(
JSON_INCLUDE_DIR
"${EXTERNAL_PROJECTS_ROOT}/ext_json-prefix/src/ext_json/include"
ABSOLUTE)
set(JSON_INCLUDE_DIR "${JSON_INCLUDE_DIR}" PARENT_SCOPE)
......@@ -266,8 +266,9 @@ if (NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR AND MKLDNN_INCLUDE_DIR)
DEPENDS resource_generator ext_eigen ext_llvm ext_mkldnn
BYPRODUCTS
)
add_dependencies(ngraph header_resource)
add_dependencies(ngraph header_resource ext_json)
include_directories(${CMAKE_BINARY_DIR})
include_directories(SYSTEM ${JSON_INCLUDE_DIR})
endif()
if (NOT APPLE)
......
This diff is collapsed.
......@@ -21,8 +21,8 @@
#include <string>
#include <vector>
#include "ngraph/json.hpp"
#include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "nlohmann/json.hpp"
namespace ngraph
{
......
......@@ -90,57 +90,6 @@ static std::shared_ptr<ngraph::Function>
static json write(const ngraph::Function&);
static json write(const ngraph::Node&);
// There should be a map from element type names to element types so deserialization can
// find the singletons and serialization can serialize by name.
static const element::Type& to_ref(const element::Type& t)
{
if (t == element::boolean)
{
return element::boolean;
}
if (t == element::f32)
{
return element::f32;
}
if (t == element::f64)
{
return element::f64;
}
if (t == element::i8)
{
return element::i8;
}
if (t == element::i16)
{
return element::i16;
}
if (t == element::i32)
{
return element::i32;
}
if (t == element::i64)
{
return element::i64;
}
if (t == element::u8)
{
return element::u8;
}
if (t == element::u16)
{
return element::u16;
}
if (t == element::u32)
{
return element::u32;
}
if (t == element::u64)
{
return element::u64;
}
throw runtime_error("type not valid");
}
static json write_element_type(const ngraph::element::Type& n)
{
json j;
......@@ -148,12 +97,12 @@ static json write_element_type(const ngraph::element::Type& n)
return j;
}
static const element::Type& read_element_type(const json& j)
static element::Type read_element_type(const json& j)
{
size_t bitwidth = 0;
bool is_real;
bool is_signed;
string c_type_string;
bool is_real = false;
bool is_signed = false;
string c_type_string = "";
if (j.is_object())
{
bitwidth = j.at("bitwidth").get<size_t>();
......@@ -176,26 +125,7 @@ static const element::Type& read_element_type(const json& j)
}
}
}
return to_ref(element::Type(bitwidth, is_real, is_signed, c_type_string));
}
static json write_tensor_type(const element::Type& element_type, const Shape& shape)
{
json j;
j["element_type"] = write_element_type(element_type);
j["shape"] = shape;
return j;
}
static std::shared_ptr<const TensorViewType>
read_tensor_type(const json& j, const string& type, const string& sshape)
{
const element::Type& et = read_element_type(j.at(type));
Shape shape =
j.count(sshape) > 0
? Shape(j.at(sshape).get<vector<size_t>>())
: Shape{} /*HACK, so we could call read_tensor_type uniformly @ each callsite*/;
return make_shared<TensorViewType>(et, shape);
return element::Type(bitwidth, is_real, is_signed, c_type_string);
}
string ngraph::serialize(shared_ptr<ngraph::Function> func, size_t indent)
......@@ -216,7 +146,7 @@ string ngraph::serialize(shared_ptr<ngraph::Function> func, size_t indent)
}
else
{
rc = j.dump(indent);
rc = j.dump(static_cast<int>(indent));
}
return rc;
}
......@@ -405,14 +335,14 @@ static shared_ptr<ngraph::Function>
{
auto type_node_js =
node_js.count("element_type") == 0 ? node_js.at("value_type") : node_js;
auto& element_type = read_element_type(type_node_js.at("element_type"));
auto element_type = read_element_type(type_node_js.at("element_type"));
auto shape = type_node_js.at("shape");
auto value = node_js.at("value").get<vector<string>>();
node = make_shared<op::Constant>(element_type, shape, value);
}
else if (node_op == "Convert")
{
auto& target_type = read_element_type(node_js.at("target_type"));
auto target_type = read_element_type(node_js.at("target_type"));
node = make_shared<op::Convert>(args[0], target_type);
}
else if (node_op == "Convolution")
......@@ -662,7 +592,7 @@ static shared_ptr<ngraph::Function>
{
auto type_node_js =
node_js.count("element_type") == 0 ? node_js.at("value_type") : node_js;
auto& element_type = read_element_type(type_node_js.at("element_type"));
auto element_type = read_element_type(type_node_js.at("element_type"));
auto shape = type_node_js.at("shape");
node = make_shared<op::Parameter>(element_type, shape);
}
......
......@@ -20,8 +20,8 @@
#include <unordered_map>
#include "ngraph/function.hpp"
#include "ngraph/json.hpp"
#include "ngraph/node.hpp"
#include "nlohmann/json.hpp"
namespace ngraph
{
......
......@@ -37,7 +37,5 @@ if (NGRAPH_CPU_ENABLE)
set(HEADER_SEARCH_DEFINES ${HEADER_SEARCH_DEFINES} "NGRAPH_TBB_ENABLE")
endif()
message("HEADER_SEARCH_DEFINES ${HEADER_SEARCH_DEFINES}")
set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
endif()
......@@ -26,13 +26,14 @@ if (NGRAPH_CPU_ENABLE)
add_executable(nbench ${SRC})
add_dependencies(nbench ngraph)
set(HEADER_SEARCH_DEFINES
"NGRAPH_HEADERS_PATH=\"${NGRAPH_INCLUDE_PATH}\""
)
target_link_libraries(nbench ngraph)
include_directories(SYSTEM ${JSON_INCLUDE_DIR})
set_source_files_properties(nbench.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
endif()
......@@ -178,7 +178,8 @@ endif()
target_link_libraries(unit-test ngraph libgtest pthread)
target_link_libraries(unit-test ${CMAKE_DL_LIBS})
add_dependencies(unit-test ngraph libgtest ext_eigen)
add_dependencies(unit-test ngraph libgtest ext_eigen ext_json)
include_directories(SYSTEM ${JSON_INCLUDE_DIR})
add_custom_target(style-check
COMMAND ${PROJECT_SOURCE_DIR}/maint/check-code-format.sh
......
......@@ -24,7 +24,6 @@
#include "ngraph/file_util.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/json.hpp"
#include "ngraph/log.hpp"
#include "ngraph/ngraph.hpp"
#include "ngraph/ops/relu.hpp"
......@@ -37,6 +36,7 @@
#include "ngraph/runtime/argon/pass/argon_fusion.hpp"
#include "ngraph/serializer.hpp"
#include "ngraph/util.hpp"
#include "nlohmann/json.hpp"
#include "util/matcher.hpp"
#include "util/test_tools.hpp"
......
......@@ -3055,7 +3055,7 @@ TEST(${BACKEND_NAME}, scalar_constant_float32)
auto result = backend->make_primary_tensor_view(element::f32, Shape{});
cf->call({}, {result});
EXPECT_EQ(vector<float>{4.8}, read_vector<float>(result));
EXPECT_EQ(vector<float>{4.8f}, read_vector<float>(result));
}
TEST(${BACKEND_NAME}, scalar_constant_int64)
......@@ -3073,7 +3073,7 @@ TEST(${BACKEND_NAME}, scalar_constant_int64)
auto result = backend->make_primary_tensor_view(element::i64, Shape{});
cf->call({}, {result});
EXPECT_EQ(vector<int64_t>{{2112}}, read_vector<int64_t>(result));
EXPECT_EQ(vector<int64_t>{2112}, read_vector<int64_t>(result));
}
TEST(${BACKEND_NAME}, tensor_constant_float32)
......@@ -3092,7 +3092,7 @@ TEST(${BACKEND_NAME}, tensor_constant_float32)
auto result = backend->make_primary_tensor_view(element::f32, shape);
cf->call({}, {result});
EXPECT_EQ((vector<float>{4.8, 4.7, -5.3, 0}), read_vector<float>(result));
EXPECT_EQ((vector<float>{4.8f, 4.7f, -5.3f, 0.0f}), read_vector<float>(result));
}
TEST(${BACKEND_NAME}, tensor_constant_int64)
......@@ -3514,11 +3514,11 @@ TEST(${BACKEND_NAME}, sum_to_scalar_stable)
// Create some tensors for input/output
auto a = backend->make_primary_tensor_view(element::f32, shape);
copy_data(a, vector<float>{1e-6, -1, 0, 1});
copy_data(a, vector<float>{1e-6f, -1, 0, 1});
auto result = backend->make_primary_tensor_view(element::f32, Shape{});
cf->call({a}, {result});
EXPECT_TRUE(test::all_close(read_vector<float>(result), vector<float>{1e-6}, 5e-2f));
EXPECT_TRUE(test::all_close(read_vector<float>(result), vector<float>{1e-6f}, 5e-2f));
// EXPECT_EQ(vector<float>{1e-6}, read_vector<float>(result));
}
......@@ -3539,13 +3539,13 @@ TEST(${BACKEND_NAME}, sum_3d_to_vector_stable)
// Create some tensors for input/output
auto a = backend->make_primary_tensor_view(element::f32, shape_a);
copy_data(a, vector<float>{1, 1, 1, 1, 1, 1, 1e-4, 1e-5, 1e-6, 1, 1, 1, 1, 1,
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1});
copy_data(a, vector<float>{1, 1, 1, 1, 1, 1, 1e-4f, 1e-5f, 1e-6f, 1, 1, 1, 1, 1,
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1});
auto result = backend->make_primary_tensor_view(element::f32, shape_rt);
cf->call({a}, {result});
EXPECT_TRUE(
test::all_close(read_vector<float>(result), vector<float>{1e-4, 1e-5, 1e-6}, 5e-2f));
test::all_close(read_vector<float>(result), vector<float>{1e-4f, 1e-5f, 1e-6f}, 5e-2f));
}
TEST(${BACKEND_NAME}, sign)
......@@ -3562,7 +3562,7 @@ TEST(${BACKEND_NAME}, sign)
// Create some tensors for input/output
auto a = backend->make_primary_tensor_view(element::f32, shape);
copy_data(a, vector<float>{1, -2, 0, -4.8f, 4.8f, -0.0});
copy_data(a, vector<float>{1, -2, 0, -4.8f, 4.8f, -0.0f});
auto result = backend->make_primary_tensor_view(element::f32, shape);
cf->call({a}, {result});
......
......@@ -24,7 +24,6 @@
#include "ngraph/file_util.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/json.hpp"
#include "ngraph/log.hpp"
#include "ngraph/ngraph.hpp"
#include "ngraph/ops/relu.hpp"
......@@ -36,6 +35,7 @@
#include "ngraph/pattern/op/label.hpp"
#include "ngraph/serializer.hpp"
#include "ngraph/util.hpp"
#include "nlohmann/json.hpp"
#include "util/matcher.hpp"
#include "util/test_tools.hpp"
......
......@@ -33,13 +33,13 @@
#include "ngraph/pattern/op/label.hpp"
//
#include "ngraph/file_util.hpp"
#include "ngraph/json.hpp"
#include "ngraph/pass/reshape_elimination.hpp"
#include "ngraph/pass/visualize_tree.hpp"
#include "ngraph/runtime/cpu/ops/matmul_bias.hpp"
#include "ngraph/runtime/cpu/pass/cpu_fusion.hpp"
#include "ngraph/serializer.hpp"
#include "ngraph/util.hpp"
#include "nlohmann/json.hpp"
#include "util/all_close.hpp"
#include "util/matcher.hpp"
#include "util/test_tools.hpp"
......@@ -201,26 +201,26 @@ TEST(cpu_fusion, batchnorm_fprop_b1c2h2w2)
0.54488319f,
0.42365479f,
0.64589411f,
0.4375872,
0.89177299});
0.4375872f,
0.89177299f});
auto _mean = backend->make_primary_tensor_view(element::f32, mean_shape);
copy_data(_mean, vector<float>{0.60291237, 0.59972727});
copy_data(_mean, vector<float>{0.60291237f, 0.59972727f});
auto _var = backend->make_primary_tensor_view(element::f32, var_shape);
copy_data(_var, vector<float>{0.00472505, 0.03617825});
copy_data(_var, vector<float>{0.00472505f, 0.03617825f});
auto _gamma = backend->make_primary_tensor_view(element::f32, gamma_shape);
copy_data(_gamma, vector<float>{1.0f, 1.0f});
auto _beta = backend->make_primary_tensor_view(element::f32, beta_shape);
copy_data(_beta, vector<float>{0.0f, 0.0f});
auto result = backend->make_primary_tensor_view(element::f32, shape_r);
vector<float> expected_result{-0.71498716,
1.48388731,
-0.00196938,
-0.76693159,
-0.91316032,
0.23943391,
-0.84090298,
1.51462936};
vector<float> expected_result{-0.71498716f,
1.48388731f,
-0.00196938f,
-0.76693159f,
-0.91316032f,
0.23943391f,
-0.84090298f,
1.51462936f};
cf->call({_mean, _var, _input, _gamma, _beta}, {result});
EXPECT_TRUE(test::all_close(expected_result, read_vector<float>(result)));
}
......@@ -255,12 +255,12 @@ TEST(cpu_fusion, batchnorm_fprop_b2c2h2w1)
0.54488319f,
0.42365479f,
0.64589411f,
0.4375872,
0.89177299});
0.4375872f,
0.89177299f});
auto _mean = backend->make_primary_tensor_view(element::f32, mean_shape);
copy_data(_mean, vector<float>{0.60291237, 0.59972727});
copy_data(_mean, vector<float>{0.60291237f, 0.59972727f});
auto _var = backend->make_primary_tensor_view(element::f32, var_shape);
copy_data(_var, vector<float>{0.00472505, 0.03617825});
copy_data(_var, vector<float>{0.00472505f, 0.03617825f});
auto _gamma = backend->make_primary_tensor_view(element::f32, gamma_shape);
copy_data(_gamma, vector<float>{1.0f, 1.0f});
auto _beta = backend->make_primary_tensor_view(element::f32, beta_shape);
......@@ -268,7 +268,7 @@ TEST(cpu_fusion, batchnorm_fprop_b2c2h2w1)
auto result = backend->make_primary_tensor_view(element::f32, shape_r);
vector<float> expected_result{
-0.714987, 1.48389, 0.015746, -0.284436, -2.36912, 0.56806, -0.840903, 1.51463};
-0.714987f, 1.48389f, 0.015746f, -0.284436f, -2.36912f, 0.56806f, -0.840903f, 1.51463f};
cf->call({_mean, _var, _input, _gamma, _beta}, {result});
EXPECT_TRUE(test::all_close(expected_result, read_vector<float>(result)));
}
......
......@@ -23,7 +23,6 @@
#include "gtest/gtest.h"
#include "ngraph/file_util.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/json.hpp"
#include "ngraph/log.hpp"
#include "ngraph/ngraph.hpp"
#include "ngraph/ops/sum.hpp"
......@@ -35,6 +34,7 @@
#include "ngraph/pattern/op/label.hpp"
#include "ngraph/serializer.hpp"
#include "ngraph/util.hpp"
#include "nlohmann/json.hpp"
#include "util/matcher.hpp"
#include "util/test_tools.hpp"
......
......@@ -20,10 +20,10 @@
#include "gtest/gtest.h"
#include "ngraph/file_util.hpp"
#include "ngraph/json.hpp"
#include "ngraph/ngraph.hpp"
#include "ngraph/serializer.hpp"
#include "ngraph/util.hpp"
#include "nlohmann/json.hpp"
#include "util/test_tools.hpp"
using namespace std;
......@@ -60,8 +60,8 @@ TEST(serialize, main)
string js = serialize(h, 4);
{
ofstream f("serialize_function.js");
f << js;
ofstream out("serialize_function.js");
out << js;
}
istringstream in(js);
......
......@@ -36,8 +36,8 @@ namespace ngraph
template <typename T>
bool all_close(const std::vector<T>& a,
const std::vector<T>& b,
T rtol = 1e-5f,
T atol = 1e-8f)
T rtol = static_cast<T>(1e-5),
T atol = static_cast<T>(1e-8))
{
assert(a.size() == b.size());
for (size_t i = 0; i < a.size(); ++i)
......
......@@ -19,6 +19,7 @@ if(NOT DEFINED EXTERNAL_PROJECTS_ROOT)
endif()
include( ../cmake/external_gtest.cmake )
include( ../cmake/external_json.cmake )
include( ../cmake/external_eigen.cmake )
include( ../cmake/external_mkldnn.cmake )
if (NGRAPH_USE_PREBUILT_LLVM OR DEFINED LLVM_TARBALL_URL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment