diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2016-12-02 09:45:06 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-12-02 10:04:11 -0800 |
commit | a5e51222300c0ecf644087f99f3183644b76fd00 (patch) | |
tree | 1c41b3a6c6b3eef1c61a6e0cd8171c7e3e9454ff /tensorflow/contrib/compiler | |
parent | 9f2bc83209c4a4f2f57697716f4509e3aa7dde8e (diff) |
Add experimental_jit_scope to support scoped compilation regions.
Change: 140860022
Diffstat (limited to 'tensorflow/contrib/compiler')
-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 |
3 files changed, 100 insertions, 0 deletions
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 |