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.

utils.h 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Copyright 2020 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. #ifndef MINDSPORE_STUB_SERVING_UTILS_H
  17. #define MINDSPORE_STUB_SERVING_UTILS_H
  18. #include <memory>
  19. #include <atomic>
  20. #include <string>
  21. #include <vector>
  22. #include <set>
  23. #include "utils/log_adapter.h"
  24. namespace mindspore {
  25. class FuncGraph {};
  26. using FuncGraphPtr = std::shared_ptr<FuncGraph>;
  27. namespace common {
  28. static inline const char *SafeCStr(const std::string &str) {
  29. const int CACHED_STR_NUM = 1 << 8;
  30. const int CACHED_STR_MASK = CACHED_STR_NUM - 1;
  31. std::vector<std::string> STR_HOLDER(CACHED_STR_NUM);
  32. static std::atomic<uint32_t> index{0};
  33. uint32_t cur_index = index++;
  34. cur_index = cur_index & CACHED_STR_MASK;
  35. STR_HOLDER[cur_index] = str;
  36. return STR_HOLDER[cur_index].c_str();
  37. }
  38. } // namespace common
  39. } // namespace mindspore
  40. #endif // MINDSPORE_STUB_SERVING_UTILS_H

A lightweight and high-performance service module that helps MindSpore developers efficiently deploy online inference services in the production environment.