runtime_op.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright 2019-2020 Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #pragma once
  16. #include "../datatypes.h"
  17. #include <string_view>
  18. namespace nncase
  19. {
  20. namespace runtime
  21. {
  22. #define BEGINE_DEFINE_TARGET(...)
  23. #define DEFINE_NEUTRAL_RUNTIME_OP(id, name, value) rop_##id = value,
  24. #define DEFINE_RUNTIME_OP(target, id, name, value) rop_##target##_##id = value,
  25. #define END_DEFINE_TARGET()
  26. enum runtime_opcode : uint32_t
  27. {
  28. #include "runtime_op.def"
  29. };
  30. #undef DEFINE_NEUTRAL_RUNTIME_OP
  31. #undef DEFINE_RUNTIME_OP
  32. #define DEFINE_NEUTRAL_RUNTIME_OP(id, name, value) \
  33. case rop_##id: \
  34. return #name;
  35. #define DEFINE_RUNTIME_OP(target, id, name, value) \
  36. case rop_##target##_##id: \
  37. return #name;
  38. constexpr std::string_view node_opcode_names(runtime_opcode opcode)
  39. {
  40. switch (opcode)
  41. {
  42. #include "runtime_op.def"
  43. default:
  44. return {};
  45. }
  46. }
  47. #undef BEGINE_DEFINE_TARGET
  48. #undef DEFINE_NEUTRAL_RUNTIME_OP
  49. #undef DEFINE_RUNTIME_OP
  50. #undef END_DEFINE_TARGET
  51. }
  52. }