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
… dev/unify_gpu_context3
  • Loading branch information
zhiqiu committed Aug 1, 2022
2 parents 8b50436 + 2a8219c commit 89ee39e
Show file tree
Hide file tree
Showing 26 changed files with 943 additions and 523 deletions.
2 changes: 1 addition & 1 deletion cmake/external/dgc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ExternalProject_Add(
URL_MD5 "94e6fa1bc97169d0e1aad44570fe3251"
PREFIX "${DGC_PREFIX_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND make -j $(nproc)
BUILD_COMMAND make -j${NPROC}
INSTALL_COMMAND
mkdir -p ${DGC_INSTALL_DIR}/lib/ ${DGC_INCLUDE_DIR}/dgc && cp
${DGC_SOURCES_DIR}/build/lib/libdgc.a ${DGC_LIBRARIES} && cp
Expand Down
4 changes: 2 additions & 2 deletions cmake/external/gflags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ else()
set(GFLAGS_LIBRARIES
"${GFLAGS_INSTALL_DIR}/lib/libgflags.a"
CACHE FILEPATH "GFLAGS_LIBRARIES" FORCE)
set(BUILD_COMMAND $(MAKE) --silent)
set(INSTALL_COMMAND $(MAKE) install)
set(BUILD_COMMAND ${CMAKE_COMMAND} --build .)
set(INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install)
endif()

include_directories(${GFLAGS_INCLUDE_DIR})
Expand Down
9 changes: 8 additions & 1 deletion cmake/external/mkldnn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ else()
CACHE FILEPATH "mkldnn library." FORCE)
endif()

if(LINUX)
set(BUILD_BYPRODUCTS_ARGS ${MKLDNN_LIB})
else()
set(BUILD_BYPRODUCTS_ARGS "")
endif()

ExternalProject_Add(
${MKLDNN_PROJECT}
${EXTERNAL_PROJECT_LOG_ARGS} ${SHALLOW_CLONE}
Expand All @@ -83,7 +89,8 @@ ExternalProject_Add(
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DDNNL_BUILD_TESTS=OFF
-DDNNL_BUILD_EXAMPLES=OFF
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR})
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR}
BUILD_BYPRODUCTS ${BUILD_BYPRODUCTS_ARGS})

message(STATUS "MKLDNN library: ${MKLDNN_LIB}")
add_definitions(-DPADDLE_WITH_MKLDNN)
Expand Down
2 changes: 1 addition & 1 deletion cmake/external/openblas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if(NOT WIN32)
PREFIX ${CBLAS_PREFIX_DIR}
INSTALL_DIR ${CBLAS_INSTALL_DIR}
BUILD_IN_SOURCE 1
BUILD_COMMAND make -j$(nproc) ${COMMON_ARGS} ${OPTIONAL_ARGS}
BUILD_COMMAND make -j${NPROC} ${COMMON_ARGS} ${OPTIONAL_ARGS}
INSTALL_COMMAND make install NO_SHARED=1 NO_LAPACK=1 PREFIX=<INSTALL_DIR>
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
Expand Down
3 changes: 2 additions & 1 deletion cmake/external/rocksdb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ ExternalProject_Add(
${ROCKSDB_PREFIX_DIR}/src/extern_rocksdb/librocksdb.a ${ROCKSDB_LIBRARIES}
&& cp -r ${ROCKSDB_PREFIX_DIR}/src/extern_rocksdb/include
${ROCKSDB_INSTALL_DIR}/
BUILD_IN_SOURCE 1)
BUILD_IN_SOURCE 1
BYPRODUCTS ${ROCKSDB_LIBRARIES})

add_dependencies(extern_rocksdb snappy)

