Unverified Commit 97c9cf9d authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

Normalize line endings (#1649)

* set global line ending options for repo

* Normalize line endings

* add newline at eof
parent 54403cdc
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.cpp text
*.hpp text
//***************************************************************************** //*****************************************************************************
// Copyright 2017-2018 Intel Corporation // Copyright 2017-2018 Intel Corporation
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include "ngraph/op/lrn.hpp" #include "ngraph/op/lrn.hpp"
#include "ngraph/runtime/cpu/cpu_builder.hpp" #include "ngraph/runtime/cpu/cpu_builder.hpp"
#include "ngraph/runtime/cpu/mkldnn_invoke.hpp" #include "ngraph/runtime/cpu/mkldnn_invoke.hpp"
#include "ngraph/runtime/cpu/mkldnn_utils.hpp" #include "ngraph/runtime/cpu/mkldnn_utils.hpp"
#include "ngraph/runtime/reference/lrn.hpp" #include "ngraph/runtime/reference/lrn.hpp"
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
namespace ngraph namespace ngraph
{ {
namespace runtime namespace runtime
{ {
namespace cpu namespace cpu
{ {
template <> template <>
void Builder::BUILDER_DECL(ngraph::op::LRN) void Builder::BUILDER_DECL(ngraph::op::LRN)
{ {
auto& functors = external_function->get_functors(); auto& functors = external_function->get_functors();
const ngraph::op::LRN* lrn = static_cast<const ngraph::op::LRN*>(node); const ngraph::op::LRN* lrn = static_cast<const ngraph::op::LRN*>(node);
function<void(CPURuntimeContext*)> functor; function<void(CPURuntimeContext*)> functor;
auto& arg_tensor = external_function->get_tensor_data(args[0].get_name()); auto& arg_tensor = external_function->get_tensor_data(args[0].get_name());
auto& out_tensor = external_function->get_tensor_data(out[0].get_name()); auto& out_tensor = external_function->get_tensor_data(out[0].get_name());
if (runtime::cpu::mkldnn_utils::use_mkldnn_kernel(node)) if (runtime::cpu::mkldnn_utils::use_mkldnn_kernel(node))
{ {
auto& mkldnn_emitter = external_function->get_mkldnn_emitter(); auto& mkldnn_emitter = external_function->get_mkldnn_emitter();
auto input_data_desc = mkldnn_utils::get_input_mkldnn_md(node, 0); auto input_data_desc = mkldnn_utils::get_input_mkldnn_md(node, 0);
auto result_desc = mkldnn_utils::get_output_mkldnn_md(node, 0); auto result_desc = mkldnn_utils::get_output_mkldnn_md(node, 0);
auto lrn_index = auto lrn_index =
mkldnn_emitter->build_lrn_forward(input_data_desc, mkldnn_emitter->build_lrn_forward(input_data_desc,
result_desc, result_desc,
static_cast<float>(lrn->get_alpha()), static_cast<float>(lrn->get_alpha()),
static_cast<float>(lrn->get_beta()), static_cast<float>(lrn->get_beta()),
static_cast<float>(lrn->get_bias()), static_cast<float>(lrn->get_bias()),
static_cast<int>(lrn->get_nsize())); static_cast<int>(lrn->get_nsize()));
auto& deps = mkldnn_emitter->get_primitive_deps(lrn_index); auto& deps = mkldnn_emitter->get_primitive_deps(lrn_index);
functor = [&, lrn_index](CPURuntimeContext* ctx) { functor = [&, lrn_index](CPURuntimeContext* ctx) {
cpu::mkldnn_utils::set_memory_ptr(ctx, deps[0], arg_tensor); cpu::mkldnn_utils::set_memory_ptr(ctx, deps[0], arg_tensor);
cpu::mkldnn_utils::set_memory_ptr(ctx, deps[1], out_tensor); cpu::mkldnn_utils::set_memory_ptr(ctx, deps[1], out_tensor);
cpu::mkldnn_utils::mkldnn_invoke_primitive(ctx, lrn_index); cpu::mkldnn_utils::mkldnn_invoke_primitive(ctx, lrn_index);
}; };
} }
else else
{ {
double alpha = lrn->get_alpha(); double alpha = lrn->get_alpha();
double beta = lrn->get_beta(); double beta = lrn->get_beta();
double bias = lrn->get_bias(); double bias = lrn->get_bias();
double nsize = lrn->get_nsize(); double nsize = lrn->get_nsize();
Shape arg_shape = args[0].get_shape(); Shape arg_shape = args[0].get_shape();
auto element_type = lrn->get_element_type(); auto element_type = lrn->get_element_type();
if (element_type == element::f32) if (element_type == element::f32)
{ {
functor = [&, alpha, beta, bias, arg_shape, nsize](CPURuntimeContext* ctx) { functor = [&, alpha, beta, bias, arg_shape, nsize](CPURuntimeContext* ctx) {
ngraph::runtime::reference::lrn<float>(static_cast<float*>(arg_tensor), ngraph::runtime::reference::lrn<float>(static_cast<float*>(arg_tensor),
static_cast<float*>(out_tensor), static_cast<float*>(out_tensor),
arg_shape, arg_shape,
alpha, alpha,
beta, beta,
bias, bias,
nsize); nsize);
}; };
} }
else if (element_type == element::f64) else if (element_type == element::f64)
{ {
functor = [&, alpha, beta, bias, arg_shape, nsize](CPURuntimeContext* ctx) { functor = [&, alpha, beta, bias, arg_shape, nsize](CPURuntimeContext* ctx) {
ngraph::runtime::reference::lrn<double>( ngraph::runtime::reference::lrn<double>(
static_cast<double*>(arg_tensor), static_cast<double*>(arg_tensor),
static_cast<double*>(out_tensor), static_cast<double*>(out_tensor),
arg_shape, arg_shape,
alpha, alpha,
beta, beta,
bias, bias,
nsize); nsize);
}; };
} }
else else
{ {
throw ngraph_error("Unsupported type in CPU Builder for LRN"); throw ngraph_error("Unsupported type in CPU Builder for LRN");
} }
} }
functors.emplace_back(functor); functors.emplace_back(functor);
} }
REGISTER_OP_BUILDER(LRN); REGISTER_OP_BUILDER(LRN);
} }
} }
} }
//***************************************************************************** //*****************************************************************************
// Copyright 2017-2018 Intel Corporation // Copyright 2017-2018 Intel Corporation
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#pragma once #pragma once
#include <array> #include <array>
#include <cstring> #include <cstring>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <random> #include <random>
#include <sstream> #include <sstream>
#include <string> #include <string>
static std::mt19937_64 random_generator; static std::mt19937_64 random_generator;
namespace ngraph namespace ngraph
{ {
class uuid_type; class uuid_type;
} }
class ngraph::uuid_type class ngraph::uuid_type
{ {
public: public:
uuid_type() uuid_type()
{ {
m_data[0] = random_generator(); m_data[0] = random_generator();
m_data[1] = random_generator(); m_data[1] = random_generator();
uint8_t* p = reinterpret_cast<uint8_t*>(m_data); uint8_t* p = reinterpret_cast<uint8_t*>(m_data);
p[6] = (p[6] & 0x0F) | 0x40; p[6] = (p[6] & 0x0F) | 0x40;
p[8] = (p[8] & 0x3F) | 0x80; p[8] = (p[8] & 0x3F) | 0x80;
} }
std::string to_string() const std::string to_string() const
{ {
std::stringstream ss; std::stringstream ss;
const uint8_t* p = reinterpret_cast<const uint8_t*>(m_data); const uint8_t* p = reinterpret_cast<const uint8_t*>(m_data);
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++); ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++);
} }
ss << "-"; ss << "-";
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++); ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++);
} }
ss << "-"; ss << "-";
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++); ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++);
} }
ss << "-"; ss << "-";
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++); ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++);
} }
ss << "-"; ss << "-";
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++); ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*p++);
} }
return ss.str(); return ss.str();
} }
static uuid_type zero() static uuid_type zero()
{ {
uuid_type rc; uuid_type rc;
rc.m_data[0] = 0; rc.m_data[0] = 0;
rc.m_data[1] = 0; rc.m_data[1] = 0;
return rc; return rc;
} }
bool operator==(const uuid_type& other) const { return memcmp(m_data, other.m_data, 16) == 0; } bool operator==(const uuid_type& other) const { return memcmp(m_data, other.m_data, 16) == 0; }
bool operator!=(const uuid_type& other) const { return !(*this == other); } bool operator!=(const uuid_type& other) const { return !(*this == other); }
friend std::ostream& operator<<(std::ostream& out, const uuid_type& id) friend std::ostream& operator<<(std::ostream& out, const uuid_type& id)
{ {
out << id.to_string(); out << id.to_string();
return out; return out;
} }
private: private:
uint64_t m_data[2]; uint64_t m_data[2];
}; };
//***************************************************************************** //*****************************************************************************
// Copyright 2017-2018 Intel Corporation // Copyright 2017-2018 Intel Corporation
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "ngraph/log.hpp" #include "ngraph/log.hpp"
#include "ngraph/ngraph.hpp" #include "ngraph/ngraph.hpp"
#include "ngraph/pass/dump_sorted.hpp" #include "ngraph/pass/dump_sorted.hpp"
#include "ngraph/pass/liveness.hpp" #include "ngraph/pass/liveness.hpp"
#include "ngraph/pass/liveness.hpp" #include "ngraph/pass/liveness.hpp"
#include "ngraph/pass/manager.hpp" #include "ngraph/pass/manager.hpp"
#include "ngraph/pass/visualize_tree.hpp" #include "ngraph/pass/visualize_tree.hpp"
#include "util/test_tools.hpp" #include "util/test_tools.hpp"
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
namespace ng = ngraph; namespace ng = ngraph;
TEST(liveness, constant) TEST(liveness, constant)
{ {
Shape shape{1}; Shape shape{1};
auto c = op::Constant::create(element::i32, shape, {5}); auto c = op::Constant::create(element::i32, shape, {5});
auto f = make_shared<Function>(make_shared<op::Negative>(c), op::ParameterVector{}); auto f = make_shared<Function>(make_shared<op::Negative>(c), op::ParameterVector{});
pass::Manager pass_manager; pass::Manager pass_manager;
pass_manager.register_pass<pass::Liveness>(); pass_manager.register_pass<pass::Liveness>();
pass_manager.run_passes(f); pass_manager.run_passes(f);
auto tmp = f->get_ordered_ops(); auto tmp = f->get_ordered_ops();
vector<shared_ptr<Node>> sorted{tmp.begin(), tmp.end()}; vector<shared_ptr<Node>> sorted{tmp.begin(), tmp.end()};
ASSERT_EQ(3, sorted.size()); ASSERT_EQ(3, sorted.size());
EXPECT_EQ(0, sorted[0]->liveness_new_list.size()); EXPECT_EQ(0, sorted[0]->liveness_new_list.size());
EXPECT_EQ(0, sorted[0]->liveness_free_list.size()); EXPECT_EQ(0, sorted[0]->liveness_free_list.size());
// op::Negative is live on output to op::Result // op::Negative is live on output to op::Result
// op::Negative is new // op::Negative is new
EXPECT_EQ(1, sorted[1]->liveness_new_list.size()); EXPECT_EQ(1, sorted[1]->liveness_new_list.size());
EXPECT_EQ(0, sorted[1]->liveness_free_list.size()); EXPECT_EQ(0, sorted[1]->liveness_free_list.size());
// op::Negative is live on input to op::Result // op::Negative is live on input to op::Result
EXPECT_EQ(0, sorted[2]->liveness_new_list.size()); EXPECT_EQ(0, sorted[2]->liveness_new_list.size());
// op::Negative is freed // op::Negative is freed
EXPECT_EQ(1, sorted[2]->liveness_free_list.size()); EXPECT_EQ(1, sorted[2]->liveness_free_list.size());
} }
//***************************************************************************** //*****************************************************************************
// Copyright 2017-2018 Intel Corporation // Copyright 2017-2018 Intel Corporation
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "ngraph/ngraph.hpp" #include "ngraph/ngraph.hpp"
#include "ngraph/pass/dump_sorted.hpp" #include "ngraph/pass/dump_sorted.hpp"
#include "ngraph/pass/liveness.hpp" #include "ngraph/pass/liveness.hpp"
#include "ngraph/pass/liveness.hpp" #include "ngraph/pass/liveness.hpp"
#include "ngraph/pass/manager.hpp" #include "ngraph/pass/manager.hpp"
#include "ngraph/pass/memory_layout.hpp" #include "ngraph/pass/memory_layout.hpp"
#include "ngraph/pass/visualize_tree.hpp" #include "ngraph/pass/visualize_tree.hpp"
#include "util/test_tools.hpp" #include "util/test_tools.hpp"
using namespace ngraph; using namespace ngraph;
using namespace std; using namespace std;
static vector<pass::MemoryManager::node> get_node_list(const pass::MemoryManager& mm) static vector<pass::MemoryManager::node> get_node_list(const pass::MemoryManager& mm)
{ {
vector<pass::MemoryManager::node> rc; vector<pass::MemoryManager::node> rc;
rc.insert(rc.end(), mm.begin(), mm.end()); rc.insert(rc.end(), mm.begin(), mm.end());
return rc; return rc;
} }
TEST(memory_manager, allocate) TEST(memory_manager, allocate)
{ {
pass::MemoryManager mm{1}; pass::MemoryManager mm{1};
// Special case, allocating size zero bumps the size of the alloc up to the alignment size // Special case, allocating size zero bumps the size of the alloc up to the alignment size
EXPECT_EQ(0, mm.allocate(0)); EXPECT_EQ(0, mm.allocate(0));
EXPECT_EQ(1, mm.allocate(10)); EXPECT_EQ(1, mm.allocate(10));
EXPECT_EQ(11, mm.allocate(10)); EXPECT_EQ(11, mm.allocate(10));
EXPECT_EQ(21, mm.allocate(10)); EXPECT_EQ(21, mm.allocate(10));
} }
TEST(memory_manager, free_first_allocated) TEST(memory_manager, free_first_allocated)
{ {
pass::MemoryManager mm{1}; pass::MemoryManager mm{1};
EXPECT_EQ(0, mm.allocate(10)); EXPECT_EQ(0, mm.allocate(10));
EXPECT_EQ(10, mm.allocate(10)); EXPECT_EQ(10, mm.allocate(10));
EXPECT_EQ(3, mm.get_node_list().size()); EXPECT_EQ(3, mm.get_node_list().size());
mm.free(0); mm.free(0);
auto node_list = get_node_list(mm); auto node_list = get_node_list(mm);
EXPECT_EQ(3, node_list.size()); EXPECT_EQ(3, node_list.size());
EXPECT_TRUE(node_list[0].is_free()); EXPECT_TRUE(node_list[0].is_free());
EXPECT_FALSE(node_list[1].is_free()); EXPECT_FALSE(node_list[1].is_free());
EXPECT_TRUE(node_list[2].is_free()); EXPECT_TRUE(node_list[2].is_free());
} }
TEST(memory_manager, free_middle_allocated) TEST(memory_manager, free_middle_allocated)
{ {
pass::MemoryManager mm{1}; pass::MemoryManager mm{1};
EXPECT_EQ(0, mm.allocate(10)); EXPECT_EQ(0, mm.allocate(10));
EXPECT_EQ(10, mm.allocate(10)); EXPECT_EQ(10, mm.allocate(10));
EXPECT_EQ(20, mm.allocate(10)); EXPECT_EQ(20, mm.allocate(10));
EXPECT_EQ(30, mm.allocate(10)); EXPECT_EQ(30, mm.allocate(10));
EXPECT_EQ(40, mm.allocate(10)); EXPECT_EQ(40, mm.allocate(10));
EXPECT_EQ(6, mm.get_node_list().size()); EXPECT_EQ(6, mm.get_node_list().size());
mm.free(10); mm.free(10);
auto node_list = get_node_list(mm); auto node_list = get_node_list(mm);
EXPECT_EQ(6, node_list.size()); EXPECT_EQ(6, node_list.size());
EXPECT_FALSE(node_list[0].is_free()); EXPECT_FALSE(node_list[0].is_free());
EXPECT_TRUE(node_list[1].is_free()); EXPECT_TRUE(node_list[1].is_free());
EXPECT_FALSE(node_list[2].is_free()); EXPECT_FALSE(node_list[2].is_free());
EXPECT_FALSE(node_list[3].is_free()); EXPECT_FALSE(node_list[3].is_free());
EXPECT_FALSE(node_list[4].is_free()); EXPECT_FALSE(node_list[4].is_free());
} }
TEST(memory_manager, free_last_allocated) TEST(memory_manager, free_last_allocated)
{ {
pass::MemoryManager mm{1}; pass::MemoryManager mm{1};
EXPECT_EQ(0, mm.allocate(10)); EXPECT_EQ(0, mm.allocate(10));
EXPECT_EQ(10, mm.allocate(10)); EXPECT_EQ(10, mm.allocate(10));
EXPECT_EQ(20, mm.allocate(10)); EXPECT_EQ(20, mm.allocate(10));
EXPECT_EQ(30, mm.allocate(10)); EXPECT_EQ(30, mm.allocate(10));
EXPECT_EQ(40, mm.allocate(10)); EXPECT_EQ(40, mm.allocate(10));
EXPECT_EQ(6, mm.get_node_list().size()); EXPECT_EQ(6, mm.get_node_list().size());
mm.free(40); mm.free(40);
auto node_list = get_node_list(mm); auto node_list = get_node_list(mm);
EXPECT_EQ(5, node_list.size()); EXPECT_EQ(5, node_list.size());
EXPECT_FALSE(node_list[0].is_free()); EXPECT_FALSE(node_list[0].is_free());
EXPECT_FALSE(node_list[1].is_free()); EXPECT_FALSE(node_list[1].is_free());
EXPECT_FALSE(node_list[2].is_free()); EXPECT_FALSE(node_list[2].is_free());
EXPECT_FALSE(node_list[3].is_free()); EXPECT_FALSE(node_list[3].is_free());
EXPECT_TRUE(node_list[4].is_free()); EXPECT_TRUE(node_list[4].is_free());
} }
TEST(memory_manager, free_first_free) TEST(memory_manager, free_first_free)
{ {
pass::MemoryManager mm{1}; pass::MemoryManager mm{1};
EXPECT_EQ(0, mm.allocate(10)); EXPECT_EQ(0, mm.allocate(10));
EXPECT_EQ(10, mm.allocate(10)); EXPECT_EQ(10, mm.allocate(10));
EXPECT_EQ(20, mm.allocate(10)); EXPECT_EQ(20, mm.allocate(10));
EXPECT_EQ(30, mm.allocate(10)); EXPECT_EQ(30, mm.allocate(10));
EXPECT_EQ(40, mm.allocate(10)); EXPECT_EQ(40, mm.allocate(10));
EXPECT_EQ(6, mm.get_node_list().size()); EXPECT_EQ(6, mm.get_node_list().size());
mm.free(10); mm.free(10);
mm.free(0); mm.free(0);
auto node_list = get_node_list(mm); auto node_list = get_node_list(mm);
EXPECT_EQ(5, node_list.size()); EXPECT_EQ(5, node_list.size());
EXPECT_TRUE(node_list[0].is_free()); EXPECT_TRUE(node_list[0].is_free());
EXPECT_FALSE(node_list[1].is_free()); EXPECT_FALSE(node_list[1].is_free());
EXPECT_FALSE(node_list[2].is_free()); EXPECT_FALSE(node_list[2].is_free());
EXPECT_FALSE(node_list[3].is_free()); EXPECT_FALSE(node_list[3].is_free());
} }
TEST(memory_manager, free_middle_free) TEST(memory_manager, free_middle_free)
{ {
pass::MemoryManager mm{1}; pass::MemoryManager mm{1};
EXPECT_EQ(0, mm.allocate(10)); EXPECT_EQ(0, mm.allocate(10));
EXPECT_EQ(10, mm.allocate(10)); EXPECT_EQ(10, mm.allocate(10));
EXPECT_EQ(20, mm.allocate(10)); EXPECT_EQ(20, mm.allocate(10));
EXPECT_EQ(30, mm.allocate(10)); EXPECT_EQ(30, mm.allocate(10));
EXPECT_EQ(40, mm.allocate(10)); EXPECT_EQ(40, mm.allocate(10));
EXPECT_EQ(6, mm.get_node_list().size()); EXPECT_EQ(6, mm.get_node_list().size());
mm.free(0); mm.free(0);
mm.free(20); mm.free(20);
mm.free(10); mm.free(10);
auto node_list = get_node_list(mm); auto node_list = get_node_list(mm);
EXPECT_EQ(4, node_list.size()); EXPECT_EQ(4, node_list.size());
EXPECT_TRUE(node_list[0].is_free()); EXPECT_TRUE(node_list[0].is_free());
EXPECT_FALSE(node_list[1].is_free()); EXPECT_FALSE(node_list[1].is_free());
EXPECT_FALSE(node_list[2].is_free()); EXPECT_FALSE(node_list[2].is_free());
} }
TEST(memory_manager, max_allocated) TEST(memory_manager, max_allocated)
{ {
pass::MemoryManager mm{1}; pass::MemoryManager mm{1};
EXPECT_EQ(0, mm.allocate(10)); EXPECT_EQ(0, mm.allocate(10));
EXPECT_EQ(10, mm.allocate(10)); EXPECT_EQ(10, mm.allocate(10));
EXPECT_EQ(20, mm.allocate(10)); EXPECT_EQ(20, mm.allocate(10));
EXPECT_EQ(30, mm.allocate(10)); EXPECT_EQ(30, mm.allocate(10));
EXPECT_EQ(40, mm.allocate(10)); EXPECT_EQ(40, mm.allocate(10));
EXPECT_EQ(6, mm.get_node_list().size()); EXPECT_EQ(6, mm.get_node_list().size());
mm.free(0); mm.free(0);
mm.free(20); mm.free(20);
mm.free(10); mm.free(10);
EXPECT_EQ(mm.max_allocated(), 50); EXPECT_EQ(mm.max_allocated(), 50);
} }
TEST(memory_manager, bad_free) TEST(memory_manager, bad_free)
{ {
pass::MemoryManager mm{1}; pass::MemoryManager mm{1};
EXPECT_THROW(mm.free(10), std::runtime_error); EXPECT_THROW(mm.free(10), std::runtime_error);
} }
TEST(memory_manager, align) TEST(memory_manager, align)
{ {
EXPECT_EQ(8, pass::MemoryManager::align(0, 8)); EXPECT_EQ(8, pass::MemoryManager::align(0, 8));
EXPECT_EQ(8, pass::MemoryManager::align(1, 8)); EXPECT_EQ(8, pass::MemoryManager::align(1, 8));
EXPECT_EQ(8, pass::MemoryManager::align(2, 8)); EXPECT_EQ(8, pass::MemoryManager::align(2, 8));
EXPECT_EQ(8, pass::MemoryManager::align(3, 8)); EXPECT_EQ(8, pass::MemoryManager::align(3, 8));
EXPECT_EQ(8, pass::MemoryManager::align(4, 8)); EXPECT_EQ(8, pass::MemoryManager::align(4, 8));
EXPECT_EQ(8, pass::MemoryManager::align(5, 8)); EXPECT_EQ(8, pass::MemoryManager::align(5, 8));
EXPECT_EQ(8, pass::MemoryManager::align(6, 8)); EXPECT_EQ(8, pass::MemoryManager::align(6, 8));
EXPECT_EQ(8, pass::MemoryManager::align(7, 8)); EXPECT_EQ(8, pass::MemoryManager::align(7, 8));
EXPECT_EQ(8, pass::MemoryManager::align(8, 8)); EXPECT_EQ(8, pass::MemoryManager::align(8, 8));
EXPECT_EQ(16, pass::MemoryManager::align(9, 8)); EXPECT_EQ(16, pass::MemoryManager::align(9, 8));
} }
TEST(memory_manager, memory_align) TEST(memory_manager, memory_align)
{ {
pass::MemoryManager mm{64}; pass::MemoryManager mm{64};
EXPECT_EQ(0, mm.allocate(4)); EXPECT_EQ(0, mm.allocate(4));
EXPECT_EQ(64, mm.allocate(4)); EXPECT_EQ(64, mm.allocate(4));
EXPECT_EQ(128, mm.allocate(4)); EXPECT_EQ(128, mm.allocate(4));
} }
TEST(memory_layout, basic) TEST(memory_layout, basic)
{ {
string dump_file = "memory_layout.txt"; string dump_file = "memory_layout.txt";
pass::Manager pass_manager; pass::Manager pass_manager;
pass_manager.register_pass<pass::Liveness>(); pass_manager.register_pass<pass::Liveness>();
pass_manager.register_pass<pass::MemoryLayout>(); pass_manager.register_pass<pass::MemoryLayout>();
pass_manager.register_pass<pass::DumpSorted>(dump_file); pass_manager.register_pass<pass::DumpSorted>(dump_file);
auto graph = make_test_graph(); auto graph = make_test_graph();
pass_manager.run_passes(graph); pass_manager.run_passes(graph);
auto sorted = graph->get_ordered_ops(); auto sorted = graph->get_ordered_ops();
size_t temporary_pool_size = graph->get_temporary_pool_size(); size_t temporary_pool_size = graph->get_temporary_pool_size();
EXPECT_EQ(12, temporary_pool_size); EXPECT_EQ(12, temporary_pool_size);
} }
TEST(memory_layout, constant) TEST(memory_layout, constant)
{ {
string dump_file = "constant.txt"; string dump_file = "constant.txt";
pass::Manager pass_manager; pass::Manager pass_manager;
pass_manager.register_pass<pass::Liveness>(); pass_manager.register_pass<pass::Liveness>();
pass_manager.register_pass<pass::MemoryLayout>(); pass_manager.register_pass<pass::MemoryLayout>();
pass_manager.register_pass<pass::DumpSorted>(dump_file); pass_manager.register_pass<pass::DumpSorted>(dump_file);
Shape shape{1}; Shape shape{1};
auto c = op::Constant::create(element::i32, shape, {5}); auto c = op::Constant::create(element::i32, shape, {5});
auto f = make_shared<Function>(make_shared<op::Negative>(c), op::ParameterVector{}); auto f = make_shared<Function>(make_shared<op::Negative>(c), op::ParameterVector{});
pass_manager.run_passes(f); pass_manager.run_passes(f);
auto sorted = f->get_ordered_ops(); auto sorted = f->get_ordered_ops();
size_t temporary_pool_size = f->get_temporary_pool_size(); size_t temporary_pool_size = f->get_temporary_pool_size();
EXPECT_EQ(4, temporary_pool_size); EXPECT_EQ(4, temporary_pool_size);
} }
//***************************************************************************** //*****************************************************************************
// Copyright 2017-2018 Intel Corporation // Copyright 2017-2018 Intel Corporation
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "ngraph/uuid.hpp" #include "ngraph/uuid.hpp"
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
TEST(uuid, zero) TEST(uuid, zero)
{ {
uuid_type zero = uuid_type::zero(); uuid_type zero = uuid_type::zero();
stringstream ss; stringstream ss;
ss << zero; ss << zero;
std::string expected = "00000000-0000-0000-0000-000000000000"; std::string expected = "00000000-0000-0000-0000-000000000000";
EXPECT_STREQ(expected.c_str(), ss.str().c_str()); EXPECT_STREQ(expected.c_str(), ss.str().c_str());
} }
TEST(uuid, eq) TEST(uuid, eq)
{ {
uuid_type z1 = uuid_type::zero(); uuid_type z1 = uuid_type::zero();
uuid_type z2 = uuid_type::zero(); uuid_type z2 = uuid_type::zero();
EXPECT_EQ(z1, z2); EXPECT_EQ(z1, z2);
} }
TEST(uuid, ne) TEST(uuid, ne)
{ {
uuid_type u1; uuid_type u1;
uuid_type u2; uuid_type u2;
EXPECT_NE(u1, u2); EXPECT_NE(u1, u2);
} }
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