Skip to content

Commit

Permalink
Merge branch 'PaddlePaddle:develop' into divide
Browse files Browse the repository at this point in the history
  • Loading branch information
Asthestarsfalll authored Oct 8, 2024
2 parents cdde50f + 8db2e3d commit 7f8d0f2
Show file tree
Hide file tree
Showing 1,041 changed files with 18,004 additions and 13,528 deletions.
16 changes: 8 additions & 8 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ paddle/fluid/framework/tensor.h @XiaoguangHu01 @zhiqiu @Xreki @Aurelius84
paddle/fluid/framework/unused_var_check.cc @zhiqiu @phlrain
paddle/fluid/framework/var_desc.h @XiaoguangHu01 @zhiqiu @Xreki @Aurelius84
paddle/fluid/operators/distributed/send_recv.proto.in @gongweibao @seiriosPlus
paddle/fluid/prim/api/api.yaml @cxxly @xiaoguoguo626807 @Charles-hit @cyber-pioneer @JiabinYang
paddle/fluid/prim/api/composite_backward/composite_backward_api.h @cxxly @xiaoguoguo626807 @Charles-hit @cyber-pioneer @JiabinYang
paddle/fluid/prim/api/composite_backward/composite_double_backward_api.h @cxxly @xiaoguoguo626807 @Charles-hit @cyber-pioneer @JiabinYang
paddle/fluid/prim/api/manual_prim/prim_manual_api.h @cxxly @xiaoguoguo626807 @Charles-hit @cyber-pioneer @JiabinYang
paddle/fluid/prim/api/api.yaml @xiaoguoguo626807 @JiabinYang @phlrain
paddle/fluid/prim/api/composite_backward/composite_backward_api.h @xiaoguoguo626807 @JiabinYang
paddle/fluid/prim/api/composite_backward/composite_double_backward_api.h @xiaoguoguo626807 @JiabinYang
paddle/fluid/prim/api/manual_prim/prim_manual_api.h @xiaoguoguo626807 @JiabinYang
paddle/phi/api/include/tensor.h @phlrain @zyfncg @YuanRisheng
paddle/phi/core/attribute.h @phlrain @zyfncg @YuanRisheng
paddle/phi/core/dense_tensor.h @phlrain @zyfncg @YuanRisheng
Expand All @@ -47,8 +47,8 @@ paddle/phi/infermeta/spmd_rules @LiYuRio @ForFishes @zhiqiu
paddle/scripts/paddle_build.bat @zhwesky2010 @wanghuancoder @Aurelius84
paddle/scripts/paddle_build.sh @risemeup1 @zhangbo9674 @XieYunshen
pyproject.toml @SigureMo @gouzil
python/paddle/autograd/backward_utils.py @Aurelius84 @cxxly @xiaoguoguo626807 @changeyoung98 @cyber-pioneer
python/paddle/autograd/ir_backward.py @Aurelius84 @cxxly @xiaoguoguo626807 @changeyoung98
python/paddle/autograd/backward_utils.py @Aurelius84 @xiaoguoguo626807 @changeyoung98 @phlrain
python/paddle/autograd/ir_backward.py @Aurelius84 @xiaoguoguo626807 @changeyoung98
python/paddle/base/backward.py @XiaoguangHu01 @zhiqiu @Xreki @qili93 @Aurelius84
python/paddle/base/compiler.py @XiaoguangHu01 @zhiqiu @Xreki @qili93 @Aurelius84
python/paddle/base/dygraph/layers.py @JiabinYang @phlrain
Expand All @@ -65,8 +65,8 @@ python/paddle/base/tests/unittests/white_list/op_threshold_white_list.py @juncai
python/paddle/distributed/fleet/__init__.py @sneaxiy @raindrops2sea
python/paddle/distributed/fleet/launch.py @sneaxiy @raindrops2sea
python/paddle/distributed/__init__.py @sneaxiy @raindrops2sea
python/paddle/incubate/autograd/composite_rules.py @cyber-pioneer @xiaoguoguo626807 @Charles-hit @JiabinYang
python/paddle/incubate/autograd/primitives.py @cyber-pioneer @xiaoguoguo626807 @Charles-hit @JiabinYang
python/paddle/incubate/autograd/composite_rules.py @xiaoguoguo626807 @JiabinYang
python/paddle/incubate/autograd/primitives.py @xiaoguoguo626807 @JiabinYang @phlrain
python/paddle/_typing @SigureMo @zrr1999 @gouzil
python/requirements.txt @phlrain @jzhang533 @kolinwei
test/dygraph_to_static @SigureMo @Aurelius84 @gouzil
Expand Down
2 changes: 1 addition & 1 deletion cmake/external/dlpack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
include(ExternalProject)

