kernel_factory.cc 20.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//   Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

15
#include "paddle/phi/core/kernel_factory.h"
16

W
wanghuancoder 已提交
17 18 19 20
#include <regex>
#include <string>
#include <unordered_set>

21
#include "glog/logging.h"
22
#include "paddle/phi/core/enforce.h"
23
#include "paddle/utils/flags.h"
24
#if defined(PADDLE_WITH_XPU)
25
#include "paddle/phi/backends/xpu/xpu_op_list.h"
26
#include "paddle/phi/common/data_type.h"
27 28
#include "paddle/phi/core/compat/convert_utils.h"
#endif
29 30 31
#if defined(PADDLE_WITH_CUSTOM_DEVICE)
#include "paddle/phi/backends/custom/custom_device_op_list.h"
#endif
32
#include "paddle/phi/core/compat/op_utils.h"
33
#include "paddle/phi/core/flags.h"
34
#include "paddle/utils/string/string_helper.h"
35

36 37 38
PHI_DEFINE_EXPORTED_bool(use_stride_kernel,
                         true,
                         "Whether to use strdie kernel if op support stride.");
W
wanghuancoder 已提交
39

W
wanghuancoder 已提交
40 41 42 43
PHI_DEFINE_EXPORTED_string(stride_kernel_blacklist,
                           "",
                           "It controls the strided kernel subset do not use.");

