Browse Source

add graph dsl for building graph

tags/v1.3.0
WeiGangqiang 3 years ago
parent
commit
bde0f45eba
94 changed files with 3712 additions and 208 deletions
  1. +9
    -7
      build.sh
  2. +1
    -0
      tests/CMakeLists.txt
  3. +32
    -0
      tests/framework/CMakeLists.txt
  4. +0
    -0
      tests/framework/cmake/graphengine.cmake
  5. +26
    -0
      tests/framework/easy_graph/CMakeLists.txt
  6. +40
    -0
      tests/framework/easy_graph/include/easy_graph/builder/box_builder.h
  7. +81
    -0
      tests/framework/easy_graph/include/easy_graph/builder/chain_builder.h
  8. +64
    -0
      tests/framework/easy_graph/include/easy_graph/builder/graph_builder.h
  9. +45
    -0
      tests/framework/easy_graph/include/easy_graph/builder/graph_dsl.h
  10. +49
    -0
      tests/framework/easy_graph/include/easy_graph/builder/link.h
  11. +29
    -0
      tests/framework/easy_graph/include/easy_graph/eg.h
  12. +41
    -0
      tests/framework/easy_graph/include/easy_graph/graph/box.h
  13. +46
    -0
      tests/framework/easy_graph/include/easy_graph/graph/edge.h
  14. +31
    -0
      tests/framework/easy_graph/include/easy_graph/graph/edge_type.h
  15. +41
    -0
      tests/framework/easy_graph/include/easy_graph/graph/endpoint.h
  16. +58
    -0
      tests/framework/easy_graph/include/easy_graph/graph/graph.h
  17. +37
    -0
      tests/framework/easy_graph/include/easy_graph/graph/graph_visitor.h
  18. +62
    -0
      tests/framework/easy_graph/include/easy_graph/graph/node.h
  19. +15
    -8
      tests/framework/easy_graph/include/easy_graph/graph/node_id.h
  20. +30
    -0
      tests/framework/easy_graph/include/easy_graph/graph/port_id.h
  21. +59
    -0
      tests/framework/easy_graph/include/easy_graph/infra/default.h
  22. +39
    -0
      tests/framework/easy_graph/include/easy_graph/infra/ext_traits.h
  23. +42
    -0
      tests/framework/easy_graph/include/easy_graph/infra/keywords.h
  24. +64
    -0
      tests/framework/easy_graph/include/easy_graph/infra/log.h
  25. +58
    -0
      tests/framework/easy_graph/include/easy_graph/infra/macro_traits.h
  26. +68
    -0
      tests/framework/easy_graph/include/easy_graph/infra/operator.h
  27. +41
    -0
      tests/framework/easy_graph/include/easy_graph/infra/scope_guard.h
  28. +42
    -0
      tests/framework/easy_graph/include/easy_graph/infra/singleton.h
  29. +55
    -0
      tests/framework/easy_graph/include/easy_graph/infra/status.h
  30. +31
    -0
      tests/framework/easy_graph/include/easy_graph/layout/engines/graph_easy/graph_easy_executor.h
  31. +53
    -0
      tests/framework/easy_graph/include/easy_graph/layout/engines/graph_easy/graph_easy_layout_context.h
  32. +63
    -0
      tests/framework/easy_graph/include/easy_graph/layout/engines/graph_easy/graph_easy_option.h
  33. +45
    -0
      tests/framework/easy_graph/include/easy_graph/layout/engines/graph_easy/graph_easy_visitor.h
  34. +40
    -0
      tests/framework/easy_graph/include/easy_graph/layout/graph_layout.h
  35. +34
    -0
      tests/framework/easy_graph/include/easy_graph/layout/layout_executor.h
  36. +28
    -0
      tests/framework/easy_graph/include/easy_graph/layout/layout_option.h
  37. +72
    -0
      tests/framework/easy_graph/src/builder/chain_builder.cc
  38. +78
    -0
      tests/framework/easy_graph/src/builder/graph_builder.cc
  39. +53
    -0
      tests/framework/easy_graph/src/graph/edge.cc
  40. +43
    -0
      tests/framework/easy_graph/src/graph/endpoint.cc
  41. +70
    -0
      tests/framework/easy_graph/src/graph/graph.cc
  42. +49
    -0
      tests/framework/easy_graph/src/graph/node.cc
  43. +138
    -0
      tests/framework/easy_graph/src/infra/log.cc
  44. +47
    -0
      tests/framework/easy_graph/src/layout/engines/graph_easy/graph_easy_executor.cc
  45. +65
    -0
      tests/framework/easy_graph/src/layout/engines/graph_easy/graph_easy_layout_context.cc
  46. +54
    -0
      tests/framework/easy_graph/src/layout/engines/graph_easy/graph_easy_option.cc
  47. +188
    -0
      tests/framework/easy_graph/src/layout/engines/graph_easy/graph_easy_visitor.cc
  48. +43
    -0
      tests/framework/easy_graph/src/layout/engines/graph_easy/utils/shell_executor.cc
  49. +32
    -0
      tests/framework/easy_graph/src/layout/engines/graph_easy/utils/shell_executor.h
  50. +35
    -0
      tests/framework/easy_graph/src/layout/graph_layout.cc
  51. +18
    -0
      tests/framework/ge_graph_dsl/CMakeLists.txt
  52. +17
    -0
      tests/framework/ge_graph_dsl/include/CMakeLists.txt
  53. +29
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/ge.h
  54. +38
    -34
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/graph_dsl.h
  55. +33
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_box.h
  56. +52
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg.h
  57. +51
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg_box.h
  58. +34
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg_repo.h
  59. +57
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_node_builder.h
  60. +38
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_ptr_box.h
  61. +28
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_type.h
  62. +44
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/vistor/ge_graph_vistor.h
  63. +47
    -0
      tests/framework/ge_graph_dsl/include/ge_graph_dsl/vistor/ge_subgraph_vistor.h
  64. +28
    -0
      tests/framework/ge_graph_dsl/src/CMakeLists.txt
  65. +79
    -0
      tests/framework/ge_graph_dsl/src/ge_graph_vistor.cc
  66. +70
    -0
      tests/framework/ge_graph_dsl/src/ge_subgraph_vistor.cc
  67. +39
    -0
      tests/framework/ge_graph_dsl/src/graph_dsl.cc
  68. +75
    -0
      tests/framework/ge_graph_dsl/src/op_desc_cfg_box.cc
  69. +46
    -0
      tests/framework/ge_graph_dsl/src/op_desc_cfg_repo.cc
  70. +24
    -17
      tests/framework/ge_graph_dsl/src/op_desc_ptr_box.cc
  71. +33
    -0
      tests/framework/ge_graph_dsl/tests/CMakeLists.txt
  72. +218
    -0
      tests/framework/ge_graph_dsl/tests/graph_dsl_test.cc
  73. +33
    -0
      tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc
  74. +2
    -21
      tests/framework/stub_engine/CMakeLists.txt
  75. +6
    -2
      tests/framework/stub_engine/engine/stub_engine.cc
  76. +0
    -0
      tests/framework/stub_engine/engine/stub_engine.h
  77. +3
    -3
      tests/framework/stub_engine/inc/st_types.h
  78. +0
    -1
      tests/framework/stub_engine/ops_kernel_store/op/host_op.cc
  79. +0
    -0
      tests/framework/stub_engine/ops_kernel_store/op/host_op.h
  80. +0
    -0
      tests/framework/stub_engine/ops_kernel_store/op/op.h
  81. +0
    -0
      tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.cc
  82. +11
    -7
      tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.h
  83. +9
    -5
      tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.cc
  84. +0
    -0
      tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.h
  85. +3
    -1
      tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.cc
  86. +3
    -1
      tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.h
  87. +0
    -0
      tests/framework/utils/builder/graph_builder_utils.cc
  88. +3
    -1
      tests/framework/utils/builder/graph_builder_utils.h
  89. +0
    -0
      tests/framework/utils/builder/tensor_builder_utils.cc
  90. +0
    -0
      tests/framework/utils/builder/tensor_builder_utils.h
  91. +0
    -4
      tests/st/CMakeLists.txt
  92. +0
    -17
      tests/st/framework/framework.cc
  93. +1
    -1
      tests/st/testcase/CMakeLists.txt
  94. +74
    -78
      tests/st/testcase/test_framework_dummy.cc

+ 9
- 7
build.sh View File

@@ -174,12 +174,12 @@ build_graphengine()
elif [ "x${PLATFORM}" = "xinference" ]
then
TARGET="ge_compiler atc_atc.bin ge_executor_shared ${TARGET}"
elif [ "X$ENABLE_GE_ST" = "Xon" ]
then
TARGET="ge_graph_dsl_test graph_engine_test"
elif [ "X$ENABLE_GE_UT" = "Xon" ]
then
TARGET="ut_libgraph ut_libge_multiparts_utest ut_libge_others_utest ut_libge_kernel_utest ut_libge_distinct_load_utest"
elif [ "X$ENABLE_GE_ST" = "Xon" ]
then
TARGET="graph_engine_test"
elif [ "X$MINDSPORE_MODE" = "Xon" ]
then
TARGET="ge_common graph"
@@ -242,15 +242,17 @@ if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
mkdir -p ${OUTPUT_PATH}/plugin/nnengine
mkdir -p ${OUTPUT_PATH}/plugin/nnengine/ge_config
mkdir -p ${OUTPUT_PATH}/plugin/opskernel
cp ${BUILD_PATH}/tests/st/libnnengine.so ${OUTPUT_PATH}/plugin/nnengine
cp ${BUILD_PATH}/tests/framework/libnnengine.so ${OUTPUT_PATH}/plugin/nnengine
cp ${BUILD_PATH}/engine_conf.json ${OUTPUT_PATH}/plugin/nnengine/ge_config
cp ${BUILD_PATH}/tests/st/libhost_cpu_engine.so ${OUTPUT_PATH}/plugin/opskernel
cp ${BUILD_PATH}/tests/st/libge_local_engine.so ${OUTPUT_PATH}/plugin/opskernel
cp ${BUILD_PATH}/tests/st/framework/libfe.so ${OUTPUT_PATH}/plugin/opskernel
cp ${BUILD_PATH}/tests/framework/libhost_cpu_engine.so ${OUTPUT_PATH}/plugin/opskernel
cp ${BUILD_PATH}/tests/framework/libge_local_engine.so ${OUTPUT_PATH}/plugin/opskernel
cp ${BUILD_PATH}/tests/framework/stub_engine/libfe.so ${OUTPUT_PATH}/plugin/opskernel
#prepare st execution bin
cp ${BUILD_PATH}/tests/st/testcase/graph_engine_test ${OUTPUT_PATH}
cp ${BUILD_PATH}/tests/framework/ge_graph_dsl/tests/ge_graph_dsl_test ${OUTPUT_PATH}
#execute st testcase
RUN_TEST_CASE=${OUTPUT_PATH}/graph_engine_test && ${RUN_TEST_CASE}
RUN_TEST_CASE=${OUTPUT_PATH}/ge_graph_dsl_test && ${RUN_TEST_CASE}
if [[ "$?" -ne 0 ]]; then
echo "!!! ST FAILED, PLEASE CHECK YOUR CHANGES !!!"
echo -e "\033[31m${RUN_TEST_CASE}\033[0m"


+ 1
- 0
tests/CMakeLists.txt View File

@@ -28,5 +28,6 @@ if (ENABLE_GE_COV OR ENABLE_GE_UT)
endif()

if (ENABLE_GE_ST)
add_subdirectory(framework)
add_subdirectory(st)
endif()

+ 32
- 0
tests/framework/CMakeLists.txt View File

@@ -0,0 +1,32 @@
# Copyright 2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

include(cmake/graphengine.cmake)
add_subdirectory(easy_graph)
add_subdirectory(stub_engine)
add_subdirectory(ge_graph_dsl)

file(GLOB_RECURSE UTILS_SRC CONFIGURE_DEPENDS
"utils/*.cc"
)

add_library(framework STATIC ${UTILS_SRC})

target_include_directories(framework
PUBLIC utils/
)

set_target_properties(framework PROPERTIES CXX_STANDARD 11)
target_link_libraries(framework PUBLIC ge_graph_dsl graphengine fe)

tests/st/cmake/graphengine.cmake → tests/framework/cmake/graphengine.cmake View File


+ 26
- 0
tests/framework/easy_graph/CMakeLists.txt View File

@@ -0,0 +1,26 @@
# Copyright 2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

