You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

kernel_build_client.cc 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Copyright 2020-2021 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "backend/session/kernel_build_client.h"
  17. #include <memory>
  18. namespace mindspore {
  19. namespace kernel {
  20. void ReplaceStr(std::string *dest, const std::string &replace, char new_char) {
  21. std::string::size_type start = 0;
  22. while ((start = (*dest).find(replace, start)) != std::string::npos) {
  23. (*dest).replace(start, replace.size(), 1, new_char);
  24. start++; // Replaced 1 character.
  25. }
  26. }
  27. bool KernelBuildClient::AkgStart(int process_num, int wait_time) {
  28. // Start compiling..
  29. auto res = SendRequest(kAkgStart);
  30. if (res != kAck) {
  31. MS_LOG(ERROR) << "AKG/START failed, res: " << res;
  32. return false;
  33. }
  34. std::string process_num_str = std::to_string(process_num);
  35. res = SendRequest(process_num_str);
  36. if (res != kAck) {
  37. MS_LOG(ERROR) << "AKG/START(process_num) responds failed, res: " << res;
  38. return false;
  39. }
  40. std::string wait_time_str = std::to_string(wait_time);
  41. res = SendRequest(wait_time_str);
  42. if (res != kAck) {
  43. MS_LOG(ERROR) << "AKG/START(wait_time) responds failed, res: " << res;
  44. return false;
  45. }
  46. return true;
  47. }
  48. bool KernelBuildClient::AkgSendAttr(const std::string &attr) {
  49. auto res = SendRequest(kAkgAttr);
  50. if (res != kAck) {
  51. MS_LOG(ERROR) << "AKG/ATTR failed, res: " << res;
  52. return false;
  53. }
  54. res = SendRequest(attr);
  55. if (res != kAck) {
  56. MS_LOG(ERROR) << "AKG/ATTR.. responds failed, res: " << res << ", when sending [" << attr << "]";
  57. return false;
  58. }
  59. return true;
  60. }
  61. bool KernelBuildClient::AkgSendData(const std::vector<std::string> &jsons) {
  62. auto res = SendRequest(kAkgData);
  63. if (res != kAck) {
  64. MS_LOG(ERROR) << "AKG/DATA failed, res: " << res;
  65. return false;
  66. }
  67. for (auto &json : jsons) {
  68. res = SendRequest(json);
  69. if (res != kAck) {
  70. MS_LOG(ERROR) << "AKG/DATA.. responds failed, res: " << res << ", when sending [" << json << "]";
  71. return false;
  72. }
  73. }
  74. return true;
  75. }
  76. // Fetch the result of AKG compiling.
  77. bool KernelBuildClient::AkgWait() {
  78. auto res = SendRequest(kAkgWait);
  79. if (res != kTrue) {
  80. MS_LOG(ERROR) << "AKG/WAIT failed, res: " << res;
  81. return false;
  82. }
  83. return true;
  84. }
  85. std::string AscendKernelBuildClient::DispatchToServer(const std::string &job_json_str) {
  86. auto res = SendRequest(job_json_str);
  87. if (res == kFailed) {
  88. MS_LOG(ERROR) << "Send TBE job json failed, res: " << res;
  89. return "";
  90. }
  91. return res;
  92. }
  93. } // namespace kernel
  94. } // namespace mindspore