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.

prim_to_function.h 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright 2019 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_CCSRC_OPERATOR_PRIM_TO_FUNCTION_H_
  17. #define MINDSPORE_CCSRC_OPERATOR_PRIM_TO_FUNCTION_H_
  18. #include <memory>
  19. #include <mutex>
  20. #include <sstream>
  21. #include <string>
  22. #include <typeindex>
  23. #include <unordered_map>
  24. #include <vector>
  25. #include "ir/anf.h"
  26. #include "ir/primitive.h"
  27. #include "ir/dtype.h"
  28. namespace mindspore {
  29. /* namespace to support prim related definition */
  30. namespace prim {
  31. // Supported meta type
  32. enum PrimType { kPrimTypeUnknown, kPrimTypeOneArg, kPrimTypeTwoArgs };
  33. class PrimToFunction;
  34. // Get the args, return value and function handle for a primitive instance.
  35. class PrimToFunction {
  36. public:
  37. // Return a thread-safe singleton instance
  38. static PrimToFunction &GetInstance() {
  39. static PrimToFunction instance;
  40. return instance;
  41. }
  42. PrimToFunction(const PrimToFunction &) = delete;
  43. PrimToFunction &operator=(const PrimToFunction &) = delete;
  44. ~PrimToFunction() = default;
  45. // Get the args and return value for a primitive instance.
  46. bool GetFunction(const PrimitivePtr &prim, FunctionPtr *func) const;
  47. private:
  48. PrimToFunction();
  49. // Get the number of primitive arguments
  50. int GetPrimType(const PrimitivePtr &prim) const;
  51. const std::unordered_map<std::string, int> prim_func_type_map_;
  52. };
  53. } // namespace prim
  54. } // namespace mindspore
  55. #endif // MINDSPORE_CCSRC_OPERATOR_PRIM_TO_FUNCTION_H_