file(GLOB_RECURSE EASY_GRAPH_SRCS src/*.cc)

add_library(easy_graph STATIC ${EASY_GRAPH_SRCS})

target_link_libraries(easy_graph PUBLIC
$<BUILD_INTERFACE:intf_pub> )

set_target_properties(easy_graph PROPERTIES CXX_STANDARD 17)

target_include_directories(easy_graph PUBLIC include
PRIVATE src)

+ 40
- 0
tests/framework/easy_graph/include/easy_graph/builder/box_builder.h View File

@@ -0,0 +1,40 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HE7D53295_59F0_46B0_A881_D6A33B1F9C14
#define HE7D53295_59F0_46B0_A881_D6A33B1F9C14

#include <type_traits>
#include "easy_graph/graph/box.h"

EG_NS_BEGIN

namespace detail {
template<typename Anything>
struct BoxWrapper : Anything, Box {
using Anything::Anything;
};

template<typename Anything>
using BoxedAnything = std::conditional_t<std::is_base_of_v<Box, Anything>, Anything, BoxWrapper<Anything>>;
} // namespace detail

#define BOX_WRAPPER(Anything) ::EG_NS::detail::BoxedAnything<Anything>
#define BOX_OF(Anything, ...) ::EG_NS::BoxPacking<Anything>(__VA_ARGS__)

EG_NS_END

#endif

+ 81
- 0
tests/framework/easy_graph/include/easy_graph/builder/chain_builder.h View File

@@ -0,0 +1,81 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HDF50E564_F050_476A_A479_F82B20F35C84
#define HDF50E564_F050_476A_A479_F82B20F35C84

#include "easy_graph/builder/link.h"
#include "easy_graph/graph/node_id.h"
#include "easy_graph/graph/node.h"

EG_NS_BEGIN

struct GraphBuilder;
struct Graph;
struct Edge;

struct ChainBuilder {
ChainBuilder(GraphBuilder &graphBuilder, EdgeType defaultEdgeType);

struct LinkBuilder {
using NodeObj = ::EG_NS::Node;
using EdgeObj = ::EG_NS::Edge;

LinkBuilder(ChainBuilder &chain, EdgeType defaultEdgeType);

ChainBuilder &Node(const NodeObj &node);

template<typename... PARAMS>
ChainBuilder &Node(const NodeId &id, const PARAMS &... params) {
auto node = chain_.FindNode(id);
if (node) {
return this->Node(*node);
}
return this->Node(NodeObj(id, params...));
}

ChainBuilder &Ctrl(const std::string &label = "");
ChainBuilder &Data(const std::string &label = "");

ChainBuilder &Data(PortId srcId = UNDEFINED_PORT_ID, PortId dstId = UNDEFINED_PORT_ID,
const std::string &label = "");

ChainBuilder &Edge(EdgeType type, PortId srcId = UNDEFINED_PORT_ID, PortId dstId = UNDEFINED_PORT_ID,
const std::string &label = "");

private:
ChainBuilder &startLink(const Link &);

private:
ChainBuilder &chain_;
EdgeType default_edge_type_;
Link from_link_;
} linker;

LinkBuilder *operator->();

private:
ChainBuilder &LinkTo(const Node &, const Link &);
const Node *FindNode(const NodeId &) const;

private:
Node *prev_node_{nullptr};
GraphBuilder &graph_builder_;
};

EG_NS_END

#endif

+ 64
- 0
tests/framework/easy_graph/include/easy_graph/builder/graph_builder.h View File

@@ -0,0 +1,64 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H5FED5F58_167D_4536_918A_D5FE8F28DD9C
#define H5FED5F58_167D_4536_918A_D5FE8F28DD9C

#include "easy_graph/graph/graph.h"

EG_NS_BEGIN

struct Link;

struct GraphBuilder {
GraphBuilder(const std::string &name);

Node *BuildNode(const Node &);
Edge *BuildEdge(const Node &src, const Node &dst, const Link &);

Graph &operator*() {
return graph_;
}

const Graph &operator*() const {
return graph_;
}

Graph *operator->() {
return &graph_;
}

const Graph *operator->() const {
return &graph_;
}

private:
struct NodeInfo {
PortId inPortMax{0};
PortId outPortMax{0};
};

NodeInfo *FindNode(const NodeId &);
const NodeInfo *FindNode(const NodeId &) const;

private:
std::map<NodeId, NodeInfo> nodes_;
Graph graph_;
};

EG_NS_END

#endif

+ 45
- 0
tests/framework/easy_graph/include/easy_graph/builder/graph_dsl.h View File

@@ -0,0 +1,45 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H46D07001_D54E_497C_B1BA_878A47164DA5
#define H46D07001_D54E_497C_B1BA_878A47164DA5

#include "easy_graph/builder/graph_builder.h"
#include "easy_graph/builder/chain_builder.h"
#include "easy_graph/builder/box_builder.h"
#include "easy_graph/infra/macro_traits.h"

EG_NS_BEGIN

////////////////////////////////////////////////////////////////
namespace detail {
template<typename GRAPH_BUILDER>
Graph BuildGraph(const char *name, GRAPH_BUILDER builderInDSL) {
GraphBuilder builder(name);
builderInDSL(builder);
return std::move(*builder);
}
} // namespace detail

#define HAS_NAME(...) NOT_EMPTY_SELECT(__VA_ARGS__)
#define DEF_GRAPH(G, ...) ::EG_NS::Graph G = ::EG_NS::detail::BuildGraph(HAS_NAME(__VA_ARGS__)(__VA_ARGS__, #G), [&](::EG_NS::GraphBuilder& BUILDER)
#define DATA_CHAIN(...) ::EG_NS::ChainBuilder(BUILDER, ::EG_NS::EdgeType::DATA)->__VA_ARGS__
#define CTRL_CHAIN(...) ::EG_NS::ChainBuilder(BUILDER, ::EG_NS::EdgeType::CTRL)->__VA_ARGS__
#define CHAIN(...) DATA_CHAIN(__VA_ARGS__)

EG_NS_END

#endif

+ 49
- 0
tests/framework/easy_graph/include/easy_graph/builder/link.h View File

@@ -0,0 +1,49 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H35695B82_E9E5_419D_A6B4_C13FB0842C9F
#define H35695B82_E9E5_419D_A6B4_C13FB0842C9F

#include <string>
#include "easy_graph/graph/edge_type.h"
#include "easy_graph/graph/port_id.h"

EG_NS_BEGIN

struct Link {
explicit Link(EdgeType type) : type_(type) {
Reset(type);
}

Link(EdgeType type, const std::string &label, PortId srcPortId, PortId dstPortId)
: type_(type), label_(label), src_port_id_(srcPortId), dst_port_id_(dstPortId) {}

void Reset(EdgeType type) {
this->type_ = type;
this->label_ = "";
this->src_port_id_ = UNDEFINED_PORT_ID;
this->dst_port_id_ = UNDEFINED_PORT_ID;
}

EdgeType type_;
std::string label_;
PortId src_port_id_;
PortId dst_port_id_;
};

EG_NS_END

#endif

+ 29
- 0
tests/framework/easy_graph/include/easy_graph/eg.h View File

@@ -0,0 +1,29 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H04F67145_86B2_4529_BC2E_EBDB2115687E
#define H04F67145_86B2_4529_BC2E_EBDB2115687E

#define EG_NS eg
#define EG_NS_BEGIN namespace EG_NS {
#define EG_NS_END }
#define USING_EG_NS using namespace EG_NS;
#define FWD_DECL_EG(type) \
namespace EG_NS { \
struct type; \
}

#endif

+ 41
- 0
tests/framework/easy_graph/include/easy_graph/graph/box.h View File

@@ -0,0 +1,41 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H4AA49861_3311_4114_8687_1C7D04FA43B9
#define H4AA49861_3311_4114_8687_1C7D04FA43B9

#include <memory>
#include "easy_graph/infra/keywords.h"

EG_NS_BEGIN

INTERFACE(Box){};

using BoxPtr = std::shared_ptr<Box>;

template<typename Anything, typename... Args>
BoxPtr BoxPacking(Args &&... args) {
return std::make_shared<Anything>(std::forward<Args>(args)...);
}

template<typename Anything>
Anything *BoxUnpacking(const BoxPtr &box) {
return dynamic_cast<Anything *>(box.get());
}

EG_NS_END

#endif

+ 46
- 0
tests/framework/easy_graph/include/easy_graph/graph/edge.h View File

@@ -0,0 +1,46 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HE62943BF_1F7C_4EF9_B306_D9C94634EA74
#define HE62943BF_1F7C_4EF9_B306_D9C94634EA74

#include <string>
#include "easy_graph/graph/edge_type.h"
#include "easy_graph/graph/endpoint.h"

EG_NS_BEGIN

struct Edge {
Edge(const EdgeType type, const std::string &label, const Endpoint &src, const Endpoint &dst);

__DECL_COMP(Edge);

EdgeType GetType() const;
std::string GetLabel() const;

Endpoint GetSrc() const;
Endpoint GetDst() const;

private:
std::string label_;
EdgeType type_;
Endpoint src_;
Endpoint dst_;
};

EG_NS_END

#endif

+ 31
- 0
tests/framework/easy_graph/include/easy_graph/graph/edge_type.h View File

@@ -0,0 +1,31 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H19D3F004_119F_4E6A_ACFA_A635FD6FEA98
#define H19D3F004_119F_4E6A_ACFA_A635FD6FEA98

#include "easy_graph/eg.h"

EG_NS_BEGIN

enum class EdgeType {
CTRL = 0,
DATA,
};

EG_NS_END

#endif

+ 41
- 0
tests/framework/easy_graph/include/easy_graph/graph/endpoint.h View File

@@ -0,0 +1,41 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H8DB48A37_3257_4E15_8869_09E58221ADE8
#define H8DB48A37_3257_4E15_8869_09E58221ADE8

#include "easy_graph/graph/node_id.h"
#include "easy_graph/graph/port_id.h"
#include "easy_graph/infra/operator.h"

EG_NS_BEGIN

struct Endpoint {
Endpoint(const NodeId &, const PortId &);

__DECL_COMP(Endpoint);

NodeId getNodeId() const;
PortId getPortId() const;

private:
NodeId node_id_;
PortId port_id_;
};

EG_NS_END

#endif

+ 58
- 0
tests/framework/easy_graph/include/easy_graph/graph/graph.h View File

@@ -0,0 +1,58 @@
#ifndef H813EC8C1_3850_4320_8AC0_CE071C89B871
#define H813EC8C1_3850_4320_8AC0_CE071C89B871

#include "easy_graph/graph/node.h"
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/graph/edge.h"
#include "easy_graph/infra/status.h"
#include <string>
#include <set>
#include <map>

EG_NS_BEGIN

struct GraphVisitor;
struct LayoutOption;

struct Graph {
explicit Graph(const std::string &name);

std::string GetName() const;

Node *AddNode(const Node &);
Edge *AddEdge(const Edge &);

Node *FindNode(const NodeId &);
const Node *FindNode(const NodeId &) const;

std::pair<const Node *, const Node *> FindNodePair(const Edge &) const;
std::pair<Node *, Node *> FindNodePair(const Edge &);

void Accept(GraphVisitor &) const;

Status Layout(const LayoutOption *option = nullptr) const;

private:
std::string name_;
std::map<NodeId, Node> nodes_;
std::set<Edge> edges_;
};

EG_NS_END

#endif

+ 37
- 0
tests/framework/easy_graph/include/easy_graph/graph/graph_visitor.h View File

@@ -0,0 +1,37 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H13960AED_B5B1_45F9_A664_6CB6C15CA3C1
#define H13960AED_B5B1_45F9_A664_6CB6C15CA3C1

#include "easy_graph/infra/keywords.h"
#include "easy_graph/infra/status.h"

EG_NS_BEGIN

struct Graph;
struct Node;
struct Edge;

INTERFACE(GraphVisitor) {
DEFAULT(Status, Visit(const Graph &));
DEFAULT(Status, Visit(const Node &));
DEFAULT(Status, Visit(const Edge &));
};

EG_NS_END

#endif

+ 62
- 0
tests/framework/easy_graph/include/easy_graph/graph/node.h View File

@@ -0,0 +1,62 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HF37ACE88_F726_4AA3_8599_ED7A888AA623
#define HF37ACE88_F726_4AA3_8599_ED7A888AA623

#include <vector>
#include "easy_graph/graph/node_id.h"
#include "easy_graph/infra/operator.h"
#include "easy_graph/infra/ext_traits.h"
#include "easy_graph/graph/box.h"

EG_NS_BEGIN

struct GraphVisitor;
struct Graph;

struct Node {
template<typename... GRAPHS, SUBGRAPH_CONCEPT(GRAPHS, Graph)>
Node(const NodeId &id, const GRAPHS &... graphs) : id_(id), subgraphs_{&graphs...} {}

template<typename... GRAPHS, SUBGRAPH_CONCEPT(GRAPHS, Graph)>
Node(const NodeId &id, const BoxPtr &box, const GRAPHS &... graphs) : id_(id), box_(box), subgraphs_{&graphs...} {}

__DECL_COMP(Node);

NodeId GetId() const;

Node &Packing(const BoxPtr &);

template<typename Anything>
Anything *Unpacking() const {
if (!box_)
return nullptr;
return BoxUnpacking<Anything>(box_);
}

Node &AddSubgraph(const Graph &);
void Accept(GraphVisitor &) const;

private:
NodeId id_;
BoxPtr box_;
std::vector<const Graph *> subgraphs_;
};

EG_NS_END

#endif

tests/st/framework/framework.h → tests/framework/easy_graph/include/easy_graph/graph/node_id.h View File

@@ -1,22 +1,29 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
*/

#ifndef HB53D0830_615F_4E4A_8531_77E2A177717D
#define HB53D0830_615F_4E4A_8531_77E2A177717D

#ifndef GRAPHENGINE_LLT_ST_FRAMEWORK_H_
#define GRAPHENGINE_LLT_ST_FRAMEWORK_H_
#include <string>
#include "common/ge_inner_error_codes.h"
#include "easy_graph/eg.h"

EG_NS_BEGIN

typedef std::string NodeId;

EG_NS_END

#endif // GRAPHENGINE_LLT_ST_FRAMEWORK_H_
#endif

+ 30
- 0
tests/framework/easy_graph/include/easy_graph/graph/port_id.h View File

@@ -0,0 +1,30 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HC8732748_F658_4759_9284_CC13C0BFE6D4
#define HC8732748_F658_4759_9284_CC13C0BFE6D4

#include "easy_graph/eg.h"

EG_NS_BEGIN

typedef unsigned int PortId;

static const PortId UNDEFINED_PORT_ID = 0xFFFFFFFF;

EG_NS_END

#endif

+ 59
- 0
tests/framework/easy_graph/include/easy_graph/infra/default.h View File

@@ -0,0 +1,59 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H05B2224D_B926_4FC0_A936_77B52B8A98DB
#define H05B2224D_B926_4FC0_A936_77B52B8A98DB

#include "easy_graph/eg.h"

EG_NS_BEGIN

namespace details {
template<typename T>
struct DefaultValue {
static T value() {
return T();
}
};

template<typename T>
struct DefaultValue<T *> {
static T *value() {
return 0;
}
};

template<typename T>
struct DefaultValue<const T *> {
static T *value() {
return 0;
}
};

template<>
struct DefaultValue<void> {
static void value() {}
};
} // namespace details

#define DEFAULT(type, method) \
virtual type method { \
return ::EG_NS::details::DefaultValue<type>::value(); \
}

EG_NS_END

#endif

+ 39
- 0
tests/framework/easy_graph/include/easy_graph/infra/ext_traits.h View File

@@ -0,0 +1,39 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HF25A2E8D_A775_44BF_88D1_166DFF56186A
#define HF25A2E8D_A775_44BF_88D1_166DFF56186A

#include <type_traits>
#include "easy_graph/eg.h"

EG_NS_BEGIN

template<typename T, typename... TS>
using all_same_traits = typename std::enable_if<std::conjunction<std::is_same<T, TS>...>::value>::type;

template<typename T, typename... TS>
using all_same_but_none_traits = typename std::enable_if<
std::disjunction<std::bool_constant<not(sizeof...(TS))>, std::conjunction<std::is_same<T, TS>...>>::value>::type;

#define ALL_SAME_CONCEPT(TS, T) all_same_traits<T, TS...> * = nullptr
#define ALL_SAME_BUT_NONE_CONCEPT(TS, T) ::EG_NS::all_same_but_none_traits<T, TS...> * = nullptr

#define SUBGRAPH_CONCEPT(GS, G) ALL_SAME_BUT_NONE_CONCEPT(GS, G)

EG_NS_END

#endif

+ 42
- 0
tests/framework/easy_graph/include/easy_graph/infra/keywords.h View File

@@ -0,0 +1,42 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H05B2224D_B926_4FC0_A936_97B52B8A98DB
#define H05B2224D_B926_4FC0_A936_97B52B8A98DB

#include "easy_graph/infra/default.h"

EG_NS_BEGIN

namespace details {
template<typename T>
struct Interface {
virtual ~Interface() {}
};
} // namespace details

#define INTERFACE(Intf) struct Intf : ::EG_NS::details::Interface<Intf>

#define ABSTRACT(...) virtual __VA_ARGS__ = 0

#define OVERRIDE(...) virtual __VA_ARGS__ override

#define EXTENDS(...) , ##__VA_ARGS__
#define IMPLEMENTS(...) EXTENDS(__VA_ARGS__)

EG_NS_END

#endif

+ 64
- 0
tests/framework/easy_graph/include/easy_graph/infra/log.h View File

@@ -0,0 +1,64 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H38247538_297F_4A80_94D3_8A289788461B
#define H38247538_297F_4A80_94D3_8A289788461B

#include "easy_graph/eg.h"

EG_NS_BEGIN

enum EgLogLevel {
EG_NONE_LEVEL = 0x0,
EG_DEBUG_LEVEL = 0x01,
EG_INFO_LEVEL = 0x02,
EG_SUCC_LEVEL = 0x04,
EG_WARN_LEVEL = 0x08,
EG_ERR_LEVEL = 0x10,
EG_FATAL_LEVEL = 0x20,
EG_TOTAL_LEVEL = 0xFF
};

#define EG_LOG_LEVELS (EG_FATAL_LEVEL | EG_ERR_LEVEL | EG_WARN_LEVEL | EG_INFO_LEVEL)

/////////////////////////////////////////////////////////////////

void eg_log(int level, const char *levelstr, const char *file, unsigned int line, const char *fmt, ...);

#define EG_LOG_OUTPUT eg_log

#define __EG_LOG_TITLE(level, levelstr, fmt, ...) \
do { \
if (level & EG_LOG_LEVELS) { \
EG_LOG_OUTPUT(level, levelstr, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
} \
} while (0)

#define EG_FATAL(fmt, ...) __EG_LOG_TITLE(EG_FATAL_LEVEL, "FATAL", fmt, ##__VA_ARGS__)

#define EG_ERR(fmt, ...) __EG_LOG_TITLE(EG_ERR_LEVEL, "ERROR", fmt, ##__VA_ARGS__)

#define EG_WARN(fmt, ...) __EG_LOG_TITLE(EG_WARN_LEVEL, "WARN", fmt, ##__VA_ARGS__)

#define EG_SUCC(fmt, ...) __EG_LOG_TITLE(EG_SUCC_LEVEL, "SUCC", fmt, ##__VA_ARGS__)

#define EG_INFO(fmt, ...) __EG_LOG_TITLE(EG_INFO_LEVEL, "INFO", fmt, ##__VA_ARGS__)

#define EG_DBG(fmt, ...) __EG_LOG_TITLE(EG_DEBUG_LEVEL, "DEBUG", fmt, ##__VA_ARGS__)

EG_NS_END

#endif

+ 58
- 0
tests/framework/easy_graph/include/easy_graph/infra/macro_traits.h View File

@@ -0,0 +1,58 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H7DA4A075_246A_4DD6_B1BB_ECA3806C9483
#define H7DA4A075_246A_4DD6_B1BB_ECA3806C9483

#include "easy_graph/eg.h"

EG_NS_BEGIN

////////////////////////////////////////////////////////////////////////

#define VA_ARGS_NUM(...) \
VA_ARGS_NUM_PRIVATE(0, ##__VA_ARGS__, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, \
45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, \
21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

#define VA_ARGS_NUM_PRIVATE(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \
_20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, \
_38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, \
_56, _57, _58, _59, _60, _61, _62, _63, _64, N, ...) \
N

////////////////////////////////////////////////////////////////////////

#define __MACRO_CONCAT(x, y) x##y
#define MACRO_CONCAT(x, y) __MACRO_CONCAT(x, y)

#define __MACRO_SECOND(FIRST, SECOND, ...) SECOND
#define MACRO_SECOND(...) __MACRO_SECOND(__VA_ARGS__)

#define MACRO_VERIFY_FIRST(...) MACRO_SECOND(__VA_ARGS__, 1)

#define MACRO_BOOL_0 MACRO_DUMMY, 0
#define MACRO_BOOL(N) MACRO_VERIFY_FIRST(__MACRO_CONCAT(MACRO_BOOL_, N))

#define MACRO_CONDITION_0(TRUE_BRANCH, FALSE_BRANCH) FALSE_BRANCH
#define MACRO_CONDITION_1(TRUE_BRANCH, FALSE_BRANCH) TRUE_BRANCH
#define MACRO_CONDITION(N) MACRO_CONCAT(MACRO_CONDITION_, MACRO_BOOL(N))

#define NOT_EMPTY_SELECT(...) MACRO_CONDITION(VA_ARGS_NUM(__VA_ARGS__))

EG_NS_END

#endif

+ 68
- 0
tests/framework/easy_graph/include/easy_graph/infra/operator.h View File

@@ -0,0 +1,68 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H05B2224D_B927_4FC0_A936_97B52B8A99DB
#define H05B2224D_B927_4FC0_A936_97B52B8A99DB

//////////////////////////////////////////////////////////////
#define __DECL_EQUALS(cls) \
bool operator!=(const cls &rhs) const; \
bool operator==(const cls &rhs) const

//////////////////////////////////////////////////////////////
#define __FIELD_EQ(name) this->name == rhs.name
#define __FIELD_LT(name) this->name < rhs.name

//////////////////////////////////////////////////////////////
#define __SUPER_EQ(super) static_cast<const super &>(*this) == rhs
#define __SUPER_LT(super) static_cast<const super &>(*this) < rhs

//////////////////////////////////////////////////////////////
#define __DEF_EQUALS(cls) \
bool cls::operator!=(const cls &rhs) const { \
return !(*this == rhs); \
} \
bool cls::operator==(const cls &rhs) const

/////////////////////////////////////////////////////////////
#define __INLINE_EQUALS(cls) \
bool operator!=(const cls &rhs) const { \
return !(*this == rhs); \
} \
bool operator==(const cls &rhs) const

/////////////////////////////////////////////////////////////
#define __DECL_COMP(cls) \
__DECL_EQUALS(cls); \
bool operator<(const cls &) const; \
bool operator>(const cls &) const; \
bool operator<=(const cls &) const; \
bool operator>=(const cls &) const

/////////////////////////////////////////////////////////////
#define __DEF_COMP(cls) \
bool cls::operator>(const cls &rhs) const { \
return !(*this <= rhs); \
} \
bool cls::operator>=(const cls &rhs) const { \
return !(*this < rhs); \
} \
bool cls::operator<=(const cls &rhs) const { \
return (*this < rhs) || (*this == rhs); \
} \
bool cls::operator<(const cls &rhs) const

#endif

+ 41
- 0
tests/framework/easy_graph/include/easy_graph/infra/scope_guard.h View File

@@ -0,0 +1,41 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H187A4A00_BD91_4B9D_8DD9_3D6C9EA15854
#define H187A4A00_BD91_4B9D_8DD9_3D6C9EA15854

#include "easy_graph/eg.h"

EG_NS_BEGIN

template<typename BEGIN, typename END>
struct ScopeGuard {
ScopeGuard(BEGIN begin, END end) : begin(begin), end(end) {
begin();
}

~ScopeGuard() {
end();
}

private:
BEGIN begin;
END end;
};

EG_NS_END

#endif

+ 42
- 0
tests/framework/easy_graph/include/easy_graph/infra/singleton.h View File

@@ -0,0 +1,42 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HD18A3E42_2801_4BEB_B365_03633D1D81C4
#define HD18A3E42_2801_4BEB_B365_03633D1D81C4

#include "easy_graph/eg.h"

EG_NS_BEGIN

template<typename T>
struct Singleton {
static T &GetInstance() {
static T instance;
return instance;
}

Singleton(const Singleton &) = delete;
Singleton &operator=(const Singleton &) = delete;

protected:
Singleton() {}
};

#define SINGLETON(object) struct object : ::EG_NS::Singleton<object>

EG_NS_END

#endif

+ 55
- 0
tests/framework/easy_graph/include/easy_graph/infra/status.h View File

@@ -0,0 +1,55 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HA25033D6_1564_4748_B2C8_4DE2C5A286DE
#define HA25033D6_1564_4748_B2C8_4DE2C5A286DE

#include <stdbool.h>
#include <stdint.h>
#include "easy_graph/eg.h"

EG_NS_BEGIN

typedef uint32_t Status;

#define EG_SUCC_STATUS(status) (EG_NS::Status) status
#define EG_FAIL_STATUS(status) (EG_NS::Status)(status | EG_RESERVED_FAIL)

/* OK */
#define EG_SUCCESS EG_SUCC_STATUS(0)

/* Error Status */
#define EG_RESERVED_FAIL (EG_NS::Status) 0x80000000
#define EG_FAILURE EG_FAIL_STATUS(1)
#define EG_FATAL_BUG EG_FAIL_STATUS(2)
#define EG_TIMEDOUT EG_FAIL_STATUS(3)
#define EG_OUT_OF_RANGE EG_FAIL_STATUS(4)
#define EG_UNIMPLEMENTED EG_FAIL_STATUS(5)

static inline bool eg_status_is_ok(Status status) {
return (status & EG_RESERVED_FAIL) == 0;
}

static inline bool eg_status_is_fail(Status status) {
return !eg_status_is_ok(status);
}

#define __EG_FAILED(result) eg_status_is_fail(result)
#define __EG_OK(result) eg_status_is_ok(result)

EG_NS_END

#endif

+ 31
- 0
tests/framework/easy_graph/include/easy_graph/layout/engines/graph_easy/graph_easy_executor.h View File

@@ -0,0 +1,31 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HAC96EB3A_2169_4BB0_A8EB_7B966C262B2F
#define HAC96EB3A_2169_4BB0_A8EB_7B966C262B2F

#include "easy_graph/layout/layout_executor.h"

EG_NS_BEGIN

struct GraphEasyExecutor : LayoutExecutor {
private:
Status Layout(const Graph &, const LayoutOption *) override;
};

EG_NS_END

#endif

+ 53
- 0
tests/framework/easy_graph/include/easy_graph/layout/engines/graph_easy/graph_easy_layout_context.h View File

@@ -0,0 +1,53 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HB8CC77BE_6A2E_4EB4_BE59_CA85DE56C027
#define HB8CC77BE_6A2E_4EB4_BE59_CA85DE56C027

#include "easy_graph/eg.h"
#include <string>
#include <deque>

EG_NS_BEGIN

struct GraphEasyOption;
struct Graph;

struct GraphEasyLayoutContext {
GraphEasyLayoutContext(const GraphEasyOption &);

const Graph *GetCurrentGraph() const;

void EnterGraph(const Graph &);
void ExitGraph();

void LinkBegin();
void LinkEnd();

bool InLinking() const;

std::string GetGroupPath() const;
const GraphEasyOption &GetOptions() const;

private:
std::deque<const Graph *> graphs_;
const GraphEasyOption &options_;
bool is_linking_{false};
};

EG_NS_END

#endif

+ 63
- 0
tests/framework/easy_graph/include/easy_graph/layout/engines/graph_easy/graph_easy_option.h View File

@@ -0,0 +1,63 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H37156CC2_92BD_44DA_8DA7_A11629E762BE
#define H37156CC2_92BD_44DA_8DA7_A11629E762BE

#include "easy_graph/layout/layout_option.h"
#include <string>

EG_NS_BEGIN

enum class FlowDir {
LR = 0,
TB,
};

enum class LayoutType {
FREE = 0,
REGULAR,
};

enum class LayoutFormat {
ASCII = 0,
BOXART,
SVG,
DOT,
HTML,
};

enum class LayoutOutput {
CONSOLE = 0,
FILE,
};

struct GraphEasyOption : LayoutOption {
static const GraphEasyOption &GetDefault();

std::string GetLayoutCmdArgs(const std::string &graphName) const;

LayoutFormat format_{LayoutFormat::BOXART};
LayoutOutput output_{LayoutOutput::CONSOLE};
FlowDir dir_{FlowDir::LR};
LayoutType type_{LayoutType::FREE};
size_t scale_{1};
std::string output_path_{"./"};
};

EG_NS_END

#endif

+ 45
- 0
tests/framework/easy_graph/include/easy_graph/layout/engines/graph_easy/graph_easy_visitor.h View File

@@ -0,0 +1,45 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HB6783151_C24E_4DA3_B969_46C2298FF43F
#define HB6783151_C24E_4DA3_B969_46C2298FF43F

#include <string>
#include "easy_graph/graph/graph_visitor.h"
#include "easy_graph/layout/engines/graph_easy/graph_easy_layout_context.h"

EG_NS_BEGIN

struct GraphEasyOption;

struct GraphEasyVisitor : GraphVisitor {
GraphEasyVisitor(const GraphEasyOption &);

std::string GetLayout() const;

private:
Status Visit(const Graph &) override;
Status Visit(const Node &) override;
Status Visit(const Edge &) override;

private:
std::string layout_;
GraphEasyLayoutContext ctxt_;
};

EG_NS_END

#endif

+ 40
- 0
tests/framework/easy_graph/include/easy_graph/layout/graph_layout.h View File

@@ -0,0 +1,40 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H550E4ACB_BEC7_4E71_8C6F_CD7FA53662A9
#define H550E4ACB_BEC7_4E71_8C6F_CD7FA53662A9

#include "easy_graph/infra/status.h"
#include "easy_graph/infra/singleton.h"

EG_NS_BEGIN

struct LayoutExecutor;
struct LayoutOption;
struct Graph;

SINGLETON(GraphLayout) {
void Config(LayoutExecutor &, const LayoutOption * = nullptr);
Status Layout(const Graph &, const LayoutOption * = nullptr);

private:
LayoutExecutor *executor_{nullptr};
const LayoutOption *options_{nullptr};
};

EG_NS_END

#endif

+ 34
- 0
tests/framework/easy_graph/include/easy_graph/layout/layout_executor.h View File

@@ -0,0 +1,34 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HE4984335_C586_4533_A056_27F9F996DF50
#define HE4984335_C586_4533_A056_27F9F996DF50

#include "easy_graph/infra/status.h"
#include "easy_graph/infra/keywords.h"

EG_NS_BEGIN

struct Graph;
struct LayoutOption;

INTERFACE(LayoutExecutor) {
ABSTRACT(Status Layout(const Graph &, const LayoutOption *));
};

EG_NS_END

#endif

+ 28
- 0
tests/framework/easy_graph/include/easy_graph/layout/layout_option.h View File

@@ -0,0 +1,28 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H9491820D_4371_4C88_804E_4C77613F80C1
#define H9491820D_4371_4C88_804E_4C77613F80C1

#include "easy_graph/infra/keywords.h"

EG_NS_BEGIN

INTERFACE(LayoutOption){};

EG_NS_END

#endif

+ 72
- 0
tests/framework/easy_graph/src/builder/chain_builder.cc View File

@@ -0,0 +1,72 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/builder/chain_builder.h"
#include "easy_graph/builder/graph_builder.h"

EG_NS_BEGIN

ChainBuilder::ChainBuilder(GraphBuilder &graphBuilder, EdgeType defaultEdgeType)
: linker(*this, defaultEdgeType), graph_builder_(graphBuilder) {}

ChainBuilder::LinkBuilder *ChainBuilder::operator->() {
return &linker;
}

ChainBuilder &ChainBuilder::LinkTo(const Node &node, const Link &link) {
Node *currentNode = graph_builder_.BuildNode(node);
if (prev_node_) {
graph_builder_.BuildEdge(*prev_node_, *currentNode, link);
}
prev_node_ = currentNode;
return *this;
}

const Node *ChainBuilder::FindNode(const NodeId &id) const {
return graph_builder_->FindNode(id);
}

ChainBuilder::LinkBuilder::LinkBuilder(ChainBuilder &chain, EdgeType defaultEdgeType)
: chain_(chain), default_edge_type_(defaultEdgeType), from_link_(defaultEdgeType) {}

ChainBuilder &ChainBuilder::LinkBuilder::Node(const NodeObj &node) {
chain_.LinkTo(node, from_link_);
from_link_.Reset(default_edge_type_);
return chain_;
}

ChainBuilder &ChainBuilder::LinkBuilder::startLink(const Link &link) {
this->from_link_ = link;
return chain_;
}

ChainBuilder &ChainBuilder::LinkBuilder::Ctrl(const std::string &label) {
return this->Edge(EdgeType::CTRL, UNDEFINED_PORT_ID, UNDEFINED_PORT_ID, label);
}

ChainBuilder &ChainBuilder::LinkBuilder::Data(const std::string &label) {
return this->Edge(EdgeType::DATA, UNDEFINED_PORT_ID, UNDEFINED_PORT_ID, label);
}

ChainBuilder &ChainBuilder::LinkBuilder::Data(PortId srcId, PortId dstId, const std::string &label) {
return this->Edge(EdgeType::DATA, srcId, dstId, label);
}

ChainBuilder &ChainBuilder::LinkBuilder::Edge(EdgeType type, PortId srcPort, PortId dstPort, const std::string &label) {
return this->startLink(Link(type, label, srcPort, dstPort));
}

EG_NS_END

+ 78
- 0
tests/framework/easy_graph/src/builder/graph_builder.cc View File

@@ -0,0 +1,78 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/builder/graph_builder.h"
#include "easy_graph/graph/endpoint.h"
#include "easy_graph/builder/link.h"
#include "easy_graph/infra/log.h"

EG_NS_BEGIN

namespace {
PortId getPortIdBy(const EdgeType &type, const PortId &specifiedPortId, PortId &reservedPortId) {
if (type == EdgeType::CTRL)
return 0;
if (specifiedPortId == UNDEFINED_PORT_ID)
return reservedPortId++;
if (specifiedPortId < reservedPortId)
return specifiedPortId;
reservedPortId = specifiedPortId;
return reservedPortId++;
}
} // namespace

GraphBuilder::GraphBuilder(const std::string &name) : graph_(name) {}

GraphBuilder::NodeInfo *GraphBuilder::FindNode(const NodeId &id) {
auto it = nodes_.find(id);
if (it == nodes_.end()) {
return nullptr;
}
return &(it->second);
}

const GraphBuilder::NodeInfo *GraphBuilder::FindNode(const NodeId &id) const {
return const_cast<GraphBuilder &>(*this).FindNode(id);
}

Node *GraphBuilder::BuildNode(const Node &node) {
auto it = nodes_.find(node.GetId());
if (it == nodes_.end()) {
nodes_.emplace(std::make_pair(node.GetId(), NodeInfo()));
}
return graph_.AddNode(node);
}

Edge *GraphBuilder::BuildEdge(const Node &src, const Node &dst, const Link &link) {
NodeInfo *srcInfo = FindNode(src.GetId());
NodeInfo *dstInfo = FindNode(dst.GetId());

if (!srcInfo || !dstInfo) {
EG_ERR("link edge{%d : %s} error!", link.type_, link.label_.c_str());
return nullptr;
}

PortId srcPortId = getPortIdBy(link.type_, link.src_port_id_, srcInfo->outPortMax);
PortId dstPortId = getPortIdBy(link.type_, link.dst_port_id_, dstInfo->inPortMax);

EG_DBG("link edge(%d) from (%s:%d) to (%s:%d)", link.type_, src.GetId().c_str(), srcPortId, dst.GetId().c_str(),
dstPortId);

return graph_.AddEdge(
Edge(link.type_, link.label_, Endpoint(src.GetId(), srcPortId), Endpoint(dst.GetId(), dstPortId)));
}

EG_NS_END

+ 53
- 0
tests/framework/easy_graph/src/graph/edge.cc View File

@@ -0,0 +1,53 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/graph/edge.h"

EG_NS_BEGIN

Edge::Edge(const EdgeType type, const std::string &label, const Endpoint &src, const Endpoint &dst)
: type_(type), label_(label), src_(src), dst_(dst) {}

__DEF_EQUALS(Edge) {
return (type_ == rhs.type_) && (src_ == rhs.src_) && (dst_ == rhs.dst_);
}

__DEF_COMP(Edge) {
if (src_ < rhs.src_)
return true;
if ((src_ == rhs.src_) && (dst_ < rhs.dst_))
return true;
if ((src_ == rhs.src_) && (dst_ < rhs.dst_) && (type_ < rhs.type_))
return true;
return false;
}

EdgeType Edge::GetType() const {
return type_;
}

std::string Edge::GetLabel() const {
return label_;
}

Endpoint Edge::GetSrc() const {
return src_;
}
Endpoint Edge::GetDst() const {
return dst_;
}

EG_NS_END

+ 43
- 0
tests/framework/easy_graph/src/graph/endpoint.cc View File

@@ -0,0 +1,43 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/graph/endpoint.h"

EG_NS_BEGIN

Endpoint::Endpoint(const NodeId &nodeId, const PortId &portId) : node_id_(nodeId), port_id_(portId) {}

__DEF_EQUALS(Endpoint) {
return (node_id_ == rhs.node_id_) && (port_id_ == rhs.port_id_);
}

__DEF_COMP(Endpoint) {
if (node_id_ < rhs.node_id_)
return true;
if ((node_id_ == rhs.node_id_) && (port_id_ < rhs.port_id_))
return true;
return false;
}

NodeId Endpoint::getNodeId() const {
return node_id_;
}

PortId Endpoint::getPortId() const {
return port_id_;
}

EG_NS_END

+ 70
- 0
tests/framework/easy_graph/src/graph/graph.cc View File

@@ -0,0 +1,70 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/graph/graph.h"
#include "easy_graph/graph/graph_visitor.h"
#include "easy_graph/layout/graph_layout.h"
#include <algorithm>

EG_NS_BEGIN

Graph::Graph(const std::string &name) : name_(name) {}

std::string Graph::GetName() const {
return name_;
}

Node *Graph::AddNode(const Node &node) {
auto result = nodes_.emplace(node.GetId(), node);
return &(result.first->second);
}

Edge *Graph::AddEdge(const Edge &edge) {
auto result = edges_.emplace(edge);
return &(const_cast<Edge &>(*(result.first)));
}

Node *Graph::FindNode(const NodeId &id) {
auto it = nodes_.find(id);
if (it == nodes_.end()) {
return nullptr;
}
return &(it->second);
}

const Node *Graph::FindNode(const NodeId &id) const {
return const_cast<Graph &>(*this).FindNode(id);
}

std::pair<const Node *, const Node *> Graph::FindNodePair(const Edge &edge) const {
return std::make_pair(FindNode(edge.GetSrc().getNodeId()), FindNode(edge.GetDst().getNodeId()));
}

std::pair<Node *, Node *> Graph::FindNodePair(const Edge &edge) {
return std::make_pair(FindNode(edge.GetSrc().getNodeId()), FindNode(edge.GetDst().getNodeId()));
}

void Graph::Accept(GraphVisitor &visitor) const {
visitor.Visit(*this);
std::for_each(nodes_.begin(), nodes_.end(), [&visitor](const auto &node) { visitor.Visit(node.second); });
std::for_each(edges_.begin(), edges_.end(), [&visitor](const auto &edge) { visitor.Visit(edge); });
}

Status Graph::Layout(const LayoutOption *option) const {
return GraphLayout::GetInstance().Layout(*this, option);
}

EG_NS_END

+ 49
- 0
tests/framework/easy_graph/src/graph/node.cc View File

@@ -0,0 +1,49 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/graph/node.h"
#include "easy_graph/graph/graph_visitor.h"
#include <algorithm>

EG_NS_BEGIN

__DEF_EQUALS(Node) {
return id_ == rhs.id_;
}

__DEF_COMP(Node) {
return id_ < rhs.id_;
}

NodeId Node::GetId() const {
return id_;
}

Node &Node::Packing(const BoxPtr &box) {
this->box_ = box;
return *this;
}

Node &Node::AddSubgraph(const Graph &graph) {
subgraphs_.push_back(&graph);
return *this;
}

void Node::Accept(GraphVisitor &visitor) const {
std::for_each(subgraphs_.begin(), subgraphs_.end(), [&visitor](const auto &graph) { visitor.Visit(*graph); });
}

EG_NS_END

+ 138
- 0
tests/framework/easy_graph/src/infra/log.cc View File

@@ -0,0 +1,138 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <iostream>
#include <string.h>
#include <stdarg.h>
#include "easy_graph/infra/log.h"

EG_NS_BEGIN

namespace {
struct ConsoleState {
bool isColorful() const {
return colorful;
}

protected:
ConsoleState(bool c) : colorful(c) {}

private:
bool colorful;
};

////////////////////////////////////////////////////////
#define DEF_COLOR_STATE(STATE, COLOR) \
struct STATE : ConsoleState { \
STATE(bool colorful) : ConsoleState(colorful) {} \
}; \
std::ostream &operator<<(std::ostream &os, const STATE &state) { \
if (state.isColorful()) \
os << COLOR; \
return os; \
}

////////////////////////////////////////////////////////
#define __RED "\033[1;31m"
#define __GREEN "\033[1;32m"
#define __YELLOW "\033[1;33m"
#define __BLUE "\033[1;34m"
#define __MAGENTA "\033[1;35m"
#define __CYAN "\033[1;36m"
#define __WHITE "\033[0m"

DEF_COLOR_STATE(DebugState, __BLUE)
DEF_COLOR_STATE(InfoState, __CYAN)
DEF_COLOR_STATE(NormalState, __WHITE)
DEF_COLOR_STATE(SuccState, __GREEN)
DEF_COLOR_STATE(WarnState, __YELLOW)
DEF_COLOR_STATE(FailState, __RED)

///////////////////////////////////////////////////////
struct StdoutListener;
StdoutListener *inst = nullptr;

struct StdoutListener {
static StdoutListener &getInstance() {
if (inst == 0) {
inst = new StdoutListener(true);
}

return *inst;
}

void println(const uint8_t level, const char *msg) {
#define ON_LEVEL(level, state) \
case level: \
doPrint(state, msg); \
break;

switch (level) {
ON_LEVEL(EG_FATAL_LEVEL, fail)
ON_LEVEL(EG_ERR_LEVEL, fail)
ON_LEVEL(EG_WARN_LEVEL, warn)
ON_LEVEL(EG_SUCC_LEVEL, succ)
ON_LEVEL(EG_INFO_LEVEL, info)
ON_LEVEL(EG_DEBUG_LEVEL, debug)
default:
doPrint(normal, msg);
}
}

private:
StdoutListener(bool colorful)
: succ(colorful), fail(colorful), normal(colorful), info(colorful), warn(colorful), debug(colorful) {}

template<typename STATE>
void doPrint(const STATE &state, const char *msg) {
std::cout << state << msg << normal << std::endl;
}

private:
SuccState succ;
FailState fail;
NormalState normal;
InfoState info;
WarnState warn;
DebugState debug;
};

const char *getBaseName(const char *absPath) {
if (absPath == 0)
return "";
const char *p = absPath + strlen(absPath);
while ((p != absPath) && (*(p - 1) != '/')) {
p--;
}
return p;
}

} // namespace

void eg_log(int level, const char *levelstr, const char *file, unsigned int line, const char *fmt, ...) {
const int FMT_BUFF_SIZE = 1024;
char fmt_buff[FMT_BUFF_SIZE] = {0};
va_list valist;
va_start(valist, fmt);
vsnprintf(fmt_buff, FMT_BUFF_SIZE, fmt, valist);
va_end(valist);

char buff[1280] = {0};
sprintf(buff, "[%s]: %s:%u: %s", levelstr, getBaseName(file), line, fmt_buff);
StdoutListener::getInstance().println(level, buff);
}

EG_NS_END

+ 47
- 0
tests/framework/easy_graph/src/layout/engines/graph_easy/graph_easy_executor.cc View File

@@ -0,0 +1,47 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/layout/engines/graph_easy/graph_easy_executor.h"
#include "easy_graph/layout/engines/graph_easy/graph_easy_visitor.h"
#include "easy_graph/layout/engines/graph_easy/graph_easy_option.h"
#include "layout/engines/graph_easy/utils/shell_executor.h"
#include "easy_graph/layout/layout_option.h"
#include "easy_graph/graph/graph.h"

EG_NS_BEGIN

namespace {
const GraphEasyOption *GraphEasyOptionCast(const LayoutOption *opts) {
if (!opts)
return &(GraphEasyOption::GetDefault());
auto options = dynamic_cast<const GraphEasyOption *>(opts);
if (options)
return options;
return &(GraphEasyOption::GetDefault());
}
} // namespace

Status GraphEasyExecutor::Layout(const Graph &graph, const LayoutOption *opts) {
auto options = GraphEasyOptionCast(opts);
GraphEasyVisitor visitor(*options);
graph.Accept(visitor);

std::string script =
std::string("echo \"") + visitor.GetLayout() + "\" | graph-easy " + options->GetLayoutCmdArgs(graph.GetName());
return ShellExecutor::execute(script);
}

EG_NS_END

+ 65
- 0
tests/framework/easy_graph/src/layout/engines/graph_easy/graph_easy_layout_context.cc View File

@@ -0,0 +1,65 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <algorithm>
#include "easy_graph/layout/engines/graph_easy/graph_easy_layout_context.h"
#include "easy_graph/layout/engines/graph_easy/graph_easy_option.h"
#include "easy_graph/graph/graph.h"

EG_NS_BEGIN

GraphEasyLayoutContext::GraphEasyLayoutContext(const GraphEasyOption &options) : options_(options) {}

const Graph *GraphEasyLayoutContext::GetCurrentGraph() const {
if (graphs_.empty())
return nullptr;
return graphs_.back();
}

void GraphEasyLayoutContext::EnterGraph(const Graph &graph) {
graphs_.push_back(&graph);
}

void GraphEasyLayoutContext::ExitGraph() {
graphs_.pop_back();
}

void GraphEasyLayoutContext::LinkBegin() {
is_linking_ = true;
}

void GraphEasyLayoutContext::LinkEnd() {
is_linking_ = false;
}

bool GraphEasyLayoutContext::InLinking() const {
return is_linking_;
}

std::string GraphEasyLayoutContext::GetGroupPath() const {
if (graphs_.empty())
return "";
std::string result("");
std::for_each(graphs_.begin(), graphs_.end(),
[&result](const auto &graph) { result += (std::string("/") + graph->GetName()); });
return (result + "/");
}

const GraphEasyOption &GraphEasyLayoutContext::GetOptions() const {
return options_;
}

EG_NS_END

+ 54
- 0
tests/framework/easy_graph/src/layout/engines/graph_easy/graph_easy_option.cc View File

@@ -0,0 +1,54 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <map>
#include "easy_graph/layout/engines/graph_easy/graph_easy_option.h"

EG_NS_BEGIN

namespace {
struct Format {
const char *format;
const char *postfix;
};

std::map<LayoutFormat, Format> formats = {{LayoutFormat::ASCII, {"ascii", "txt"}},
{LayoutFormat::BOXART, {"boxart", "txt"}},
{LayoutFormat::SVG, {"svg", "svg"}},
{LayoutFormat::DOT, {"dot", "dot"}},
{LayoutFormat::HTML, {"html", "html"}}};

std::string GetLayoutOutputArg(const GraphEasyOption &options, const std::string &graphName) {
if (options.output_ == LayoutOutput::CONSOLE)
return "";
return std::string(" --output ") + options.output_path_ + graphName + "." + formats[options.format_].postfix;
}

std::string GetLayoutFomartArg(const GraphEasyOption &options) {
return std::string(" --as=") + formats[options.format_].format;
}
} // namespace

const GraphEasyOption &GraphEasyOption::GetDefault() {
static GraphEasyOption option;
return option;
}

std::string GraphEasyOption::GetLayoutCmdArgs(const std::string &graphName) const {
return GetLayoutFomartArg(*this) + GetLayoutOutputArg(*this, graphName);
}

EG_NS_END

+ 188
- 0
tests/framework/easy_graph/src/layout/engines/graph_easy/graph_easy_visitor.cc View File

@@ -0,0 +1,188 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/layout/engines/graph_easy/graph_easy_visitor.h"
#include "layout/engines/graph_easy/utils/shell_executor.h"
#include "easy_graph/layout/engines/graph_easy/graph_easy_option.h"
#include "easy_graph/infra/scope_guard.h"
#include "easy_graph/graph/graph.h"
#include "easy_graph/graph/edge.h"
#include "easy_graph/graph/node.h"
#include "easy_graph/infra/log.h"

EG_NS_BEGIN

namespace {
struct SubgraphLayoutVisitor : GraphVisitor {
SubgraphLayoutVisitor(const NodeId &id, GraphEasyLayoutContext &ctxt) : id_(id), ctxt_(ctxt) {}
std::string layout;
bool hasSubgraph{false};

private:
Status Visit(const Graph &graph) override {
ScopeGuard guard([this, &graph]() { ctxt_.EnterGraph(graph); }, [this]() { ctxt_.ExitGraph(); });
layout += (std::string(" -- [") + id_ + "/" + graph.GetName() + "]" +
"{class : subgraph; label : " + graph.GetName() + ";}");
hasSubgraph = true;
return EG_SUCCESS;
}

private:
NodeId id_;
GraphEasyLayoutContext &ctxt_;
};

/////////////////////////////////////////////////////////////////////////
std::string GetGraphLayoutTitle(const Graph &graph, const GraphEasyLayoutContext &ctxt) {
std::string flowDirection = (ctxt.GetOptions().dir_ == FlowDir::LR) ? "east" : "down";
std::string graphTitle = std::string("graph { label : ") + graph.GetName() + "; flow : " + flowDirection +
" ; } node.subgraph { border : double-dash; }";
return graphTitle;
}
/////////////////////////////////////////////////////////////////////////
std::string GetNodeLayout(const Node &node, GraphEasyLayoutContext &ctxt) {
const auto &id = node.GetId();
std::string nodeBox = std::string("[") + id + "]";

SubgraphLayoutVisitor subgraphVisitor(id, ctxt);
node.Accept(subgraphVisitor);

if (!subgraphVisitor.hasSubgraph || ctxt.InLinking())
return nodeBox;

return (std::string("( ") + id + ": " + nodeBox + subgraphVisitor.layout + ")");
}

/////////////////////////////////////////////////////////////////////////
INTERFACE(EdgeLayout) {
EdgeLayout(GraphEasyLayoutContext & ctxt, const Edge &edge) : ctxt_(ctxt), options_(ctxt.GetOptions()), edge_(edge) {}

std::string GetLayout() const {
auto graph = ctxt_.GetCurrentGraph();
if (!graph) {
EG_FATAL("Layout context has no graph!");
return "";
}

auto node_pair = graph->FindNodePair(edge_);

if ((!node_pair.first) || (!node_pair.second)) {
EG_FATAL("Layout context graph(%s) has not found node(%s, %s)!", graph->GetName().c_str(),
edge_.GetSrc().getNodeId().c_str(), edge_.GetDst().getNodeId().c_str());
return "";
}

std::string src_node_layout = GetNodeLayout(*node_pair.first, ctxt_);
std::string dst_node_layout = GetNodeLayout(*node_pair.second, ctxt_);
return src_node_layout + GetArrowLayout() + GetAttrLayout() + dst_node_layout;
}

private:
ABSTRACT(std::string GetAttrLayout() const);
ABSTRACT(std::string GetArrowLayout() const);

protected:
GraphEasyLayoutContext &ctxt_;
const GraphEasyOption &options_;
const Edge &edge_;
};

/////////////////////////////////////////////////////////////////////////
struct CtrlEdgeLayout : EdgeLayout {
using EdgeLayout::EdgeLayout;

private:
std::string GetAttrLayout() const override {
if (edge_.GetLabel() == "")
return "";
return std::string("{label : ") + edge_.GetLabel() + "}";
}

std::string GetArrowLayout() const override {
return " ..> ";
}
};

/////////////////////////////////////////////////////////////////////////
struct DataEdgeLayout : EdgeLayout {
using EdgeLayout::EdgeLayout;

private:
std::string GetAttrLayout() const override {
return std::string("{ ") + GetLabelAttr() + GetPortAttr() + " }";
}

std::string GetArrowLayout() const override {
return " --> ";
}

private:
std::string GetPortPair() const {
return std::string("(") + std::to_string(edge_.GetSrc().getPortId()) + "," +
std::to_string(edge_.GetDst().getPortId()) + ")";
}

std::string GetLabelAttr() const {
return std::string("label :") + edge_.GetLabel() + GetPortPair() + "; ";
}

std::string GetPortAttr() const {
return (options_.type_ == LayoutType::FREE) ? "" : GetOutPortAttr() + GetInPortAttr();
}

std::string GetOutPortAttr() const {
return std::string(" start : ") + "front" + ", " + std::to_string(edge_.GetSrc().getPortId() * options_.scale_) +
"; ";
}

std::string GetInPortAttr() const {
return std::string(" end : ") + "back" + ", " + std::to_string(edge_.GetDst().getPortId() * options_.scale_) + "; ";
}
};
} // namespace

GraphEasyVisitor::GraphEasyVisitor(const GraphEasyOption &options) : ctxt_(options) {}

Status GraphEasyVisitor::Visit(const Graph &graph) {
ctxt_.EnterGraph(graph);
layout_ += GetGraphLayoutTitle(graph, ctxt_);
return EG_SUCCESS;
}

Status GraphEasyVisitor::Visit(const Node &node) {
layout_ += GetNodeLayout(node, ctxt_);
return EG_SUCCESS;
}

Status GraphEasyVisitor::Visit(const Edge &edge) {
ScopeGuard guard([this]() { ctxt_.LinkBegin(); }, [this]() { ctxt_.LinkEnd(); });

auto makeEdgeLayout = [this, &edge]() -> const EdgeLayout * {
if (edge.GetType() == EdgeType::CTRL)
return new CtrlEdgeLayout(ctxt_, edge);
return new DataEdgeLayout(ctxt_, edge);
};

std::unique_ptr<const EdgeLayout> edgeLayout(makeEdgeLayout());
layout_ += edgeLayout->GetLayout();
return EG_SUCCESS;
}

std::string GraphEasyVisitor::GetLayout() const {
return layout_;
}

EG_NS_END

+ 43
- 0
tests/framework/easy_graph/src/layout/engines/graph_easy/utils/shell_executor.cc View File

@@ -0,0 +1,43 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <sys/types.h>
#include <sys/wait.h>
#include <cstdlib>
#include <string>
#include "easy_graph/infra/log.h"
#include "layout/engines/graph_easy/utils/shell_executor.h"

EG_NS_BEGIN

Status ShellExecutor::execute(const std::string &script) {
EG_DBG("%s", script.c_str());

pid_t status = system(script.c_str());
if (-1 == status) {
EG_ERR("system execute return error!");
return EG_FAILURE;
}

if (WIFEXITED(status) && (0 == WEXITSTATUS(status)))
return EG_SUCCESS;

EG_ERR("system execute {%s} exit status value = [0x%x], exit code: %d\n", script.c_str(), status,
WEXITSTATUS(status));
return EG_FAILURE;
}

EG_NS_END

+ 32
- 0
tests/framework/easy_graph/src/layout/engines/graph_easy/utils/shell_executor.h View File

@@ -0,0 +1,32 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HB141A993_B14A_4A1D_A1DD_353D33AE77A2
#define HB141A993_B14A_4A1D_A1DD_353D33AE77A2

#include <string>
#include "easy_graph/eg.h"
#include "easy_graph/infra/status.h"

EG_NS_BEGIN

struct ShellExecutor {
static Status execute(const std::string &script);
};

EG_NS_END

#endif

+ 35
- 0
tests/framework/easy_graph/src/layout/graph_layout.cc View File

@@ -0,0 +1,35 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/layout/graph_layout.h"
#include "easy_graph/layout/layout_executor.h"
#include "easy_graph/graph/graph.h"

EG_NS_BEGIN

void GraphLayout::Config(LayoutExecutor &executor, const LayoutOption *opts) {
this->executor_ = &executor;
options_ = opts;
}

Status GraphLayout::Layout(const Graph &graph, const LayoutOption *opts) {
const LayoutOption *options = opts ? opts : this->options_;
if (!executor_)
return EG_UNIMPLEMENTED;
return executor_->Layout(graph, options);
}

EG_NS_END

+ 18
- 0
tests/framework/ge_graph_dsl/CMakeLists.txt View File

@@ -0,0 +1,18 @@
# Copyright 2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(tests)

+ 17
- 0
tests/framework/ge_graph_dsl/include/CMakeLists.txt View File

@@ -0,0 +1,17 @@
# Copyright 2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

add_library(ge_graph_dsl_inc INTERFACE)
target_include_directories(ge_graph_dsl_inc INTERFACE ./)

+ 29
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/ge.h View File

@@ -0,0 +1,29 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H382C2083_01CC_43DF_8BBD_EF6714FF62B2
#define H382C2083_01CC_43DF_8BBD_EF6714FF62B2

#define GE_NS ge
#define GE_NS_BEGIN namespace GE_NS {
#define GE_NS_END }
#define USING_GE_NS using namespace GE_NS;
#define FWD_DECL_GE(type) \
namespace GE_NS { \
struct type; \
}

#endif /* H382C2083_01CC_43DF_8BBD_EF6714FF62B2 */

tests/st/framework/utils/assertion/graph_assertion.h → tests/framework/ge_graph_dsl/include/ge_graph_dsl/graph_dsl.h View File

@@ -1,34 +1,38 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GRAPHENGINE_LLT_ST_GRAPH_ASSERTION_H
#define GRAPHENGINE_LLT_ST_GRAPH_ASSERTION_H
/*
* Compare graph node size, node_attr
*/
#define ASSERT_GRAPH_EQUAL(g1,g2) \
do { \
} while (0)
#define ASSERT_GRAPH_CORRECT(g) \
do { \
} while (0)
#define ASSERT_GRAPH_SHAPE_CONTINOUS(g) \
do { \
} while (0)
#endif // GRAPHENGINE_LLT_ST_GRAPH_ASSERTION_H
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H7C82E219_BDEF_4480_A2D9_30F0590C8AC5
#define H7C82E219_BDEF_4480_A2D9_30F0590C8AC5

#include "easy_graph/graph/graph.h"
#include "easy_graph/builder/graph_dsl.h"
#include "ge_graph_dsl/ge.h"
#include "ge_graph_dsl/op_desc/op_desc_node_builder.h"
#include "external/graph/graph.h"

GE_NS_BEGIN

Graph ToGeGraph(const ::EG_NS::Graph &graph);
ComputeGraphPtr ToComputeGraph(const ::EG_NS::Graph &graph);

#define DATA_EDGE(...) Data(__VA_ARGS__)
#define CTRL_EDGE(...) Ctrl(__VA_ARGS__)
#define NODE(...) Node(::GE_NS::OpDescNodeBuild(__VA_ARGS__))
#define EDGE(...) DATA_EDGE(__VA_ARGS__)

GE_NS_END

#endif

+ 33
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_box.h View File

@@ -0,0 +1,33 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H6DCF6C61_7C9B_4048_BB5D_E748142FF7F8
#define H6DCF6C61_7C9B_4048_BB5D_E748142FF7F8

#include "ge_graph_dsl/ge.h"
#include "easy_graph/graph/node_id.h"
#include "easy_graph/graph/box.h"
#include "external/graph/gnode.h"

GE_NS_BEGIN

struct OpBox : ::EG_NS::Box {
ABSTRACT(OpDescPtr Build(const ::EG_NS::NodeId &) const);
};

GE_NS_END

#endif /* H6DCF6C61_7C9B_4048_BB5D_E748142FF7F8 */

+ 52
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg.h View File

@@ -0,0 +1,52 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H77F0BD09_6C00_4E45_8DED_38A676D6B20A
#define H77F0BD09_6C00_4E45_8DED_38A676D6B20A

#include <string>
#include "ge_graph_dsl/ge.h"
#include "graph/types.h"
#include "ge_graph_dsl/op_desc/op_type.h"

GE_NS_BEGIN

struct OpDescCfg {
struct TensorCfg {
TensorCfg(Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT, std::vector<int64_t> shape = {1, 1, 224, 224})
: format_(format), data_type_(data_type), shape_(shape) {}
Format format_;
DataType data_type_;
std::vector<int64_t> shape_;
};

OpDescCfg(const OpType &type, int in_cnt = 0, int out_cnt = 0, Format format = FORMAT_NCHW,
DataType data_type = DT_FLOAT, std::vector<int64_t> shape = {1, 1, 224, 224})
: type_(type), in_cnt_(in_cnt), out_cnt_(out_cnt), default_tensor_(format, data_type, shape) {}

protected:
OpType GetType() const {
return type_;
}
OpType type_;
int in_cnt_;
int out_cnt_;
TensorCfg default_tensor_;
};

GE_NS_END

#endif /* H77F0BD09_6C00_4E45_8DED_38A676D6B20A */

+ 51
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg_box.h View File

@@ -0,0 +1,51 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HF55B1FFE_C64C_4671_8A25_A57DDD5D1280
#define HF55B1FFE_C64C_4671_8A25_A57DDD5D1280

#include "easy_graph/graph/node_id.h"
#include "ge_graph_dsl/ge.h"
#include "ge_graph_dsl/op_desc/op_box.h"
#include "ge_graph_dsl/op_desc/op_desc_cfg.h"
#include "graph/op_desc.h"

GE_NS_BEGIN

struct OpDescCfgBox : OpBox, private OpDescCfg {
OpDescCfgBox(const OpType &opType);
OpDescCfgBox &InCnt(int in_cnt);
OpDescCfgBox &OutCnt(int out_cnt);
OpDescCfgBox &TensorDesc(Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT,
std::vector<int64_t> shape = {1, 1, 224, 224});
template<typename Type>
OpDescCfgBox& Attr(const std::string &name, Type value) {
auto attrvalue = ge::GeAttrValue::CreateFrom<Type>(value);
attrs_.emplace(std::make_pair(name, attrvalue));
return *this;
}

private:
OpDescPtr Build(const ::EG_NS::NodeId &id) const override;
void UpdateAttrs(OpDescPtr&) const;
std::map<std::string, GeAttrValue> attrs_;
};

#define OP_CFG(optype) ::GE_NS::OpDescCfgBox(optype)

GE_NS_END

#endif /* HF55B1FFE_C64C_4671_8A25_A57DDD5D1280 */

+ 34
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg_repo.h View File

@@ -0,0 +1,34 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H600DEDD4_D5B9_4803_AF48_262B2C4FBA94d
#define H600DEDD4_D5B9_4803_AF48_262B2C4FBA94c

#include "easy_graph/infra/singleton.h"
#include "ge_graph_dsl/ge.h"
#include "ge_graph_dsl/op_desc/op_type.h"

GE_NS_BEGIN

struct OpDescCfg;

SINGLETON(OpDescCfgRepo) {
const OpDescCfg *FindBy(const OpType &);
};

GE_NS_END

#endif /* H600DEDD4_D5B9_4803_AF48_262B2C4FBA94 */

+ 57
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_node_builder.h View File

@@ -0,0 +1,57 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef H53F1A984_1D06_4458_9595_0A6DC60EA9CE
#define H53F1A984_1D06_4458_9595_0A6DC60EA9CE

#include "easy_graph/graph/node.h"
#include "ge_graph_dsl/ge.h"
#include "ge_graph_dsl/op_desc/op_desc_ptr_box.h"
#include "ge_graph_dsl/op_desc/op_desc_cfg_box.h"
#include "graph/op_desc.h"

using ::EG_NS::Node;
using ::EG_NS::NodeId;

GE_NS_BEGIN

inline const ::EG_NS::NodeId OpDescNodeBuild(const ::EG_NS::NodeId &id) {
return id;
}

template<typename... GRAPHS, SUBGRAPH_CONCEPT(GRAPHS, ::EG_NS::Graph)>
inline ::EG_NS::Node OpDescNodeBuild(const ::EG_NS::NodeId &id, const GRAPHS &... graphs) {
return ::EG_NS::Node(id, graphs...);
}

template<typename... GRAPHS, SUBGRAPH_CONCEPT(GRAPHS, ::EG_NS::Graph)>
inline ::EG_NS::Node OpDescNodeBuild(const OpDescPtr &op, const GRAPHS &... graphs) {
return ::EG_NS::Node(op->GetName(), BOX_OF(::GE_NS::OpDescPtrBox, op), graphs...);
}

template<typename... GRAPHS, SUBGRAPH_CONCEPT(GRAPHS, ::EG_NS::Graph)>
inline ::EG_NS::Node OpDescNodeBuild(const ::EG_NS::NodeId &id, const OpType &opType, const GRAPHS &... graphs) {
return ::EG_NS::Node(id, BOX_OF(OpDescCfgBox, opType), graphs...);
}

template<typename... GRAPHS, SUBGRAPH_CONCEPT(GRAPHS, ::EG_NS::Graph)>
inline ::EG_NS::Node OpDescNodeBuild(const ::EG_NS::NodeId &id, const OpDescCfgBox &opBox, const GRAPHS &... graphs) {
return ::EG_NS::Node(id, BOX_OF(OpDescCfgBox, opBox), graphs...);
}

GE_NS_END

#endif /* H53F1A984_1D06_4458_9595_0A6DC60EA9CE */

+ 38
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_ptr_box.h View File

@@ -0,0 +1,38 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HCFDD0816_CC46_4264_9363_9E8C6934F43E
#define HCFDD0816_CC46_4264_9363_9E8C6934F43E

#include "easy_graph/eg.h"
#include "easy_graph/graph/node_id.h"
#include "graph/op_desc.h"
#include "ge_graph_dsl/ge.h"
#include "ge_graph_dsl/op_desc/op_box.h"

GE_NS_BEGIN

struct OpDescPtrBox : OpBox {
OpDescPtrBox(const OpDescPtr &op) : op_(op) {}

private:
OpDescPtr Build(const ::EG_NS::NodeId &id) const override;
const OpDescPtr op_;
};

GE_NS_END

#endif /* HCFDD0816_CC46_4264_9363_9E8C6934F43E */

+ 28
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_type.h View File

@@ -0,0 +1,28 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HAA2D4486_DB43_4ED2_BCF8_F41AD8267A85
#define HAA2D4486_DB43_4ED2_BCF8_F41AD8267A85

#include <string>
#include "ge_graph_dsl/ge.h"

GE_NS_BEGIN

using OpType = std::string;

GE_NS_END

#endif /* HAA2D4486_DB43_4ED2_BCF8_F41AD8267A85 */

+ 44
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/vistor/ge_graph_vistor.h View File

@@ -0,0 +1,44 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HD31125D4_0EB8_494C_B83D_3B8B923A914D
#define HD31125D4_0EB8_494C_B83D_3B8B923A914D

#include "easy_graph/graph/graph_visitor.h"
#include "graph/compute_graph.h"
#include "external/graph/graph.h"
#include "ge_graph_dsl/ge.h"

GE_NS_BEGIN

struct GeGraphVisitor : ::EG_NS::GraphVisitor {
GeGraphVisitor();
void reset(const ComputeGraphPtr &graph);
Graph BuildGeGraph() const;
ComputeGraphPtr BuildComputeGraph() const;

private:
::EG_NS::Status Visit(const ::EG_NS::Graph &) override;
::EG_NS::Status Visit(const ::EG_NS::Node &) override;
::EG_NS::Status Visit(const ::EG_NS::Edge &) override;

private:
ComputeGraphPtr build_graph_;
};

GE_NS_END

#endif /* TESTS_ST_EASY_GRAPH_GELAYOUT_GRAPH_GE_VISTOR_H_ */

+ 47
- 0
tests/framework/ge_graph_dsl/include/ge_graph_dsl/vistor/ge_subgraph_vistor.h View File

@@ -0,0 +1,47 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HF900DC04_D202_42ED_992A_35DD7C940CE6
#define HF900DC04_D202_42ED_992A_35DD7C940CE6

#include "easy_graph/infra/status.h"
#include "external/graph/gnode.h"
#include "ge_graph_dsl/ge.h"
#include "ge_graph_dsl/vistor/ge_graph_vistor.h"

GE_NS_BEGIN

struct GeSubgraphVisitor : ::EG_NS::GraphVisitor {
GeSubgraphVisitor(ComputeGraphPtr &, const ::EG_NS::Node &);
::EG_NS::Status BuildGraphRelations();

private:
::EG_NS::Status Visit(const ::EG_NS::Graph &) override;
::EG_NS::Status Visit(const ::EG_NS::Node &) override;
::EG_NS::Status Visit(const ::EG_NS::Edge &) override;

private:
::EG_NS::Status BuildGraphRelations(OpDescPtr &);

private:
ComputeGraphPtr &root_graph_;
const ::EG_NS::Node &node_;
GeGraphVisitor cur_graph_vistor_;
std::vector<ComputeGraphPtr> subgraphs_;
};

GE_NS_END

#endif /* HF900DC04_D202_42ED_992A_35DD7C940CE6 */

+ 28
- 0
tests/framework/ge_graph_dsl/src/CMakeLists.txt View File

@@ -0,0 +1,28 @@
# Copyright 2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP")

add_library(ge_graph_dsl STATIC ${SOURCES})

target_include_directories(ge_graph_dsl
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(ge_graph_dsl PUBLIC
$<BUILD_INTERFACE:intf_pub>)

set_target_properties(ge_graph_dsl PROPERTIES CXX_STANDARD 17)
target_link_libraries(ge_graph_dsl PUBLIC ge_graph_dsl_inc easy_graph metadef_graph)

+ 79
- 0
tests/framework/ge_graph_dsl/src/ge_graph_vistor.cc View File

@@ -0,0 +1,79 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "easy_graph/graph/edge.h"
#include "easy_graph/graph/graph.h"
#include "easy_graph/graph/node.h"
#include "easy_graph/graph/edge_type.h"
#include "easy_graph/builder/box_builder.h"

#include "external/graph/types.h"
#include "graph/utils/graph_utils.h"
#include "graph/compute_graph.h"
#include "graph/ge_tensor.h"

#include "framework/common/types.h"
#include "ge_graph_dsl/op_desc/op_box.h"
#include "ge_graph_dsl/op_desc/op_desc_cfg_box.h"
#include "ge_graph_dsl/vistor/ge_graph_vistor.h"
#include "ge_graph_dsl/vistor/ge_subgraph_vistor.h"

using ::EG_NS::Status;

GE_NS_BEGIN

GeGraphVisitor::GeGraphVisitor() : build_graph_(std::make_shared<ComputeGraph>("")) {}

void GeGraphVisitor::reset(const ComputeGraphPtr &graph) {
build_graph_ = graph;
}

Graph GeGraphVisitor::BuildGeGraph() const {
return GraphUtils::CreateGraphFromComputeGraph(build_graph_);
}

ComputeGraphPtr GeGraphVisitor::BuildComputeGraph() const {
return build_graph_;
}

Status GeGraphVisitor::Visit(const ::EG_NS::Graph &graph) {
build_graph_->SetName(graph.GetName());
return EG_SUCCESS;
}

Status GeGraphVisitor::Visit(const ::EG_NS::Node &node) {
GeSubgraphVisitor vistor(build_graph_, node);
return vistor.BuildGraphRelations();
}

Status GeGraphVisitor::Visit(const ::EG_NS::Edge &edge) {
auto src_node = build_graph_->FindNode(edge.GetSrc().getNodeId());
auto dst_node = build_graph_->FindNode(edge.GetDst().getNodeId());

if (edge.GetType() == ::EG_NS::EdgeType::CTRL) {
GraphUtils::AddEdge(src_node->GetOutControlAnchor(), dst_node->GetInControlAnchor());
return EG_SUCCESS;
}

if (src_node->GetAllOutDataAnchorsSize() <= edge.GetSrc().getPortId() ||
dst_node->GetAllInDataAnchorsSize() <= edge.GetDst().getPortId()) {
return EG_FAILURE;
}
GraphUtils::AddEdge(src_node->GetOutDataAnchor(edge.GetSrc().getPortId()),
dst_node->GetInDataAnchor(edge.GetDst().getPortId()));
return EG_SUCCESS;
}

GE_NS_END

+ 70
- 0
tests/framework/ge_graph_dsl/src/ge_subgraph_vistor.cc View File

@@ -0,0 +1,70 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/graph/node.h"
#include "easy_graph/graph/graph.h"
#include "easy_graph/graph/edge.h"
#include "ge_graph_dsl/op_desc/op_box.h"
#include "ge_graph_dsl/vistor/ge_subgraph_vistor.h"

GE_NS_BEGIN

GeSubgraphVisitor::GeSubgraphVisitor(ComputeGraphPtr &rootGraph, const ::EG_NS::Node &node)
: root_graph_(rootGraph), node_(node) {}

::EG_NS::Status GeSubgraphVisitor::BuildGraphRelations() {
node_.Accept(*this);
auto nod_builder = node_.Unpacking<OpBox>();
if (nod_builder == nullptr) {
return EG_FAILURE;
} else {
auto opPtr = nod_builder->Build(node_.GetId());
return BuildGraphRelations(opPtr);
}
}

::EG_NS::Status GeSubgraphVisitor::BuildGraphRelations(OpDescPtr &opPtr) {
auto node = root_graph_->AddNode(opPtr);
int graph_index = 0;
for (auto subGraph : subgraphs_) {
opPtr->AddSubgraphName(subGraph->GetName());
opPtr->SetSubgraphInstanceName(graph_index++, subGraph->GetName());
subGraph->SetParentNode(node);
subGraph->SetParentGraph(root_graph_);
root_graph_->AddSubgraph(subGraph);
}
return EG_SUCCESS;
}

::EG_NS::Status GeSubgraphVisitor::Visit(const ::EG_NS::Graph &graph) {
auto subgraph = std::make_shared<ComputeGraph>(graph.GetName());
cur_graph_vistor_.reset(subgraph);
graph.Accept(cur_graph_vistor_);
subgraphs_.push_back(subgraph);
return EG_SUCCESS;
}

::EG_NS::Status GeSubgraphVisitor::Visit(const ::EG_NS::Node &node) {
::EG_NS::GraphVisitor &vistor = cur_graph_vistor_;
return vistor.Visit(node);
}

::EG_NS::Status GeSubgraphVisitor::Visit(const ::EG_NS::Edge &edge) {
::EG_NS::GraphVisitor &vistor = cur_graph_vistor_;
return vistor.Visit(edge);
}

GE_NS_END

+ 39
- 0
tests/framework/ge_graph_dsl/src/graph_dsl.cc View File

@@ -0,0 +1,39 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "easy_graph/builder/graph_dsl.h"
#include "easy_graph/graph/graph.h"
#include "external/graph/graph.h"
#include "ge_graph_dsl/graph_dsl.h"
#include "ge_graph_dsl/vistor/ge_graph_vistor.h"

GE_NS_BEGIN

Graph ToGeGraph(const ::EG_NS::Graph &graph) {
graph.Layout();
GeGraphVisitor geVistor;
graph.Accept(geVistor);
return geVistor.BuildGeGraph();
}

ComputeGraphPtr ToComputeGraph(const ::EG_NS::Graph &graph) {
graph.Layout();
GeGraphVisitor geVistor;
graph.Accept(geVistor);
return geVistor.BuildComputeGraph();
}

GE_NS_END

+ 75
- 0
tests/framework/ge_graph_dsl/src/op_desc_cfg_box.cc View File

@@ -0,0 +1,75 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ge_graph_dsl/op_desc/op_desc_cfg_box.h"
#include "easy_graph/infra/status.h"
#include "ge_graph_dsl/op_desc/op_desc_cfg_repo.h"
#include "ge_graph_dsl/op_desc/op_desc_cfg.h"
#include "external/graph/gnode.h"
#include "graph/ge_tensor.h"

using ::EG_NS::Status;
using ::GE_NS::OpDescCfg;

GE_NS_BEGIN

OpDescCfgBox::OpDescCfgBox(const OpType &opType) : OpDescCfg(opType) {
auto opCfg = OpDescCfgRepo::GetInstance().FindBy(opType);
if (opCfg != nullptr) {
::OpDescCfg &base = *this;
base = (*opCfg);
}
}

OpDescCfgBox &OpDescCfgBox::InCnt(int in_cnt) {
this->in_cnt_ = in_cnt;
return *this;
}

OpDescCfgBox &OpDescCfgBox::OutCnt(int out_cnt) {
this->out_cnt_ = out_cnt;
return *this;
}

OpDescCfgBox &OpDescCfgBox::TensorDesc(Format format, DataType data_type, std::vector<int64_t> shape) {
default_tensor_.format_ = format;
default_tensor_.data_type_ = data_type;
default_tensor_.shape_ = shape;
return *this;
}

void OpDescCfgBox::UpdateAttrs(OpDescPtr& op_desc) const {
std::for_each(attrs_.begin(), attrs_.end(), [&op_desc](const auto &attr){
op_desc->SetAttr(attr.first, attr.second);
});
}

OpDescPtr OpDescCfgBox::Build(const ::EG_NS::NodeId &id) const {
auto opPtr = std::make_shared<OpDesc>(id, GetType());
GeTensorDesc tensor_desc(ge::GeShape(default_tensor_.shape_), default_tensor_.format_, default_tensor_.data_type_);
for (int i = 0; i < in_cnt_; i++) {
opPtr->AddInputDesc(tensor_desc);
}

for (int i = 0; i < out_cnt_; i++) {
opPtr->AddOutputDesc(tensor_desc);
}

UpdateAttrs(opPtr);
return opPtr;
}

GE_NS_END

+ 46
- 0
tests/framework/ge_graph_dsl/src/op_desc_cfg_repo.cc View File

@@ -0,0 +1,46 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ge_graph_dsl/op_desc/op_desc_cfg_repo.h"
#include "framework/common/types.h"
#include "graph/debug/ge_attr_define.h"
#include "ge_graph_dsl/op_desc/op_desc_cfg.h"

GE_NS_BEGIN

namespace {

#define OP_CFG(optype, ...) \
{ \
optype, OpDescCfg { \
optype, __VA_ARGS__ \
} \
}

static std::map<OpType, OpDescCfg> cfg_repo{OP_CFG(DATA, 1, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}),
OP_CFG(ADD, 2, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}),
OP_CFG(VARIABLE, 1, 1)};
} // namespace

const OpDescCfg *OpDescCfgRepo::FindBy(const OpType &id) {
auto it = cfg_repo.find(id);
if (it == cfg_repo.end()) {
return nullptr;
}
return &(it->second);
}

GE_NS_END

tests/st/framework/utils/assertion/graph_assertion.cc → tests/framework/ge_graph_dsl/src/op_desc_ptr_box.cc View File

@@ -1,17 +1,24 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "graph_assertion.h"
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ge_graph_dsl/op_desc/op_desc_ptr_box.h"
#include "external/graph/gnode.h"

USING_GE_NS

OpDescPtr OpDescPtrBox::Build(const ::EG_NS::NodeId &id) const {
return op_;
}

+ 33
- 0
tests/framework/ge_graph_dsl/tests/CMakeLists.txt View File

@@ -0,0 +1,33 @@
# Copyright 2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP")

add_executable(ge_graph_dsl_test ${SOURCES})

target_include_directories(ge_graph_dsl_test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
)

target_compile_options(ge_graph_dsl_test PRIVATE
-g
)
set_target_properties(ge_graph_dsl_test PROPERTIES CXX_STANDARD 17)

target_link_libraries(ge_graph_dsl_test PUBLIC gtest gtest_main ge_graph_dsl)

include(CTest)
enable_testing()
add_test(NAME test COMMAND ge_graph_dsl_test)

+ 218
- 0
tests/framework/ge_graph_dsl/tests/graph_dsl_test.cc View File

@@ -0,0 +1,218 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "gtest/gtest.h"
#include <string>
#include "easy_graph/graph/box.h"
#include "easy_graph/graph/node.h"
#include "easy_graph/builder/graph_dsl.h"
#include "easy_graph/builder/box_builder.h"
#include "easy_graph/layout/graph_layout.h"
#include "easy_graph/layout/engines/graph_easy/graph_easy_option.h"
#include "easy_graph/layout/engines/graph_easy/graph_easy_executor.h"
#include "graph/graph.h"
#include "graph/compute_graph.h"
#include "framework/common/types.h"
#include "graph/debug/ge_attr_define.h"
#include "ge_graph_dsl/graph_dsl.h"
#include "ge_graph_dsl/op_desc/op_desc_cfg_box.h"

USING_GE_NS

class GraphDslTest : public testing::Test {
private:
EG_NS::GraphEasyExecutor executor;

protected:
void SetUp() {
EG_NS::GraphLayout::GetInstance().Config(executor, nullptr);
}

void TearDown() {}
};

TEST_F(GraphDslTest, test_build_graph_from_optype_with_name) {
DEF_GRAPH(g1) {
CHAIN(NODE("data1", DATA)->NODE("add", ADD));
});

auto geGraph = ToGeGraph(g1);
auto computeGraph = ToComputeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 2);
ASSERT_EQ(computeGraph->GetAllNodesSize(), 2);
}

