From 5a9d59c55a7ef701fa7ebf0e65da04dbefac11d7 Mon Sep 17 00:00:00 2001 From: ronnywang Date: Wed, 29 Mar 2023 10:41:04 +0800 Subject: [PATCH] auto generate a phi config header (#52224) --- .gitignore | 1 + paddle/phi/CMakeLists.txt | 3 +++ paddle/phi/config.h.in | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 paddle/phi/config.h.in diff --git a/.gitignore b/.gitignore index 8336e1d976b..56d34af5d53 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ paddle/phi/api/lib/sparse_bw_api.cc paddle/phi/api/lib/tensor_api.cc paddle/phi/api/lib/tensor_operants.cc paddle/phi/extension.h +paddle/phi/config.h paddle/phi/include/* paddle/phi/infermeta/generated.* paddle/fluid/prim/api/generated_prim/*.cc diff --git a/paddle/phi/CMakeLists.txt b/paddle/phi/CMakeLists.txt index 330f0391b25..60246fc47f4 100644 --- a/paddle/phi/CMakeLists.txt +++ b/paddle/phi/CMakeLists.txt @@ -1,3 +1,5 @@ +configure_file(config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h) + # phi auto cmake utils include(phi) @@ -52,6 +54,7 @@ file( "// Header file generated by paddle/phi/CMakeLists.txt for external users,\n// DO NOT edit or include it within paddle.\n\n#pragma once\n\n" ) +file(APPEND ${phi_extension_header_file} "#include \"paddle/phi/config.h\"\n\n") # generate inner headers include dir for users generate_unify_header(backends EXCLUDES context_pool_utils.h) generate_unify_header(core EXCLUDES cuda_stream.h) diff --git a/paddle/phi/config.h.in b/paddle/phi/config.h.in new file mode 100644 index 00000000000..3e1e3025780 --- /dev/null +++ b/paddle/phi/config.h.in @@ -0,0 +1,36 @@ +// Header file generated by paddle/phi/CMakeLists.txt + +// Generate a compilation configuration to avoid compilation errors or +// incompatibilities caused by using phi without defining a phi compilation +// macro. At the same time, configuration file definition macros are more +// readable than those defined through the compilation option `-D`. + +#pragma once + +#undef ON +#undef OFF +#define ON 1 +#define OFF 0 + +// WITH_MKLDNN +#if @WITH_MKLDNN@ +#undef PADDLE_WITH_MKLDNN +#define PADDLE_WITH_MKLDNN +#endif + +// WITH_CUSTOM_DEVICE +#if @WITH_CUSTOM_DEVICE@ +#undef PADDLE_WITH_CUSTOM_DEVICE +#undef PADDLE_WITH_CUSTOM_KERNEL +#define PADDLE_WITH_CUSTOM_DEVICE +#define PADDLE_WITH_CUSTOM_KERNEL +#endif + +// WITH_ARM +#if @WITH_ARM@ +#undef PADDLE_WITH_ARM +#define PADDLE_WITH_ARM +#endif + +#undef ON +#undef OFF -- GitLab