1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #include "tensorflow/core/framework/versions.h"
17 #include "tensorflow/core/framework/versions.pb.h"
18 #include "tensorflow/core/lib/core/errors.h"
19 #include "tensorflow/core/public/version.h"
20
21 namespace tensorflow {
22
CheckVersions(const VersionDef & versions,int consumer,int min_producer,const char * upper_name,const char * lower_name)23 Status CheckVersions(const VersionDef& versions, int consumer, int min_producer,
24 const char* upper_name, const char* lower_name) {
25 // Guard against the caller misordering the arguments
26 if (consumer < min_producer) {
27 return errors::Internal(upper_name, " version check has consumer ",
28 consumer, " < min_producer ", min_producer, ".");
29 }
30
31 // Check versions
32 if (versions.producer() < min_producer) {
33 return errors::InvalidArgument(
34 upper_name, " producer version ", versions.producer(),
35 " below min producer ", min_producer, " supported by TensorFlow ",
36 TF_VERSION_STRING, ". Please regenerate your ", lower_name, ".");
37 }
38 if (versions.min_consumer() > consumer) {
39 return errors::InvalidArgument(
40 upper_name, " min consumer version ", versions.min_consumer(),
41 " above current version ", consumer, " for TensorFlow ",
42 TF_VERSION_STRING, ". Please upgrade TensorFlow.");
43 }
44 for (const int bad_consumer : versions.bad_consumers()) {
45 if (bad_consumer == consumer) {
46 return errors::InvalidArgument(
47 upper_name, " disallows consumer version ", bad_consumer,
48 ". Please upgrade TensorFlow: this version is likely buggy.");
49 }
50 }
51
52 // All good!
53 return Status::OK();
54 }
55
56 } // namespace tensorflow
57