Skip to content

Commit

Permalink
Merge branch 'PaddlePaddle:develop' into C18
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyulingyue authored Mar 1, 2024
2 parents 5ffa617 + e5404f0 commit f6b4427
Show file tree
Hide file tree
Showing 483 changed files with 5,936 additions and 3,301 deletions.
2 changes: 1 addition & 1 deletion cmake/cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ select_nvcc_arch_flags(NVCC_FLAGS_EXTRA NVCC_ARCH_BIN)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${NVCC_FLAGS_EXTRA}")
message(STATUS "NVCC_FLAGS_EXTRA: ${NVCC_FLAGS_EXTRA}")

# Set C++14 support
# Set C++17 support
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
# Release/Debug flags set by cmake. Such as -O3 -g -DNDEBUG etc.
# So, don't set these flags here.
Expand Down
46 changes: 35 additions & 11 deletions cmake/phi_header.cmake → cmake/export_paddle_header.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,57 @@
set(PADDLE_INFERENCE_INSTALL_DIR
"${CMAKE_BINARY_DIR}/paddle_inference_install_dir")

function(phi_header_path_compat TARGET_PATH)
message(STATUS "phi header path compat processing: ${TARGET_PATH}")
function(header_path_compat TARGET_PATH)
message(STATUS "header path compat processing: ${TARGET_PATH}")
file(GLOB HEADERS "${TARGET_PATH}/*" "*.h")
foreach(header ${HEADERS})
if(${header} MATCHES ".*.h$")
file(READ ${header} HEADER_CONTENT)
string(REPLACE "paddle/fluid/platform/" "paddle/phi/" HEADER_CONTENT
"${HEADER_CONTENT}")
string(REPLACE "paddle/pir/include/" "paddle/pir/" HEADER_CONTENT
"${HEADER_CONTENT}")
string(REPLACE "paddle/fluid/pir/drr/include/" "paddle/pir/drr/"
HEADER_CONTENT "${HEADER_CONTENT}")
string(REPLACE "paddle/fluid/pir/transforms/" "paddle/pir/transforms/"
HEADER_CONTENT "${HEADER_CONTENT}")
file(WRITE ${header} "${HEADER_CONTENT}")
message(STATUS "phi header path compat processing complete: ${header}")
message(STATUS "header path compat processing complete: ${header}")
endif()
endforeach()
endfunction()

phi_header_path_compat(${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle)
phi_header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/phi)
phi_header_path_compat(
header_path_compat(${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle)
header_path_compat(${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/phi)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/phi/api)
phi_header_path_compat(
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/phi/api/ext)
phi_header_path_compat(
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/phi/api/include)
phi_header_path_compat(
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/phi/common)
phi_header_path_compat(
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/phi/core)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/core)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/core/parser)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/dialect/control_flow/ir
)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/dialect/shape/ir)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/dialect/shape/utils)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/drr)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/pass)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/pattern_rewrite)
header_path_compat(
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/transforms)

