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.

context.cc 2.1 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "worker/context.h"
  17. namespace mindspore::serving {
  18. std::shared_ptr<ServableContext> ServableContext::Instance() {
  19. static std::shared_ptr<ServableContext> instance;
  20. if (instance == nullptr) {
  21. instance = std::make_shared<ServableContext>();
  22. }
  23. return instance;
  24. }
  25. void ServableContext::SetDeviceType(DeviceType device_type) { device_type_ = device_type; }
  26. DeviceType ServableContext::GetDeviceType() const { return device_type_; }
  27. void ServableContext::SetDeviceId(uint32_t device_id) { device_id_ = device_id; }
  28. uint32_t ServableContext::GetDeviceId() const { return device_id_; }
  29. Status ServableContext::SetDeviceTypeStr(const std::string &device_type) {
  30. DeviceType type;
  31. std::string device_type_lowcase = device_type;
  32. for (auto &c : device_type_lowcase) {
  33. // cppcheck-suppress useStlAlgorithm
  34. if (c >= 'A' && c <= 'Z') {
  35. c = c - 'A' + 'a';
  36. }
  37. }
  38. if (device_type_lowcase == "ascend" || device_type_lowcase == "davinci") {
  39. type = kDeviceTypeAscend;
  40. } else if (device_type_lowcase == "gpu") {
  41. type = kDeviceTypeGpu;
  42. } else if (device_type_lowcase == "cpu") {
  43. type = kDeviceTypeCpu;
  44. } else if (device_type_lowcase == "none") {
  45. type = kDeviceTypeNotSpecified;
  46. } else {
  47. return INFER_STATUS_LOG_ERROR(FAILED)
  48. << "Unsupported device type '" << device_type
  49. << "', only support 'Ascend', 'Davinci'(same with 'Ascend') and None, case ignored";
  50. }
  51. SetDeviceType(type);
  52. return SUCCESS;
  53. }
  54. } // namespace mindspore::serving

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