Onnx: ::google::protobuf::io::CodedInputStream::SetTotalBytesLimit does not take 2 arguments

Created on 23 Mar 2020  路  3Comments  路  Source: onnx/onnx

Hi,
I compiled onnxruntime today together with protobuf 3.11.2. and had to change a snippet to make it work.

When using older versions of protobuf (3.10.0 and less) I got the following error on several lines:

 onnx/onnx-ml.pb.h:3700:111: error: only virtual member functions can be marked 'final'
       ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;

Edit: the error was due to mixing different versions of protoc and protobuf sources

When using protobuf 3.11.2 the interface of SetTotalBytesLimit is different and only one parmeter can be given:

 diff --git a/onnx/proto_utils.h b/onnx/proto_utils.h

 index ec125fde..3de807ac 100644
 --- a/onnx/proto_utils.h
 +++ b/onnx/proto_utils.h
 @@ -31,7 +31,7 @@ bool ParseProtoFromBytes(Proto* proto, const char* buffer, size_t length) {
    // respectively.
    ::google::protobuf::io::ArrayInputStream input_stream(buffer, static_cast<int>(length));
    ::google::protobuf::io::CodedInputStream coded_stream(&input_stream);
 -  coded_stream.SetTotalBytesLimit((2048LL << 20) - 1, 512LL << 20);
 +  coded_stream.SetTotalBytesLimit((2048LL << 20) - 1);
    return proto->ParseFromCodedStream(&coded_stream);
  }
bug

Most helpful comment

The problem is: ONNX doesn't work perfectly with protobuf version > 3.11.x.

ONNX should have a "#ifdef" there. If the protobuf version larger than a specific value, then call the function with only one argument.

Like

#if GOOGLE_PROTOBUF_VERSION >= 3002000
    SetTotalBytesLimit(total_bytes_limit);
#else
    SetTotalBytesLimit(total_bytes_limit, 102400);
#endif

The fix need be happened in ONNX, not onnxruntime.

All 3 comments

It's better to move the issue to onnx runtime community - http://github.com/microsoft/onnxruntime.

This method uses, at least since protobuf 3.6.1, only the first argument the second one is ignored.
This code was added in 12/2017

  PROTOBUF_RUNTIME_DEPRECATED(
      "Please use the single parameter version of SetTotalBytesLimit(). The "
      "second parameter is ignored.")
  void SetTotalBytesLimit(int total_bytes_limit, int) {
    SetTotalBytesLimit(total_bytes_limit);
  }

For protobuf >3.11.x it wont compile.

it's either compatiblity for pb >=3.6 or <=3.10

The problem is: ONNX doesn't work perfectly with protobuf version > 3.11.x.

ONNX should have a "#ifdef" there. If the protobuf version larger than a specific value, then call the function with only one argument.

Like

#if GOOGLE_PROTOBUF_VERSION >= 3002000
    SetTotalBytesLimit(total_bytes_limit);
#else
    SetTotalBytesLimit(total_bytes_limit, 102400);
#endif

The fix need be happened in ONNX, not onnxruntime.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhangguangzhi picture zhangguangzhi  路  5Comments

tom888888 picture tom888888  路  4Comments

leodestiny picture leodestiny  路  5Comments

fdwr picture fdwr  路  3Comments

PenghuiCheng picture PenghuiCheng  路  3Comments