diff options
-rw-r--r-- | tensorflow/BUILD | 1 | ||||
-rw-r--r-- | tensorflow/contrib/BUILD | 1 | ||||
-rw-r--r-- | tensorflow/contrib/__init__.py | 1 | ||||
-rw-r--r-- | tensorflow/contrib/compiler/BUILD | 29 | ||||
-rw-r--r-- | tensorflow/contrib/compiler/__init__.py | 21 | ||||
-rw-r--r-- | tensorflow/contrib/compiler/jit.py | 50 |
6 files changed, 103 insertions, 0 deletions
diff --git a/tensorflow/BUILD b/tensorflow/BUILD index 73b5954337..869eb6c947 100644 --- a/tensorflow/BUILD +++ b/tensorflow/BUILD @@ -86,6 +86,7 @@ filegroup( "//tensorflow/contrib:all_files", "//tensorflow/contrib/android:all_files", "//tensorflow/contrib/bayesflow:all_files", + "//tensorflow/contrib/compiler:all_files", "//tensorflow/contrib/copy_graph:all_files", "//tensorflow/contrib/crf:all_files", "//tensorflow/contrib/cudnn_rnn:all_files", diff --git a/tensorflow/contrib/BUILD b/tensorflow/contrib/BUILD index 27cb689d79..568c838f07 100644 --- a/tensorflow/contrib/BUILD +++ b/tensorflow/contrib/BUILD @@ -14,6 +14,7 @@ py_library( visibility = ["//visibility:public"], deps = [ "//tensorflow/contrib/bayesflow:bayesflow_py", + "//tensorflow/contrib/compiler:compiler_py", "//tensorflow/contrib/copy_graph:copy_graph_py", "//tensorflow/contrib/crf:crf_py", "//tensorflow/contrib/cudnn_rnn:cudnn_rnn_py", diff --git a/tensorflow/contrib/__init__.py b/tensorflow/contrib/__init__.py index 31c3064cde..2a4f503a54 100644 --- a/tensorflow/contrib/__init__.py +++ b/tensorflow/contrib/__init__.py @@ -20,6 +20,7 @@ from __future__ import print_function # Add projects here, they will show up under tf.contrib. from tensorflow.contrib import bayesflow +from tensorflow.contrib import compiler from tensorflow.contrib import copy_graph from tensorflow.contrib import crf from tensorflow.contrib import cudnn_rnn diff --git a/tensorflow/contrib/compiler/BUILD b/tensorflow/contrib/compiler/BUILD new file mode 100644 index 0000000000..444f5e9e16 --- /dev/null +++ b/tensorflow/contrib/compiler/BUILD @@ -0,0 +1,29 @@ +licenses(["notice"]) # Apache 2.0 + +package(default_visibility = [":friends"]) + +package_group( + name = "friends", + packages = ["//tensorflow/..."], +) + +py_library( + name = "compiler_py", + srcs = [ + "__init__.py", + "jit.py", + ], + srcs_version = "PY2AND3", +) + +filegroup( + name = "all_files", + srcs = glob( + ["**/*"], + exclude = [ + "**/METADATA", + "**/OWNERS", + ], + ), + visibility = ["//tensorflow:__subpackages__"], +) diff --git a/tensorflow/contrib/compiler/__init__.py b/tensorflow/contrib/compiler/__init__.py new file mode 100644 index 0000000000..c4937dadfb --- /dev/null +++ b/tensorflow/contrib/compiler/__init__.py @@ -0,0 +1,21 @@ +# Copyright 2016 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""A module for controlling the Tensorflow/XLA JIT compiler.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from tensorflow.contrib.compiler import jit diff --git a/tensorflow/contrib/compiler/jit.py b/tensorflow/contrib/compiler/jit.py new file mode 100644 index 0000000000..5c84159fcf --- /dev/null +++ b/tensorflow/contrib/compiler/jit.py @@ -0,0 +1,50 @@ +# Copyright 2016 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Library for controlling the Tensorflow/XLA JIT compiler.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import contextlib + +import tensorflow as tf + + +@contextlib.contextmanager +def experimental_jit_scope(compile_ops=True): + """Enable or disable JIT compilation of operators within the scope. + + NOTE: This is an experimental feature. + + The compilation is a hint and only supported on a best-effort basis. + + Example usage: + with tf.contrib.framework.experimental_jit_scope(): + c = tf.matmul(a, b) # compiled + with tf.contrib.framework.experimental_jit_scope(compile_ops=False): + d = tf.matmul(a, c) # not compiled + + Args: + compile_ops: boolean, whether to enable or disable compilation in the scope. + Yields: + The current scope, enabling or disabling compilation. + + """ + attrs = {"_XlaCompile": tf.AttrValue(b=compile_ops)} + # pylint: disable=protected-access + with tf.get_default_graph()._attr_scope(attrs): + yield + # pylint: enable=protected-access |