1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16// See docs in ../ops/array_ops.cc.
17#include "tensorflow/core/kernels/reshape_op.h"
18
19namespace tensorflow {
20
21REGISTER_KERNEL_BUILDER(Name("Reshape")
22 .Device(DEVICE_CPU)
23 .HostMemory("shape")
24 .TypeConstraint<int32>("Tshape"),
25 ReshapeOp);
26REGISTER_KERNEL_BUILDER(Name("Reshape")
27 .Device(DEVICE_CPU)
28 .HostMemory("shape")
29 .TypeConstraint<int64_t>("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_t>("Tshape"), \
44 ReshapeOp);
45TF_CALL_NUMBER_TYPES_NO_INT32(REGISTER_GPU_KERNEL);
46TF_CALL_bool(REGISTER_GPU_KERNEL);
47#undef REGISTER_GPU_KERNEL
48
49#if (defined(GOOGLE_CUDA) && GOOGLE_CUDA) || \
50 (defined(TENSORFLOW_USE_ROCM) && TENSORFLOW_USE_ROCM)
51// A special GPU kernel for int32.
52// TODO(b/25387198): Also enable int32 in device memory. This kernel
53// registration requires all int32 inputs and outputs to be in host memory.
54REGISTER_KERNEL_BUILDER(Name("Reshape")
55 .Device(DEVICE_GPU)
56 .HostMemory("tensor")
57 .HostMemory("shape")
58 .HostMemory("output")
59 .TypeConstraint<int32>("T")
60 .TypeConstraint<int32>("Tshape"),
61 ReshapeOp);
62REGISTER_KERNEL_BUILDER(Name("Reshape")
63 .Device(DEVICE_GPU)
64 .HostMemory("tensor")
65 .HostMemory("shape")
66 .HostMemory("output")
67 .TypeConstraint<int32>("T")
68 .TypeConstraint<int64_t>("Tshape"),
69 ReshapeOp);
70#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM
71
72#define REGISTER_DEFAULT_KERNEL(type) \
73 REGISTER_KERNEL_BUILDER(Name("Reshape") \
74 .Device(DEVICE_DEFAULT) \
75 .HostMemory("shape") \
76 .TypeConstraint<type>("T") \
77 .TypeConstraint<int32>("Tshape"), \
78 ReshapeOp); \
79 REGISTER_KERNEL_BUILDER(Name("Reshape") \
80 .Device(DEVICE_DEFAULT) \
81 .HostMemory("shape") \
82 .TypeConstraint<type>("T") \
83 .TypeConstraint<int64_t>("Tshape"), \
84 ReshapeOp);
85TF_CALL_NUMBER_TYPES_NO_INT32(REGISTER_DEFAULT_KERNEL);
86TF_CALL_bool(REGISTER_DEFAULT_KERNEL);
87#undef REGISTER_DEFAULT_KERNEL
88
89REGISTER_KERNEL_BUILDER(Name("Reshape")
90 .Device(DEVICE_DEFAULT)
91 .HostMemory("tensor")
92 .HostMemory("shape")
93 .HostMemory("output")
94 .TypeConstraint<int32>("T")
95 .TypeConstraint<int32>("Tshape"),
96 ReshapeOp);
97REGISTER_KERNEL_BUILDER(Name("Reshape")
98 .Device(DEVICE_DEFAULT)
99 .HostMemory("tensor")
100 .HostMemory("shape")
101 .HostMemory("output")
102 .TypeConstraint<int32>("T")
103 .TypeConstraint<int64_t>("Tshape"),
104 ReshapeOp);
105
106} // namespace tensorflow
107