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"""Experimental API for controlling threading in `tf.data` pipelines.""" 16from __future__ import absolute_import 17from __future__ import division 18from __future__ import print_function 19 20 21from tensorflow.python.data.util import options 22from tensorflow.python.util.tf_export import tf_export 23 24 25@tf_export("data.experimental.ThreadingOptions") 26class ThreadingOptions(options.OptionsBase): 27 """Represents options for dataset threading. 28 29 You can set the threading options of a dataset through the 30 `experimental_threading` property of `tf.data.Options`; the property is 31 an instance of `tf.data.experimental.ThreadingOptions`. 32 33 ```python 34 options = tf.data.Options() 35 options.experimental_threading.private_threadpool_size = 10 36 dataset = dataset.with_options(options) 37 ``` 38 """ 39 40 max_intra_op_parallelism = options.create_option( 41 name="max_intra_op_parallelism", 42 ty=int, 43 docstring= 44 "If set, it overrides the maximum degree of intra-op parallelism.") 45 46 private_threadpool_size = options.create_option( 47 name="private_threadpool_size", 48 ty=int, 49 docstring= 50 "If set, the dataset will use a private threadpool of the given size.") 51