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.

preprocess.h 2.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_SERVING_WORKER_PREPROCESS_H
  17. #define MINDSPORE_SERVING_WORKER_PREPROCESS_H
  18. #include <memory>
  19. #include <unordered_map>
  20. #include <vector>
  21. #include <string>
  22. #include <utility>
  23. #include "common/serving_common.h"
  24. #include "common/instance.h"
  25. namespace mindspore::serving {
  26. class MS_API PreprocessBase : public std::enable_shared_from_this<PreprocessBase> {
  27. public:
  28. PreprocessBase() = default;
  29. virtual ~PreprocessBase() = default;
  30. virtual Status Preprocess(const std::string &preprocess_name, const InstanceData &input, InstanceData *output) = 0;
  31. virtual size_t GetInputsCount(const std::string &preprocess_name) const = 0;
  32. virtual size_t GetOutputsCount(const std::string &preprocess_name) const = 0;
  33. virtual bool IsPythonPreprocess() const { return false; }
  34. };
  35. class MS_API PreprocessStorage {
  36. public:
  37. bool Register(const std::string &preprocess_name, std::shared_ptr<PreprocessBase> preprocess);
  38. void Unregister(const std::string &preprocess_name);
  39. std::shared_ptr<PreprocessBase> GetPreprocess(const std::string &preprocess_name) const;
  40. static PreprocessStorage &Instance();
  41. private:
  42. std::unordered_map<std::string, std::shared_ptr<PreprocessBase>> preprocess_map_;
  43. };
  44. class MS_API RegPreprocess {
  45. public:
  46. RegPreprocess(const std::string &preprocess_name, std::shared_ptr<PreprocessBase> preprocess);
  47. ~RegPreprocess();
  48. private:
  49. std::string preprocess_name_;
  50. bool register_success_ = false;
  51. };
  52. #define REGISTER_PREPROCESS(cls_name, preprocess_name) \
  53. static RegPreprocess g_register_preprocess_##cls_name(preprocess_name, std::make_shared<cls_name>());
  54. } // namespace mindspore::serving
  55. #endif // MINDSPORE_SERVING_WORKER_PREPROCESS_H

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