Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network compatibility. #970

Merged
merged 1 commit into from Oct 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Network compatibility.
  • Loading branch information
mooskagh committed Oct 26, 2019
commit d932bc791eaf4542cf973ce554b1795344023b43
11 changes: 7 additions & 4 deletions src/neural/loader.cc
Expand Up @@ -30,6 +30,7 @@
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <zlib.h>

#include <algorithm>
#include <cctype>
#include <cstdio>
Expand Down Expand Up @@ -59,7 +60,8 @@ std::string DecompressGzip(const std::string& filename) {
const gzFile file = gzopen(filename.c_str(), "rb");
if (!file) throw Exception("Cannot read weights from " + filename);
while (true) {
const int sz = gzread(file, &buffer[bytes_read], buffer.size() - bytes_read);
const int sz =
gzread(file, &buffer[bytes_read], buffer.size() - bytes_read);
if (sz < 0) {
int errnum;
throw Exception(gzerror(file, &errnum));
Expand Down Expand Up @@ -102,7 +104,8 @@ WeightsFile ParseWeightsProto(const std::string& buffer) {
GetVersionInt(net.min_version().major(), net.min_version().minor(),
net.min_version().patch());

if (net_ver > lc0_ver)
// Weights files with this signature are also compatible.
if (net_ver != 0x5c99973 && net_ver > lc0_ver)
throw Exception("Invalid weight file: lc0 version >= " + min_version +
" required.");

Expand Down Expand Up @@ -200,8 +203,8 @@ std::string DiscoverWeightsFile() {
// First byte of the protobuf stream is 0x0d for fixed32, so we ignore it as
// our own magic should suffice.
const auto magic = buf[1] | (static_cast<uint32_t>(buf[2]) << 8) |
(static_cast<uint32_t>(buf[3]) << 16) |
(static_cast<uint32_t>(buf[4]) << 24);
(static_cast<uint32_t>(buf[3]) << 16) |
(static_cast<uint32_t>(buf[4]) << 24);
if (magic == kWeightMagic) {
CERR << "Found pb network file: " << candidate.second;
return candidate.second;
Expand Down