Skip to content

Commit 0c32e1b

Browse files
jerryzh168facebook-github-bot
authored andcommitted
use C10_MOBILE/ANDROID/IOS (pytorch#15363)
Summary: Pull Request resolved: pytorch#15363 Didn't define C10_MOBILE in the numa file move diff: D13380559 move CAFFE2_MOBILE/ANDROID/IOS to c10 ``` codemod -m -d caffe2 --extensions h,hpp,cc,cpp,mm "CAFFE2_MOBILE" "C10_MOBILE" codemod -m -d caffe2 --extensions h,hpp,cc,cpp,mm "CAFFE2_ANDROID" "C10_ANDROID" codemod -m -d caffe2 --extensions h,hpp,cc,cpp,mm "CAFFE2_IOS" "C10_IOS" ``` i-am-not-moving-c2-to-c10 Reviewed By: marcinkwiatkowski Differential Revision: D13490020 fbshipit-source-id: c4f01cacbefc0f16d5de94155c26c92fd5d780e4
1 parent 5838b59 commit 0c32e1b

18 files changed

+34
-53
lines changed

caffe2/core/common.h

+1-19
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424

2525
// Macros used during the build of this caffe2 instance. This header file
2626
// is automatically generated by the cmake script during build.
27-
#include "caffe2/core/common.h"
2827
#include "caffe2/core/macros.h"
2928

30-
#include "c10/macros/Macros.h"
29+
#include <c10/macros/Macros.h>
3130

3231
#include "c10/util/string_utils.h"
3332

@@ -63,23 +62,6 @@ using std::vector;
6362
#define CAFFE2_USED __attribute__((__used__))
6463
#endif //_MSC_VER
6564

66-
// Define enabled when building for iOS or Android devices
67-
#if !defined(CAFFE2_MOBILE)
68-
#if defined(__ANDROID__)
69-
#define CAFFE2_ANDROID 1
70-
#define CAFFE2_MOBILE 1
71-
#elif (defined(__APPLE__) && \
72-
(TARGET_IPHONE_SIMULATOR || TARGET_OS_SIMULATOR || TARGET_OS_IPHONE))
73-
#define CAFFE2_IOS 1
74-
#define CAFFE2_MOBILE 1
75-
#elif (defined(__APPLE__) && TARGET_OS_MAC)
76-
#define CAFFE2_IOS 1
77-
#define CAFFE2_MOBILE 0
78-
#else
79-
#define CAFFE2_MOBILE 0
80-
#endif // ANDROID / IOS / MACOS
81-
#endif // CAFFE2_MOBILE
82-
8365
// Define alignment macro that is cross platform
8466
#if defined(_MSC_VER)
8567
#define CAFFE2_ALIGNED(x) __declspec(align(x))

