1 /* Copyright 2018 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/compiler/tf2tensorrt/convert/utils.h" 17 18 #include "tensorflow/core/lib/core/errors.h" 19 #include "tensorflow/core/lib/core/status.h" 20 21 namespace tensorflow { 22 namespace tensorrt { 23 TrtPrecisionModeToName(TrtPrecisionMode mode,string * name)24Status TrtPrecisionModeToName(TrtPrecisionMode mode, string* name) { 25 switch (mode) { 26 case TrtPrecisionMode::FP32: 27 *name = "FP32"; 28 break; 29 case TrtPrecisionMode::FP16: 30 *name = "FP16"; 31 break; 32 case TrtPrecisionMode::INT8: 33 *name = "INT8"; 34 break; 35 default: 36 return errors::OutOfRange("Unknown precision mode"); 37 } 38 return Status::OK(); 39 } 40 TrtPrecisionModeFromName(const string & name,TrtPrecisionMode * mode)41Status TrtPrecisionModeFromName(const string& name, TrtPrecisionMode* mode) { 42 if (name == "FP32") { 43 *mode = TrtPrecisionMode::FP32; 44 } else if (name == "FP16") { 45 *mode = TrtPrecisionMode::FP16; 46 } else if (name == "INT8") { 47 *mode = TrtPrecisionMode::INT8; 48 } else { 49 return errors::InvalidArgument("Invalid precision mode name: ", name); 50 } 51 return Status::OK(); 52 } 53 54 } // namespace tensorrt 55 } // namespace tensorflow 56