Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/shuaihehe/Paddle into er…
Browse files Browse the repository at this point in the history
…r_21
  • Loading branch information
shuaihehe committed Apr 7, 2024
2 parents 99b75ce + 81ae815 commit bbaa3b9
Show file tree
Hide file tree
Showing 253 changed files with 1,915 additions and 1,471 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
path = third_party/xbyak
url = https://github.com/herumi/xbyak.git
ignore = dirty
[submodule "third_party/mkldnn"]
path = third_party/mkldnn
[submodule "third_party/onednn"]
path = third_party/onednn
url = https://github.com/oneapi-src/oneDNN.git
ignore = dirty
[submodule "third_party/flashattn"]
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ repos:
hooks:
- id: copyright_checker
name: copyright_checker
entry: python ./tools/codestyle/copyright.hook
entry: python ./tools/codestyle/copyright.py
language: system
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|xpu|kps|py|sh)$
exclude: |
Expand All @@ -67,15 +67,15 @@ repos:
- id: clang-format
name: clang-format
description: Format files with ClangFormat.
entry: bash ./tools/codestyle/clang_format.hook -i
entry: bash ./tools/codestyle/clang_format.sh -i
language: system
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$
- repo: local
hooks:
- id: cpplint-cpp-source
name: cpplint
description: Check C++ code style using cpplint.py.
entry: bash ./tools/codestyle/cpplint_pre_commit.hook
entry: bash ./tools/codestyle/cpplint_pre_commit.sh
language: system
files: \.(cc|cxx|cpp|cu|h|hpp|hxx)$
args:
Expand Down
4 changes: 2 additions & 2 deletions cmake/cinn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ if(WITH_MKL)
add_dependencies(cinnapi cinn_mklml)
if(WITH_MKLDNN)
target_link_libraries(cinnapi ${MKLDNN_LIB})
add_dependencies(cinnapi ${MKLDNN_PROJECT})
add_dependencies(cinnapi ${ONEDNN_PROJECT})
endif()
endif()

Expand Down Expand Up @@ -240,7 +240,7 @@ function(gen_cinncore LINKTYPE)
add_dependencies(${CINNCORE_TARGET} cinn_mklml)
if(WITH_MKLDNN)
target_link_libraries(${CINNCORE_TARGET} ${MKLDNN_LIB})
add_dependencies(${CINNCORE_TARGET} ${MKLDNN_PROJECT})
add_dependencies(${CINNCORE_TARGET} ${ONEDNN_PROJECT})
endif()
endif()

Expand Down
70 changes: 35 additions & 35 deletions cmake/external/mkldnn.cmake → cmake/external/onednn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

include(ExternalProject)

set(MKLDNN_PROJECT "extern_mkldnn")
set(MKLDNN_PREFIX_DIR ${THIRD_PARTY_PATH}/mkldnn)
set(MKLDNN_INSTALL_DIR ${THIRD_PARTY_PATH}/install/mkldnn)
set(ONEDNN_PROJECT "extern_onednn")
set(ONEDNN_PREFIX_DIR ${THIRD_PARTY_PATH}/onednn)
set(MKLDNN_INSTALL_DIR ${THIRD_PARTY_PATH}/install/onednn)
set(MKLDNN_INC_DIR
"${MKLDNN_INSTALL_DIR}/include"
CACHE PATH "mkldnn include directory." FORCE)
set(SOURCE_DIR ${PADDLE_SOURCE_DIR}/third_party/mkldnn)
CACHE PATH "oneDNN include directory." FORCE)
set(SOURCE_DIR ${PADDLE_SOURCE_DIR}/third_party/onednn)

# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
Expand All @@ -36,28 +36,28 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}"
"${MKLDNN_INSTALL_DIR}/${LIBDIR}")

include_directories(${MKLDNN_INC_DIR}
)# For MKLDNN code to include internal headers.
)# For oneDNN code to include internal headers.

