Skip to content

Commit

Permalink
Removed pointer from ov::get_openvino_version (openvinotoolkit#8687)
Browse files Browse the repository at this point in the history
* Removed pointer from ov::get_openvino_version

* Fixed issues with version print

* Clang-format
  • Loading branch information
ilya-lavrenov authored Nov 22, 2021
1 parent b05d900 commit 7c10998
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion ngraph/core/include/openvino/core/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ struct Version {
* @brief Gets the current OpenVINO version
* @return The current OpenVINO version
*/
OPENVINO_API_C(const Version*) get_openvino_version() noexcept;
OPENVINO_API_C(const Version) get_openvino_version() noexcept;

} // namespace ov
2 changes: 1 addition & 1 deletion ngraph/core/src/ngraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
OPENVINO_SUPPRESS_DEPRECATED_START

const char* get_ngraph_version_string() {
return ov::get_openvino_version()->buildNumber;
return ov::get_openvino_version().buildNumber;
}

void ngraph::get_version(size_t& major, size_t& minor, size_t& patch, std::string& extra) {
Expand Down
4 changes: 2 additions & 2 deletions ngraph/core/src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const char* NGRAPH_VERSION_NUMBER = CI_BUILD_NUMBER;

namespace ov {

const Version* get_openvino_version() noexcept {
const Version get_openvino_version() noexcept {
static const Version version = {NGRAPH_VERSION_NUMBER, "OpenVINO Runtime"};
return &version;
return version;
}

} // namespace ov
4 changes: 2 additions & 2 deletions ngraph/test/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ using namespace ngraph;

TEST(openvino_version, version) {
auto version = ov::get_openvino_version();
ASSERT_EQ(std::string("OpenVINO Runtime"), version->description);
ASSERT_FALSE(std::string(version->buildNumber).empty());
ASSERT_EQ(std::string("OpenVINO Runtime"), version.description);
ASSERT_FALSE(std::string(version.buildNumber).empty());
}

TEST(ngraph_version_variable, version) {
Expand Down
6 changes: 4 additions & 2 deletions runtime/bindings/python/src/compatibility/pyngraph/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <pybind11/numpy.h>

#include "ngraph/validation_util.hpp"
#include "openvino/core/version.hpp"
#include "ngraph/version.hpp"

namespace py = pybind11;

Expand Down Expand Up @@ -37,6 +37,8 @@ void regmodule_pyngraph_util(py::module m) {
)");

mod.def("get_ngraph_version_string", []() -> std::string {
return ov::get_openvino_version()->buildNumber;
NGRAPH_SUPPRESS_DEPRECATED_START
return get_ngraph_version_string();
NGRAPH_SUPPRESS_DEPRECATED_END
});
}
2 changes: 1 addition & 1 deletion runtime/bindings/python/src/pyopenvino/pyopenvino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::string get_version() {
auto version = ov::get_openvino_version();
std::string version_str = std::to_string(OPENVINO_VERSION_MAJOR) + ".";
version_str += std::to_string(OPENVINO_VERSION_MINOR) + ".";
version_str += version->buildNumber;
version_str += version.buildNumber;
return version_str;
}

Expand Down
2 changes: 1 addition & 1 deletion samples/cpp/benchmark_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int main(int argc, char* argv[]) {

slog::info << "InferenceEngine: " << GetInferenceEngineVersion() << slog::endl;
slog::info << "Device info: " << slog::endl;
std::cout << ie.GetVersions(device_name) << std::endl;
slog::info << ie.GetVersions(device_name) << slog::endl;

// ----------------- 3. Setting device configuration
// -----------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion samples/cpp/classification_sample_async/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool ParseAndCheckCommandLine(int argc, char* argv[]) {
int main(int argc, char* argv[]) {
try {
// -------- Get OpenVINO Runtime version --------
slog::info << "OpenVINO runtime: " << ov::get_openvino_version() << slog::endl;
slog::info << ov::get_openvino_version() << slog::endl;

// -------- Parsing and validation of input arguments --------
if (!ParseAndCheckCommandLine(argc, argv)) {
Expand Down
43 changes: 19 additions & 24 deletions samples/cpp/common/utils/include/samples/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <vector>

#include "openvino/openvino.hpp"
#include "slog.hpp"

#ifndef UNUSED
# if defined(_MSC_VER) && !defined(__clang__)
Expand Down Expand Up @@ -101,7 +102,7 @@ inline std::string& trim(std::string& s) {
* @param filepath - full file name
* @return filename without extension
*/
static UNUSED std::string fileNameNoExt(const std::string& filepath) {
inline std::string fileNameNoExt(const std::string& filepath) {
auto pos = filepath.rfind('.');
if (pos == std::string::npos)
return filepath;
Expand All @@ -120,46 +121,40 @@ inline std::string fileExt(const std::string& filename) {
return filename.substr(pos + 1);
}

inline std::ostream& operator<<(std::ostream& os, const InferenceEngine::Version& version) {
os << "\t" << version.description << " version ......... ";
os << IE_VERSION_MAJOR << "." << IE_VERSION_MINOR << "." << IE_VERSION_PATCH;
inline slog::LogStream& operator<<(slog::LogStream& os, const InferenceEngine::Version& version) {
os << version.description << " version ......... ";
os << IE_VERSION_MAJOR << "." << IE_VERSION_MINOR << "." << IE_VERSION_PATCH << slog::endl;

os << "\n\tBuild ........... ";
os << version.buildNumber;
os << "Build ........... ";
os << version.buildNumber << slog::endl;

return os;
}

inline std::ostream& operator<<(std::ostream& os, const ov::Version& version) {
os << "\t" << version.description << " version ......... ";
os << OPENVINO_VERSION_MAJOR << "." << OPENVINO_VERSION_MINOR << "." << OPENVINO_VERSION_PATCH;
inline slog::LogStream& operator<<(slog::LogStream& os, const ov::Version& version) {
os << version.description << " version ......... ";
os << OPENVINO_VERSION_MAJOR << "." << OPENVINO_VERSION_MINOR << "." << OPENVINO_VERSION_PATCH << slog::endl;

os << "\n\tBuild ........... ";
os << version.buildNumber;
os << "Build ........... ";
os << version.buildNumber << slog::endl;

return os;
}

inline std::ostream& operator<<(std::ostream& os, const InferenceEngine::Version* version) {
if (nullptr != version) {
os << std::endl << *version;
}
return os;
}

inline std::ostream& operator<<(std::ostream& os, const std::map<std::string, InferenceEngine::Version>& versions) {
inline slog::LogStream& operator<<(slog::LogStream& os,
const std::map<std::string, InferenceEngine::Version>& versions) {
for (auto&& version : versions) {
os << "\t" << version.first << std::endl;
os << version.second << std::endl;
os << version.first << slog::endl;
os << version.second << slog::endl;
}

return os;
}

inline std::ostream& operator<<(std::ostream& os, const std::map<std::string, ov::Version>& versions) {
inline slog::LogStream& operator<<(slog::LogStream& os, const std::map<std::string, ov::Version>& versions) {
for (auto&& version : versions) {
os << "\t" << version.first << std::endl;
os << version.second << std::endl;
os << version.first << slog::endl;
os << version.second << slog::endl;
}

return os;
Expand Down
2 changes: 2 additions & 0 deletions samples/cpp/common/utils/src/slog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ LogStream::LogStream(const std::string& prefix, std::ostream& log_stream) : _pre

// Specializing for LogStreamEndLine to support slog::endl
LogStream& LogStream::operator<<(const LogStreamEndLine& /*arg*/) {
if (_new_line)
(*_log_stream) << "[ " << _prefix << " ] ";
_new_line = true;

(*_log_stream) << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions samples/cpp/ngraph_function_creation_sample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ std::shared_ptr<ov::Function> createNgraphFunction() {
int main(int argc, char* argv[]) {
try {
// -------- Get OpenVINO runtime version --------
slog::info << "OpenVINO Runtime: " << ov::get_openvino_version() << slog::endl;
slog::info << ov::get_openvino_version() << slog::endl;

// -------- Parsing and validation of input arguments --------
if (!ParseAndCheckCommandLine(argc, argv)) {
Expand All @@ -266,7 +266,7 @@ int main(int argc, char* argv[]) {
runtime::Core core;

slog::info << "Device info: " << slog::endl;
std::cout << core.get_versions(FLAGS_d) << std::endl;
slog::info << core.get_versions(FLAGS_d) << slog::endl;

// -------- Step 2. Create network using ov::Function --------

Expand Down
2 changes: 1 addition & 1 deletion samples/cpp/object_detection_sample_ssd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) {
// ------------------------------ Get Available Devices
// ------------------------------------------------------
slog::info << "Device info: " << slog::endl;
std::cout << ie.GetVersions(FLAGS_d) << std::endl;
slog::info << ie.GetVersions(FLAGS_d) << slog::endl;

if (!FLAGS_l.empty()) {
IExtensionPtr extension_ptr = std::make_shared<Extension>(FLAGS_l);
Expand Down
2 changes: 1 addition & 1 deletion samples/cpp/speech_sample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ int main(int argc, char* argv[]) {
std::string deviceStr = useHetero && useGna ? "HETERO:GNA,CPU" : FLAGS_d.substr(0, (FLAGS_d.find("_")));

slog::info << "Device info: " << slog::endl;
std::cout << ie.GetVersions(deviceStr) << std::endl;
slog::info << ie.GetVersions(deviceStr) << slog::endl;
// -----------------------------------------------------------------------------------------------------

// --------------------------- Step 2. Read a model in OpenVINO Intermediate Representation (.xml and .bin
Expand Down
2 changes: 1 addition & 1 deletion samples/cpp/style_transfer_sample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) {
// ------------------------------ Get Available Devices
// ------------------------------------------------------
slog::info << "Device info: " << slog::endl;
std::cout << ie.GetVersions(FLAGS_d) << std::endl;
slog::info << ie.GetVersions(FLAGS_d) << slog::endl;

if (!FLAGS_l.empty()) {
IExtensionPtr extension_ptr = std::make_shared<Extension>(FLAGS_l);
Expand Down

0 comments on commit 7c10998

Please sign in to comment.