Expand Down
3 changes: 3 additions & 0 deletions cmake/third_party.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ set(THIRD_PARTY_CACHE_PATH
set(THIRD_PARTY_BUILD_TYPE Release)
set(third_party_deps)

include(ProcessorCount)
ProcessorCount(NPROC)

# cache funciton to avoid repeat download code of third_party.
# This function has 4 parameters, URL / REPOSITOR / TAG / DIR:
# 1. URL: specify download url of 3rd party
Expand Down
30 changes: 0 additions & 30 deletions paddle/fluid/operators/lu_unpack_op.cu

This file was deleted.

139 changes: 18 additions & 121 deletions paddle/fluid/operators/overlap_add_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/fluid/operators/overlap_add_op.h"
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/backward.h"
#include "paddle/phi/infermeta/unary.h"

namespace paddle {
namespace operators {
Expand All @@ -21,93 +25,6 @@ class OverlapAddOp : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;

void InferShape(framework::InferShapeContext* ctx) const override {
OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "overlap_add");
OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "overlap_add");

const int hop_length = ctx->Attrs().Get<int>("hop_length");
const int axis = ctx->Attrs().Get<int>("axis");

const auto x_dims = ctx->GetInputDim("X");
const int x_rank = x_dims.size();

PADDLE_ENFORCE_GE(
x_rank,
2,
platform::errors::InvalidArgument(
"Input(X) of OverlapAddOp should be a tensor which contains "
"at least 2 dimensions, but got rank %s.",
x_rank));

PADDLE_ENFORCE_GT(
hop_length,
0,
platform::errors::InvalidArgument(
"Attribute(hop_length) of OverlapAddOp should be greater "
"than 0, but got %s.",
hop_length));

PADDLE_ENFORCE_EQ(
(axis == 0 || axis == -1),
true,
platform::errors::InvalidArgument(
"Attribute(axis) of OverlapAddOp should 0 or -1, but got %s.",
axis));

std::vector<int64_t> output_shape;
int n_frames;
int frame_length;
int seq_length;

int start_axis;
int end_axis;
if (axis == 0) {
n_frames = x_dims[0];
frame_length = x_dims[1];
start_axis = 2;
end_axis = x_rank - 1;
} else {
n_frames = x_dims[x_rank - 1];
frame_length = x_dims[x_rank - 2];
start_axis = 0;
end_axis = x_rank - 3;
}

bool contain_unknown_dim = phi::contain_unknown_dim(x_dims);
bool check = ctx->IsRuntime() || !contain_unknown_dim;
if (check) {
PADDLE_ENFORCE_LE(
hop_length,
frame_length,
platform::errors::InvalidArgument(
"Attribute(hop_length) of OverlapAddOp should be less or equal "
"than frame_length, but got hop_length(%s) > frame_length(%s).",
hop_length,
frame_length));
}

if (n_frames == -1) {
seq_length = -1;
} else {
seq_length = (n_frames - 1) * hop_length + frame_length;
}

// It won't go into for loop when x_rank == 2U.
for (int i = start_axis; i <= end_axis; i++) {
output_shape.push_back(x_dims[i]);
}

if (axis == 0) {
// (seq_length, ...)
output_shape.insert(output_shape.begin(), seq_length);
} else {
// (..., seq_length)
output_shape.push_back(seq_length);
}

ctx->SetOutputDim("Out", phi::make_ddim(output_shape));
}

protected:
framework::OpKernelType GetExpectedKernelType(
const framework::ExecutionContext& ctx) const override {
Expand Down Expand Up @@ -137,17 +54,6 @@ class OverlapAddOpMaker : public framework::OpProtoAndCheckerMaker {
class OverlapAddOpGrad : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;
void InferShape(framework::InferShapeContext* ctx) const override {
OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "overlap_add_grad");
OP_INOUT_CHECK(ctx->HasInput(framework::GradVarName("Out")),
"Input",
"Out@GRAD",
"overlap_add_grad");
const auto x_dims = ctx->GetInputDim("X");
if (ctx->HasOutput(framework::GradVarName("X"))) {
ctx->SetOutputDim(framework::GradVarName("X"), x_dims);
}
}

protected:
framework::OpKernelType GetExpectedKernelType(
Expand Down Expand Up @@ -176,30 +82,21 @@ class OverlapAddOpGradMaker : public framework::SingleGradOpMaker<T> {

namespace ops = paddle::operators;

DECLARE_INFER_SHAPE_FUNCTOR(overlap_add,
OverlapAddInferShapeFunctor,
PD_INFER_META(phi::OverlapAddInferMeta));

DECLARE_INFER_SHAPE_FUNCTOR(overlap_add_grad,
OverlapAddGradInferShapeFunctor,
PD_INFER_META(phi::OverlapAddGradInferMeta));

REGISTER_OPERATOR(overlap_add,
ops::OverlapAddOp,
ops::OverlapAddOpMaker,
ops::OverlapAddOpGradMaker<paddle::framework::OpDesc>,
ops::OverlapAddOpGradMaker<paddle::imperative::OpBase>);

REGISTER_OPERATOR(overlap_add_grad, ops::OverlapAddOpGrad);

REGISTER_OP_CPU_KERNEL(
overlap_add,
ops::OverlapAddKernel<phi::CPUContext, int>,
ops::OverlapAddKernel<phi::CPUContext, int64_t>,
ops::OverlapAddKernel<phi::CPUContext, float>,
ops::OverlapAddKernel<phi::CPUContext, double>,
ops::OverlapAddKernel<phi::CPUContext, paddle::platform::complex<float>>,
ops::OverlapAddKernel<phi::CPUContext, paddle::platform::complex<double>>);
ops::OverlapAddOpGradMaker<paddle::imperative::OpBase>,
OverlapAddInferShapeFunctor);

REGISTER_OP_CPU_KERNEL(
overlap_add_grad,
ops::OverlapAddGradKernel<phi::CPUContext, int>,
ops::OverlapAddGradKernel<phi::CPUContext, int64_t>,
ops::OverlapAddGradKernel<phi::CPUContext, float>,
ops::OverlapAddGradKernel<phi::CPUContext, double>,
ops::OverlapAddGradKernel<phi::CPUContext,
paddle::platform::complex<float>>,
ops::OverlapAddGradKernel<phi::CPUContext,
paddle::platform::complex<double>>);
REGISTER_OPERATOR(overlap_add_grad,
ops::OverlapAddOpGrad,
OverlapAddGradInferShapeFunctor);
39 changes: 0 additions & 39 deletions paddle/fluid/operators/overlap_add_op.cu

This file was deleted.

Loading

0 comments on commit 89ee39e

Please sign in to comment.