1# Copyright 2020 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"""Python module for MLIR functions exported by pybind11.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21# pylint: disable=invalid-import-order, g-bad-import-order, wildcard-import, unused-import, undefined-variable 22from tensorflow.python import pywrap_tensorflow 23from tensorflow.python.eager import context 24from tensorflow.python._pywrap_mlir import * 25 26 27def import_graphdef(graphdef, 28 pass_pipeline, 29 show_debug_info, 30 input_names=None, 31 input_data_types=None, 32 input_data_shapes=None, 33 output_names=[]): 34 if input_names is not None: 35 return ImportGraphDef( 36 str(graphdef).encode('utf-8'), pass_pipeline.encode('utf-8'), 37 show_debug_info, ','.join(input_names).encode('utf-8'), 38 ','.join(input_data_types).encode('utf-8'), 39 ':'.join(input_data_shapes).encode('utf-8'), 40 ','.join(output_names).encode('utf-8')) 41 return ImportGraphDef( 42 str(graphdef).encode('utf-8'), pass_pipeline.encode('utf-8'), 43 show_debug_info) 44 45 46def import_function(concrete_function, pass_pipeline, show_debug_info): 47 ctxt = context.context() 48 ctxt.ensure_initialized() 49 return ImportFunction(ctxt._handle, 50 str(concrete_function.function_def).encode('utf-8'), 51 pass_pipeline.encode('utf-8'), show_debug_info) 52 53 54def experimental_convert_saved_model_to_mlir(saved_model_path, exported_names, 55 show_debug_info): 56 return ExperimentalConvertSavedModelToMlir( 57 str(saved_model_path).encode('utf-8'), 58 str(exported_names).encode('utf-8'), show_debug_info) 59 60 61def experimental_convert_saved_model_v1_to_mlir_lite(saved_model_path, 62 exported_names, tags, 63 upgrade_legacy, 64 show_debug_info): 65 return ExperimentalConvertSavedModelV1ToMlirLite( 66 str(saved_model_path).encode('utf-8'), 67 str(exported_names).encode('utf-8'), 68 str(tags).encode('utf-8'), upgrade_legacy, show_debug_info) 69 70 71def experimental_convert_saved_model_v1_to_mlir(saved_model_path, 72 exported_names, tags, 73 lift_variables, upgrade_legacy, 74 show_debug_info): 75 return ExperimentalConvertSavedModelV1ToMlir( 76 str(saved_model_path).encode('utf-8'), 77 str(exported_names).encode('utf-8'), 78 str(tags).encode('utf-8'), lift_variables, upgrade_legacy, 79 show_debug_info) 80 81 82def experimental_run_pass_pipeline(mlir_txt, pass_pipeline, show_debug_info): 83 return ExperimentalRunPassPipeline( 84 mlir_txt.encode('utf-8'), pass_pipeline.encode('utf-8'), show_debug_info) 85