set(DLPACK_PREFIX_DIR ${THIRD_PARTY_PATH}/dlpack)
set(DLPACK_TAG v0.4)
set(DLPACK_TAG v0.8)
set(DLPACK_INCLUDE_DIR ${THIRD_PARTY_PATH}/dlpack/src/extern_dlpack/include)
set(SOURCE_DIR ${PADDLE_SOURCE_DIR}/third_party/dlpack)
include_directories(${SOURCE_DIR}/include)
Expand Down
4 changes: 2 additions & 2 deletions cmake/external/xpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ if(NOT DEFINED XPU_XRE_BASE_VERSION)
set(XPU_XRE_BASE_VERSION "4.32.0.1")
endif()
if(NOT DEFINED XPU_XHPC_BASE_DATE)
set(XPU_XHPC_BASE_DATE "eb35/20240906")
set(XPU_XHPC_BASE_DATE "eb35/20240927")
endif()
set(XPU_XCCL_BASE_VERSION "1.2.11c")
set(XPU_XCCL_BASE_VERSION "1.2.11e")
if(NOT DEFINED XPU_XFT_BASE_VERSION)
set(XPU_XFT_BASE_VERSION "20230602")
endif()
Expand Down
51 changes: 46 additions & 5 deletions paddle/cinn/adt/equation_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <typeinfo>
#include <unordered_map>
#include <variant>

Expand All @@ -33,15 +34,23 @@ std::unordered_map<Variable, Value> InferValuesImpl(
IndexExprInferContext* ctx) {
const auto& [out_iter, in_iter] = id.tuple();
Variable in_variable{in_iter.value()};
CHECK(ctx->HasValue(in_variable));
PADDLE_ENFORCE_EQ(
ctx->HasValue(in_variable),
true,
::common::errors::NotFound("The param id's out_iter must contain "
"its in_iter's value"));
return {{out_iter.value(), ctx->GetValue(in_variable)}};
}

std::unordered_map<Variable, Value> InferValuesImpl(
const Identity<tOut<Index>, tIn<Index>>& id, IndexExprInferContext* ctx) {
const auto& [out_index, in_index] = id.tuple();
Variable in_variable{in_index.value()};
CHECK(ctx->HasValue(in_variable));
PADDLE_ENFORCE_EQ(
ctx->HasValue(in_variable),
true,
::common::errors::NotFound("The param id's out_iter must contain "
"its in_iter's value"));
return {{out_index.value(), ctx->GetValue(in_variable)}};
}

Expand Down Expand Up @@ -203,13 +212,30 @@ std::unordered_map<Variable, Value> InferValuesImpl(
in_msg_out_indexes.value()->size()));
for (std::size_t i = 0; i < out_msg_in_indexes.value()->size(); ++i) {
const auto& value = ctx->GetValue(in_msg_in_indexes.value()->at(i));
CHECK(ret.emplace(out_msg_in_indexes.value()->at(i), value).second);
PADDLE_ENFORCE_EQ(
ret.emplace(out_msg_in_indexes.value()->at(i), value).second,
true,
::common::errors::AlreadyExists([&]() {
std::ostringstream oss;
oss << "Failed to insert the variable '"
<< "out_msg_in_indexes.value()->at(" << i
<< ")' into the map: key already exists.";
return oss.str();
}()));
}
for (std::size_t i = 0; i < out_msg_out_indexes.value()->size(); ++i) {
const auto& value = ctx->GetValue(in_msg_out_indexes.value()->at(i));
const auto& out_index = out_msg_out_indexes.value()->at(i);
if (out_index.has_value()) {
CHECK(ret.emplace(out_index.value(), value).second);
PADDLE_ENFORCE_EQ(ret.emplace(out_index.value(), value).second,
true,
::common::errors::AlreadyExists([&]() {
std::ostringstream oss;
oss << "Failed to insert the variable '"
<< "out_index.value()"
<< "' into the map: key already exists.";
return oss.str();
}()));
}
}
return ret;
Expand Down Expand Up @@ -265,6 +291,12 @@ tValueInferSuccess<bool> MergeInferedValuesIntoCtx(const Function* function,
});
}

