Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#33 from zyfncg/merge_dev
Browse files Browse the repository at this point in the history
Merge develop
  • Loading branch information
yuanlehome authored Sep 20, 2023
2 parents 5239e7d + 10dba83 commit 43d5e48
Show file tree
Hide file tree
Showing 1,570 changed files with 45,152 additions and 18,953 deletions.
6 changes: 3 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ clang-analyzer-cplusplus.InnerPointer,
-clang-analyzer-cplusplus.SelfAssignment,
-clang-analyzer-cplusplus.SmartPtr,
-clang-analyzer-cplusplus.VirtualCallModeling,
-clang-analyzer-deadcode.DeadStores,
clang-analyzer-deadcode.DeadStores,
-clang-analyzer-fuchsia.HandleChecker,
-clang-analyzer-nullability.NullPassedToNonnull,
-clang-analyzer-nullability.NullReturnedFromNonnull,
Expand Down Expand Up @@ -156,8 +156,8 @@ cppcoreguidelines-avoid-c-arrays,
cppcoreguidelines-c-copy-assignment-signature,
cppcoreguidelines-explicit-virtual-functions,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-no-malloc,
cppcoreguidelines-narrowing-conversions,
cppcoreguidelines-no-malloc,
-cppcoreguidelines-pro-type-const-cast,
-cppcoreguidelines-pro-type-member-init,
-cppcoreguidelines-slicing,
Expand Down
8 changes: 6 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
select = C,E,W
exclude =
./build,
# Exclude fluid directory
./python/paddle/base/**,
# Exclude third-party libraries
./third_party/**,
./python/paddle/utils/gast/**,
Expand All @@ -27,3 +25,9 @@ ignore =
per-file-ignores =
# These files need tabs for testing.
test/dygraph_to_static/test_error.py:E101,W191

# temp ignore base directory
python/paddle/base/*:
E712,
E266,
E714
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ python/paddle/incubate/fleet/parameter_server/pslib/ps_pb2.py
paddle/phi/kernels/fusion/cutlass/conv2d/generated/*
python/paddle/base/incubate/fleet/parameter_server/pslib/ps_pb2.py
paddle/fluid/ir_adaptor/translator/op_compat_info.cc
paddle/phi/kernels/fusion/cutlass/cutlass_kernels/fpA_intB_gemm/autogen/*
paddle/fluid/pybind/static_op_function.*
paddle/fluid/pybind/ops_api.cc
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ repos:
- id: flake8
args: ["--config=.flake8"]
- repo: /~https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.272
rev: v0.0.289
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --no-cache]
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ option(WITH_CUDNN_FRONTEND
option(WITH_CUDNN_DSO "Compile PaddlePaddle with cuDNN dynamic-link libraries"
OFF)
option(WITH_SHARED_IR "Compile PaddlePaddle with SHARED LIB of IR" ON)
option(WITH_NVCC_LAZY
"Compile PaddlePaddle with nvcc lazy mode, used for CI-Inference only."
ON)

if(WITH_RECORD_BUILDTIME)
set_property(
Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at paddle-dev@baidu.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ext_paddle_oss@baidu.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

## 强制执行

可以通过paddle-dev@baidu.com,来联系项目团队来举报滥用、骚扰或其他不被接受的行为。
可以通过ext_paddle_oss@baidu.com,来联系项目团队来举报滥用、骚扰或其他不被接受的行为。

任何维护团队认为有必要且适合的所有投诉都将进行审查及调查,并做出相对应的回应。项目小组有对事件回报者有保密的义务。具体执行的方针近一步细节可能会单独公布。

Expand Down
6 changes: 6 additions & 0 deletions cmake/experiments/cuda_module_loading_lazy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
# this experiment option makes Paddle supports lazy loading before CUDA 11.7.

if(LINUX)
if(NOT WITH_NVCC_LAZY)
message(
"EXP_CUDA_MODULE_LOADING_LAZY only works with WITH_NVCC_LAZY=ON on Linux platforms"
)
return()
endif()
if(NOT ON_INFER)
message(
"EXP_CUDA_MODULE_LOADING_LAZY only works with ON_INFER=ON on Linux platforms"
Expand Down
2 changes: 1 addition & 1 deletion cmake/external/gloo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if(WITH_GPU)
file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/gloo/device.cc.patch
native_dst)
set(GLOO_PATCH_COMMAND
git checkout -- . && git checkout ${GLOO_TAG} &&patch -Nd
git checkout -- . && git checkout ${GLOO_TAG} && patch -Nd
${SOURCE_DIR}/gloo/transport/tcp < ${native_dst})
endif()
endif()
Expand Down
8 changes: 6 additions & 2 deletions cmake/hip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ find_package_and_include(rocsparse)
find_package_and_include(rocfft)

# set CXX flags for HIP
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__HIP_PLATFORM_HCC__")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__HIP_PLATFORM_HCC__")
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -D__HIP_PLATFORM_HCC__ -DROCM_NO_WRAPPER_HEADER_WARNING")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -D__HIP_PLATFORM_HCC__ -DROCM_NO_WRAPPER_HEADER_WARNING"
)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIP")
set(THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_HIP)
Expand All @@ -96,6 +99,7 @@ list(APPEND HIP_CXX_FLAGS -fPIC)
list(APPEND HIP_CXX_FLAGS -D__HIP_PLATFORM_HCC__=1)
# Note(qili93): HIP has compile conflicts of float16.h as platform::float16 overload std::is_floating_point and std::is_integer
list(APPEND HIP_CXX_FLAGS -D__HIP_NO_HALF_CONVERSIONS__=1)
list(APPEND HIP_CXX_FLAGS -DROCM_NO_WRAPPER_HEADER_WARNING)
list(APPEND HIP_CXX_FLAGS -Wno-macro-redefined)
list(APPEND HIP_CXX_FLAGS -Wno-inconsistent-missing-override)
list(APPEND HIP_CXX_FLAGS -Wno-exceptions)
Expand Down
1 change: 1 addition & 0 deletions paddle/cinn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if(WITH_TESTING)
endif()

add_subdirectory(api)
add_subdirectory(ast_gen_ius)
add_subdirectory(auto_schedule)
add_subdirectory(common)
add_subdirectory(utils)
Expand Down
6 changes: 6 additions & 0 deletions paddle/cinn/ast_gen_ius/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
core_gather_headers()

gather_srcs(cinnapi_src SRCS ast_gen.cc tensor_group.cc)

cinn_cc_test(test_ast_gen_ius SRCS ast_gen_test.cc DEPS cinncore)
cinn_cc_test(test_tensor_group SRCS tensor_group_test.cc DEPS cinncore)
132 changes: 132 additions & 0 deletions paddle/cinn/ast_gen_ius/ast_gen.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright (c) 2023 CINN Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/cinn/ast_gen_ius/ast_gen.h"
#include "paddle/cinn/ir/ir.h"
#include "paddle/cinn/ir/ir_base.h"
#include "paddle/cinn/ir/operation.h"
#include "paddle/cinn/ir/tensor.h"
#include "paddle/cinn/ir/utils/ir_printer.h"
#include "paddle/cinn/lang/compute.h"

namespace cinn {
namespace ast_gen_ius {

ir::Expr ConvertReduceBody(ir::Expr body,
ir::Tensor tensor,
const std::vector<Expr>& axis_exprs) {
ir::Reduce* reduce_node = body.As<ir::Reduce>();
if (!reduce_node) {
return ir::Store::Make(tensor, body, axis_exprs);
}

switch (reduce_node->reduce_type) {
case ir::Reduce::kSum:
return ir::Store::Make(
tensor, tensor(axis_exprs) + reduce_node->body, axis_exprs);
case ir::Reduce::kMul:
return ir::Store::Make(
tensor, tensor(axis_exprs) * reduce_node->body, axis_exprs);
case ir::Reduce::kMax:
return ir::Store::Make(
tensor,
ir::Max::Make(tensor(axis_exprs), reduce_node->body),
axis_exprs);
case ir::Reduce::kMin:
return ir::Store::Make(
tensor,
ir::Min::Make(tensor(axis_exprs), reduce_node->body),
axis_exprs);
case ir::Reduce::kAll:
return ir::Store::Make(
tensor, tensor(axis_exprs) && reduce_node->body, axis_exprs);
case ir::Reduce::kAny:
return ir::Store::Make(
tensor, tensor(axis_exprs) || reduce_node->body, axis_exprs);
default:
CINN_NOT_IMPLEMENTED
}
}

ir::Expr AstGen::Build(const ir::Tensor& tensor, TensorGroup* tensor_group) {
const std::vector<ir::Var>& axis = tensor->axis();
const std::vector<ir::Expr>& shape = tensor->shape;
size_t axis_len = axis.size();
CHECK_EQ(shape.size(), axis_len) << "Internal Error: Tensor has different "
"shape and axis length in AstGen";
std::vector<ir::Expr> axis_exprs;
for (const auto& a : axis) {
axis_exprs.push_back(a);
}

if (tensor->is_reduce_tensor()) {
// Make an init Tensor for domain without reduce axis
Expr init_value = tensor->GetReduceInitVal();
// TODO(zhhsplendid): Clean the handcoded "__reduce_init" string
std::string reduce_init_name = tensor->name + "__reduce_init";
const std::vector<Expr>& domain = tensor->domain_without_reduce_axis();
ir::Tensor init_tensor = lang::Compute(
domain,
[=](const std::vector<Expr>& axis) { return init_value; },
reduce_init_name);
tensor_group->Insert(init_tensor);
tensor_group->MarkShareMemBuffer(tensor, init_tensor);
tensor_group->CtrlDepend(tensor, init_tensor);
Expr init_body = ir::Store::Make(init_tensor, init_value, axis_exprs);

// For the remaining reduce axis, make reduce body
const std::vector<ir::Var>& reduce_axis = tensor->reduce_axis;
ir::Expr reduce_body =
ConvertReduceBody(tensor->body(), tensor, axis_exprs);
for (int i = static_cast<int>(reduce_axis.size()) - 1; i >= 0; --i) {
reduce_body = ir::For::Make(reduce_axis[i],
reduce_axis[i]->lower_bound,
reduce_axis[i]->upper_bound,
ir::ForType::Serial,
ir::DeviceAPI::Host,
ir::Block::Make({reduce_body}));
}

// Put the two parts together
ir::Expr body = ir::Block::Make({init_body, reduce_body});
for (int i = static_cast<int>(axis_len) - 1; i >= 0; --i) {
ir::Var loop_var = axis[i];
ir::Expr loop_extent = shape[i];
body = ir::For::Make(
loop_var,
Expr(0),
loop_extent,
ir::ForType::Serial,
ir::DeviceAPI::Host,
i == static_cast<int>(axis_len) - 1 ? body : ir::Block::Make({body}));
}
return body;
} else {
ir::Expr body = ir::Store::Make(tensor, tensor->body(), axis_exprs);
for (int i = static_cast<int>(axis_len) - 1; i >= 0; --i) {
ir::Var loop_var = axis[i];
ir::Expr loop_extent = shape[i];
body = ir::For::Make(loop_var,
Expr(0),
loop_extent,
ir::ForType::Serial,
ir::DeviceAPI::Host,
ir::Block::Make({body}));
}
return body;
}
}

} // namespace ast_gen_ius
} // namespace cinn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 CINN Authors. All Rights Reserved.
// Copyright (c) 2023 CINN Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,22 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* This file implements the strategy to remove the unnecessary nested block.
*/
#pragma once
#include <vector>

