Skip to content

Commit fe596e1

Browse files
A. Unique TensorFlowertensorflower-gardener
authored andcommitted
Introduce IS_MOBILE_PLATFORM macro, defined in platform.h, and use this for
only registering some types on android and ios (instead of __ANDROID__ macro). Change: 123983258
1 parent 6b1b429 commit fe596e1

7 files changed

Lines changed: 25 additions & 14 deletions

File tree

tensorflow/core/framework/register_types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ limitations under the License.
4343
#undef REGISTER_PARTITION
4444
*/
4545

46-
#if !defined(__ANDROID__) || defined(SUPPORT_SELECTIVE_REGISTRATION)
46+
#if !defined(IS_MOBILE_PLATFORM) || defined(SUPPORT_SELECTIVE_REGISTRATION)
4747
// Call "m" for all number types that support the comparison operations "<" and
4848
// ">".
4949
#define TF_CALL_INTEGRAL_TYPES(m) \
@@ -111,7 +111,7 @@ limitations under the License.
111111
#define TF_CALL_QUANTIZED_TYPES(m) \
112112
m(::tensorflow::qint8) m(::tensorflow::quint8) m(::tensorflow::qint32)
113113

114-
#else // defined(__ANDROID__) && !defined(__ANDROID_TYPES_FULL__)
114+
#else // defined(IS_MOBILE_PLATFORM) && !defined(__ANDROID_TYPES_FULL__)
115115

116116
#define TF_CALL_REAL_NUMBER_TYPES(m) m(float) m(::tensorflow::int32)
117117

@@ -130,6 +130,6 @@ limitations under the License.
130130

131131
#define TF_CALL_QUANTIZED_TYPES(m)
132132

133-
#endif // defined(__ANDROID__)
133+
#endif // defined(IS_MOBILE_PLATFORM)
134134

135135
#endif // TENSORFLOW_FRAMEWORK_REGISTER_TYPES_H_

tensorflow/core/framework/types.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ DataTypeVector AllTypes() {
181181
DT_QUINT16, DT_QINT32, DT_HALF};
182182
}
183183

184-
#if !defined(__ANDROID__) || defined(SUPPORT_SELECTIVE_REGISTRATION)
184+
#if !defined(IS_MOBILE_PLATFORM) || defined(SUPPORT_SELECTIVE_REGISTRATION)
185185

186186
DataTypeVector RealNumberTypes() {
187187
return {DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8,
@@ -224,7 +224,7 @@ DataTypeVector RealAndQuantizedTypes() {
224224
DT_QINT16, DT_QUINT16, DT_QINT32, DT_HALF};
225225
}
226226

227-
#else // defined(__ANDROID__) && !defined(__ANDROID_TYPES_FULL__)
227+
#else // defined(IS_MOBILE_PLATFORM) && !defined(__ANDROID_TYPES_FULL__)
228228

229229
DataTypeVector RealNumberTypes() { return {DT_FLOAT, DT_INT32}; }
230230

@@ -241,7 +241,7 @@ DataTypeVector RealAndQuantizedTypes() {
241241
DT_QINT16, DT_QUINT16, DT_QINT32};
242242
}
243243

244-
#endif // defined(__ANDROID__)
244+
#endif // defined(IS_MOBILE_PLATFORM)
245245

246246
// TODO(jeff): Maybe unify this with Tensor::CanUseDMA, or the underlying
247247
// is_simple<T> in tensor.cc (and possible choose a more general name?)