44 45 46
PD_DECLARE_int32(low_precision_op_list);
PD_DECLARE_bool(enable_api_kernel_fallback);
PD_DECLARE_bool(run_kp_kernel);
47
namespace phi {
48

49 50
const static Kernel empty_kernel;  // NOLINT

51 52
std::string KernelSelectionErrorMessage(const std::string& kernel_name,
                                        const KernelKey& target_key);
53

54 55 56 57 58 59 60 61 62
uint32_t KernelKey::Hash::operator()(const KernelKey& key) const {
  uint32_t hash_value = 0;
  // |----31-20------|---19-12---|---11-8----|---7-0---|
  // | For extension | DataType | DataLayout | Backend |
  hash_value |= static_cast<uint8_t>(key.backend());
  hash_value |=
      (static_cast<uint8_t>(key.layout()) << KernelKey::kBackendBitLength);
  hash_value |=
      (static_cast<uint16_t>(key.dtype())
63
       << (KernelKey::kBackendBitLength + KernelKey::kDataLayoutBitLength));
64 65 66 67 68 69 70 71
  return hash_value;
}

KernelFactory& KernelFactory::Instance() {
  static KernelFactory g_op_kernel_factory;
  return g_op_kernel_factory;
}

72 73 74 75 76 77 78 79 80 81 82
bool KernelFactory::HasCompatiblePhiKernel(const std::string& op_type) const {
  if (deprecated_op_names.find(op_type) == deprecated_op_names.end()) {
    if (phi::OpUtilsMap::Instance().Contains(op_type)) {
      return true;
    } else if (kernels_.find(op_type) != kernels_.end()) {
      return true;
    }
  }
  return false;
}

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
bool KernelFactory::HasStructuredKernel(const std::string& op_type) const {
  auto phi_kernel_name = phi::OpUtilsMap::Instance().GetBaseKernelName(op_type);
  auto kernel_iter = kernels_.find(phi_kernel_name);
  if (deprecated_op_names.find(op_type) == deprecated_op_names.end() &&
      kernel_iter != kernels_.end()) {
    return std::any_of(kernel_iter->second.begin(),
                       kernel_iter->second.end(),
                       [](phi::KernelKeyMap::const_reference kernel_pair) {
                         return kernel_pair.second.GetKernelRegisteredType() ==
                                KernelRegisteredType::STRUCTURE;
                       });
  }
  return false;
}

98 99
const Kernel& KernelFactory::SelectKernel(const std::string& kernel_name,
                                          const KernelKey& kernel_key) const {
100 101
  auto iter = kernels_.find(kernel_name);
  if (iter == kernels_.end()) {
102
    return empty_kernel;
103
  }
H
hong 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

  auto kernel_iter = iter->second.find(kernel_key);
  if (kernel_iter == iter->second.end() &&
      kernel_key.layout() != phi::DataLayout::ALL_LAYOUT) {
    phi::KernelKey any_layout_kernel_key(
        kernel_key.backend(), phi::DataLayout::ALL_LAYOUT, kernel_key.dtype());
    kernel_iter = iter->second.find(any_layout_kernel_key);
  }

#if defined(PADDLE_WITH_CUSTOM_DEVICE)
  if (kernel_iter == iter->second.end() &&
      kernel_key.backend() > phi::Backend::NUM_BACKENDS) {
    kernel_iter = iter->second.find({phi::Backend::CUSTOM,
                                     phi::DataLayout::ALL_LAYOUT,
                                     kernel_key.dtype()});
  }
#endif

  if (kernel_iter == iter->second.end()) {
    return empty_kernel;
  }

  return kernel_iter->second;
}

const Kernel& KernelFactory::SelectKernelWithGPUDNN(
    const std::string& kernel_name, const KernelKey& const_kernel_key) const {
  auto iter = kernels_.find(kernel_name);
  if (iter == kernels_.end()) {
    return empty_kernel;
  }
  KernelKey kernel_key = KernelKey(const_kernel_key);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
  if (kernel_key.backend() == Backend::GPUDNN) {
    auto kernel_iter = iter->second.find(
        {Backend::GPUDNN, phi::DataLayout::ALL_LAYOUT, kernel_key.dtype()});
    if (kernel_iter != iter->second.end()) {
      return kernel_iter->second;
    }
    kernel_key =
        KernelKey(Backend::GPU, kernel_key.layout(), kernel_key.dtype());
  }
#endif

148
  auto kernel_iter = iter->second.find(kernel_key);
149 150 151 152 153 154
  if (kernel_iter == iter->second.end() &&
      kernel_key.layout() != phi::DataLayout::ALL_LAYOUT) {
    phi::KernelKey any_layout_kernel_key(
        kernel_key.backend(), phi::DataLayout::ALL_LAYOUT, kernel_key.dtype());
    kernel_iter = iter->second.find(any_layout_kernel_key);
  }
H
hong 已提交
155

156 157 158 159 160 161 162 163
#if defined(PADDLE_WITH_CUSTOM_DEVICE)
  if (kernel_iter == iter->second.end() &&
      kernel_key.backend() > phi::Backend::NUM_BACKENDS) {
    kernel_iter = iter->second.find({phi::Backend::CUSTOM,
                                     phi::DataLayout::ALL_LAYOUT,
                                     kernel_key.dtype()});
  }
#endif
164

165
  if (kernel_iter == iter->second.end()) {
166
    return empty_kernel;
167
  }
168

169 170 171
  return kernel_iter->second;
}

172 173
KernelKeyMap KernelFactory::SelectKernelMap(
    const std::string& kernel_name) const {
174 175
  auto iter = kernels_.find(kernel_name);
  if (iter == kernels_.end()) {
176
    return KernelKeyMap();
177 178 179 180
  }
  return iter->second;
}

181 182
bool KernelFactory::HasKernel(const std::string& kernel_name,
                              const KernelKey& kernel_key) const {
183 184 185 186 187 188 189 190 191 192 193 194 195
  auto iter = kernels_.find(kernel_name);
  PADDLE_ENFORCE_NE(
      iter,
      kernels_.end(),
      phi::errors::NotFound("The kernel `%s` is not registered.", kernel_name));

  auto kernel_iter = iter->second.find(kernel_key);
  if (kernel_iter == iter->second.end()) {
    return false;
  }
  return true;
}

196
void KernelFactory::AddToLowPrecisionKernelList(
197
    const std::string& name, const phi::DataType& kernel_key_type) {
198 199 200 201 202
  if (FLAGS_low_precision_op_list >= 1) {
    auto op_name = phi::TransToFluidOpName(name);
    if (op_name.find("_grad") != std::string::npos) {
      return;  // only record forward api
    }
203 204 205 206 207

    if (low_precision_kernels_.find(op_name) == low_precision_kernels_.end()) {
      auto count = OpCount();
      low_precision_kernels_[op_name] = count;
    }
208
    if (kernel_key_type == phi::DataType::FLOAT16) {
209
      low_precision_kernels_[op_name].fp16_called_ += 1;
210
    } else if (kernel_key_type == phi::DataType::BFLOAT16) {
211
      low_precision_kernels_[op_name].bf16_called_ += 1;
212
    } else if (kernel_key_type == phi::DataType::FLOAT32) {
213 214 215
      low_precision_kernels_[op_name].fp32_called_ += 1;
    } else {
      low_precision_kernels_[op_name].other_called_ += 1;
216 217 218 219
    }
  }
}

220 221
std::map<const std::string, OpCount>
KernelFactory::GetLowPrecisionKernelList() {
222 223 224
  return low_precision_kernels_;
}

225
KernelResult KernelFactory::SelectKernelOrThrowError(
W
wanghuancoder 已提交
226 227 228
    const std::string& kernel_name,
    const KernelKey& const_kernel_key,
    bool use_strided_kernel) const {
229
  auto iter = kernels_.find(kernel_name);
230

231 232 233 234
  PADDLE_ENFORCE_NE(
      iter,
      kernels_.end(),
      phi::errors::NotFound("The kernel `%s` is not registered.", kernel_name));
235

W
wanghuancoder 已提交
236
  if (FLAGS_use_stride_kernel && use_strided_kernel) {
W
wanghuancoder 已提交
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
    std::regex reg(",");
    std::unordered_set<std::string> elems{
        std::sregex_token_iterator(FLAGS_stride_kernel_blacklist.begin(),
                                   FLAGS_stride_kernel_blacklist.end(),
                                   reg,
                                   -1),
        std::sregex_token_iterator()};
    elems.erase("");

    if (!elems.count(kernel_name)) {
      auto stride_kernel_iter = iter->second.find(
          {const_kernel_key.backend() == paddle::experimental::Backend::GPUDNN
               ? paddle::experimental::Backend::GPU
               : const_kernel_key.backend(),
           phi::DataLayout::STRIDED,
           const_kernel_key.dtype()});
      if (stride_kernel_iter != iter->second.end()) {
        VLOG(1) << "use strided kernel, kernel_name = " << kernel_name;
        return {stride_kernel_iter->second, false, true};
      }
W
wanghuancoder 已提交
257 258 259
    }
  }

260 261 262
  KernelKey kernel_key = KernelKey(const_kernel_key.backend(),
                                   phi::DataLayout::ALL_LAYOUT,
                                   const_kernel_key.dtype());
Z
zyfncg 已提交
263
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
264
  if (kernel_key.backend() == Backend::GPUDNN) {
Z
zyfncg 已提交
265
    auto kernel_iter = iter->second.find(
266
        {Backend::GPUDNN, phi::DataLayout::ALL_LAYOUT, kernel_key.dtype()});
Z
zyfncg 已提交
267
    if (kernel_iter != iter->second.end()) {
W
wanghuancoder 已提交
268
      return {kernel_iter->second, false, false};
Z
zyfncg 已提交
269
    }
270 271
    kernel_key =
        KernelKey(Backend::GPU, kernel_key.layout(), kernel_key.dtype());
Z
zyfncg 已提交
272 273
  }
#endif
274
  auto kernel_iter = iter->second.find(kernel_key);
275

276 277 278 279
  PADDLE_ENFORCE_NE(
      kernel_iter == iter->second.end() && kernel_key.backend() == Backend::CPU,
      true,
      phi::errors::NotFound(
280
          "The kernel with key %s of kernel `%s` is not registered. %s",
281
          kernel_key,
282
          kernel_name,
283
          KernelSelectionErrorMessage(kernel_name, kernel_key)));
284

285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
#if defined(PADDLE_WITH_XPU_KP)
  auto fluid_op_name = TransToFluidOpName(kernel_name);
  bool has_kp_kernel = false;
  VLOG(6) << "fluid_op_name: " << TransToFluidOpName(kernel_name);
  bool is_xpu_kp_supported = phi::backends::xpu::is_xpu_kp_support_op(
      fluid_op_name, kernel_key.dtype());
  // Check in xpu_kp
  if (is_xpu_kp_supported && FLAGS_run_kp_kernel) {
    auto kernel_key_kp =
        KernelKey(Backend::KPS, kernel_key.layout(), kernel_key.dtype());
    auto kernel_iter_kp = iter->second.find(kernel_key_kp);
    has_kp_kernel = (kernel_iter_kp != iter->second.end());
    if (has_kp_kernel) {
      kernel_key = kernel_key_kp;
      kernel_iter = kernel_iter_kp;
    }
  }
  // check in xpu
  bool xpu_unsupport =
      !phi::backends::xpu::is_xpu_support_op(fluid_op_name, kernel_key.dtype());
  VLOG(6) << "Current KernelKey is " << kernel_key;
  // Fall back to CPU, when FLAGS_enable_api_kernel_fallback is true and op
  // was unregistered in xpu and kp
  if (FLAGS_enable_api_kernel_fallback &&
      (kernel_iter == iter->second.end() || (xpu_unsupport && !has_kp_kernel))
#elif defined(PADDLE_WITH_XPU) && !defined(PADDLE_WITH_XPU_KP)
311 312
  VLOG(6) << "fluid_op_name: " << TransToFluidOpName(kernel_name);
  if ((FLAGS_enable_api_kernel_fallback && kernel_iter == iter->second.end()) ||
Q
QingshuChen 已提交
313 314
      !phi::backends::xpu::is_xpu_support_op(TransToFluidOpName(kernel_name),
                                             kernel_key.dtype())
315
#elif defined(PADDLE_WITH_CUSTOM_DEVICE)
316 317 318 319 320 321
  if (kernel_iter == iter->second.end() &&
      kernel_key.backend() > phi::Backend::NUM_BACKENDS) {
    kernel_iter = iter->second.find({phi::Backend::CUSTOM,
                                     phi::DataLayout::ALL_LAYOUT,
                                     kernel_key.dtype()});
  }
322 323 324 325
  if (FLAGS_enable_api_kernel_fallback &&
      (kernel_iter == iter->second.end() ||
       phi::backends::custom_device::is_in_custom_black_list(
           TransToFluidOpName(kernel_name)))
326 327
#else
  if ((FLAGS_enable_api_kernel_fallback && kernel_iter == iter->second.end())
328 329
#endif
  ) {
330 331 332 333
    // Fallback CPU backend
    phi::KernelKey cpu_kernel_key(
        phi::Backend::CPU, kernel_key.layout(), kernel_key.dtype());
    kernel_iter = iter->second.find(cpu_kernel_key);
334 335 336 337 338

    PADDLE_ENFORCE_NE(
        kernel_iter,
        iter->second.end(),
        phi::errors::NotFound(
339 340
            "The kernel with key %s of kernel `%s` is not registered and "
            "fail to fallback to CPU one. %s",
341
            kernel_key,
342
            kernel_name,
343
            KernelSelectionErrorMessage(kernel_name, kernel_key)));
344 345 346 347 348

    VLOG(3) << "missing " << kernel_key.backend() << " kernel: " << kernel_name
            << ", expected_kernel_key:" << kernel_key
            << ", fallbacking to CPU one!";

W
wanghuancoder 已提交
349
    return {kernel_iter->second, true, false};
350 351
  }

352 353 354
  PADDLE_ENFORCE_NE(
      kernel_iter,
      iter->second.end(),
355
      phi::errors::NotFound(
356 357
          "The kernel with key %s of kernel `%s` is not registered. %s "
          "The current value of FLAGS_enable_api_kernel_fallback(bool,"
358 359
          " default true) is false. If you want to fallback this kernel"
          " to CPU one, please set the flag true before run again.",
360
          kernel_key,
361
          kernel_name,
362
          KernelSelectionErrorMessage(kernel_name, kernel_key)));
363

W
wanghuancoder 已提交
364
  return {kernel_iter->second, false, false};
365 366
}

367 368 369 370 371 372 373 374 375 376
const KernelArgsDef& KernelFactory::GetFirstKernelArgsDef(
    const std::string& kernel_name) const {
  auto iter = kernels_.find(kernel_name);
  PADDLE_ENFORCE_NE(
      iter,
      kernels_.end(),
      phi::errors::NotFound("The kernel `%s` is not registered.", kernel_name));
  return iter->second.cbegin()->second.args_def();
}

377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
std::ostream& operator<<(std::ostream& os, AttributeType attr_type) {
  switch (attr_type) {
    case AttributeType::BOOL:
      os << "bool";
      break;
    case AttributeType::INT32:
      os << "int";
      break;
    case AttributeType::INT64:
      os << "int64_t";
      break;
    case AttributeType::FLOAT32:
      os << "float";
      break;
    case AttributeType::FLOAT64:
      os << "double";
      break;
    case AttributeType::STRING:
      os << "string";
      break;
    case AttributeType::BOOLS:
      os << "vector<bool>";
      break;
    case AttributeType::INT32S:
      os << "vector<int>";
      break;
    case AttributeType::INT64S:
      os << "vector<int64_t>";
      break;
    case AttributeType::FLOAT32S:
      os << "vector<float>";
      break;
    case AttributeType::FLOAT64S:
      os << "vector<double>";
      break;
    case AttributeType::STRINGS:
      os << "vector<string>";
      break;
    case AttributeType::SCALAR:
      os << "Scalar";
      break;
    case AttributeType::SCALARS:
      os << "vector<Scalar>";
      break;
    case AttributeType::INT_ARRAY:
      os << "IntArray";
      break;
    case AttributeType::DATA_TYPE:
      os << "DataType";
      break;
    case AttributeType::DATA_LAYOUT:
      os << "DataLayout";
      break;
    case AttributeType::PLACE:
      os << "Place";
      break;
    default:
      os << "Undefined";
  }
  return os;
}

439 440 441 442 443 444 445
// print kernel info with json format:
// {
//   "(CPU, Undefined(AnyLayout), complex64)": {
//   "input": ["CPU, NCHW, complex64", "CPU, NCHW, complex64"],
//   "output": ["CPU, NCHW, complex64"],
//   "attribute": ["i"]
// }
446
std::ostream& operator<<(std::ostream& os, const Kernel& kernel) {
447 448 449
  // input
  os << "{\"input\":[";
  bool need_comma = false;
450
  for (auto& in_def : kernel.args_def().input_defs()) {
451 452 453 454
    if (need_comma) os << ",";
    os << "\"" << in_def.backend << ", " << in_def.layout << ", "
       << in_def.dtype << "\"";
    need_comma = true;
455
  }
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
  os << "],";

  // output
  os << "\"output\":[";
  need_comma = false;
  for (auto& out_def : kernel.args_def().output_defs()) {
    if (need_comma) os << ",";
    os << "\"" << out_def.backend << ", " << out_def.layout << ", "
       << out_def.dtype << "\"";
    need_comma = true;
  }
  os << "],";

  // attr
  os << "\"attribute\":[";
  need_comma = false;
  for (auto& arg_def : kernel.args_def().attribute_defs()) {
    if (need_comma) os << ",";
474
    os << "\"" << arg_def.type_index << "\"";
475 476 477 478
    need_comma = true;
  }
  os << "]}";

479 480 481
  return os;
}

482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
// print all kernels info with json format:
// {
//  "kernel_name1":
//      [
//        {
//          "(CPU, Undefined(AnyLayout), complex64)": {
//          "input": ["CPU, NCHW, complex64", "CPU, NCHW, complex64"],
//          "output": ["CPU, NCHW, complex64"],
//          "attribute": ["i"]
//        },
//        ...
//      ],
//    "kernel_name2": []
//    ...
// }
497
std::ostream& operator<<(std::ostream& os, KernelFactory& kernel_factory) {
498 499
  os << "{";
  bool need_comma_kernels = false;
500
  for (const auto& op_kernel_pair : kernel_factory.kernels()) {
501 502 503 504 505
    if (need_comma_kernels) {
      os << ",";
      os << std::endl;
    }
    os << "\"" << op_kernel_pair.first << " \":[" << std::endl;
506
    bool need_comma_per_kernel = false;
507
    for (const auto& kernel_pair : op_kernel_pair.second) {
508 509 510 511
      if (need_comma_per_kernel) {
        os << ",";
        os << std::endl;
      }
512 513
      os << "{\"" << kernel_pair.first << "\":" << kernel_pair.second << "}";
      need_comma_per_kernel = true;
514
    }
515 516
    os << "]";
    need_comma_kernels = true;
517
  }
518 519
  os << "}";

520 521 522
  return os;
}

523 524 525 526 527 528 529 530 531 532 533 534
// return all kernel selection error message of specific kernel_name:
// 1. If target_key not supports target backend, output "Selected wrong Backend
// ..."
// 2. If target_key not supports target datatype, output "Selected wrong
// DataType ..."
// 3. `target_key` is still not supported, output all kernel keys of
// corresponding kernel_name:
// {
//   (CPU, NCHW, [int8, int16, ...]);
//   (GPU, Undefined(AnyLayout), [float32, float64, ...]);
//   ...
// }
535 536
std::string KernelSelectionErrorMessage(const std::string& kernel_name,
                                        const KernelKey& target_key) {
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
  PADDLE_ENFORCE_NE(
      KernelFactory::Instance().kernels().find(kernel_name),
      KernelFactory::Instance().kernels().end(),
      phi::errors::NotFound("The kernel `%s` is not registered.", kernel_name));

  // Init data structure
  bool support_backend = false;
  bool support_dtype = false;
  std::unordered_map<std::string, std::vector<std::string>> all_kernel_key;
  std::unordered_set<std::string> backend_set;
  std::unordered_set<std::string> dtype_set;

  // Record all kernel information of kernel_name
  for (auto iter : KernelFactory::Instance().kernels()[kernel_name]) {
    KernelKey kernel_key = iter.first;
    if (kernel_key.backend() == target_key.backend()) {
      support_backend = true;
      if (kernel_key.dtype() == target_key.dtype()) {
        support_dtype = true;
      }
557
      dtype_set.insert(DataTypeToString(kernel_key.dtype()));
558 559 560 561 562
    }
    backend_set.insert(
        paddle::experimental::BackendToString(kernel_key.backend()));
    all_kernel_key[paddle::experimental::BackendToString(kernel_key.backend()) +
                   ", " + phi::DataLayoutToString(kernel_key.layout())]
563
        .push_back(DataTypeToString(kernel_key.dtype()));
564 565 566 567
  }
  // 1. If target_key not supports target backend, output "Selected wrong
  // Backend ..."
  if (!support_backend) {
568
    std::string error_message = paddle::string::join_strings(backend_set, ", ");
569 570 571 572 573 574 575
    return "Selected wrong Backend `" +
           paddle::experimental::BackendToString(target_key.backend()) +
           "`. Paddle support following Backends: " + error_message + ".";
  }
  // 2. If target_key not supports target datatype, output "Selected wrong
  // DataType ..."
  if (!support_dtype) {
576
    std::string error_message = paddle::string::join_strings(dtype_set, ", ");
577
    return "Selected wrong DataType `" + DataTypeToString(target_key.dtype()) +
578 579 580 581 582 583
           "`. Paddle support following DataTypes: " + error_message + ".";
  }
  // 3. `target_key` is still not supported, output all kernel keys of
  // corresponding kernel_name
  std::string message = "Currently, paddle support following kernel keys of `" +
                        kernel_name + "`: { ";
584 585 586
  for (auto& item : all_kernel_key) {
    std::vector<std::string>& dtype_vec = item.second;
    message += "(" + item.first + ", [";
587
    message += paddle::string::join_strings(dtype_vec, ", ");
588 589 590 591 592 593
    message += "]); ";
  }
  message += "}.";
  return message;
}

594
}  // namespace phi