Skip to content

Commit

Permalink
use C10_MOBILE/ANDROID/IOS (pytorch#15363)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jerryzh168 authored and facebook-github-bot committed Jan 9, 2019
1 parent 5838b59 commit 0c32e1b
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 53 deletions.
20 changes: 1 addition & 19 deletions caffe2/core/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <c10/macros/Macros.h>

#include "c10/util/string_utils.h"

Expand Down Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion caffe2/core/macros.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions caffe2/mobile/contrib/ios/ios_caffe_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion caffe2/mobile/contrib/ios/mpscnn/mpscnn.mm
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.mm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include "caffe2/core/common.h"

#if CAFFE2_MOBILE
#if C10_MOBILE

#include "mpscnn_context.h"
#include "mpscnn_kernels.h"
Expand Down
2 changes: 1 addition & 1 deletion caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.mm
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion caffe2/mobile/contrib/ulp2/ulp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion caffe2/observers/runcnt_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
8 changes: 4 additions & 4 deletions caffe2/onnx/backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions caffe2/operators/conv_transpose_op_mobile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions caffe2/operators/conv_transpose_op_mobile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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_
6 changes: 3 additions & 3 deletions caffe2/operators/conv_transpose_op_mobile_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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_
2 changes: 1 addition & 1 deletion caffe2/predictor/predictor_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion caffe2/share/contrib/depthwise/depthwise3x3_conv_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion caffe2/utils/signal_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions caffe2/utils/threadpool/ThreadPool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
8 changes: 4 additions & 4 deletions caffe2/utils/threadpool/ThreadPoolCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions modules/observers/perf_observer.cc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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>());
Expand Down

0 comments on commit 0c32e1b

Please sign in to comment.