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

[Eager] generate eager core ops, only 4 ops #37813

Merged
merged 43 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3847c76
refine a test case, test=develop
wanghuancoder Nov 23, 2021
a11334b
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Nov 23, 2021
fa2bf36
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Nov 25, 2021
3b4356b
publish python c api for eager, test=develop
wanghuancoder Nov 25, 2021
cf6cceb
revert modify about test_allclose_layer.py, test=develop
wanghuancoder Nov 25, 2021
35c5d0a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Nov 26, 2021
6352ae1
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Nov 29, 2021
a5b4261
refine, test=develop
wanghuancoder Nov 29, 2021
0732c3f
refine, test=develop
wanghuancoder Nov 29, 2021
e121ff8
refine, test=develop
wanghuancoder Nov 29, 2021
5cfa2e3
refine, test=develop
wanghuancoder Nov 29, 2021
ca2a4af
refine, test=develop
wanghuancoder Nov 29, 2021
79d1611
refine, test=develop
wanghuancoder Nov 29, 2021
5cb333a
delete numpy includes, use pybind11 numpy.h, test=develop
wanghuancoder Nov 30, 2021
0807b22
refine, test=develop
wanghuancoder Nov 30, 2021
56a25f6
refine, test=develop
wanghuancoder Nov 30, 2021
d2144f3
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Dec 1, 2021
24ebe93
refine, test=develop
wanghuancoder Dec 1, 2021
8d7d916
suport eager error msg, and add grad test case, test=develop
wanghuancoder Dec 1, 2021
c14d512
refine, test=develop
wanghuancoder Dec 1, 2021
f4fc5d2
refine, test=develop
wanghuancoder Dec 1, 2021
7582b6a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Dec 1, 2021
aeebaad
Merge commit 'refs/pull/37550/head' of https://github.com/PaddlePaddl…
wanghuancoder Dec 1, 2021
d32efe8
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Dec 2, 2021
a9651c5
generate eager core ops, only 4 ops, test=develop
wanghuancoder Dec 3, 2021
f77ab0e
merge
wanghuancoder Dec 3, 2021
6c1d436
refine, test=develop
wanghuancoder Dec 3, 2021
cccecb5
refine, test=develop
wanghuancoder Dec 3, 2021
70eb35e
refine, test=develop
wanghuancoder Dec 3, 2021
b83ec01
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Dec 3, 2021
0af3169
refine, test=develop
wanghuancoder Dec 3, 2021
2a28b95
refine, test=develop
wanghuancoder Dec 3, 2021
1294de0
refine, test=develop
wanghuancoder Dec 3, 2021
e636f31
refine, test=develop
wanghuancoder Dec 3, 2021
0aa0337
refine, test=develop
wanghuancoder Dec 3, 2021
1e09cce
refine, test=develop
wanghuancoder Dec 3, 2021
af85f65
refine, test=develop
wanghuancoder Dec 3, 2021
b3c6f28
refine, test=develop
wanghuancoder Dec 6, 2021
83a9506
refine, test=develop
wanghuancoder Dec 6, 2021
372fdb0
refine, test=develop
wanghuancoder Dec 6, 2021
a97365a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Dec 6, 2021
9a7c769
refine, test=develop
wanghuancoder Dec 7, 2021
4098851
Merge branch 'develop' into eager_coreops
wanghuancoder Dec 7, 2021
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
63 changes: 59 additions & 4 deletions paddle/fluid/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,25 @@ if(WITH_PYTHON)

add_executable(op_function_generator op_function_generator.cc)
target_link_libraries(op_function_generator ${OP_FUNCTION_GENERETOR_DEPS})
add_executable(eager_op_function_generator eager_op_function_generator.cc)
target_link_libraries(eager_op_function_generator ${OP_FUNCTION_GENERETOR_DEPS})

