mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-14 20:57:59 +00:00
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
This commit is contained in:
parent
5838b59c5d
commit
0c32e1b43e
18 changed files with 34 additions and 53 deletions
|
|
@ -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"
|
||||
|
||||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "caffe2/core/common.h"
|
||||
|
||||
#if CAFFE2_MOBILE
|
||||
#if C10_MOBILE
|
||||
|
||||
#include "mpscnn_context.h"
|
||||
#include "mpscnn_kernels.h"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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.";
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
|
|||
|
|
@ -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 &&
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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>());
|
||||
|
|
|
|||
Loading…
Reference in a new issue