Skip to content

Commit cbd1b32

Browse files
committed
Xu separate python so (#1186)
* separate common python so. * add pybind11 abi to complier flags.
1 parent 6aa5dce commit cbd1b32

File tree

20 files changed

+297
-57
lines changed

20 files changed

+297
-57
lines changed

cmake/python/BuildOptions.cmake

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
## Included by CMakeLists
2+
if(PYTHON_BUILD_OPTIONS_cmake_included)
3+
return()
4+
endif()
5+
set(PYTHON_BUILD_OPTIONS_cmake_included true)
6+
7+
# check and set CMAKE_CXX_STANDARD
8+
string(FIND "${CMAKE_CXX_FLAGS}" "-std=c++" env_cxx_standard)
9+
if(env_cxx_standard GREATER -1)
10+
message(
11+
WARNING "C++ standard version definition detected in environment variable."
12+
"PyTorch requires -std=c++14. Please remove -std=c++ settings in your environment.")
13+
endif()
14+
set(CMAKE_CXX_STANDARD 14)
15+
set(CMAKE_C_STANDARD 11)
16+
set(CMAKE_CXX_EXTENSIONS OFF)
17+
18+
set(_CXX11_ABI_FLAG 0)
19+
if(DEFINED GLIBCXX_USE_CXX11_ABI)
20+
if(${GLIBCXX_USE_CXX11_ABI} EQUAL 1)
21+
set(CXX_STANDARD_REQUIRED ON)
22+
set(_CXX11_ABI_FLAG 1)
23+
endif()
24+
endif()
25+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=${_CXX11_ABI_FLAG}")
26+
27+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
28+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
29+
# Eigen fails to build with some versions, so convert this to a warning
30+
# Details at http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1459
31+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
32+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
33+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
34+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-type-limits")
35+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-array-bounds")
36+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
37+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
38+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
39+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
40+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
41+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result")
42+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-overflow")
43+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing")
44+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations")
45+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ignored-qualifiers")
46+
if (CMAKE_COMPILER_IS_GNUCXX AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0))
47+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-overflow")
48+
endif()
49+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=pedantic")
50+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=redundant-decls")
51+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=old-style-cast")
52+
53+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
54+
# These flags are not available in GCC-4.8.5. Set only when using clang.
55+
# Compared against https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/Option-Summary.html
56+
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
57+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-partial-specialization")
58+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-typedef-redefinition")
59+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
60+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field")
61+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")
62+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-aligned-allocation-unavailable")
63+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++14-extensions")
64+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-constexpr-not-const")
65+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces")
66+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
67+
if (${COLORIZE_OUTPUT})
68+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
69+
endif()
70+
endif()
71+
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
72+
if (${COLORIZE_OUTPUT})
73+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
74+
endif()
75+
endif()
76+
if ((APPLE AND (NOT ("${CLANG_VERSION_STRING}" VERSION_LESS "9.0")))
77+
OR (CMAKE_COMPILER_IS_GNUCXX
78+
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 AND NOT APPLE)))
79+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -faligned-new")
80+
endif()
81+
if (WERROR)
82+
check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
83+
if (NOT COMPILER_SUPPORT_WERROR)
84+
set(WERROR FALSE)
85+
else()
86+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
87+
endif()
88+
endif(WERROR)
89+
if (NOT APPLE)
90+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")
91+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-uninitialized")
92+
endif()
93+
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -O0")
94+
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -O0")
95+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-math-errno")
96+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math")
97+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-Bsymbolic-functions")
98+
99+
# Define build type
100+
IF(CMAKE_BUILD_TYPE MATCHES Debug)
101+
message("Debug build.")
102+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DEBUG")
103+
ELSEIF(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
104+
message("RelWithDebInfo build")
105+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
106+
ELSE()
107+
message("Release build.")
108+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
109+
ENDIF()
110+
111+
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
112+
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
113+
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")

csrc/cpu/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ else()
8383
message(FATAL_ERROR, "Cannot find installed PyTorch directory")
8484
endif()
8585

86+
if(DEFINED PYBIND11_CL_FLAGS)
87+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PYBIND11_CL_FLAGS}")
88+
else()
89+
message(FATAL_ERROR, "Cannot get pybind11 abi compiler flags")
90+
endif()
91+
8692
# Set Python include dir
8793
if(DEFINED PYTHON_INCLUDE_DIR)
8894
include_directories(${PYTHON_INCLUDE_DIR})

