Home | History | Annotate | Download | only in kernels
      1 /* Copyright 2015 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 // See docs in ../ops/array_ops.cc.
     17 #include "tensorflow/core/kernels/reshape_op.h"
     18 
     19 namespace tensorflow {
     20 
     21 REGISTER_KERNEL_BUILDER(Name("Reshape")
     22                             .Device(DEVICE_CPU)
     23                             .HostMemory("shape")
     24                             .TypeConstraint<int32>("Tshape"),
     25                         ReshapeOp);
     26 REGISTER_KERNEL_BUILDER(Name("Reshape")
     27                             .Device(DEVICE_CPU)
     28                             .HostMemory("shape")
     29                             .TypeConstraint<int64>("Tshape"),
     30                         ReshapeOp);
     31 
     32 #define REGISTER_GPU_KERNEL(type)                               \
     33   REGISTER_KERNEL_BUILDER(Name("Reshape")                       \
     34                               .Device(DEVICE_GPU)               \
     35                               .HostMemory("shape")              \
     36                               .TypeConstraint<type>("T")        \
     37                               .TypeConstraint<int32>("Tshape"), \
     38                           ReshapeOp);                           \
     39   REGISTER_KERNEL_BUILDER(Name("Reshape")                       \
     40                               .Device(DEVICE_GPU)               \
     41                               .HostMemory("shape")              \
     42                               .TypeConstraint<type>("T")        \
     43                               .TypeConstraint<int64>("Tshape"), \
     44                           ReshapeOp);
     45 TF_CALL_NUMBER_TYPES_NO_INT32(REGISTER_GPU_KERNEL);
     46 TF_CALL_bool(REGISTER_GPU_KERNEL);
     47 #undef REGISTER_GPU_KERNEL
     48 
     49 #ifdef TENSORFLOW_USE_SYCL
     50 #define REGISTER_SYCL_KERNEL(type)                              \
     51   REGISTER_KERNEL_BUILDER(Name("Reshape")                       \
     52                               .Device(DEVICE_SYCL)              \
     53                               .HostMemory("shape")              \
     54                               .TypeConstraint<type>("T")        \
     55                               .TypeConstraint<int32>("Tshape"), \
     56                           ReshapeOp);                           \
     57   REGISTER_KERNEL_BUILDER(Name("Reshape")                       \
     58                               .Device(DEVICE_SYCL)              \
     59                               .HostMemory("shape")              \
     60                               .TypeConstraint<type>("T")        \
     61                               .TypeConstraint<int64>("Tshape"), \
     62                           ReshapeOp);
     63 REGISTER_SYCL_KERNEL(float)
     64 REGISTER_SYCL_KERNEL(double)
     65 REGISTER_SYCL_KERNEL(uint8)
     66 REGISTER_SYCL_KERNEL(int8)
     67 REGISTER_SYCL_KERNEL(int64)
     68 REGISTER_SYCL_KERNEL(uint16)
     69 
     70 REGISTER_KERNEL_BUILDER(Name("Reshape")
     71                             .Device(DEVICE_SYCL)
     72                             .HostMemory("tensor")
     73                             .HostMemory("shape")
     74                             .HostMemory("output")
     75                             .TypeConstraint<int32>("T")
     76                             .TypeConstraint<int32>("Tshape"),
     77                         ReshapeOp);
     78 REGISTER_KERNEL_BUILDER(Name("Reshape")
     79                             .Device(DEVICE_SYCL)
     80                             .HostMemory("tensor")
     81                             .HostMemory("shape")
     82                             .HostMemory("output")
     83                             .TypeConstraint<int32>("T")
     84                             .TypeConstraint<int64>("Tshape"),
     85                         ReshapeOp);
     86 #undef REGISTER_SYCL_KERNEL
     87 #endif  // TENSORFLOW_USE_SYCL
     88 
     89 #if GOOGLE_CUDA
     90 // A special GPU kernel for int32.
     91 // TODO(b/25387198): Also enable int32 in device memory. This kernel
     92 // registration requires all int32 inputs and outputs to be in host memory.
     93 REGISTER_KERNEL_BUILDER(Name("Reshape")
     94                             .Device(DEVICE_GPU)
     95                             .HostMemory("tensor")
     96                             .HostMemory("shape")
     97                             .HostMemory("output")
     98                             .TypeConstraint<int32>("T")
     99                             .TypeConstraint<int32>("Tshape"),
    100                         ReshapeOp);
    101 REGISTER_KERNEL_BUILDER(Name("Reshape")
    102                             .Device(DEVICE_GPU)
    103                             .HostMemory("tensor")
    104                             .HostMemory("shape")
    105                             .HostMemory("output")
    106                             .TypeConstraint<int32>("T")
    107                             .TypeConstraint<int64>("Tshape"),
    108                         ReshapeOp);
    109 #endif
    110 
    111 }  // namespace tensorflow
    112