caffe2/core/macros.h.in

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ static_assert(
2323
(CAFFE2_VERSION_MAJOR * 10000 + CAFFE2_VERSION_MINOR * 100 + \
2424
CAFFE2_VERSION_PATCH)
2525

26-
#cmakedefine CAFFE2_ANDROID
2726
#cmakedefine CAFFE2_BUILD_SHARED_LIBS
2827
#cmakedefine CAFFE2_FORCE_FALLBACK_CUDA_MPI
2928
#cmakedefine CAFFE2_HAS_MKL_DNN

caffe2/mobile/contrib/ios/ios_caffe_predictor.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "caffe2/core/flags.h"
33
#include "caffe2/core/tensor.h"
44

5-
#if defined(CAFFE2_USE_MPSCNN) && CAFFE2_MOBILE
5+
#if defined(CAFFE2_USE_MPSCNN) && C10_MOBILE
66
#include "caffe2/mobile/contrib/ios/mpscnn/mpscnn.h"
77
#endif
88

@@ -14,7 +14,7 @@ Caffe2IOSPredictor* Caffe2IOSPredictor::NewCaffe2IOSPredictor(const caffe2::NetD
1414
bool allowMetalOperators) {
1515
caffe2::NetDef metal_predict_net;
1616
bool usingMetalOperators = false;
17-
#if defined(CAFFE2_USE_MPSCNN) && CAFFE2_MOBILE
17+
#if defined(CAFFE2_USE_MPSCNN) && C10_MOBILE
1818
if (allowMetalOperators) {
1919
caffe2::dumpDef(predict_net);
2020
if (caffe2::tryConvertToMPSCNN(init_net, predict_net, &metal_predict_net)) {
@@ -38,7 +38,7 @@ Caffe2IOSPredictor::Caffe2IOSPredictor(const caffe2::NetDef& init_net,
3838
bool disableMultithreadProcessing,
3939
bool usingMetalOperators)
4040
: usingMetalOperators(usingMetalOperators), predictor_(init_net, predict_net) {
41-
#if CAFFE2_MOBILE
41+
#if C10_MOBILE
4242
if (disableMultithreadProcessing) {
4343
caffe2::ThreadPool* threadpool = predictor_.ws()->GetThreadPool();
4444
if (threadpool != nullptr) {

caffe2/mobile/contrib/ios/mpscnn/mpscnn.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "caffe2/core/common.h"
22
#include "caffe2/core/context.h"
33

4-
#if defined(CAFFE2_USE_MPSCNN) && CAFFE2_MOBILE
4+
#if defined(CAFFE2_USE_MPSCNN) && C10_MOBILE
55

66
#include "caffe2/core/operator.h"
77
#include "caffe2/core/timer.h"

caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#include "caffe2/core/common.h"
33

4-
#if CAFFE2_MOBILE
4+
#if C10_MOBILE
55

66
#include "mpscnn_context.h"
77
#include "mpscnn_kernels.h"

caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "caffe2/core/common.h"
22

3-
#if CAFFE2_MOBILE && defined(CAFFE2_USE_MPSCNN_TEST)
3+
#if C10_MOBILE && defined(CAFFE2_USE_MPSCNN_TEST)
44

55
#include "mpscnn_context.h"
66
#include "mpscnn_graph_mask.h"

caffe2/mobile/contrib/ulp2/ulp.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ std::unique_ptr<QConvState> create2b1bConvState(Workspace* ws,
280280
// r->WQL1Norm.mutable_data<float>()[i] *= center_distance;
281281
// }
282282
state->parallelFor = [ws](size_t range, std::function<void(size_t)> f) {
283-
#if CAFFE2_MOBILE
283+
#if C10_MOBILE
284284
ws->GetThreadPool()->run([&](int, size_t v) { f(v); }, range);
285285
#else
286286
for (size_t v = 0; v < range; ++v) {

caffe2/observers/runcnt_observer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RunCountOperatorObserver::RunCountOperatorObserver(
1010
}
1111

1212
std::string RunCountNetObserver::debugInfo() {
13-
#if CAFFE2_ANDROID
13+
#if C10_ANDROID
1414
// workaround
1515
int foo = cnt_;
1616
return "This operator runs " + c10::to_string(foo) + " times.";

caffe2/onnx/backend.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "caffe2/utils/map_utils.h"
77
#include "caffe2/utils/proto_utils.h"
88

9-
#if !CAFFE2_MOBILE
9+
#if !C10_MOBILE
1010
#include "onnx/checker.h"
1111
#include "onnx/optimizer/optimize.h"
1212
#endif
@@ -69,7 +69,7 @@ caffe2::DeviceOption GetDeviceOption(const Device& onnx_device) {
6969
return d;
7070
}
7171

72-
#if !CAFFE2_MOBILE
72+
#if !C10_MOBILE
7373
ModelProto OptimizeOnnx(const ModelProto& input, bool init) {
7474
std::vector<std::string> passes{"fuse_consecutive_transposes",
7575
"eliminate_nop_transpose",
@@ -1456,7 +1456,7 @@ void Caffe2Backend::OnnxToCaffe2(
14561456
const std::vector<Caffe2Ops>& extras) {
14571457
auto device_option = GetDeviceOption(Device(device));
14581458

1459-
#if !CAFFE2_MOBILE
1459+
#if !C10_MOBILE
14601460
ModelProto init_model = OptimizeOnnx(onnx_model, true);
14611461
ModelProto pred_model = OptimizeOnnx(onnx_model, false);
14621462
#else
@@ -1560,7 +1560,7 @@ Caffe2BackendRep* Caffe2Backend::Prepare(
15601560
ModelProto onnx_model;
15611561
ParseProtoFromLargeString(onnx_model_str, &onnx_model);
15621562

1563-
#if !CAFFE2_MOBILE
1563+
#if !C10_MOBILE
15641564
::ONNX_NAMESPACE::checker::check_model(onnx_model);
15651565
#endif
15661566

caffe2/operators/conv_transpose_op_mobile.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
namespace caffe2 {
55

6-
#ifndef CAFFE2_MOBILE
6+
#ifndef C10_MOBILE
77
#error "mobile build state not defined"
88
#endif
99

10-
#if CAFFE2_MOBILE
10+
#if C10_MOBILE
1111
// mobile-only implementation (tiled + vectorized + multithreaded)
1212
REGISTER_CPU_OPERATOR_WITH_ENGINE(
1313
ConvTranspose,

caffe2/operators/conv_transpose_op_mobile.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
#include "caffe2/core/common.h"
55

6-
#ifndef CAFFE2_MOBILE
6+
#ifndef C10_MOBILE
77
#error "mobile build state not defined"
88
#endif
99

10-
#if CAFFE2_MOBILE
10+
#if C10_MOBILE
1111

1212
#include "caffe2/core/context.h"
1313
#include "caffe2/core/operator.h"
@@ -44,6 +44,6 @@ class ConvTransposeMobileOp final : public ConvTransposeUnpoolBase<Context> {
4444

4545
} // namespace caffe2
4646

47-
#endif // CAFFE2_MOBILE
47+
#endif // C10_MOBILE
4848

4949
#endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_H_

caffe2/operators/conv_transpose_op_mobile_impl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#include "caffe2/core/common.h"
77

8-
#ifndef CAFFE2_MOBILE
8+
#ifndef C10_MOBILE
99
#error "mobile build state not defined"
1010
#endif
1111

12-
#if CAFFE2_MOBILE
12+
#if C10_MOBILE
1313

1414
#include "caffe2/core/logging.h"
1515
#include "caffe2/operators/conv_op_shared.h"
@@ -695,6 +695,6 @@ bool ConvTransposeMobileOp<T, Context>::RunOnDeviceWithOrderNHWC() {
695695

696696
} // namespace caffe2
697697

698-
#endif // CAFFE2_MOBILE
698+
#endif // C10_MOBILE
699699

700700
#endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_IMPL_H_

caffe2/predictor/predictor_config.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ PredictorConfig makePredictorConfig(
7171
if (run_init) {
7272
CAFFE_ENFORCE(ws.RunNetOnce(init_net));
7373
}
74-
#if CAFFE2_MOBILE
74+
#if C10_MOBILE
7575
GlobalInit();
7676
#endif
7777
if (optimization &&

caffe2/share/contrib/depthwise/depthwise3x3_conv_op.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ class Depthwise3x3ConvOp final : public ConvPoolOpBase<CPUContext> {
489489

490490
Timer t;
491491

492-
#if CAFFE2_MOBILE
492+
#if C10_MOBILE
493493
ws_->GetThreadPool()->run(
494494
[&](int, int n_g) {
495495
const int g = n_g / N;

caffe2/utils/signal_handler.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "caffe2/core/init.h"
2424
#include "caffe2/core/workspace.h"
2525

26-
#if CAFFE2_ANDROID
26+
#if C10_ANDROID
2727
#ifndef SYS_gettid
2828
#define SYS_gettid __NR_gettid
2929
#endif

caffe2/utils/threadpool/ThreadPool.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ std::unique_ptr<ThreadPool> ThreadPool::defaultThreadPool() {
2626
int numThreads = cpuinfo_get_processors_count();
2727

2828
bool applyCap = false;
29-
#if CAFFE2_ANDROID
29+
#if C10_ANDROID
3030
applyCap = FLAGS_caffe2_threadpool_android_cap;
31-
#elif CAFFE2_IOS
31+
#elif C10_IOS
3232
applyCap = FLAGS_caffe2_threadpool_ios_cap;
3333
#endif
3434

3535
if (applyCap) {
3636
switch (numThreads) {
37-
#if CAFFE2_ANDROID && (CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64)
37+
#if C10_ANDROID && (CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64)
3838
case 4:
3939
switch (cpuinfo_get_core(0)->midr & UINT32_C(0xFF00FFF0)) {
4040
case UINT32_C(0x51002110): /* Snapdragon 820 Kryo Silver */

caffe2/utils/threadpool/ThreadPoolCommon.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// caffe2 depends upon NNPACK, which depends upon this threadpool, so
99
// unfortunately we can't reference core/common.h here
1010

11-
// This is copied from core/common.h's definition of CAFFE2_MOBILE
11+
// This is copied from core/common.h's definition of C10_MOBILE
1212
// Define enabled when building for iOS or Android devices
1313
#if defined(__ANDROID__)
14-
#define CAFFE2_ANDROID 1
14+
#define C10_ANDROID 1
1515
#elif (defined(__APPLE__) && \
1616
(TARGET_IPHONE_SIMULATOR || TARGET_OS_SIMULATOR || TARGET_OS_IPHONE))
17-
#define CAFFE2_IOS 1
17+
#define C10_IOS 1
1818
#elif (defined(__APPLE__) && TARGET_OS_MAC)
19-
#define CAFFE2_IOS 1
19+
#define C10_IOS 1
2020
#else
2121
#endif // ANDROID / IOS / MACOS
2222

modules/observers/perf_observer.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "observers/perf_observer.h"
22
#include "observers/observer_config.h"
3-
#if !CAFFE2_MOBILE
3+
#if !C10_MOBILE
44
#include "caffe2/core/flags.h"
55
#include "observers/net_observer_reporter_print.h"
66
#endif
@@ -10,7 +10,7 @@
1010
#include "caffe2/core/init.h"
1111
#include "caffe2/core/operator.h"
1212

13-
#if !CAFFE2_MOBILE
13+
#if !C10_MOBILE
1414
C10_DEFINE_int64(
1515
aiBench_netInitSampleRate,
1616
0,
@@ -45,7 +45,7 @@ bool registerGlobalPerfNetObserverCreator(int* /*pargc*/, char*** /*pargv*/) {
4545
return caffe2::make_unique<PerfNetObserver>(subject);
4646
});
4747

48-
#if !CAFFE2_MOBILE
48+
#if !C10_MOBILE
4949
// for aibench usage
5050
caffe2::ObserverConfig::setReporter(
5151
caffe2::make_unique<caffe2::NetObserverReporterPrint>());

0 commit comments

Comments
 (0)