if(NOT WIN32)
set(MKLDNN_FLAG
set(ONEDNN_FLAG
"-Wno-error=strict-overflow -Wno-error=unused-result -Wno-error=array-bounds"
)
set(MKLDNN_FLAG "${MKLDNN_FLAG} -Wno-unused-result -Wno-unused-value")
set(MKLDNN_CFLAG "${CMAKE_C_FLAGS} ${MKLDNN_FLAG}")
set(MKLDNN_CXXFLAG "${CMAKE_CXX_FLAGS} ${MKLDNN_FLAG}")
set(MKLDNN_CXXFLAG_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(MKLDNN_CFLAG_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
set(ONEDNN_FLAG "${ONEDNN_FLAG} -Wno-unused-result -Wno-unused-value")
set(ONEDNN_CFLAG "${CMAKE_C_FLAGS} ${ONEDNN_FLAG}")
set(ONEDNN_CXXFLAG "${CMAKE_CXX_FLAGS} ${ONEDNN_FLAG}")
set(ONEDNN_CXXFLAG_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(ONEDNN_CFLAG_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
set(MKLDNN_LIB
"${MKLDNN_INSTALL_DIR}/${LIBDIR}/libdnnl.so"
CACHE FILEPATH "mkldnn library." FORCE)
CACHE FILEPATH "oneDNN library." FORCE)
else()
set(MKLDNN_CXXFLAG "${CMAKE_CXX_FLAGS} /EHsc")
set(MKLDNN_CFLAG "${CMAKE_C_FLAGS}")
string(REPLACE "/O2 " "" MKLDNN_CFLAG_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/O2 " "" MKLDNN_CXXFLAG_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(ONEDNN_CXXFLAG "${CMAKE_CXX_FLAGS} /EHsc")
set(ONEDNN_CFLAG "${CMAKE_C_FLAGS}")
string(REPLACE "/O2 " "" ONEDNN_CFLAG_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/O2 " "" ONEDNN_CXXFLAG_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(MKLDNN_LIB
"${MKLDNN_INSTALL_DIR}/bin/mkldnn.lib"
CACHE FILEPATH "mkldnn library." FORCE)
CACHE FILEPATH "oneDNN library." FORCE)
endif()

if(LINUX)
Expand All @@ -67,21 +67,21 @@ else()
endif()

ExternalProject_Add(
${MKLDNN_PROJECT}
${ONEDNN_PROJECT}
${EXTERNAL_PROJECT_LOG_ARGS}
SOURCE_DIR ${SOURCE_DIR}
DEPENDS ${MKLDNN_DEPENDS}
PREFIX ${MKLDNN_PREFIX_DIR}
DEPENDS ${ONEDNN_DEPENDS}
PREFIX ${ONEDNN_PREFIX_DIR}
UPDATE_COMMAND ""
#BUILD_ALWAYS 1
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_FLAGS=${MKLDNN_CXXFLAG}
-DCMAKE_CXX_FLAGS_RELEASE=${MKLDNN_CXXFLAG_RELEASE}
-DCMAKE_CXX_FLAGS=${ONEDNN_CXXFLAG}
-DCMAKE_CXX_FLAGS_RELEASE=${ONEDNN_CXXFLAG_RELEASE}
-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
-DCMAKE_C_FLAGS=${MKLDNN_CFLAG}
-DCMAKE_C_FLAGS=${ONEDNN_CFLAG}
-DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
-DCMAKE_C_FLAGS_RELEASE=${MKLDNN_CFLAG_RELEASE}
-DCMAKE_C_FLAGS_RELEASE=${ONEDNN_CFLAG_RELEASE}
-DCMAKE_INSTALL_PREFIX=${MKLDNN_INSTALL_DIR}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
Expand All @@ -90,7 +90,7 @@ ExternalProject_Add(
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR}
BUILD_BYPRODUCTS ${BUILD_BYPRODUCTS_ARGS})

message(STATUS "MKLDNN library: ${MKLDNN_LIB}")
message(STATUS "OneDNN library: ${MKLDNN_LIB}")
add_definitions(-DPADDLE_WITH_DNNL)
# copy the real so.0 lib to install dir
# it can be directly contained in wheel or capi
Expand Down Expand Up @@ -123,21 +123,21 @@ if(WIN32)
COMMAND lib /def:${MKLDNN_INSTALL_DIR}/bin/mkldnn.def /out:${MKLDNN_LIB}
/machine:x64
COMMENT "Generate mkldnn.lib manually--->"
DEPENDS ${MKLDNN_PROJECT}
DEPENDS ${ONEDNN_PROJECT}
VERBATIM)
add_custom_target(mkldnn_cmd ALL DEPENDS ${MKLDNN_LIB})
add_custom_target(onednn_cmd ALL DEPENDS ${MKLDNN_LIB})
else()
set(MKLDNN_SHARED_LIB ${MKLDNN_INSTALL_DIR}/libdnnl.so.3)
add_custom_command(
OUTPUT ${MKLDNN_SHARED_LIB}
COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_LIB} ${MKLDNN_SHARED_LIB}
DEPENDS ${MKLDNN_PROJECT})
add_custom_target(mkldnn_cmd ALL DEPENDS ${MKLDNN_SHARED_LIB})
DEPENDS ${ONEDNN_PROJECT})
add_custom_target(onednn_cmd ALL DEPENDS ${MKLDNN_SHARED_LIB})
endif()

# generate a static dummy target to track mkldnn dependencies
# for cc_library(xxx SRCS xxx.c DEPS mkldnn)
generate_dummy_static_lib(LIB_NAME "mkldnn" GENERATOR "mkldnn.cmake")
# generate a static dummy target to track onednn dependencies
# for cc_library(xxx SRCS xxx.c DEPS onednn)
generate_dummy_static_lib(LIB_NAME "onednn" GENERATOR "onednn.cmake")

target_link_libraries(mkldnn ${MKLDNN_LIB} ${MKLML_IOMP_LIB})
add_dependencies(mkldnn ${MKLDNN_PROJECT} mkldnn_cmd)
target_link_libraries(onednn ${MKLDNN_LIB} ${MKLML_IOMP_LIB})
add_dependencies(onednn ${ONEDNN_PROJECT} onednn_cmd)
4 changes: 2 additions & 2 deletions cmake/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ function(paddle_test_build TARGET_NAME)
add_dependencies(${TARGET_NAME} ${paddle_lib} ${paddle_test_DEPS} common
paddle_gtest_main_new)
if(WITH_MKLDNN)
target_link_libraries(${TARGET_NAME} mkldnn)
add_dependencies(${TARGET_NAME} mkldnn)
target_link_libraries(${TARGET_NAME} onednn)
add_dependencies(${TARGET_NAME} onednn)
endif()
if(WITH_SHARED_PHI)
target_link_libraries(${TARGET_NAME} $<TARGET_LINKER_FILE:phi>)
Expand Down
2 changes: 1 addition & 1 deletion cmake/inference_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function(copy_part_of_third_party TARGET DST)
endif()

if(WITH_MKLDNN)
set(dst_dir "${DST}/third_party/install/mkldnn")
set(dst_dir "${DST}/third_party/install/onednn")
if(WIN32)
copy(
${TARGET}
Expand Down
4 changes: 2 additions & 2 deletions cmake/third_party.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ elseif(${CBLAS_PROVIDER} STREQUAL EXTERN_OPENBLAS)
endif()

if(WITH_MKLDNN)
include(external/mkldnn) # download, build, install mkldnn
list(APPEND third_party_deps extern_mkldnn)
include(external/onednn) # download, build, install onednn
list(APPEND third_party_deps extern_onednn)
endif()

include(external/protobuf) # find first, then download, build, install protobuf
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/index_dataset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if(WITH_MKLDNN)
cc_library(
index_sampler
SRCS index_sampler.cc
DEPS xxhash index_wrapper eigen3 mkldnn)
DEPS xxhash index_wrapper eigen3 onednn)
else()
cc_library(
index_sampler
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/eager/auto_code_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if(WIN32)
OUTPUT ${eager_generator_path}/mkldnn.dll
COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_SHARED_LIB}
${eager_generator_path}
DEPENDS mkldnn)
DEPENDS onednn)
list(APPEND EAGER_CODEGEN_DEPS ${eager_generator_path}/mkldnn.dll)
endif()

Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/eager/to_static/run_program_op_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "paddle/pir/include/core/value.h"