TEST_F(GraphDslTest, test_build_graph_with_name) {
DEF_GRAPH(g1, "sample_graph") {
CHAIN(NODE("data1", DATA)->NODE("add", ADD));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 2);
ASSERT_EQ(geGraph.GetName(), "sample_graph");
}

TEST_F(GraphDslTest, test_build_from_from_op_desc_ptr) {
DEF_GRAPH(g1) {
auto data = std::make_shared<OpDesc>("data1", DATA);
auto add = std::make_shared<OpDesc>("Add", ADD);
CHAIN(NODE(data)->NODE(add));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 2);
}

TEST_F(GraphDslTest, test_build_from_op_desc_cfg) {
DEF_GRAPH(g1) {
auto datCfg = OP_CFG(DATA).InCnt(1).OutCnt(1);
auto addCfg = OP_CFG(DATA).InCnt(1).OutCnt(1);
CHAIN(NODE("data1", datCfg)->NODE("add", addCfg));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 2);
}

TEST_F(GraphDslTest, test_build_from_op_desc_cfg_inline) {
DEF_GRAPH(g1) {
CHAIN(NODE("data1", OP_CFG(DATA).InCnt(1).OutCnt(1))->NODE("add", OP_CFG(ADD).InCnt(2).OutCnt(1)));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 2);
}

