diff --git a/ngraph/core/include/ngraph/file_util.hpp b/ngraph/core/include/ngraph/file_util.hpp index 4a08fe45677..b589d62df53 100644 --- a/ngraph/core/include/ngraph/file_util.hpp +++ b/ngraph/core/include/ngraph/file_util.hpp @@ -54,44 +54,6 @@ namespace ngraph const std::string& s3, const std::string& s4); - /// \brief Returns the size in bytes of filename - /// \param filename The name of the file - NGRAPH_API - size_t get_file_size(const std::string& filename); - - /// \brief Removes all files and directories starting at dir - /// \param dir The path of the directory to remove - NGRAPH_API - void remove_directory(const std::string& dir); - - /// \brief Create a directory - /// \param dir Path of the directory to create - /// \return true if the directory was created, false otherwise - NGRAPH_API - bool make_directory(const std::string& dir); - - /// \brief Gets the path of the system temporary directory - /// \return the path to the system temporary directory - NGRAPH_API - std::string get_temp_directory_path(); - - /// \brief Removes a file from the filesystem - /// \param file The path to the file to be removed - NGRAPH_API - void remove_file(const std::string& file); - - /// \brief Reads the contents of a file - /// \param path The path of the file to read - /// \return vector of the file's contents - NGRAPH_API - std::vector read_file_contents(const std::string& path); - - /// \brief Reads the contents of a file - /// \param path The path of the file to read - /// \return string of the file's contents - NGRAPH_API - std::string read_file_to_string(const std::string& path); - /// \brief Iterate through files and optionally directories. Symbolic links are skipped. /// \param path The path to iterate over /// \param func A callback function called with each file or directory encountered @@ -101,17 +63,5 @@ namespace ngraph std::function func, bool recurse = false, bool include_links = false); - - /// \brief Create a temporary file - /// \param extension Optional extension for the temporary file - /// \return Name of the temporary file - NGRAPH_API - std::string tmp_filename(const std::string& extension = ""); - - /// \brief Test for the existence of a path or file - /// \param path The path to test - /// \return true if the path exists, false otherwise - NGRAPH_API - bool exists(const std::string& path); } } diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/detection_output.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/detection_output.hpp index 8379d79a51b..d2499be7cf4 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/detection_output.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/detection_output.hpp @@ -563,8 +563,12 @@ namespace ngraph { continue; } + if (confScores.find(c) == confScores.end()) + continue; const std::vector& scores = confScores.find(c)->second; int label = attrs.share_location ? -1 : c; + if (decodeBboxesImage.find(label) == decodeBboxesImage.end()) + continue; const std::vector& bboxes = decodeBboxesImage.find(label)->second; caffeNMS(bboxes, scores, indices[c]); @@ -585,6 +589,8 @@ namespace ngraph { int label = it->first; const std::vector& labelIndices = it->second; + if (confScores.find(label) == confScores.end()) + continue; const std::vector& scores = confScores.find(label)->second; for (int j = 0; j < labelIndices.size(); ++j) @@ -625,6 +631,8 @@ namespace ngraph int label = it->first; const std::vector& scores = confScores.find(label)->second; int loc_label = attrs.share_location ? -1 : label; + if (decodeBboxesImage.find(loc_label) == decodeBboxesImage.end()) + continue; const std::vector& bboxes = decodeBboxesImage.find(loc_label)->second; std::vector& indices = it->second; diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/gather_nd.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/gather_nd.hpp index a596098958c..e21f4f700bc 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/gather_nd.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/gather_nd.hpp @@ -94,6 +94,8 @@ namespace ngraph params_end_corner, params_strides, params_axis_order); + if (out_coord_iter == out_transform.end()) + break; auto out_index = out_transform.index(*out_coord_iter); for (const Coordinate& params_coord : params_transform) { diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp index 6cd65693336..28f94035db0 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp @@ -283,7 +283,7 @@ namespace ngraph struct LinearModeInnerIterationResult { bool condition; - float w; + float w = 0; Coordinate inner_coord; }; diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/matmul.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/matmul.hpp index 6ee0d3146ca..4ac53903299 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/matmul.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/matmul.hpp @@ -146,13 +146,14 @@ namespace ngraph // Inputs are 2D and below, perform dot directly if (arg0_rank <= 2 && arg1_rank <= 2) { - return dot(arg0_update, - arg1_update, - out, - wip_arg0_shape, - wip_arg1_shape, - out_shape, - 1); + dot(arg0_update, + arg1_update, + out, + wip_arg0_shape, + wip_arg1_shape, + out_shape, + 1); + return; } // Check and perform auto-broadcast if needed diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/replace_slice.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/replace_slice.hpp index 6cf444fd6c5..1580dbcad71 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/replace_slice.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/replace_slice.hpp @@ -57,6 +57,8 @@ namespace ngraph for (const Coordinate& input_coord : input_transform) { + if (output_it == output_transform.end()) + break; const Coordinate& output_coord = *output_it; out[output_transform.index(output_coord)] = diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp index f8d00b17ebf..c79a6a91a5e 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp @@ -89,6 +89,8 @@ namespace ngraph // Define the CoordinateTransform for updates coordinates. // All except indices-dimensions. + if (updates_indices_coord_iter == updates_indices_transform.end()) + break; Coordinate updates_update_start_corner = *updates_indices_coord_iter; Coordinate updates_update_end_corner(updates_shape); for (size_t i = 0; i < indices_ndim; ++i) @@ -105,6 +107,8 @@ namespace ngraph auto updates_update_coord_iter = updates_update_transform.begin(); for (const Coordinate& out_cord : out_transform) { + if (updates_update_coord_iter == updates_update_transform.end()) + break; const auto src_idx = updates_update_transform.index(*updates_update_coord_iter) * elem_size; std::copy(updates + src_idx, diff --git a/ngraph/core/reference/src/runtime/reference/pad.cpp b/ngraph/core/reference/src/runtime/reference/pad.cpp index 95274324fab..2f441beef95 100644 --- a/ngraph/core/reference/src/runtime/reference/pad.cpp +++ b/ngraph/core/reference/src/runtime/reference/pad.cpp @@ -64,6 +64,8 @@ namespace ngraph for (const Coordinate& in_coord : input_transform) { + if (output_it == output_transform.end()) + break; const Coordinate& out_coord = *output_it; std::fill(v.begin(), v.end(), 0); diff --git a/ngraph/core/reference/src/runtime/reference/reshape.cpp b/ngraph/core/reference/src/runtime/reference/reshape.cpp index 5872ee3e77e..a9c06e81942 100644 --- a/ngraph/core/reference/src/runtime/reference/reshape.cpp +++ b/ngraph/core/reference/src/runtime/reference/reshape.cpp @@ -46,6 +46,8 @@ void runtime::reference::reshape(const char* arg, for (const Coordinate& input_coord : input_transform) { + if (output_it == output_transform.end()) + break; const Coordinate& output_coord = *output_it; memcpy(out + output_transform.index(output_coord) * elem_size, diff --git a/ngraph/core/reference/src/runtime/reference/slice.cpp b/ngraph/core/reference/src/runtime/reference/slice.cpp index 415d55af1f7..532b596979e 100644 --- a/ngraph/core/reference/src/runtime/reference/slice.cpp +++ b/ngraph/core/reference/src/runtime/reference/slice.cpp @@ -45,6 +45,8 @@ namespace ngraph for (const Coordinate& in_coord : input_transform) { + if (output_it == output_transform.end()) + break; const Coordinate& out_coord = *output_it; memcpy(out + output_transform.index(out_coord) * elem_size, diff --git a/ngraph/core/src/env_util.cpp b/ngraph/core/src/env_util.cpp index 450c456535f..81aff3a1290 100644 --- a/ngraph/core/src/env_util.cpp +++ b/ngraph/core/src/env_util.cpp @@ -25,8 +25,7 @@ using namespace std; std::string ngraph::getenv_string(const char* env_var) { const char* env_p = ::getenv(env_var); - string env_string = env_p ? env_p : ""; - return env_string; + return env_p != nullptr ? string(env_p) : ""; } int32_t ngraph::getenv_int(const char* env_var, int32_t default_value) diff --git a/ngraph/core/src/file_util.cpp b/ngraph/core/src/file_util.cpp index 2d4237924be..14c855097df 100644 --- a/ngraph/core/src/file_util.cpp +++ b/ngraph/core/src/file_util.cpp @@ -125,118 +125,6 @@ string file_util::path_join(const string& s1, const string& s2) return rc; } -size_t file_util::get_file_size(const string& filename) -{ - // ensure that filename exists and get its size - - struct stat stats; - if (stat(filename.c_str(), &stats) == -1) - { - throw runtime_error("Could not find file: \"" + filename + "\""); - } - - return stats.st_size; -} - -void file_util::remove_directory(const string& dir) -{ - struct stat status; - if (stat(dir.c_str(), &status) != -1) - { - iterate_files(dir, - [](const string& file, bool is_dir) { - if (is_dir) - { - RMDIR(file.c_str()); - } - else - { - RMFILE(file.c_str()); - } - }, - true); - RMDIR(dir.c_str()); - } -} - -void file_util::remove_file(const string& file) -{ - remove(file.c_str()); -} - -bool file_util::make_directory(const string& dir) -{ -#ifdef _WIN32 - CreateDirectoryA(dir.c_str(), nullptr); -#else - if (mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) - { - if (errno == EEXIST) - { - // not really an error, the directory already exists - return false; - } - throw runtime_error("error making directory " + dir + " " + strerror(errno)); - } -#endif - return true; -} - -string file_util::get_temp_directory_path() -{ - const vector potential_tmps = {"NGRAPH_TMP", "TMPDIR", "TMP", "TEMP", "TEMPDIR"}; - - string path; - for (const string& var : potential_tmps) - { - path = getenv_string(var.c_str()); - if (!path.empty()) - { - break; - } - } - if (path.empty()) - { - path = "/tmp"; - } - - return path; -} - -vector file_util::read_file_contents(const string& path) -{ - size_t file_size = get_file_size(path); - vector data(file_size); - - FILE* f = fopen(path.c_str(), "rb"); - if (f) - { - char* p = data.data(); - size_t remainder = file_size; - size_t offset = 0; - while (f && remainder > 0) - { - size_t rc = fread(&p[offset], 1, remainder, f); - offset += rc; - remainder -= rc; - } - fclose(f); - } - else - { - throw runtime_error("error opening file '" + path + "'"); - } - return data; -} - -string file_util::read_file_to_string(const string& path) -{ - ifstream f(path); - stringstream ss; - ss << f.rdbuf(); - return ss.str(); -} - #ifndef _WIN32 static void iterate_files_worker(const string& path, function func, @@ -352,30 +240,3 @@ void file_util::iterate_files(const string& path, func(f, true); } } - -string file_util::tmp_filename(const string& extension) -{ - string rc; -#ifdef _WIN32 - rc = _tempnam(file_util::get_temp_directory_path().c_str(), "ngraph_"); -#else - string tmp_template = - file_util::path_join(file_util::get_temp_directory_path(), "ngraph_XXXXXX" + extension); - char* tmpname = strdup(tmp_template.c_str()); - if (tmpname != nullptr) - { - // mkstemp opens the file with open() so we need to close it - close(mkstemps(tmpname, static_cast(extension.size()))); - - rc = tmpname; - free(tmpname); - } -#endif - return rc; -} - -bool file_util::exists(const string& filename) -{ - struct stat buffer; - return (stat(filename.c_str(), &buffer) == 0); -} diff --git a/ngraph/core/src/op/shape_of.cpp b/ngraph/core/src/op/shape_of.cpp index 3aa6224dba0..851ddd935b8 100644 --- a/ngraph/core/src/op/shape_of.cpp +++ b/ngraph/core/src/op/shape_of.cpp @@ -193,6 +193,12 @@ shared_ptr op::v0::ShapeOf::clone_with_new_inputs(const OutputVector& new_ { check_new_args_count(this, new_args); auto new_shape_of = make_shared(new_args.at(0)); + NGRAPH_CHECK(new_shape_of.get(), + new_shape_of != nullptr, + "Cannot clone ", + description(), + " operation with name ", + get_friendly_name()); new_shape_of->set_is_foldable(m_is_foldable); return new_shape_of; } diff --git a/ngraph/core/src/op/tensor_iterator.cpp b/ngraph/core/src/op/tensor_iterator.cpp index d1ee19e8899..73456a8d8fd 100644 --- a/ngraph/core/src/op/tensor_iterator.cpp +++ b/ngraph/core/src/op/tensor_iterator.cpp @@ -618,6 +618,12 @@ std::shared_ptr op::v0::TensorIterator::clone_with_new_inputs(const OutputVector& new_args) const { auto op = make_shared(new_args); + NGRAPH_CHECK(op.get(), + op != nullptr, + "Cannot clone ", + description(), + " operation with name ", + get_friendly_name()); op->set_output_size(m_output_descriptions.size()); std::vector<::ngraph::element::Type> types(m_body->get_parameters().size()); diff --git a/ngraph/core/src/op/util/scatter_base.cpp b/ngraph/core/src/op/util/scatter_base.cpp index 371bb00cd2e..cfad2e3428b 100644 --- a/ngraph/core/src/op/util/scatter_base.cpp +++ b/ngraph/core/src/op/util/scatter_base.cpp @@ -79,54 +79,51 @@ void op::util::ScatterBase::validate_and_infer_types() data_shape.rank().get_length() - 1, "Updates rank is expected to be indices rank + data rank - 1."); - bool compatible = true; - int64_t axis; bool is_axis_constant = op::is_constant(input_value(AXIS).get_node()); // Get axis value if possible. if (is_axis_constant && data_shape.rank().is_static()) { + bool compatible = true; const auto axis_const_input = as_type_ptr(input_value(AXIS).get_node_shared_ptr()); - axis = axis_const_input->cast_vector().at(0); + int64_t axis = axis_const_input->cast_vector().at(0); axis = normalize_axis(this, axis, data_shape.rank().get_length()); + + if (indices_shape.rank().is_static() && updates_shape.rank().is_static()) + { + for (int64_t i = 0; i < indices_shape.rank().get_length(); ++i) + { + compatible = compatible && updates_shape[axis + i].compatible(indices_shape[i]); + } + + int64_t indices_rank = indices_shape.rank().get_length(); + // Check [d_0, d_1, ... d_(axis - 1)] updates dimensions + for (int64_t i = 0; i < axis; ++i) + { + compatible = compatible && updates_shape[i].compatible(data_shape[i]); + } + // Check [d_(axis + k + 1), ..., d_n] updates dimensions + for (int64_t i = axis + 1; i < data_shape.rank().get_length(); ++i) + { + compatible = + compatible && updates_shape[indices_rank - 1 + i].compatible(data_shape[i]); + } + } + NODE_VALIDATION_CHECK(this, + compatible, + "Updates shape must have appropriate dimensions equal to indices and " + "data dimensions. Updates shape:", + updates_shape, + ", data shape: ", + data_shape, + ", indices_shape: ", + indices_shape, + ", axis: ", + axis, + "."); } - if (is_axis_constant && data_shape.rank().is_static() && indices_shape.rank().is_static() && - updates_shape.rank().is_static()) - { - for (int64_t i = 0; i < indices_shape.rank().get_length(); ++i) - { - compatible = compatible && updates_shape[axis + i].compatible(indices_shape[i]); - } - - int64_t indices_rank = indices_shape.rank().get_length(); - // Check [d_0, d_1, ... d_(axis - 1)] updates dimensions - for (int64_t i = 0; i < axis; ++i) - { - compatible = compatible && updates_shape[i].compatible(data_shape[i]); - } - // Check [d_(axis + k + 1), ..., d_n] updates dimensions - for (int64_t i = axis + 1; i < data_shape.rank().get_length(); ++i) - { - compatible = - compatible && updates_shape[indices_rank - 1 + i].compatible(data_shape[i]); - } - } - - NODE_VALIDATION_CHECK(this, - compatible, - "Updates shape must have appropriate dimensions equal to indices and " - "data dimensions. Updates shape:", - updates_shape, - ", data shape: ", - data_shape, - ", indices_shape: ", - indices_shape, - ", axis: ", - axis, - "."); - if (data_shape.is_dynamic()) { set_input_is_relevant_to_shape(0); diff --git a/ngraph/core/src/runtime/aligned_buffer.cpp b/ngraph/core/src/runtime/aligned_buffer.cpp index 3ae127d82c2..a6d1bba127e 100644 --- a/ngraph/core/src/runtime/aligned_buffer.cpp +++ b/ngraph/core/src/runtime/aligned_buffer.cpp @@ -37,7 +37,7 @@ runtime::AlignedBuffer::AlignedBuffer(size_t byte_size, size_t alignment) size_t allocation_size = m_byte_size + alignment; m_allocated_buffer = static_cast(ngraph_malloc(allocation_size)); m_aligned_buffer = m_allocated_buffer; - size_t mod = size_t(m_aligned_buffer) % alignment; + size_t mod = (alignment != 0) ? size_t(m_aligned_buffer) % alignment : 0; if (mod != 0) { @@ -67,6 +67,10 @@ runtime::AlignedBuffer& runtime::AlignedBuffer::operator=(AlignedBuffer&& other) { if (this != &other) { + if (m_allocated_buffer != nullptr) + { + free(m_allocated_buffer); + } m_allocated_buffer = other.m_allocated_buffer; m_aligned_buffer = other.m_aligned_buffer; m_byte_size = other.m_byte_size; diff --git a/ngraph/core/src/runtime/host_tensor.cpp b/ngraph/core/src/runtime/host_tensor.cpp index a1b624c977d..5a8c7fe8505 100644 --- a/ngraph/core/src/runtime/host_tensor.cpp +++ b/ngraph/core/src/runtime/host_tensor.cpp @@ -38,6 +38,10 @@ runtime::HostTensor::HostTensor(const ngraph::element::Type& element_type, { allocate_buffer(); } + else + { + m_buffer_size = 0; + } } runtime::HostTensor::HostTensor(const element::Type& element_type, @@ -52,6 +56,7 @@ runtime::HostTensor::HostTensor(const element::Type& element_type, const std::string& name) : runtime::Tensor( std::make_shared(element_type, partial_shape, name)) + , m_buffer_size(0) { // Defer allocation until ptr is requested } diff --git a/ngraph/frontend/onnx_import/src/ops_bridge.cpp b/ngraph/frontend/onnx_import/src/ops_bridge.cpp index 111443ad3c4..8d127b19f28 100644 --- a/ngraph/frontend/onnx_import/src/ops_bridge.cpp +++ b/ngraph/frontend/onnx_import/src/ops_bridge.cpp @@ -157,7 +157,6 @@ namespace ngraph const std::map::const_iterator find(std::int64_t version, const std::map& map) { - std::map::const_iterator it{}; // Get the latest version. if (version == -1) { @@ -165,13 +164,13 @@ namespace ngraph } while (version > 0) { - it = map.find(version--); + std::map::const_iterator it = map.find(version--); if (it != std::end(map)) { return it; } } - return it; + return std::end(map); } } diff --git a/ngraph/test/file_util.cpp b/ngraph/test/file_util.cpp index a573e31b1f2..ff676169c9d 100644 --- a/ngraph/test/file_util.cpp +++ b/ngraph/test/file_util.cpp @@ -89,9 +89,3 @@ TEST(file_util, path_join) EXPECT_STREQ("/test1/test2", file_util::path_join(s1, s2).c_str()); } } - -TEST(file_util, get_temp_directory_path) -{ - string tmp = file_util::get_temp_directory_path(); - EXPECT_NE(0, tmp.size()); -} diff --git a/ngraph/test/runtime/ie/ie_backend.cpp b/ngraph/test/runtime/ie/ie_backend.cpp index 27adc6eec65..20a0f58b993 100644 --- a/ngraph/test/runtime/ie/ie_backend.cpp +++ b/ngraph/test/runtime/ie/ie_backend.cpp @@ -73,6 +73,8 @@ shared_ptr runtime::ie::IE_Backend::create_tensor( const element::Type& element_type, const Shape& shape, void* data) { shared_ptr tensor = make_shared(element_type, shape); + if (tensor == nullptr) + throw runtime_error("Cannot create IETensor!"); tensor->write(data, shape_size(shape) * element_type.size()); return tensor; } diff --git a/ngraph/test/runtime/ie/ie_executable.cpp b/ngraph/test/runtime/ie/ie_executable.cpp index 2ba251deabe..d3f959cd7a3 100644 --- a/ngraph/test/runtime/ie/ie_executable.cpp +++ b/ngraph/test/runtime/ie/ie_executable.cpp @@ -150,7 +150,10 @@ bool runtime::ie::IE_Executable::call(const vector>& } // Prepare output blobs - string output_name = m_network.getOutputsInfo().begin()->first; + auto outInfo = m_network.getOutputsInfo(); + if (outInfo.size() != 1) + THROW_IE_EXCEPTION << "Networks should contain only one output!"; + string output_name = outInfo.begin()->first; infer_request.Infer(); InferenceEngine::Blob::Ptr output = infer_request.GetBlob(output_name);