#ifdef PADDLE_WITH_DNNL
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/platform/onednn_helper.h"
#endif

COMMON_DECLARE_bool(enable_pir_with_pt_in_dy2st);
Expand Down
14 changes: 7 additions & 7 deletions paddle/fluid/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ if(WITH_XPU)
target_link_libraries(var_type_traits dynload_xpti)
endif()

# every source file that includes "dnnl.h" must depends on mkldnn
# or, the first one should depends on mkldnn
# every source file that includes "dnnl.h" must depends on onednn
# or, the first one should depends on onednn
if(WITH_MKLDNN)
add_dependencies(var_type_traits mkldnn)
add_dependencies(var_type_traits onednn)
endif()

set(BRPC_DEPS "")
Expand Down Expand Up @@ -273,10 +273,10 @@ cc_library(
SRCS shape_inference.cc
DEPS phi common attribute selected_rows_utils)

# every source file that includes "dnnl.h" must depends on mkldnn
# or, the first one should depends on mkldnn
# every source file that includes "dnnl.h" must depends on onednn
# or, the first one should depends on onednn
if(WITH_MKLDNN)
add_dependencies(shape_inference mkldnn)
add_dependencies(shape_inference onednn)
endif()

cc_library(
Expand Down Expand Up @@ -955,7 +955,7 @@ cc_library(
target_link_libraries(type_info pir op_dialect)
add_dependencies(type_info framework_proto auto_parallel_proto xxhash)
if(WITH_MKLDNN)
add_dependencies(type_info mkldnn)
add_dependencies(type_info onednn)
endif()

set(FLUID_FRAMEWORK_MODULES
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/data_transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Variable;
} // namespace paddle

#ifdef PADDLE_WITH_DNNL
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/platform/onednn_helper.h"
#endif

namespace paddle {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/details/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ set(op_handle_deps
reference_count_pass_helper)

if(WITH_MKLDNN)
set(op_handle_deps ${op_handle_deps} mkldnn)
set(op_handle_deps ${op_handle_deps} onednn)
endif()

if(WITH_DGC)
Expand Down Expand Up @@ -162,5 +162,5 @@ cc_library(
DEPS pass_builder ${IR_PASS_DEPS})

if(WITH_MKLDNN)
target_link_libraries(build_strategy mkldnn_placement_pass)
target_link_libraries(build_strategy onednn_placement_pass)
endif()
8 changes: 4 additions & 4 deletions paddle/fluid/framework/details/build_strategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ParallelExecutorPassBuilder : public ir::PassBuilder {
AppendMultiDevPass();
AppendMultiGraphOptPasses();

AppendPassToSetMkldnnAttr("mkldnn_placement_pass");
AppendPassToSetMkldnnAttr("onednn_placement_pass");
// runtime_context_cache pass should be the last pass to enable the attr of
// all original and fused operators. But no operators can be enabled this
// attr if putting it after MultiDevPass.
Expand Down Expand Up @@ -179,7 +179,7 @@ class ParallelExecutorPassBuilder : public ir::PassBuilder {
"delete_dropout_op_x_pass");
AppendPassWithCheck(
strategy_.enable_inference_pass_ && strategy_.use_mkldnn_,
"mkldnn_placement_pass");
"onednn_placement_pass");

// 2. trainning pass
#ifdef PADDLE_WITH_CUDNN_FRONTEND
Expand Down Expand Up @@ -480,7 +480,7 @@ ir::Graph *BuildStrategy::Apply(ir::Graph *graph,
"GPU, skipped.";
continue;
}
} else if (pass->Type() == "mkldnn_placement_pass") {
} else if (pass->Type() == "onednn_placement_pass") {
pass->Set("mkldnn_enabled_op_types",
new std::unordered_set<std::string>(mkldnn_enabled_op_types_));
} else if (pass->Type() == "backward_optimizer_op_deps_pass") {
Expand Down Expand Up @@ -548,7 +548,7 @@ USE_PASS(build_cinn_pass);
USE_PASS(fused_feedforward_pass);
#endif
#ifdef PADDLE_WITH_DNNL
USE_PASS(mkldnn_placement_pass);
USE_PASS(onednn_placement_pass);
#endif
#if (defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)) && \
!defined(_WIN32) && !defined(__APPLE__)
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License. */
#include "paddle/fluid/platform/profiler.h"
#include "paddle/fluid/platform/profiler/event_tracing.h"
#ifdef PADDLE_WITH_DNNL
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/platform/onednn_helper.h"
#endif
#include "paddle/common/flags.h"
#include "paddle/fluid/framework/executor_gc_helper.h"
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ cc_library(
DEPS ${framework_io_deps})

if(WITH_MKLDNN)
add_dependencies(framework_io mkldnn)
add_dependencies(framework_io onednn)
endif()
Loading

0 comments on commit bbaa3b9

Please sign in to comment.