TEST_F(GraphDslTest, test_build_from_control_chain) {
DEF_GRAPH(g1) {
CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 2);
}

TEST_F(GraphDslTest, test_build_from_data_chain) {
DEF_GRAPH(g1) {
DATA_CHAIN(NODE("data1", DATA)->NODE("add", ADD));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 2);
}

TEST_F(GraphDslTest, test_build_from_data_chain_with_edge) {
DEF_GRAPH(g1) {
CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD));
CHAIN(NODE("data1", DATA)->EDGE(2, 2)->NODE("add"));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 2);
}

TEST_F(GraphDslTest, test_build_graph_reused_before_node) {
DEF_GRAPH(g1) {
CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD));
CHAIN(NODE("data1")->EDGE(2, 2)->NODE("add"));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 2);
}

TEST_F(GraphDslTest, test_build_graph_with_constant_folding) {
DEF_GRAPH(g1) {
CHAIN(NODE("data1", DATA)->NODE("add", ADD));
CHAIN(NODE("data2", DATA)->NODE("add"));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 3);
}

TEST_F(GraphDslTest, test_build_complex_normal_graph_build_suggested) {
DEF_GRAPH(g1) {
CHAIN(NODE("w1", VARIABLE)->NODE("prefetch1", HCOMALLGATHER)->NODE("Add1", ADD));
CHAIN(NODE("w2", VARIABLE)->NODE("prefetch2", HCOMALLGATHER)->NODE("Add2", ADD));
CHAIN(NODE("w3", VARIABLE)->NODE("prefetch3", HCOMALLGATHER)->NODE("Add3", ADD));
CHAIN(NODE("w4", VARIABLE)->NODE("prefetch4", HCOMALLGATHER)->NODE("Add4", ADD));
CHAIN(NODE("w5", VARIABLE)->NODE("prefetch5", HCOMALLGATHER)->NODE("Add5", ADD));
CHAIN(NODE("const1", CONSTANTOP)
->NODE("Add1")
->NODE("Add2")
->NODE("Add3")
->NODE("Add4")
->NODE("Add5")
->NODE("net_output", NETOUTPUT));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 17);
}

