use C10_MOBILE/ANDROID/IOS (#15363)
authorJerry Zhang <jerryzh@fb.com>
Wed, 9 Jan 2019 23:05:29 +0000 (15:05 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 9 Jan 2019 23:08:20 +0000 (15:08 -0800)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/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

18 files changed:
caffe2/core/common.h
caffe2/core/macros.h.in
caffe2/mobile/contrib/ios/ios_caffe_predictor.cc
caffe2/mobile/contrib/ios/mpscnn/mpscnn.mm
caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.mm
caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.mm
caffe2/mobile/contrib/ulp2/ulp.cc
caffe2/observers/runcnt_observer.cc
caffe2/onnx/backend.cc
caffe2/operators/conv_transpose_op_mobile.cc
caffe2/operators/conv_transpose_op_mobile.h
caffe2/operators/conv_transpose_op_mobile_impl.h
caffe2/predictor/predictor_config.cc
caffe2/share/contrib/depthwise/depthwise3x3_conv_op.cc
caffe2/utils/signal_handler.cc
caffe2/utils/threadpool/ThreadPool.cc
caffe2/utils/threadpool/ThreadPoolCommon.h
modules/observers/perf_observer.cc

index 2aee5e6..4bc041d 100644 (file)
 
 // Macros used during the build of this caffe2 instance. This header file
 // is automatically generated by the cmake script during build.
-#include "caffe2/core/common.h"
 #include "caffe2/core/macros.h"
 
-#include "c10/macros/Macros.h"
+#include <c10/macros/Macros.h>
 
 #include "c10/util/string_utils.h"
 
@@ -63,23 +62,6 @@ using std::vector;
 #define CAFFE2_USED __attribute__((__used__))
 #endif //_MSC_VER
 
-// Define enabled when building for iOS or Android devices
-#if !defined(CAFFE2_MOBILE)
-#if defined(__ANDROID__)
-#define CAFFE2_ANDROID 1
-#define CAFFE2_MOBILE 1
-#elif (defined(__APPLE__) &&                                            \
-       (TARGET_IPHONE_SIMULATOR || TARGET_OS_SIMULATOR || TARGET_OS_IPHONE))
-#define CAFFE2_IOS 1
-#define CAFFE2_MOBILE 1
-#elif (defined(__APPLE__) && TARGET_OS_MAC)
-#define CAFFE2_IOS 1
-#define CAFFE2_MOBILE 0
-#else
-#define CAFFE2_MOBILE 0
-#endif // ANDROID / IOS / MACOS
-#endif // CAFFE2_MOBILE
-
 // Define alignment macro that is cross platform
 #if defined(_MSC_VER)
 #define CAFFE2_ALIGNED(x) __declspec(align(x))
index 8c2d18f..12a472a 100644 (file)
@@ -23,7 +23,6 @@ static_assert(
   (CAFFE2_VERSION_MAJOR * 10000 + CAFFE2_VERSION_MINOR * 100 + \
    CAFFE2_VERSION_PATCH)
 
-#cmakedefine CAFFE2_ANDROID
 #cmakedefine CAFFE2_BUILD_SHARED_LIBS
 #cmakedefine CAFFE2_FORCE_FALLBACK_CUDA_MPI
 #cmakedefine CAFFE2_HAS_MKL_DNN
index 2119032..65214ce 100644 (file)
@@ -2,7 +2,7 @@
 #include "caffe2/core/flags.h"
 #include "caffe2/core/tensor.h"
 
-#if defined(CAFFE2_USE_MPSCNN) && CAFFE2_MOBILE
+#if defined(CAFFE2_USE_MPSCNN) && C10_MOBILE
 #include "caffe2/mobile/contrib/ios/mpscnn/mpscnn.h"
 #endif
 
@@ -14,7 +14,7 @@ Caffe2IOSPredictor* Caffe2IOSPredictor::NewCaffe2IOSPredictor(const caffe2::NetD
                                                               bool allowMetalOperators) {
   caffe2::NetDef metal_predict_net;
   bool usingMetalOperators = false;
-#if defined(CAFFE2_USE_MPSCNN) && CAFFE2_MOBILE
+#if defined(CAFFE2_USE_MPSCNN) && C10_MOBILE
   if (allowMetalOperators) {
     caffe2::dumpDef(predict_net);
     if (caffe2::tryConvertToMPSCNN(init_net, predict_net, &metal_predict_net)) {
@@ -38,7 +38,7 @@ Caffe2IOSPredictor::Caffe2IOSPredictor(const caffe2::NetDef& init_net,
                                        bool disableMultithreadProcessing,
                                        bool usingMetalOperators)
     : usingMetalOperators(usingMetalOperators), predictor_(init_net, predict_net) {
-#if CAFFE2_MOBILE
+#if C10_MOBILE
   if (disableMultithreadProcessing) {
     caffe2::ThreadPool* threadpool = predictor_.ws()->GetThreadPool();
     if (threadpool != nullptr) {
index aa6a547..8db103c 100644 (file)
@@ -1,7 +1,7 @@
 #include "caffe2/core/common.h"
 #include "caffe2/core/context.h"
 
-#if defined(CAFFE2_USE_MPSCNN) && CAFFE2_MOBILE
+#if defined(CAFFE2_USE_MPSCNN) && C10_MOBILE
 
 #include "caffe2/core/operator.h"
 #include "caffe2/core/timer.h"
index e52534f..3553213 100644 (file)
@@ -1,7 +1,7 @@
 
 #include "caffe2/core/common.h"
 
-#if CAFFE2_MOBILE
+#if C10_MOBILE
 
 #include "mpscnn_context.h"
 #include "mpscnn_kernels.h"
index 7ac6290..543d776 100644 (file)
@@ -1,6 +1,6 @@
 #include "caffe2/core/common.h"
 
-#if CAFFE2_MOBILE && defined(CAFFE2_USE_MPSCNN_TEST)
+#if C10_MOBILE && defined(CAFFE2_USE_MPSCNN_TEST)
 
 #include "mpscnn_context.h"
 #include "mpscnn_graph_mask.h"
index e003312..6ed85aa 100644 (file)
@@ -280,7 +280,7 @@ std::unique_ptr<QConvState> create2b1bConvState(Workspace* ws,
   //   r->WQL1Norm.mutable_data<float>()[i] *= center_distance;
   // }
   state->parallelFor = [ws](size_t range, std::function<void(size_t)> f) {
-#if CAFFE2_MOBILE
+#if C10_MOBILE
     ws->GetThreadPool()->run([&](int, size_t v) { f(v); }, range);
 #else
     for (size_t v = 0; v < range; ++v) {
index c309f6f..9763e8e 100644 (file)
@@ -10,7 +10,7 @@ RunCountOperatorObserver::RunCountOperatorObserver(
 }
 
 std::string RunCountNetObserver::debugInfo() {
-#if CAFFE2_ANDROID
+#if C10_ANDROID
   // workaround
   int foo = cnt_;
   return "This operator runs " + c10::to_string(foo) + " times.";
index 481b295..7ea113f 100644 (file)
@@ -6,7 +6,7 @@
 #include "caffe2/utils/map_utils.h"
 #include "caffe2/utils/proto_utils.h"
 
-#if !CAFFE2_MOBILE
+#if !C10_MOBILE
 #include "onnx/checker.h"
 #include "onnx/optimizer/optimize.h"
 #endif
@@ -69,7 +69,7 @@ caffe2::DeviceOption GetDeviceOption(const Device& onnx_device) {
   return d;
 }
 
-#if !CAFFE2_MOBILE
+#if !C10_MOBILE
 ModelProto OptimizeOnnx(const ModelProto& input, bool init) {
   std::vector<std::string> passes{"fuse_consecutive_transposes",
                                   "eliminate_nop_transpose",
@@ -1456,7 +1456,7 @@ void Caffe2Backend::OnnxToCaffe2(
     const std::vector<Caffe2Ops>& extras) {
   auto device_option = GetDeviceOption(Device(device));
 
-#if !CAFFE2_MOBILE
+#if !C10_MOBILE
   ModelProto init_model = OptimizeOnnx(onnx_model, true);
   ModelProto pred_model = OptimizeOnnx(onnx_model, false);
 #else
@@ -1560,7 +1560,7 @@ Caffe2BackendRep* Caffe2Backend::Prepare(
   ModelProto onnx_model;
   ParseProtoFromLargeString(onnx_model_str, &onnx_model);
 
-#if !CAFFE2_MOBILE
+#if !C10_MOBILE
   ::ONNX_NAMESPACE::checker::check_model(onnx_model);
 #endif
 
index 468d46c..eec8692 100644 (file)
@@ -3,11 +3,11 @@
 
 namespace caffe2 {
 
-#ifndef CAFFE2_MOBILE
+#ifndef C10_MOBILE
 #error "mobile build state not defined"
 #endif
 
-#if CAFFE2_MOBILE
+#if C10_MOBILE
 // mobile-only implementation (tiled + vectorized + multithreaded)
 REGISTER_CPU_OPERATOR_WITH_ENGINE(
     ConvTranspose,
index 568dd34..ba4a767 100644 (file)
@@ -3,11 +3,11 @@
 
 #include "caffe2/core/common.h"
 
-#ifndef CAFFE2_MOBILE
+#ifndef C10_MOBILE
 #error "mobile build state not defined"
 #endif
 
-#if CAFFE2_MOBILE
+#if C10_MOBILE
 
 #include "caffe2/core/context.h"
 #include "caffe2/core/operator.h"
@@ -44,6 +44,6 @@ class ConvTransposeMobileOp final : public ConvTransposeUnpoolBase<Context> {
 
 } // namespace caffe2
 
-#endif // CAFFE2_MOBILE
+#endif // C10_MOBILE
 
 #endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_H_
index 4f3f3cc..5b4a8c7 100644 (file)
@@ -5,11 +5,11 @@
 
 #include "caffe2/core/common.h"
 
-#ifndef CAFFE2_MOBILE
+#ifndef C10_MOBILE
 #error "mobile build state not defined"
 #endif
 
-#if CAFFE2_MOBILE
+#if C10_MOBILE
 
 #include "caffe2/core/logging.h"
 #include "caffe2/operators/conv_op_shared.h"
@@ -695,6 +695,6 @@ bool ConvTransposeMobileOp<T, Context>::RunOnDeviceWithOrderNHWC() {
 
 } // namespace caffe2
 
-#endif // CAFFE2_MOBILE
+#endif // C10_MOBILE
 
 #endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_IMPL_H_
index cabbd4b..ab735a9 100644 (file)
@@ -71,7 +71,7 @@ PredictorConfig makePredictorConfig(
   if (run_init) {
     CAFFE_ENFORCE(ws.RunNetOnce(init_net));
   }
-#if CAFFE2_MOBILE
+#if C10_MOBILE
   GlobalInit();
 #endif
   if (optimization &&
index 04028e0..7b1c662 100644 (file)
@@ -489,7 +489,7 @@ class Depthwise3x3ConvOp final : public ConvPoolOpBase<CPUContext> {
 
     Timer t;
 
-#if CAFFE2_MOBILE
+#if C10_MOBILE
     ws_->GetThreadPool()->run(
         [&](int, int n_g) {
           const int g = n_g / N;
index 57ad0ad..5620eb8 100644 (file)
@@ -23,7 +23,7 @@
 #include "caffe2/core/init.h"
 #include "caffe2/core/workspace.h"
 
-#if CAFFE2_ANDROID
+#if C10_ANDROID
 #ifndef SYS_gettid
 #define SYS_gettid __NR_gettid
 #endif
index 40930c4..cf0dbc2 100644 (file)
@@ -26,15 +26,15 @@ std::unique_ptr<ThreadPool> ThreadPool::defaultThreadPool() {
   int numThreads = cpuinfo_get_processors_count();
 
   bool applyCap = false;
-#if CAFFE2_ANDROID
+#if C10_ANDROID
   applyCap = FLAGS_caffe2_threadpool_android_cap;
-#elif CAFFE2_IOS
+#elif C10_IOS
   applyCap = FLAGS_caffe2_threadpool_ios_cap;
 #endif
 
   if (applyCap) {
     switch (numThreads) {
-#if CAFFE2_ANDROID && (CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64)
+#if C10_ANDROID && (CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64)
       case 4:
           switch (cpuinfo_get_core(0)->midr & UINT32_C(0xFF00FFF0)) {
             case UINT32_C(0x51002110): /* Snapdragon 820 Kryo Silver */
index 997b5b1..2448914 100644 (file)
@@ -8,15 +8,15 @@
 // caffe2 depends upon NNPACK, which depends upon this threadpool, so
 // unfortunately we can't reference core/common.h here
 
-// This is copied from core/common.h's definition of CAFFE2_MOBILE
+// This is copied from core/common.h's definition of C10_MOBILE
 // Define enabled when building for iOS or Android devices
 #if defined(__ANDROID__)
-#define CAFFE2_ANDROID 1
+#define C10_ANDROID 1
 #elif (defined(__APPLE__) &&                                            \
        (TARGET_IPHONE_SIMULATOR || TARGET_OS_SIMULATOR || TARGET_OS_IPHONE))
-#define CAFFE2_IOS 1
+#define C10_IOS 1
 #elif (defined(__APPLE__) && TARGET_OS_MAC)
-#define CAFFE2_IOS 1
+#define C10_IOS 1
 #else
 #endif // ANDROID / IOS / MACOS
 
index 0ef59ce..ea5d22c 100644 (file)
@@ -1,6 +1,6 @@
 #include "observers/perf_observer.h"
 #include "observers/observer_config.h"
-#if !CAFFE2_MOBILE
+#if !C10_MOBILE
 #include "caffe2/core/flags.h"
 #include "observers/net_observer_reporter_print.h"
 #endif
@@ -10,7 +10,7 @@
 #include "caffe2/core/init.h"
 #include "caffe2/core/operator.h"
 
-#if !CAFFE2_MOBILE
+#if !C10_MOBILE
 C10_DEFINE_int64(
     aiBench_netInitSampleRate,
     0,
@@ -45,7 +45,7 @@ bool registerGlobalPerfNetObserverCreator(int* /*pargc*/, char*** /*pargv*/) {
     return caffe2::make_unique<PerfNetObserver>(subject);
   });
 
-#if !CAFFE2_MOBILE
+#if !C10_MOBILE
   // for aibench usage
   caffe2::ObserverConfig::setReporter(
       caffe2::make_unique<caffe2::NetObserverReporterPrint>());