csrc/cpu/autocast/autocast_kernels.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
namespace torch_ipex {
1313
namespace autocast {
1414

15-
void _amp_foreach_non_finite_check_and_unscale_cpu_(
15+
TORCH_API void _amp_foreach_non_finite_check_and_unscale_cpu_(
1616
std::vector<at::Tensor> scaled_grads,
1717
at::Tensor& found_inf,
1818
const at::Tensor& inv_scale);
1919

20-
at::Tensor& _amp_update_scale_cpu_(
20+
TORCH_API at::Tensor& _amp_update_scale_cpu_(
2121
at::Tensor& current_scale,
2222
at::Tensor& growth_tracker,
2323
const at::Tensor& found_inf,

csrc/cpu/autocast/autocast_mode.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using at::Tensor;
1616
using at::TensorList;
1717
using namespace c10;
1818

19-
enum class DtypeCastPolicy : uint8_t {
19+
enum class TORCH_API DtypeCastPolicy : uint8_t {
2020
user_defined_dtype = 0,
2121
fp32, // Cast all inputs to at::kFloat before running the op.
2222
fp32_set_opt_dtype, // Treats functions (like softmax) that
@@ -38,9 +38,9 @@ enum class DtypeCastPolicy : uint8_t {
3838
fallthrough, // Do not cast inputs.
3939
};
4040

41-
at::ScalarType get_autocast_dtype();
42-
void set_autocast_dtype(at::ScalarType dtype);
43-
void clear_autocast_cache();
41+
TORCH_API at::ScalarType get_autocast_dtype();
42+
TORCH_API void set_autocast_dtype(at::ScalarType dtype);
43+
TORCH_API void clear_autocast_cache();
4444

4545
Tensor cpu_cached_cast(at::ScalarType to_type, const Tensor& arg);
4646

csrc/cpu/runtime/CPUPool.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <mutex>
88
#include <vector>
99

10+
#include <torch/csrc/jit/api/module.h>
11+
1012
namespace torch_ipex {
1113
namespace runtime {
1214

@@ -18,7 +20,7 @@ typedef void (*kmp_destroy_affinity_mask_p)(kmp_affinity_mask_t*);
1820
typedef int (*kmp_get_affinity_p)(kmp_affinity_mask_t*);
1921
typedef int (*kmp_get_affinity_max_proc_p)();
2022

21-
class CPUPool {
23+
class TORCH_API CPUPool {
2224
public:
2325
explicit CPUPool(const std::vector<int32_t>& cpu_core_list);
2426
explicit CPUPool(std::vector<kmp_affinity_mask_t>&& cpu_core_mask);
@@ -48,19 +50,20 @@ class CPUPool {
4850
CPUPool& operator=(CPUPool&& source_cpu_pool) = delete;
4951
};
5052

51-
std::vector<int32_t> init_process_available_cores();
52-
std::vector<int32_t> get_process_available_cores();
53-
std::vector<int32_t> filter_cores_by_thread_affinity(
53+
TORCH_API std::vector<int32_t> init_process_available_cores();
54+
TORCH_API std::vector<int32_t> get_process_available_cores();
55+
TORCH_API std::vector<int32_t> filter_cores_by_thread_affinity(
5456
const std::vector<int32_t>& cpu_core_list);
5557
bool do_load_iomp_symbol();
56-
bool is_runtime_ext_enabled();
57-
void init_runtime_ext();
58-
void _pin_cpu_cores(const torch_ipex::runtime::CPUPool& cpu_pool);
59-
bool is_same_core_affinity_setting(const std::vector<int32_t>& cpu_core_list);
60-
CPUPool get_cpu_pool_from_mask_affinity();
61-
void set_mask_affinity_from_cpu_pool(const CPUPool& cpu_pool);
58+
TORCH_API bool is_runtime_ext_enabled();
59+
TORCH_API void init_runtime_ext();
60+
TORCH_API void _pin_cpu_cores(const torch_ipex::runtime::CPUPool& cpu_pool);
61+
TORCH_API bool is_same_core_affinity_setting(
62+
const std::vector<int32_t>& cpu_core_list);
63+
TORCH_API CPUPool get_cpu_pool_from_mask_affinity();
64+
TORCH_API void set_mask_affinity_from_cpu_pool(const CPUPool& cpu_pool);
6265

63-
class WithCPUPool {
66+
class TORCH_API WithCPUPool {
6467
public:
6568
explicit WithCPUPool(CPUPool&& cpu_pool)
6669
: previous_cpu_pool(

csrc/cpu/runtime/Task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace runtime {
1818
// refer to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2709.html
1919
/*Task is used to handle input of general C++ functions*/
2020
template <class F, class... Args>
21-
class Task {
21+
class TORCH_API Task {
2222
public:
2323
explicit Task(F&& f, std::shared_ptr<TaskExecutor> task_executor);
2424
Task(const Task& task) = delete;

csrc/cpu/runtime/TaskExecutor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace torch_ipex {
2323
namespace runtime {
2424

25-
class TaskExecutor {
25+
class TORCH_API TaskExecutor {
2626
public:
2727
explicit TaskExecutor(const torch_ipex::runtime::CPUPool& cpu_pool);
2828
std::mutex& get_mutex();

csrc/cpu/utils/fpmath_mode.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#include <torch/csrc/jit/api/module.h>
2+
13
namespace torch_ipex {
24

3-
enum FP32MathMode : int { FP32 = 0, TF32 = 1, BF32 = 2 };
5+
enum TORCH_API FP32MathMode : int { FP32 = 0, TF32 = 1, BF32 = 2 };
46

5-
void setFP32MathModeCpu(FP32MathMode mode = FP32MathMode::FP32);
7+
TORCH_API void setFP32MathModeCpu(FP32MathMode mode = FP32MathMode::FP32);
68

7-
FP32MathMode getFP32MathModeCpu();
9+
TORCH_API FP32MathMode getFP32MathModeCpu();
810

911
} // namespace torch_ipex

csrc/cpu/utils/onednn_utils.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#include <torch/csrc/jit/api/module.h>
2+
13
namespace torch_ipex {
24
namespace utils {
35

4-
int onednn_set_verbose(int level);
5-
bool onednn_has_bf16_type_support();
6-
bool onednn_has_fp16_type_support();
6+
TORCH_API int onednn_set_verbose(int level);
7+
TORCH_API bool onednn_has_bf16_type_support();
8+
TORCH_API bool onednn_has_fp16_type_support();
79

810
} // namespace utils
911
} // namespace torch_ipex

csrc/jit/auto_opt_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace torch_ipex {
55

6-
class AutoOptConfig {
6+
class TORCH_API AutoOptConfig {
77
public:
88
static AutoOptConfig& singleton() {
99
static AutoOptConfig auto_opt_conf;

0 commit comments

Comments
 (0)