From 0c32e1b43e2fda3f85aca1a213680dcaeda9c5d3 Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Wed, 9 Jan 2019 15:05:29 -0800 Subject: [PATCH] use C10_MOBILE/ANDROID/IOS (#15363) 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 --- caffe2/core/common.h | 20 +------------------- caffe2/core/macros.h.in | 1 - caffe2/mobile/contrib/ios/ios_caffe_predictor.cc | 6 +++--- caffe2/mobile/contrib/ios/mpscnn/mpscnn.mm | 2 +- caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.mm | 2 +- caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.mm | 2 +- caffe2/mobile/contrib/ulp2/ulp.cc | 2 +- caffe2/observers/runcnt_observer.cc | 2 +- caffe2/onnx/backend.cc | 8 ++++---- caffe2/operators/conv_transpose_op_mobile.cc | 4 ++-- caffe2/operators/conv_transpose_op_mobile.h | 6 +++--- caffe2/operators/conv_transpose_op_mobile_impl.h | 6 +++--- caffe2/predictor/predictor_config.cc | 2 +- .../share/contrib/depthwise/depthwise3x3_conv_op.cc | 2 +- caffe2/utils/signal_handler.cc | 2 +- caffe2/utils/threadpool/ThreadPool.cc | 6 +++--- caffe2/utils/threadpool/ThreadPoolCommon.h | 8 ++++---- modules/observers/perf_observer.cc | 6 +++--- 18 files changed, 34 insertions(+), 53 deletions(-) diff --git a/caffe2/core/common.h b/caffe2/core/common.h index 2aee5e6..4bc041d 100644 --- a/caffe2/core/common.h +++ b/caffe2/core/common.h @@ -24,10 +24,9 @@ // 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 #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)) diff --git a/caffe2/core/macros.h.in b/caffe2/core/macros.h.in index 8c2d18f..12a472a 100644 --- a/caffe2/core/macros.h.in +++ b/caffe2/core/macros.h.in @@ -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 diff --git a/caffe2/mobile/contrib/ios/ios_caffe_predictor.cc b/caffe2/mobile/contrib/ios/ios_caffe_predictor.cc index 2119032..65214ce 100644 --- a/caffe2/mobile/contrib/ios/ios_caffe_predictor.cc +++ b/caffe2/mobile/contrib/ios/ios_caffe_predictor.cc @@ -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) { diff --git a/caffe2/mobile/contrib/ios/mpscnn/mpscnn.mm b/caffe2/mobile/contrib/ios/mpscnn/mpscnn.mm index aa6a547..8db103c 100644 --- a/caffe2/mobile/contrib/ios/mpscnn/mpscnn.mm +++ b/caffe2/mobile/contrib/ios/mpscnn/mpscnn.mm @@ -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" diff --git a/caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.mm b/caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.mm index e52534f..3553213 100644 --- a/caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.mm +++ b/caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.mm @@ -1,7 +1,7 @@ #include "caffe2/core/common.h" -#if CAFFE2_MOBILE +#if C10_MOBILE #include "mpscnn_context.h" #include "mpscnn_kernels.h" diff --git a/caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.mm b/caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.mm index 7ac6290..543d776 100644 --- a/caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.mm +++ b/caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.mm @@ -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" diff --git a/caffe2/mobile/contrib/ulp2/ulp.cc b/caffe2/mobile/contrib/ulp2/ulp.cc index e003312..6ed85aa 100644 --- a/caffe2/mobile/contrib/ulp2/ulp.cc +++ b/caffe2/mobile/contrib/ulp2/ulp.cc @@ -280,7 +280,7 @@ std::unique_ptr create2b1bConvState(Workspace* ws, // r->WQL1Norm.mutable_data()[i] *= center_distance; // } state->parallelFor = [ws](size_t range, std::function 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) { diff --git a/caffe2/observers/runcnt_observer.cc b/caffe2/observers/runcnt_observer.cc index c309f6f..9763e8e 100644 --- a/caffe2/observers/runcnt_observer.cc +++ b/caffe2/observers/runcnt_observer.cc @@ -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."; diff --git a/caffe2/onnx/backend.cc b/caffe2/onnx/backend.cc index 481b295..7ea113f 100644 --- a/caffe2/onnx/backend.cc +++ b/caffe2/onnx/backend.cc @@ -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 passes{"fuse_consecutive_transposes", "eliminate_nop_transpose", @@ -1456,7 +1456,7 @@ void Caffe2Backend::OnnxToCaffe2( const std::vector& 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 diff --git a/caffe2/operators/conv_transpose_op_mobile.cc b/caffe2/operators/conv_transpose_op_mobile.cc index 468d46c..eec8692 100644 --- a/caffe2/operators/conv_transpose_op_mobile.cc +++ b/caffe2/operators/conv_transpose_op_mobile.cc @@ -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, diff --git a/caffe2/operators/conv_transpose_op_mobile.h b/caffe2/operators/conv_transpose_op_mobile.h index 568dd34..ba4a767 100644 --- a/caffe2/operators/conv_transpose_op_mobile.h +++ b/caffe2/operators/conv_transpose_op_mobile.h @@ -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 { } // namespace caffe2 -#endif // CAFFE2_MOBILE +#endif // C10_MOBILE #endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_H_ diff --git a/caffe2/operators/conv_transpose_op_mobile_impl.h b/caffe2/operators/conv_transpose_op_mobile_impl.h index 4f3f3cc..5b4a8c7 100644 --- a/caffe2/operators/conv_transpose_op_mobile_impl.h +++ b/caffe2/operators/conv_transpose_op_mobile_impl.h @@ -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::RunOnDeviceWithOrderNHWC() { } // namespace caffe2 -#endif // CAFFE2_MOBILE +#endif // C10_MOBILE #endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_IMPL_H_ diff --git a/caffe2/predictor/predictor_config.cc b/caffe2/predictor/predictor_config.cc index cabbd4b..ab735a9 100644 --- a/caffe2/predictor/predictor_config.cc +++ b/caffe2/predictor/predictor_config.cc @@ -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 && diff --git a/caffe2/share/contrib/depthwise/depthwise3x3_conv_op.cc b/caffe2/share/contrib/depthwise/depthwise3x3_conv_op.cc index 04028e0..7b1c662 100644 --- a/caffe2/share/contrib/depthwise/depthwise3x3_conv_op.cc +++ b/caffe2/share/contrib/depthwise/depthwise3x3_conv_op.cc @@ -489,7 +489,7 @@ class Depthwise3x3ConvOp final : public ConvPoolOpBase { Timer t; -#if CAFFE2_MOBILE +#if C10_MOBILE ws_->GetThreadPool()->run( [&](int, int n_g) { const int g = n_g / N; diff --git a/caffe2/utils/signal_handler.cc b/caffe2/utils/signal_handler.cc index 57ad0ad..5620eb8 100644 --- a/caffe2/utils/signal_handler.cc +++ b/caffe2/utils/signal_handler.cc @@ -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 diff --git a/caffe2/utils/threadpool/ThreadPool.cc b/caffe2/utils/threadpool/ThreadPool.cc index 40930c4..cf0dbc2 100644 --- a/caffe2/utils/threadpool/ThreadPool.cc +++ b/caffe2/utils/threadpool/ThreadPool.cc @@ -26,15 +26,15 @@ std::unique_ptr 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 */ diff --git a/caffe2/utils/threadpool/ThreadPoolCommon.h b/caffe2/utils/threadpool/ThreadPoolCommon.h index 997b5b1..2448914 100644 --- a/caffe2/utils/threadpool/ThreadPoolCommon.h +++ b/caffe2/utils/threadpool/ThreadPoolCommon.h @@ -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 diff --git a/modules/observers/perf_observer.cc b/modules/observers/perf_observer.cc index 0ef59ce..ea5d22c 100644 --- a/modules/observers/perf_observer.cc +++ b/modules/observers/perf_observer.cc @@ -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(subject); }); -#if !CAFFE2_MOBILE +#if !C10_MOBILE // for aibench usage caffe2::ObserverConfig::setReporter( caffe2::make_unique()); -- 2.7.4