get_property (os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
target_link_libraries(op_function_generator ${os_dependency_modules})
target_link_libraries(eager_op_function_generator ${os_dependency_modules})
if(WITH_ROCM)
target_link_libraries(op_function_generator ${ROCM_HIPRTC_LIB})
target_link_libraries(eager_op_function_generator ${ROCM_HIPRTC_LIB})
endif()

set(impl_file ${CMAKE_SOURCE_DIR}/paddle/fluid/pybind/op_function_impl.h)
set(tmp_impl_file ${impl_file}.tmp)
set(eager_impl_file ${CMAKE_SOURCE_DIR}/paddle/fluid/pybind/eager_op_function_impl.h)
set(tmp_eager_impl_file ${eager_impl_file}.tmp)

set(OP_IMPL_DEPS op_function_generator)
set(EAGER_OP_IMPL_DEPS eager_op_function_generator)

if(WIN32)
if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
set(op_impl_path "${CMAKE_CURRENT_BINARY_DIR}")
Expand All @@ -165,29 +173,55 @@ if(WITH_PYTHON)
")\n"
"exit /b 0")

file(WRITE ${CMAKE_BINARY_DIR}/paddle/fluid/pybind/eager_op_function_generator_retry.bat ""
"set build_times=1\n"
":retry\n"
"ECHO eager_op_function_generator run %build_times% time\n"
"taskkill /f /im eager_op_function_generator.exe 2>NUL\n"
"${op_impl_path}/eager_op_function_generator.exe ${tmp_eager_impl_file}\n"
"if %ERRORLEVEL% NEQ 0 (\n"
" set /a build_times=%build_times%+1\n"
" if %build_times% GEQ 10 (\n"
" exit /b 1\n"
" ) else (\n"
" goto :retry\n"
" )\n"
")\n"
"exit /b 0")

if(${CBLAS_PROVIDER} STREQUAL MKLML)
ADD_CUSTOM_COMMAND(OUTPUT ${op_impl_path}/libiomp5md.dll
COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_SHARED_IOMP_LIB} ${op_impl_path}
DEPENDS mklml)
list(APPEND OP_IMPL_DEPS ${op_impl_path}/libiomp5md.dll)
list(APPEND EAGER_OP_IMPL_DEPS ${op_impl_path}/libiomp5md.dll)
else(${CBLAS_PROVIDER} STREQUAL EXTERN_OPENBLAS)
ADD_CUSTOM_COMMAND(OUTPUT ${op_impl_path}/openblas.dll
COMMAND ${CMAKE_COMMAND} -E copy ${OPENBLAS_SHARED_LIB} ${op_impl_path}
DEPENDS extern_openblas)
list(APPEND OP_IMPL_DEPS ${op_impl_path}/openblas.dll)
list(APPEND EAGER_OP_IMPL_DEPS ${op_impl_path}/openblas.dll)
endif()
if(WITH_MKLDNN)
ADD_CUSTOM_COMMAND(OUTPUT ${op_impl_path}/mkldnn.dll
COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_SHARED_LIB} ${op_impl_path}
DEPENDS mkldnn)
list(APPEND OP_IMPL_DEPS ${op_impl_path}/mkldnn.dll)
list(APPEND EAGER_OP_IMPL_DEPS ${op_impl_path}/mkldnn.dll)
endif()

add_custom_command(OUTPUT ${impl_file}
COMMAND ${CMAKE_BINARY_DIR}/paddle/fluid/pybind/op_function_generator_retry.bat
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_impl_file} ${impl_file}
COMMENT "copy_if_different ${tmp_impl_file} to ${impl_file}"
DEPENDS ${OP_IMPL_DEPS})
if(NOT ON_INFER)
add_custom_command(OUTPUT ${eager_impl_file}
COMMAND ${CMAKE_BINARY_DIR}/paddle/fluid/pybind/eager_op_function_generator_retry.bat
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_eager_impl_file} ${eager_impl_file}
COMMENT "copy_if_different ${tmp_eager_impl_file} to ${eager_impl_file}"
DEPENDS ${EAGER_OP_IMPL_DEPS})
endif()
else(WIN32)
# If there are no *.so in /usr/lib or LD_LIBRARY_PATH,
# copy these *.so to current directory and append current directory to
Expand All @@ -198,12 +232,14 @@ if(WITH_PYTHON)
COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_SHARED_IOMP_LIB} ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS mklml)
list(APPEND OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/libiomp5.so)
list(APPEND EAGER_OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/libiomp5.so)
endif()
if(WITH_MKLDNN)
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libdnnl.so.0
COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_SHARED_LIB} ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS mkldnn)
list(APPEND OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/libdnnl.so.0)
list(APPEND EAGER_OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/libdnnl.so.0)
endif()
add_custom_command(OUTPUT ${impl_file}
COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:."
Expand All @@ -213,15 +249,34 @@ if(WITH_PYTHON)
COMMENT "copy_if_different ${tmp_impl_file} to ${impl_file}"
DEPENDS ${OP_IMPL_DEPS}
VERBATIM)
if(NOT ON_INFER)
add_custom_command(OUTPUT ${eager_impl_file}
COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:."
"${CMAKE_CURRENT_BINARY_DIR}/eager_op_function_generator"
"${tmp_eager_impl_file}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_eager_impl_file} ${eager_impl_file}
COMMENT "copy_if_different ${tmp_eager_impl_file} to ${eager_impl_file}"
DEPENDS ${EAGER_OP_IMPL_DEPS}
VERBATIM)
endif()
endif(WIN32)
add_custom_target(op_function_generator_cmd ALL DEPENDS ${impl_file})
if(NOT ON_INFER)
add_custom_target(eager_op_function_generator_cmd ALL DEPENDS ${eager_impl_file})
endif()