# NOTE(liuyuanle): In inference lib, no need include paddle/utils/pybind.h, so we delete this.
file(READ ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/extension.h
Expand Down
48 changes: 45 additions & 3 deletions cmake/inference_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,54 @@ copy(
SRCS ${PADDLE_SOURCE_DIR}/paddle/extension.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/)

# the include path of phi needs to be changed to adapt to inference api path
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/pir/include/core/parser/*.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/core/parser/)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/pir/include/core/*.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/core/)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/pir/include/dialect/control_flow/ir/*.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/dialect/control_flow/ir/
)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/pir/include/dialect/shape/ir/*.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/dialect/shape/ir/
)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/pir/include/dialect/shape/utils/*.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/dialect/shape/utils/
)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/pir/include/pass/*.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/pass/)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/pir/include/pattern_rewrite/*.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/pattern_rewrite/
)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/drr/include/*.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/drr/)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/transforms/transform_general_functions.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/pir/transforms/)

# the include path of paddle needs to be changed to adapt to inference api path
add_custom_command(
TARGET inference_lib_dist
POST_BUILD
COMMAND ${CMAKE_COMMAND} -P "${PADDLE_SOURCE_DIR}/cmake/phi_header.cmake"
COMMENT "Change phi header include path to adapt to inference api path")
COMMAND ${CMAKE_COMMAND} -P
"${PADDLE_SOURCE_DIR}/cmake/export_paddle_header.cmake"
COMMENT "Change paddle header include path to adapt to inference api path")

# CAPI inference library for only inference
set(PADDLE_INFERENCE_C_INSTALL_DIR
Expand Down
6 changes: 3 additions & 3 deletions paddle/cinn/backends/codegen_c_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ TEST(CodeGenC, module) {
LOG(INFO) << "C.body: " << C->get_compute_op()->body.front();

Target target;
target.arch = Target::Arch ::X86;
target.bits = Target::Bit ::k32;
target.os = Target::OS ::Linux;
target.arch = Target::Arch::X86;
target.bits = Target::Bit::k32;
target.os = Target::OS::Linux;
Module::Builder builder("module1", target);

ast_gen_ius::TensorGroup tensor_group({A, B, C});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ void ApplyCinnPreprocessPass(

pass_manager->AddPass(
cinn::dialect::ir::CreateMoveGenerateShapeOpsToProloguePass());
pass_manager->AddPass(cinn::dialect::ir::CreateDivideGroupOpToFusionOpPass());
pass_manager->AddPass(cinn::dialect::ir::CreateDynamicReshapeOpPass());
pass_manager->AddPass(cinn::dialect::ir::CreateReplaceDynamicExpandOpPass());
pass_manager->AddPass(cinn::dialect::ir::CreateDivideGroupOpToFusionOpPass());
pass_manager->AddPass(pir::CreateDeadCodeEliminationPass());

pass_manager->Run(program);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class DynamicReshapeOpPass : public pir::Pass {
for (uint32_t i = 0; i < op->num_regions(); ++i) {
for (auto& block : op->region(i)) {
for (auto& op : block) {
if (op.isa<cinn::dialect::FusionOp>()) {
if (op.isa<cinn::dialect::GroupOp>()) {
auto [_, num_rewrites] =
pir::ApplyPatternsGreedily(&op, patterns_, cfg);
AddStatistics(num_rewrites);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,28 @@ class DynamicExpandOpPattern
for (size_t i = 0; i < x_rank; ++i) {
broadcast_axes[i] = i + index_gap;
}
std::vector<int64_t> out_shape(out_rank, -1);

pir::ShapeConstraintIRAnalysis& shape_analysis =
pir::ShapeAnalysisManager::Instance().Get(op->GetParentProgram());

const auto& UpdateOutputShapeByDimExpr = [&]() -> std::vector<int64_t> {
std::vector<int64_t> out_shape(out_rank, -1);
if (shape_analysis.HasShapeOrDataForValue(op->result(0))) {
VLOG(3) << "found shape dialect";
auto shape_info =
shape_analysis.GetShapeOrDataForValue(op->result(0)).shape();

for (size_t i = 0; i < shape_info.size(); ++i) {
if (shape_info[i].isa<int64_t>()) {
out_shape[i] = shape_info[i].Get<int64_t>();
}
}
}
return out_shape;
};

auto out_shape = UpdateOutputShapeByDimExpr();

return rewriter.Build<cinn::dialect::BroadcastOp>(
op->operand_source(0), broadcast_axes, out_shape);
}();
Expand Down Expand Up @@ -91,7 +112,7 @@ class ReplaceDynamicExpandOpPass : public pir::Pass {
for (uint32_t i = 0; i < op->num_regions(); ++i) {
for (auto& block : op->region(i)) {
for (auto& op : block) {
if (op.isa<cinn::dialect::FusionOp>()) {
if (op.isa<cinn::dialect::GroupOp>()) {
const auto& [_, num_rewrites] =
pir::ApplyPatternsGreedily(&op, patterns_, cfg);
AddStatistics(num_rewrites);
Expand Down
3 changes: 3 additions & 0 deletions paddle/cinn/hlir/framework/pir/op_mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
// limitations under the License.

#pragma once

#include <glog/logging.h>
#include <string>
#include <unordered_map>
#include <vector>

#include "paddle/cinn/utils/type_defs.h"
#include "paddle/pir/include/core/operation.h"

Expand Down
2 changes: 1 addition & 1 deletion paddle/cinn/ir/schedule/impl/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ Expr DyScheduleImpl::SampleCategorical(
std::string primitive = "SampleCategorical";
std::ostringstream os;
if (candidates.size() != probs.size()) {
os << "vector<int> params(candidates) and vector<int> prama(probs) must "
os << "vector<int> params(candidates) and vector<int> params(probs) must "
"have same size in SampleCategorical!\n";
throw IRScheduleErrorHandler(primitive, os.str(), module_expr_);
}
Expand Down
4 changes: 2 additions & 2 deletions paddle/cinn/ir/schedule/impl/compute_location.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ void DyScheduleImpl::ComputeAt(const Expr& block,
std::string primitive = "ComputeAt";
std::ostringstream os;
if (!block.As<ir::ScheduleBlockRealize>()) {
os << "Expr prama(block) should be a ScheduleBlockRealize!\n";
os << "Expr param(block) should be a ScheduleBlockRealize!\n";
throw IRScheduleErrorHandler(primitive, os.str(), module_expr_);
}
if (!loop.As<ir::For>()) {
os << "Expr prama(loop) should be a For node!\n";
os << "Expr param(loop) should be a For node!\n";
throw IRScheduleErrorHandler(primitive, os.str(), module_expr_);
}
Expr root = this->GetRootBlock(block);
Expand Down
2 changes: 1 addition & 1 deletion paddle/cinn/ir/schedule/ir_schedule_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace ir {

std::string IRScheduleErrorHandler::GeneralErrorMessage() const {
std::ostringstream os;
os << "[IRScheduleError] An error occurred in the scheduel primitive < "
os << "[IRScheduleError] An error occurred in the schedule primitive < "
<< this->primitive_ << " >. " << std::endl;
os << indent_str_ << "[Error info] " << this->err_msg_;
return os.str();
Expand Down
8 changes: 4 additions & 4 deletions paddle/cinn/ir/schedule/ir_schedule_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void ReplaceExpr(Expr* source,
const std::vector<Expr>& candidates) {
CHECK_EQ(replaced.size(), candidates.size())
<< "In ReplaceExpr, the size of Vars to be replaced must be equal to the "
"size of cadidate Exprs! Please check.";
"size of candidate Exprs! Please check.";
if (replaced.empty()) return;
std::map<Var, Expr, CompVar> replacing_map;
for (int i = 0; i < replaced.size(); ++i) {
Expand Down Expand Up @@ -764,7 +764,7 @@ Expr ConstructNewLoopChain(const std::vector<Expr>& chain,
// } }
// } }
//
// We go throuph origin loop and check other body stmts, adding it as another
// We go through origin loop and check other body stmts, adding it as another
// chain, such as:
//
// for (i, 0, 32) {
Expand Down Expand Up @@ -1022,7 +1022,7 @@ void InsertBlock(Expr& for_loop, const Expr& insertion, int index) { // NOLINT
auto dst_it = dst_block->stmts.begin() + index;
if (dst_it->As<IfThenElse>()) {
auto* inserted_block = dst_it->As<IfThenElse>()->true_case.As<Block>();
CHECK(inserted_block) << "the IfThenElse node to be inserted shuold "
CHECK(inserted_block) << "the IfThenElse node to be inserted should "
"contain a true_case block";
inserted_block->stmts.insert(inserted_block->stmts.begin(), insertion);
} else {
Expand Down Expand Up @@ -1060,7 +1060,7 @@ std::vector<IterRange> CalculateRequiredRegions(
}

std::vector<IterRange> required_buffer_range;
// deduce accessed regions of the provided tensor in block by itering each
// deduce accessed regions of the provided tensor in block by iterating each
// required block
for (const Expr& pro_node : provided_nodes) {
std::string provided_tensor_name =
Expand Down
12 changes: 6 additions & 6 deletions paddle/cinn/ir/schedule/schedule_desc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace cinn {
namespace ir {

// ------ Following codes are about `Apply` functions registry of variaous types
// ------ Following codes are about `Apply` functions registry of various types
// of ScheduleDesc::Step
class PackedStepContext;
// uniformed function prototype of a scheduling operation in IRSchedule
Expand Down Expand Up @@ -118,7 +118,7 @@ class PackedStepContext {
return absl::get<AttrType>(attrs_.at(idx));
} catch (absl::bad_variant_access& ex) {
LOG(FATAL) << "Attribute cast error, idx:" << idx
<< ", get tpye:" << typeid(AttrType).name()
<< ", get type:" << typeid(AttrType).name()
<< ", real index:" << attrs_.at(idx).index();
throw ex;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ struct FreeFuncConverter<Return (IRSchedule::*)(Args...) const, impl_fn> {
}
};

// used for formatting scheduling functions with variaous function signatures to
// used for formatting scheduling functions with various function signatures to
// be uniformed form
template <typename F, F f>
struct ApplyFuncImpl;
Expand Down Expand Up @@ -689,8 +689,8 @@ proto::ScheduleDesc ScheduleDesc::ToProto() const {
}
}

// each output Expr is represented by a formatted name, to be refered by
// suceeding steps
// each output Expr is represented by a formatted name, to be referred by
// succeeding steps
for (auto&& expr : step.outputs) {
std::string local_name = "e" + std::to_string(expr2name.size());
expr2name.emplace(expr, local_name);
Expand Down Expand Up @@ -722,7 +722,7 @@ std::vector<Expr> ScheduleDesc::ReplayWithProto(
absl::flat_hash_map<std::string, Expr> name2expr;
std::vector<Expr> last_outputs;

// resotre each scheduling step and apply to the new IRSchedule object
// restore each scheduling step and apply to the new IRSchedule object
for (auto&& step_proto : desc_proto.steps()) {
VLOG(4) << "Replay step:\n" << step_proto.DebugString();
ScheduleDesc::Step step;
Expand Down
2 changes: 1 addition & 1 deletion paddle/cinn/ir/test/tensor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ TEST(Tensor, ReshapeCopied) {

stages->InsertLazily(B);

ir::Module::Builder builder("some_modue", cinn::common::DefaultHostTarget());
ir::Module::Builder builder("some_module", cinn::common::DefaultHostTarget());
auto func = lang::Lower("fn", stages, {A, B}, {}, {}, &builder);

backends::CodeGenC codegenc(cinn::common::DefaultHostTarget());
Expand Down
6 changes: 3 additions & 3 deletions paddle/cinn/lang/lower_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class LowerImpl {
std::vector<Tensor> CollectTemporaryTensors();

/**
* \brief Check both the tensor_args and sclar_args not contain duplication
* (different arguemnt with the same name).
* \brief Check both the tensor_args and scalar_args not contain duplication
* (different argument with the same name).
*/
void CheckArgsUnique();

Expand Down Expand Up @@ -304,7 +304,7 @@ struct MarkParallelMutator : public ir::IRMutator<Expr*> {
auto it = parallels.find(tensor_n->name);
if (it != parallels.end()) {
for (int level : it->second) {
VLOG(1) << "Mark " << level << " Paralled";
VLOG(1) << "Mark " << level << " Parallelled";
CHECK_LT(level, stack.size());
stack[level]->set_parallel();
}
Expand Down
2 changes: 1 addition & 1 deletion paddle/cinn/optim/insert_debug_log_callee.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct InsertDebugLogCalleeMutator : public ir::IRMutator<> {
ir::IRMutator<>::Visit(&node->body, &node->body);

auto deal_with_exprs =
[&](std::vector<Expr> *exprs) { // deal with op->argument_preapre_exprs
[&](std::vector<Expr> *exprs) { // deal with op->argument_prepare_exprs
std::vector<Expr> new_stmts;
for (auto &expr : *exprs) {
auto msg =
Expand Down
2 changes: 1 addition & 1 deletion paddle/cinn/optim/unroll_loops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct UnrollMutator : public ir::IRMutator<Expr*> {
void Visit(const ir::For* op, Expr* expr) override {
IRMutator<>::Visit(op, expr);
if (op->extent.As<ir::IntImm>() == nullptr) {
VLOG(5) << "loop to be unrolled should have a contant extent";
VLOG(5) << "loop to be unrolled should have a constant extent";
return;
}
int64_t extent = op->extent.as_int64();
Expand Down
Loading

0 comments on commit f6b4427

Please sign in to comment.