tensorflow/core/kernels/conv_grad_ops_3d.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class Conv3DBackpropInputOp : public OpKernel {
197197
REGISTER_KERNEL_BUILDER(
198198
Name("Conv3DBackpropInput").Device(DEVICE_CPU).TypeConstraint<float>("T"),
199199
Conv3DBackpropInputOp<CPUDevice, float>);
200-
#ifndef __ANDROID__
200+
#ifndef IS_MOBILE_PLATFORM
201201
REGISTER_KERNEL_BUILDER(
202202
Name("Conv3DBackpropInput").Device(DEVICE_CPU).TypeConstraint<double>("T"),
203203
Conv3DBackpropInputOp<CPUDevice, double>);
@@ -306,7 +306,7 @@ class Conv3DBackpropFilterOp : public OpKernel {
306306
REGISTER_KERNEL_BUILDER(
307307
Name("Conv3DBackpropFilter").Device(DEVICE_CPU).TypeConstraint<float>("T"),
308308
Conv3DBackpropFilterOp<CPUDevice, float>);
309-
#ifndef __ANDROID__
309+
#ifndef IS_MOBILE_PLATFORM
310310
REGISTER_KERNEL_BUILDER(
311311
Name("Conv3DBackpropFilter").Device(DEVICE_CPU).TypeConstraint<double>("T"),
312312
Conv3DBackpropFilterOp<CPUDevice, double>);

tensorflow/core/kernels/conv_ops_3d.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ REGISTER_KERNEL_BUILDER(
124124
Name("Conv3D").Device(DEVICE_CPU).TypeConstraint<float>("T"),
125125
Conv3DOp<CPUDevice, float>);
126126

127-
#ifndef __ANDROID__
127+
#ifndef IS_MOBILE_PLATFORM
128128
REGISTER_KERNEL_BUILDER(
129129
Name("Conv3D").Device(DEVICE_CPU).TypeConstraint<double>("T"),
130130
Conv3DOp<CPUDevice, double>);

tensorflow/core/kernels/cwise_op_abs.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ limitations under the License.
1818
namespace tensorflow {
1919
REGISTER5(UnaryOp, CPU, "Abs", functor::abs, float, Eigen::half, double, int32,
2020
int64);
21-
#if !defined(__ANDROID__)
21+
#if !defined(IS_MOBILE_PLATFORM)
2222
REGISTER2(UnaryOp, CPU, "ComplexAbs", functor::abs, complex64, complex128);
2323
#endif
2424
#if GOOGLE_CUDA

tensorflow/core/kernels/lrn_op.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License.
2525
#include "tensorflow/core/kernels/ops_util.h"
2626
#include "tensorflow/core/lib/core/errors.h"
2727

28-
#if !defined(__ANDROID__)
28+
#if !defined(IS_MOBILE_PLATFORM)
2929
#include "tensorflow/core/util/work_sharder.h"
3030
#endif
3131

@@ -87,7 +87,7 @@ class LRNOp : public OpKernel {
8787
context->allocate_output(
8888
0, TensorShape({batch, rows, cols, depth}), &output));
8989

90-
#if defined(__ANDROID__)
90+
#if defined(IS_MOBILE_PLATFORM)
9191
SingleThreadedLRN(in, batch, rows, cols, depth, output);
9292
#else
9393
if (depth > kSingleThreadedLRNDepthCutoff &&
@@ -171,7 +171,7 @@ class LRNOp : public OpKernel {
171171

172172
REGISTER_KERNEL_BUILDER(Name("LRN").Device(DEVICE_CPU), LRNOp);
173173

174-
#if !defined(__ANDROID__)
174+
#if !defined(IS_MOBILE_PLATFORM)
175175

176176
class LRNGradOp : public OpKernel {
177177
public:
@@ -277,6 +277,6 @@ class LRNGradOp : public OpKernel {
277277

278278
REGISTER_KERNEL_BUILDER(Name("LRNGrad").Device(DEVICE_CPU), LRNGradOp);
279279

280-
#endif // !defined(__ANDROID__)
280+
#endif // !defined(IS_MOBILE_PLATFORM)
281281

282282
} // namespace tensorflow

tensorflow/core/platform/platform.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@ limitations under the License.
1616
#ifndef TENSORFLOW_PLATFORM_PLATFORM_DEFINE_H_
1717
#define TENSORFLOW_PLATFORM_PLATFORM_DEFINE_H_
1818

19+
// Set one PLATFORM_* macro and set IS_MOBILE_PLATFORM if the platform is for
20+
// mobile.
21+
1922
#if !defined(PLATFORM_POSIX) && !defined(PLATFORM_GOOGLE) && \
2023
!defined(PLATFORM_POSIX_ANDROID) && !defined(PLATFORM_GOOGLE_ANDROID)
2124

2225
// Choose which platform we are on.
2326
#if defined(ANDROID) || defined(__ANDROID__)
2427
#define PLATFORM_POSIX_ANDROID
28+
#define IS_MOBILE_PLATFORM
2529

2630
#elif defined(__APPLE__)
2731
#define PLATFORM_POSIX
2832

33+
#include "TargetConditionals.h"
34+
#if TARGET_IPHONE_SIMULATOR
35+
#define IS_MOBILE_PLATFORM
36+
#elif TARGET_OS_IPHONE
37+
#define IS_MOBILE_PLATFORM
38+
#endif
39+
2940
#else
3041
// If no platform specified, use:
3142
#define PLATFORM_POSIX

0 commit comments

Comments
 (0)