Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into cinn-pass-ir_sim…
Browse files Browse the repository at this point in the history
…plify
  • Loading branch information
Albresky committed Jan 9, 2025
2 parents 0150a6f + 266e3cd commit 16b85ca
Show file tree
Hide file tree
Showing 335 changed files with 4,982 additions and 3,574 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PaddlePaddle uses this [Git branching model](http://nvie.com/posts/a-successful-
pre-commit install
```

Our pre-commit configuration requires clang-format 3.8 for auto-formating C/C++ code and yapf for Python.
Our pre-commit configuration requires clang-format 3.8 for auto-formatting C/C++ code and yapf for Python.

Once installed, `pre-commit` checks the style of code and documentation in every commit. We will see something like the following when you run `git commit`:

Expand All @@ -52,7 +52,7 @@ PaddlePaddle uses this [Git branching model](http://nvie.com/posts/a-successful-
Check for broken symlinks................................................Passed
Detect Private Key...................................(no files to check)Skipped
Fix End of Files.....................................(no files to check)Skipped
clang-formater.......................................(no files to check)Skipped
clang-format.........................................(no files to check)Skipped
[my-cool-stuff c703c041] add test file
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 233
Expand Down
81 changes: 11 additions & 70 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ extend-exclude = [
# Skip `intermidiate` check in these files
"test/cpp/eager/task_tests/CMakeLists.txt",
"test/cpp/eager/task_tests/hook_test_intermidiate.cc",
# Skip `creater` check in these files
"paddle/fluid/inference/tensorrt/convert/CMakeLists.txt",
"paddle/fluid/inference/tensorrt/convert/generic_and_custom_plugin_creater.cc",
"paddle/fluid/inference/tensorrt/convert/test_custom_plugin_creater.cc",
]

[default]
# Ignore 1-3 letter words, refer to https://github.com/crate-ci/typos/issues/1079
extend-ignore-words-re = ["^[a-zA-Z]{1,3}$"]
# refer to https://github.com/crate-ci/typos/blob/master/docs/reference.md#example-configurations
extend-ignore-re = [
# Ignore lines by `# typos: disable-line`
"(?Rm)^.*(#|//)\\s*typos:\\s*disable-line$",
# Ignore block by `# typos: off` and `# typos: on`
"(?s)(#|//)\\s*typos:\\s*off.*?\\n\\s*(#|//)\\s*typos:\\s*on"
]

[default.extend-words]
# PaddlePaddle specific words
Expand All @@ -34,54 +45,11 @@ pash = 'pash'
unpacket = "unpacket"

# These words need to be fixed
Creater = 'Creater'
creater = 'creater'
dito = 'dito'
devide = 'devide'
documention = 'documention'
doens = 'doens'
doen = 'doen'
doubel = 'doubel'
dobule = 'dobule'
Dowloading = 'Dowloading'
downsteram = 'downsteram'
fetchs = 'fetchs'
Flattend = 'Flattend'
flattend = 'flattend'
flattern = 'flattern'
Flattern = 'Flattern'
filpped = 'filpped'
flaot = 'flaot'
follwed = 'follwed'
folowing = 'folowing'
formater = 'formater'
formating = 'formating'
foramt = 'foramt'
formate = 'formate'
formt = 'formt'
forwrad = 'forwrad'
forwad = 'forwad'
forword = 'forword'
founf = 'founf'
framwork = 'framwork'
frequence = 'frequence'
fron = 'fron'
fullfill = 'fullfill'
Indexs = 'Indexs'
indexs = 'indexs'
indiates = 'indiates'
indeces = 'indeces'
inferrence = 'inferrence'
Infered = 'Infered'
infered = 'infered'
infering = 'infering'
informations = 'informations'
imformation = 'imformation'
infomation = 'infomation'
Infor = 'Infor'
infor = 'infor'
inheritted = 'inheritted'
initilization = 'initilization'
initilized = 'initilized'
initalized = 'initalized'
initalize = 'initalize'
Expand Down Expand Up @@ -190,25 +158,6 @@ protocal = 'protocal'
PROTOCAL = 'PROTOCAL'
pyrhon = 'pyrhon'
pthon = 'pthon'
qucik = 'qucik'
quitted = 'quitted'
runned = 'runned'
readed = 'readed'
recived = 'recived'
recevied = 'recevied'
reveived = 'reveived'
recieved = 'recieved'
recieves = 'recieves'
recive = 'recive'
receving = 'receving'
recommand = 'recommand'
recomplie = 'recomplie'
recored = 'recored'
Recusive = 'Recusive'
recusive = 'recusive'
recursivly = 'recursivly'
Recursivly = 'Recursivly'
reduntant = 'reduntant'
Refered = 'Refered'
refered = 'refered'
registed = 'registed'
Expand Down Expand Up @@ -322,14 +271,6 @@ suppport = 'suppport'
SWTICH = 'SWTICH'
Swith = 'Swith'
sysyem = 'sysyem'
targt = 'targt'
Taget = 'Taget'
templat = 'templat'
temporaily = 'temporaily'
temporily = 'temporily'
Temperarily = 'Temperarily'
temporaly = 'temporaly'
Temperary = 'Temperary'
tenosr = 'tenosr'
iterm = 'iterm'
termiante = 'termiante'
Expand Down
2 changes: 1 addition & 1 deletion cmake/external/openvino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/openvino/convert.patch
native_convert)

