Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PTen->Phi PR2] Rename PT_REGISTER macro to PD_REGISTER #39790

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions cmake/pten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,26 @@ endfunction()
function(kernel_declare TARGET_LIST)
foreach(kernel_path ${TARGET_LIST})
file(READ ${kernel_path} kernel_impl)
# TODO(chenweihang): rename PT_REGISTER_KERNEL to PT_REGISTER_KERNEL
# TODO(chenweihang): rename PD_REGISTER_KERNEL to PD_REGISTER_KERNEL
# NOTE(chenweihang): now we don't recommend to use digit in kernel name
string(REGEX MATCH "(PT_REGISTER_KERNEL|PT_REGISTER_GENERAL_KERNEL)\\([ \t\r\n]*[a-z0-9_]*," first_registry "${kernel_impl}")
string(REGEX MATCH "(PD_REGISTER_KERNEL|PD_REGISTER_GENERAL_KERNEL)\\([ \t\r\n]*[a-z0-9_]*," first_registry "${kernel_impl}")
if (NOT first_registry STREQUAL "")
# parse the first kernel name
string(REPLACE "PT_REGISTER_KERNEL(" "" kernel_name "${first_registry}")
string(REPLACE "PT_REGISTER_GENERAL_KERNEL(" "" kernel_name "${kernel_name}")
string(REPLACE "PD_REGISTER_KERNEL(" "" kernel_name "${first_registry}")
string(REPLACE "PD_REGISTER_GENERAL_KERNEL(" "" kernel_name "${kernel_name}")
string(REPLACE "," "" kernel_name "${kernel_name}")
string(REGEX REPLACE "[ \t\r\n]+" "" kernel_name "${kernel_name}")
# append kernel declare into declarations.h
# TODO(chenweihang): default declare ALL_LAYOUT for each kernel
if (${kernel_path} MATCHES "./cpu\/")
file(APPEND ${kernel_declare_file} "PT_DECLARE_KERNEL(${kernel_name}, CPU, ALL_LAYOUT);\n")
file(APPEND ${kernel_declare_file} "PD_DECLARE_KERNEL(${kernel_name}, CPU, ALL_LAYOUT);\n")
elseif (${kernel_path} MATCHES "./gpu\/")
file(APPEND ${kernel_declare_file} "PT_DECLARE_KERNEL(${kernel_name}, GPU, ALL_LAYOUT);\n")
file(APPEND ${kernel_declare_file} "PD_DECLARE_KERNEL(${kernel_name}, GPU, ALL_LAYOUT);\n")
elseif (${kernel_path} MATCHES "./xpu\/")
file(APPEND ${kernel_declare_file} "PT_DECLARE_KERNEL(${kernel_name}, XPU, ALL_LAYOUT);\n")
file(APPEND ${kernel_declare_file} "PD_DECLARE_KERNEL(${kernel_name}, XPU, ALL_LAYOUT);\n")
else ()
# deal with device independent kernel, now we use CPU temporaary
file(APPEND ${kernel_declare_file} "PT_DECLARE_KERNEL(${kernel_name}, CPU, ALL_LAYOUT);\n")
file(APPEND ${kernel_declare_file} "PD_DECLARE_KERNEL(${kernel_name}, CPU, ALL_LAYOUT);\n")
endif()
endif()
endforeach()
Expand Down Expand Up @@ -285,9 +285,9 @@ endfunction()

function(append_op_util_declare TARGET)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET} target_content)
string(REGEX MATCH "(PT_REGISTER_BASE_KERNEL_NAME|PT_REGISTER_ARG_MAPPING_FN)\\([ \t\r\n]*[a-z0-9_]*" util_registrar "${target_content}")
string(REPLACE "PT_REGISTER_ARG_MAPPING_FN" "PT_DECLARE_ARG_MAPPING_FN" util_declare "${util_registrar}")
string(REPLACE "PT_REGISTER_BASE_KERNEL_NAME" "PT_DECLARE_BASE_KERNEL_NAME" util_declare "${util_declare}")
string(REGEX MATCH "(PD_REGISTER_BASE_KERNEL_NAME|PD_REGISTER_ARG_MAPPING_FN)\\([ \t\r\n]*[a-z0-9_]*" util_registrar "${target_content}")
string(REPLACE "PD_REGISTER_ARG_MAPPING_FN" "PD_DECLARE_ARG_MAPPING_FN" util_declare "${util_registrar}")
string(REPLACE "PD_REGISTER_BASE_KERNEL_NAME" "PD_DECLARE_BASE_KERNEL_NAME" util_declare "${util_declare}")
string(APPEND util_declare ");\n")
file(APPEND ${op_utils_header} "${util_declare}")
endfunction()
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/infershape_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ REGISTER_OPERATOR(infer_shape_utils_test,
paddle::framework::InferShapeUtilsTestOpMaker,
InferShapeUtilsTestInferShapeFunctor);