#include "paddle/cinn/common/common.h"
#include "paddle/cinn/ir/ir.h"
#include "paddle/cinn/ir/ir_base.h"
#include "paddle/cinn/ir/tensor.h"

namespace cinn {
namespace optim {
namespace ast_gen_ius {

/**
* Remove the unecessary nested block.
*/
void RemoveNestedBlock(Expr* e);
class AstGen {
public:
static ir::Expr Build(const ir::Tensor& tensor, TensorGroup* tensor_group);
};

} // namespace optim
} // namespace ast_gen_ius
} // namespace cinn
46 changes: 46 additions & 0 deletions paddle/cinn/ast_gen_ius/ast_gen_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2023 CINN Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>
#include <vector>

#include "paddle/cinn/ast_gen_ius/ast_gen.h"
#include "paddle/cinn/ast_gen_ius/tensor_group.h"
#include "paddle/cinn/ir/ir.h"
#include "paddle/cinn/ir/ir_base.h"
#include "paddle/cinn/ir/tensor.h"
#include "paddle/cinn/lang/builtin.h"
#include "paddle/cinn/lang/compute.h"
#include "paddle/cinn/lang/placeholder.h"

namespace cinn {
namespace ast_gen_ius {

using cinn::ir::Expr;
using cinn::ir::Tensor;

TEST(AstGen, Build) {
std::vector<Expr> shape = {Expr(10), Expr(10), Expr(10), Expr(10)};
lang::Placeholder<float> A("A", shape);
Tensor B = lang::Compute(
shape,
[&](const std::vector<Expr>& indice) { return lang::Relu(A(indice), 0); },
"relu_test");
TensorGroup tensor_group({B});
Expr out = AstGen::Build(B, &tensor_group);
LOG(INFO) << out;
}

} // namespace ast_gen_ius
} // namespace cinn
Loading

0 comments on commit 43d5e48

Please sign in to comment.