1# Copyright 2017 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 wrapper for prefetching_ops.""" 16from __future__ import absolute_import 17from __future__ import division 18from __future__ import print_function 19 20from tensorflow.python.data.experimental.ops import prefetching_ops 21from tensorflow.python.util import deprecation 22 23 24@deprecation.deprecated(None, 25 "Use `tf.data.experimental.prefetch_to_device(...)`.") 26def prefetch_to_device(device, buffer_size=None): 27 """A transformation that prefetches dataset values to the given `device`. 28 29 NOTE: Although the transformation creates a `tf.data.Dataset`, the 30 transformation must be the final `Dataset` in the input pipeline. 31 32 Args: 33 device: A string. The name of a device to which elements will be prefetched. 34 buffer_size: (Optional.) The number of elements to buffer on `device`. 35 Defaults to an automatically chosen value. 36 37 Returns: 38 A `Dataset` transformation function, which can be passed to 39 `tf.data.Dataset.apply`. 40 """ 41 return prefetching_ops.prefetch_to_device(device, buffer_size) 42 43 44@deprecation.deprecated(None, "Use `tf.data.experimental.copy_to_device(...)`.") 45def copy_to_device(target_device, source_device="/cpu:0"): 46 """A transformation that copies dataset elements to the given `target_device`. 47 48 Args: 49 target_device: The name of a device to which elements will be copied. 50 source_device: The original device on which `input_dataset` will be placed. 51 52 Returns: 53 A `Dataset` transformation function, which can be passed to 54 `tf.data.Dataset.apply`. 55 """ 56 return prefetching_ops.copy_to_device(target_device, source_device) 57