PT_REGISTER_KERNEL(infer_shape_utils_test, CPU, ALL_LAYOUT,
PD_REGISTER_KERNEL(infer_shape_utils_test, CPU, ALL_LAYOUT,
paddle::framework::InferShapeUtilsTestKernel, int) {}

TEST(InferShapeUtilsTest, ALL) {
Expand Down
17 changes: 9 additions & 8 deletions paddle/phi/api/ext/op_kernel_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,16 +630,16 @@ class PADDLE_API OpKernelInfoBuilder {
};
/////////////////////// Custom kernel register API /////////////////////////
// For inference: compile directly with framework
// Call after PD_REGISTER_KERNEL(...)
// Call after PD_REGISTER_BUILTIN_KERNEL(...)
void RegisterAllCustomKernel();

//////////////// Custom kernel register macro /////////////////////
// Refer to paddle/phi/core/kernel_registry.h, we can not use
// PT_REGISTER_KERNEL directly, common macros and functions are
// PD_REGISTER_KERNEL directly, common macros and functions are
// not ready for custom kernel now.
// Difference: custom_kernel stores all kernels' info into global
// g_custom_kernel_info_map before loading and registering into
// pten kernel management. Only providing PD_REGISTER_KERNEL which
// pten kernel management. Only providing PD_REGISTER_BUILTIN_KERNEL which
// supports 2 template arguments.

#define PD_BACKEND(arg__) phi::Backend::arg__
Expand All @@ -666,11 +666,12 @@ void RegisterAllCustomKernel();
#define PD_ID __LINE__
#endif

#define PD_REGISTER_KERNEL(kernel_name, backend, layout, func, cpp_dtype, ...) \
STATIC_ASSERT_GLOBAL_NAMESPACE( \
_reg_custom_kernel_ns_check_##kernel_name##_##backend##_##layout, \
"PD_REGISTER_KERNEL must be called in global namespace."); \
_PD_REGISTER_2TA_KERNEL( \
#define PD_REGISTER_BUILTIN_KERNEL( \
kernel_name, backend, layout, func, cpp_dtype, ...) \
STATIC_ASSERT_GLOBAL_NAMESPACE( \
_reg_custom_kernel_ns_check_##kernel_name##_##backend##_##layout, \
"PD_REGISTER_BUILTIN_KERNEL must be called in global namespace."); \
_PD_REGISTER_2TA_KERNEL( \
kernel_name, backend, layout, func, cpp_dtype, ##__VA_ARGS__)

// WIN32 is not supported
Expand Down
6 changes: 3 additions & 3 deletions paddle/phi/api/lib/api_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ limitations under the License. */
// api symbols declare, remove in the future
#include "paddle/phi/api/lib/api_registry.h"

PT_DECLARE_API(Math);
PT_DECLARE_API(Utils);
PT_DECLARE_API(SparseApi);
PD_DECLARE_API(Math);
PD_DECLARE_API(Utils);
PD_DECLARE_API(SparseApi);
4 changes: 2 additions & 2 deletions paddle/phi/api/lib/api_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ namespace experimental {
*/

// use to declare symbol
#define PT_REGISTER_API(name) \
#define PD_REGISTER_API(name) \
PADDLE_API int RegisterSymbolsFor##name() { return 0; }

#define PT_DECLARE_API(name) \
#define PD_DECLARE_API(name) \
extern PADDLE_API int RegisterSymbolsFor##name(); \
UNUSED static int use_pten_api_##name = RegisterSymbolsFor##name()

Expand Down
10 changes: 5 additions & 5 deletions paddle/phi/api/lib/manual_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ limitations under the License. */
#include "paddle/phi/core/meta_tensor.h"
#include "paddle/phi/infermeta/unary.h"

PT_DECLARE_KERNEL(copy, CPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(split, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(copy, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(split, CPU, ALL_LAYOUT);

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PT_DECLARE_KERNEL(copy, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(copy, GPU, ALL_LAYOUT);
#endif

#ifdef PADDLE_WITH_XPU
PT_DECLARE_KERNEL(copy, XPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(copy, XPU, ALL_LAYOUT);
#endif

namespace paddle {
Expand Down Expand Up @@ -147,4 +147,4 @@ PADDLE_API std::vector<Tensor> split(const Tensor& x,
} // namespace experimental
} // namespace paddle

PT_REGISTER_API(Utils);
PD_REGISTER_API(Utils);
2 changes: 1 addition & 1 deletion paddle/phi/api/lib/op_kernel_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ OpKernelInfoBuilder& OpKernelInfoBuilder::ArgsDef(CustomKernelArgsDefFn func) {
/////////////////////// Op register API /////////////////////////

// For inference: compile directly with framework
// Call after PD_REGISTER_KERNEL(...)
// Call after PD_REGISTER_BUILTIN_KERNEL(...)
void RegisterAllCustomKernel() {
auto& op_kernel_info_map = OpKernelInfoMap::Instance();
framework::RegisterKernelWithMetaInfoMap(op_kernel_info_map);
Expand Down
26 changes: 13 additions & 13 deletions paddle/phi/api/lib/sparse_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ limitations under the License. */
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/infermeta/unary.h"

PT_DECLARE_KERNEL(dense_to_sparse_coo, CPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(sparse_csr_to_coo, CPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(dense_to_sparse_csr, CPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(sparse_coo_to_csr, CPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(sparse_coo_to_dense, CPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(sparse_csr_to_dense, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(dense_to_sparse_coo, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sparse_csr_to_coo, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(dense_to_sparse_csr, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sparse_coo_to_csr, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sparse_coo_to_dense, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sparse_csr_to_dense, CPU, ALL_LAYOUT);

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PT_DECLARE_KERNEL(dense_to_sparse_coo, GPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(sparse_csr_to_coo, GPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(dense_to_sparse_csr, GPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(sparse_coo_to_csr, GPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(sparse_coo_to_dense, GPU, ALL_LAYOUT);
PT_DECLARE_KERNEL(sparse_csr_to_dense, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(dense_to_sparse_coo, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sparse_csr_to_coo, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(dense_to_sparse_csr, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sparse_coo_to_csr, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sparse_coo_to_dense, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(sparse_csr_to_dense, GPU, ALL_LAYOUT);
#endif

namespace paddle {
Expand Down Expand Up @@ -228,4 +228,4 @@ PADDLE_API Tensor to_dense(const Tensor& x, Backend backend) {
} // namespace experimental
} // namespace paddle

PT_REGISTER_API(SparseApi);
PD_REGISTER_API(SparseApi);
14 changes: 7 additions & 7 deletions paddle/phi/common/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ enum class Backend : uint8_t {
* Of course, we have also considered solving this problem through different
* named macros, for example, if we define
*
* PT_REGISTER_KERNEL_FOR_ALL_BACKEND
* PD_REGISTER_KERNEL_FOR_ALL_BACKEND
*
* Based on this design pattern, the dtype and layout also have the same
* requirements, this cause we need to define a series of macros
*
* PT_REGISTER_KERNEL_FOR_ALL_DTYPE
* PT_REGISTER_KERNEL_FOR_ALL_LAYOUT
* PT_REGISTER_KERNEL_FOR_ALL_BACKEND_AND_LAYOUT
* PT_REGISTER_KERNEL_FOR_ALL_BACKEND_AND_DTYPE
* PT_REGISTER_KERNEL_FOR_ALL_LAYOUT_AND_DTYPE
* PT_REGISTER_KERNEL_FOR_ALL_BACKEND_AND_LAYOUT_AND_DTYPE
* PD_REGISTER_KERNEL_FOR_ALL_DTYPE
* PD_REGISTER_KERNEL_FOR_ALL_LAYOUT
* PD_REGISTER_KERNEL_FOR_ALL_BACKEND_AND_LAYOUT
* PD_REGISTER_KERNEL_FOR_ALL_BACKEND_AND_DTYPE
* PD_REGISTER_KERNEL_FOR_ALL_LAYOUT_AND_DTYPE
* PD_REGISTER_KERNEL_FOR_ALL_BACKEND_AND_LAYOUT_AND_DTYPE
*
* It makes the system of registering macros more complicated, we think
* this is not a simple design, so we still adopt the design of providing
Expand Down
24 changes: 12 additions & 12 deletions paddle/phi/core/compat/op_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,34 +164,34 @@ struct ArgumentMappingFnRegistrar {
}
};

#define PT_REGISTER_BASE_KERNEL_NAME(op_type, base_kernel_name) \
#define PD_REGISTER_BASE_KERNEL_NAME(op_type, base_kernel_name) \
PT_STATIC_ASSERT_GLOBAL_NAMESPACE( \
pt_register_base_kernel_name_ns_check_##op_type, \
"PT_REGISTER_BASE_KERNEL_NAME must be called in global namespace."); \
PD_REGISTER_base_kernel_name_ns_check_##op_type, \
"PD_REGISTER_BASE_KERNEL_NAME must be called in global namespace."); \
static const ::phi::BaseKernelNameRegistrar \
__registrar_base_kernel_name_for_##op_type(#op_type, #base_kernel_name); \
int TouchBaseKernelNameSymbol_##op_type() { return 0; }

#define PT_DECLARE_BASE_KERNEL_NAME(op_type) \
#define PD_DECLARE_BASE_KERNEL_NAME(op_type) \
PT_STATIC_ASSERT_GLOBAL_NAMESPACE( \
pt_declare_ai_name_ns_check_##op_type, \
"PT_DECLARE_BASE_KERNEL_NAME must be called in global namespace."); \
PD_DECLARE_ai_name_ns_check_##op_type, \
"PD_DECLARE_BASE_KERNEL_NAME must be called in global namespace."); \
extern int TouchBaseKernelNameSymbol_##op_type(); \
UNUSED static int __declare_base_kernel_name_symbol_for_##op_type = \
TouchBaseKernelNameSymbol_##op_type()

#define PT_REGISTER_ARG_MAPPING_FN(op_type, arg_mapping_fn) \
#define PD_REGISTER_ARG_MAPPING_FN(op_type, arg_mapping_fn) \
PT_STATIC_ASSERT_GLOBAL_NAMESPACE( \
pt_register_arg_map_fn_ns_check_##op_type, \
"PT_REGISTER_ARG_MAPPING_FN must be called in global namespace."); \
PD_REGISTER_arg_map_fn_ns_check_##op_type, \
"PD_REGISTER_ARG_MAPPING_FN must be called in global namespace."); \
static const ::phi::ArgumentMappingFnRegistrar \
__registrar_arg_map_fn_for_##op_type(#op_type, arg_mapping_fn); \
int TouchArgumentMappingFnSymbol_##op_type() { return 0; }

#define PT_DECLARE_ARG_MAPPING_FN(op_type) \
#define PD_DECLARE_ARG_MAPPING_FN(op_type) \
PT_STATIC_ASSERT_GLOBAL_NAMESPACE( \
pt_declare_arg_map_fn_ns_check_##op_type, \
"PT_DECLARE_ARG_MAPPING_FN must be called in global namespace."); \
PD_DECLARE_arg_map_fn_ns_check_##op_type, \
"PD_DECLARE_ARG_MAPPING_FN must be called in global namespace."); \
extern int TouchArgumentMappingFnSymbol_##op_type(); \
UNUSED static int __declare_arg_map_fn_symbol_for_##op_type = \
TouchArgumentMappingFnSymbol_##op_type()
Expand Down
6 changes: 3 additions & 3 deletions paddle/phi/core/infermeta_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ struct InferMetaFnRegistrar {
}
};

#define PT_REGISTER_INFER_META_FN(kernel_name_prefix, variadic_infer_meta_fn) \
#define PD_REGISTER_INFER_META_FN(kernel_name_prefix, variadic_infer_meta_fn) \
PT_STATIC_ASSERT_GLOBAL_NAMESPACE( \
pt_register_infer_meta_fn_ns_check_##kernel_name_prefix, \
"PT_REGISTER_INFER_META_FN must be called in global namespace."); \
PD_REGISTER_infer_meta_fn_ns_check_##kernel_name_prefix, \
"PD_REGISTER_INFER_META_FN must be called in global namespace."); \
static const ::phi::InferMetaFnRegistrar \
__registrar_arg_map_fn_for_##kernel_name_prefix( \
#kernel_name_prefix, PT_INFER_META(variadic_infer_meta_fn))
Expand Down
Loading