Home | History | Annotate | Download | only in kernels
      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 #include <limits>
     17 
     18 #define EIGEN_USE_THREADS
     19 #if GOOGLE_CUDA
     20 #define EIGEN_USE_GPU
     21 
     22 #include "tensorflow/core/kernels/list_kernels.h"
     23 
     24 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
     25 #include "tensorflow/core/framework/op_kernel.h"
     26 #include "tensorflow/core/framework/register_types.h"
     27 #include "tensorflow/core/framework/tensor_types.h"
     28 #include "tensorflow/core/framework/variant.h"
     29 #include "tensorflow/core/framework/variant_op_registry.h"
     30 #include "tensorflow/core/kernels/concat_lib.h"
     31 #include "tensorflow/core/lib/core/coding.h"
     32 #include "tensorflow/core/lib/core/errors.h"
     33 #include "tensorflow/core/util/util.h"
     34 
     35 namespace tensorflow {
     36 
     37 typedef Eigen::GpuDevice GPUDevice;
     38 
     39 #define REGISTER_TENSOR_LIST_STACK_GPU(T)                         \
     40   REGISTER_KERNEL_BUILDER(Name("TensorListStack")                 \
     41                               .TypeConstraint<T>("element_dtype") \
     42                               .Device(DEVICE_GPU),                \
     43                           TensorListStack<GPUDevice, T>)
     44 
     45 TF_CALL_GPU_NUMBER_TYPES(REGISTER_TENSOR_LIST_STACK_GPU);
     46 REGISTER_TENSOR_LIST_STACK_GPU(bfloat16);
     47 TF_CALL_complex64(REGISTER_TENSOR_LIST_STACK_GPU);
     48 TF_CALL_complex128(REGISTER_TENSOR_LIST_STACK_GPU);
     49 TF_CALL_int64(REGISTER_TENSOR_LIST_STACK_GPU);
     50 REGISTER_TENSOR_LIST_STACK_GPU(bool);
     51 
     52 #undef REGISTER_TENSOR_LIST_STACK_GPU
     53 
     54 #define REGISTER_TENSOR_LIST_FROM_TENSOR_GPU(T)                   \
     55   REGISTER_KERNEL_BUILDER(Name("TensorListFromTensor")            \
     56                               .TypeConstraint<T>("element_dtype") \
     57                               .Device(DEVICE_GPU)                 \
     58                               .HostMemory("element_shape"),       \
     59                           TensorListFromTensor<GPUDevice, T>)
     60 
     61 TF_CALL_GPU_NUMBER_TYPES(REGISTER_TENSOR_LIST_FROM_TENSOR_GPU);
     62 REGISTER_TENSOR_LIST_FROM_TENSOR_GPU(bfloat16);
     63 TF_CALL_complex64(REGISTER_TENSOR_LIST_FROM_TENSOR_GPU);
     64 TF_CALL_complex128(REGISTER_TENSOR_LIST_FROM_TENSOR_GPU);
     65 TF_CALL_int64(REGISTER_TENSOR_LIST_FROM_TENSOR_GPU);
     66 REGISTER_TENSOR_LIST_FROM_TENSOR_GPU(bool);
     67 
     68 #undef REGISTER_TENSOR_LIST_FROM_TENSOR_GPU
     69 
     70 REGISTER_UNARY_VARIANT_BINARY_OP_FUNCTION(ADD_VARIANT_BINARY_OP, DEVICE_GPU,
     71                                           TensorList, TensorList::kTypeName,
     72                                           TensorListBinaryAdd<GPUDevice>);
     73 REGISTER_UNARY_VARIANT_UNARY_OP_FUNCTION(ZEROS_LIKE_VARIANT_UNARY_OP,
     74                                          DEVICE_GPU, TensorList,
     75                                          TensorList::kTypeName,
     76                                          TensorListZerosLike<GPUDevice>);
     77 
     78 }  // namespace tensorflow
     79 #endif  // GOOGLE_CUDA
     80