std::string GetFunctionName(const Function* function) {
return std::visit(
[](auto&& arg) -> std::string { return typeid(arg).name(); },
function->variant());
}

void SolveEquations(
const EquationGraphTopoWalker<Variable, const Function*>& walker,
const std::vector<Variable>& starts,
Expand All @@ -273,7 +305,16 @@ void SolveEquations(
starts.begin(), starts.end(), [&](const Function* function) {
tValueInferSuccess<bool> has_unique_value =
MergeInferedValuesIntoCtx(function, ctx);
CHECK(has_unique_value.value());
PADDLE_ENFORCE_EQ(
has_unique_value.value(),
true,
::common::errors::InvalidArgument([&]() {
std::ostringstream oss;
oss << "Failed to merge inferred values into the context for "
"function '"
<< GetFunctionName(function) << "'.";
return oss.str();
}()));
});
}

Expand Down
32 changes: 0 additions & 32 deletions paddle/cinn/backends/codegen_invoke_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,6 @@ llvm::Value* CodeGenInvokeModule::LowerInvokeFunc(
return f_;
}

llvm::Value* CodeGenInvokeModule::LowerParseArgsValueCall(
const ir::Call* call_ir) {
auto ret_type = CinnTypeToLLVMType(Int(64), m_);
std::vector<llvm::Type*> args_type;
PADDLE_ENFORCE_EQ(
call_ir->read_args.size(),
2,
::common::errors::InvalidArgument(
"The number of arguments of ParseArgsValue should be 2"));
PADDLE_ENFORCE_EQ(call_ir->read_args[0].is_var() &&
call_ir->read_args[0].as_var()->type().is_cpp_handle(),
true,
::common::errors::InvalidArgument(
"The first read argument must be a variable "
"with a C++ handle type."));

PADDLE_ENFORCE_EQ(call_ir->read_args[1].type().is_int(32),
true,
::common::errors::InvalidArgument(
"The second read argument must be of type int32."));
args_type.push_back(CinnTypeToLLVMType(type_of<void*>(), m_));
args_type.push_back(CinnTypeToLLVMType(type_of<int32_t>(), m_));

auto func_type = llvm::FunctionType::get(ret_type, args_type, false);
auto call_func = m_->getOrInsertFunction(call_ir->name, func_type);

std::vector<llvm::Value*> call_args;
call_args.push_back(std::addressof(*f_->arg_begin()));
call_args.push_back(b_->getInt32(call_ir->read_args[1].as_int32()));
return b_->CreateCall(call_func, call_args);
}