list(APPEND PYBIND_DEPS interpretercore standalone_executor)
cc_library(op_function_common SRCS op_function_common.cc DEPS ${PYBIND_DEPS})
list(APPEND PYBIND_DEPS op_function_common)

cc_library(paddle_eager
SRCS eager.cc eager_functions.cc eager_method.cc eager_properties.cc eager_utils.cc
DEPS autograd_meta grad_node_info pten global_utils utils eager_api accumulation_node backward python)
list(APPEND PYBIND_DEPS paddle_eager)
if(NOT ON_INFER)
cc_library(paddle_eager
SRCS eager.cc eager_functions.cc eager_method.cc eager_properties.cc eager_utils.cc
DEPS eager_api autograd_meta backward grad_node_info pten op_function_common dygraph_function dygraph_node math_cpu linalg_cpu creation_cpu utils_cpu manipulation_cpu accumulation_node global_utils utils python)
add_dependencies(paddle_eager eager_codegen)
add_dependencies(paddle_eager eager_op_function_generator_cmd)
list(APPEND PYBIND_DEPS paddle_eager)
endif()

cc_library(paddle_pybind SHARED
SRCS ${PYBIND_SRCS}
Expand Down
3 changes: 3 additions & 0 deletions paddle/fluid/pybind/eager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License. */
#include <vector>

#include "paddle/fluid/eager/api/all.h"
#include "paddle/fluid/eager/api/generated/fluid_generated/dygraph_forward_api.h"
#include "paddle/fluid/eager/autograd_meta.h"
#include "paddle/fluid/eager/utils.h"
#include "paddle/fluid/memory/allocation/allocator.h"
Expand All @@ -27,6 +28,7 @@ limitations under the License. */
#include "paddle/pten/core/dense_tensor.h"
#include "paddle/pten/include/core.h"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#include "paddle/fluid/pybind/eager_op_function_impl.h"

namespace paddle {
namespace pybind {
Expand Down Expand Up @@ -126,6 +128,7 @@ void BindEager(pybind11::module* module) {
}

BindFunctions(m.ptr());
BindEagerOpFunctions(&m);
}

} // namespace pybind
Expand Down
4 changes: 4 additions & 0 deletions paddle/fluid/pybind/eager_method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern PyTypeObject* pEagerTensorType;
static PyObject* eager_tensor_method_numpy(EagerTensorObject* self,
PyObject* args, PyObject* kwargs) {
EAGER_TRY
self->eagertensor.SyncToTensor();
if (!self->eagertensor.initialized()) {
Py_INCREF(Py_None);
return Py_None;
Expand Down Expand Up @@ -93,6 +94,9 @@ static PyObject* eager_tensor_method_is_initialized(EagerTensorObject* self,
PyObject* args,
PyObject* kwargs) {
EAGER_TRY
if (self->eagertensor.Var().IsInitialized()) {
self->eagertensor.SyncToTensor();
}
return ToPyObject(self->eagertensor.initialized());
EAGER_CATCH_AND_THROW_RETURN_NULL
}
Expand Down
Loading