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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. if (c >= 'A' && c <= 'Z') {
  34. c = c - 'A' + 'a';
  35. }
  36. }
  37. if (device_type_lowcase == "ascend" || device_type_lowcase == "davinci") {
  38. type = kDeviceTypeAscend;
  39. } else if (device_type_lowcase == "gpu") {
  40. type = kDeviceTypeGpu;
  41. } else if (device_type_lowcase == "cpu") {
  42. type = kDeviceTypeCpu;
  43. } else if (device_type_lowcase == "none") {
  44. type = kDeviceTypeNotSpecified;
  45. } else {
  46. return INFER_STATUS_LOG_ERROR(FAILED)
  47. << "Unsupport device type '" << device_type
  48. << "', only support 'Ascend', 'Davinci'(same with 'Ascend') and None, case ignored";
  49. }
  50. SetDeviceType(type);
  51. return SUCCESS;
  52. }
  53. } // namespace mindspore::serving

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