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 2.0 kB

4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. static void WriteProtoToTextFile(const google::protobuf::Message &proto, const char *filename);
  32. };
  33. namespace ut {
  34. class GraphBuilder {
  35. public:
  36. explicit GraphBuilder(const std::string &name) { graph_ = std::make_shared<ComputeGraph>(name); }
  37. NodePtr AddNode(const std::string &name, const std::string &type, int in_cnt, int out_cnt,
  38. Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT,
  39. std::vector<int64_t> shape = {1, 1, 224, 224});
  40. void AddDataEdge(const NodePtr &src_node, int src_idx, const NodePtr &dst_node, int dst_idx);
  41. void AddControlEdge(const NodePtr &src_node, const NodePtr &dst_node);
  42. ComputeGraphPtr GetGraph() {
  43. graph_->TopologicalSorting();
  44. return graph_;
  45. }
  46. private:
  47. ComputeGraphPtr graph_;
  48. };
  49. } // namespace ut
  50. } // namespace ge
  51. #endif // GE_PARSER_TESTS_UT_PARSER_H_