Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion paddle/fluid/framework/custom_operator_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ limitations under the License. */
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/string/string_helper.h"
#include "paddle/phi/api/ext/op_meta_info.h"
#include "paddle/phi/core/enforce.h"

namespace paddle {
namespace framework {

constexpr char kCustomDialectPrefix[] = "custom_op."; // NOLINT
namespace detail {

// dynamic lib load func
Expand Down Expand Up @@ -81,6 +82,31 @@ inline static bool IsMemberOf(const std::vector<std::string>& vec,
return std::find(vec.cbegin(), vec.cend(), name) != vec.cend();
}

inline static const OpMetaInfo& GetOpInfoByPirName(
const std::string& pir_op_name) {
auto custom_name = pir_op_name.substr(strlen(kCustomDialectPrefix));
int pos = custom_name.length();
if (custom_name.find("_grad_grad") != custom_name.npos) {
pos = custom_name.find("_grad_grad") + 1;
} else if (custom_name.find("_grad") != custom_name.npos) {
pos = custom_name.find("_grad") + 1;
}
auto custom_name_prefix = custom_name.substr(0, pos);
auto map_iter =
paddle::OpMetaInfoMap::Instance().GetMap().find(custom_name_prefix);
if (map_iter == paddle::OpMetaInfoMap::Instance().GetMap().end()) {
PADDLE_THROW("The info of custom op : " + custom_name + " is not exists!");
}
const auto& vec_op_meta = map_iter->second;
if (custom_name.find("_grad_grad") != custom_name.npos) {
return vec_op_meta[2];
} else if (custom_name.find("_grad") != custom_name.npos) {
return vec_op_meta[1];
} else {
return vec_op_meta[0];
}
}

} // namespace detail
} // namespace framework
} // namespace paddle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cc_library(
tuple_pop_instruction.cc
builtin_combine_instruction.cc
instruction_util.cc
custom_kernel_instruction.cc
DEPS pir_adaptor phi common framework_proto)

if(WITH_CINN AND NOT CINN_ONLY)
Expand Down
Loading