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.1 kB

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. #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 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. void Register(const std::string &preprocess_name, std::shared_ptr<PreprocessBase> preprocess);
  38. std::shared_ptr<PreprocessBase> GetPreprocess(const std::string &preprocess_name) const;
  39. static PreprocessStorage &Instance();
  40. private:
  41. std::unordered_map<std::string, std::shared_ptr<PreprocessBase>> preprocess_map_;
  42. };
  43. class RegPreprocess {
  44. public:
  45. RegPreprocess(const std::string &preprocess_name, std::shared_ptr<PreprocessBase> preprocess);
  46. };
  47. #define REGISTER_PREPROCESS(cls_name, preprocess_name) \
  48. static RegPreprocess g_register_preprocess_##cls_name(preprocess_name, std::make_shared<cls_name>());
  49. } // namespace mindspore::serving
  50. #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.