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.

parser_ut_utils.h 1.9 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright 2021 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 GE_PARSER_TESTS_UT_PARSER_H_
  17. #define GE_PARSER_TESTS_UT_PARSER_H_
  18. #include "framework/omg/parser/parser_inner_ctx.h"
  19. #include "graph/compute_graph.h"
  20. namespace ge {
  21. struct MemBuffer {
  22. void *data;
  23. uint32_t size;
  24. };
  25. class ParerUTestsUtils {
  26. public:
  27. static void ClearParserInnerCtx();
  28. static MemBuffer* MemBufferFromFile(const char *path);
  29. static bool ReadProtoFromText(const char *file, google::protobuf::Message *message);
  30. static void WriteProtoToBinaryFile(const google::protobuf::Message &proto, const char *filename);
  31. };
  32. namespace ut {
  33. class GraphBuilder {
  34. public:
  35. explicit GraphBuilder(const std::string &name) { graph_ = std::make_shared<ComputeGraph>(name); }
  36. NodePtr AddNode(const std::string &name, const std::string &type, int in_cnt, int out_cnt,
  37. Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT,
  38. std::vector<int64_t> shape = {1, 1, 224, 224});
  39. void AddDataEdge(const NodePtr &src_node, int src_idx, const NodePtr &dst_node, int dst_idx);
  40. void AddControlEdge(const NodePtr &src_node, const NodePtr &dst_node);
  41. ComputeGraphPtr GetGraph() {
  42. graph_->TopologicalSorting();
  43. return graph_;
  44. }
  45. private:
  46. ComputeGraphPtr graph_;
  47. };
  48. } // namespace ut
  49. } // namespace ge
  50. #endif // GE_PARSER_TESTS_UT_PARSER_H_