set(OPENVINO_PATCH_COMMAND
git checkout -- . && git fetch --depth=1 origin <OPENVINO_COMMIT> && git
git checkout -- . && git fetch --depth=1 origin ${OPENVINO_COMMIT} && git
checkout ${OPENVINO_COMMIT} && patch -Np1 -d ${SOURCE_DIR} <
${native_convert} || true)

Expand Down
10 changes: 10 additions & 0 deletions cmake/simd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(AVX512F_FLAG "-mavx512f")
set(Wno_Maybe_Uninitialized "-Wno-maybe-uninitialized")
set(FMA_FLAG "-mfma")
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL 12.0)
set(NO_INLINE "-fno-inline")
else()
set(NO_INLINE "")
endif()
elseif(MSVC)
set(MMX_FLAG "/arch:MMX")
set(SSE2_FLAG "/arch:SSE2")
Expand All @@ -22,6 +27,11 @@ elseif(MSVC)
set(AVX512F_FLAG "/arch:AVX512")
set(Wno_Maybe_Uninitialized "/wd4701")
set(FMA_FLAG "/arch:AVX2")
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL 12.0)
set(NO_INLINE "/Ob0")
else()
set(NO_INLINE "")
endif()
endif()

set(CMAKE_REQUIRED_FLAGS_RETAINED ${CMAKE_REQUIRED_FLAGS})
Expand Down
4 changes: 2 additions & 2 deletions paddle/cinn/backends/codegen_gpu_dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ std::vector<Expr> FilterDeallocTempBuffers(const std::vector<Expr> &frees) {
bool has_symbolic_constant = false;
const ir::_Buffer_ *buffer = op->destination.As<ir::_Buffer_>();
for (Expr shape : buffer->shape) {
shape = common::AutoSimplify(shape);
shape = optim::ArithSimplify(shape);
ir::ir_utils::CollectIRNodes(shape, [&](const Expr *x) {
if (x->as_var()) {
PADDLE_ENFORCE_EQ(
Expand Down Expand Up @@ -539,7 +539,7 @@ ir::Expr CalculateSharedMemory(const ir::LoweredFunc &func) {
shm_size = shm_size + CalculateSharedMemory(buffer);
}
}
return common::AutoSimplify(shm_size);
return optim::ArithSimplify(shm_size);
}

} // namespace backends
Expand Down
1 change: 0 additions & 1 deletion paddle/cinn/backends/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ void Compiler::CompileCudaModule(const Module& module,
device_fn_name_.emplace_back(kernel_fn_name);
}
engine_->Link<CodeGenGpuHost>(host_module);

#else
CINN_NOT_IMPLEMENTED
#endif
Expand Down
6 changes: 2 additions & 4 deletions paddle/cinn/backends/llvm/codegen_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ llvm::Value *CodeGenLLVM::Visit(const ir::Store *op) {
// fit the total_lanes in native_lanes(split into multiple native steps)
for (int offset = 0; offset < total_lanes; offset += total_lanes) {
int lanes = total_lanes;
Expr base = cinn::common::AutoSimplify(ramp->base + offset);
Expr base = optim::ArithSimplify(ramp->base + offset);
optim::VarModSimplify(&base);
auto *ptr =
CreateBufferPtr(op->type().ElementOf(), buffer, Visit(&base));
Expand Down Expand Up @@ -1242,10 +1242,8 @@ llvm::Value *CodeGenLLVM::DenseVectorLoad(const ir::Load *op) {

for (int i = 0; i < load_lanes; i += load_lanes) {
int slice_lanes = load_lanes;
auto slice_base = cinn::common::AutoSimplify(ramp->base + i);
auto slice_base = optim::ArithSimplify(ramp->base + i);
optim::VarModSimplify(&slice_base);
auto slide_stride = Expr(1);
auto slide_index = slice_base;

#if LLVM_VERSION_MAJOR >= 11
const llvm::ElementCount elem_count(slice_lanes, /*scalable*/ false);
Expand Down
14 changes: 13 additions & 1 deletion paddle/cinn/backends/llvm/execution_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ std::unique_ptr<llvm::MemoryBuffer> NaiveObjectCache::getObject(

template <typename CodeGenT>
void ExecutionEngine::Link(const ir::Module &module) {
if (module.functions().size() == 0) {
return;
}
utils::RecordEvent("ExecutionEngine Link", utils::EventType::kOrdinary);

auto ir_emitter = std::make_unique<CodeGenT>(m.get(), b.get());
VLOG(3) << "ir_emitter->Compile(module) Begin";
ir_emitter->Compile(module);
Expand Down Expand Up @@ -211,6 +213,16 @@ void ExecutionEngine::Link(const ir::Module &module) {
}
}

template <>
void ExecutionEngine::Link<CodeGenGpuHost>(const ir::Module &module) {
if (module.functions().size() == 0) {
return;
}
utils::RecordEvent("ExecutionEngine Link", utils::EventType::kOrdinary);
auto ir_emitter = std::make_unique<CodeGenGpuHost>(m.get(), b.get());
ir_emitter->Compile(module);
}

bool ExecutionEngine::AddModule(std::unique_ptr<llvm::Module> module,
std::unique_ptr<llvm::LLVMContext> context) {
utils::RecordEvent("ExecutionEngine AddModule", utils::EventType::kOrdinary);
Expand Down
7 changes: 3 additions & 4 deletions paddle/cinn/common/ir_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ Expr RampRelatedAdd(ir::Ramp *ramp, ir::Ramp *other) {
::common::errors::InvalidArgument(
"Other ramp pointer should not be null."));
if (ramp->lanes == other->lanes) {
Expr base_add = cinn::common::AutoSimplify(ramp->base + other->base);
Expr stride_add = cinn::common::AutoSimplify(ramp->stride + other->stride);
Expr base_add = optim::ArithSimplify(ramp->base + other->base);
Expr stride_add = optim::ArithSimplify(ramp->stride + other->stride);
VLOG(2) << base_add;
VLOG(2) << stride_add;
return ir::Ramp::Make(base_add, stride_add, ramp->lanes);
Expand Down Expand Up @@ -641,8 +641,7 @@ ir::IndexExpr SimplifySymbolicDivide(const ir::IndexExpr &lhs,

bool ProveDivisible(const ir::IndexExpr &lhs, const ir::IndexExpr &rhs) {
if (IsZero(lhs % rhs)) return true;
// remove AutoSimplify later.
if (IsZero(AutoSimplify(lhs % rhs))) return true;
if (IsZero(optim::ArithSimplify(lhs % rhs))) return true;
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion paddle/cinn/common/ir_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ inline void UnpackReduction(const ir::IndexExpr &expr, FLeaf fleaf) {
}

/*!
* \brief Flattern the expression into a vector of expressions splited by `Add`
* \brief Flatten the expression into a vector of expressions splited by `Add`
* or `Mul`.
*
* For example (Add):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ bool MakeGenerateShapeOpAttribute(
}
}
if (!has_symbol_binding) {
LOG(WARNING) << "no symbol binding found for dim expr: " << symbol_name;
VLOG(2) << "no symbol binding found for dim expr: " << symbol_name;
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion paddle/cinn/hlir/dialect/operator/ir/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
output : Tensor(out)
infer_meta :
func : ReduceSumInferMeta
param : [x, axis, keepdim]
param : [x, axis, keepdim, dtype]
kernel :
func : frobenius_norm
param : [x, axis, keepdim]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ std::ostream& operator<<(std::ostream& stream,
}

DimExprs4ValueT MakeDimExprs4Value(
pir::Program* program, const PassManagerCreater& CreatePassManager) {
pir::Program* program, const PassManagerCreator& CreatePassManager) {
std::shared_ptr<pir::PassManager> pass_manager = CreatePassManager();
pass_manager->AddPass(pir::CreateShapeOptimizationPass());
pass_manager->Run(program);
Expand Down Expand Up @@ -404,13 +404,13 @@ struct ShapeSignatureGenerator {
const DoEachT& DoEach) {
if (set_size <= 0) return DoEach(is_subset_flags);

const auto& RecusiveVisit = [&](bool is_subset) {
const auto& RecursiveVisit = [&](bool is_subset) {
std::vector<IsSubset> current_is_subset_flags(is_subset_flags);
current_is_subset_flags.push_back(static_cast<int>(is_subset));
VisitEachSubSet(set_size - 1, current_is_subset_flags, DoEach);
};
RecusiveVisit(true);
RecusiveVisit(false);
RecursiveVisit(true);
RecursiveVisit(false);
}

std::optional<ConstrainedSymbolNamesList> GetConstrainedSymbolNamesList(
Expand Down Expand Up @@ -623,7 +623,7 @@ void CheckProgramDimExprConstraints(
} // namespace

void CheckInferSymbolicIfNeed(pir::Program* program,
const PassManagerCreater& CreatePassManager) {
const PassManagerCreator& CreatePassManager) {
if (!FLAGS_prim_all || !FLAGS_check_infer_symbolic) return;
const auto& GraphDimExprs4Value =
MakeDimExprs4Value(program, CreatePassManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace cinn {
namespace dialect {
namespace ir {

using PassManagerCreater = std::function<std::shared_ptr<pir::PassManager>()>;
using PassManagerCreator = std::function<std::shared_ptr<pir::PassManager>()>;

void CheckInferSymbolicIfNeed(pir::Program* program,
const PassManagerCreater& CreatePassManager);
const PassManagerCreator& CreatePassManager);

} // namespace ir
} // namespace dialect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ std::vector<pir::Value> FindSourceDenseTensorOfDimTensor(
[](const symbol::NullShapeOrDataDimExpr& null_shape_or_data) {
return false;
}};
// For TensorListShapeOrDataDimExprs case, we should recursivly visit its
// For TensorListShapeOrDataDimExprs case, we should recursively visit its
// each dim_expr, which is automatically in next step.
const auto& NeedTrackUpstream = [&](pir::Value value) -> bool {
const auto& sym_shape = ShapeOrDataDimExprs4Value(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ OpLoweringGroupPtr BuildOpLoweringGroup(pir::Operation* fusion_op_ptr) {
if (FLAGS_cinn_enable_map_expr) {
cinn::adt::TryGenerateMapExprFromGroup(group);
}
// Rebuild other informations
// Rebuild other information
// TODO(zhangyuqin1998): Do we need group.master_ops?
return group;
}
Expand Down
Loading

0 comments on commit 16b85ca

Please sign in to comment.