Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
Browse files Browse the repository at this point in the history
… while_loop_0d
  • Loading branch information
CtfGo committed Feb 6, 2023
2 parents 48e89ac + b8e6ca9 commit c283184
Show file tree
Hide file tree
Showing 450 changed files with 8,188 additions and 4,487 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,14 @@ if(WIN32)
endforeach()
endif()

# NOTE(zhouwei): msvc max/min macro conflict with std::min/max, define NOMINMAX globally
# msvc max/min macro conflict with std::min/max, define NOMINMAX globally
add_definitions("-DNOMINMAX")

# 1. windows.h define 'small' cause CUDA11.6/11.7/11.8 's cub compile error,
# see https://github.com/microsoft/onnxruntime/issues/11227
# 2. WIN32_LEAN_AND_MEAN minimize the windows include files, avoid define 'small'
add_definitions(-DWIN32_LEAN_AND_MEAN)

# windows build turn off warnings, use parallel compiling.
foreach(
flag_var
Expand Down
5 changes: 4 additions & 1 deletion cmake/external/cinn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ set(CINN_OPTIONAL_ARGS
-DWITH_MKL_CBLAS=${WITH_MKL}
-DWITH_MKLDNN=${WITH_MKL}
-DPUBLISH_LIBS=ON
-DWITH_TESTING=ON)
-DWITH_TESTING=ON
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
-DPYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR}
-DPYTHON_LIBRARIES=${PYTHON_LIBRARIES})
set(CINN_BUILD_COMMAND ${CMAKE_COMMAND} --build . --target cinnapi -j)
set(CINN_BINARY_DIR ${CINN_PREFIX_DIR}/src/external_cinn-build)
set(CINN_LIB_NAME "libcinnapi.so")
Expand Down
4 changes: 2 additions & 2 deletions cmake/external/cub.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

include(ExternalProject)