llvm::Value* CodeGenSwitchHost::LowerInnerCaseCall(const ir::Call* op) {
std::vector<llvm::Value*> ll_function_args;
std::transform(f_->arg_begin(),
Expand Down
13 changes: 1 addition & 12 deletions paddle/cinn/backends/codegen_invoke_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,8 @@ class CodeGenInvokeModule : public CodeGenLLVM {
return LowerInvokeFunc(func);
}

llvm::Value *Visit(const ir::Call *op) override {
// TODO(Hongqing-work): change intrinsic name to get_value_in_kernel_args
if (op->name == runtime::intrinsic::get_value_in_cuda_kernel_args) {
return LowerParseArgsValueCall(op);
} else {
return CodeGenLLVM::Visit(op);
}
}

protected:
llvm::Value *LowerInvokeFunc(const ir::_LoweredFunc_ *func);

llvm::Value *LowerParseArgsValueCall(const ir::Call *call_ir);
};

class CodeGenHost : public CodeGenInvokeModule {
Expand All @@ -80,7 +69,7 @@ class CodeGenSwitchHost : public CodeGenInvokeModule {
// only support call of args get function and inner case host function call
llvm::Value *Visit(const ir::Call *op) override {
if (op->name == runtime::intrinsic::get_value_in_cuda_kernel_args) {
return CodeGenInvokeModule::LowerParseArgsValueCall(op);
return CodeGenLLVM::Visit(op);
} else {
return LowerInnerCaseCall(op);
}
Expand Down
76 changes: 6 additions & 70 deletions paddle/cinn/backends/llvm/codegen_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,53 +511,6 @@ llvm::Value *CodeGenLLVM::Visit(const ir::Cast *op) {
llvm::Value *CodeGenLLVM::CreateSerialFor(const ir::For *op, int stride) {
SymbolTableGuard symbol_table_guard(*symbol_table_);

do {
break;
llvm::BasicBlock *preheader_bb = b_->GetInsertBlock();
auto *for_begin = llvm::BasicBlock::Create(
b_->getContext(), "for_begin", b_->GetInsertBlock()->getParent());
auto *for_body = llvm::BasicBlock::Create(
b_->getContext(), "for_body", b_->GetInsertBlock()->getParent());
auto *for_end = llvm::BasicBlock::Create(
b_->getContext(), "for_end", b_->GetInsertBlock()->getParent());

Br(for_begin);
b_->SetInsertPoint(for_begin);

auto *begin = Visit(&op->min);
auto *loop_value = PHI(begin->getType(), 2);
loop_value->addIncoming(begin, preheader_bb);

llvm::Value *old_var = GetVar(op->loop_var->name);
SetVar(op->loop_var->name, loop_value);
auto *end = Visit(&op->extent);
CondBr(ICmpSLT(loop_value, end), for_body, for_end);
b_->SetInsertPoint(for_body);
Visit(&op->body);

if (old_var) {
SetVar(op->loop_var->name, old_var);
} else {
symbol_table_->Erase(op->loop_var->name);
}

auto loop_next = Add(loop_value,
llvm::ConstantInt::get(b_->getInt32Ty(), stride),
"indvar.inc",
true,
true);
loop_value->addIncoming(loop_next, b_->GetInsertBlock());

Br(for_begin);
b_->SetInsertPoint(for_end);

return nullptr;
// llvm::AllocaInst *loop_var = Alloca(b_->getInt32Ty(), nullptr,
// op->loop_var->name); loop_var->setAlignment(llvm::Align(4));
// SetVar(op->loop_var->name, loop_var);
} while (false);

////////////////////////////////////
llvm::BasicBlock *preheader_bb = b_->GetInsertBlock();
llvm::BasicBlock *exit_bb = nullptr;

Expand Down Expand Up @@ -814,20 +767,13 @@ llvm::Value *CodeGenLLVM::Visit(const ir::_Module_ *op) {
}

llvm::Value *CodeGenLLVM::Visit(const ir::_Var_ *op) {
llvm::Value *value = GetVar(op->name, false);
llvm::Value *result{};
CHECK(value) << "ir::_Var_[" << op->name << "]: value is null";
// TODO(fc500110) hard coding
if (LLVM_WillVarLowerAsPointer(op->name)) {
result = value;
} else if (value->getType()->isPointerTy() &&
!value->getType()->getPointerElementType()->isPointerTy()) {
result = Load(value, op->name + "_load");
} else {
result = value;
llvm::Value *value = GetVar(op->name, /* lazy= */ false);
// When visiting a Var that is allocated on the stack, we are actually
// reading its value instead of its address.
if (llvm::AllocaInst::classof(value)) {
return Load(value, op->name + "_load");
}

return result;
return value;
}

void CodeGenLLVM::Scalarize(
Expand Down Expand Up @@ -1043,12 +989,6 @@ llvm::Value *CodeGenLLVM::Visit(const ir::_Buffer_ *op) {

llvm::Value *CodeGenLLVM::Visit(const ir::_Tensor_ *op) {
return GetVar(op->name);
auto *buffer_op = op->buffer.As<ir::_Buffer_>();
if (symbol_table_->Lookup(buffer_op->name)) {
return Visit(buffer_op);
}

return SetVar(buffer_op->name, Visit(buffer_op));
}

template <typename T,
Expand Down Expand Up @@ -1437,10 +1377,6 @@ void CodeGenLLVM::InitTarget(const Target &target) {
naive_vec_alignment_ = GetNaiveVecAlignment(target);
}

bool LLVM_WillVarLowerAsPointer(const std::string &var_name) {
return var_name == "_args" || utils::EndsWith(var_name, "__ptr");
}

void CodeGenLLVM::AddTbaaMetadata(llvm::Instruction *inst,
absl::string_view buffer,
Expr index) {
Expand Down
8 changes: 0 additions & 8 deletions paddle/cinn/backends/llvm/codegen_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ class LLVMIRVisitor : public ir::IRVisitorRequireReImpl<llvm::Value *> {
#undef __m
};

/**
* Tell whether a variable called \p \var_name will lowered to a pointer type in
* LLVM.
* @param var_name name of the variable.
* @return a boolean.
*/
bool LLVM_WillVarLowerAsPointer(const std::string &var_name);

class SymbolTable {
public:
SymbolTable() = default;
Expand Down
Loading

0 comments on commit 7f8d0f2

Please sign in to comment.