TEST_F(GraphDslTest, test_build_complex_mult_normal_graph_build) {
DEF_GRAPH(g1) {
CHAIN(NODE("w1", VARIABLE)->NODE("prefetch1", HCOMALLGATHER)->NODE("add1", ADD));
CHAIN(NODE("w2", VARIABLE)->NODE("prefetch2", HCOMALLGATHER)->NODE("add1"));
CHAIN(NODE("w3", VARIABLE)->NODE("prefetch3", HCOMALLGATHER)->NODE("add2", ADD));
CHAIN(NODE("w4", VARIABLE)->NODE("prefetch4", HCOMALLGATHER)->NODE("add2"));
CHAIN(NODE("w5", VARIABLE)->NODE("prefetch5", HCOMALLGATHER)->NODE("add3", ADD));
CHAIN(NODE("const1", CONSTANTOP)->NODE("add3"));
CHAIN(NODE("add1")->NODE("net_output", NETOUTPUT));
CHAIN(NODE("add2")->NODE("net_output"));
CHAIN(NODE("add3")->NODE("net_output"));
CTRL_CHAIN(NODE("add1")->NODE("add2")->NODE("add3"));
});

auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 15);
}

TEST_F(GraphDslTest, test_build_graph_with_sub_graph) {
DEF_GRAPH(sub_1) {
CHAIN(NODE("data_i", DATA)->NODE("less", LESS)->NODE("netoutput", NETOUTPUT));
CHAIN(NODE("const_5", CONSTANTOP)->NODE("less"));
});

