MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / PD_RegisterOperator

Function PD_RegisterOperator

paddle/fluid/framework/custom_operator.cc:1336–1443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1334
1335#ifdef PADDLE_WITH_CUSTOM_DEVICE
1336void PD_RegisterOperator(const char* kernel_name_cstr,
1337 size_t in_nargs,
1338 PD_KernelArgumentType* in_args_type,
1339 size_t attr_nargs,
1340 PD_KernelArgumentType* attr_args_type,
1341 size_t out_nargs,
1342 PD_KernelArgumentType* out_args_type,
1343 void (*infer_shape_fn)(PD_InferMetaContext*)) {
1344 std::string kernel_name(kernel_name_cstr);
1345 if (infer_shape_fn &&
1346 !paddle::framework::OpInfoMap::Instance().Has(kernel_name)) {
1347 VLOG(8) << "Registering a new operator: " << kernel_name;
1348
1349 std::vector<std::string> op_inputs, op_outputs, op_attrs;
1350
1351 for (size_t i = 0; i < in_nargs; ++i) {
1352 if (in_args_type[i] == PD_KernelArgumentType::PD_ARG_TYPE_TENSOR) {
1353 op_inputs.push_back("Input_" + std::to_string(i));
1354 } else if (in_args_type[i] ==
1355 PD_KernelArgumentType::PD_ARG_TYPE_LIST_TENSOR) {
1356 op_inputs.push_back("Input_" + std::to_string(i) +
1357 paddle::kTensorVectorSuffix);
1358 } else if (in_args_type[i] ==
1359 PD_KernelArgumentType::PD_ARG_TYPE_OPTIONAL_TENSOR) {
1360 op_inputs.push_back("Input_" + std::to_string(i) +
1361 paddle::kOptionalSuffix);
1362 } else {
1363 op_inputs.push_back("Input_unknown");
1364 }
1365 }
1366 for (size_t i = 0; i < out_nargs; ++i) {
1367 if (out_args_type[i] == PD_KernelArgumentType::PD_ARG_TYPE_TENSOR) {
1368 op_outputs.push_back("Output_" + std::to_string(i));
1369 } else if (out_args_type[i] ==
1370 PD_KernelArgumentType::PD_ARG_TYPE_LIST_TENSOR) {
1371 op_outputs.push_back("Output_" + std::to_string(i) +
1372 paddle::kTensorVectorSuffix);
1373 } else {
1374 op_outputs.push_back("Output_unknown");
1375 }
1376 }
1377 for (size_t i = 0; i < attr_nargs; ++i) {
1378 auto attr_type = attr_args_type[i];
1379 if (attr_type == PD_KernelArgumentType::PD_ARG_TYPE_BOOL) {
1380 op_attrs.push_back("Attr_" + std::to_string(i) + ":bool");
1381 } else if (attr_type == PD_KernelArgumentType::PD_ARG_TYPE_INT32) {
1382 op_attrs.push_back("Attr_" + std::to_string(i) + ":int");
1383 } else if (attr_type == PD_KernelArgumentType::PD_ARG_TYPE_FLOAT32) {
1384 op_attrs.push_back("Attr_" + std::to_string(i) + ":float");
1385 } else if (attr_type == PD_KernelArgumentType::PD_ARG_TYPE_FLOAT64) {
1386 op_attrs.push_back("Attr_" + std::to_string(i) + ":double");
1387 } else if (attr_type == PD_KernelArgumentType::PD_ARG_TYPE_INT64) {
1388 op_attrs.push_back("Attr_" + std::to_string(i) + ":int64_t");
1389 } else if (attr_type == PD_KernelArgumentType::PD_ARG_TYPE_STRING) {
1390 op_attrs.push_back("Attr_" + std::to_string(i) + ":std::string");
1391 } else if (attr_type == PD_KernelArgumentType::PD_ARG_TYPE_LIST_INT32) {
1392 op_attrs.push_back("Attr_" + std::to_string(i) + ":std::vector<int>");
1393 } else if (attr_type == PD_KernelArgumentType::PD_ARG_TYPE_LIST_FLOAT32) {

Callers

nothing calls this directly

Calls 8

InstanceFunction · 0.85
BuildInferMetaContextFunction · 0.85
to_stringFunction · 0.50
HasMethod · 0.45
push_backMethod · 0.45
set_typeMethod · 0.45
IsInitializedMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected