Skip to content

Commit

Permalink
Use protobuf-lite instead of protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
daquexian committed May 24, 2019
1 parent 4fe4b42 commit 013c6a2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmake/DNNLibraryConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
get_filename_component(DNNLibrary_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

if (@DNN_READ_ONNX@)
if (NOT TARGET protobuf::libprotobuf)
if (NOT TARGET protobuf::libprotobuf-lite)
find_package(Protobuf REQUIRED)
endif()
if (NOT TARGET onnx)
Expand Down
2 changes: 1 addition & 1 deletion cmake/ONNX2daqConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
get_filename_component(ONNX2daq_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

if (NOT TARGET protobuf::libprotobuf)
if (NOT TARGET protobuf::libprotobuf-lite)
find_package(Protobuf REQUIRED)
endif()

Expand Down
1 change: 1 addition & 0 deletions cmake/onnx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function(configure_onnx)
message(FATAL ERROR "DNN_CUSTOM_PROTOC_EXECUTABLE is not set or wrong.")
endif()
set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${DNN_CUSTOM_PROTOC_EXECUTABLE})
option(ONNX_USE_LITE_PROTO "" ON)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/onnx)
target_compile_definitions(onnx_proto PRIVATE ONNX_BUILD_MAIN_LIB)
# Since https://github.com/onnx/onnx/pull/1318 is merged, we don't need to set it manually
Expand Down
10 changes: 9 additions & 1 deletion dnnlibrary/src/OnnxReader.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
#include <dnnlibrary/OnnxReader.h>

#include <algorithm>
#include <fstream>
#include <iterator>

#include <tools/onnx2daq/OnnxConverter.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>

namespace dnn {
void OnnxReader::ReadOnnx(const std::string &filepath, ModelBuilder &builder) {
ONNX_NAMESPACE::ModelProto model_proto;
{
std::ifstream ifs(filepath, std::ios::in | std::ios::binary);
model_proto.ParseFromIstream(&ifs);
std::stringstream ss;
ss << ifs.rdbuf();
// FIXME: Handle the return value
model_proto.ParseFromString(ss.str());
ifs.close();
}
ReadOnnx(model_proto, builder);
}

void OnnxReader::ReadOnnx(const uint8_t *buf, const size_t size, ModelBuilder &builder) {
ONNX_NAMESPACE::ModelProto model_proto;
// FIXME: Handle the return value
model_proto.ParseFromArray(buf, size);
ReadOnnx(model_proto, builder);
}
Expand Down
5 changes: 1 addition & 4 deletions tools/onnx2daq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_library(onnx2daq
${PROJECT_SOURCE_DIR}/common/Shaper.cpp
)
target_link_libraries(onnx2daq
protobuf::libprotobuf
protobuf::libprotobuf-lite
glog::glog
onnx)
target_include_directories(onnx2daq
Expand Down Expand Up @@ -72,9 +72,6 @@ if (NOT ONNX2DAQ_ONLY_LIB)

target_link_libraries(_onnx2daq
PUBLIC
protobuf::libprotobuf
glog::glog
onnx
onnx2daq
pybind11::pybind11
)
Expand Down

0 comments on commit 013c6a2

Please sign in to comment.