DEF_GRAPH(sub_2) {
CHAIN(NODE("data_a", DATA)->NODE("mul", MUL)->NODE("netoutput", NETOUTPUT));
CHAIN(NODE("const_2", CONSTANTOP)->NODE("mul"));
});

DEF_GRAPH(g1) {
CHAIN(NODE("data_a", DATA)->NODE("while", WHILE, sub_1, sub_2)->NODE("netoutput", NETOUTPUT));
CHAIN(NODE("data_i", DATA)->NODE("while"));
});

sub_1.Layout();
sub_2.Layout();
auto geGraph = ToGeGraph(g1);

ASSERT_EQ(geGraph.GetAllNodes().size(), 12);
}

+ 33
- 0
tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc View File

@@ -0,0 +1,33 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "framework/common/types.h"
#include "graph/debug/ge_attr_define.h"
#include "ge_graph_dsl/ge.h"

GE_NS_BEGIN

REGISTER_OPTYPE_DEFINE(DATA, "Data");
REGISTER_OPTYPE_DEFINE(HCOMALLGATHER, "HcomAllGather");
REGISTER_OPTYPE_DEFINE(VARIABLE, "Variable");
REGISTER_OPTYPE_DEFINE(CONSTANTOP, "Constant");
REGISTER_OPTYPE_DEFINE(LESS, "Less");
REGISTER_OPTYPE_DEFINE(MUL, "Mul");
REGISTER_OPTYPE_DEFINE(NETOUTPUT, "NetOutput");
REGISTER_OPTYPE_DEFINE(ADD, "Add");
REGISTER_OPTYPE_DEFINE(WHILE, "While");

