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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 "utils/log_adapter.h"
  23. namespace mindspore {
  24. class FuncGraph {};
  25. using FuncGraphPtr = std::shared_ptr<FuncGraph>;
  26. namespace common {
  27. static inline const char *SafeCStr(const std::string &str) {
  28. const int CACHED_STR_NUM = 1 << 8;
  29. const int CACHED_STR_MASK = CACHED_STR_NUM - 1;
  30. std::vector<std::string> STR_HOLDER(CACHED_STR_NUM);
  31. static std::atomic<uint32_t> index{0};
  32. uint32_t cur_index = index++;
  33. cur_index = cur_index & CACHED_STR_MASK;
  34. STR_HOLDER[cur_index] = str;
  35. return STR_HOLDER[cur_index].c_str();
  36. }
  37. } // namespace common
  38. } // namespace mindspore
  39. #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.