preprocessor cleanup (#33957)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33957

lots of small preprocessor warning cleanup for windows

Test Plan: CI green

Reviewed By: malfet, albanD

Differential Revision: D20153582

fbshipit-source-id: 18fd61c466fd1f55ededdae4448b3009a9cedc04
This commit is contained in:
Michael Ranieri
2020-03-02 13:34:22 -08:00
committed by Facebook Github Bot
parent 4b3ae7e0af
commit 51d969e86a
10 changed files with 20 additions and 9 deletions

View File

@@ -4,7 +4,9 @@
#include <random>
// define constants like M_PI and C keywords for MSVC
#ifdef _MSC_VER
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#endif
#include <ATen/ATen.h>

View File

@@ -10,7 +10,7 @@ RunCountOperatorObserver::RunCountOperatorObserver(
}
std::string RunCountNetObserver::debugInfo() {
#if C10_ANDROID
#ifdef C10_ANDROID
// workaround
int foo = cnt_;
return "This operator runs " + c10::to_string(foo) + " times.";

View File

@@ -8,7 +8,9 @@
#include <vector>
#ifdef _MSC_VER
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#endif // _MSC_VER

View File

@@ -1,5 +1,7 @@
#ifdef _MSC_VER
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES // For M_PI
#endif
#endif // _MSC_VER
#include <cmath>

View File

@@ -2,7 +2,9 @@
#define CAFFE2_OPERATORS_SINUSOID_POSITION_ENCODING_OP_H_
#ifdef _MSC_VER
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#endif // _MSC_VER
#include <cmath>

View File

@@ -1,13 +1,14 @@
#ifndef CAFFE2_SGD_LEARNING_RATE_FUNCTORS_H_
#define CAFFE2_SGD_LEARNING_RATE_FUNCTORS_H_
#define _USE_MATH_DEFINES
#include <cmath>
#include <list>
#include <map>
#ifdef _MSC_VER
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#endif // _MSC_VER

View File

@@ -23,7 +23,7 @@
#include "caffe2/core/init.h"
#include "caffe2/core/workspace.h"
#if C10_ANDROID
#ifdef C10_ANDROID
#ifndef SYS_gettid
#define SYS_gettid __NR_gettid
#endif

View File

@@ -36,7 +36,7 @@ struct ProxyPrinter {
const Tensor* tensor;
TensorPrinter* tensorPrinter;
};
}
} // namespace
SmartTensorPrinter::SmartTensorPrinter(const std::string& tensor_name)
: tensorPrinter_(tensor_name) {}
@@ -62,7 +62,7 @@ void SmartTensorPrinter::Print(const Tensor& tensor) {
SmartTensorPrinter& SmartTensorPrinter::DefaultTensorPrinter() {
// TODO(janusz): thread_local does not work under mac.
#if __APPLE__
#if defined(__APPLE__)
CAFFE_THROW(
"SmartTensorPrinter does not work on mac yet due to thread_local.");
#else
@@ -74,4 +74,4 @@ SmartTensorPrinter& SmartTensorPrinter::DefaultTensorPrinter() {
void SmartTensorPrinter::PrintTensor(const Tensor& tensor) {
DefaultTensorPrinter().Print(tensor);
}
}
} // namespace caffe2

View File

@@ -22,15 +22,15 @@ size_t getDefaultNumThreads() {
int numThreads = cpuinfo_get_processors_count();
bool applyCap = false;
#if C10_ANDROID
#if defined(C10_ANDROID)
applyCap = FLAGS_caffe2_threadpool_android_cap;
#elif C10_IOS
#elif defined(C10_IOS)
applyCap = FLAGS_caffe2_threadpool_ios_cap;
#endif
if (applyCap) {
switch (numThreads) {
#if C10_ANDROID && (CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64)
#if defined(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 */

View File

@@ -1,7 +1,9 @@
// NB: Must be at the top of file to avoid including the deprecated "math.h".
// https://stackoverflow.com/questions/6563810/m-pi-works-with-math-h-but-not-with-cmath-in-visual-studio
#ifdef _MSC_VER
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <cmath>
#endif