GE_NS_END

tests/st/framework/CMakeLists.txt → tests/framework/stub_engine/CMakeLists.txt View File

@@ -31,20 +31,14 @@ list(APPEND INCLUDE_DIRECTORIES
)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP" "*.c++")
#todo
file(GLOB_RECURSE STUB_ENGINE_SRC CONFIGURE_DEPENDS
"stub_engine/*.cc"
)
# ---- Target : stub Host engine ----

add_library(fe SHARED ${STUB_ENGINE_SRC})
# ---- Target : stub Host engine ----
add_library(fe SHARED ${SOURCES})

target_include_directories(fe
PUBLIC
${INCLUDE_DIRECTORIES}
${GE_CODE_DIR}/tests/st/framework
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/stub_engine
)

target_compile_definitions(fe PRIVATE
@@ -62,16 +56,3 @@ target_link_libraries(fe PUBLIC
)

set_target_properties(fe PROPERTIES CXX_STANDARD 11)

# ---- Target : framework ----
list(REMOVE_ITEM SOURCES ${STUB_ENGINE_SRC})

add_library(framework STATIC ${SOURCES})

target_include_directories(framework
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)

set_target_properties(framework PROPERTIES CXX_STANDARD 11)

target_link_libraries(framework PUBLIC graphengine fe)

tests/st/framework/stub_engine/engine/stub_engine.cc → tests/framework/stub_engine/engine/stub_engine.cc View File

@@ -51,7 +51,9 @@ void StubEngine::GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr>
// no optimizer for host cpu engine
}

Status StubEngine::Finalize() { return SUCCESS; }
Status StubEngine::Finalize() {
return SUCCESS;
}
} // namespace st
} // namespace ge

@@ -67,4 +69,6 @@ void GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr> &graph_optim
ge::st::StubEngine::Instance().GetGraphOptimizerObjs(graph_optimizers);
}

ge::Status Finalize() { return ge::st::StubEngine::Instance().Finalize(); }
ge::Status Finalize() {
return ge::st::StubEngine::Instance().Finalize();
}

tests/st/framework/stub_engine/engine/stub_engine.h → tests/framework/stub_engine/engine/stub_engine.h View File


tests/st/framework/inc/st_types.h → tests/framework/stub_engine/inc/st_types.h View File

@@ -25,9 +25,9 @@ const std::string kAicpuAscendLibName = "AicpuAscendLib";
const std::string kHcclLibName = "HcclLib";
const std::string kRTSLibName = "RTSLib";
const std::map<std::string, std::string> kStubEngine2KernelLib = {
{"AIcoreEngine", "AiCoreLib"}, {"VectorEngine", "VectorLib"},
{"DNN_VM_AICPU", "AicpuLib"}, {"DNN_VM_AICPU_ASCEND", "AicpuAscendLib"},
{"DNN_HCCL", "HcclLib"}, {"DNN_VM_RTS", "RTSLib"}};
{"AIcoreEngine", "AiCoreLib"}, {"VectorEngine", "VectorLib"},
{"DNN_VM_AICPU", "AicpuLib"}, {"DNN_VM_AICPU_ASCEND", "AicpuAscendLib"},
{"DNN_HCCL", "HcclLib"}, {"DNN_VM_RTS", "RTSLib"}};
} // namespace st
} // namespace ge
#endif // GRAPHENGINE_ST_TYPES_H

tests/st/framework/stub_engine/ops_kernel_store/op/host_op.cc → tests/framework/stub_engine/ops_kernel_store/op/host_op.cc View File

@@ -19,7 +19,6 @@
#include "framework/common/util.h"
#include "stub_engine/ops_kernel_store/op/stub_op_factory.h"


