@@ -50,7 +50,7 @@ CommentPragmas: '^ IWYU pragma:' | |||||
CompactNamespaces: false | CompactNamespaces: false | ||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true | ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||||
ConstructorInitializerIndentWidth: 4 | ConstructorInitializerIndentWidth: 4 | ||||
ContinuationIndentWidth: 2 | |||||
ContinuationIndentWidth: 4 | |||||
Cpp11BracedListStyle: true | Cpp11BracedListStyle: true | ||||
DerivePointerAlignment: true | DerivePointerAlignment: true | ||||
DisableFormat: false | DisableFormat: false | ||||
@@ -144,7 +144,6 @@ build_graphengine() | |||||
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_UT=ON" | CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_UT=ON" | ||||
fi | fi | ||||
if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then | if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then | ||||
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_ST=ON" | CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_ST=ON" | ||||
fi | fi | ||||
@@ -176,7 +175,7 @@ build_graphengine() | |||||
TARGET="ge_compiler atc_atc.bin ge_executor_shared ${TARGET}" | TARGET="ge_compiler atc_atc.bin ge_executor_shared ${TARGET}" | ||||
elif [ "X$ENABLE_GE_ST" = "Xon" ] | elif [ "X$ENABLE_GE_ST" = "Xon" ] | ||||
then | then | ||||
TARGET="ge_graph_dsl_test graph_engine_test" | |||||
TARGET="ge_graph_dsl_test ge_running_env_test graph_engine_test" | |||||
elif [ "X$ENABLE_GE_UT" = "Xon" ] | elif [ "X$ENABLE_GE_UT" = "Xon" ] | ||||
then | then | ||||
TARGET="ut_libgraph ut_libge_multiparts_utest ut_libge_others_utest ut_libge_kernel_utest ut_libge_distinct_load_utest" | TARGET="ut_libgraph ut_libge_multiparts_utest ut_libge_others_utest ut_libge_kernel_utest ut_libge_distinct_load_utest" | ||||
@@ -244,13 +243,13 @@ if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then | |||||
mkdir -p ${OUTPUT_PATH}/plugin/opskernel | mkdir -p ${OUTPUT_PATH}/plugin/opskernel | ||||
cp ${BUILD_PATH}/tests/framework/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}/engine_conf.json ${OUTPUT_PATH}/plugin/nnengine/ge_config | ||||
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/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 | #prepare st execution bin | ||||
cp ${BUILD_PATH}/tests/st/testcase/graph_engine_test ${OUTPUT_PATH} | cp ${BUILD_PATH}/tests/st/testcase/graph_engine_test ${OUTPUT_PATH} | ||||
cp ${BUILD_PATH}/tests/framework/ge_running_env/tests/ge_running_env_test ${OUTPUT_PATH} | |||||
cp ${BUILD_PATH}/tests/framework/ge_graph_dsl/tests/ge_graph_dsl_test ${OUTPUT_PATH} | cp ${BUILD_PATH}/tests/framework/ge_graph_dsl/tests/ge_graph_dsl_test ${OUTPUT_PATH} | ||||
#execute st testcase | #execute st testcase | ||||
RUN_TEST_CASE=${OUTPUT_PATH}/ge_running_env_test && ${RUN_TEST_CASE} | |||||
RUN_TEST_CASE=${OUTPUT_PATH}/graph_engine_test && ${RUN_TEST_CASE} | RUN_TEST_CASE=${OUTPUT_PATH}/graph_engine_test && ${RUN_TEST_CASE} | ||||
RUN_TEST_CASE=${OUTPUT_PATH}/ge_graph_dsl_test && ${RUN_TEST_CASE} | RUN_TEST_CASE=${OUTPUT_PATH}/ge_graph_dsl_test && ${RUN_TEST_CASE} | ||||
if [[ "$?" -ne 0 ]]; then | if [[ "$?" -ne 0 ]]; then | ||||
@@ -16,6 +16,7 @@ | |||||
#include "ge_runtime/task/hccl_task.h" | #include "ge_runtime/task/hccl_task.h" | ||||
#include <algorithm> | #include <algorithm> | ||||
#include "framework/common/util.h" | |||||
#include "ge_runtime/task/task_factory.h" | #include "ge_runtime/task/task_factory.h" | ||||
#include "common/opskernel/ops_kernel_info_store.h" | #include "common/opskernel/ops_kernel_info_store.h" | ||||
#include "common/opskernel/ge_task_info.h" | #include "common/opskernel/ge_task_info.h" | ||||
@@ -23,13 +23,46 @@ | |||||
void dav_log(int module_id, const char *fmt, ...) {} | void dav_log(int module_id, const char *fmt, ...) {} | ||||
void DlogErrorInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } | |||||
static int log_level = DLOG_ERROR; | |||||
#define __DO_PRINT() \ | |||||
do { \ | |||||
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); \ | |||||
printf("%s \n", fmt_buff); \ | |||||
} while (0) | |||||
void DlogErrorInner(int module_id, const char *fmt, ...) { | |||||
if (log_level > DLOG_ERROR) { | |||||
return; | |||||
} | |||||
__DO_PRINT(); | |||||
} | |||||
void DlogWarnInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } | |||||
void DlogWarnInner(int module_id, const char *fmt, ...) { | |||||
if (log_level > DLOG_WARN) { | |||||
return; | |||||
} | |||||
__DO_PRINT(); | |||||
} | |||||
void DlogInfoInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } | |||||
void DlogInfoInner(int module_id, const char *fmt, ...) { | |||||
if (log_level > DLOG_INFO) { | |||||
return; | |||||
} | |||||
__DO_PRINT(); | |||||
} | |||||
void DlogDebugInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } | |||||
void DlogDebugInner(int module_id, const char *fmt, ...) { | |||||
if (log_level > DLOG_DEBUG) { | |||||
return; | |||||
} | |||||
__DO_PRINT(); | |||||
} | |||||
void DlogEventInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } | void DlogEventInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } | ||||
@@ -39,30 +72,25 @@ void DlogWithKVInner(int module_id, int level, KeyValue *pst_kv_array, int kv_nu | |||||
dav_log(module_id, fmt); | dav_log(module_id, fmt); | ||||
} | } | ||||
int dlog_setlevel(int module_id, int level, int enable_event) { return DLOG_DEBUG; } | |||||
int dlog_setlevel(int module_id, int level, int enable_event) { | |||||
log_level = level; | |||||
return log_level; | |||||
} | |||||
int dlog_getlevel(int module_id, int *enable_event) { return DLOG_DEBUG; } | |||||
int dlog_getlevel(int module_id, int *enable_event) { return log_level; } | |||||
int CheckLogLevel(int moduleId, int logLevel) | |||||
{ | |||||
return 1; | |||||
} | |||||
int CheckLogLevel(int moduleId, int log_level_check) { return log_level >= log_level_check; } | |||||
/** | /** | ||||
* @ingroup plog | * @ingroup plog | ||||
* @brief DlogReportInitialize: init log in service process before all device setting. | * @brief DlogReportInitialize: init log in service process before all device setting. | ||||
* @return: 0: SUCCEED, others: FAILED | * @return: 0: SUCCEED, others: FAILED | ||||
*/ | */ | ||||
int DlogReportInitialize() { | |||||
return 0; | |||||
} | |||||
int DlogReportInitialize() { return 0; } | |||||
/** | /** | ||||
* @ingroup plog | * @ingroup plog | ||||
* @brief DlogReportFinalize: release log resource in service process after all device reset. | * @brief DlogReportFinalize: release log resource in service process after all device reset. | ||||
* @return: 0: SUCCEED, others: FAILED | * @return: 0: SUCCEED, others: FAILED | ||||
*/ | */ | ||||
int DlogReportFinalize() { | |||||
return 0; | |||||
} | |||||
int DlogReportFinalize() { return 0; } |
@@ -15,8 +15,8 @@ | |||||
include(cmake/graphengine.cmake) | include(cmake/graphengine.cmake) | ||||
add_subdirectory(easy_graph) | add_subdirectory(easy_graph) | ||||
add_subdirectory(stub_engine) | |||||
add_subdirectory(ge_graph_dsl) | add_subdirectory(ge_graph_dsl) | ||||
add_subdirectory(ge_running_env) | |||||
file(GLOB_RECURSE UTILS_SRC CONFIGURE_DEPENDS | file(GLOB_RECURSE UTILS_SRC CONFIGURE_DEPENDS | ||||
"utils/*.cc" | "utils/*.cc" | ||||
@@ -29,4 +29,4 @@ target_include_directories(framework | |||||
) | ) | ||||
set_target_properties(framework PROPERTIES CXX_STANDARD 11) | set_target_properties(framework PROPERTIES CXX_STANDARD 11) | ||||
target_link_libraries(framework PUBLIC ge_graph_dsl graphengine fe) | |||||
target_link_libraries(framework PUBLIC ge_graph_dsl ge_with_env) |
@@ -150,7 +150,7 @@ set_target_properties(metadef_graph PROPERTIES CXX_STANDARD 11) | |||||
# ---- Target : Local engine ---- | # ---- Target : Local engine ---- | ||||
add_library(ge_local_engine SHARED ${LOCAL_ENGINE_SRC} ${METADEF_REGISTER_SRCS}) | |||||
add_library(ge_local_engine SHARED ${LOCAL_ENGINE_SRC}) | |||||
target_include_directories(ge_local_engine | target_include_directories(ge_local_engine | ||||
PUBLIC | PUBLIC | ||||
@@ -169,38 +169,11 @@ target_compile_options(ge_local_engine PRIVATE | |||||
target_link_libraries(ge_local_engine PUBLIC | target_link_libraries(ge_local_engine PUBLIC | ||||
$<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} | $<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} | ||||
metadef_graph | |||||
-lrt -ldl -lpthread -lgcov | -lrt -ldl -lpthread -lgcov | ||||
) | ) | ||||
set_target_properties(ge_local_engine PROPERTIES CXX_STANDARD 11) | set_target_properties(ge_local_engine PROPERTIES CXX_STANDARD 11) | ||||
# ---- Target : Host engine ---- | |||||
add_library(host_cpu_engine SHARED ${HOST_ENGINE_SRC}) | |||||
target_include_directories(host_cpu_engine | |||||
PUBLIC | |||||
"${INCLUDE_DIRECTORIES}" | |||||
"${GE_CODE_DIR}/ge/host_cpu_engine" | |||||
) | |||||
target_compile_definitions(host_cpu_engine PRIVATE | |||||
google=ascend_private | |||||
FMK_SUPPORT_DUMP | |||||
) | |||||
target_compile_options(host_cpu_engine PRIVATE | |||||
-g --coverage -fprofile-arcs -ftest-coverage | |||||
-Werror=format | |||||
) | |||||
target_link_libraries(host_cpu_engine PUBLIC | |||||
$<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} metadef_graph -lrt -ldl -lpthread -lgcov | |||||
) | |||||
set_target_properties(host_cpu_engine PROPERTIES CXX_STANDARD 11) | |||||
# ---- Target : engine plugin---- | # ---- Target : engine plugin---- | ||||
# | # | ||||
@@ -273,4 +246,4 @@ target_link_libraries(graphengine PUBLIC | |||||
) | ) | ||||
set_target_properties(graphengine PROPERTIES CXX_STANDARD 11) | set_target_properties(graphengine PROPERTIES CXX_STANDARD 11) | ||||
add_dependencies(graphengine host_cpu_engine ge_local_engine nnengine engine_conf.json optimizer_priority.pbtxt) | |||||
add_dependencies(graphengine ge_local_engine nnengine engine_conf.json optimizer_priority.pbtxt) |
@@ -21,6 +21,7 @@ | |||||
#include "ge_graph_dsl/ge.h" | #include "ge_graph_dsl/ge.h" | ||||
#include "ge_graph_dsl/op_desc/op_box.h" | #include "ge_graph_dsl/op_desc/op_box.h" | ||||
#include "ge_graph_dsl/op_desc/op_desc_cfg.h" | #include "ge_graph_dsl/op_desc/op_desc_cfg.h" | ||||
#include "graph/ge_attr_value.h" | |||||
#include "graph/op_desc.h" | #include "graph/op_desc.h" | ||||
GE_NS_BEGIN | GE_NS_BEGIN | ||||
@@ -29,19 +30,32 @@ struct OpDescCfgBox : OpBox, private OpDescCfg { | |||||
OpDescCfgBox(const OpType &opType); | OpDescCfgBox(const OpType &opType); | ||||
OpDescCfgBox &InCnt(int in_cnt); | OpDescCfgBox &InCnt(int in_cnt); | ||||
OpDescCfgBox &OutCnt(int out_cnt); | OpDescCfgBox &OutCnt(int out_cnt); | ||||
OpDescCfgBox &ParentNodeIndex(int node_index); | |||||
OpDescCfgBox &TensorDesc(Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT, | 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; | |||||
} | |||||
std::vector<int64_t> shape = {1, 1, 224, 224}); | |||||
OpDescCfgBox &Weight(GeTensorPtr &); | |||||
private: | |||||
template <typename Type> | |||||
OpDescCfgBox &Attr(const std::string &name, Type &&value) { | |||||
auto attrvalue = ge::GeAttrValue::CreateFrom<Type>(std::forward<Type>(value)); | |||||
attrs_.emplace(std::make_pair(name, attrvalue)); | |||||
return *this; | |||||
} | |||||
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; | |||||
} | |||||
OpDescCfgBox &Attr(const std::string &name, int value); | |||||
OpDescCfgBox &Attr(const std::string &name, const char *value); | |||||
OpDescPtr Build(const ::EG_NS::NodeId &id) const override; | OpDescPtr Build(const ::EG_NS::NodeId &id) const override; | ||||
void UpdateAttrs(OpDescPtr&) const; | |||||
std::map<std::string, GeAttrValue> attrs_; | |||||
private: | |||||
void UpdateAttrs(OpDescPtr &) const; | |||||
std::map<std::string, GeAttrValue> attrs_; | |||||
}; | }; | ||||
#define OP_CFG(optype) ::GE_NS::OpDescCfgBox(optype) | #define OP_CFG(optype) ::GE_NS::OpDescCfgBox(optype) | ||||
@@ -17,8 +17,8 @@ | |||||
#include "ge_graph_dsl/op_desc/op_desc_cfg_box.h" | #include "ge_graph_dsl/op_desc/op_desc_cfg_box.h" | ||||
#include "easy_graph/infra/status.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_repo.h" | ||||
#include "ge_graph_dsl/op_desc/op_desc_cfg.h" | |||||
#include "external/graph/gnode.h" | #include "external/graph/gnode.h" | ||||
#include "graph/debug/ge_attr_define.h" | |||||
#include "graph/ge_tensor.h" | #include "graph/ge_tensor.h" | ||||
using ::EG_NS::Status; | using ::EG_NS::Status; | ||||
@@ -44,6 +44,26 @@ OpDescCfgBox &OpDescCfgBox::OutCnt(int out_cnt) { | |||||
return *this; | return *this; | ||||
} | } | ||||
OpDescCfgBox &OpDescCfgBox::ParentNodeIndex(int node_index) { | |||||
this->Attr(ATTR_NAME_PARENT_NODE_INDEX, node_index); | |||||
return *this; | |||||
} | |||||
OpDescCfgBox &OpDescCfgBox::Attr(const std::string &name, int value) { | |||||
this->Attr(name, (int64_t)value); | |||||
return *this; | |||||
} | |||||
OpDescCfgBox &OpDescCfgBox::Attr(const std::string &name, const char *value) { | |||||
this->Attr(name, std::string(value)); | |||||
return *this; | |||||
} | |||||
OpDescCfgBox &OpDescCfgBox::Weight(GeTensorPtr &tensor_ptr) { | |||||
this->Attr<GeAttrValue::TENSOR>(ATTR_NAME_WEIGHTS, tensor_ptr); | |||||
return *this; | |||||
} | |||||
OpDescCfgBox &OpDescCfgBox::TensorDesc(Format format, DataType data_type, std::vector<int64_t> shape) { | OpDescCfgBox &OpDescCfgBox::TensorDesc(Format format, DataType data_type, std::vector<int64_t> shape) { | ||||
default_tensor_.format_ = format; | default_tensor_.format_ = format; | ||||
default_tensor_.data_type_ = data_type; | default_tensor_.data_type_ = data_type; | ||||
@@ -51,10 +71,9 @@ OpDescCfgBox &OpDescCfgBox::TensorDesc(Format format, DataType data_type, std::v | |||||
return *this; | 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); | |||||
}); | |||||
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 { | OpDescPtr OpDescCfgBox::Build(const ::EG_NS::NodeId &id) const { | ||||
@@ -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 "gtest/gtest.h" | |||||
#include "framework/common/types.h" | |||||
#include "graph/debug/ge_attr_define.h" | |||||
#include "ge_graph_dsl/op_desc/op_desc_cfg_box.h" | |||||
#include "graph/ge_tensor.h" | |||||
#include "graph/utils/attr_utils.h" | |||||
GE_NS_BEGIN | |||||
class OpDescCfgTest : public testing::Test {}; | |||||
TEST_F(OpDescCfgTest, test_attr_set_string_success) { | |||||
auto op_ptr = OP_CFG(DATA).Attr(ENTER_ATTR_FRAME_NAME, "1").Build("data1"); | |||||
ge::GeAttrValue ret; | |||||
op_ptr->GetAttr(ENTER_ATTR_FRAME_NAME, ret); | |||||
std::string value; | |||||
ret.GetValue<std::string>(value); | |||||
ASSERT_EQ(value, "1"); | |||||
} | |||||
TEST_F(OpDescCfgTest, test_attr_set_int_success) { | |||||
auto op_ptr = OP_CFG(DATA).Attr(ENTER_ATTR_FRAME_NAME, 2).Build("data1"); | |||||
ge::GeAttrValue ret; | |||||
op_ptr->GetAttr(ENTER_ATTR_FRAME_NAME, ret); | |||||
int64_t value; | |||||
ret.GetValue<int64_t>(value); | |||||
ASSERT_EQ(value, 2); | |||||
} | |||||
TEST_F(OpDescCfgTest, test_attr_set_perent_node_index_success) { | |||||
auto op_ptr = OP_CFG(DATA).ParentNodeIndex(2).Build("data1"); | |||||
ge::GeAttrValue ret; | |||||
op_ptr->GetAttr(ATTR_NAME_PARENT_NODE_INDEX, ret); | |||||
int64_t value; | |||||
ret.GetValue<int64_t>(value); | |||||
ASSERT_EQ(value, 2); | |||||
} | |||||
TEST_F(OpDescCfgTest, test_attr_set_weight_success) { | |||||
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 = std::make_shared<GeTensor>(data_tensor_desc, (uint8_t *)data_value_vec.data(), | |||||
data_value_vec.size() * sizeof(int32_t)); | |||||
auto op_ptr = OP_CFG(CONSTANT).Weight(data_tensor).Build("const1"); | |||||
ConstGeTensorPtr tensor_value; | |||||
ASSERT_TRUE(AttrUtils::GetTensor(op_ptr, ge::ATTR_NAME_WEIGHTS, tensor_value)); | |||||
ASSERT_EQ(tensor_value->GetTensorDesc().GetDataType(), DT_INT32); | |||||
} | |||||
GE_NS_END |
@@ -23,6 +23,7 @@ GE_NS_BEGIN | |||||
REGISTER_OPTYPE_DEFINE(DATA, "Data"); | REGISTER_OPTYPE_DEFINE(DATA, "Data"); | ||||
REGISTER_OPTYPE_DEFINE(HCOMALLGATHER, "HcomAllGather"); | REGISTER_OPTYPE_DEFINE(HCOMALLGATHER, "HcomAllGather"); | ||||
REGISTER_OPTYPE_DEFINE(VARIABLE, "Variable"); | REGISTER_OPTYPE_DEFINE(VARIABLE, "Variable"); | ||||
REGISTER_OPTYPE_DEFINE(CONSTANT, "Const"); | |||||
REGISTER_OPTYPE_DEFINE(CONSTANTOP, "Constant"); | REGISTER_OPTYPE_DEFINE(CONSTANTOP, "Constant"); | ||||
REGISTER_OPTYPE_DEFINE(LESS, "Less"); | REGISTER_OPTYPE_DEFINE(LESS, "Less"); | ||||
REGISTER_OPTYPE_DEFINE(MUL, "Mul"); | REGISTER_OPTYPE_DEFINE(MUL, "Mul"); | ||||
@@ -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) |
@@ -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_running_env_inc INTERFACE) | |||||
target_include_directories(ge_running_env_inc INTERFACE ./) |
@@ -14,23 +14,22 @@ | |||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_HOST_OP_H_ | |||||
#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_HOST_OP_H_ | |||||
#ifndef H1D9F4FDE_BB21_4DE4_AC7E_751920B45039 | |||||
#define H1D9F4FDE_BB21_4DE4_AC7E_751920B45039 | |||||
#include "stub_engine/ops_kernel_store/op/op.h" | |||||
#include "fake_ns.h" | |||||
#include "opskernel_manager/ops_kernel_manager.h" | |||||
#include "register/ops_kernel_builder_registry.h" | |||||
namespace ge { | |||||
namespace st { | |||||
class GE_FUNC_VISIBILITY HostOp : public Op { | |||||
public: | |||||
HostOp(const Node &node, RunContext &run_context) : Op(node, run_context) {} | |||||
~HostOp() override = default; | |||||
HostOp &operator=(const HostOp &op) = delete; | |||||
HostOp(const HostOp &op) = delete; | |||||
FAKE_NS_BEGIN | |||||
Status Run() override; | |||||
struct EnvInstaller { | |||||
virtual void InstallTo(std::map<string, OpsKernelInfoStorePtr>&) const {} | |||||
virtual void InstallTo(std::map<string, GraphOptimizerPtr>&) const {} | |||||
virtual void InstallTo(std::map<string, OpsKernelBuilderPtr>&) const {} | |||||
virtual void Install() const {} | |||||
}; | }; | ||||
} // namespace st | |||||
} // namespace ge | |||||
#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_HOST_OP_H_ | |||||
FAKE_NS_END | |||||
#endif |
@@ -0,0 +1,56 @@ | |||||
/** | |||||
* 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 HAF5E9BF2_752F_4E03_B0A5_E1B912A5FA24 | |||||
#define HAF5E9BF2_752F_4E03_B0A5_E1B912A5FA24 | |||||
#include <string> | |||||
#include "fake_ns.h" | |||||
#include "ge_running_env/env_installer.h" | |||||
#include "common/opskernel/ops_kernel_info_types.h" | |||||
#include "opskernel_manager/ops_kernel_manager.h" | |||||
#include "register/ops_kernel_builder_registry.h" | |||||
#include "fake_ops_kernel_builder.h" | |||||
#include "fake_ops_kernel_info_store.h" | |||||
FAKE_NS_BEGIN | |||||
using FakeOpsKernelBuilderPtr = std::shared_ptr<FakeOpsKernelBuilder>; | |||||
using FakeOpsKernelInfoStorePtr = std::shared_ptr<FakeOpsKernelInfoStore>; | |||||
struct FakeEngine : EnvInstaller { | |||||
FakeEngine(const std::string& engine_name); | |||||
FakeEngine& KernelBuilder(FakeOpsKernelBuilderPtr); | |||||
FakeEngine& KernelInfoStore(FakeOpsKernelInfoStorePtr); | |||||
FakeEngine& KernelInfoStore(const std::string&); | |||||
private: | |||||
void InstallTo(std::map<string, OpsKernelInfoStorePtr>&) const override; | |||||
void InstallTo(std::map<string, OpsKernelBuilderPtr>&) const override; | |||||
private: | |||||
template <typename BasePtr, typename SubClass> | |||||
void InstallFor(std::map<string, BasePtr>& maps, const std::map<std::string, std::shared_ptr<SubClass>>&) const; | |||||
private: | |||||
std::string engine_name_; | |||||
std::set<std::string> info_store_names_; | |||||
std::map<std::string, FakeOpsKernelBuilderPtr> custom_builders_; | |||||
std::map<std::string, FakeOpsKernelInfoStorePtr> custom_info_stores_; | |||||
}; | |||||
FAKE_NS_END | |||||
#endif |
@@ -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 H7AEFF0EA_9FDE_487F_8562_2917A2D48EA2 | |||||
#define H7AEFF0EA_9FDE_487F_8562_2917A2D48EA2 | |||||
#define FAKE_NS ge | |||||
#define FAKE_NS_BEGIN namespace FAKE_NS { | |||||
#define FAKE_NS_END } | |||||
#define USING_STUB_NS using namespace FAKE_NS; | |||||
#define FWD_DECL_STUB(type) \ | |||||
namespace FAKE_NS { \ | |||||
struct type; \ | |||||
} | |||||
#endif |
@@ -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 H737AD661_27C0_400F_8B08_29701308C5D0 | |||||
#define H737AD661_27C0_400F_8B08_29701308C5D0 | |||||
#include <string> | |||||
#include <set> | |||||
#include "fake_ns.h" | |||||
#include "ge_running_env/env_installer.h" | |||||
#include "graph/operator_factory.h" | |||||
FAKE_NS_BEGIN | |||||
struct FakeOp : EnvInstaller { | |||||
FakeOp(const std::string& op_type); | |||||
FakeOp& Inputs(const std::vector<std::string>&); | |||||
FakeOp& Outputs(const std::vector<std::string>&); | |||||
FakeOp& InferShape(InferShapeFunc); | |||||
FakeOp& InfoStoreAndBuilder(const std::string&); | |||||
private: | |||||
void Install() const override; | |||||
void InstallTo(std::map<string, OpsKernelInfoStorePtr>&) const override; | |||||
private: | |||||
const std::string op_type_; | |||||
std::vector<std::string> inputs_; | |||||
std::vector<std::string> outputs_; | |||||
InferShapeFunc info_fun_; | |||||
std::set<std::string> info_store_names_; | |||||
}; | |||||
FAKE_NS_END | |||||
#endif /* H737AD661_27C0_400F_8B08_29701308C5D0 */ |
@@ -13,39 +13,26 @@ | |||||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
#ifndef H39E4E719_91F4_4D0F_BA4F_6BA56CB1E20D | |||||
#define H39E4E719_91F4_4D0F_BA4F_6BA56CB1E20D | |||||
#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_BUILDER_H_ | |||||
#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_BUILDER_H_ | |||||
#include "fake_ns.h" | |||||
#include "common/opskernel/ops_kernel_builder.h" | |||||
#include "info_store_holder.h" | |||||
#if defined(_MSC_VER) | |||||
#ifdef FUNC_VISIBILITY | |||||
#define GE_FUNC_VISIBILITY _declspec(dllexport) | |||||
#else | |||||
#define GE_FUNC_VISIBILITY | |||||
#endif | |||||
#else | |||||
#ifdef FUNC_VISIBILITY | |||||
#define GE_FUNC_VISIBILITY __attribute__((visibility("default"))) | |||||
#else | |||||
#define GE_FUNC_VISIBILITY | |||||
#endif | |||||
#endif | |||||
FAKE_NS_BEGIN | |||||
#include "common/opskernel/ops_kernel_builder.h" | |||||
struct FakeOpsKernelBuilder : OpsKernelBuilder, InfoStoreHolder { | |||||
FakeOpsKernelBuilder(const std::string &kernel_lib_name); | |||||
FakeOpsKernelBuilder(); | |||||
namespace ge { | |||||
namespace st { | |||||
class GE_FUNC_VISIBILITY StubOpsKernelBuilder : public OpsKernelBuilder { | |||||
public: | |||||
private: | |||||
Status Initialize(const map<std::string, std::string> &options) override; | Status Initialize(const map<std::string, std::string> &options) override; | ||||
Status Finalize() override; | Status Finalize() override; | ||||
Status CalcOpRunningParam(Node &node) override; | Status CalcOpRunningParam(Node &node) override; | ||||
Status GenerateTask(const Node &node, RunContext &context, std::vector<domi::TaskDef> &tasks) override; | Status GenerateTask(const Node &node, RunContext &context, std::vector<domi::TaskDef> &tasks) override; | ||||
}; | }; | ||||
} // namespace st | |||||
} // namespace ge | |||||
#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_BUILDER_H_ | |||||
FAKE_NS_END | |||||
#endif |
@@ -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 H1EBABA85_7056_48F0_B496_E4DB68E5FED3 | |||||
#define H1EBABA85_7056_48F0_B496_E4DB68E5FED3 | |||||
#include "fake_ns.h" | |||||
#include "common/opskernel/ops_kernel_info_store.h" | |||||
#include "ge/ge_api_types.h" | |||||
#include "info_store_holder.h" | |||||
FAKE_NS_BEGIN | |||||
struct FakeOpsKernelInfoStore : OpsKernelInfoStore, InfoStoreHolder { | |||||
FakeOpsKernelInfoStore(const std::string &kernel_lib_name); | |||||
FakeOpsKernelInfoStore(); | |||||
private: | |||||
Status Initialize(const std::map<std::string, std::string> &options) override; | |||||
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; | |||||
}; | |||||
FAKE_NS_END | |||||
#endif |
@@ -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 H99C11FC4_700E_4D4D_B073_7808FA88BEBC | |||||
#define H99C11FC4_700E_4D4D_B073_7808FA88BEBC | |||||
#include "ge_running_env/fake_engine.h" | |||||
#include "fake_ns.h" | |||||
#include "opskernel_manager/ops_kernel_manager.h" | |||||
#include "register/ops_kernel_builder_registry.h" | |||||
FAKE_NS_BEGIN | |||||
struct GeRunningEnvFaker { | |||||
GeRunningEnvFaker(); | |||||
GeRunningEnvFaker &Reset(); | |||||
GeRunningEnvFaker &Install(const EnvInstaller &); | |||||
GeRunningEnvFaker &InstallDefault(); | |||||
static void BackupEnv(); | |||||
private: | |||||
void flush(); | |||||
private: | |||||
std::map<string, vector<OpInfo>> &op_kernel_info_; | |||||
std::map<string, OpsKernelInfoStorePtr> &ops_kernel_info_stores_; | |||||
std::map<string, GraphOptimizerPtr> &ops_kernel_optimizers_; | |||||
std::map<string, OpsKernelBuilderPtr> &ops_kernel_builders_; | |||||
}; | |||||
FAKE_NS_END | |||||
#endif /* H99C11FC4_700E_4D4D_B073_7808FA88BEBC */ |
@@ -13,33 +13,27 @@ | |||||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
#ifndef H7992249B_058D_40A1_94EA_52BBCB76434E | |||||
#define H7992249B_058D_40A1_94EA_52BBCB76434E | |||||
#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_H_ | |||||
#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_H_ | |||||
#include <climits> | |||||
#include <string> | |||||
#include <vector> | |||||
#include "common/ge_inner_error_codes.h" | |||||
#include "fake_ns.h" | |||||
#include "common/opskernel/ops_kernel_info_types.h" | #include "common/opskernel/ops_kernel_info_types.h" | ||||
#include "graph/node.h" | |||||
namespace ge { | |||||
namespace st { | |||||
/** | |||||
* The base class for all op. | |||||
*/ | |||||
class GE_FUNC_VISIBILITY Op { | |||||
public: | |||||
Op(const Node &node, RunContext &run_context) : run_context_(run_context), node_(node) {} | |||||
virtual ~Op() = default; | |||||
virtual Status Run() = 0; | |||||
FAKE_NS_BEGIN | |||||
struct InfoStoreHolder { | |||||
InfoStoreHolder(); | |||||
InfoStoreHolder(const std::string&); | |||||
void EngineName(std::string engine_name); | |||||
void RegistOp(std::string op_type); | |||||
std::string GetLibName(); | |||||
protected: | protected: | ||||
const RunContext &run_context_; | |||||
const Node &node_; | |||||
std::map<std::string, ge::OpInfo> op_info_map_; | |||||
std::string kernel_lib_name_; | |||||
std::string engine_name_; | |||||
}; | }; | ||||
} // namespace st | |||||
} // namespace ge | |||||
#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_H_ | |||||
FAKE_NS_END | |||||
#endif |
@@ -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. | |||||
# ============================================================================ | |||||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP" "*.c++") | |||||
# ---- Target : stub Host engine ---- | |||||
add_library(ge_with_env STATIC ${SOURCES}) | |||||
target_include_directories(ge_with_env | |||||
PUBLIC | |||||
include | |||||
) | |||||
target_include_directories(ge_with_env | |||||
PRIVATE | |||||
${CMAKE_CURRENT_SOURCE_DIR} | |||||
) | |||||
target_compile_definitions(ge_with_env PRIVATE | |||||
google=ascend_private | |||||
FMK_SUPPORT_DUMP | |||||
) | |||||
target_compile_options(ge_with_env PRIVATE | |||||
-g --coverage -fprofile-arcs -ftest-coverage | |||||
-Werror=format | |||||
) | |||||
target_link_libraries(ge_with_env PUBLIC | |||||
$<BUILD_INTERFACE:intf_pub> ge_running_env_inc graphengine -lrt -ldl -lpthread -lgcov | |||||
) | |||||
set_target_properties(ge_with_env PROPERTIES CXX_STANDARD 17) |
@@ -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. | |||||
*/ | |||||
#include "ge_running_env/fake_engine.h" | |||||
#include "ge_running_env/fake_ops_kernel_builder.h" | |||||
#include "ge_running_env/fake_ops_kernel_info_store.h" | |||||
#include "opskernel_manager/ops_kernel_manager.h" | |||||
FAKE_NS_BEGIN | |||||
FakeEngine::FakeEngine(const std::string &engine_name) : engine_name_(engine_name) {} | |||||
FakeEngine &FakeEngine::KernelInfoStore(const std::string &info_store) { | |||||
info_store_names_.insert(info_store); | |||||
return *this; | |||||
} | |||||
FakeEngine &FakeEngine::KernelInfoStore(FakeOpsKernelInfoStorePtr ptr) { | |||||
info_store_names_.insert(ptr->GetLibName()); | |||||
custom_info_stores_.insert(std::make_pair(ptr->GetLibName(), ptr)); | |||||
return *this; | |||||
} | |||||
FakeEngine &FakeEngine::KernelBuilder(FakeOpsKernelBuilderPtr builder) { | |||||
info_store_names_.insert(builder->GetLibName()); | |||||
custom_builders_.insert(std::make_pair(builder->GetLibName(), builder)); | |||||
return *this; | |||||
} | |||||
namespace { | |||||
template <typename BasePtr, typename SubClass> | |||||
void InstallDefault(std::map<string, BasePtr> &maps, const std::string &info_store_name, | |||||
const std::string &engine_name) { | |||||
auto parent_obj = std::make_shared<SubClass>(info_store_name); | |||||
if (parent_obj == nullptr) { | |||||
return; | |||||
} | |||||
parent_obj->EngineName(engine_name); | |||||
maps.insert(std::make_pair(parent_obj->GetLibName(), parent_obj)); | |||||
} | |||||
} // namespace | |||||
template <typename BasePtr, typename SubClass> | |||||
void FakeEngine::InstallFor(std::map<string, BasePtr> &maps, | |||||
const std::map<std::string, std::shared_ptr<SubClass>> &child_maps) const { | |||||
if (info_store_names_.empty()) { | |||||
InstallDefault<BasePtr, SubClass>(maps, engine_name_, engine_name_); | |||||
} else { | |||||
for (auto &info_store_name : info_store_names_) { | |||||
auto iter = child_maps.find(info_store_name); | |||||
if (iter == child_maps.end()) { | |||||
InstallDefault<BasePtr, SubClass>(maps, info_store_name, engine_name_); | |||||
} else { | |||||
maps.insert(std::make_pair(iter->second->GetLibName(), iter->second)); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
void FakeEngine::InstallTo(std::map<string, OpsKernelInfoStorePtr> &ops_kernel_info_stores) const { | |||||
InstallFor<OpsKernelInfoStorePtr, FakeOpsKernelInfoStore>(ops_kernel_info_stores, custom_info_stores_); | |||||
} | |||||
void FakeEngine::InstallTo(std::map<string, OpsKernelBuilderPtr> &ops_kernel_builders) const { | |||||
InstallFor<OpsKernelBuilderPtr, FakeOpsKernelBuilder>(ops_kernel_builders, custom_builders_); | |||||
} | |||||
FAKE_NS_END |
@@ -14,40 +14,25 @@ | |||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
#include "stub_ops_kernel_builder.h" | |||||
#include <memory> | |||||
#include "ge_running_env/fake_ops_kernel_builder.h" | |||||
#include "graph/utils/node_utils.h" | |||||
#include "common/ge_inner_error_codes.h" | #include "common/ge_inner_error_codes.h" | ||||
#include "ge/ge_api_types.h" | #include "ge/ge_api_types.h" | ||||
#include "graph/utils/node_utils.h" | #include "graph/utils/node_utils.h" | ||||
#include "graph/utils/tensor_utils.h" | #include "graph/utils/tensor_utils.h" | ||||
#include "graph/utils/type_utils.h" | #include "graph/utils/type_utils.h" | ||||
#include <securec.h> | |||||
#include "framework/common/debug/ge_log.h" | #include "framework/common/debug/ge_log.h" | ||||
#include "host_cpu_engine/common/constant/constant.h" | |||||
#include "register/ops_kernel_builder_registry.h" | |||||
#include "inc/st_types.h" | |||||
FAKE_NS_BEGIN | |||||
namespace ge { | |||||
namespace st { | |||||
REGISTER_OPS_KERNEL_BUILDER(kAicoreLibName, StubOpsKernelBuilder); | |||||
REGISTER_OPS_KERNEL_BUILDER(kVectorLibName, StubOpsKernelBuilder); | |||||
REGISTER_OPS_KERNEL_BUILDER(kAicpuLibName, StubOpsKernelBuilder); | |||||
REGISTER_OPS_KERNEL_BUILDER(kAicpuAscendLibName, StubOpsKernelBuilder); | |||||
REGISTER_OPS_KERNEL_BUILDER(kHcclLibName, StubOpsKernelBuilder); | |||||
REGISTER_OPS_KERNEL_BUILDER(kRTSLibName, StubOpsKernelBuilder); | |||||
FakeOpsKernelBuilder::FakeOpsKernelBuilder(const std::string &info_store_name) : InfoStoreHolder(info_store_name) {} | |||||
FakeOpsKernelBuilder::FakeOpsKernelBuilder() : InfoStoreHolder() {} | |||||
Status StubOpsKernelBuilder::Finalize() { | |||||
return SUCCESS; | |||||
} | |||||
Status StubOpsKernelBuilder::Initialize(const map<std::string, std::string> &options) { | |||||
return SUCCESS; | |||||
} | |||||
Status FakeOpsKernelBuilder::Finalize() { return SUCCESS; } | |||||
Status FakeOpsKernelBuilder::Initialize(const map<std::string, std::string> &options) { return SUCCESS; } | |||||
Status StubOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { | |||||
Status FakeOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { | |||||
OpDescPtr op_desc = ge_node.GetOpDesc(); | OpDescPtr op_desc = ge_node.GetOpDesc(); | ||||
if (op_desc == nullptr) { | if (op_desc == nullptr) { | ||||
GELOGE(FAILED, "[Get][OpDesc]CalcOpRunningParam failed, as op desc is null"); | |||||
REPORT_INNER_ERROR("E19999", "GetOpDesc failed."); | |||||
return FAILED; | return FAILED; | ||||
} | } | ||||
@@ -86,9 +71,9 @@ Status StubOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { | |||||
name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(), | name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(), | ||||
TypeUtils::DataTypeToSerialString(data_type).c_str()); | TypeUtils::DataTypeToSerialString(data_type).c_str()); | ||||
REPORT_CALL_ERROR( | 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; | 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, | GELOGI("Calc op[%s:%s] out[%zu] mem size is %ld, format=%s, data_type=%s.", name.c_str(), type.c_str(), i, | ||||
@@ -111,9 +96,9 @@ Status StubOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
Status StubOpsKernelBuilder::GenerateTask(const Node &node, RunContext &context, vector<domi::TaskDef> &tasks) { | |||||
Status FakeOpsKernelBuilder::GenerateTask(const Node &node, RunContext &context, vector<domi::TaskDef> &tasks) { | |||||
// no need to generate device task | // no need to generate device task | ||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
} // namespace st | |||||
} // namespace ge | |||||
FAKE_NS_END |
@@ -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. | |||||
*/ | |||||
#include "external/ge/ge_api_error_codes.h" | |||||
#include "ge_running_env/fake_ops_kernel_info_store.h" | |||||
FAKE_NS_BEGIN | |||||
FakeOpsKernelInfoStore::FakeOpsKernelInfoStore(const std::string &info_store_name) : InfoStoreHolder(info_store_name) {} | |||||
FakeOpsKernelInfoStore::FakeOpsKernelInfoStore() : InfoStoreHolder() {} | |||||
Status FakeOpsKernelInfoStore::Finalize() { | |||||
op_info_map_.clear(); | |||||
return SUCCESS; | |||||
} | |||||
Status FakeOpsKernelInfoStore::Initialize(const std::map<std::string, std::string> &options) { return SUCCESS; } | |||||
void FakeOpsKernelInfoStore::GetAllOpsKernelInfo(map<string, OpInfo> &infos) const { infos = op_info_map_; } | |||||
bool FakeOpsKernelInfoStore::CheckSupported(const OpDescPtr &op_desc, std::string &) const { | |||||
if (op_desc == nullptr) { | |||||
return false; | |||||
} | |||||
return op_info_map_.count(op_desc->GetType()) > 0; | |||||
} | |||||
FAKE_NS_END |
@@ -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 "ge_running_env/info_store_holder.h" | |||||
FAKE_NS_BEGIN | |||||
namespace { | |||||
std::string GenStoreName() { | |||||
static int store_id = 0; | |||||
return "store_" + std::to_string(store_id++); | |||||
} | |||||
} // namespace | |||||
InfoStoreHolder::InfoStoreHolder(const std::string& kernel_lib_name) : kernel_lib_name_(kernel_lib_name) {} | |||||
InfoStoreHolder::InfoStoreHolder() : kernel_lib_name_(GenStoreName()) {} | |||||
void InfoStoreHolder::RegistOp(std::string op_type) { | |||||
OpInfo default_op_info = {.engine = engine_name_, | |||||
.opKernelLib = kernel_lib_name_, | |||||
.computeCost = 0, | |||||
.flagPartial = false, | |||||
.flagAsync = false, | |||||
.isAtomic = false}; | |||||
auto iter = op_info_map_.find(op_type); | |||||
if (iter == op_info_map_.end()) { | |||||
op_info_map_.emplace(op_type, default_op_info); | |||||
} | |||||
} | |||||
void InfoStoreHolder::EngineName(std::string engine_name) { engine_name_ = engine_name; } | |||||
std::string InfoStoreHolder::GetLibName() { return kernel_lib_name_; } | |||||
FAKE_NS_END |
@@ -0,0 +1,56 @@ | |||||
/** | |||||
* 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_default_running_env.h" | |||||
#include "ge_running_env/ge_running_env_faker.h" | |||||
#include "ge_running_env/fake_op.h" | |||||
FAKE_NS_BEGIN | |||||
namespace { | |||||
std::vector<FakeEngine> default_engines = {FakeEngine("AIcoreEngine").KernelInfoStore("AiCoreLib"), | |||||
FakeEngine("VectorEngine").KernelInfoStore("VectorLib"), | |||||
FakeEngine("DNN_VM_AICPU").KernelInfoStore("AicpuLib"), | |||||
FakeEngine("DNN_VM_AICPU_ASCEND").KernelInfoStore("AicpuAscendLib"), | |||||
FakeEngine("DNN_HCCL").KernelInfoStore("HcclLib"), | |||||
FakeEngine("DNN_VM_RTS").KernelInfoStore("RTSLib")}; | |||||
std::vector<FakeOp> fake_ops = { | |||||
FakeOp(ENTER).InfoStoreAndBuilder("RTSLib"), FakeOp(MERGE).InfoStoreAndBuilder("RTSLib"), | |||||
FakeOp(SWITCH).InfoStoreAndBuilder("RTSLib"), FakeOp(LOOPCOND).InfoStoreAndBuilder("RTSLib"), | |||||
FakeOp(STREAMMERGE).InfoStoreAndBuilder("RTSLib"), FakeOp(STREAMSWITCH).InfoStoreAndBuilder("RTSLib"), | |||||
FakeOp(STREAMACTIVE).InfoStoreAndBuilder("RTSLib"), FakeOp(EXIT).InfoStoreAndBuilder("RTSLib"), | |||||
FakeOp(LESS).InfoStoreAndBuilder("AiCoreLib"), FakeOp(NEXTITERATION).InfoStoreAndBuilder("AiCoreLib"), | |||||
FakeOp(CAST).InfoStoreAndBuilder("AiCoreLib"), FakeOp(TRANSDATA).InfoStoreAndBuilder("AiCoreLib"), | |||||
FakeOp(NOOP).InfoStoreAndBuilder("AiCoreLib"), FakeOp(VARIABLE).InfoStoreAndBuilder("AiCoreLib"), | |||||
FakeOp(CONSTANT).InfoStoreAndBuilder("AiCoreLib"), FakeOp(ASSIGN).InfoStoreAndBuilder("AiCoreLib"), | |||||
FakeOp(ADD).InfoStoreAndBuilder("AiCoreLib"), FakeOp(MUL).InfoStoreAndBuilder("AiCoreLib"), | |||||
FakeOp(DATA).InfoStoreAndBuilder("AiCoreLib"), FakeOp(NETOUTPUT).InfoStoreAndBuilder("AiCoreLib"), | |||||
}; | |||||
} // namespace | |||||
void GeDefaultRunningEnv::InstallTo(GeRunningEnvFaker& ge_env) { | |||||
for (auto& fake_engine : default_engines) { | |||||
ge_env.Install(fake_engine); | |||||
} | |||||
for (auto& fake_op : fake_ops) { | |||||
ge_env.Install(fake_op); | |||||
} | |||||
} | |||||
FAKE_NS_END |
@@ -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 INC_5D044B8760CB41ABA108AE2E37E8EBDE | |||||
#define INC_5D044B8760CB41ABA108AE2E37E8EBDE | |||||
#include "ge_running_env/fake_ns.h" | |||||
FAKE_NS_BEGIN | |||||
struct GeRunningEnvFaker; | |||||
struct GeDefaultRunningEnv { | |||||
static void InstallTo(GeRunningEnvFaker&); | |||||
}; | |||||
FAKE_NS_END | |||||
#endif |
@@ -0,0 +1,109 @@ | |||||
/** | |||||
* 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 <algorithm> | |||||
#include "external/ge/ge_api.h" | |||||
#include "opskernel_manager/ops_kernel_builder_manager.h" | |||||
#include "init/gelib.h" | |||||
#include "utility" | |||||
#include "ge_running_env/ge_running_env_faker.h" | |||||
#include "ge_default_running_env.h" | |||||
#include "ge_running_env/env_installer.h" | |||||
#include "op/fake_op_repo.h" | |||||
FAKE_NS_BEGIN | |||||
namespace { | |||||
OpsKernelManager& getKernelManger() { | |||||
std::shared_ptr<GELib> instancePtr = ge::GELib::GetInstance(); | |||||
return instancePtr->OpsKernelManagerObj(); | |||||
} | |||||
struct InitEnv { | |||||
static InitEnv& GetInstance() { | |||||
static InitEnv instance; | |||||
return instance; | |||||
} | |||||
void reset(std::map<string, OpsKernelInfoStorePtr>& ops_kernel_info_stores, | |||||
std::map<string, OpsKernelBuilderPtr>& builders) { | |||||
std::set<string> remove_info_names; | |||||
for (auto iter : ops_kernel_info_stores) { | |||||
if (kernel_info_names.find(iter.first) == kernel_info_names.end()) { | |||||
remove_info_names.insert(iter.first); | |||||
} | |||||
} | |||||
for (auto info_name : remove_info_names) { | |||||
ops_kernel_info_stores.erase(info_name); | |||||
builders.erase(info_name); | |||||
} | |||||
} | |||||
private: | |||||
InitEnv() { | |||||
for (auto iter : getKernelManger().GetAllOpsKernelInfoStores()) { | |||||
kernel_info_names.insert(iter.first); | |||||
} | |||||
} | |||||
private: | |||||
std::set<string> kernel_info_names; | |||||
}; | |||||
} // namespace | |||||
GeRunningEnvFaker::GeRunningEnvFaker() | |||||
: op_kernel_info_(const_cast<std::map<string, vector<OpInfo>>&>(getKernelManger().GetAllOpsKernelInfo())), | |||||
ops_kernel_info_stores_( | |||||
const_cast<std::map<string, OpsKernelInfoStorePtr>&>(getKernelManger().GetAllOpsKernelInfoStores())), | |||||
ops_kernel_optimizers_( | |||||
const_cast<std::map<string, GraphOptimizerPtr>&>(getKernelManger().GetAllGraphOptimizerObjs())), | |||||
ops_kernel_builders_(const_cast<std::map<string, OpsKernelBuilderPtr>&>( | |||||
OpsKernelBuilderManager::Instance().GetAllOpsKernelBuilders())) { | |||||
Reset(); | |||||
} | |||||
GeRunningEnvFaker& GeRunningEnvFaker::Reset() { | |||||
InitEnv& init_env = InitEnv::GetInstance(); | |||||
FakeOpRepo::Reset(); | |||||
init_env.reset(ops_kernel_info_stores_, ops_kernel_builders_); | |||||
flush(); | |||||
return *this; | |||||
} | |||||
void GeRunningEnvFaker::BackupEnv() { InitEnv::GetInstance(); } | |||||
GeRunningEnvFaker& GeRunningEnvFaker::Install(const EnvInstaller& installer) { | |||||
installer.Install(); | |||||
installer.InstallTo(ops_kernel_info_stores_); | |||||
installer.InstallTo(ops_kernel_optimizers_); | |||||
installer.InstallTo(ops_kernel_builders_); | |||||
flush(); | |||||
return *this; | |||||
} | |||||
void GeRunningEnvFaker::flush() { | |||||
op_kernel_info_.clear(); | |||||
getKernelManger().GetOpsKernelInfo(""); | |||||
} | |||||
GeRunningEnvFaker& GeRunningEnvFaker::InstallDefault() { | |||||
Reset(); | |||||
GeDefaultRunningEnv::InstallTo(*this); | |||||
return *this; | |||||
} | |||||
FAKE_NS_END |
@@ -0,0 +1,95 @@ | |||||
/** | |||||
* 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_running_env/fake_op.h" | |||||
#include "fake_op_repo.h" | |||||
#include "ge_running_env/info_store_holder.h" | |||||
#include "graph/operator_factory.h" | |||||
FAKE_NS_BEGIN | |||||
FakeOp::FakeOp(const std::string& op_type) : op_type_(op_type) {} | |||||
FakeOp& FakeOp::Inputs(const std::vector<std::string>& inputs) { | |||||
inputs_ = inputs; | |||||
return *this; | |||||
} | |||||
FakeOp& FakeOp::Outputs(const std::vector<std::string>& outputs) { | |||||
outputs_ = outputs; | |||||
return *this; | |||||
} | |||||
FakeOp& FakeOp::InferShape(InferShapeFunc infer_fun) { | |||||
info_fun_ = infer_fun; | |||||
return *this; | |||||
} | |||||
FakeOp& FakeOp::InfoStoreAndBuilder(const std::string& name) { | |||||
info_store_names_.insert(name); | |||||
return *this; | |||||
} | |||||
namespace { | |||||
void RegistOpToInfoStore(OpsKernelInfoStorePtr& info_store, const std::string& op_type) { | |||||
if (info_store == nullptr) { | |||||
return; | |||||
} | |||||
auto holder = dynamic_cast<InfoStoreHolder*>(info_store.get()); | |||||
holder->RegistOp(op_type); | |||||
} | |||||
struct FakeOperator : Operator { | |||||
FakeOperator(const std::string& op_type) : Operator(op_type) {} | |||||
FakeOperator& RegistInputs(const std::vector<std::string>& inputs) { | |||||
for (auto& input : inputs) { | |||||
Operator::InputRegister(input); | |||||
} | |||||
return *this; | |||||
} | |||||
FakeOperator& RegistOutputs(const std::vector<std::string>& outputs) { | |||||
for (auto& output : outputs) { | |||||
Operator::OutputRegister(output); | |||||
} | |||||
return *this; | |||||
} | |||||
}; | |||||
} // namespace | |||||
void FakeOp::InstallTo(std::map<string, OpsKernelInfoStorePtr>& info_stores) const { | |||||
std::for_each(info_store_names_.begin(), info_store_names_.end(), [=, &info_stores](auto& info_store_name) { | |||||
auto iter = info_stores.find(info_store_name); | |||||
if (iter != info_stores.end()) { | |||||
RegistOpToInfoStore(iter->second, op_type_); | |||||
} | |||||
}); | |||||
} | |||||
void FakeOp::Install() const { | |||||
FakeOpRepo::Regist( | |||||
op_type_, | |||||
[op_type = this->op_type_, inputs = this->inputs_, outputs = this->outputs_](const std::string&) -> Operator { | |||||
return FakeOperator(op_type).RegistInputs(inputs).RegistOutputs(outputs); | |||||
}); | |||||
if (info_fun_) { | |||||
FakeOpRepo::Regist(op_type_, info_fun_); | |||||
} | |||||
} | |||||
FAKE_NS_END |
@@ -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 "graph/operator_factory_impl.h" | |||||
#include "ge_running_env/fake_op.h" | |||||
#include "fake_op_repo.h" | |||||
FAKE_NS_BEGIN | |||||
void FakeOpRepo::Reset() { | |||||
if (OperatorFactoryImpl::operator_creators_) { | |||||
OperatorFactoryImpl::operator_creators_->clear(); | |||||
} | |||||
if (OperatorFactoryImpl::operator_infershape_funcs_) { | |||||
OperatorFactoryImpl::operator_infershape_funcs_->clear(); | |||||
} | |||||
} | |||||
void FakeOpRepo::Regist(const std::string &operator_type, const OpCreator creator) { | |||||
OperatorFactoryImpl::RegisterOperatorCreator(operator_type, creator); | |||||
} | |||||
void FakeOpRepo::Regist(const std::string &operator_type, const InferShapeFunc infer_fun) { | |||||
OperatorFactoryImpl::RegisterInferShapeFunc(operator_type, infer_fun); | |||||
} | |||||
FAKE_NS_END |
@@ -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 DBF6CE7CD4AC4A83BA4ED4B372FC66E4 | |||||
#define DBF6CE7CD4AC4A83BA4ED4B372FC66E4 | |||||
#include "ge_running_env/fake_ns.h" | |||||
#include "graph/operator_factory.h" | |||||
FAKE_NS_BEGIN | |||||
struct FakeOpRepo { | |||||
static void Reset(); | |||||
static void Regist(const std::string &operator_type, const OpCreator); | |||||
static void Regist(const std::string &operator_type, const InferShapeFunc); | |||||
}; | |||||
FAKE_NS_END | |||||
#endif |
@@ -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_running_env_test ${SOURCES}) | |||||
target_include_directories(ge_running_env_test | |||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} | |||||
) | |||||
target_compile_options(ge_running_env_test PRIVATE | |||||
-g | |||||
) | |||||
set_target_properties(ge_running_env_test PROPERTIES CXX_STANDARD 17) | |||||
target_link_libraries(ge_running_env_test PUBLIC gtest ge_with_env) | |||||
include(CTest) | |||||
enable_testing() | |||||
add_test(NAME test COMMAND ge_running_env_test) |
@@ -0,0 +1,148 @@ | |||||
/** | |||||
* 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 "graph/operator_factory_impl.h" | |||||
#include "init/gelib.h" | |||||
#include "external/ge/ge_api.h" | |||||
#include "opskernel_manager/ops_kernel_builder_manager.h" | |||||
#include "ge_running_env/fake_ops_kernel_builder.h" | |||||
#include "ge_running_env/fake_ns.h" | |||||
#include "ge_running_env/ge_running_env_faker.h" | |||||
#include "ge_running_env/fake_op.h" | |||||
FAKE_NS_BEGIN | |||||
#define ASSERT_OPS_LIST_SIZE(list_size) \ | |||||
std::vector<AscendString> ops_list; \ | |||||
OperatorFactory::GetOpsTypeList(ops_list);\ | |||||
ASSERT_EQ(ops_list.size(), list_size); | |||||
class GeRunningEvnFakerTest : public testing::Test { | |||||
protected: | |||||
void SetUp() {} | |||||
OpsKernelManager &kernel_manager = ge::GELib::GetInstance()->OpsKernelManagerObj(); | |||||
OpsKernelBuilderManager &builder_manager = OpsKernelBuilderManager::Instance(); | |||||
}; | |||||
TEST_F(GeRunningEvnFakerTest, test_reset_running_env_is_success) { | |||||
GeRunningEnvFaker ge_env; | |||||
ge_env.Reset(); | |||||
ASSERT_OPS_LIST_SIZE(0); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 1); | |||||
ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 1); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); | |||||
ASSERT_EQ(kernel_manager.GetOpsKernelInfo(SWITCH).size(), 1); | |||||
} | |||||
TEST_F(GeRunningEvnFakerTest, test_install_fake_op_success) { | |||||
GeRunningEnvFaker ge_env; | |||||
ge_env.Install(FakeOp(DATA)).Install(FakeOp(SWITCH)); | |||||
ASSERT_OPS_LIST_SIZE(2); | |||||
ASSERT_TRUE(OperatorFactory::IsExistOp(DATA)); | |||||
ASSERT_TRUE(OperatorFactory::IsExistOp(SWITCH)); | |||||
} | |||||
TEST_F(GeRunningEvnFakerTest, test_install_fake_op_with_inputs_and_outputs_success) { | |||||
GeRunningEnvFaker ge_env; | |||||
ge_env.Install(FakeOp(ADD).Inputs({"x1", "x2"}).Outputs({"y"})); | |||||
auto add1 = OperatorFactory::CreateOperator("add1", ADD); | |||||
ASSERT_EQ(add1.GetInputsSize(), 2); | |||||
ASSERT_EQ(add1.GetOutputsSize(), 1); | |||||
ASSERT_OPS_LIST_SIZE(1); | |||||
} | |||||
TEST_F(GeRunningEvnFakerTest, test_install_fake_op_with_infer_shape_success) { | |||||
GeRunningEnvFaker ge_env; | |||||
auto infer_fun = [](Operator &op) -> graphStatus { | |||||
TensorDesc input_desc = op.GetInputDescByName("data"); | |||||
return GRAPH_SUCCESS; | |||||
}; | |||||
ASSERT_TRUE(OperatorFactoryImpl::GetInferShapeFunc(DATA) == nullptr); | |||||
ge_env.Install(FakeOp(DATA).Inputs({"data"}).InferShape(infer_fun)); | |||||
ASSERT_TRUE(OperatorFactoryImpl::GetInferShapeFunc(DATA) != nullptr); | |||||
} | |||||
TEST_F(GeRunningEvnFakerTest, test_install_engine_with_default_info_store) { | |||||
GeRunningEnvFaker ge_env; | |||||
ge_env.Install(FakeEngine("DNN_HCCL")); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 2); | |||||
ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 2); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); | |||||
ASSERT_EQ(kernel_manager.GetOpsKernelInfo(SWITCH).size(), 1); | |||||
} | |||||
TEST_F(GeRunningEvnFakerTest, test_install_engine_with_info_store_name) { | |||||
GeRunningEnvFaker ge_env; | |||||
ge_env.Install(FakeEngine("DNN_HCCL").KernelInfoStore("AiCoreLib2")) | |||||
.Install(FakeOp(SWITCH).InfoStoreAndBuilder("AiCoreLib2")); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 2); | |||||
ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 2); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); | |||||
ASSERT_EQ(kernel_manager.GetOpsKernelInfo(SWITCH).size(), 2); | |||||
} | |||||
TEST_F(GeRunningEvnFakerTest, test_install_custom_kernel_builder_success) { | |||||
struct FakeKernelBuilder : FakeOpsKernelBuilder { | |||||
Status CalcOpRunningParam(Node &node) override { | |||||
OpDescPtr op_desc = node.GetOpDesc(); | |||||
if (op_desc == nullptr) { | |||||
return FAILED; | |||||
} | |||||
return SUCCESS; | |||||
} | |||||
}; | |||||
GeRunningEnvFaker ge_env; | |||||
auto ai_core_kernel = FakeEngine("DNN_HCCL").KernelBuilder(std::make_shared<FakeKernelBuilder>()); | |||||
ge_env.Reset().Install(ai_core_kernel); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 2); | |||||
ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 2); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); | |||||
} | |||||
TEST_F(GeRunningEvnFakerTest, test_install_custom_kernel_info_store_success) { | |||||
struct FakeKernelBuilder : FakeOpsKernelInfoStore { | |||||
FakeKernelBuilder(const std::string &kernel_lib_name) : FakeOpsKernelInfoStore(kernel_lib_name) {} | |||||
bool CheckSupported(const OpDescPtr &op_desc, std::string &reason) const override { return FAILED; } | |||||
}; | |||||
GeRunningEnvFaker ge_env; | |||||
auto ai_core_kernel = FakeEngine("DNN_HCCL").KernelInfoStore(std::make_shared<FakeKernelBuilder>("AiCoreLib2")); | |||||
ge_env.Reset().Install(ai_core_kernel); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 2); | |||||
ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 2); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); | |||||
} | |||||
TEST_F(GeRunningEvnFakerTest, test_install_default_fake_engine_success) { | |||||
GeRunningEnvFaker ge_env; | |||||
ge_env.InstallDefault(); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 7); | |||||
ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 7); | |||||
ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 66); | |||||
} | |||||
FAKE_NS_END |
@@ -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. | |||||
*/ | |||||
#include <gtest/gtest.h> | |||||
#include "common/debug/log.h" | |||||
#include "external/ge/ge_api.h" | |||||
#include "ge_running_env/ge_running_env_faker.h" | |||||
using namespace std; | |||||
using namespace ge; | |||||
int main(int argc, char **argv) { | |||||
map<AscendString, AscendString> options; | |||||
ge::GEInitialize(options); | |||||
GeRunningEnvFaker::BackupEnv(); | |||||
testing::InitGoogleTest(&argc, argv); | |||||
int ret = RUN_ALL_TESTS(); | |||||
return ret; | |||||
} |
@@ -1,58 +0,0 @@ | |||||
list(APPEND INCLUDE_DIRECTORIES | |||||
"${CMAKE_CURRENT_SOURCE_DIR}" | |||||
"${GE_CODE_DIR}" | |||||
"${GE_CODE_DIR}/inc" | |||||
"${GE_CODE_DIR}/metadef/inc" | |||||
"${GE_CODE_DIR}/ge" | |||||
"${GE_CODE_DIR}/ge/inc" | |||||
"${GE_CODE_DIR}/ge/ir_build" | |||||
"${GE_CODE_DIR}/metadef" | |||||
"${GE_CODE_DIR}/metadef/graph" | |||||
"${GE_CODE_DIR}/inc/external" | |||||
"${GE_CODE_DIR}/inc/framework/common" | |||||
"${GE_CODE_DIR}/metadef/inc/external" | |||||
"${GE_CODE_DIR}/metadef/inc/external/graph" | |||||
"${GE_CODE_DIR}/metadef/inc/graph" | |||||
"${GE_CODE_DIR}/inc/framework" | |||||
"${GE_CODE_DIR}/metadef/inc/common" | |||||
"${GE_CODE_DIR}/metadef/third_party" | |||||
"${GE_CODE_DIR}/metadef/third_party/transformer/inc" | |||||
"${GE_CODE_DIR}/parser" | |||||
"${GE_CODE_DIR}/parser/parser" | |||||
"${GE_CODE_DIR}/third_party/fwkacllib/inc" | |||||
"${GE_CODE_DIR}/third_party/fwkacllib/inc/cce" | |||||
"${GE_CODE_DIR}/third_party/fwkacllib/inc/ops" | |||||
"${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain" | |||||
"${GE_CODE_DIR}/tests/ut/ge" | |||||
"${GE_CODE_DIR}/tests/ut/common" | |||||
"${CMAKE_BINARY_DIR}" | |||||
"${CMAKE_BINARY_DIR}/proto/ge" | |||||
"${CMAKE_BINARY_DIR}/proto/ge/proto" | |||||
) | |||||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP" "*.c++") | |||||
# ---- Target : stub Host engine ---- | |||||
add_library(fe SHARED ${SOURCES}) | |||||
target_include_directories(fe | |||||
PUBLIC | |||||
${INCLUDE_DIRECTORIES} | |||||
${CMAKE_CURRENT_SOURCE_DIR} | |||||
) | |||||
target_compile_definitions(fe PRIVATE | |||||
google=ascend_private | |||||
FMK_SUPPORT_DUMP | |||||
) | |||||
target_compile_options(fe PRIVATE | |||||
-g --coverage -fprofile-arcs -ftest-coverage | |||||
-Werror=format | |||||
) | |||||
target_link_libraries(fe PUBLIC | |||||
$<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} metadef_graph -lmmpa -L${GE_CODE_DIR}/third_party/prebuild/x86_64 -lrt -ldl -lpthread -lgcov | |||||
) | |||||
set_target_properties(fe PROPERTIES CXX_STANDARD 11) |
@@ -1,74 +0,0 @@ | |||||
/** | |||||
* Copyright 2020 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 "stub_engine.h" | |||||
#include <map> | |||||
#include <memory> | |||||
#include <string> | |||||
#include <securec.h> | |||||
#include "framework/common/debug/ge_log.h" | |||||
#include "common/ge/ge_util.h" | |||||
#include "inc/st_types.h" | |||||
namespace ge { | |||||
namespace st { | |||||
StubEngine &StubEngine::Instance() { | |||||
static StubEngine instance; | |||||
return instance; | |||||
} | |||||
Status StubEngine::Initialize(const std::map<string, string> &options) { | |||||
for (const auto engine_2_lib : kStubEngine2KernelLib) { | |||||
auto ops_kernel_store = MakeShared<StubOpsKernelInfoStore>(engine_2_lib.second); | |||||
if (ops_kernel_store == nullptr) { | |||||
return FAILED; | |||||
} | |||||
ops_kernel_store_map_.insert(make_pair(engine_2_lib.second, ops_kernel_store)); | |||||
} | |||||
return SUCCESS; | |||||
} | |||||
void StubEngine::GetOpsKernelInfoStores(std::map<std::string, OpsKernelInfoStorePtr> &ops_kernel_map) { | |||||
for (const auto name_2_ops_kernel_store : ops_kernel_store_map_) { | |||||
ops_kernel_map[name_2_ops_kernel_store.first] = name_2_ops_kernel_store.second; | |||||
} | |||||
} | |||||
void StubEngine::GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr> &) { | |||||
// no optimizer for host cpu engine | |||||
} | |||||
Status StubEngine::Finalize() { | |||||
return SUCCESS; | |||||
} | |||||
} // namespace st | |||||
} // namespace ge | |||||
ge::Status Initialize(const std::map<string, string> &options) { | |||||
return ge::st::StubEngine::Instance().Initialize(options); | |||||
} | |||||
void GetOpsKernelInfoStores(std::map<std::string, OpsKernelInfoStorePtr> &ops_kernel_map) { | |||||
ge::st::StubEngine::Instance().GetOpsKernelInfoStores(ops_kernel_map); | |||||
} | |||||
void GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr> &graph_optimizers) { | |||||
ge::st::StubEngine::Instance().GetGraphOptimizerObjs(graph_optimizers); | |||||
} | |||||
ge::Status Finalize() { | |||||
return ge::st::StubEngine::Instance().Finalize(); | |||||
} |
@@ -1,127 +0,0 @@ | |||||
/** | |||||
* Copyright 2020 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 GRAPH_ENGINE_LLT_STUB_ENGINE_H_ | |||||
#define GRAPH_ENGINE_LLT_STUB_ENGINE_H_ | |||||
#if defined(_MSC_VER) | |||||
#ifdef FUNC_VISIBILITY | |||||
#define GE_FUNC_VISIBILITY _declspec(dllexport) | |||||
#else | |||||
#define GE_FUNC_VISIBILITY | |||||
#endif | |||||
#else | |||||
#ifdef FUNC_VISIBILITY | |||||
#define GE_FUNC_VISIBILITY __attribute__((visibility("default"))) | |||||
#else | |||||
#define GE_FUNC_VISIBILITY | |||||
#endif | |||||
#endif | |||||
#include <map> | |||||
#include <memory> | |||||
#include <string> | |||||
#include "inc/st_types.h" | |||||
#include "common/opskernel/ops_kernel_info_store.h" | |||||
#include "common/optimizer/graph_optimizer.h" | |||||
#include "stub_engine/ops_kernel_store/stub_ops_kernel_store.h" | |||||
using OpsKernelInfoStorePtr = std::shared_ptr<ge::OpsKernelInfoStore>; | |||||
using StubOpsKernelInfoStorePtr = std::shared_ptr<ge::st::StubOpsKernelInfoStore>; | |||||
using GraphOptimizerPtr = std::shared_ptr<ge::GraphOptimizer>; | |||||
namespace ge { | |||||
namespace st { | |||||
/** | |||||
* host cpu engine. | |||||
* Used for the ops which executes on host. | |||||
*/ | |||||
class GE_FUNC_VISIBILITY StubEngine { | |||||
public: | |||||
/** | |||||
* get StubEngine instance. | |||||
* @return StubEngine instance. | |||||
*/ | |||||
static StubEngine &Instance(); | |||||
virtual ~StubEngine() = default; | |||||
/** | |||||
* When Ge start, GE will invoke this interface | |||||
* @return The status whether initialize successfully | |||||
*/ | |||||
Status Initialize(const std::map<string, string> &options); | |||||
/** | |||||
* After the initialize, GE will invoke this interface | |||||
* to get the Ops kernel Store. | |||||
* @param ops_kernel_map The host cpu's ops kernel info | |||||
*/ | |||||
void GetOpsKernelInfoStores(std::map<std::string, OpsKernelInfoStorePtr> &ops_kernel_map); | |||||
/** | |||||
* After the initialize, GE will invoke this interface | |||||
* to get the Graph Optimizer. | |||||
* @param graph_optimizers The host cpu's Graph Optimizer objs | |||||
*/ | |||||
void GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr> &graph_optimizers); | |||||
/** | |||||
* When the graph finished, GE will invoke this interface | |||||
* @return The status whether initialize successfully | |||||
*/ | |||||
Status Finalize(); | |||||
StubEngine(const StubEngine &StubEngine) = delete; | |||||
StubEngine(const StubEngine &&StubEngine) = delete; | |||||
StubEngine &operator=(const StubEngine &StubEngine) = delete; | |||||
StubEngine &operator=(StubEngine &&StubEngine) = delete; | |||||
private: | |||||
StubEngine() = default; | |||||
map<string, OpsKernelInfoStorePtr> ops_kernel_store_map_; | |||||
}; | |||||
} // namespace st | |||||
} // namespace ge | |||||
extern "C" { | |||||
/** | |||||
* When Ge start, GE will invoke this interface | |||||
* @return The status whether initialize successfully | |||||
*/ | |||||
GE_FUNC_VISIBILITY ge::Status Initialize(const map<string, string> &options); | |||||
/** | |||||
* After the initialize, GE will invoke this interface to get the Ops kernel Store | |||||
* @param ops_kernel_map The host cpu's ops kernel info | |||||
*/ | |||||
GE_FUNC_VISIBILITY void GetOpsKernelInfoStores(std::map<std::string, OpsKernelInfoStorePtr> &ops_kernel_map); | |||||
/** | |||||
* After the initialize, GE will invoke this interface to get the Graph Optimizer | |||||
* @param graph_optimizers The host cpu's Graph Optimizer objs | |||||
*/ | |||||
GE_FUNC_VISIBILITY void GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr> &graph_optimizers); | |||||
/** | |||||
* When the graph finished, GE will invoke this interface | |||||
* @return The status whether initialize successfully | |||||
*/ | |||||
GE_FUNC_VISIBILITY ge::Status Finalize(); | |||||
} | |||||
#endif // GRAPH_ENGINE_LLT_STUB_ENGINE_H_ |
@@ -1,33 +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. | |||||
*/ | |||||
#ifndef GRAPHENGINE_ST_TYPES_H | |||||
#define GRAPHENGINE_ST_TYPES_H | |||||
#include <map> | |||||
namespace ge { | |||||
namespace st { | |||||
const std::string kAicoreLibName = "AiCoreLib"; | |||||
const std::string kVectorLibName = "VectorLib"; | |||||
const std::string kAicpuLibName = "AicpuLib"; | |||||
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"}}; | |||||
} // namespace st | |||||
} // namespace ge | |||||
#endif // GRAPHENGINE_ST_TYPES_H |
@@ -1,41 +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 "inc/st_types.h" | |||||
#include "stub_engine/ops_kernel_store/op/host_op.h" | |||||
#include "framework/common/util.h" | |||||
#include "stub_engine/ops_kernel_store/op/stub_op_factory.h" | |||||
namespace ge { | |||||
namespace st { | |||||
Status HostOp::Run() { | |||||
// no need to generate device task | |||||
return SUCCESS; | |||||
} | |||||
REGISTER_OP_CREATOR(Enter, RTSLib, HostOp); | |||||
REGISTER_OP_CREATOR(Merge, RTSLib, HostOp); | |||||
REGISTER_OP_CREATOR(Switch, RTSLib, HostOp); | |||||
REGISTER_OP_CREATOR(Less, AiCoreLib, HostOp); | |||||
REGISTER_OP_CREATOR(NextIteration, AiCoreLib, HostOp); | |||||
REGISTER_OP_CREATOR(LoopCond, RTSLib, HostOp); | |||||
REGISTER_OP_CREATOR(Exit, RTSLib, HostOp); | |||||
REGISTER_OP_CREATOR(StreamMerge, RTSLib, HostOp); | |||||
REGISTER_OP_CREATOR(StreamSwitch, RTSLib, HostOp); | |||||
REGISTER_OP_CREATOR(StreamActive, RTSLib, HostOp); | |||||
REGISTER_OP_CREATOR(Cast, AiCoreLib, HostOp); | |||||
REGISTER_OP_CREATOR(Transdata, AiCoreLib, HostOp); | |||||
} // namespace st | |||||
} // namespace ge |
@@ -1,51 +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 "stub_op_factory.h" | |||||
#include "framework/common/debug/ge_log.h" | |||||
#include "common/ge_inner_error_codes.h" | |||||
#include "graph/op_desc.h" | |||||
namespace ge { | |||||
namespace st { | |||||
OpFactory &OpFactory::Instance() { | |||||
static OpFactory instance; | |||||
return instance; | |||||
} | |||||
std::shared_ptr<Op> OpFactory::CreateOp(const Node &node, RunContext &run_context) { | |||||
auto iter = op_creator_map_.find(node.GetType()); | |||||
if (iter != op_creator_map_.end()) { | |||||
return iter->second(node, run_context); | |||||
} | |||||
GELOGE(FAILED, "Not supported OP, type = %s, name = %s", node.GetType().c_str(), node.GetName().c_str()); | |||||
return nullptr; | |||||
} | |||||
void OpFactory::RegisterCreator(const std::string &type, const std::string &kernel_lib, const OP_CREATOR_FUNC &func) { | |||||
if (func == nullptr) { | |||||
GELOGW("Func is NULL."); | |||||
return; | |||||
} | |||||
if (all_store_ops_.find(kernel_lib) != all_store_ops_.end()) { | |||||
all_store_ops_[kernel_lib].emplace_back(type); | |||||
} else { | |||||
all_store_ops_[kernel_lib] = {type}; | |||||
} | |||||
} | |||||
} // namespace st | |||||
} // namespace ge |
@@ -1,109 +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. | |||||
*/ | |||||
#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_FACTORY_H_ | |||||
#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_FACTORY_H_ | |||||
#include <functional> | |||||
#include <map> | |||||
#include <memory> | |||||
#include <string> | |||||
#include <vector> | |||||
#include "common/ge/ge_util.h" | |||||
#include "stub_engine/ops_kernel_store/op/op.h" | |||||
#include "inc/st_types.h" | |||||
namespace ge { | |||||
namespace st { | |||||
using OP_CREATOR_FUNC = std::function<std::shared_ptr<Op>(const Node &, RunContext &)>; | |||||
/** | |||||
* manage all the op, support create op. | |||||
*/ | |||||
class GE_FUNC_VISIBILITY OpFactory { | |||||
public: | |||||
static OpFactory &Instance(); | |||||
/** | |||||
* @brief create Op. | |||||
* @param [in] node share ptr of node | |||||
* @param [in] run_context run context | |||||
* @return not nullptr success | |||||
* @return nullptr fail | |||||
*/ | |||||
std::shared_ptr<Op> CreateOp(const Node &node, RunContext &run_context); | |||||
/** | |||||
* @brief Register Op create function. | |||||
* @param [in] type Op type | |||||
* @param [in] func Op create func | |||||
*/ | |||||
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(std::string lib_name) const { | |||||
auto iter = all_store_ops_.find(lib_name); | |||||
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(); | |||||
} | |||||
OpFactory(const OpFactory &) = delete; | |||||
OpFactory &operator=(const OpFactory &) = delete; | |||||
OpFactory(OpFactory &&) = delete; | |||||
OpFactory &operator=(OpFactory &&) = delete; | |||||
private: | |||||
OpFactory() = default; | |||||
~OpFactory() = default; | |||||
// the op creator function map | |||||
std::map<std::string, OP_CREATOR_FUNC> op_creator_map_; | |||||
std::map<std::string, std::map<std::string, OP_CREATOR_FUNC>> lib_op_creator_map_; | |||||
std::vector<std::string> all_ops_; | |||||
std::map<std::string, vector<std::string>> all_store_ops_; | |||||
}; | |||||
class GE_FUNC_VISIBILITY OpRegistrar { | |||||
public: | |||||
OpRegistrar(const std::string &type, const std::string &kernel_lib, const OP_CREATOR_FUNC &func) { | |||||
OpFactory::Instance().RegisterCreator(type, kernel_lib, func); | |||||
} | |||||
~OpRegistrar() = default; | |||||
OpRegistrar(const OpRegistrar &) = delete; | |||||
OpRegistrar &operator=(const OpRegistrar &) = delete; | |||||
OpRegistrar(OpRegistrar &&) = delete; | |||||
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); \ | |||||
} \ | |||||
OpRegistrar g_##type##Op_creator(#type, #lib_name, Creator_##type##Op) | |||||
} // namespace st | |||||
} // namespace ge | |||||
#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_FACTORY_H_ |
@@ -1,77 +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 "stub_ops_kernel_store.h" | |||||
#include <memory> | |||||
#include "ge/ge_api_types.h" | |||||
#include "framework/common/debug/ge_log.h" | |||||
#include "graph/utils/node_utils.h" | |||||
#include "graph/utils/tensor_utils.h" | |||||
#include "graph/utils/type_utils.h" | |||||
#include "op/stub_op_factory.h" | |||||
namespace ge { | |||||
namespace st { | |||||
using domi::TaskDef; | |||||
using std::map; | |||||
using std::string; | |||||
using std::vector; | |||||
Status StubOpsKernelInfoStore::Initialize(const map<string, string> &options) { | |||||
GELOGI("StubOpsKernelInfoStore init start."); | |||||
string engine_name; | |||||
for (const auto &engine_2_lib : kStubEngine2KernelLib) { | |||||
if (engine_2_lib.second == store_name_) { | |||||
engine_name = engine_2_lib.first; | |||||
} | |||||
} | |||||
if (engine_name.empty()) { | |||||
return FAILED; | |||||
} | |||||
OpInfo default_op_info = {.engine = engine_name, | |||||
.opKernelLib = store_name_, | |||||
.computeCost = 0, | |||||
.flagPartial = false, | |||||
.flagAsync = false, | |||||
.isAtomic = false}; | |||||
// Init op_info_map_ | |||||
auto all_ops_in_store = OpFactory::Instance().GetAllOps(store_name_); | |||||
for (auto &op : all_ops_in_store) { | |||||
op_info_map_[op] = default_op_info; | |||||
} | |||||
GELOGI("StubOpsKernelInfoStore inited success. op num=%zu", op_info_map_.size()); | |||||
return SUCCESS; | |||||
} | |||||
Status StubOpsKernelInfoStore::Finalize() { | |||||
op_info_map_.clear(); | |||||
return SUCCESS; | |||||
} | |||||
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) { | |||||
return false; | |||||
} | |||||
return op_info_map_.count(op_desc->GetType()) > 0; | |||||
} | |||||
} // namespace st | |||||
} // namespace ge |
@@ -1,73 +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. | |||||
*/ | |||||
#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_INFO_H_ | |||||
#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_INFO_H_ | |||||
#if defined(_MSC_VER) | |||||
#ifdef FUNC_VISIBILITY | |||||
#define GE_FUNC_VISIBILITY _declspec(dllexport) | |||||
#else | |||||
#define GE_FUNC_VISIBILITY | |||||
#endif | |||||
#else | |||||
#ifdef FUNC_VISIBILITY | |||||
#define GE_FUNC_VISIBILITY __attribute__((visibility("default"))) | |||||
#else | |||||
#define GE_FUNC_VISIBILITY | |||||
#endif | |||||
#endif | |||||
#include <map> | |||||
#include <string> | |||||
#include <vector> | |||||
#include "common/opskernel/ops_kernel_info_store.h" | |||||
namespace ge { | |||||
namespace st { | |||||
/*const vector<std::string> kStubOpKernelLibNameVec = { | |||||
"AiCoreLib", | |||||
"AicpuLib", | |||||
"HcclLib", | |||||
"RTSLib" | |||||
};*/ | |||||
class GE_FUNC_VISIBILITY StubOpsKernelInfoStore : public OpsKernelInfoStore { | |||||
public: | |||||
StubOpsKernelInfoStore(std::string store_name) : store_name_(store_name) {} | |||||
~StubOpsKernelInfoStore() override = default; | |||||
Status Initialize(const std::map<std::string, std::string> &options) override; | |||||
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_; | |||||
} | |||||
StubOpsKernelInfoStore(const StubOpsKernelInfoStore &ops_kernel_store) = delete; | |||||
StubOpsKernelInfoStore(const StubOpsKernelInfoStore &&ops_kernel_store) = delete; | |||||
StubOpsKernelInfoStore &operator=(const StubOpsKernelInfoStore &ops_kernel_store) = delete; | |||||
StubOpsKernelInfoStore &operator=(StubOpsKernelInfoStore &&ops_kernel_store) = delete; | |||||
private: | |||||
// store op name and OpInfo key-value pair | |||||
std::map<std::string, ge::OpInfo> op_info_map_; | |||||
std::string store_name_; | |||||
}; | |||||
} // namespace st | |||||
} // namespace ge | |||||
#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_INFO_H_ |
@@ -8,7 +8,7 @@ target_include_directories(graph_engine_test | |||||
set_target_properties(graph_engine_test PROPERTIES CXX_STANDARD 17) | set_target_properties(graph_engine_test PROPERTIES CXX_STANDARD 17) | ||||
target_link_libraries(graph_engine_test PRIVATE gtest gtest_main framework) | |||||
target_link_libraries(graph_engine_test PRIVATE gtest framework) | |||||
include(CTest) | include(CTest) | ||||
enable_testing() | enable_testing() |
@@ -17,9 +17,13 @@ | |||||
#include <gtest/gtest.h> | #include <gtest/gtest.h> | ||||
#include <map> | #include <map> | ||||
#include "external/ge/ge_api.h" | #include "external/ge/ge_api.h" | ||||
#include "ge_running_env/fake_engine.h" | |||||
#include "graph/debug/ge_attr_define.h" | #include "graph/debug/ge_attr_define.h" | ||||
#include "framework/common/types.h" | #include "framework/common/types.h" | ||||
#include "builder/graph_builder_utils.h" | #include "builder/graph_builder_utils.h" | ||||
#include "ge_running_env/ge_running_env_faker.h" | |||||
#include "graph/operator_reg.h" | #include "graph/operator_reg.h" | ||||
#include "graph/operator.h" | #include "graph/operator.h" | ||||
#define protected public | #define protected public | ||||
@@ -109,8 +113,8 @@ Graph BuildV1ControlFlowGraph() { | |||||
for_each(data_vec.begin(), data_vec.end(), [&](int64_t &data) { dims_size *= data; }); | for_each(data_vec.begin(), data_vec.end(), [&](int64_t &data) { dims_size *= data; }); | ||||
vector<int32_t> data_value_vec(dims_size, 1); | vector<int32_t> data_value_vec(dims_size, 1); | ||||
GeTensorDesc data_tensor_desc(GeShape(data_vec), FORMAT_NCHW, DT_INT32); | 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(), | |||||
data_value_vec.size() * sizeof(int32_t)); | |||||
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_5->GetOpDesc(), data_tensor); | ||||
OpDescUtils::SetWeights(const_2->GetOpDesc(), data_tensor); | OpDescUtils::SetWeights(const_2->GetOpDesc(), data_tensor); | ||||
OpDescUtils::SetWeights(const_1->GetOpDesc(), data_tensor); | OpDescUtils::SetWeights(const_1->GetOpDesc(), data_tensor); | ||||
@@ -120,13 +124,9 @@ Graph BuildV1ControlFlowGraph() { | |||||
} // namespace | } // namespace | ||||
class FrameworkTest : public testing::Test { | class FrameworkTest : public testing::Test { | ||||
protected: | protected: | ||||
void SetUp() { | |||||
// ge initialize | |||||
map<AscendString, AscendString> options; | |||||
auto ret = ge::GEInitialize(options); | |||||
EXPECT_EQ(ret, SUCCESS); | |||||
} | |||||
void SetUp() { ge_env.InstallDefault(); } | |||||
void TearDown() {} | void TearDown() {} | ||||
GeRunningEnvFaker ge_env; | |||||
}; | }; | ||||
/// data data | /// data data | ||||
@@ -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. | |||||
*/ | |||||
#include <gtest/gtest.h> | |||||
#include "common/debug/log.h" | |||||
#include "external/ge/ge_api.h" | |||||
#include "ge_running_env/include/ge_running_env/ge_running_env_faker.h" | |||||
using namespace std; | |||||
using namespace ge; | |||||
int main(int argc, char **argv) { | |||||
// init the logging | |||||
map<AscendString, AscendString> options; | |||||
auto init_status = ge::GEInitialize(options); | |||||
if (init_status != SUCCESS) { | |||||
std::cout << "ge init failed , ret code:" << init_status << endl; | |||||
} | |||||
GeRunningEnvFaker::BackupEnv(); | |||||
testing::InitGoogleTest(&argc, argv); | |||||
int ret = RUN_ALL_TESTS(); | |||||
return ret; | |||||
} |