# Note(zhouwei): extern_cub has code __FILE_, If the path of extern_cub is changed,
# extern_cub has code __FILE_, If the path of extern_cub is changed,
# it will effect about 30+ cu files sccache hit and slow compile speed on windows.
# Therefore, a fixed CUB_PATH will be input to increase the sccache hit rate.
set(CUB_PATH
Expand All @@ -25,7 +25,7 @@ set(CUB_PREFIX_DIR ${CUB_PATH})
set(CUB_REPOSITORY ${GIT_URL}/NVlabs/cub.git)

if(${CMAKE_CUDA_COMPILER_VERSION} GREATER_EQUAL 11.6)
# cuda_11.6.2_511.65‘s own cub is 1.15.0, which will cause compiling error in windows.
# cuda_11.6/11.7/11.8‘s own cub is 1.15.0, which will cause compiling error in windows.
set(CUB_TAG 1.16.0)
# cub 1.16.0 is not compitable with current thrust version
add_definitions(-DTHRUST_IGNORE_CUB_VERSION_CHECK)
Expand Down
11 changes: 11 additions & 0 deletions cmake/operators.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,17 @@ function(op_library TARGET)
set(pybind_flag 1)
endif()

# pybind USE_OP_ITSELF
set(op_name "")
# Add PHI Kernel Registry Message
find_register(${cc_src} "REGISTER_ACTIVATION_OP" op_name)
if(NOT ${op_name} EQUAL "")
file(APPEND ${pybind_file} "USE_OP_ITSELF(${op_name});\n")
# hack: for example, the target in conv_transpose_op.cc is conv2d_transpose, used in mkldnn
set(TARGET ${op_name})
set(pybind_flag 1)
endif()

set(op_name "")
find_register(${cc_src} "REGISTER_OP_WITHOUT_GRADIENT" op_name)
if(NOT ${op_name} EQUAL "")
Expand Down
3 changes: 1 addition & 2 deletions cmake/third_party.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ if(WITH_ONNXRUNTIME)
endif()

if(WITH_GPU)
if(${CMAKE_CUDA_COMPILER_VERSION} LESS 11.0
OR (WIN32 AND ${CMAKE_CUDA_COMPILER_VERSION} GREATER_EQUAL 11.6))
if(${CMAKE_CUDA_COMPILER_VERSION} LESS 11.0)
include(external/cub) # download cub
list(APPEND third_party_deps extern_cub)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class {} : public egr::GradNodeBase {{
#include "paddle/fluid/eager/nan_inf_utils.h"
#include "paddle/phi/api/include/sparse_api.h"
#include "paddle/fluid/eager/api/manual/eager_manual/nodes/nodes.h"
#include "paddle/fluid/prim/api/manual/backward/composite_backward_api.h"
#include "paddle/fluid/prim/api/composite_backward/composite_backward_api.h"
#include "paddle/fluid/prim/api/all.h"
#include "paddle/fluid/prim/utils/utils.h"
DECLARE_bool(check_nan_inf);
Expand Down
52 changes: 52 additions & 0 deletions paddle/fluid/framework/dlpack_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,58 @@ struct DLDeviceVisitor
};
} // namespace internal

struct PaddleDLMTensor {
phi::DenseTensor handle;
DLManagedTensor tensor;
};

void deleter(DLManagedTensor *arg) {
delete[] arg->dl_tensor.shape;
delete[] arg->dl_tensor.strides;
delete static_cast<PaddleDLMTensor *>(arg->manager_ctx);
}

DLManagedTensor *toDLPack(const phi::DenseTensor &src) {
PaddleDLMTensor *pdDLMTensor(new PaddleDLMTensor);
pdDLMTensor->handle = const_cast<phi::DenseTensor &>(src);
pdDLMTensor->tensor.manager_ctx = pdDLMTensor;
pdDLMTensor->tensor.deleter = &deleter;
pdDLMTensor->tensor.dl_tensor.data = const_cast<void *>(src.data());

// init ndim
using DimType = decltype(pdDLMTensor->tensor.dl_tensor.ndim); // int
pdDLMTensor->tensor.dl_tensor.ndim = static_cast<DimType>(src.dims().size());
DimType ndim = pdDLMTensor->tensor.dl_tensor.ndim;

// init shape
auto shape = new int64_t[ndim];
for (DimType i = 0; i < ndim; ++i) {
shape[i] = src.dims()[i];
}
pdDLMTensor->tensor.dl_tensor.shape = shape;

// init stride
auto strides = new int64_t[ndim];
for (DimType i = 0; i < ndim; ++i) {
strides[i] = 1;
}
for (DimType i = ndim - 2; i >= 0; --i) {
strides[i] = shape[i + 1] * strides[i + 1];
}
pdDLMTensor->tensor.dl_tensor.strides = strides;

// init device, DLDevice type with device_type and device_id
auto place = src.place();
pdDLMTensor->tensor.dl_tensor.device =
paddle::platform::VisitPlace(place, internal::DLDeviceVisitor());

pdDLMTensor->tensor.dl_tensor.dtype = internal::GetDLDataTypeFromTypeIndex(
framework::TransToProtoVarType(src.dtype()));

pdDLMTensor->tensor.dl_tensor.byte_offset = 0;
return &(pdDLMTensor->tensor);
}

DLPackTensor::DLPackTensor(const phi::DenseTensor &tensor, LaneType lanes) {
// init data, data buffer
t_.data = const_cast<void *>(tensor.data());
Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/framework/dlpack_tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ class DLPackTensor {
ShapeType shape_[DDim::kMaxRank];
};

DLManagedTensor* toDLPack(const phi::DenseTensor& src);

} // namespace framework
} // namespace paddle
5 changes: 5 additions & 0 deletions paddle/fluid/framework/feed_fetch_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ namespace framework {
using FeedType =
paddle::variant<phi::DenseTensor, Strings, phi::SparseCooTensor>;

template <>
struct PhiVectorType<FeedType> {
const char *type_name = "PhiVectorFeedType";
};

using FeedList = paddle::framework::PhiVector<FeedType>;

using FetchType = paddle::variant<phi::DenseTensor,
Expand Down
12 changes: 0 additions & 12 deletions paddle/fluid/framework/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,10 @@ if(WITH_MKLDNN)
test_depthwise_conv_mkldnn_pass
SRCS mkldnn/depthwise_conv_mkldnn_pass_tester.cc
DEPS depthwise_conv_mkldnn_pass)
cc_test(
test_conv_bias_mkldnn_fuse_pass_cc
SRCS mkldnn/conv_bias_mkldnn_fuse_pass_tester.cc
DEPS conv_bias_mkldnn_fuse_pass naive_executor)
cc_test(
test_conv_activation_mkldnn_fuse_pass
SRCS mkldnn/conv_activation_mkldnn_fuse_pass_tester.cc
DEPS conv_activation_mkldnn_fuse_pass)
cc_test(
test_conv_concat_relu_mkldnn_fuse_pass
SRCS mkldnn/conv_concat_relu_mkldnn_fuse_pass_tester.cc
DEPS conv_activation_mkldnn_fuse_pass)
cc_test_old(
test_conv_elementwise_add_mkldnn_fuse_pass SRCS
mkldnn/conv_elementwise_add_mkldnn_fuse_pass_tester.cc DEPS
conv_elementwise_add_mkldnn_fuse_pass pass_test_util)
cc_test_old(
test_int8_scale_calculation_mkldnn_pass SRCS
mkldnn/int8_scale_calculation_mkldnn_pass_tester.cc DEPS
Expand Down
Loading

0 comments on commit c283184

Please sign in to comment.