Skip to content

Commit

Permalink
[Tensorflow] add helper script to check version, if tf is not install…
Browse files Browse the repository at this point in the history
…ed or too old, return error
  • Loading branch information
hydai committed Dec 4, 2020
1 parent 9d7b62d commit dbbb1cf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions preinstall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#!/usr/bin/env bash
# Build SSVM-Storage dependencies
cd ./rust_native_storage_library/
make target/debug/librust_native_storage_library.so
cd ../

# Check TensorFlow version
c++ ./utils/checker/tensorflow_version_checker.cc -ltensorflow -o ./tf_ver
./tf_ver
if [ "$?" -eq "0" ]
then
rm ./tf_ver
exit 0
else
echo "TensorFlow C library is not yet installed or is too old to support"
exit 1
fi
42 changes: 42 additions & 0 deletions utils/checker/tensorflow_version_checker.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
#include <string>
#include <sstream>
#include <tensorflow/c/c_api.h>

struct Version {
int Major;
int Minor;
int Revision;
Version() = default;
Version(std::string Str) {
std::stringstream Ss(Str);
std::string Buffer;
// Major
std::getline(Ss, Buffer, '.');
Major = std::stoi(Buffer);
// Minor
std::getline(Ss, Buffer, '.');
Minor = std::stoi(Buffer);
// Revision
std::getline(Ss, Buffer, '.');
Revision = std::stoi(Buffer);
}
bool isTooOld() {
if (Major < 2) {
return true;
} else if (Major == 2 && Minor < 3) {
return true;
}
return false;
}
};
int main() {
std::string TFVer(TF_Version());
std::cout << "Your TensorFlow C library version: " << TFVer << "\n";
Version V(TFVer);
if (V.isTooOld()) {
std::cerr << "Your TensorFlow C library is too old. Please upgrade to >=2.3.0\n";
return 1;
}
return 0;
}

0 comments on commit dbbb1cf

Please sign in to comment.