namespace ge {
namespace st {
Status HostOp::Run() {

tests/st/framework/stub_engine/ops_kernel_store/op/host_op.h → tests/framework/stub_engine/ops_kernel_store/op/host_op.h View File


tests/st/framework/stub_engine/ops_kernel_store/op/op.h → tests/framework/stub_engine/ops_kernel_store/op/op.h View File


tests/st/framework/stub_engine/ops_kernel_store/op/stub_op_factory.cc → tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.cc View File


tests/st/framework/stub_engine/ops_kernel_store/op/stub_op_factory.h → tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.h View File

@@ -53,17 +53,21 @@ class GE_FUNC_VISIBILITY OpFactory {
*/
void RegisterCreator(const std::string &type, const std::string &lib_name, const OP_CREATOR_FUNC &func);

const std::vector<std::string> &GetAllOps() const { return all_ops_; }
const std::vector<std::string> &GetAllOps() const {
return all_ops_;
}

const std::vector<std::string> &GetAllOps(std::string lib_name) const {
auto iter = all_store_ops_.find(lib_name);
if(iter == all_store_ops_.end()){
if (iter == all_store_ops_.end()) {
return all_ops_;
}
return iter->second;
}

bool CheckSupported(const std::string &type) { return op_creator_map_.find(type) != op_creator_map_.end(); }
bool CheckSupported(const std::string &type) {
return op_creator_map_.find(type) != op_creator_map_.end();
}

OpFactory(const OpFactory &) = delete;
OpFactory &operator=(const OpFactory &) = delete;
@@ -94,10 +98,10 @@ class GE_FUNC_VISIBILITY OpRegistrar {
OpRegistrar &operator=(OpRegistrar &&) = delete;
};

#define REGISTER_OP_CREATOR(type, lib_name, clazz) \
std::shared_ptr<Op> Creator_##type##Op(const Node &node, RunContext &run_context) { \
return MakeShared<clazz>(node, run_context); \
} \
#define REGISTER_OP_CREATOR(type, lib_name, clazz) \
std::shared_ptr<Op> Creator_##type##Op(const Node &node, RunContext &run_context) { \
return MakeShared<clazz>(node, run_context); \
} \
OpRegistrar g_##type##Op_creator(#type, #lib_name, Creator_##type##Op)
} // namespace st
} // namespace ge

tests/st/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.cc → tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.cc View File

@@ -36,8 +36,12 @@ REGISTER_OPS_KERNEL_BUILDER(kAicpuAscendLibName, StubOpsKernelBuilder);
REGISTER_OPS_KERNEL_BUILDER(kHcclLibName, StubOpsKernelBuilder);
REGISTER_OPS_KERNEL_BUILDER(kRTSLibName, StubOpsKernelBuilder);

Status StubOpsKernelBuilder::Finalize() { return SUCCESS; }
Status StubOpsKernelBuilder::Initialize(const map<std::string, std::string> &options) { return SUCCESS; }
Status StubOpsKernelBuilder::Finalize() {
return SUCCESS;
}
Status StubOpsKernelBuilder::Initialize(const map<std::string, std::string> &options) {
return SUCCESS;
}

Status StubOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) {
OpDescPtr op_desc = ge_node.GetOpDesc();
@@ -82,9 +86,9 @@ Status StubOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) {
name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(),
TypeUtils::DataTypeToSerialString(data_type).c_str());
REPORT_CALL_ERROR(
"E19999", "CalcTensorMemSize failed for op[%s:%s] out[%zu] mem size, mem_size=%ld, format=%s, data_type=%s.",
name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(),
TypeUtils::DataTypeToSerialString(data_type).c_str());
"E19999", "CalcTensorMemSize failed for op[%s:%s] out[%zu] mem size, mem_size=%ld, format=%s, data_type=%s.",
name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(),
TypeUtils::DataTypeToSerialString(data_type).c_str());
return FAILED;
}
GELOGI("Calc op[%s:%s] out[%zu] mem size is %ld, format=%s, data_type=%s.", name.c_str(), type.c_str(), i,

tests/st/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.h → tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.h View File


tests/st/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.cc → tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.cc View File

@@ -63,7 +63,9 @@ Status StubOpsKernelInfoStore::Finalize() {
return SUCCESS;
}

void StubOpsKernelInfoStore::GetAllOpsKernelInfo(map<string, OpInfo> &infos) const { infos = op_info_map_; }
void StubOpsKernelInfoStore::GetAllOpsKernelInfo(map<string, OpInfo> &infos) const {
infos = op_info_map_;
}

bool StubOpsKernelInfoStore::CheckSupported(const OpDescPtr &op_desc, std::string &) const {
if (op_desc == nullptr) {

tests/st/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.h → tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.h View File

@@ -53,7 +53,9 @@ class GE_FUNC_VISIBILITY StubOpsKernelInfoStore : public OpsKernelInfoStore {
Status Finalize() override;
bool CheckSupported(const OpDescPtr &op_desc, std::string &reason) const override;
void GetAllOpsKernelInfo(std::map<std::string, ge::OpInfo> &infos) const override;
std::string GetOpsKernelStoreName() const { return store_name_; }
std::string GetOpsKernelStoreName() const {
return store_name_;
}

StubOpsKernelInfoStore(const StubOpsKernelInfoStore &ops_kernel_store) = delete;
StubOpsKernelInfoStore(const StubOpsKernelInfoStore &&ops_kernel_store) = delete;

tests/st/framework/utils/builder/graph_builder_utils.cc → tests/framework/utils/builder/graph_builder_utils.cc View File


tests/st/framework/utils/builder/graph_builder_utils.h → tests/framework/utils/builder/graph_builder_utils.h View File

@@ -29,7 +29,9 @@ namespace ge {
namespace st {
class ComputeGraphBuilder {
public:
explicit ComputeGraphBuilder(const std::string &name) { graph_ = std::make_shared<ComputeGraph>(name); }
explicit ComputeGraphBuilder(const std::string &name) {
graph_ = std::make_shared<ComputeGraph>(name);
}
NodePtr AddNode(const std::string &name, const std::string &type, int in_cnt, int out_cnt,
Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT,
std::vector<int64_t> shape = {1, 1, 224, 224});

tests/st/framework/utils/builder/tensor_builder_utils.cc → tests/framework/utils/builder/tensor_builder_utils.cc View File


tests/st/framework/utils/builder/tensor_builder_utils.h → tests/framework/utils/builder/tensor_builder_utils.h View File


+ 0
- 4
tests/st/CMakeLists.txt View File

@@ -1,6 +1,2 @@
project(graphengine_st)

include(cmake/graphengine.cmake)

add_subdirectory(framework)
add_subdirectory(testcase)

+ 0
- 17
tests/st/framework/framework.cc View File

@@ -1,17 +0,0 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd

* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "framework.h"

+ 1
- 1
tests/st/testcase/CMakeLists.txt View File

@@ -6,7 +6,7 @@ target_include_directories(graph_engine_test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
)

set_target_properties(graph_engine_test PROPERTIES CXX_STANDARD 11)
set_target_properties(graph_engine_test PROPERTIES CXX_STANDARD 17)

target_link_libraries(graph_engine_test PRIVATE gtest gtest_main framework)



+ 74
- 78
tests/st/testcase/test_framework_dummy.cc View File

@@ -19,13 +19,13 @@
#include "external/ge/ge_api.h"
#include "graph/debug/ge_attr_define.h"
#include "framework/common/types.h"
#include "framework.h"
#include "framework/utils/builder/graph_builder_utils.h"
#include "builder/graph_builder_utils.h"
#include "graph/operator_reg.h"
#include "graph/operator.h"
#define protected public
#define private public
#include "graph/utils/op_desc_utils.h"
#include "ge_graph_dsl/graph_dsl.h"
#undef protected
#undef private

@@ -33,83 +33,83 @@ using namespace std;
using namespace ge;
namespace {
/** data a = 2;
* for(int i =0; i<5; ++i){
* a=a * 2;
* }
* return a;
* ----------------------------------------------|
* | const(5) exit const(1) |
* | \ / \ |
* data(i)--Enter--merge--less--loopcond--switch-----add-----nextiteration
* \________________\___/
* ------\------------------------|
* | \ const(2) |
* | \ \ |
* data(a)--Enter--merge--switch------mul-----nextiteration
* \
* exit
* \
* netoutput
*
**/
Graph BuildV1ControlFlowGraph(){
* for(int i =0; i<5; ++i){
* a=a * 2;
* }
* return a;
* ----------------------------------------------|
* | const(5) exit const(1) |
* | \ / \ |
* data(i)--Enter--merge--less--loopcond--switch-----add-----nextiteration
* \________________\___/
* ------\------------------------|
* | \ const(2) |
* | \ \ |
* data(a)--Enter--merge--switch------mul-----nextiteration
* \
* exit
* \
* netoutput
*
**/
Graph BuildV1ControlFlowGraph() {
// build graph
st::ComputeGraphBuilder graphBuilder("g1");
auto data_i = graphBuilder.AddNode("data_i",DATA,1,1);
auto enter_i = graphBuilder.AddNode("enter_i",ENTER,1,1);
auto data_i = graphBuilder.AddNode("data_i", DATA, 1, 1);
auto enter_i = graphBuilder.AddNode("enter_i", ENTER, 1, 1);
ge::AttrUtils::SetStr(enter_i->GetOpDesc(), ENTER_ATTR_FRAME_NAME, "1");
auto merge_i = graphBuilder.AddNode("merge_i",MERGE,2,1);
auto const_5 = graphBuilder.AddNode("const_5",CONSTANT,0,1);
auto less = graphBuilder.AddNode("less",LESS,2,1);
auto loopcond = graphBuilder.AddNode("loopcond",LOOPCOND,1,1,FORMAT_NCHW,DT_BOOL);
auto switch_i = graphBuilder.AddNode("switch_i",SWITCH,2,2);
auto exit_i = graphBuilder.AddNode("switch_i",EXIT,1,1);
auto const_1 = graphBuilder.AddNode("const_1",CONSTANT,0,1);
auto add = graphBuilder.AddNode("add",ADD,2,1);
auto next_iteration_i = graphBuilder.AddNode("next_iteration_i",NEXTITERATION,1,1);
auto merge_i = graphBuilder.AddNode("merge_i", MERGE, 2, 1);
auto const_5 = graphBuilder.AddNode("const_5", CONSTANT, 0, 1);
auto less = graphBuilder.AddNode("less", LESS, 2, 1);
auto loopcond = graphBuilder.AddNode("loopcond", LOOPCOND, 1, 1, FORMAT_NCHW, DT_BOOL);
auto switch_i = graphBuilder.AddNode("switch_i", SWITCH, 2, 2);
auto exit_i = graphBuilder.AddNode("switch_i", EXIT, 1, 1);
auto const_1 = graphBuilder.AddNode("const_1", CONSTANT, 0, 1);
auto add = graphBuilder.AddNode("add", ADD, 2, 1);
auto next_iteration_i = graphBuilder.AddNode("next_iteration_i", NEXTITERATION, 1, 1);

auto data_a = graphBuilder.AddNode("data_a",DATA,1,1);
auto enter_a = graphBuilder.AddNode("enter_a",ENTER,1,1);
auto data_a = graphBuilder.AddNode("data_a", DATA, 1, 1);
auto enter_a = graphBuilder.AddNode("enter_a", ENTER, 1, 1);
ge::AttrUtils::SetStr(enter_a->GetOpDesc(), ENTER_ATTR_FRAME_NAME, "1");
auto merge_a = graphBuilder.AddNode("merge_a",MERGE,2,1);
auto switch_a = graphBuilder.AddNode("switch_a",SWITCH,2,2);
auto exit_a = graphBuilder.AddNode("exit_a",EXIT,1,1);
auto mul = graphBuilder.AddNode("mul",MUL,2,1);
auto const_2 = graphBuilder.AddNode("const_2",CONSTANT,0,1);
auto next_iteration_a = graphBuilder.AddNode("next_iteration_a",NEXTITERATION,1,1);
auto netoutput = graphBuilder.AddNode("netoutput",NETOUTPUT,2,2);
auto merge_a = graphBuilder.AddNode("merge_a", MERGE, 2, 1);
auto switch_a = graphBuilder.AddNode("switch_a", SWITCH, 2, 2);
auto exit_a = graphBuilder.AddNode("exit_a", EXIT, 1, 1);
auto mul = graphBuilder.AddNode("mul", MUL, 2, 1);
auto const_2 = graphBuilder.AddNode("const_2", CONSTANT, 0, 1);
auto next_iteration_a = graphBuilder.AddNode("next_iteration_a", NEXTITERATION, 1, 1);
auto netoutput = graphBuilder.AddNode("netoutput", NETOUTPUT, 2, 2);
// i = i+1
graphBuilder.AddDataEdge(data_i, 0, enter_i,0);
graphBuilder.AddDataEdge(enter_i, 0, merge_i,0);
graphBuilder.AddDataEdge(next_iteration_i, 0, merge_i,1);
graphBuilder.AddDataEdge(merge_i, 0, less,0);
graphBuilder.AddDataEdge(const_5, 0, less,1);
graphBuilder.AddDataEdge(less, 0, loopcond,0);
graphBuilder.AddDataEdge(loopcond, 0, switch_i,1);
graphBuilder.AddDataEdge(merge_i, 0, switch_i,0);
graphBuilder.AddDataEdge(switch_i, 0, exit_i,0);
graphBuilder.AddDataEdge(switch_i, 1, add,0);
graphBuilder.AddDataEdge(const_1, 0, add,1);
graphBuilder.AddDataEdge(add, 0, next_iteration_i,0);
graphBuilder.AddDataEdge(exit_i, 0, netoutput,1);
graphBuilder.AddDataEdge(data_i, 0, enter_i, 0);
graphBuilder.AddDataEdge(enter_i, 0, merge_i, 0);
graphBuilder.AddDataEdge(next_iteration_i, 0, merge_i, 1);
graphBuilder.AddDataEdge(merge_i, 0, less, 0);
graphBuilder.AddDataEdge(const_5, 0, less, 1);
graphBuilder.AddDataEdge(less, 0, loopcond, 0);
graphBuilder.AddDataEdge(loopcond, 0, switch_i, 1);
graphBuilder.AddDataEdge(merge_i, 0, switch_i, 0);
graphBuilder.AddDataEdge(switch_i, 0, exit_i, 0);
graphBuilder.AddDataEdge(switch_i, 1, add, 0);
graphBuilder.AddDataEdge(const_1, 0, add, 1);
graphBuilder.AddDataEdge(add, 0, next_iteration_i, 0);
graphBuilder.AddDataEdge(exit_i, 0, netoutput, 1);
// a=a*2
graphBuilder.AddDataEdge(data_a, 0, enter_a,0);
graphBuilder.AddDataEdge(enter_a, 0, merge_a,0);
graphBuilder.AddDataEdge(next_iteration_a, 0, merge_a,1);
graphBuilder.AddDataEdge(loopcond, 0, switch_a,1);
graphBuilder.AddDataEdge(merge_a, 0, switch_a,0);
graphBuilder.AddDataEdge(switch_a, 0, exit_a,0);
graphBuilder.AddDataEdge(switch_a, 1, mul,0);
graphBuilder.AddDataEdge(const_2, 0, mul,1);
graphBuilder.AddDataEdge(mul, 0, next_iteration_a,0);
graphBuilder.AddDataEdge(exit_a, 0, netoutput,0);
graphBuilder.AddDataEdge(data_a, 0, enter_a, 0);
graphBuilder.AddDataEdge(enter_a, 0, merge_a, 0);
graphBuilder.AddDataEdge(next_iteration_a, 0, merge_a, 1);
graphBuilder.AddDataEdge(loopcond, 0, switch_a, 1);
graphBuilder.AddDataEdge(merge_a, 0, switch_a, 0);
graphBuilder.AddDataEdge(switch_a, 0, exit_a, 0);
graphBuilder.AddDataEdge(switch_a, 1, mul, 0);
graphBuilder.AddDataEdge(const_2, 0, mul, 1);
graphBuilder.AddDataEdge(mul, 0, next_iteration_a, 0);
graphBuilder.AddDataEdge(exit_a, 0, netoutput, 0);
// set const weight
int64_t dims_size = 1;
vector<int64_t> data_vec = {5};
for_each(data_vec.begin(), data_vec.end(), [&](int64_t &data) { dims_size *= data; });
vector<int32_t> data_value_vec(dims_size, 1);
GeTensorDesc data_tensor_desc(GeShape(data_vec), FORMAT_NCHW, DT_INT32);
GeTensorPtr data_tensor = make_shared<GeTensor>(data_tensor_desc, (uint8_t *)data_value_vec.data(),
GeTensorPtr data_tensor = make_shared<GeTensor>(data_tensor_desc, (uint8_t *) data_value_vec.data(),
data_value_vec.size() * sizeof(int32_t));
OpDescUtils::SetWeights(const_5->GetOpDesc(), data_tensor);
OpDescUtils::SetWeights(const_2->GetOpDesc(), data_tensor);
@@ -117,7 +117,7 @@ Graph BuildV1ControlFlowGraph(){

return graphBuilder.GetGraph();
}
}
} // namespace
class FrameworkTest : public testing::Test {
protected:
void SetUp() {
@@ -126,23 +126,19 @@ class FrameworkTest : public testing::Test {
auto ret = ge::GEInitialize(options);
EXPECT_EQ(ret, SUCCESS);
}
void TearDown() {
}
void TearDown() {}
};

/// data data
/// \ /
/// add
TEST_F(FrameworkTest, test_framework_add) {
// build graph
st::ComputeGraphBuilder graphBuilder("g1");
auto data1 = graphBuilder.AddNode("data1",DATA,1,1);
auto data2 = graphBuilder.AddNode("data2",DATA,1,1);
auto add = graphBuilder.AddNode("add",ADD,2,1);
graphBuilder.AddDataEdge(data1, 0, add,0);
graphBuilder.AddDataEdge(data2, 0, add,1);
Graph graph = graphBuilder.GetGraph();
DEF_GRAPH(g1) {
CHAIN(NODE("data1", DATA)->NODE("add", ADD));
CHAIN(NODE("data2", DATA)->NODE("add"));
});

auto graph = ToGeGraph(g1);
// new session & add graph
map<AscendString, AscendString> options;
Session session(options);
@@ -174,7 +170,7 @@ TEST_F(FrameworkTest, test_framework_add) {
* \
* netoutput
*
**/
**/
TEST_F(FrameworkTest, test_framework_v1_control_flow) {
// build graph
Graph graph = BuildV1ControlFlowGraph();


Loading…
Cancel
Save