未验证 提交 e00aa903 编写于 作者: C Chen Weihang 提交者: GitHub

[Cherry-pick] Several bugs fix (#44991)

* fix device context init error (#43910)

* Fix core so name mismatch error (#43977)

* fix core avx soname error

* remove print info

* add clip_extra (#44008)

* fix tensor stream error in custom op (#44500)

* fix custom op attr names size error (#44938)
上级 c5f4a9cc
...@@ -58,7 +58,7 @@ limitations under the License. */ ...@@ -58,7 +58,7 @@ limitations under the License. */
#endif #endif
#ifdef PADDLE_WITH_MKLDNN #ifdef PADDLE_WITH_MKLDNN
#include "dnnl.hpp" #include "dnnl.hpp" // NOLINT
#include "paddle/fluid/framework/data_layout.h" #include "paddle/fluid/framework/data_layout.h"
#endif #endif
...@@ -902,6 +902,8 @@ class DeviceContextPool { ...@@ -902,6 +902,8 @@ class DeviceContextPool {
return *pool; return *pool;
} }
static bool IsInitialized() { return pool != nullptr; }
static void SetPool(DeviceContextPool* dev_pool) { pool = dev_pool; } static void SetPool(DeviceContextPool* dev_pool) { pool = dev_pool; }
/*! \brief Return handle of single device context. */ /*! \brief Return handle of single device context. */
......
...@@ -305,8 +305,7 @@ static std::vector<paddle::any> CastAttrsToTragetType( ...@@ -305,8 +305,7 @@ static std::vector<paddle::any> CastAttrsToTragetType(
attrs_names.size(), src.size())); attrs_names.size(), src.size()));
for (size_t i = 0; i < src.size(); i++) { for (size_t i = 0; i < src.size(); i++) {
size_t end = attrs_names[i].find(": "); size_t end = attrs_names[i].find(": ");
std::string type_name = std::string type_name = attrs_names[i].substr(end + 2);
attrs_names[i].substr(end + 2, attrs_names.size() - end - 2);
if (type_name == "int") { if (type_name == "int") {
if (src[i].type() == typeid(bool)) { if (src[i].type() == typeid(bool)) {
res.emplace_back(static_cast<int>(paddle::any_cast<bool>(src[i]))); res.emplace_back(static_cast<int>(paddle::any_cast<bool>(src[i])));
......
add_subdirectory(utils) add_subdirectory(utils)
if (WITH_GPU) if(WITH_GPU)
nv_library(phi_tensor_raw SRCS tensor.cc DEPS tensor_base dense_tensor phi_api_utils phi_enforce) nv_library(
elseif (WITH_ROCM) phi_tensor_raw
hip_library(phi_tensor_raw SRCS tensor.cc DEPS tensor_base dense_tensor phi_api_utils phi_enforce) SRCS tensor.cc
DEPS tensor_base dense_tensor phi_api_utils phi_enforce context_pool)
elseif(WITH_ROCM)
hip_library(
phi_tensor_raw
SRCS tensor.cc
DEPS tensor_base dense_tensor phi_api_utils phi_enforce context_pool)
else() else()
cc_library(phi_tensor_raw SRCS tensor.cc DEPS tensor_base dense_tensor phi_api_utils phi_enforce) cc_library(
phi_tensor_raw
SRCS tensor.cc
DEPS tensor_base dense_tensor phi_api_utils phi_enforce context_pool)
endif() endif()
set(api_gen_base ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/api_base.py) set(api_gen_base ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/api_base.py)
...@@ -19,51 +28,71 @@ set(api_header_file_tmp ${api_header_file}.tmp) ...@@ -19,51 +28,71 @@ set(api_header_file_tmp ${api_header_file}.tmp)
set(api_source_file_tmp ${api_source_file}.tmp) set(api_source_file_tmp ${api_source_file}.tmp)
# backward api file # backward api file
set(bw_api_gen_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/backward_api_gen.py) set(bw_api_gen_file
set(bw_api_yaml_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/backward.yaml) ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/backward_api_gen.py)
set(bw_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/backward/backward_api.h) set(bw_api_yaml_file
${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/backward.yaml)
set(bw_api_header_file
${CMAKE_SOURCE_DIR}/paddle/phi/api/backward/backward_api.h)
set(bw_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/backward_api.cc) set(bw_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/backward_api.cc)
set(bw_api_header_file_tmp ${bw_api_header_file}.tmp) set(bw_api_header_file_tmp ${bw_api_header_file}.tmp)
set(bw_api_source_file_tmp ${bw_api_source_file}.tmp) set(bw_api_source_file_tmp ${bw_api_source_file}.tmp)
# dygraph(intermediate) api file # dygraph(intermediate) api file
set(im_api_gen_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/intermediate_api_gen.py) set(im_api_gen_file
set(dygraph_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/dygraph_api.h) ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/intermediate_api_gen.py)
set(dygraph_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/dygraph_api.cc) set(dygraph_api_header_file
${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/dygraph_api.h)
set(dygraph_api_source_file
${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/dygraph_api.cc)
set(dygraph_api_header_file_tmp ${dygraph_api_header_file}.tmp) set(dygraph_api_header_file_tmp ${dygraph_api_header_file}.tmp)
set(dygraph_api_source_file_tmp ${dygraph_api_source_file}.tmp) set(dygraph_api_source_file_tmp ${dygraph_api_source_file}.tmp)
# sparse api file # sparse api file
set(sparse_api_gen_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/sparse_api_gen.py) set(sparse_api_gen_file
set(sparse_api_yaml_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/sparse_api.yaml) ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/sparse_api_gen.py)
set(sparse_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/sparse_api.h) set(sparse_api_yaml_file
${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/sparse_api.yaml)
set(sparse_api_header_file
${CMAKE_SOURCE_DIR}/paddle/phi/api/include/sparse_api.h)
set(sparse_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/sparse_api.cc) set(sparse_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/sparse_api.cc)
set(sparse_api_header_file_tmp ${sparse_api_header_file}.tmp) set(sparse_api_header_file_tmp ${sparse_api_header_file}.tmp)
set(sparse_api_source_file_tmp ${sparse_api_source_file}.tmp) set(sparse_api_source_file_tmp ${sparse_api_source_file}.tmp)
# sparse bw api file # sparse bw api file
set(sparse_bw_api_gen_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/sparse_bw_api_gen.py) set(sparse_bw_api_gen_file
set(sparse_bw_api_yaml_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/sparse_bw_api.yaml) ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/sparse_bw_api_gen.py)
set(sparse_bw_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/backward/sparse_bw_api.h) set(sparse_bw_api_yaml_file
set(sparse_bw_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/sparse_bw_api.cc) ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/sparse_bw_api.yaml)
set(sparse_bw_api_header_file
${CMAKE_SOURCE_DIR}/paddle/phi/api/backward/sparse_bw_api.h)
set(sparse_bw_api_source_file
${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/sparse_bw_api.cc)
set(sparse_bw_api_header_file_tmp ${sparse_bw_api_header_file}.tmp) set(sparse_bw_api_header_file_tmp ${sparse_bw_api_header_file}.tmp)
set(sparse_bw_api_source_file_tmp ${sparse_bw_api_source_file}.tmp) set(sparse_bw_api_source_file_tmp ${sparse_bw_api_source_file}.tmp)
# strings api file # strings api file
set(strings_api_gen_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/strings_api_gen.py) set(strings_api_gen_file
set(strings_api_yaml_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/strings_api.yaml) ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/strings_api_gen.py)
set(strings_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/strings_api.h) set(strings_api_yaml_file
set(strings_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/strings_api.cc) ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/strings_api.yaml)
set(strings_api_header_file
${CMAKE_SOURCE_DIR}/paddle/phi/api/include/strings_api.h)
set(strings_api_source_file
${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/strings_api.cc)
set(strings_api_header_file_tmp ${strings_api_header_file}.tmp) set(strings_api_header_file_tmp ${strings_api_header_file}.tmp)
set(strings_api_source_file_tmp ${strings_api_source_file}.tmp) set(strings_api_source_file_tmp ${strings_api_source_file}.tmp)
# wrapped infermeta file # wrapped infermeta file
set(wrapped_infermeta_gen_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/wrapped_infermeta_gen.py) set(wrapped_infermeta_gen_file
${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/wrapped_infermeta_gen.py)
set(api_yaml_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/api.yaml) set(api_yaml_file ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/api.yaml)
set(wrapped_infermeta_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/infermeta/generated.h) set(wrapped_infermeta_header_file
set(wrapped_infermeta_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/infermeta/generated.cc) ${CMAKE_SOURCE_DIR}/paddle/phi/infermeta/generated.h)
set(wrapped_infermeta_source_file
${CMAKE_SOURCE_DIR}/paddle/phi/infermeta/generated.cc)
if (NOT PYTHON_EXECUTABLE) if(NOT PYTHON_EXECUTABLE)
find_package(PythonInterp REQUIRED) find_package(PythonInterp REQUIRED)
endif() endif()
...@@ -71,25 +100,30 @@ endif() ...@@ -71,25 +100,30 @@ endif()
add_custom_command( add_custom_command(
OUTPUT ${api_header_file} ${api_source_file} OUTPUT ${api_header_file} ${api_source_file}
COMMAND ${PYTHON_EXECUTABLE} -m pip install pyyaml COMMAND ${PYTHON_EXECUTABLE} -m pip install pyyaml
COMMAND ${PYTHON_EXECUTABLE} ${api_gen_file} COMMAND
--api_yaml_path ${api_yaml_file} ${PYTHON_EXECUTABLE} ${api_gen_file} --api_yaml_path ${api_yaml_file}
--api_header_path ${api_header_file_tmp} --api_header_path ${api_header_file_tmp} --api_source_path
--api_source_path ${api_source_file_tmp} ${api_source_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${api_header_file_tmp} ${api_header_file} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${api_header_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${api_source_file_tmp} ${api_source_file} ${api_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${api_source_file_tmp}
${api_source_file}
COMMENT "copy_if_different ${api_header_file} ${api_source_file}" COMMENT "copy_if_different ${api_header_file} ${api_source_file}"
DEPENDS ${api_yaml_file} ${api_gen_file} ${api_gen_base} DEPENDS ${api_yaml_file} ${api_gen_file} ${api_gen_base}
VERBATIM) VERBATIM)
# generate backward api # generate backward api
add_custom_command( add_custom_command(
OUTPUT ${bw_api_header_file} ${bw_api_source_file} ${bw_api_header_file_tmp} ${bw_api_source_file_tmp} OUTPUT ${bw_api_header_file} ${bw_api_source_file} ${bw_api_header_file_tmp}
COMMAND ${PYTHON_EXECUTABLE} ${bw_api_gen_file} ${bw_api_source_file_tmp}
--backward_yaml_path ${bw_api_yaml_file} COMMAND
--backward_header_path ${bw_api_header_file_tmp} ${PYTHON_EXECUTABLE} ${bw_api_gen_file} --backward_yaml_path
${bw_api_yaml_file} --backward_header_path ${bw_api_header_file_tmp}
--backward_source_path ${bw_api_source_file_tmp} --backward_source_path ${bw_api_source_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${bw_api_header_file_tmp} ${bw_api_header_file} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${bw_api_header_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${bw_api_source_file_tmp} ${bw_api_source_file} ${bw_api_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${bw_api_source_file_tmp}
${bw_api_source_file}
COMMENT "copy_if_different ${bw_api_header_file} ${bw_api_source_file}" COMMENT "copy_if_different ${bw_api_header_file} ${bw_api_source_file}"
DEPENDS ${bw_api_yaml_file} ${bw_api_gen_file} ${api_gen_base} DEPENDS ${bw_api_yaml_file} ${bw_api_gen_file} ${api_gen_base}
VERBATIM) VERBATIM)
...@@ -97,81 +131,173 @@ add_custom_command( ...@@ -97,81 +131,173 @@ add_custom_command(
# generate sparse api # generate sparse api
add_custom_command( add_custom_command(
OUTPUT ${sparse_api_header_file} ${sparse_api_source_file} OUTPUT ${sparse_api_header_file} ${sparse_api_source_file}
COMMAND ${PYTHON_EXECUTABLE} ${sparse_api_gen_file} COMMAND
--api_yaml_path ${sparse_api_yaml_file} ${PYTHON_EXECUTABLE} ${sparse_api_gen_file} --api_yaml_path
--api_header_path ${sparse_api_header_file_tmp} ${sparse_api_yaml_file} --api_header_path ${sparse_api_header_file_tmp}
--api_source_path ${sparse_api_source_file_tmp} --api_source_path ${sparse_api_source_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_api_header_file_tmp} ${sparse_api_header_file} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_api_header_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_api_source_file_tmp} ${sparse_api_source_file} ${sparse_api_header_file}
COMMENT "copy_if_different ${sparse_api_header_file} ${sparse_sparse_api_source_file}" COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_api_source_file_tmp}
DEPENDS ${sparse_api_yaml_file} ${sparse_api_gen_file} ${api_gen_base} ${api_gen_file} ${sparse_api_source_file}
COMMENT
"copy_if_different ${sparse_api_header_file} ${sparse_sparse_api_source_file}"
DEPENDS ${sparse_api_yaml_file} ${sparse_api_gen_file} ${api_gen_base}
${api_gen_file}
VERBATIM) VERBATIM)
# generate backward sparse api # generate backward sparse api
add_custom_command( add_custom_command(
OUTPUT ${sparse_bw_api_header_file} ${sparse_bw_api_source_file} OUTPUT ${sparse_bw_api_header_file} ${sparse_bw_api_source_file}
COMMAND ${PYTHON_EXECUTABLE} ${sparse_bw_api_gen_file} COMMAND
--api_yaml_path ${sparse_bw_api_yaml_file} ${PYTHON_EXECUTABLE} ${sparse_bw_api_gen_file} --api_yaml_path
--api_header_path ${sparse_bw_api_header_file_tmp} ${sparse_bw_api_yaml_file} --api_header_path
--api_source_path ${sparse_bw_api_source_file_tmp} ${sparse_bw_api_header_file_tmp} --api_source_path
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_bw_api_header_file_tmp} ${sparse_bw_api_header_file} ${sparse_bw_api_source_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_bw_api_source_file_tmp} ${sparse_bw_api_source_file} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_bw_api_header_file_tmp}
COMMENT "copy_if_different ${sparse_bw_api_header_file} ${sparse_bw_sparse_api_source_file}" ${sparse_bw_api_header_file}
DEPENDS ${sparse_bw_api_yaml_file} ${sparse_bw_api_gen_file} ${api_gen_base} ${api_gen_file} ${sparse_api_gen_file} ${bw_api_gen_file} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_bw_api_source_file_tmp}
${sparse_bw_api_source_file}
COMMENT
"copy_if_different ${sparse_bw_api_header_file} ${sparse_bw_sparse_api_source_file}"
DEPENDS ${sparse_bw_api_yaml_file} ${sparse_bw_api_gen_file} ${api_gen_base}
${api_gen_file} ${sparse_api_gen_file} ${bw_api_gen_file}
VERBATIM) VERBATIM)
# generate strings api # generate strings api
add_custom_command( add_custom_command(
OUTPUT ${strings_api_header_file} ${strings_api_source_file} OUTPUT ${strings_api_header_file} ${strings_api_source_file}
COMMAND ${PYTHON_EXECUTABLE} ${strings_api_gen_file} COMMAND
--api_yaml_path ${strings_api_yaml_file} ${PYTHON_EXECUTABLE} ${strings_api_gen_file} --api_yaml_path
--api_header_path ${strings_api_header_file_tmp} ${strings_api_yaml_file} --api_header_path ${strings_api_header_file_tmp}
--api_source_path ${strings_api_source_file_tmp} --api_source_path ${strings_api_source_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${strings_api_header_file_tmp} ${strings_api_header_file} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${strings_api_header_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${strings_api_source_file_tmp} ${strings_api_source_file} ${strings_api_header_file}
COMMENT "copy_if_different ${strings_api_header_file} ${strings_strings_api_source_file}" COMMAND ${CMAKE_COMMAND} -E copy_if_different ${strings_api_source_file_tmp}
DEPENDS ${strings_api_yaml_file} ${strings_api_gen_file} ${api_gen_base} ${api_gen_file} ${strings_api_source_file}
COMMENT
"copy_if_different ${strings_api_header_file} ${strings_strings_api_source_file}"
DEPENDS ${strings_api_yaml_file} ${strings_api_gen_file} ${api_gen_base}
${api_gen_file}
VERBATIM) VERBATIM)
# generate dygraph(intermediate) api # generate dygraph(intermediate) api
add_custom_command( add_custom_command(
OUTPUT ${dygraph_api_header_file} ${dygraph_api_source_file} OUTPUT ${dygraph_api_header_file} ${dygraph_api_source_file}
COMMAND ${PYTHON_EXECUTABLE} ${im_api_gen_file} COMMAND
--api_yaml_path ${api_yaml_file} ${PYTHON_EXECUTABLE} ${im_api_gen_file} --api_yaml_path ${api_yaml_file}
--sparse_api_yaml_path ${sparse_api_yaml_file} --sparse_api_yaml_path ${sparse_api_yaml_file} --dygraph_api_header_path
--dygraph_api_header_path ${dygraph_api_header_file_tmp} ${dygraph_api_header_file_tmp} --dygraph_api_source_path
--dygraph_api_source_path ${dygraph_api_source_file_tmp} ${dygraph_api_source_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${dygraph_api_header_file_tmp} ${dygraph_api_header_file} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${dygraph_api_header_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${dygraph_api_source_file_tmp} ${dygraph_api_source_file} ${dygraph_api_header_file}
DEPENDS ${api_yaml_file} ${sparse_api_yaml_file} ${im_api_gen_file} ${api_gen_base} ${api_gen_file} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${dygraph_api_source_file_tmp}
${dygraph_api_source_file}
DEPENDS ${api_yaml_file} ${sparse_api_yaml_file} ${im_api_gen_file}
${api_gen_base} ${api_gen_file}
VERBATIM) VERBATIM)
# generate wrapped infermeta # generate wrapped infermeta
add_custom_command( add_custom_command(
OUTPUT ${wrapped_infermeta_header_file} ${wrapped_infermeta_source_file} OUTPUT ${wrapped_infermeta_header_file} ${wrapped_infermeta_source_file}
COMMAND ${PYTHON_EXECUTABLE} ${wrapped_infermeta_gen_file} COMMAND
--api_yaml_path ${api_yaml_file} ${PYTHON_EXECUTABLE} ${wrapped_infermeta_gen_file} --api_yaml_path
--wrapped_infermeta_header_path ${wrapped_infermeta_header_file} ${api_yaml_file} --wrapped_infermeta_header_path
--wrapped_infermeta_source_path ${wrapped_infermeta_source_file} ${wrapped_infermeta_header_file} --wrapped_infermeta_source_path
${wrapped_infermeta_source_file}
DEPENDS ${api_yaml_file} ${wrapped_infermeta_gen_file} ${api_gen_base} DEPENDS ${api_yaml_file} ${wrapped_infermeta_gen_file} ${api_gen_base}
VERBATIM) VERBATIM)
cc_library(op_meta_info SRCS op_meta_info.cc DEPS phi_tensor_raw) cc_library(
cc_library(wrapped_infermeta SRCS ${wrapped_infermeta_source_file} DEPS phi) op_meta_info
cc_library(context_pool SRCS context_pool.cc DEPS phi_context phi_enforce place) SRCS op_meta_info.cc
DEPS phi_tensor_raw)
cc_library(kernel_dispatch SRCS kernel_dispatch.cc DEPS phi_tensor_raw phi_context kernel_factory context_pool) cc_library(
cc_library(api_gen_utils SRCS api_gen_utils.cc DEPS phi_tensor_raw selected_rows sparse_csr_tensor sparse_coo_tensor) wrapped_infermeta
cc_library(phi_data_transform SRCS data_transform.cc DEPS phi_tensor_raw transfer_layout_kernel cast_kernel data_device_transform) SRCS ${wrapped_infermeta_source_file}
cc_library(api_custom_impl SRCS api_custom_impl.cc DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils backward_infermeta phi_data_transform) DEPS phi)
cc_library(sparse_api_custom_impl SRCS sparse_api_custom_impl.cc DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils phi_data_transform tensor_copy) cc_library(
context_pool
cc_library(phi_function_api SRCS ${api_source_file} DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils phi_data_transform api_custom_impl) SRCS context_pool.cc
cc_library(phi_bw_function_api SRCS ${bw_api_source_file} DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils backward_infermeta phi_data_transform phi_function_api api_custom_impl global_utils) DEPS phi_context phi_enforce place init)
cc_library(sparse_api SRCS ${sparse_api_source_file} DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils sparse_api_custom_impl)
cc_library(sparse_bw_api SRCS ${sparse_bw_api_source_file} DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils sparse_api sparse_api_custom_impl) cc_library(
cc_library(phi_dygraph_api SRCS ${dygraph_api_source_file} DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils phi_data_transform phi_function_api sparse_api) kernel_dispatch
cc_library(strings_api SRCS ${strings_api_source_file} DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils) SRCS kernel_dispatch.cc
cc_library(phi_tensor SRCS tensor_method.cc DEPS phi_tensor_raw phi_function_api api_gen_utils kernel_dispatch infermeta sparse_api strings_api) DEPS phi_tensor_raw phi_context kernel_factory context_pool)
cc_library(tensor_copy SRCS tensor_copy.cc DEPS phi_tensor_raw copy_kernel kernel_dispatch api_gen_utils) cc_library(
cc_library(api_scalar SRCS scalar.cc DEPS tensor_copy) api_gen_utils
SRCS api_gen_utils.cc
DEPS phi_tensor_raw selected_rows sparse_csr_tensor sparse_coo_tensor)
cc_library(
phi_data_transform
SRCS data_transform.cc
DEPS phi_tensor_raw transfer_layout_kernel cast_kernel data_device_transform)
cc_library(
api_custom_impl
SRCS api_custom_impl.cc
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils backward_infermeta
phi_data_transform)
cc_library(
sparse_api_custom_impl
SRCS sparse_api_custom_impl.cc
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils phi_data_transform
tensor_copy)
cc_library(
phi_function_api
SRCS ${api_source_file}
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils phi_data_transform
api_custom_impl)
cc_library(
phi_bw_function_api
SRCS ${bw_api_source_file}
DEPS phi_tensor_raw
phi
kernel_dispatch
api_gen_utils
backward_infermeta
phi_data_transform
phi_function_api
api_custom_impl
global_utils)
cc_library(
sparse_api
SRCS ${sparse_api_source_file}
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils sparse_api_custom_impl)
cc_library(
sparse_bw_api
SRCS ${sparse_bw_api_source_file}
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils sparse_api
sparse_api_custom_impl)
cc_library(
phi_dygraph_api
SRCS ${dygraph_api_source_file}
DEPS phi_tensor_raw
phi
kernel_dispatch
api_gen_utils
phi_data_transform
phi_function_api
sparse_api)
cc_library(
strings_api
SRCS ${strings_api_source_file}
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils)
cc_library(
phi_tensor
SRCS tensor_method.cc
DEPS phi_tensor_raw
phi_function_api
api_gen_utils
kernel_dispatch
infermeta
sparse_api
strings_api)
cc_library(
tensor_copy
SRCS tensor_copy.cc
DEPS phi_tensor_raw copy_kernel kernel_dispatch api_gen_utils)
cc_library(
api_scalar
SRCS scalar.cc
DEPS tensor_copy)
...@@ -17,6 +17,8 @@ limitations under the License. */ ...@@ -17,6 +17,8 @@ limitations under the License. */
#include "paddle/phi/backends/all_context.h" #include "paddle/phi/backends/all_context.h"
#include "paddle/phi/core/enforce.h" #include "paddle/phi/core/enforce.h"
#include "paddle/fluid/platform/init.h"
namespace paddle { namespace paddle {
namespace experimental { namespace experimental {
...@@ -28,6 +30,9 @@ DeviceContextPool& DeviceContextPool::Instance() { ...@@ -28,6 +30,9 @@ DeviceContextPool& DeviceContextPool::Instance() {
const phi::DeviceContext* DeviceContextPool::Get(const Place& place) { const phi::DeviceContext* DeviceContextPool::Get(const Place& place) {
auto it = context_map_.find(place); auto it = context_map_.find(place);
if (it == context_map_.end()) { if (it == context_map_.end()) {
if (!paddle::platform::DeviceContextPool::IsInitialized()) {
paddle::framework::InitDevices();
}
// only when we need the specific DeviceContext, get and cache it // only when we need the specific DeviceContext, get and cache it
auto* dev_ctx = paddle::platform::DeviceContextPool::Instance().Get(place); auto* dev_ctx = paddle::platform::DeviceContextPool::Instance().Get(place);
{ {
......
...@@ -20,7 +20,9 @@ limitations under the License. */ ...@@ -20,7 +20,9 @@ limitations under the License. */
#include "glog/logging.h" #include "glog/logging.h"
#include "paddle/phi/api/include/context_pool.h"
#include "paddle/phi/api/lib/utils/allocator.h" #include "paddle/phi/api/lib/utils/allocator.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/backends/gpu/gpu_info.h" #include "paddle/phi/backends/gpu/gpu_info.h"
#include "paddle/phi/core/ddim.h" #include "paddle/phi/core/ddim.h"
#include "paddle/phi/core/dense_tensor.h" #include "paddle/phi/core/dense_tensor.h"
...@@ -32,8 +34,7 @@ limitations under the License. */ ...@@ -32,8 +34,7 @@ limitations under the License. */
#include "paddle/phi/core/tensor_base.h" #include "paddle/phi/core/tensor_base.h"
#include "paddle/phi/core/tensor_meta.h" #include "paddle/phi/core/tensor_meta.h"
#include "paddle/phi/core/tensor_utils.h" #include "paddle/phi/core/tensor_utils.h"
// clang-format off
#include "paddle/fluid/platform/stream/cuda_stream.h"
namespace paddle { namespace paddle {
namespace experimental { namespace experimental {
...@@ -305,7 +306,10 @@ void Tensor::set_impl(std::shared_ptr<phi::TensorBase> &&impl) { ...@@ -305,7 +306,10 @@ void Tensor::set_impl(std::shared_ptr<phi::TensorBase> &&impl) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
gpuStream_t Tensor::stream() const { gpuStream_t Tensor::stream() const {
return platform::stream::get_current_stream(-1)->raw_stream(); int device_id = phi::backends::gpu::GetCurrentDeviceId();
auto* gpu_context = DeviceContextPool::Instance()
.Get<AllocationType::GPU>(GPUPlace(device_id));
return gpu_context->stream();
} }
#endif #endif
......
...@@ -64,8 +64,8 @@ def _extract_vars(inputs, result_list, err_tag='inputs'): ...@@ -64,8 +64,8 @@ def _extract_vars(inputs, result_list, err_tag='inputs'):
_extract_vars(var, result_list, err_tag) _extract_vars(var, result_list, err_tag)
else: else:
raise TypeError( raise TypeError(
"The type of 'each element of {}' in fluid.dygraph.jit.TracedLayer.trace must be fluid.Variable, but received {}.". "The type of 'each element of {}' in fluid.dygraph.jit.TracedLayer.trace must be fluid.Variable, but received {}."
format(err_tag, type(inputs))) .format(err_tag, type(inputs)))
def extract_vars(inputs, err_tag='inputs'): def extract_vars(inputs, err_tag='inputs'):
...@@ -211,8 +211,7 @@ def declarative(function=None, input_spec=None, build_strategy=None): ...@@ -211,8 +211,7 @@ def declarative(function=None, input_spec=None, build_strategy=None):
_, python_func = unwrap_decorators(python_func) _, python_func = unwrap_decorators(python_func)
# Step 2. copy some attributes from original python function. # Step 2. copy some attributes from original python function.
static_layer = copy_decorator_attrs( static_layer = copy_decorator_attrs(original_func=python_func,
original_func=python_func,
decorated_obj=StaticFunction( decorated_obj=StaticFunction(
function=python_func, function=python_func,
input_spec=input_spec, input_spec=input_spec,
...@@ -223,8 +222,8 @@ def declarative(function=None, input_spec=None, build_strategy=None): ...@@ -223,8 +222,8 @@ def declarative(function=None, input_spec=None, build_strategy=None):
build_strategy = build_strategy or BuildStrategy() build_strategy = build_strategy or BuildStrategy()
if not isinstance(build_strategy, BuildStrategy): if not isinstance(build_strategy, BuildStrategy):
raise TypeError( raise TypeError(
"Required type(build_strategy) shall be `paddle.static.BuildStrategy`, but received {}". "Required type(build_strategy) shall be `paddle.static.BuildStrategy`, but received {}"
format(type(build_strategy).__name__)) .format(type(build_strategy).__name__))
# for usage: `declarative(foo, ...)` # for usage: `declarative(foo, ...)`
if function is not None: if function is not None:
...@@ -232,8 +231,8 @@ def declarative(function=None, input_spec=None, build_strategy=None): ...@@ -232,8 +231,8 @@ def declarative(function=None, input_spec=None, build_strategy=None):
if isinstance(function.forward, StaticFunction): if isinstance(function.forward, StaticFunction):
class_name = function.__class__.__name__ class_name = function.__class__.__name__
logging_utils.warn( logging_utils.warn(
"`{}.forward` has already been decorated somewhere. It will be redecorated to replace previous one.". "`{}.forward` has already been decorated somewhere. It will be redecorated to replace previous one."
format(class_name)) .format(class_name))
function.forward = decorated(function.forward) function.forward = decorated(function.forward)
return function return function
else: else:
...@@ -284,6 +283,7 @@ def not_to_static(func=None): ...@@ -284,6 +283,7 @@ def not_to_static(func=None):
class _SaveLoadConfig(object): class _SaveLoadConfig(object):
def __init__(self): def __init__(self):
self._output_spec = None self._output_spec = None
self._model_filename = None self._model_filename = None
...@@ -371,7 +371,7 @@ class _SaveLoadConfig(object): ...@@ -371,7 +371,7 @@ class _SaveLoadConfig(object):
def _parse_save_configs(configs): def _parse_save_configs(configs):
supported_configs = ['output_spec', "with_hook"] supported_configs = ['output_spec', "with_hook", "clip_extra"]
# input check # input check
for key in configs: for key in configs:
...@@ -384,6 +384,7 @@ def _parse_save_configs(configs): ...@@ -384,6 +384,7 @@ def _parse_save_configs(configs):
inner_config = _SaveLoadConfig() inner_config = _SaveLoadConfig()
inner_config.output_spec = configs.get('output_spec', None) inner_config.output_spec = configs.get('output_spec', None)
inner_config.with_hook = configs.get('with_hook', False) inner_config.with_hook = configs.get('with_hook', False)
inner_config.clip_extra = configs.get("clip_extra", False)
return inner_config return inner_config
...@@ -622,6 +623,7 @@ def _remove_save_pre_hook(hook): ...@@ -622,6 +623,7 @@ def _remove_save_pre_hook(hook):
def _run_save_pre_hooks(func): def _run_save_pre_hooks(func):
def wrapper(layer, path, input_spec=None, **configs): def wrapper(layer, path, input_spec=None, **configs):
global _save_pre_hooks global _save_pre_hooks
for hook in _save_pre_hooks: for hook in _save_pre_hooks:
...@@ -775,8 +777,8 @@ def save(layer, path, input_spec=None, **configs): ...@@ -775,8 +777,8 @@ def save(layer, path, input_spec=None, **configs):
"The paddle.jit.save doesn't work when setting ProgramTranslator.enable to False." "The paddle.jit.save doesn't work when setting ProgramTranslator.enable to False."
) )
if not (isinstance(layer, Layer) or inspect.isfunction(layer) or isinstance( if not (isinstance(layer, Layer) or inspect.isfunction(layer)
layer, StaticFunction)): or isinstance(layer, StaticFunction)):
raise TypeError( raise TypeError(
"The input of paddle.jit.save should be 'Layer' or 'Function', but received input type is %s." "The input of paddle.jit.save should be 'Layer' or 'Function', but received input type is %s."
% type(layer)) % type(layer))
...@@ -848,7 +850,9 @@ def save(layer, path, input_spec=None, **configs): ...@@ -848,7 +850,9 @@ def save(layer, path, input_spec=None, **configs):
with_hook = True with_hook = True
else: else:
# layer is function # layer is function
functions = [layer, ] functions = [
layer,
]
for attr_func in functions: for attr_func in functions:
if isinstance(layer, Layer): if isinstance(layer, Layer):
static_func = getattr(inner_layer, attr_func, None) static_func = getattr(inner_layer, attr_func, None)
...@@ -862,8 +866,8 @@ def save(layer, path, input_spec=None, **configs): ...@@ -862,8 +866,8 @@ def save(layer, path, input_spec=None, **configs):
if inner_input_spec: if inner_input_spec:
inner_input_spec = pack_sequence_as(input_spec, inner_input_spec = pack_sequence_as(input_spec,
inner_input_spec) inner_input_spec)
static_forward = declarative( static_forward = declarative(inner_layer.forward,
inner_layer.forward, input_spec=inner_input_spec) input_spec=inner_input_spec)
concrete_program = static_forward.concrete_program_specify_input_spec( concrete_program = static_forward.concrete_program_specify_input_spec(
with_hook=with_hook) with_hook=with_hook)
# the input_spec has been used in declarative, which is equal to # the input_spec has been used in declarative, which is equal to
...@@ -882,14 +886,14 @@ def save(layer, path, input_spec=None, **configs): ...@@ -882,14 +886,14 @@ def save(layer, path, input_spec=None, **configs):
if inner_input_spec: if inner_input_spec:
inner_input_spec = pack_sequence_as(input_spec, inner_input_spec = pack_sequence_as(input_spec,
inner_input_spec) inner_input_spec)
static_function = declarative( static_function = declarative(attr_func,
attr_func, input_spec=inner_input_spec) input_spec=inner_input_spec)
concrete_program = static_function.concrete_program concrete_program = static_function.concrete_program
if static_function._class_instance is None: if static_function._class_instance is None:
warnings.warn( warnings.warn(
'`jit.save` will only save the `Program`, not the parameters. If you have to save the parameters, please make sure that {} is a member function of `paddle.nn.Layer` and the saved parameters are in `state_dict`'. '`jit.save` will only save the `Program`, not the parameters. If you have to save the parameters, please make sure that {} is a member function of `paddle.nn.Layer` and the saved parameters are in `state_dict`'
format(layer)) .format(layer))
dygraph_state_dict = None dygraph_state_dict = None
if isinstance(inner_layer, Layer): if isinstance(inner_layer, Layer):
...@@ -922,8 +926,8 @@ def save(layer, path, input_spec=None, **configs): ...@@ -922,8 +926,8 @@ def save(layer, path, input_spec=None, **configs):
param_or_buffer_tensor = scope.var( param_or_buffer_tensor = scope.var(
param_or_buffer.name).get_tensor() param_or_buffer.name).get_tensor()
#src_tensor = param_or_buffer.value().get_tensor() #src_tensor = param_or_buffer.value().get_tensor()
src_tensor = state_var_dict[param_or_buffer.name].value( src_tensor = state_var_dict[
).get_tensor() param_or_buffer.name].value().get_tensor()
param_or_buffer_tensor._share_data_with(src_tensor) param_or_buffer_tensor._share_data_with(src_tensor)
# record var info # record var info
if param_or_buffer.name not in extra_var_info: if param_or_buffer.name not in extra_var_info:
...@@ -986,7 +990,7 @@ def save(layer, path, input_spec=None, **configs): ...@@ -986,7 +990,7 @@ def save(layer, path, input_spec=None, **configs):
params_filename=params_filename, params_filename=params_filename,
export_for_deployment=configs._export_for_deployment, export_for_deployment=configs._export_for_deployment,
program_only=configs._program_only, program_only=configs._program_only,
clip_extra=False) clip_extra=configs.clip_extra)
# NOTE(chenweihang): [ Save extra variable info ] # NOTE(chenweihang): [ Save extra variable info ]
# save_inference_model will lose some important variable information, including: # save_inference_model will lose some important variable information, including:
...@@ -1534,13 +1538,15 @@ class TracedLayer(object): ...@@ -1534,13 +1538,15 @@ class TracedLayer(object):
"fluid.dygraph.jit.TracedLayer.save_inference_model") "fluid.dygraph.jit.TracedLayer.save_inference_model")
if isinstance(feed, list): if isinstance(feed, list):
for f in feed: for f in feed:
check_type(f, "each element of feed", int, check_type(
f, "each element of feed", int,
"fluid.dygraph.jit.TracedLayer.save_inference_model") "fluid.dygraph.jit.TracedLayer.save_inference_model")
check_type(fetch, "fetch", (type(None), list), check_type(fetch, "fetch", (type(None), list),
"fluid.dygraph.jit.TracedLayer.save_inference_model") "fluid.dygraph.jit.TracedLayer.save_inference_model")
if isinstance(fetch, list): if isinstance(fetch, list):
for f in fetch: for f in fetch:
check_type(f, "each element of fetch", int, check_type(
f, "each element of fetch", int,
"fluid.dygraph.jit.TracedLayer.save_inference_model") "fluid.dygraph.jit.TracedLayer.save_inference_model")
clip_extra = kwargs.get('clip_extra', False) clip_extra = kwargs.get('clip_extra', False)
# path check # path check
...@@ -1575,8 +1581,7 @@ class TracedLayer(object): ...@@ -1575,8 +1581,7 @@ class TracedLayer(object):
model_filename = file_prefix + INFER_MODEL_SUFFIX model_filename = file_prefix + INFER_MODEL_SUFFIX
params_filename = file_prefix + INFER_PARAMS_SUFFIX params_filename = file_prefix + INFER_PARAMS_SUFFIX
save_inference_model( save_inference_model(dirname=dirname,
dirname=dirname,
feeded_var_names=feeded_var_names, feeded_var_names=feeded_var_names,
target_vars=target_vars, target_vars=target_vars,
executor=self._exe, executor=self._exe,
......
...@@ -570,7 +570,8 @@ if '${CMAKE_BUILD_TYPE}' == 'Release': ...@@ -570,7 +570,8 @@ if '${CMAKE_BUILD_TYPE}' == 'Release':
commands = ["install_name_tool -id '@loader_path/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so'] commands = ["install_name_tool -id '@loader_path/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so']
commands.append("install_name_tool -add_rpath '@loader_path/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so') commands.append("install_name_tool -add_rpath '@loader_path/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so')
else: else:
commands = ["patchelf --set-rpath '$ORIGIN/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so'] commands = ["patchelf --set-soname '${FLUID_CORE_NAME}.so' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so']
commands.append("patchelf --set-rpath '$ORIGIN/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so')
# The sw_64 not suppot patchelf, so we just disable that. # The sw_64 not suppot patchelf, so we just disable that.
if platform.machine() != 'sw_64' and platform.machine() != 'mips64': if platform.machine() != 'sw_64' and platform.machine() != 'mips64':
for command in commands: for command in commands:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册