Home | History | Annotate | Download | only in tensorrt
      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 /* Wrap trt_conversion */
     17 %{
     18 #define SWIG_FILE_WITH_INIT
     19 %}
     20 
     21 %{
     22 struct version_struct{
     23   int vmajor;
     24   int vminor;
     25   int vpatch;
     26 };
     27 
     28 PyObject* version_helper(version_struct* in) {
     29   PyObject *tuple(nullptr);
     30   tuple = Py_BuildValue("(iii)", in->vmajor, in->vminor, in->vpatch);
     31   if (!tuple) {
     32     if (!PyErr_Occurred()) {
     33       PyErr_SetString(PyExc_TypeError,
     34                       "Tuple creation from version structure failed!");
     35     }
     36     return NULL;
     37   }
     38   return tuple;
     39 }
     40 
     41 %}
     42 
     43 %typemap(out) version_struct {
     44   PyObject *tuple = version_helper(&$1);
     45   if (!tuple) SWIG_fail;
     46   $result = tuple;
     47 }
     48 
     49 %{
     50 #include "tensorflow/compiler/tf2tensorrt/utils/py_utils.h"
     51 %}
     52 
     53 %ignore "";
     54 %rename("%s") get_linked_tensorrt_version;
     55 %rename("%s") get_loaded_tensorrt_version;
     56 %rename("%s") is_tensorrt_enabled;
     57 
     58 %{
     59 
     60 version_struct get_linked_tensorrt_version() {
     61   // Return the version at the link time.
     62   version_struct s;
     63   tensorflow::tensorrt::GetLinkedTensorRTVersion(
     64       &s.vmajor, &s.vminor, &s.vpatch);
     65   return s;
     66 }
     67 
     68 version_struct get_loaded_tensorrt_version() {
     69   // Return the version from the loaded library.
     70   version_struct s;
     71   tensorflow::tensorrt::GetLoadedTensorRTVersion(
     72       &s.vmajor, &s.vminor, &s.vpatch);
     73   return s;
     74 }
     75 
     76 bool is_tensorrt_enabled() {
     77   return tensorflow::tensorrt::IsGoogleTensorRTEnabled();
     78 }
     79 
     80 %}
     81 
     82 version_struct get_linked_tensorrt_version();
     83 version_struct get_loaded_tensorrt_version();
     84 bool is_tensorrt_enabled();
     85 
     86 %rename("%s") "";
     87