Browse Source

!2130 upgrad Ascend software package 15 Jul 22

Merge pull request !2130 from yanghaoran/master
tags/v1.8.0^0
yanghaoran Gitee 2 years ago
parent
commit
811731b922
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
100 changed files with 11807 additions and 3100 deletions
  1. +1
    -2
      CMakeLists.txt
  2. +0
    -4
      cmake/external_libs/json.cmake
  3. +4
    -5
      ge/common/model/ge_model.cc
  4. +18
    -16
      ge/common/model/ge_model.h
  5. +1
    -0
      ge/ge_runtime/CMakeLists.txt
  6. +2
    -14
      ge/ge_runtime/task/hccl_task.cc
  7. +41
    -15
      ge/ge_runtime/task/label_goto_task.cc
  8. +10
    -6
      ge/ge_runtime/task/label_goto_task.h
  9. +119
    -0
      ge/ge_runtime/task/label_manager.cc
  10. +54
    -0
      ge/ge_runtime/task/label_manager.h
  11. +11
    -14
      ge/ge_runtime/task/label_switch_task.cc
  12. +4
    -2
      ge/ge_runtime/task/label_switch_task.h
  13. +82
    -0
      inc/external/acl/acl.h
  14. +656
    -0
      inc/external/acl/acl_base.h
  15. +1237
    -0
      inc/external/acl/acl_mdl.h
  16. +532
    -0
      inc/external/acl/acl_op.h
  17. +200
    -0
      inc/external/acl/acl_op_compiler.h
  18. +485
    -0
      inc/external/acl/acl_prof.h
  19. +1031
    -0
      inc/external/acl/acl_rt.h
  20. +316
    -0
      inc/external/acl/acl_tdt.h
  21. +476
    -0
      inc/external/acl/acl_tdt_queue.h
  22. +77
    -0
      inc/external/acl/error_codes/ge_error_codes.h
  23. +123
    -0
      inc/external/acl/error_codes/rt_error_codes.h
  24. +334
    -0
      inc/external/acl/ops/acl_cblas.h
  25. +2683
    -0
      inc/external/acl/ops/acl_dvpp.h
  26. +348
    -0
      inc/external/acl/ops/acl_fv.h
  27. +14
    -14
      inc/external/ge/ge_api.h
  28. +27
    -57
      inc/external/ge/ge_api_error_codes.h
  29. +193
    -137
      inc/external/ge/ge_api_types.h
  30. +35
    -33
      inc/external/ge/ge_error_codes.h
  31. +24
    -27
      inc/external/ge/ge_ir_build.h
  32. +210
    -0
      inc/external/hccl/hccl.h
  33. +101
    -0
      inc/external/hccl/hccl_types.h
  34. +123
    -0
      inc/external/runtime/rt_error_codes.h
  35. +1
    -1
      inc/framework/common/aicpu_op.h
  36. +64
    -44
      inc/framework/common/debug/ge_log.h
  37. +89
    -172
      inc/framework/common/debug/log.h
  38. +51
    -0
      inc/framework/common/file_constant_util.h
  39. +15
    -9
      inc/framework/common/fmk_error_codes.h
  40. +1
    -1
      inc/framework/common/fmk_types.h
  41. +1
    -1
      inc/framework/common/ge_compiler_options.h
  42. +3
    -3
      inc/framework/common/ge_format_util.h
  43. +54
    -42
      inc/framework/common/ge_inner_error_codes.h
  44. +106
    -34
      inc/framework/common/ge_types.h
  45. +1
    -1
      inc/framework/common/gflags_util.h
  46. +42
    -49
      inc/framework/common/helper/model_helper.h
  47. +28
    -34
      inc/framework/common/helper/om_file_helper.h
  48. +7
    -90
      inc/framework/common/l2_cache_optimize.h
  49. +3
    -134
      inc/framework/common/op/attr_value_util.h
  50. +25
    -78
      inc/framework/common/op/ge_op_utils.h
  51. +25
    -25
      inc/framework/common/op/op_parser_util.h
  52. +12
    -16
      inc/framework/common/op_types.h
  53. +4
    -28
      inc/framework/common/profiling/ge_profiling.h
  54. +1
    -1
      inc/framework/common/profiling/ge_runner_profiling.h
  55. +220
    -0
      inc/framework/common/profiling_definitions.h
  56. +38
    -0
      inc/framework/common/runtime_tensor_desc.h
  57. +10
    -6
      inc/framework/common/scope_guard.h
  58. +30
    -24
      inc/framework/common/string_util.h
  59. +31
    -10
      inc/framework/common/taskdown_common.h
  60. +52
    -472
      inc/framework/common/types.h
  61. +191
    -196
      inc/framework/common/util.h
  62. +30
    -11
      inc/framework/engine/dnnengine.h
  63. +118
    -75
      inc/framework/executor/ge_executor.h
  64. +0
    -113
      inc/framework/ge_runtime/davinci_model.h
  65. +0
    -68
      inc/framework/ge_runtime/model_runner.h
  66. +0
    -72
      inc/framework/ge_runtime/op_info.h
  67. +0
    -405
      inc/framework/ge_runtime/task_info.h
  68. +42
    -20
      inc/framework/generator/ge_generator.h
  69. +0
    -187
      inc/framework/generator/generator_api.h
  70. +2
    -6
      inc/framework/memory/memory_api.h
  71. +3
    -3
      inc/framework/memory/memory_assigner.h
  72. +2
    -2
      inc/framework/omg/ge_init.h
  73. +1
    -1
      inc/framework/omg/model_tool.h
  74. +24
    -27
      inc/framework/omg/omg.h
  75. +14
    -41
      inc/framework/omg/omg_inner_types.h
  76. +1
    -1
      inc/framework/omg/omg_types.h
  77. +26
    -6
      inc/framework/omg/parser/model_parser.h
  78. +6
    -8
      inc/framework/omg/parser/op_parser.h
  79. +4
    -5
      inc/framework/omg/parser/parser_api.h
  80. +13
    -8
      inc/framework/omg/parser/parser_factory.h
  81. +10
    -11
      inc/framework/omg/parser/parser_inner_ctx.h
  82. +3
    -2
      inc/framework/omg/parser/parser_types.h
  83. +13
    -3
      inc/framework/omg/parser/weights_parser.h
  84. +5
    -8
      inc/framework/omg/version.h
  85. +128
    -0
      inc/framework/pne/pne_model.h
  86. +67
    -0
      inc/framework/pne/process_node_engine.h
  87. +27
    -0
      inc/framework/runtime/gert_api.h
  88. +94
    -0
      inc/framework/runtime/model_desc.h
  89. +142
    -0
      inc/framework/runtime/model_v2_executor.h
  90. +1
    -1
      metadef
  91. +107
    -0
      scripts/format_source_code.sh
  92. +5
    -8
      third_party/fwkacllib/inc/aicpu/aicpu_schedule/aicpu_op_type_list.h
  93. +72
    -3
      third_party/fwkacllib/inc/aicpu/common/aicpu_task_struct.h
  94. +9
    -7
      third_party/fwkacllib/inc/cce/fwk_adpt_struct.h
  95. +10
    -9
      third_party/fwkacllib/inc/cce/taskdown_common.hpp
  96. +52
    -0
      third_party/fwkacllib/inc/common/type_def.h
  97. +15
    -1
      third_party/fwkacllib/inc/external/runtime/rt_error_codes.h
  98. +84
    -18
      third_party/fwkacllib/inc/hccl/base.h
  99. +0
    -101
      third_party/fwkacllib/inc/hccl/hccl_types.h
  100. +0
    -52
      third_party/fwkacllib/inc/hccl/hcom.h

+ 1
- 2
CMakeLists.txt View File

@@ -125,7 +125,6 @@ else ()
message(STATUS "PLATFORM param is invalid, should be train or inference, you choose nothing!")
endif()
endif()

set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef)
set(PARSER_DIR ${CMAKE_CURRENT_LIST_DIR}/parser)
set(GE_DEPEND_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
@@ -158,6 +157,7 @@ else ()
elseif(ENABLE_MS_TESTCASES)
include(cmake/external_libs/protobuf_static.cmake)
include(cmake/external_libs/protoc.cmake)
include(cmake/external_libs/json.cmake)
include(cmake/external_libs/securec.cmake)
include(cmake/FindModule.cmake)
include(cmake/intf_pub_linux.cmake)
@@ -175,5 +175,4 @@ else ()
endif()

add_subdirectory(ge)

endif ()

+ 0
- 4
cmake/external_libs/json.cmake View File

@@ -9,10 +9,6 @@ if (GE_PB_PKG)
set(REQ_URL "${GE_PB_PKG}/libs/ge_nlohmann_json/include.zip")
set(MD5 "0dc903888211db3a0f170304cd9f3a89")
set(JSON_INCLUDE_DIR ${JSON_SRC_DIR})
#elseif (ENABLE_GITEE)
# set(REQ_URL "https://gitee.com/mirrors/JSON-for-Modern-CPP/repository/archive/v3.6.1.zip")
# set(MD5 "5bda78ce308e6cfcf614dcf1d5ff27a7")
#set(JSON_INCLUDE_DIR "${JSON_SRC_DIR}/include")
else()
set(REQ_URL "https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip")
set(MD5 "0dc903888211db3a0f170304cd9f3a89")


+ 4
- 5
ge/common/model/ge_model.cc View File

@@ -34,7 +34,6 @@ void GeModel::Init() {
}

GeModel::GeModel() {
attrs_.InitDefault();
Init();
}

@@ -78,12 +77,12 @@ void GeModel::SetPlatformVersion(const std::string &platform_version) { this->pl

void GeModel::SetPlatformType(uint8_t platform_type) { this->platform_type_ = platform_type; }

void GeModel::SetAttr(const ProtoAttrMapHelper &attrs) { attrs_ = attrs; }
void GeModel::SetAttr(const ProtoAttrMap &attrs) { attrs_ = attrs; }

ProtoAttrMapHelper GeModel::MutableAttrMap() { return attrs_; }
ProtoAttrMap &GeModel::MutableAttrMap() { return attrs_; }

ConstProtoAttrMapHelper GeModel::GetAttrMap() const {
return ConstProtoAttrMapHelper(attrs_.GetProtoOwner(), attrs_.GetProtoMsg());
ConstProtoAttrMap &GeModel::GetAttrMap() const {
return attrs_;
}

Status GeModel::GetSessionId(uint32_t model_id, uint64_t &session_id) const {


+ 18
- 16
ge/common/model/ge_model.h View File

@@ -17,24 +17,26 @@
#ifndef GE_MODEL_GE_MODEL_H_
#define GE_MODEL_GE_MODEL_H_

#include <securec.h>
#include <map>
#include <memory>
#include <string>

#include "securec.h"
#include "runtime/rt.h"
#include "common/tbe_kernel_store.h"
#include "common/cust_aicpu_kernel_store.h"
#include "framework/common/debug/log.h"
#include "framework/common/fmk_error_codes.h"
#include "framework/common/ge_types.h"
#include "graph/buffer.h"
#include "external/graph/graph.h"
#include "proto/task.pb.h"

namespace ge {
const uint32_t INVALID_MODEL_ID = 0xFFFFFFFFUL;
class GeModel : public AttrHolder {
public:
GeModel();
~GeModel() = default;
~GeModel() override = default;
GeModel(const GeModel &other) = delete;
GeModel &operator=(const GeModel &other) = delete;

@@ -55,34 +57,34 @@ class GeModel : public AttrHolder {
void SetCustAICPUKernelStore(const CustAICPUKernelStore &cust_aicpu_kernal_store);
void SetWeight(const Buffer &weights_buffer);

bool LoadTBEKernelStore(const uint8_t *const data, const size_t len);
bool loadAICPUKernelStore(const uint8_t *const data, const size_t len);

void SetName(const std::string &name);
void SetVersion(uint32_t version);
void SetVersion(const uint32_t version);
void SetPlatformVersion(const std::string &platform_version);
void SetPlatformType(uint8_t platform_type);
void SetPlatformType(const uint8_t platform_type);

void SetAttr(const ProtoAttrMapHelper &attrs);
void SetAttr(const ProtoAttrMap &attrs);

ProtoAttrMapHelper MutableAttrMap() override;
ProtoAttrMap &MutableAttrMap() override;

using AttrHolder::SetAttr;
using AttrHolder::GetAllAttrs;
using AttrHolder::GetAllAttrNames;

void SetModelId(uint32_t model_id) { model_id_ = model_id; }
void SetModelId(const uint32_t model_id) { model_id_ = model_id; }
uint32_t GetModelId() const { return model_id_; }

Status GetSessionId(uint32_t model_id, uint64_t &session_id) const;
void InsertSessionMap(uint32_t model_id, uint64_t session_id) {
model_id_to_session_id_map_.insert({model_id, session_id});
}
Status GetSessionId(const uint32_t model_id, uint64_t &session_id) const;

protected:
ConstProtoAttrMapHelper GetAttrMap() const override;
ConstProtoAttrMap &GetAttrMap() const override;

private:
void Init();

ProtoAttrMapHelper attrs_; /*lint !e148*/
ProtoAttrMap attrs_; /*lint !e148*/

Graph graph_;
std::shared_ptr<domi::ModelTaskDef> task_; /*lint !e148*/
@@ -91,9 +93,9 @@ class GeModel : public AttrHolder {
Buffer weights_buffer_; /*lint !e148*/

std::string name_;
uint32_t version_ = {0};
uint32_t version_ = {0U};
std::string platform_version_;
uint8_t platform_type_ = {0};
uint8_t platform_type_ = {0U};
uint32_t model_id_ = INVALID_MODEL_ID;
std::map<uint32_t, uint64_t> model_id_to_session_id_map_;
};


+ 1
- 0
ge/ge_runtime/CMakeLists.txt View File

@@ -16,6 +16,7 @@ set(GE_SRC_LIST
"task/label_goto_task.cc"
"task/label_set_task.cc"
"task/label_switch_task.cc"
"task/label_manager.cc"
)

add_library(ge_runtime SHARED ${GE_SRC_LIST})


+ 2
- 14
ge/ge_runtime/task/hccl_task.cc View File

@@ -53,15 +53,7 @@ HcclTask::HcclTask(const ModelContext &model_context, const std::shared_ptr<Hccl
}
}

HcclTask::~HcclTask() {
if (workspace_mem_ != nullptr) {
rtError_t rt_ret = rtFree(workspace_mem_);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "rtFree workspace_mem_ failed! ret: 0x%X.", rt_ret);
}
workspace_mem_ = nullptr;
}
}
HcclTask::~HcclTask() {}

bool HcclTask::Distribute() {
// Ops kernel info store
@@ -80,11 +72,7 @@ bool HcclTask::Distribute() {
SetSecondaryStream();

if (task_info_->workspace_size() > 0) {
rtError_t rt_ret = rtMalloc(&workspace_mem_, task_info_->workspace_size(), RT_MEMORYINFO_HBM);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
return false;
}
workspace_mem_ = task_info_->workspace_addr();
}

GELOGI("HcclTaskInfo Distribute Start. begin to call function LoadTask in hccl.");


+ 41
- 15
ge/ge_runtime/task/label_goto_task.cc View File

@@ -16,33 +16,46 @@

#include "ge_runtime/task/label_goto_task.h"
#include "ge_runtime/task/task_factory.h"
#include "framework/common/util.h"

namespace ge {
namespace model_runner {
LabelGotoTask::LabelGotoTask(const ModelContext &model_context, const std::shared_ptr<LabelGotoTaskInfo> &task_info)
: TaskRepeater<LabelGotoTaskInfo>(model_context, task_info), task_info_(task_info) {
: TaskRepeater<LabelGotoTaskInfo>(model_context, task_info),
task_info_(task_info),
stream_(nullptr),
index_value_(nullptr) {
if (task_info_ == nullptr) {
GELOGW("task_info_ is null!");
return;
}
auto stream_list = model_context.stream_list();
auto label_list = model_context.label_list();
rt_model_handle_ = model_context.rt_model_handle();
uint32_t stream_id = task_info->stream_id();
uint32_t label_id = task_info->label_id();
label_id_ = task_info->label_id();
GELOGI("Stream list size:%zu, stream id:%u.", stream_list.size(), stream_id);
GELOGI("Label list size:%zu, label id:%u.", label_list.size(), label_id);
if (stream_id >= stream_list.size() || label_id >= label_list.size()) {
GELOGI("Label list size:%zu, label id:%u.", label_list.size(), label_id_);
if (stream_id >= stream_list.size() || label_id_ >= label_list.size()) {
GELOGW("Stream/Label id invalid.");
return;
}
stream_ = stream_list[stream_id];
label_ = label_list[label_id];
label_manager_ = LabelManager::GetInstance();
if (label_manager_ == nullptr) {
GELOGW("Get label manager instance failed.");
return;
}
label_info_ = label_manager_->GetLabelInfo(rt_model_handle_, {label_id_}, label_list);
}

LabelGotoTask::~LabelGotoTask() {
GE_FREE_RT_LOG(label_info_);
GE_FREE_RT_LOG(index_value_);
if (index_value_ != nullptr) {
rtError_t rt_ret = rtFree(index_value_);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "rtFree index_value_ failed! ret: 0x%X.", rt_ret);
}
index_value_ = nullptr;
}
}

bool LabelGotoTask::Distribute() {
@@ -94,21 +107,34 @@ bool LabelGotoTask::CheckParamValid() {
return false;
}

if (label_ == nullptr) {
GELOGE(PARAM_INVALID, "label is null!");
if (label_info_ == nullptr) {
GELOGE(PARAM_INVALID, "label info is null!");
return false;
}

if (label_info_ != nullptr) {
GELOGE(PARAM_INVALID, "label_info_ has dirty data.");
return false;
if (index_value_ == nullptr) {
rtError_t rt_ret = rtMalloc(&index_value_, sizeof(uint64_t), RT_MEMORY_HBM);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
return false;
}

uint64_t index = 0;
rt_ret = rtMemcpy(index_value_, sizeof(uint64_t), &index, sizeof(index), RT_MEMCPY_HOST_TO_DEVICE);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
return false;
}
}

if (index_value_ != nullptr) {
GELOGE(PARAM_INVALID, "index_value_ has dirty data.");
void *label_info = label_info_->GetLabelInfo();
rtError_t rt_ret = rtLabelSwitchByIndex(index_value_, 1, label_info, stream_);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
return false;
}

GELOGI("DistributeTask end.");
return true;
}



+ 10
- 6
ge/ge_runtime/task/label_goto_task.h View File

@@ -18,7 +18,11 @@
#define GE_GE_RUNTIME_TASK_LABEL_GOTO_TASK_H_

#include <memory>
#include <vector>
#include <map>
#include <mutex>
#include "ge_runtime/task/task.h"
#include "ge_runtime/task/label_manager.h"

namespace ge {
namespace model_runner {
@@ -31,13 +35,13 @@ class LabelGotoTask : public TaskRepeater<LabelGotoTaskInfo> {
bool Distribute() override;

private:
bool CheckParamValid();

std::shared_ptr<LabelGotoTaskInfo> task_info_;
void *stream_{nullptr};
void *label_{nullptr};
void *label_info_{nullptr};
void *index_value_{nullptr};
void *stream_;
std::shared_ptr<LabelGuard> label_info_;
void *index_value_;
uint32_t label_id_;
rtModel_t rt_model_handle_;
std::shared_ptr<LabelManager> label_manager_;
};
} // namespace model_runner
} // namespace ge


+ 119
- 0
ge/ge_runtime/task/label_manager.cc View File

@@ -0,0 +1,119 @@
/**
* 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_runtime/task/label_manager.h"
#include <algorithm>
#include <string>
#include "runtime/mem.h"
#include "runtime/rt_model.h"
#include "common/ge_inner_error_codes.h"
#include "framework/common/debug/ge_log.h"

namespace ge {
namespace model_runner {
std::weak_ptr<LabelManager> LabelManager::instance_;
std::mutex LabelManager::instance_mutex_;

template <class T>
static std::string GetVectorString(const std::vector<T> &vec) {
std::string ret;
for (size_t i = 0; i < vec.size(); ++i) {
if (i != 0) {
ret.push_back(',');
}
ret += std::to_string(vec[i]);
}
return ret;
}

LabelGuard::~LabelGuard() {
void *label_info = GetLabelInfo();
if (label_info != nullptr) {
rtError_t rt_ret = rtFree(label_info);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "rtFree label_info failed! ret: 0x%X.", rt_ret);
}
}
}

std::shared_ptr<LabelManager> LabelManager::GetInstance() {
std::lock_guard<std::mutex> lock(instance_mutex_);
auto instance = instance_.lock();
if (instance != nullptr) {
return instance;
}

instance = std::make_shared<LabelManager>();
instance_ = instance;
return instance;
}

std::shared_ptr<LabelGuard> LabelManager::GetLabelInfo(rtModel_t model, const std::vector<uint32_t> &label_ids,
const std::vector<void *> &all_label) {
std::lock_guard<std::mutex> lock(model_info_mapping_mutex_);
rtError_t rt_ret;
auto model_iter = model_info_mapping_.find(model);
if (model_iter == model_info_mapping_.end()) {
model_info_mapping_.emplace(model, std::map<std::string, std::weak_ptr<LabelGuard>>());
model_iter = model_info_mapping_.find(model);
}

std::string label_id_str = GetVectorString(label_ids);
auto &label_map = model_iter->second;
auto label_iter = label_map.find(label_id_str);
if (label_iter != label_map.end()) {
auto label_guard = label_iter->second.lock();
if (label_guard != nullptr) {
GELOGI("model %p find same label id %s.", model, label_id_str.c_str());
return label_guard;
}
}

GELOGI("Alloc label id %s for model %p.", label_id_str.c_str(), model);
void *label_info;
std::vector<void *> label_list;
bool status = true;
std::transform(label_ids.begin(), label_ids.end(), std::back_inserter(label_list),
[&all_label, &status](uint32_t idx) -> void * {
if (idx >= all_label.size()) {
GELOGE(PARAM_INVALID, "Invalid label id %u, all label list size %zu.", idx, all_label.size());
status = false;
return nullptr;
}
return all_label[idx];
});
if (!status) {
GELOGE(PARAM_INVALID, "Get label info failed.");
return nullptr;
}
uint32_t label_info_size = sizeof(rtLabelDevInfo) * label_list.size();
rt_ret = rtMalloc(&label_info, label_info_size, RT_MEMORY_HBM);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
return nullptr;
}

rt_ret = rtLabelListCpy(label_list.data(), label_list.size(), label_info, label_info_size);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
return nullptr;
}

auto label_guard = std::make_shared<LabelGuard>(label_info);
label_map.emplace(label_id_str, label_guard);
return label_guard;
}
} // namespace model_runner
} // namespace ge

+ 54
- 0
ge/ge_runtime/task/label_manager.h View File

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

#include <vector>
#include <memory>
#include <mutex>
#include <map>
#include <runtime/base.h>

namespace ge {
namespace model_runner {
class LabelGuard {
public:
explicit LabelGuard(void *label_info) : label_info_(reinterpret_cast<uintptr_t>(label_info)) {}
~LabelGuard();
void *GetLabelInfo() { return reinterpret_cast<void *>(label_info_); }

private:
uintptr_t label_info_;
};

class LabelManager {
public:
static std::shared_ptr<LabelManager> GetInstance();
std::shared_ptr<LabelGuard> GetLabelInfo(rtModel_t model, const std::vector<uint32_t> &label_ids,
const std::vector<void *> &all_label);

private:
std::mutex model_info_mapping_mutex_;
std::map<rtModel_t, std::map<std::string, std::weak_ptr<LabelGuard>>> model_info_mapping_;

static std::weak_ptr<LabelManager> instance_;
static std::mutex instance_mutex_;
};


} // namespace model_runner
} // namespace ge
#endif // GE_GE_RUNTIME_TASK_LABEL_MANAGER_H_

+ 11
- 14
ge/ge_runtime/task/label_switch_task.cc View File

@@ -24,14 +24,14 @@ LabelSwitchTask::LabelSwitchTask(const ModelContext &model_context,
: TaskRepeater<LabelSwitchTaskInfo>(model_context, task_info),
task_info_(task_info),
stream_(nullptr),
all_label_resource_(),
label_info_(nullptr) {
if (task_info_ == nullptr) {
GELOGW("task_info_ is null!");
return;
}

all_label_resource_ = model_context.label_list();
rt_model_handle_ = model_context.rt_model_handle();
auto all_label_resource = model_context.label_list();
auto stream_list = model_context.stream_list();
uint32_t stream_id = task_info->stream_id();
GELOGI("Stream list size:%zu, stream id:%u.", stream_list.size(), stream_id);
@@ -40,18 +40,16 @@ LabelSwitchTask::LabelSwitchTask(const ModelContext &model_context,
return;
}
stream_ = stream_list[stream_id];
}

LabelSwitchTask::~LabelSwitchTask() {
if (label_info_ != nullptr) {
rtError_t rt_ret = rtFree(label_info_);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "rtFree fwkOpBuf failed! ret: 0x%X.", rt_ret);
}
label_info_ = nullptr;
label_manager_ = LabelManager::GetInstance();
if (label_manager_ == nullptr) {
GELOGW("Get label manager instance failed.");
return;
}
label_info_ = label_manager_->GetLabelInfo(rt_model_handle_, task_info_->label_list(), all_label_resource);
}

LabelSwitchTask::~LabelSwitchTask() {}

bool LabelSwitchTask::Distribute() {
GELOGI("LabelSwitchTask Distribute start.");
if (!CheckParamValid()) {
@@ -117,8 +115,8 @@ bool LabelSwitchTask::CheckParamValid() {
return false;
}

if (label_info_ != nullptr) {
GELOGE(PARAM_INVALID, "label_info_ has dirty data.");
if (label_info_ == nullptr) {
GELOGE(PARAM_INVALID, "CopyLabelList failed, label info is null.");
return false;
}

@@ -126,6 +124,5 @@ bool LabelSwitchTask::CheckParamValid() {
}

REGISTER_TASK(TaskInfoType::LABEL_SWITCH, LabelSwitchTask, LabelSwitchTaskInfo);

} // namespace model_runner
} // namespace ge

+ 4
- 2
ge/ge_runtime/task/label_switch_task.h View File

@@ -19,6 +19,7 @@

#include <memory>
#include "ge_runtime/task/task.h"
#include "ge_runtime/task/label_manager.h"

namespace ge {
namespace model_runner {
@@ -35,8 +36,9 @@ class LabelSwitchTask : public TaskRepeater<LabelSwitchTaskInfo> {

std::shared_ptr<LabelSwitchTaskInfo> task_info_;
void *stream_;
std::vector<void *> all_label_resource_;
void *label_info_;
rtModel_t rt_model_handle_;
std::shared_ptr<LabelGuard> label_info_;
std::shared_ptr<LabelManager> label_manager_;
};
} // namespace model_runner
} // namespace ge


+ 82
- 0
inc/external/acl/acl.h View File

@@ -0,0 +1,82 @@
/**
* Copyright 2019-2022 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_EXTERNAL_ACL_ACL_H_
#define INC_EXTERNAL_ACL_ACL_H_

#include "acl_rt.h"
#include "acl_op.h"
#include "acl_mdl.h"

#ifdef __cplusplus
extern "C" {
#endif

// Current version is 1.2.0
#define ACL_MAJOR_VERSION 1
#define ACL_MINOR_VERSION 2
#define ACL_PATCH_VERSION 0

/**
* @ingroup AscendCL
* @brief acl initialize
*
* @par Restriction
* The aclInit interface can be called only once in a process
* @param configPath [IN] the config path,it can be NULL
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclInit(const char *configPath);

/**
* @ingroup AscendCL
* @brief acl finalize
*
* @par Restriction
* Need to call aclFinalize before the process exits.
* After calling aclFinalize,the services cannot continue to be used normally.
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclFinalize();

/**
* @ingroup AscendCL
* @brief query ACL interface version
*
* @param majorVersion[OUT] ACL interface major version
* @param minorVersion[OUT] ACL interface minor version
* @param patchVersion[OUT] ACL interface patch version
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclrtGetVersion(int32_t *majorVersion, int32_t *minorVersion, int32_t *patchVersion);

/**
* @ingroup AscendCL
* @brief get recent error message
*
* @retval null for failed
* @retval OtherValues success
*/
ACL_FUNC_VISIBILITY const char *aclGetRecentErrMsg();

#ifdef __cplusplus
}
#endif

#endif // INC_EXTERNAL_ACL_ACL_H_

+ 656
- 0
inc/external/acl/acl_base.h View File

@@ -0,0 +1,656 @@
/**
* Copyright 2019-2022 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_EXTERNAL_ACL_ACL_BASE_H_
#define INC_EXTERNAL_ACL_ACL_BASE_H_

#include <stdint.h>
#include <stddef.h>
#include "error_codes/rt_error_codes.h"
#include "error_codes/ge_error_codes.h"

#ifdef __cplusplus
extern "C" {
#endif

#if defined(_MSC_VER)
#ifdef FUNC_VISIBILITY
#define ACL_FUNC_VISIBILITY _declspec(dllexport)
#else
#define ACL_FUNC_VISIBILITY
#endif
#else
#ifdef FUNC_VISIBILITY
#define ACL_FUNC_VISIBILITY __attribute__((visibility("default")))
#else
#define ACL_FUNC_VISIBILITY
#endif
#endif

#ifdef __GNUC__
#define ACL_DEPRECATED __attribute__((deprecated))
#define ACL_DEPRECATED_MESSAGE(message) __attribute__((deprecated(message)))
#elif defined(_MSC_VER)
#define ACL_DEPRECATED __declspec(deprecated)
#define ACL_DEPRECATED_MESSAGE(message) __declspec(deprecated(message))
#else
#define ACL_DEPRECATED
#define ACL_DEPRECATED_MESSAGE(message)
#endif

typedef void *aclrtStream;
typedef void *aclrtEvent;
typedef void *aclrtContext;
typedef int aclError;
typedef uint16_t aclFloat16;
typedef struct aclDataBuffer aclDataBuffer;
typedef struct aclTensorDesc aclTensorDesc;

static const int ACL_ERROR_NONE = 0;
static const int ACL_SUCCESS = 0;

static const int ACL_ERROR_INVALID_PARAM = 100000;
static const int ACL_ERROR_UNINITIALIZE = 100001;
static const int ACL_ERROR_REPEAT_INITIALIZE = 100002;
static const int ACL_ERROR_INVALID_FILE = 100003;
static const int ACL_ERROR_WRITE_FILE = 100004;
static const int ACL_ERROR_INVALID_FILE_SIZE = 100005;
static const int ACL_ERROR_PARSE_FILE = 100006;
static const int ACL_ERROR_FILE_MISSING_ATTR = 100007;
static const int ACL_ERROR_FILE_ATTR_INVALID = 100008;
static const int ACL_ERROR_INVALID_DUMP_CONFIG = 100009;
static const int ACL_ERROR_INVALID_PROFILING_CONFIG = 100010;
static const int ACL_ERROR_INVALID_MODEL_ID = 100011;
static const int ACL_ERROR_DESERIALIZE_MODEL = 100012;
static const int ACL_ERROR_PARSE_MODEL = 100013;
static const int ACL_ERROR_READ_MODEL_FAILURE = 100014;
static const int ACL_ERROR_MODEL_SIZE_INVALID = 100015;
static const int ACL_ERROR_MODEL_MISSING_ATTR = 100016;
static const int ACL_ERROR_MODEL_INPUT_NOT_MATCH = 100017;
static const int ACL_ERROR_MODEL_OUTPUT_NOT_MATCH = 100018;
static const int ACL_ERROR_MODEL_NOT_DYNAMIC = 100019;
static const int ACL_ERROR_OP_TYPE_NOT_MATCH = 100020;
static const int ACL_ERROR_OP_INPUT_NOT_MATCH = 100021;
static const int ACL_ERROR_OP_OUTPUT_NOT_MATCH = 100022;
static const int ACL_ERROR_OP_ATTR_NOT_MATCH = 100023;
static const int ACL_ERROR_OP_NOT_FOUND = 100024;
static const int ACL_ERROR_OP_LOAD_FAILED = 100025;
static const int ACL_ERROR_UNSUPPORTED_DATA_TYPE = 100026;
static const int ACL_ERROR_FORMAT_NOT_MATCH = 100027;
static const int ACL_ERROR_BIN_SELECTOR_NOT_REGISTERED = 100028;
static const int ACL_ERROR_KERNEL_NOT_FOUND = 100029;
static const int ACL_ERROR_BIN_SELECTOR_ALREADY_REGISTERED = 100030;
static const int ACL_ERROR_KERNEL_ALREADY_REGISTERED = 100031;
static const int ACL_ERROR_INVALID_QUEUE_ID = 100032;
static const int ACL_ERROR_REPEAT_SUBSCRIBE = 100033;
static const int ACL_ERROR_STREAM_NOT_SUBSCRIBE = 100034;
static const int ACL_ERROR_THREAD_NOT_SUBSCRIBE = 100035;
static const int ACL_ERROR_WAIT_CALLBACK_TIMEOUT = 100036;
static const int ACL_ERROR_REPEAT_FINALIZE = 100037;
static const int ACL_ERROR_NOT_STATIC_AIPP = 100038;
static const int ACL_ERROR_COMPILING_STUB_MODE = 100039;
static const int ACL_ERROR_GROUP_NOT_SET = 100040;
static const int ACL_ERROR_GROUP_NOT_CREATE = 100041;
static const int ACL_ERROR_PROF_ALREADY_RUN = 100042;
static const int ACL_ERROR_PROF_NOT_RUN = 100043;
static const int ACL_ERROR_DUMP_ALREADY_RUN = 100044;
static const int ACL_ERROR_DUMP_NOT_RUN = 100045;
static const int ACL_ERROR_PROF_REPEAT_SUBSCRIBE = 148046;
static const int ACL_ERROR_PROF_API_CONFLICT = 148047;
static const int ACL_ERROR_INVALID_MAX_OPQUEUE_NUM_CONFIG = 148048;
static const int ACL_ERROR_INVALID_OPP_PATH = 148049;
static const int ACL_ERROR_OP_UNSUPPORTED_DYNAMIC = 148050;
static const int ACL_ERROR_RELATIVE_RESOURCE_NOT_CLEARED = 148051;
static const int ACL_ERROR_UNSUPPORTED_JPEG = 148052;

static const int ACL_ERROR_BAD_ALLOC = 200000;
static const int ACL_ERROR_API_NOT_SUPPORT = 200001;
static const int ACL_ERROR_INVALID_DEVICE = 200002;
static const int ACL_ERROR_MEMORY_ADDRESS_UNALIGNED = 200003;
static const int ACL_ERROR_RESOURCE_NOT_MATCH = 200004;
static const int ACL_ERROR_INVALID_RESOURCE_HANDLE = 200005;
static const int ACL_ERROR_FEATURE_UNSUPPORTED = 200006;
static const int ACL_ERROR_PROF_MODULES_UNSUPPORTED = 200007;

static const int ACL_ERROR_STORAGE_OVER_LIMIT = 300000;

static const int ACL_ERROR_INTERNAL_ERROR = 500000;
static const int ACL_ERROR_FAILURE = 500001;
static const int ACL_ERROR_GE_FAILURE = 500002;
static const int ACL_ERROR_RT_FAILURE = 500003;
static const int ACL_ERROR_DRV_FAILURE = 500004;
static const int ACL_ERROR_PROFILING_FAILURE = 500005;

#define ACL_TENSOR_SHAPE_RANGE_NUM 2
#define ACL_TENSOR_VALUE_RANGE_NUM 2
#define ACL_UNKNOWN_RANK 0xFFFFFFFFFFFFFFFE

typedef enum {
ACL_DT_UNDEFINED = -1,
ACL_FLOAT = 0,
ACL_FLOAT16 = 1,
ACL_INT8 = 2,
ACL_INT32 = 3,
ACL_UINT8 = 4,
ACL_INT16 = 6,
ACL_UINT16 = 7,
ACL_UINT32 = 8,
ACL_INT64 = 9,
ACL_UINT64 = 10,
ACL_DOUBLE = 11,
ACL_BOOL = 12,
ACL_STRING = 13,
ACL_COMPLEX64 = 16,
ACL_COMPLEX128 = 17,
ACL_BF16 = 27
} aclDataType;

typedef enum {
ACL_FORMAT_UNDEFINED = -1,
ACL_FORMAT_NCHW = 0,
ACL_FORMAT_NHWC = 1,
ACL_FORMAT_ND = 2,
ACL_FORMAT_NC1HWC0 = 3,
ACL_FORMAT_FRACTAL_Z = 4,
ACL_FORMAT_NC1HWC0_C04 = 12,
ACL_FORMAT_HWCN = 16,
ACL_FORMAT_NDHWC = 27,
ACL_FORMAT_FRACTAL_NZ = 29,
ACL_FORMAT_NCDHW = 30,
ACL_FORMAT_NDC1HWC0 = 32,
ACL_FRACTAL_Z_3D = 33
} aclFormat;

typedef enum {
ACL_DEBUG = 0,
ACL_INFO = 1,
ACL_WARNING = 2,
ACL_ERROR = 3,
} aclLogLevel;

typedef enum { ACL_MEMTYPE_DEVICE = 0, ACL_MEMTYPE_HOST = 1, ACL_MEMTYPE_HOST_COMPILE_INDEPENDENT = 2 } aclMemType;

/**
* @ingroup AscendCL
* @brief Converts data of type aclFloat16 to data of type float
*
* @param value [IN] Data to be converted
*
* @retval Transformed data
*/
ACL_FUNC_VISIBILITY float aclFloat16ToFloat(aclFloat16 value);

/**
* @ingroup AscendCL
* @brief Converts data of type float to data of type aclFloat16
*
* @param value [IN] Data to be converted
*
* @retval Transformed data
*/
ACL_FUNC_VISIBILITY aclFloat16 aclFloatToFloat16(float value);

/**
* @ingroup AscendCL
* @brief create data of aclDataBuffer
*
* @param data [IN] pointer to data
* @li Need to be managed by the user,
* call aclrtMalloc interface to apply for memory,
* call aclrtFree interface to release memory
*
* @param size [IN] size of data in bytes
*
* @retval pointer to created instance. nullptr if run out of memory
*
* @see aclrtMalloc | aclrtFree
*/
ACL_FUNC_VISIBILITY aclDataBuffer *aclCreateDataBuffer(void *data, size_t size);

/**
* @ingroup AscendCL
* @brief destroy data of aclDataBuffer
*
* @par Function
* Only the aclDataBuffer type data is destroyed here.
* The memory of the data passed in when the aclDataDataBuffer interface
* is called to create aclDataBuffer type data must be released by the user
*
* @param dataBuffer [IN] pointer to the aclDataBuffer
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclCreateDataBuffer
*/
ACL_FUNC_VISIBILITY aclError aclDestroyDataBuffer(const aclDataBuffer *dataBuffer);

/**
* @ingroup AscendCL
* @brief update new data of aclDataBuffer
*
* @param dataBuffer [OUT] pointer to aclDataBuffer
* @li The old data need to be released by the user, otherwise it may occur memory leak leakage
* call aclGetDataBufferAddr interface to get old data address
* call aclrtFree interface to release memory
*
* @param data [IN] pointer to new data
* @li Need to be managed by the user,
* call aclrtMalloc interface to apply for memory,
* call aclrtFree interface to release memory
*
* @param size [IN] size of data in bytes
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclrtMalloc | aclrtFree | aclGetDataBufferAddr
*/
ACL_FUNC_VISIBILITY aclError aclUpdateDataBuffer(aclDataBuffer *dataBuffer, void *data, size_t size);

/**
* @ingroup AscendCL
* @brief get data address from aclDataBuffer
*
* @param dataBuffer [IN] pointer to the data of aclDataBuffer
*
* @retval data address
*/
ACL_FUNC_VISIBILITY void *aclGetDataBufferAddr(const aclDataBuffer *dataBuffer);

/**
* @ingroup AscendCL
* @brief get data size of aclDataBuffer
*
* @param dataBuffer [IN] pointer to the data of aclDataBuffer
*
* @retval data size
*/
ACL_DEPRECATED_MESSAGE("aclGetDataBufferSize is deprecated, use aclGetDataBufferSizeV2 instead")
ACL_FUNC_VISIBILITY uint32_t aclGetDataBufferSize(const aclDataBuffer *dataBuffer);

/**
* @ingroup AscendCL
* @brief get data size of aclDataBuffer to replace aclGetDataBufferSize
*
* @param dataBuffer [IN] pointer to the data of aclDataBuffer
*
* @retval data size
*/
ACL_FUNC_VISIBILITY size_t aclGetDataBufferSizeV2(const aclDataBuffer *dataBuffer);

/**
* @ingroup AscendCL
* @brief get size of aclDataType
*
* @param dataType [IN] aclDataType data the size to get
*
* @retval size of the aclDataType
*/
ACL_FUNC_VISIBILITY size_t aclDataTypeSize(aclDataType dataType);

// interfaces of tensor desc
/**
* @ingroup AscendCL
* @brief create data aclTensorDesc
*
* @param dataType [IN] Data types described by tensor
* @param numDims [IN] the number of dimensions of the shape
* @param dims [IN] the size of the specified dimension
* @param format [IN] tensor format
*
* @retval aclTensorDesc pointer.
* @retval nullptr if param is invalid or run out of memory
*/
ACL_FUNC_VISIBILITY aclTensorDesc *aclCreateTensorDesc(aclDataType dataType, int numDims, const int64_t *dims,
aclFormat format);

/**
* @ingroup AscendCL
* @brief destroy data aclTensorDesc
*
* @param desc [IN] pointer to the data of aclTensorDesc to destroy
*/
ACL_FUNC_VISIBILITY void aclDestroyTensorDesc(const aclTensorDesc *desc);

/**
* @ingroup AscendCL
* @brief set tensor shape range for aclTensorDesc
*
* @param desc [OUT] pointer to the data of aclTensorDesc
* @param dimsCount [IN] the number of dimensions of the shape
* @param dimsRange [IN] the range of dimensions of the shape
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetTensorShapeRange(aclTensorDesc *desc, size_t dimsCount,
int64_t dimsRange[][ACL_TENSOR_SHAPE_RANGE_NUM]);

/**
* @ingroup AscendCL
* @brief set value range for aclTensorDesc
*
* @param desc [OUT] pointer to the data of aclTensorDesc
* @param valueCount [IN] the number of value
* @param valueRange [IN] the range of value
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetTensorValueRange(aclTensorDesc *desc, size_t valueCount,
int64_t valueRange[][ACL_TENSOR_VALUE_RANGE_NUM]);
/**
* @ingroup AscendCL
* @brief get data type specified by the tensor description
*
* @param desc [IN] pointer to the instance of aclTensorDesc
*
* @retval data type specified by the tensor description.
* @retval ACL_DT_UNDEFINED if description is null
*/
ACL_FUNC_VISIBILITY aclDataType aclGetTensorDescType(const aclTensorDesc *desc);

/**
* @ingroup AscendCL
* @brief get data format specified by the tensor description
*
* @param desc [IN] pointer to the instance of aclTensorDesc
*
* @retval data format specified by the tensor description.
* @retval ACL_FORMAT_UNDEFINED if description is null
*/
ACL_FUNC_VISIBILITY aclFormat aclGetTensorDescFormat(const aclTensorDesc *desc);

/**
* @ingroup AscendCL
* @brief get tensor size specified by the tensor description
*
* @param desc [IN] pointer to the instance of aclTensorDesc
*
* @retval data size specified by the tensor description.
* @retval 0 if description is null
*/
ACL_FUNC_VISIBILITY size_t aclGetTensorDescSize(const aclTensorDesc *desc);

/**
* @ingroup AscendCL
* @brief get element count specified by the tensor description
*
* @param desc [IN] pointer to the instance of aclTensorDesc
*
* @retval element count specified by the tensor description.
* @retval 0 if description is null
*/
ACL_FUNC_VISIBILITY size_t aclGetTensorDescElementCount(const aclTensorDesc *desc);

/**
* @ingroup AscendCL
* @brief get number of dims specified by the tensor description
*
* @param desc [IN] pointer to the instance of aclTensorDesc
*
* @retval number of dims specified by the tensor description.
* @retval 0 if description is null
* @retval ACL_UNKNOWN_RANK if the tensor dim is -2
*/
ACL_FUNC_VISIBILITY size_t aclGetTensorDescNumDims(const aclTensorDesc *desc);

/**
* @ingroup AscendCL
* @brief Get the size of the specified dim in the tensor description
*
* @param desc [IN] pointer to the instance of aclTensorDesc
* @param index [IN] index of dims, start from 0.
*
* @retval dim specified by the tensor description and index.
* @retval -1 if description or index is invalid
*/
ACL_DEPRECATED_MESSAGE("aclGetTensorDescDim is deprecated, use aclGetTensorDescDimV2 instead")
ACL_FUNC_VISIBILITY int64_t aclGetTensorDescDim(const aclTensorDesc *desc, size_t index);

/**
* @ingroup AscendCL
* @brief Get the size of the specified dim in the tensor description
*
* @param desc [IN] pointer to the instance of aclTensorDesc
* @param index [IN] index of dims, start from 0.
* @param dimSize [OUT] size of the specified dim.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclGetTensorDescDimV2(const aclTensorDesc *desc, size_t index, int64_t *dimSize);

/**
* @ingroup AscendCL
* @brief Get the range of the specified dim in the tensor description
*
* @param desc [IN] pointer to the instance of aclTensorDesc
* @param index [IN] index of dims, start from 0.
* @param dimRangeNum [IN] number of dimRange.
* @param dimRange [OUT] range of the specified dim.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclGetTensorDescDimRange(const aclTensorDesc *desc, size_t index, size_t dimRangeNum,
int64_t *dimRange);

/**
* @ingroup AscendCL
* @brief set tensor description name
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param name [IN] tensor description name
*/
ACL_FUNC_VISIBILITY void aclSetTensorDescName(aclTensorDesc *desc, const char *name);

/**
* @ingroup AscendCL
* @brief get tensor description name
*
* @param desc [IN] pointer to the instance of aclTensorDesc
*
* @retval tensor description name.
* @retval empty string if description is null
*/
ACL_FUNC_VISIBILITY const char *aclGetTensorDescName(aclTensorDesc *desc);

/**
* @ingroup AscendCL
* @brief Convert the format in the source aclTensorDesc according to
* the specified dstFormat to generate a new target aclTensorDesc.
* The format in the source aclTensorDesc remains unchanged.
*
* @param srcDesc [IN] pointer to the source tensor desc
* @param dstFormat [IN] destination format
* @param dstDesc [OUT] pointer to the pointer to the destination tensor desc
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclTransTensorDescFormat(const aclTensorDesc *srcDesc, aclFormat dstFormat,
aclTensorDesc **dstDesc);

/**
* @ingroup AscendCL
* @brief Set the storage format specified by the tensor description
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param format [IN] the storage format
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_DEPRECATED_MESSAGE("aclSetTensorStorageFormat is deprecated, use aclSetTensorFormat instead")
ACL_FUNC_VISIBILITY aclError aclSetTensorStorageFormat(aclTensorDesc *desc, aclFormat format);

/**
* @ingroup AscendCL
* @brief Set the storage shape specified by the tensor description
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param numDims [IN] the number of dimensions of the shape
* @param dims [IN] the size of the specified dimension
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_DEPRECATED_MESSAGE("aclSetTensorStorageShape is deprecated, use aclSetTensorShape instead")
ACL_FUNC_VISIBILITY aclError aclSetTensorStorageShape(aclTensorDesc *desc, int numDims, const int64_t *dims);

/**
* @ingroup AscendCL
* @brief Set the format specified by the tensor description
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param format [IN] the storage format
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetTensorFormat(aclTensorDesc *desc, aclFormat format);

/**
* @ingroup AscendCL
* @brief Set the shape specified by the tensor description
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param numDims [IN] the number of dimensions of the shape
* @param dims [IN] the size of the specified dimension
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetTensorShape(aclTensorDesc *desc, int numDims, const int64_t *dims);

/**
* @ingroup AscendCL
* @brief Set the original format specified by the tensor description
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param format [IN] the storage format
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetTensorOriginFormat(aclTensorDesc *desc, aclFormat format);

/**
* @ingroup AscendCL
* @brief Set the original shape specified by the tensor description
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param numDims [IN] the number of dimensions of the shape
* @param dims [IN] the size of the specified dimension
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetTensorOriginShape(aclTensorDesc *desc, int numDims, const int64_t *dims);

/**
* @ingroup AscendCL
* @brief get op description info
*
* @param desc [IN] pointer to tensor description
* @param index [IN] index of tensor
*
* @retval null for failed.
* @retval OtherValues success.
*/
ACL_FUNC_VISIBILITY aclTensorDesc *aclGetTensorDescByIndex(aclTensorDesc *desc, size_t index);

/**
* @ingroup AscendCL
* @brief get address of tensor
*
* @param desc [IN] pointer to tensor description
*
* @retval null for failed
* @retval OtherValues success
*/
ACL_FUNC_VISIBILITY void *aclGetTensorDescAddress(const aclTensorDesc *desc);

/**
* @ingroup AscendCL
* @brief Set the dynamic input name specified by the tensor description
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param dynamicInputName [IN] pointer to the dynamic input name
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetTensorDynamicInput(aclTensorDesc *desc, const char *dynamicInputName);

/**
* @ingroup AscendCL
* @brief Set const data specified by the tensor description
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param dataBuffer [IN] pointer to the const databuffer
* @param length [IN] the length of const databuffer
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetTensorConst(aclTensorDesc *desc, void *dataBuffer, size_t length);

/**
* @ingroup AscendCL
* @brief Set tensor memory type specified by the tensor description
*
* @param desc [OUT] pointer to the instance of aclTensorDesc
* @param memType [IN] ACL_MEMTYPE_DEVICE means device, ACL_MEMTYPE_HOST or
* ACL_MEMTYPE_HOST_COMPILE_INDEPENDENT means host
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetTensorPlaceMent(aclTensorDesc *desc, aclMemType memType);

/**
* @ingroup AscendCL
* @brief an interface for users to output APP logs
*
* @param logLevel [IN] the level of current log
* @param func [IN] the function where the log is located
* @param file [IN] the file where the log is located
* @param line [IN] Number of source lines where the log is located
* @param fmt [IN] the format of current log
* @param ... [IN] the value of current log
*/
ACL_FUNC_VISIBILITY void aclAppLog(aclLogLevel logLevel, const char *func, const char *file, uint32_t line,
const char *fmt, ...);

/**
* @ingroup AscendCL
* @brief get soc name
*
* @retval null for failed
* @retval OtherValues success
*/
ACL_FUNC_VISIBILITY const char *aclrtGetSocName();

#define ACL_APP_LOG(level, fmt, ...) aclAppLog(level, __FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__)

#ifdef __cplusplus
}
#endif

#endif // INC_EXTERNAL_ACL_ACL_BASE_H_

+ 1237
- 0
inc/external/acl/acl_mdl.h
File diff suppressed because it is too large
View File


+ 532
- 0
inc/external/acl/acl_op.h View File

@@ -0,0 +1,532 @@
/**
* Copyright 2019-2022 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_EXTERNAL_ACL_ACL_OP_H_
#define INC_EXTERNAL_ACL_ACL_OP_H_

#include "acl_base.h"
#include "acl_rt.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct aclopHandle aclopHandle;
typedef struct aclopAttr aclopAttr;
typedef struct aclopKernelDesc aclopKernelDesc;

typedef void (*aclDataDeallocator)(void *data, size_t length);

static const int ACL_COMPILE_FLAG_BIN_SELECTOR = 1;

typedef enum aclEngineType {
ACL_ENGINE_SYS,
ACL_ENGINE_AICORE,
ACL_ENGINE_VECTOR,
} aclopEngineType;

/**
* @ingroup AscendCL
* @brief Set base directory that contains single op models
*
* @par Restriction
* The aclopSetModelDir interface can be called only once in a process.
* @param modelDir [IN] path of the directory
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetModelDir(const char *modelDir);

/**
* @ingroup AscendCL
* @brief load single op models from memory
*
* @par Restriction
* The aclopLoad interface can be called more than one times in a process.
* @param model [IN] address of single op models
* @param modelSize [IN] size of single op models
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopLoad(const void *model, size_t modelSize);

/**
* @ingroup AscendCL
* @brief create data of type aclopAttr
*
* @retval pointer to created instance.
* @retval nullptr if run out of memory
*/
ACL_FUNC_VISIBILITY aclopAttr *aclopCreateAttr();

/**
* @ingroup AscendCL
* @brief destroy data of typ aclopAttr
*
* @param attr [IN] pointer to the instance of aclopAttr
*/
ACL_FUNC_VISIBILITY void aclopDestroyAttr(const aclopAttr *attr);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is bool
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param attrValue [IN] attribute value
* false if attrValue is 0, true otherwise.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrBool(aclopAttr *attr, const char *attrName, uint8_t attrValue);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is int64_t
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param attrValue [IN] attribute value
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrInt(aclopAttr *attr, const char *attrName, int64_t attrValue);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is float
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param attrValue [IN] attribute value
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrFloat(aclopAttr *attr, const char *attrName, float attrValue);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is string
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param attrValue [IN] attribute value
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrString(aclopAttr *attr, const char *attrName, const char *attrValue);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is aclDataType
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param attrValue [IN] attribute value
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrDataType(aclopAttr *attr, const char *attrName, aclDataType attrValue);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is list of aclDataType
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param numValues [IN] number of values. false if attrValue is 0, true otherwise.
* @param values [IN] pointer to values
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrListDataType(aclopAttr *attr, const char *attrName, int numValues,
const aclDataType values[]);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is list of bools
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param numValues [IN] number of values. false if attrValue is 0, true otherwise.
* @param values [IN] pointer to values
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrListBool(aclopAttr *attr, const char *attrName, int numValues,
const uint8_t *values);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is list of ints
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param numValues [IN] number of values
* @param values [IN] pointer to values
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrListInt(aclopAttr *attr, const char *attrName, int numValues,
const int64_t *values);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is list of floats
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param numValues [IN] number of values
* @param values [IN] pointer to values
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrListFloat(aclopAttr *attr, const char *attrName, int numValues,
const float *values);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is list of strings
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param numValues [IN] number of values
* @param values [IN] pointer to values
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrListString(aclopAttr *attr, const char *attrName, int numValues,
const char **values);

/**
* @ingroup AscendCL
* @brief set an attribute. the type of the attribute is list of list of ints
*
* @param attr [OUT] pointer to the instance of aclopAttr
* @param attrName [IN] attribute name
* @param numLists [IN] number of lists
* @param numValues [IN] pointer to number of values of each list
* @param values [IN] pointer to values
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetAttrListListInt(aclopAttr *attr, const char *attrName, int numLists,
const int *numValues, const int64_t *const values[]);

/**
* @ingroup AscendCL
* @brief Load and execute the specified operator asynchronously
*
* @par Restriction
* @li The input and output organization of each operator is different,
* and the application needs to organize the operator strictly
* according to the operator input and output parameters when calling.
* @li When the user calls aclopExecute,
* the ACL finds the corresponding task according to the optype,
* the description of the input tesnsor,
* the description of the output tesnsor, and attr, and issues the execution.
*
* @param opType [IN] type of op
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param inputs [IN] pointer to array of input buffers
* @param numOutputs [IN] number of outputs
* @param outputDesc [IN] pointer to array of output tensor descriptions
* @param outputs [OUT] pointer to array of output buffers
* @param attr [IN] pointer to instance of aclopAttr.
* may pass nullptr if the op has no attribute
* @param stream [IN] stream
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_DEPRECATED_MESSAGE("aclopExecute is deprecated, use aclopExecuteV2 instead")
ACL_FUNC_VISIBILITY aclError aclopExecute(const char *opType, int numInputs, const aclTensorDesc *const inputDesc[],
const aclDataBuffer *const inputs[], int numOutputs,
const aclTensorDesc *const outputDesc[], aclDataBuffer *const outputs[],
const aclopAttr *attr, aclrtStream stream);

/**
* @ingroup AscendCL
* @brief Load and execute the specified operator
* The difference with aclopExecute is that aclopExecuteV2 will refresh outputDesc
*
* @par Restriction
* @li The input and output organization of each operator is different,
* and the application needs to organize the operator strictly
* according to the operator input and output parameters when calling.
* @li When the user calls aclopExecuteV2,
* the ACL finds the corresponding task according to the optype,
* the description of the input tesnsor,
* the description of the output tesnsor, and attr, and issues the execution.
*
* @param opType [IN] type of op
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param inputs [IN] pointer to array of input buffers
* @param numOutputs [IN] number of outputs
* @param outputDesc [IN|OUT] pointer to array of output tensor descriptions
* @param outputs [OUT] pointer to array of output buffers
* @param attr [IN] pointer to instance of aclopAttr.
* may pass nullptr if the op has no attribute
* @param stream [IN] stream
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopExecuteV2(const char *opType, int numInputs, aclTensorDesc *inputDesc[],
aclDataBuffer *inputs[], int numOutputs, aclTensorDesc *outputDesc[],
aclDataBuffer *outputs[], aclopAttr *attr, aclrtStream stream);

/**
* @ingroup AscendCL
* @brief create a instance of aclopHandle.
*
* @param opType [IN] type of op
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param numOutputs [IN] number of outputs
* @param outputDesc [IN] pointer to array of output tensor descriptions
* @param opAttr [IN] pointer to instance of aclopAttr.
* may pass nullptr if the op has no attribute
* @param handle [OUT] pointer to the pointer to the handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopCreateHandle(const char *opType, int numInputs,
const aclTensorDesc *const inputDesc[], int numOutputs,
const aclTensorDesc *const outputDesc[], const aclopAttr *opAttr,
aclopHandle **handle);

/**
* @ingroup AscendCL
* @brief destroy aclopHandle instance
*
* @param handle [IN] pointer to the instance of aclopHandle
*/
ACL_FUNC_VISIBILITY void aclopDestroyHandle(aclopHandle *handle);

/**
* @ingroup AscendCL
* @brief execute an op with the handle.
* can save op model matching cost compared with aclopExecute
*
* @param handle [IN] pointer to the instance of aclopHandle.
* The aclopCreateHandle interface has been called
* in advance to create aclopHandle type data.
* @param numInputs [IN] number of inputs
* @param inputs [IN] pointer to array of input buffers.
* The aclCreateDataBuffer interface has been called
* in advance to create aclDataBuffer type data.
* @param numOutputs [IN] number of outputs
* @param outputs [OUT] pointer to array of output buffers
* @param stream [IN] stream
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclopCreateHandle | aclCreateDataBuffer
*/
ACL_FUNC_VISIBILITY aclError aclopExecWithHandle(aclopHandle *handle, int numInputs,
const aclDataBuffer *const inputs[], int numOutputs,
aclDataBuffer *const outputs[], aclrtStream stream);

/**
* @ingroup AscendCL
* @brief cast data type
*
* @param srcDesc [IN] source tensor desc
* @param srcBuffer [IN] source tensor buffer
* @param dstDesc [IN] destination tensor desc
* @param dstBuffer [OUT] destination tensor buffer
* @param truncate [IN] do not truncate if value is 0, truncate otherwise
* @param stream [IN] stream
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopCast(const aclTensorDesc *srcDesc, const aclDataBuffer *srcBuffer,
const aclTensorDesc *dstDesc, aclDataBuffer *dstBuffer, uint8_t truncate,
aclrtStream stream);

/**
* @ingroup AscendCL
* @brief create a handle for casting datatype
*
* @param srcDesc [IN] source tensor desc
* @param dstDesc [IN] destination tensor desc
* @param truncate [IN] do not truncate if value is 0, truncate otherwise
* @param handle [OUT] pointer to the pointer to the handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopCreateHandleForCast(aclTensorDesc *srcDesc, aclTensorDesc *dstDesc, uint8_t truncate,
aclopHandle **handle);

/**
* @ingroup AscendCL
* @brief create kernel
*
* @param opType [IN] op type
* @param kernelId [IN] kernel id
* @param kernelName [IN] kernel name
* @param binData [IN] kernel bin data
* @param binSize [IN] kernel bin size
* @param enginetype [IN] enigne type
* @param deallocator [IN] callback function for deallocating bin data,
* null if bin data to be deallocated by caller
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclopCompile
*/
ACL_FUNC_VISIBILITY aclError aclopCreateKernel(const char *opType, const char *kernelId, const char *kernelName,
void *binData, int binSize, aclopEngineType enginetype,
aclDataDeallocator deallocator);

/**
* @ingroup AscendCL
* @brief create kernel
*
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param numOutputs [IN] number of outputs
* @param outputDesc [IN] pointer to array of output tensor descriptions
* @param opAttr [IN] pointer to instance of aclopAttr
* @param aclopKernelDesc [IN] pointer to instance of aclopKernelDesc
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
typedef aclError (*aclopCompileFunc)(int numInputs, const aclTensorDesc *const inputDesc[], int numOutputs,
const aclTensorDesc *const outputDesc[], const aclopAttr *opAttr,
aclopKernelDesc *aclopKernelDesc);

/**
* @ingroup AscendCL
* @brief register compile function
*
* @param opType [IN] op type
* @param func [IN] compile function
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclopUnregisterCompileFunc
*/
ACL_FUNC_VISIBILITY aclError aclopRegisterCompileFunc(const char *opType, aclopCompileFunc func);

/**
* @ingroup AscendCL
* @brief unregister compile function
*
* @param opType [IN] op type
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopUnregisterCompileFunc(const char *opType);

/**
* @ingroup AscendCL
* @brief set kernel args
*
* @param kernelDesc [IN] pointer to instance of aclopKernelDesc
* @param kernelId [IN] kernel id
* @param blockDim [IN] block dim
* @param args [IN] args
* @param argSize [IN] size in bytes of args
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetKernelArgs(aclopKernelDesc *kernelDesc, const char *kernelId, uint32_t blockDim,
const void *args, uint32_t argSize);

/**
* @ingroup AscendCL
* @brief set workspace sizes
*
* @param kernelDesc [IN] pointer to instance of aclopKernelDesc
* @param numWorkspaces [IN] number of workspaces
* @param workspaceSizes [IN] pointer to array of sizes of workspaces
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetKernelWorkspaceSizes(aclopKernelDesc *kernelDesc, int numWorkspaces,
size_t *workspaceSizes);

/**
* @ingroup AscendCL
* @brief compile op with dynamic shape
*
* @param opType [IN] op type
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param numOutputs [IN] number of outputs
* @param outputDesc [IN] pointer to array of output tensor descriptions
* @param attr [IN] pointer to instance of aclopAttr.
* may pass nullptr if the op has no attribute
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopUpdateParams(const char *opType, int numInputs,
const aclTensorDesc *const inputDesc[], int numOutputs,
const aclTensorDesc *const outputDesc[], const aclopAttr *attr);

/**
* @ingroup AscendCL
* @brief inferShape the specified operator synchronously
*
* @param opType [IN] type of op
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param inputs [IN] pointer to array of input buffers
* @param numOutputs [IN] number of outputs
* @param outputDesc [OUT] pointer to array of output tensor descriptions
* @param attr [IN] pointer to instance of aclopAttr.
* may pass nullptr if the op has no attribute
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopInferShape(const char *opType, int numInputs, aclTensorDesc *inputDesc[],
aclDataBuffer *inputs[], int numOutputs, aclTensorDesc *outputDesc[],
aclopAttr *attr);

#ifdef __cplusplus
}
#endif

#endif // INC_EXTERNAL_ACL_ACL_OP_H_

+ 200
- 0
inc/external/acl/acl_op_compiler.h View File

@@ -0,0 +1,200 @@
/**
* Copyright 2019-2022 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_EXTERNAL_ACL_ACL_OP_COMPILER_H_
#define INC_EXTERNAL_ACL_ACL_OP_COMPILER_H_

#include "acl_base.h"
#include "acl_op.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum aclCompileType { ACL_COMPILE_SYS, ACL_COMPILE_UNREGISTERED } aclopCompileType;

typedef enum {
ACL_PRECISION_MODE,
ACL_AICORE_NUM,
ACL_AUTO_TUNE_MODE,
ACL_OP_SELECT_IMPL_MODE,
ACL_OPTYPELIST_FOR_IMPLMODE,
ACL_OP_DEBUG_LEVEL,
ACL_DEBUG_DIR,
ACL_OP_COMPILER_CACHE_MODE,
ACL_OP_COMPILER_CACHE_DIR,
ACL_OP_PERFORMANCE_MODE
} aclCompileOpt;

typedef enum aclCompileFlag { ACL_OP_COMPILE_DEFAULT, ACL_OP_COMPILE_FUZZ } aclOpCompileFlag;

typedef struct aclGraphDumpOption aclGraphDumpOption;

/**
* @ingroup AscendCL
* @brief compile op
*
* @param opType [IN] op type
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param numOutputs [IN] number of outputs
* @param outputDesc [IN] pointer to array of output tensor descriptions
* @param attr [IN] pointer to instance of aclopAttr.
* may pass nullptr if the op has no attribute
* @param engineType [IN] engine type
* @param compileFlag [IN] compile flag
* @param opPath [IN] path of op
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopCompile(const char *opType, int numInputs, const aclTensorDesc *const inputDesc[],
int numOutputs, const aclTensorDesc *const outputDesc[],
const aclopAttr *attr, aclopEngineType engineType,
aclopCompileType compileFlag, const char *opPath);

/**
* @ingroup AscendCL
* @brief compile and execute op
*
* @param opType [IN] op type
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param inputs [IN] pointer to array of input buffers
* @param numOutputs [IN] number of outputs
* @param outputDesc [IN] pointer to array of output tensor descriptions
* @param outputs [IN] pointer to array of outputs buffers
* @param attr [IN] pointer to instance of aclopAttr.
* may pass nullptr if the op has no attribute
* @param engineType [IN] engine type
* @param compileFlag [IN] compile flag
* @param opPath [IN] path of op
* @param stream [IN] stream handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopCompileAndExecute(
const char *opType, int numInputs, const aclTensorDesc *const inputDesc[], const aclDataBuffer *const inputs[],
int numOutputs, const aclTensorDesc *const outputDesc[], aclDataBuffer *const outputs[], const aclopAttr *attr,
aclopEngineType engineType, aclopCompileType compileFlag, const char *opPath, aclrtStream stream);

/**
* @ingroup AscendCL
* @brief compile and execute op
*
* @param opType [IN] op type
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param inputs [IN] pointer to array of input buffers
* @param numOutputs [IN] number of outputs
* @param outputDesc [IN|OUT] pointer to array of output tensor descriptions
* @param outputs [IN] pointer to array of outputs buffers
* @param attr [IN] pointer to instance of aclopAttr.
* may pass nullptr if the op has no attribute
* @param engineType [IN] engine type
* @param compileFlag [IN] compile flag
* @param opPath [IN] path of op
* @param stream [IN] stream handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopCompileAndExecuteV2(const char *opType, int numInputs, aclTensorDesc *inputDesc[],
aclDataBuffer *inputs[], int numOutputs,
aclTensorDesc *outputDesc[], aclDataBuffer *outputs[],
aclopAttr *attr, aclopEngineType engineType,
aclopCompileType compileFlag, const char *opPath,
aclrtStream stream);

/**
* @ingroup AscendCL
* @brief set compile option
*
* @param aclCompileOpt [IN] compile option
* @param value [IN] pointer for the option value
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclSetCompileopt(aclCompileOpt opt, const char *value);

/**
* @ingroup AscendCL
* @brief set compile flag
*
* @param flag [IN] compile flag, ACL_OP_COMPILE_DEFAULT means compile with default mode
* ACL_OP_COMPILE_FUZZ means compile with fuzz mode
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclopSetCompileFlag(aclOpCompileFlag flag);

/**
* @ingroup AscendCL
* @brief generate graph and dump
*
* @param opType [IN] op type
* @param numInputs [IN] number of inputs
* @param inputDesc [IN] pointer to array of input tensor descriptions
* @param inputs [IN] pointer to array of input buffers
* @param numOutputs [IN] number of outputs
* @param outputDesc [IN] pointer to array of output tensor descriptions
* @param outputs [IN] pointer to array of outputs buffers
* @param attr [IN] pointer to instance of aclopAttr.
* may pass nullptr if the op has no attribute
* @param engineType [IN] engine type
* @param graphDumpPath [IN] dump path, if the suffix is ".txt", it means file path, else it means directory path
* @param graphDumpOpt [IN] dump option, nullptr is supported
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclGenGraphAndDumpForOp(
const char *opType, int numInputs, const aclTensorDesc *const inputDesc[], const aclDataBuffer *const inputs[],
int numOutputs, const aclTensorDesc *const outputDesc[], aclDataBuffer *const outputs[], const aclopAttr *attr,
aclopEngineType engineType, const char *graphDumpPath, const aclGraphDumpOption *graphDumpOpt);

/**
* @ingroup AscendCL
* @brief Create the graph dump option
*
* @retval null for failed
* @retval OtherValues success
*
* @see aclDestroyGraphDumpOpt
*/
ACL_FUNC_VISIBILITY aclGraphDumpOption *aclCreateGraphDumpOpt();

/**
* @ingroup AscendCL
* @brief Destroy graph dump option
*
* @param graphDumpOpt [IN] pointer to the graph dump option
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclCreateGraphDumpOpt
*/
ACL_FUNC_VISIBILITY aclError aclDestroyGraphDumpOpt(const aclGraphDumpOption *graphDumpOpt);

#ifdef __cplusplus
}
#endif

#endif // INC_EXTERNAL_ACL_ACL_OP_COMPILER_H_

+ 485
- 0
inc/external/acl/acl_prof.h View File

@@ -0,0 +1,485 @@
/**
* Copyright 2019-2022 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_EXTERNAL_ACL_PROF_H_
#define INC_EXTERNAL_ACL_PROF_H_

#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER))
#define MSVP_PROF_API __declspec(dllexport)
#else
#define MSVP_PROF_API __attribute__((visibility("default")))
#endif

#include "acl_base.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ACL_PROF_ACL_API 0x0001ULL
#define ACL_PROF_TASK_TIME 0x0002ULL
#define ACL_PROF_AICORE_METRICS 0x0004ULL
#define ACL_PROF_AICPU 0x0008ULL
#define ACL_PROF_L2CACHE 0x0010ULL
#define ACL_PROF_HCCL_TRACE 0x0020ULL
#define ACL_PROF_TRAINING_TRACE 0x0040ULL
#define ACL_PROF_MSPROFTX 0x0080ULL
#define ACL_PROF_RUNTIME_API 0x0100ULL

/**
* @deprecated please use aclprofGetOpTypeLen and aclprofGetOpTNameLen instead
*/
#define ACL_PROF_MAX_OP_NAME_LEN 257
#define ACL_PROF_MAX_OP_TYPE_LEN 65

typedef enum {
ACL_AICORE_ARITHMETIC_UTILIZATION = 0,
ACL_AICORE_PIPE_UTILIZATION = 1,
ACL_AICORE_MEMORY_BANDWIDTH = 2,
ACL_AICORE_L0B_AND_WIDTH = 3,
ACL_AICORE_RESOURCE_CONFLICT_RATIO = 4,
ACL_AICORE_MEMORY_UB = 5,
ACL_AICORE_NONE = 0xFF
} aclprofAicoreMetrics;

typedef enum {
ACL_STEP_START = 0, // step start
ACL_STEP_END = 1 // step end
} aclprofStepTag;

typedef enum {
ACL_SUBSCRIBE_OP = 0,
ACL_SUBSCRIBE_SUBGRAPH = 1,
ACL_SUBSCRIBE_OP_THREAD = 2,
ACL_SUBSCRIBE_NONE
} aclprofSubscribeOpFlag;

typedef enum { ACL_SUBSCRIBE_ATTRI_THREADID = 0, ACL_SUBSCRIBE_ATTRI_NONE } aclprofSubscribeOpAttri;

typedef struct aclprofConfig aclprofConfig;
typedef struct aclprofStopConfig aclprofStopConfig;
typedef struct aclprofAicoreEvents aclprofAicoreEvents;
typedef struct aclprofSubscribeConfig aclprofSubscribeConfig;
typedef struct aclprofStepInfo aclprofStepInfo;

/**
* @ingroup AscendCL
* @brief profiling initialize
*
* @param profilerResultPath [IN] path of profiling result
* @param length [IN] length of profilerResultPath
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclprofFinalize
*/
MSVP_PROF_API aclError aclprofInit(const char *profilerResultPath, size_t length);

/**
* @ingroup AscendCL
* @brief profiling finalize
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclprofInit
*/
MSVP_PROF_API aclError aclprofFinalize();

/**
* @ingroup AscendCL
* @brief Start profiling modules by profilerConfig
*
* @param profilerConfig [IN] config of profiling
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclprofStop
*/
MSVP_PROF_API aclError aclprofStart(const aclprofConfig *profilerConfig);

/**
* @ingroup AscendCL
* @brief Create data of type aclprofConfig
*
* @param deviceIdList [IN] list of device id
* @param deviceNums [IN] number of devices
* @param aicoreMetrics [IN] type of aicore metrics
* @param aicoreEvents [IN] pointer to aicore events, only support NULL now
* @param dataTypeConfig [IN] config modules need profiling
*
* @retval the aclprofConfig pointer
*
* @see aclprofDestroyConfig
*/
MSVP_PROF_API aclprofConfig *aclprofCreateConfig(uint32_t *deviceIdList, uint32_t deviceNums,
aclprofAicoreMetrics aicoreMetrics, aclprofAicoreEvents *aicoreEvents,
uint64_t dataTypeConfig);

/**
* @ingroup AscendCL
* @brief Destroy data of type aclprofConfig
*
* @param profilerConfig [IN] config of profiling
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclprofCreateConfig
*/
MSVP_PROF_API aclError aclprofDestroyConfig(const aclprofConfig *profilerConfig);

/**
* @ingroup AscendCL
* @brief stop profiling modules by stopProfilingConfig
*
* @param profilerConfig [IN] pointer to stop config of profiling
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclprofStart
*/
MSVP_PROF_API aclError aclprofStop(const aclprofConfig *profilerConfig);

/**
* @ingroup AscendCL
* @brief subscribe profiling data of model
*
* @param modelId [IN] the model id subscribed
* @param profSubscribeConfig [IN] pointer to config of model subscribe
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclprofModelUnSubscribe
*/
MSVP_PROF_API aclError aclprofModelSubscribe(uint32_t modelId, const aclprofSubscribeConfig *profSubscribeConfig);

/**
* @ingroup AscendCL
* @brief unsubscribe profiling data of model
*
* @param modelId [IN] the model id unsubscribed
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclprofModelSubscribe
*/
MSVP_PROF_API aclError aclprofModelUnSubscribe(uint32_t modelId);

/**
* @ingroup AscendCL
* @brief create subscribe config
*
* @param timeInfoSwitch [IN] switch whether get time info from model
* @param aicoreMetrics [IN] aicore metrics
* @param fd [IN] pointer to write pipe
*
* @retval the aclprofSubscribeConfig pointer
*
* @see aclprofDestroySubscribeConfig
*/
MSVP_PROF_API aclprofSubscribeConfig *aclprofCreateSubscribeConfig(int8_t timeInfoSwitch,
aclprofAicoreMetrics aicoreMetrics, void *fd);

/**
* @ingroup AscendCL
* @brief destroy subscribe config
*
* @param profSubscribeConfig [IN] subscribe config
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclprofCreateSubscribeConfig
*/
MSVP_PROF_API aclError aclprofDestroySubscribeConfig(const aclprofSubscribeConfig *profSubscribeConfig);

/**
* @ingroup AscendCL
* @brief create subscribe config
*
* @param opDescSize [OUT] size of op desc
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofGetOpDescSize(size_t *opDescSize);

/**
* @ingroup AscendCL
* @brief get op number from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param opNumber [OUT] op number of subscription data
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofGetOpNum(const void *opInfo, size_t opInfoLen, uint32_t *opNumber);

/**
* @ingroup AscendCL
* @brief get length op type from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param index [IN] index of op array in opInfo
* @param opTypeLen [OUT] actual length of op type string
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofGetOpTypeLen(const void *opInfo, size_t opInfoLen, uint32_t index, size_t *opTypeLen);

/**
* @ingroup AscendCL
* @brief get op type from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param index [IN] index of op array in opInfo
* @param opType [OUT] obtained op type string
* @param opTypeLen [IN] obtained length of op type string
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofGetOpType(const void *opInfo, size_t opInfoLen, uint32_t index, char *opType,
size_t opTypeLen);

/**
* @ingroup AscendCL
* @brief get length op name from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param index [IN] index of op array in opInfo
* @param opNameLen [OUT] actual length of op name string
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofGetOpNameLen(const void *opInfo, size_t opInfoLen, uint32_t index, size_t *opNameLen);

/**
* @ingroup AscendCL
* @brief get op type from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param index [IN] index of op array in opInfo
* @param opName [OUT] obtained op name string
* @param opNameLen [IN] obtained length of op name string
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofGetOpName(const void *opInfo, size_t opInfoLen, uint32_t index, char *opName,
size_t opNameLen);

/**
* @ingroup AscendCL
* @brief get start time of specified op from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param index [IN] index of op array in opInfo
*
* @retval start time(us) of specified op with timestamp
* @retval 0 for failed
*/
MSVP_PROF_API uint64_t aclprofGetOpStart(const void *opInfo, size_t opInfoLen, uint32_t index);

/**
* @ingroup AscendCL
* @brief get end time of specified op from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param index [IN] index of op array in opInfo
*
* @retval end time(us) of specified op with timestamp
* @retval 0 for failed
*/
MSVP_PROF_API uint64_t aclprofGetOpEnd(const void *opInfo, size_t opInfoLen, uint32_t index);

/**
* @ingroup AscendCL
* @brief get excution time of specified op from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param index [IN] index of op array in opInfo
*
* @retval execution time(us) of specified op with timestamp
* @retval 0 for failed
*/
MSVP_PROF_API uint64_t aclprofGetOpDuration(const void *opInfo, size_t opInfoLen, uint32_t index);

/**
* @ingroup AscendCL
* @brief get model id from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
*
* @retval model id of subscription data
* @retval 0 for failed
*/
MSVP_PROF_API size_t aclprofGetModelId(const void *opInfo, size_t opInfoLen, uint32_t index);

/**
* @ingroup AscendCL
* @brief get op flag from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param index [IN] index of op array in opInfo
*
* @retval op flag
* @retval ACL_SUBSCRIBE_NONE for failed
*/
MSVP_PROF_API aclprofSubscribeOpFlag aclprofGetOpFlag(const void *opInfo, size_t opInfoLen, uint32_t index);

/**
* @ingroup AscendCL
* @brief get op flag from subscription data
*
* @param opInfo [IN] pointer to subscription data
* @param opInfoLen [IN] memory size of subscription data
* @param index [IN] index of op array in opInfo
* @param attri [IN] attribute of op
*
* @retval op flag
* @retval NULL for failed
*/
MSVP_PROF_API const char *aclprofGetOpAttriValue(const void *opInfo, size_t opInfoLen, uint32_t index,
aclprofSubscribeOpAttri attri);

/**
* @ingroup AscendCL
* @brief
*
* @param stepInfo [IN] pointer to stepInfo data
* @param aclprofstepTag [IN] start or end flag
* @param stream [IN] steam info
*
* @retval 0 for failed
*/
MSVP_PROF_API aclError aclprofGetStepTimestamp(aclprofStepInfo *stepInfo, aclprofStepTag tag, aclrtStream stream);

/**
* @ingroup AscendCL
* @brief create pointer to aclprofStepInfo data
*
*
* @retval aclprofStepInfo pointer
*/
MSVP_PROF_API aclprofStepInfo *aclprofCreateStepInfo();

/**
* @ingroup AscendCL
* @brief destroy aclprofStepInfo pointer
*
*
* @retval void
*/
MSVP_PROF_API void aclprofDestroyStepInfo(aclprofStepInfo *stepinfo);

/**
* @ingroup AscendCL
* @brief create pointer to aclprofstamp
*
*
* @retval aclprofStamp pointer
*/
MSVP_PROF_API void *aclprofCreateStamp();

/**
* @ingroup AscendCL
* @brief destory stamp pointer
*
*
* @retval void
*/
MSVP_PROF_API void aclprofDestroyStamp(void *stamp);

/**
* @ingroup AscendCL
* @brief Record push timestamp
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofPush(void *stamp);

/**
* @ingroup AscendCL
* @brief Record pop timestamp
*
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofPop();

/**
* @ingroup AscendCL
* @brief Record range start timestamp
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofRangeStart(void *stamp, uint32_t *rangeId);

/**
* @ingroup AscendCL
* @brief Record range end timestamp
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofRangeStop(uint32_t rangeId);

/**
* @ingroup AscendCL
* @brief set message to stamp
*
*
* @retval void
*/
MSVP_PROF_API aclError aclprofSetStampTraceMessage(void *stamp, const char *msg, uint32_t msgLen);

/**
* @ingroup AscendCL
* @brief Record mark timestamp
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
MSVP_PROF_API aclError aclprofMark(void *stamp);

#ifdef __cplusplus
}
#endif

#endif // INC_EXTERNAL_ACL_PROF_H_

+ 1031
- 0
inc/external/acl/acl_rt.h
File diff suppressed because it is too large
View File


+ 316
- 0
inc/external/acl/acl_tdt.h View File

@@ -0,0 +1,316 @@
/**
* Copyright 2019-2022 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_EXTERNAL_ACL_ACL_TDT_H_
#define INC_EXTERNAL_ACL_ACL_TDT_H_

#include "acl/acl_base.h"

#ifdef __cplusplus
extern "C" {
#endif

enum acltdtTensorType {
ACL_TENSOR_DATA_UNDEFINED = -1,
ACL_TENSOR_DATA_TENSOR,
ACL_TENSOR_DATA_END_OF_SEQUENCE,
ACL_TENSOR_DATA_ABNORMAL
};

typedef struct acltdtDataItem acltdtDataItem;
typedef struct acltdtDataset acltdtDataset;
typedef struct acltdtChannelHandle acltdtChannelHandle;

/**
* @ingroup AscendCL
* @brief Get tensor type from item
*
* @param dataItem [IN] pointer to the data item
*
* @retval Tensor type.
* @retval ACL_DT_UNDEFINED if dataItem is null
*/
ACL_FUNC_VISIBILITY acltdtTensorType acltdtGetTensorTypeFromItem(const acltdtDataItem *dataItem);

/**
* @ingroup AscendCL
* @brief Get data type from item
*
* @param dataItem [IN] pointer to the data item
*
* @retval Data type.
* @retval ACL_DT_UNDEFINED if dataItem is null
*/
ACL_FUNC_VISIBILITY aclDataType acltdtGetDataTypeFromItem(const acltdtDataItem *dataItem);

/**
* @ingroup AscendCL
* @brief Get data address from item
*
* @param dataItem [IN] pointer to data item
*
* @retval null for failed
* @retval OtherValues success
*/
ACL_FUNC_VISIBILITY void *acltdtGetDataAddrFromItem(const acltdtDataItem *dataItem);

/**
* @ingroup AscendCL
* @brief Get data size from item
*
* @param dataItem [IN] pointer to data item
*
* @retval 0 for failed
* @retval OtherValues success
*/
ACL_FUNC_VISIBILITY size_t acltdtGetDataSizeFromItem(const acltdtDataItem *dataItem);

/**
* @ingroup AscendCL
* @brief Get dim's number from item
*
* @param dataItem [IN] pointer to data item
*
* @retval 0 for failed
* @retval OtherValues success
*/
ACL_FUNC_VISIBILITY size_t acltdtGetDimNumFromItem(const acltdtDataItem *dataItem);

/**
* @ingroup AscendCL
* @brief Get dims from item
*
* @param dataItem [IN] the struct of data item
* @param dims [IN|OUT] pointer to the dims of dataTtem
* @param dimNum [IN] the size of the dims
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError acltdtGetDimsFromItem(const acltdtDataItem *dataItem, int64_t *dims, size_t dimNum);

/**
* @ingroup AscendCL
* @brief Create the struct of data item
*
* @param tdtType [IN] Tdt tensor type
* @param dims [IN] pointer of tdtDataItem's dims
* @param dimNum [IN] Dim number
* @param dataType [IN] Data type
* @param data [IN] Data pointer
* @param size [IN] Data size
*
* @retval null for failed
* @retval OtherValues success
*
* @see acltdtDestroyDataItem
*/
ACL_FUNC_VISIBILITY acltdtDataItem *acltdtCreateDataItem(acltdtTensorType tdtType, const int64_t *dims, size_t dimNum,
aclDataType dataType, void *data, size_t size);

/**
* @ingroup AscendCL
* @brief Destroy the struct of data item
*
* @param dataItem [IN] pointer to the data item
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateDataItem
*/
ACL_FUNC_VISIBILITY aclError acltdtDestroyDataItem(acltdtDataItem *dataItem);

/**
* @ingroup AscendCL
* @brief Create the tdt dataset
*
* @retval null for failed
* @retval OtherValues success
*
* @see acltdtDestroyDataset
*/
ACL_FUNC_VISIBILITY acltdtDataset *acltdtCreateDataset();

/**
* @ingroup AscendCL
* @brief Destroy the tdt dataset
*
* @param dataset [IN] pointer to the dataset
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateDataset
*/
ACL_FUNC_VISIBILITY aclError acltdtDestroyDataset(acltdtDataset *dataset);

/**
* @ingroup AscendCL
* @brief Get the data item
*
* @param dataset [IN] pointer to the dataset
* @param index [IN] index of the dataset
*
* @retval null for failed
* @retval OtherValues success
*
* @see acltdtAddDataItem
*/
ACL_FUNC_VISIBILITY acltdtDataItem *acltdtGetDataItem(const acltdtDataset *dataset, size_t index);

/**
* @ingroup AscendCL
* @brief Get the data item
*
* @param dataset [OUT] pointer to the dataset
* @param dataItem [IN] pointer to the data item
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtGetDataItem
*/
ACL_FUNC_VISIBILITY aclError acltdtAddDataItem(acltdtDataset *dataset, acltdtDataItem *dataItem);

/**
* @ingroup AscendCL
* @brief Get the size of dataset
*
* @param dataset [IN] pointer to the dataset
*
* @retval 0 for failed
* @retval OtherValues success
*/
ACL_FUNC_VISIBILITY size_t acltdtGetDatasetSize(const acltdtDataset *dataset);

/**
* @ingroup AscendCL
* @brief Get the name of dataset
*
* @param dataset [IN] pointer to the dataset
*
* @retval null for failed
* @retval OtherValues success
*/
ACL_FUNC_VISIBILITY const char *acltdtGetDatasetName(const acltdtDataset *dataset);

/**
* @ingroup AscendCL
* @brief Stop the channel
*
* @param handle [IN] pointer to the channel handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateChannel | acltdtDestroyChannel
*/
ACL_FUNC_VISIBILITY aclError acltdtStopChannel(acltdtChannelHandle *handle);

/**
* @ingroup AscendCL
* @brief Create the channel
*
* @param deviceId [IN] the device id
* @param name [IN] the name of channel
*
* @retval null for failed
* @retval OtherValues success
*
* @see acltdtStopChannel | acltdtDestroyChannel
*/
ACL_FUNC_VISIBILITY acltdtChannelHandle *acltdtCreateChannel(uint32_t deviceId, const char *name);

/**
* @ingroup AscendCL
* @brief Create the channel with max size
*
* @param deviceId [IN] the device id
* @param name [IN] the name of channel
* @param capacity [IN] the capacity of channel
*
* @retval null for failed
* @retval OtherValues success
*
* @see acltdtDestroyChannel
*/
ACL_FUNC_VISIBILITY acltdtChannelHandle *acltdtCreateChannelWithCapacity(uint32_t deviceId, const char *name,
size_t capacity);

/**
* @ingroup AscendCL
* @brief Destroy the channel
*
* @param handle [IN] pointer to the channel handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateChannel | acltdtStopChannel
*/
ACL_FUNC_VISIBILITY aclError acltdtDestroyChannel(acltdtChannelHandle *handle);

/**
* @ingroup AscendCL
* @brief Send tensor to device
*
* @param handle [IN] pointer to the channel handle
* @param dataset [IN] pointer to the dataset
* @param timeout [IN] to be reserved, now it must be -1
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtReceiveTensor
*/
ACL_FUNC_VISIBILITY aclError acltdtSendTensor(const acltdtChannelHandle *handle, const acltdtDataset *dataset,
int32_t timeout);

/**
* @ingroup AscendCL
* @brief Receive tensor from device
*
* @param handle [IN] pointer to the channel handle
* @param dataset [OUT] pointer to the dataset
* @param timeout [IN] to be reserved, now it must be -1
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtSendTensor
*/
ACL_FUNC_VISIBILITY aclError acltdtReceiveTensor(const acltdtChannelHandle *handle, acltdtDataset *dataset,
int32_t timeout);

/**
* @ingroup AscendCL
* @brief query the size of the channel
*
* @param handle [IN] pointer to the channel handle
* @param size [OUT] current size of this channel
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
*/
ACL_FUNC_VISIBILITY aclError acltdtQueryChannelSize(const acltdtChannelHandle *handle, size_t *size);

#ifdef __cplusplus
}
#endif

#endif // INC_EXTERNAL_ACL_ACL_TDT_H_

+ 476
- 0
inc/external/acl/acl_tdt_queue.h View File

@@ -0,0 +1,476 @@
/**
* Copyright 2019-2022 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_EXTERNAL_ACL_ACL_TDT_QUEUE_H_
#define INC_EXTERNAL_ACL_ACL_TDT_QUEUE_H_

#include "acl/acl_base.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ACL_TDT_QUEUE_PERMISSION_MANAGE 1
#define ACL_TDT_QUEUE_PERMISSION_DEQUEUE 2
#define ACL_TDT_QUEUE_PERMISSION_ENQUEUE 4

typedef void *acltdtBuf;
typedef struct tagMemQueueAttr acltdtQueueAttr;
typedef struct acltdtQueueRouteList acltdtQueueRouteList;
typedef struct acltdtQueueRouteQueryInfo acltdtQueueRouteQueryInfo;
typedef struct acltdtQueueRoute acltdtQueueRoute;

typedef enum { ACL_TDT_QUEUE_NAME_PTR = 0, ACL_TDT_QUEUE_DEPTH_UINT32 } acltdtQueueAttrType;

typedef enum {
ACL_TDT_QUEUE_ROUTE_SRC_UINT32 = 0,
ACL_TDT_QUEUE_ROUTE_DST_UINT32,
ACL_TDT_QUEUE_ROUTE_STATUS_INT32
} acltdtQueueRouteParamType;

typedef enum {
ACL_TDT_QUEUE_ROUTE_QUERY_SRC = 0,
ACL_TDT_QUEUE_ROUTE_QUERY_DST,
ACL_TDT_QUEUE_ROUTE_QUERY_SRC_AND_DST
} acltdtQueueRouteQueryMode;

typedef enum {
ACL_TDT_QUEUE_ROUTE_QUERY_MODE_ENUM = 0,
ACL_TDT_QUEUE_ROUTE_QUERY_SRC_ID_UINT32,
ACL_TDT_QUEUE_ROUTE_QUERY_DST_ID_UINT32
} acltdtQueueRouteQueryInfoParamType;

/**
* @ingroup AscendCL
* @brief create queue
*
* @param attr [IN] pointer to the queue attr
* @param qid [OUT] pointer to the qid
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtDestroyQueue
*/
ACL_FUNC_VISIBILITY aclError acltdtCreateQueue(const acltdtQueueAttr *attr, uint32_t *qid);

/**
* @ingroup AscendCL
* @brief destroy queue
*
* @param qid [IN] qid which to be destroyed
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateQueue
*/
ACL_FUNC_VISIBILITY aclError acltdtDestroyQueue(uint32_t qid);

/**
* @ingroup AscendCL
* @brief enqueue function
*
* @param qid [IN] qid
* @param buf [IN] acltdtBuf
* @param timeout [IN] timeout, -1 means blocking
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtDequeue
*/
ACL_FUNC_VISIBILITY aclError acltdtEnqueue(uint32_t qid, acltdtBuf buf, int32_t timeout);

/**
* @ingroup AscendCL
* @brief dequeue function
*
* @param qid [IN] qid
* @param buf [OUT] pointer to the acltdtBuf
* @param timeout [IN] timeout, -1 means blocking
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtEnqueue
*/
ACL_FUNC_VISIBILITY aclError acltdtDequeue(uint32_t qid, acltdtBuf *buf, int32_t timeout);

/**
* @ingroup AscendCL
* @brief enqueue function
*
* @param qid [IN] qid
* @param data [IN] the pointer to data buf
* @param dataSize [IN] the size of data buf
* @param userData [IN] the pointer to user data buf
* @param userDataSize [IN] the size of user data buf
* @param timeout [IN] timeout, -1 means blocking
* @param rsv [IN] reserved param
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtDequeueData
*/
ACL_FUNC_VISIBILITY aclError acltdtEnqueueData(uint32_t qid, const void *data, size_t dataSize, const void *userData,
size_t userDataSize, int32_t timeout, uint32_t rsv);

/**
* @ingroup AscendCL
* @brief dequeue function
*
* @param qid [IN] qid
* @param data [IN|OUT] the pointer to data buf
* @param dataSize [IN] the size of data buf
* @param retDataSize [OUT] the return size of data buf
* @param userData [IN|OUT] the pointer to user data buf
* @param userDataSize [IN] the size of user data buf
* @param timeout [IN] timeout, -1 means blocking
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtEnqueueData
*/
ACL_FUNC_VISIBILITY aclError acltdtDequeueData(uint32_t qid, void *data, size_t dataSize, size_t *retDataSize,
void *userData, size_t userDataSize, int32_t timeout);

/**
* @ingroup AscendCL
* @brief grant queue to other process
*
* @param qid [IN] qid
* @param pid [IN] pid of dst process
* @param permission [IN] permission of queue
* @param timeout [IN] timeout, -1 means blocking
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see ACL_TDT_QUEUE_PERMISSION_MANAGE | ACL_TDT_QUEUE_PERMISSION_DEQUEUE | ACL_TDT_QUEUE_PERMISSION_ENQUEUE
*/
ACL_FUNC_VISIBILITY aclError acltdtGrantQueue(uint32_t qid, int32_t pid, uint32_t permission, int32_t timeout);

/**
* @ingroup AscendCL
* @brief attach queue in current process
*
* @param qid [IN] qid
* @param timeout [IN] timeout, -1 means blocking
* @param permission [OUT] permission of queue
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtGrantQueue
*/
ACL_FUNC_VISIBILITY aclError acltdtAttachQueue(uint32_t qid, int32_t timeout, uint32_t *permission);

/**
* @ingroup AscendCL
* @brief bind queue routes
*
* @param qRouteList [IN|OUT] pointer to the route list
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError acltdtBindQueueRoutes(acltdtQueueRouteList *qRouteList);

/**
* @ingroup AscendCL
* @brief unbind queue routes
*
* @param qRouteList [IN|OUT] pointer to the route list
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError acltdtUnbindQueueRoutes(acltdtQueueRouteList *qRouteList);

/**
* @ingroup AscendCL
* @brief query queue routes according to query mode
*
* @param queryInfo [IN] pointer to the queue route query info
* @param qRouteList [IN|OUT] pointer to the route list
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError acltdtQueryQueueRoutes(const acltdtQueueRouteQueryInfo *queryInfo,
acltdtQueueRouteList *qRouteList);

/**
* @ingroup AscendCL
* @brief alloc acltdtBuf
*
* @param size [IN] alloc buf size
* @param type [IN] reserved parameters, need to set zero currently
* @param buf [OUT] pointer to the acltdtBuf
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtFreeBuf
*/
ACL_FUNC_VISIBILITY aclError acltdtAllocBuf(size_t size, uint32_t type, acltdtBuf *buf);

/**
* @ingroup AscendCL
* @brief free acltdtBuf
*
* @param buf [IN] pointer to the acltdtBuf
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtAllocBuf
*/
ACL_FUNC_VISIBILITY aclError acltdtFreeBuf(acltdtBuf buf);

/**
* @ingroup AscendCL
* @brief get data buf address
*
* @param buf [IN] acltdtBuf
* @param dataPtr [OUT] pointer to the data ptr which is acquired from acltdtBuf
* @param size [OUT] pointer to the size
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtAllocBuf
*/
ACL_FUNC_VISIBILITY aclError acltdtGetBufData(const acltdtBuf buf, void **dataPtr, size_t *size);

/**
* @ingroup AscendCL
* @brief Create the queue attr
*
* @retval null for failed
* @retval OtherValues success
*
* @see acltdtDestroyQueueAttr
*/
ACL_FUNC_VISIBILITY acltdtQueueAttr *acltdtCreateQueueAttr();

/**
* @ingroup AscendCL
* @brief Destroy the queue attr
*
* @param attr [IN] pointer to the queue attr
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateQueueAttr
*/
ACL_FUNC_VISIBILITY aclError acltdtDestroyQueueAttr(const acltdtQueueAttr *attr);

/**
* @ingroup AscendCL
* @brief Set parameter for queue attr
*
* @param attr [IN|OUT] pointer to the queue attr
* @param type [IN] parameter type
* @param len [IN] parameter length
* @param param [IN] pointer to parameter value
*
* @retval ACL_SUCCESS for success, other for failure
*
* @see acltdtCreateQueueAttr
*/
ACL_FUNC_VISIBILITY aclError acltdtSetQueueAttr(acltdtQueueAttr *attr, acltdtQueueAttrType type, size_t len,
const void *param);

/**
* @ingroup AscendCL
*
* @brief Get parameter for queue attr.
*
* @param attr [IN] pointer to the queue attr
* @param type [IN] parameter type
* @param len [IN] parameter length
* @param paramRetSize [OUT] pointer to parameter real length
* @param param [OUT] pointer to parameter value
*
* @retval ACL_SUCCESS for success, other for failure
*
* @see acltdtCreateQueueAttr
*/
ACL_FUNC_VISIBILITY aclError acltdtGetQueueAttr(const acltdtQueueAttr *attr, acltdtQueueAttrType type, size_t len,
size_t *paramRetSize, void *param);

/**
* @ingroup AscendCL
* @brief Create the queue route
*
* @param srcId [IN] src id of queue route
* @param dstId [IN] dst id of queue route
*
* @retval null for failed
* @retval OtherValues success
*
* @see acltdtDestroyQueueRoute
*/
ACL_FUNC_VISIBILITY acltdtQueueRoute *acltdtCreateQueueRoute(uint32_t srcId, uint32_t dstId);

/**
* @ingroup AscendCL
* @brief Destroy the queue attr
*
* @param route [IN] pointer to the queue route
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateQueueRoute
*/
ACL_FUNC_VISIBILITY aclError acltdtDestroyQueueRoute(const acltdtQueueRoute *route);

/**
* @ingroup AscendCL
*
* @brief Get parameter for queue route.
*
* @param route [IN] pointer to the queue route
* @param type [IN] parameter type
* @param len [IN] parameter length
* @param paramRetSize [OUT] pointer to parameter real length
* @param param [OUT] pointer to parameter value
*
* @retval ACL_SUCCESS for success, other for failure
*
* @see acltdtCreateQueueRoute
*/
ACL_FUNC_VISIBILITY aclError acltdtGetQueueRouteParam(const acltdtQueueRoute *route, acltdtQueueRouteParamType type,
size_t len, size_t *paramRetSize, void *param);

/**
* @ingroup AscendCL
* @brief Create the queue route list
*
* @retval null for failed
* @retval OtherValues success
*
* @see acltdtDestroyQueueRouteList
*/
ACL_FUNC_VISIBILITY acltdtQueueRouteList *acltdtCreateQueueRouteList();

/**
* @ingroup AscendCL
* @brief Destroy the queue route list
*
* @param routeList [IN] pointer to the queue route list
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateQueueRouteList
*/
ACL_FUNC_VISIBILITY aclError acltdtDestroyQueueRouteList(const acltdtQueueRouteList *routeList);

/**
* @ingroup AscendCL
* @brief add queue route to the route list
*
* @param routeList [IN|OUT] pointer to the queue route list
* @param route [IN] pointer to the queue route
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateQueueRouteList | acltdtCreateQueueRoute
*
*/
ACL_FUNC_VISIBILITY aclError acltdtAddQueueRoute(acltdtQueueRouteList *routeList, const acltdtQueueRoute *route);

/**
* @ingroup AscendCL
* @brief get queue route from route list
*
* @param routeList [IN] pointer to the queue route list
* @param index [IN] index of queue route in route list
* @param route [IN|OUT] pointer to the queue route
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateQueueRouteList | acltdtCreateQueueRoute
*
*/
ACL_FUNC_VISIBILITY aclError acltdtGetQueueRoute(const acltdtQueueRouteList *routeList, size_t index,
acltdtQueueRoute *route);

/**
* @ingroup AscendCL
* @brief get queue route num from route list
*
* @param routeList [IN] pointer to the queue route list
*
* @retval the number of queue route
*
*/
ACL_FUNC_VISIBILITY size_t acltdtGetQueueRouteNum(const acltdtQueueRouteList *routeList);

/**
* @ingroup AscendCL
* @brief Create the queue route query info
*
* @retval null for failed
* @retval OtherValues success
*
* @see acltdtDestroyQueueRouteQueryInfo
*/
ACL_FUNC_VISIBILITY acltdtQueueRouteQueryInfo *acltdtCreateQueueRouteQueryInfo();

/**
* @ingroup AscendCL
* @brief Destroy the queue route query info
*
* @param info [IN] pointer to the queue route info
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see acltdtCreateQueueRouteQueryInfo
*
*/
ACL_FUNC_VISIBILITY aclError acltdtDestroyQueueRouteQueryInfo(const acltdtQueueRouteQueryInfo *info);

/**
* @ingroup AscendCL
* @brief Set parameter for queue route info
*
* @param attr [IN|OUT] pointer to the queue route info
* @param type [IN] parameter type
* @param len [IN] parameter length
* @param param [IN] pointer to parameter value
*
* @retval ACL_SUCCESS for success, other for failure
*
* @see acltdtCreateQueueRouteQueryInfo
*/
ACL_FUNC_VISIBILITY aclError acltdtSetQueueRouteQueryInfo(acltdtQueueRouteQueryInfo *param,
acltdtQueueRouteQueryInfoParamType type, size_t len,
const void *value);

#ifdef __cplusplus
}
#endif

#endif // INC_EXTERNAL_ACL_ACL_TDT_QUEUE_H_

+ 77
- 0
inc/external/acl/error_codes/ge_error_codes.h View File

@@ -0,0 +1,77 @@
/**
* Copyright 2019-2022 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_EXTERNAL_GE_GE_ERROR_CODES_H_
#define INC_EXTERNAL_GE_GE_ERROR_CODES_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 <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif
static const uint32_t ACL_ERROR_GE_PARAM_INVALID = 145000U;
static const uint32_t ACL_ERROR_GE_EXEC_NOT_INIT = 145001U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID = 145002U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_ID_INVALID = 145003U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID = 145006U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID = 145007U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID = 145008U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_MODEL_REPEATED = 145009U;
static const uint32_t ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID = 145011U;
static const uint32_t ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID = 145012U;
static const uint32_t ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID = 145013U;
static const uint32_t ACL_ERROR_GE_AIPP_BATCH_EMPTY = 145014U;
static const uint32_t ACL_ERROR_GE_AIPP_NOT_EXIST = 145015U;
static const uint32_t ACL_ERROR_GE_AIPP_MODE_INVALID = 145016U;
static const uint32_t ACL_ERROR_GE_OP_TASK_TYPE_INVALID = 145017U;
static const uint32_t ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID = 145018U;
static const uint32_t ACL_ERROR_GE_PLGMGR_PATH_INVALID = 145019U;
static const uint32_t ACL_ERROR_GE_FORMAT_INVALID = 145020U;
static const uint32_t ACL_ERROR_GE_SHAPE_INVALID = 145021U;
static const uint32_t ACL_ERROR_GE_DATATYPE_INVALID = 145022U;
static const uint32_t ACL_ERROR_GE_MEMORY_ALLOCATION = 245000U;
static const uint32_t ACL_ERROR_GE_MEMORY_OPERATE_FAILED = 245001U;
static const uint32_t ACL_ERROR_GE_DEVICE_MEMORY_OPERATE_FAILED = 245002U;
static const uint32_t ACL_ERROR_GE_INTERNAL_ERROR = 545000U;
static const uint32_t ACL_ERROR_GE_LOAD_MODEL = 545001U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_MODEL_PARTITION_FAILED = 545002U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED = 545003U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED = 545004U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_KERNEL_PARTITION_FAILED = 545005U;
static const uint32_t ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA = 545006U;
static const uint32_t ACL_ERROR_GE_COMMAND_HANDLE = 545007U;
static const uint32_t ACL_ERROR_GE_GET_TENSOR_INFO = 545008U;
static const uint32_t ACL_ERROR_GE_UNLOAD_MODEL = 545009U;

#ifdef __cplusplus
} // namespace ge
#endif
#endif // INC_EXTERNAL_GE_GE_ERROR_CODES_H_

+ 123
- 0
inc/external/acl/error_codes/rt_error_codes.h View File

@@ -0,0 +1,123 @@
/**
* Copyright 2019-2022 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_EXTERNEL_RT_ERROR_CODES_H__
#define __INC_EXTERNEL_RT_ERROR_CODES_H__

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

static const int32_t ACL_RT_SUCCESS = 0; // success

static const int32_t ACL_ERROR_RT_PARAM_INVALID = 107000; // param invalid
static const int32_t ACL_ERROR_RT_INVALID_DEVICEID = 107001; // invalid device id
static const int32_t ACL_ERROR_RT_CONTEXT_NULL = 107002; // current context null
static const int32_t ACL_ERROR_RT_STREAM_CONTEXT = 107003; // stream not in current context
static const int32_t ACL_ERROR_RT_MODEL_CONTEXT = 107004; // model not in current context
static const int32_t ACL_ERROR_RT_STREAM_MODEL = 107005; // stream not in model
static const int32_t ACL_ERROR_RT_EVENT_TIMESTAMP_INVALID = 107006; // event timestamp invalid
static const int32_t ACL_ERROR_RT_EVENT_TIMESTAMP_REVERSAL = 107007; // event timestamp reversal
static const int32_t ACL_ERROR_RT_ADDR_UNALIGNED = 107008; // memory address unaligned
static const int32_t ACL_ERROR_RT_FILE_OPEN = 107009; // open file failed
static const int32_t ACL_ERROR_RT_FILE_WRITE = 107010; // write file failed
static const int32_t ACL_ERROR_RT_STREAM_SUBSCRIBE = 107011; // error subscribe stream
static const int32_t ACL_ERROR_RT_THREAD_SUBSCRIBE = 107012; // error subscribe thread
static const int32_t ACL_ERROR_RT_GROUP_NOT_SET = 107013; // group not set
static const int32_t ACL_ERROR_RT_GROUP_NOT_CREATE = 107014; // group not create
static const int32_t ACL_ERROR_RT_STREAM_NO_CB_REG = 107015; // callback not register to stream
static const int32_t ACL_ERROR_RT_INVALID_MEMORY_TYPE = 107016; // invalid memory type
static const int32_t ACL_ERROR_RT_INVALID_HANDLE = 107017; // invalid handle
static const int32_t ACL_ERROR_RT_INVALID_MALLOC_TYPE = 107018; // invalid malloc type
static const int32_t ACL_ERROR_RT_WAIT_TIMEOUT = 107019; // wait timeout
static const int32_t ACL_ERROR_RT_TASK_TIMEOUT = 107020; // task timeout

static const int32_t ACL_ERROR_RT_FEATURE_NOT_SUPPORT = 207000; // feature not support
static const int32_t ACL_ERROR_RT_MEMORY_ALLOCATION = 207001; // memory allocation error
static const int32_t ACL_ERROR_RT_MEMORY_FREE = 207002; // memory free error
static const int32_t ACL_ERROR_RT_AICORE_OVER_FLOW = 207003; // aicore over flow
static const int32_t ACL_ERROR_RT_NO_DEVICE = 207004; // no device
static const int32_t ACL_ERROR_RT_RESOURCE_ALLOC_FAIL = 207005; // resource alloc fail
static const int32_t ACL_ERROR_RT_NO_PERMISSION = 207006; // no permission
static const int32_t ACL_ERROR_RT_NO_EVENT_RESOURCE = 207007; // no event resource
static const int32_t ACL_ERROR_RT_NO_STREAM_RESOURCE = 207008; // no stream resource
static const int32_t ACL_ERROR_RT_NO_NOTIFY_RESOURCE = 207009; // no notify resource
static const int32_t ACL_ERROR_RT_NO_MODEL_RESOURCE = 207010; // no model resource
static const int32_t ACL_ERROR_RT_NO_CDQ_RESOURCE = 207011; // no cdq resource
static const int32_t ACL_ERROR_RT_OVER_LIMIT = 207012; // over limit
static const int32_t ACL_ERROR_RT_QUEUE_EMPTY = 207013; // queue is empty
static const int32_t ACL_ERROR_RT_QUEUE_FULL = 207014; // queue is full
static const int32_t ACL_ERROR_RT_REPEATED_INIT = 207015; // repeated init
static const int32_t ACL_ERROR_RT_AIVEC_OVER_FLOW = 207016; // aivec over flow
static const int32_t ACL_ERROR_RT_OVER_FLOW = 207017; // common over flow

static const int32_t ACL_ERROR_RT_INTERNAL_ERROR = 507000; // runtime internal error
static const int32_t ACL_ERROR_RT_TS_ERROR = 507001; // ts internel error
static const int32_t ACL_ERROR_RT_STREAM_TASK_FULL = 507002; // task full in stream
static const int32_t ACL_ERROR_RT_STREAM_TASK_EMPTY = 507003; // task empty in stream
static const int32_t ACL_ERROR_RT_STREAM_NOT_COMPLETE = 507004; // stream not complete
static const int32_t ACL_ERROR_RT_END_OF_SEQUENCE = 507005; // end of sequence
static const int32_t ACL_ERROR_RT_EVENT_NOT_COMPLETE = 507006; // event not complete
static const int32_t ACL_ERROR_RT_CONTEXT_RELEASE_ERROR = 507007; // context release error
static const int32_t ACL_ERROR_RT_SOC_VERSION = 507008; // soc version error
static const int32_t ACL_ERROR_RT_TASK_TYPE_NOT_SUPPORT = 507009; // task type not support
static const int32_t ACL_ERROR_RT_LOST_HEARTBEAT = 507010; // ts lost heartbeat
static const int32_t ACL_ERROR_RT_MODEL_EXECUTE = 507011; // model execute failed
static const int32_t ACL_ERROR_RT_REPORT_TIMEOUT = 507012; // report timeout
static const int32_t ACL_ERROR_RT_SYS_DMA = 507013; // sys dma error
static const int32_t ACL_ERROR_RT_AICORE_TIMEOUT = 507014; // aicore timeout
static const int32_t ACL_ERROR_RT_AICORE_EXCEPTION = 507015; // aicore exception
static const int32_t ACL_ERROR_RT_AICORE_TRAP_EXCEPTION = 507016; // aicore trap exception
static const int32_t ACL_ERROR_RT_AICPU_TIMEOUT = 507017; // aicpu timeout
static const int32_t ACL_ERROR_RT_AICPU_EXCEPTION = 507018; // aicpu exception
static const int32_t ACL_ERROR_RT_AICPU_DATADUMP_RSP_ERR = 507019; // aicpu datadump response error
static const int32_t ACL_ERROR_RT_AICPU_MODEL_RSP_ERR = 507020; // aicpu model operate response error
static const int32_t ACL_ERROR_RT_PROFILING_ERROR = 507021; // profiling error
static const int32_t ACL_ERROR_RT_IPC_ERROR = 507022; // ipc error
static const int32_t ACL_ERROR_RT_MODEL_ABORT_NORMAL = 507023; // model abort normal
static const int32_t ACL_ERROR_RT_KERNEL_UNREGISTERING = 507024; // kernel unregistering
static const int32_t ACL_ERROR_RT_RINGBUFFER_NOT_INIT = 507025; // ringbuffer not init
static const int32_t ACL_ERROR_RT_RINGBUFFER_NO_DATA = 507026; // ringbuffer no data
static const int32_t ACL_ERROR_RT_KERNEL_LOOKUP = 507027; // kernel lookup error
static const int32_t ACL_ERROR_RT_KERNEL_DUPLICATE = 507028; // kernel register duplicate
static const int32_t ACL_ERROR_RT_DEBUG_REGISTER_FAIL = 507029; // debug register failed
static const int32_t ACL_ERROR_RT_DEBUG_UNREGISTER_FAIL = 507030; // debug unregister failed
static const int32_t ACL_ERROR_RT_LABEL_CONTEXT = 507031; // label not in current context
static const int32_t ACL_ERROR_RT_PROGRAM_USE_OUT = 507032; // program register num use out
static const int32_t ACL_ERROR_RT_DEV_SETUP_ERROR = 507033; // device setup error
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TIMEOUT = 507034; // vector core timeout
static const int32_t ACL_ERROR_RT_VECTOR_CORE_EXCEPTION = 507035; // vector core exception
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_EXCEPTION = 507036; // vector core trap exception
static const int32_t ACL_ERROR_RT_CDQ_BATCH_ABNORMAL = 507037; // cdq alloc batch abnormal
static const int32_t ACL_ERROR_RT_DIE_MODE_CHANGE_ERROR = 507038; // can not change die mode
static const int32_t ACL_ERROR_RT_DIE_SET_ERROR = 507039; // single die mode can not set die
static const int32_t ACL_ERROR_RT_INVALID_DIEID = 507040; // invalid die id
static const int32_t ACL_ERROR_RT_DIE_MODE_NOT_SET = 507041; // die mode not set
static const int32_t ACL_ERROR_RT_AICORE_TRAP_READ_OVERFLOW = 507042; // aic trap read overflow
static const int32_t ACL_ERROR_RT_AICORE_TRAP_WRITE_OVERFLOW = 507043; // aic trap write overflow
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_READ_OVERFLOW = 507044; // aiv trap read overflow
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_WRITE_OVERFLOW = 507045; // aiv trap write overflow

static const int32_t ACL_ERROR_RT_DRV_INTERNAL_ERROR = 507899; // drv internal error
static const int32_t ACL_ERROR_RT_AICPU_INTERNAL_ERROR = 507900; // aicpu internal error
static const int32_t ACL_ERROR_RT_SOCKET_CLOSE = 507901; // hdc disconnect

#ifdef __cplusplus
}
#endif
#endif // __INC_EXTERNEL_RT_ERROR_CODES_H__

+ 334
- 0
inc/external/acl/ops/acl_cblas.h View File

@@ -0,0 +1,334 @@
/**
* Copyright 2019-2022 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_EXTERNAL_ACL_OPS_ACL_CBLAS_H_
#define INC_EXTERNAL_ACL_OPS_ACL_CBLAS_H_

#include "acl/acl.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum aclTransType { ACL_TRANS_N, ACL_TRANS_T, ACL_TRANS_NZ, ACL_TRANS_NZ_T } aclTransType;

typedef enum aclComputeType { ACL_COMPUTE_HIGH_PRECISION, ACL_COMPUTE_LOW_PRECISION } aclComputeType;

/**
* @ingroup AscendCL
* @brief perform the matrix-vector multiplication
*
* @param transA [IN] transpose type of matrix A
* @param m [IN] number of rows of matrix A
* @param n [IN] number of columns of matrix A
* @param alpha [IN] pointer to scalar used for multiplication.
* of same type as dataTypeC
* @param a [IN] pointer to matrix A
* @param lda [IN] leading dimension used to store the matrix A
* @param dataTypeA [IN] datatype of matrix A
* @param x [IN] pointer to vector x
* @param incx [IN] stride between consecutive elements of vector x
* @param dataTypeX [IN] datatype of vector x
* @param beta [IN] pointer to scalar used for multiplication.
* of same type as dataTypeC If beta == 0,
* then y does not have to be a valid input
* @param y [IN|OUT] pointer to vector y
* @param incy [IN] stride between consecutive elements of vector y
* @param dataTypeY [IN] datatype of vector y
* @param type [IN] computation type
* @param stream [IN] stream
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasGemvEx(aclTransType transA, int m, int n, const void *alpha, const void *a, int lda,
aclDataType dataTypeA, const void *x, int incx, aclDataType dataTypeX,
const void *beta, void *y, int incy, aclDataType dataTypeY,
aclComputeType type, aclrtStream stream);

/**
* @ingroup AscendCL
* @brief create a handle for performing the matrix-vector multiplication
*
* @param transA [IN] transpose type of matrix A
* @param m [IN] number of rows of matrix A
* @param n [IN] number of columns of matrix A
* @param dataTypeA [IN] datatype of matrix A
* @param dataTypeX [IN] datatype of vector x
* @param dataTypeY [IN] datatype of vector y
* @param type [IN] computation type
* @param handle [OUT] pointer to the pointer to the handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForGemvEx(aclTransType transA, int m, int n, aclDataType dataTypeA,
aclDataType dataTypeX, aclDataType dataTypeY,
aclComputeType type, aclopHandle **handle);

/**
* @ingroup AscendCL
* @brief perform the matrix-vector multiplication
*
* @param transA [IN] transpose type of matrix A
* @param m [IN] number of rows of matrix A
* @param n [IN] number of columns of matrix A
* @param alpha [IN] pointer to scalar used for multiplication
* @param a [IN] pointer to matrix A
* @param lda [IN] leading dimension used to store the matrix A
* @param x [IN] pointer to vector x
* @param incx [IN] stride between consecutive elements of vector x
* @param beta [IN] pointer to scalar used for multiplication.
* If beta value == 0,
* then y does not have to be a valid input
* @param y [IN|OUT] pointer to vector y
* @param incy [IN] stride between consecutive elements of vector y
* @param type [IN] computation type
* @param stream [IN] stream
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasHgemv(aclTransType transA, int m, int n, const aclFloat16 *alpha,
const aclFloat16 *a, int lda, const aclFloat16 *x, int incx,
const aclFloat16 *beta, aclFloat16 *y, int incy, aclComputeType type,
aclrtStream stream);

/**
* @ingroup AscendCL
* @brief create a handle for performing the matrix-vector multiplication
*
* @param transA [IN] transpose type of matrix A
* @param m [IN] number of rows of matrix A
* @param n [IN] number of columns of matrix A
* @param type [IN] computation type
* @param handle [OUT] pointer to the pointer to the handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForHgemv(aclTransType transA, int m, int n, aclComputeType type,
aclopHandle **handle);

/**
* @ingroup AscendCL
* @brief perform the matrix-vector multiplication
*
* @param transA [IN] transpose type of matrix A
* @param m [IN] number of rows of matrix A
* @param n [IN] number of columns of matrix A
* @param alpha [IN] pointer to scalar used for multiplication
* @param a [IN] pointer to matrix A
* @param lda [IN] leading dimension used to store the matrix A
* @param x [IN] pointer to vector x
* @param incx [IN] stride between consecutive elements of vector x
* @param beta [IN] pointer to scalar used for multiplication.
* If beta value == 0,
* then y does not have to be a valid input
* @param y [IN|OUT] pointer to vector y
* @param incy [IN] stride between consecutive elements of vector y
* @param type [IN] computation type
* @param stream [IN] stream
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasS8gemv(aclTransType transA, int m, int n, const int32_t *alpha, const int8_t *a,
int lda, const int8_t *x, int incx, const int32_t *beta, int32_t *y,
int incy, aclComputeType type, aclrtStream stream);

/**
* @ingroup AscendCL
* @brief create a handle for performing the matrix-vector multiplication
*
* @param transA [IN] transpose type of matrix A
* @param m [IN] number of rows of matrix A
* @param n [IN] number of columns of matrix A
* @param handle [OUT] pointer to the pointer to the handle
* @param type [IN] computation type
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForS8gemv(aclTransType transA, int m, int n, aclComputeType type,
aclopHandle **handle);

/**
* @ingroup AscendCL
* @brief perform the matrix-matrix multiplication
*
* @param transA [IN] transpose type of matrix A
* @param transB [IN] transpose type of matrix B
* @param transC [IN] transpose type of matrix C
* @param m [IN] number of rows of matrix A and matrix C
* @param n [IN] number of columns of matrix B and matrix C
* @param k [IN] number of columns of matrix A and rows of matrix B
* @param alpha [IN] pointer to scalar used for multiplication. of same type as dataTypeC
* @param matrixA [IN] pointer to matrix A
* @param lda [IN] leading dimension array used to store matrix A
* @param dataTypeA [IN] datatype of matrix A
* @param matrixB [IN] pointer to matrix B
* @param ldb [IN] leading dimension array used to store matrix B
* @param dataTypeB [IN] datatype of matrix B
* @param beta [IN] pointer to scalar used for multiplication.
* of same type as dataTypeC If beta == 0,
* then matrixC does not have to be a valid input
* @param matrixC [IN|OUT] pointer to matrix C
* @param ldc [IN] leading dimension array used to store matrix C
* @param dataTypeC [IN] datatype of matrix C
* @param type [IN] computation type
* @param stream [IN] stream
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasGemmEx(aclTransType transA, aclTransType transB, aclTransType transC, int m, int n,
int k, const void *alpha, const void *matrixA, int lda,
aclDataType dataTypeA, const void *matrixB, int ldb, aclDataType dataTypeB,
const void *beta, void *matrixC, int ldc, aclDataType dataTypeC,
aclComputeType type, aclrtStream stream);

/**
* @ingroup AscendCL
* @brief create a handle for performing the matrix-matrix multiplication
*
* @param transA [IN] transpose type of matrix A
* @param transB [IN] transpose type of matrix B
* @param transC [IN] transpose type of matrix C
* @param m [IN] number of rows of matrix A and matrix C
* @param n [IN] number of columns of matrix B and matrix C
* @param k [IN] number of columns of matrix A and rows of matrix B
* @param dataTypeA [IN] datatype of matrix A
* @param dataTypeB [IN] datatype of matrix B
* @param dataTypeC [IN] datatype of matrix C
* @param type [IN] computation type
* @param handle [OUT] pointer to the pointer to the handle
* @param type [IN] computation type
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForGemmEx(aclTransType transA, aclTransType transB, aclTransType transC,
int m, int n, int k, aclDataType dataTypeA,
aclDataType dataTypeB, aclDataType dataTypeC,
aclComputeType type, aclopHandle **handle);

/**
* @ingroup AscendCL
* @brief perform the matrix-matrix multiplication
*
* @param transA [IN] transpose type of matrix A
* @param transB [IN] transpose type of matrix B
* @param transC [IN] transpose type of matrix C
* @param m [IN] number of rows of matrix A and matrix C
* @param n [IN] number of columns of matrix B and matrix C
* @param k [IN] number of columns of matrix A and rows of matrix B
* @param alpha [IN] pointer to scalar used for multiplication
* @param matrixA [IN] pointer to matrix A
* @param lda [IN] leading dimension used to store the matrix A
* @param matrixB [IN] pointer to matrix B
* @param ldb [IN] leading dimension used to store the matrix B
* @param beta [IN] pointer to scalar used for multiplication.
* If beta value == 0,
* then matrixC does not have to be a valid input
* @param matrixC [IN|OUT] pointer to matrix C
* @param ldc [IN] leading dimension used to store the matrix C
* @param type [IN] computation type
* @param stream [IN] stream
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasHgemm(aclTransType transA, aclTransType transB, aclTransType transC, int m, int n,
int k, const aclFloat16 *alpha, const aclFloat16 *matrixA, int lda,
const aclFloat16 *matrixB, int ldb, const aclFloat16 *beta,
aclFloat16 *matrixC, int ldc, aclComputeType type, aclrtStream stream);

/**
* @ingroup AscendCL
* @brief create a handle for performing the matrix-matrix multiplication
*
* @param transA [IN] transpose type of matrix A
* @param transB [IN] transpose type of matrix B
* @param transC [IN] transpose type of matrix C
* @param m [IN] number of rows of matrix A and matrix C
* @param n [IN] number of columns of matrix B and matrix C
* @param k [IN] number of columns of matrix A and rows of matrix B
* @param type [IN] computation type
* @param handle [OUT] pointer to the pointer to the handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForHgemm(aclTransType transA, aclTransType transB, aclTransType transC,
int m, int n, int k, aclComputeType type,
aclopHandle **handle);

/**
* @ingroup AscendCL
* @brief perform the matrix-matrix multiplication
*
* @param transA [IN] transpose type of matrix A
* @param transB [IN] transpose type of matrix B
* @param transC [IN] transpose type of matrix C
* @param m [IN] number of rows of matrix A and matrix C
* @param n [IN] number of columns of matrix B and matrix C
* @param k [IN] number of columns of matrix A and rows of matrix B
* @param alpha [IN] pointer to scalar used for multiplication
* @param matrixA [IN] pointer to matrix A
* @param lda [IN] leading dimension used to store the matrix A
* @param matrixB [IN] pointer to matrix B
* @param ldb [IN] leading dimension used to store the matrix B
* @param beta [IN] pointer to scalar used for multiplication.
* If beta value == 0,
* then matrixC does not have to be a valid input
* @param matrixC [IN|OUT] pointer to matrix C
* @param ldc [IN] leading dimension used to store the matrix C
* @param type [IN] computation type
* @param stream [IN] stream
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasS8gemm(aclTransType transA, aclTransType transB, aclTransType transC, int m, int n,
int k, const int32_t *alpha, const int8_t *matrixA, int lda,
const int8_t *matrixB, int ldb, const int32_t *beta, int32_t *matrixC,
int ldc, aclComputeType type, aclrtStream stream);

/**
* @ingroup AscendCL
* @brief create a handle for performing the matrix-matrix multiplication
*
* @param transA [IN] transpose type of matrix A
* @param transB [IN] transpose type of matrix B
* @param transC [IN] transpose type of matrix C
* @param m [IN] number of rows of matrix A and matrix C
* @param n [IN] number of columns of matrix B and matrix C
* @param k [IN] number of columns of matrix A and rows of matrix B
* @param type [IN] computation type
* @param handle [OUT] pointer to the pointer to the handle
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForS8gemm(aclTransType transA, aclTransType transB, aclTransType transC,
int m, int n, int k, aclComputeType type,
aclopHandle **handle);

#ifdef __cplusplus
}
#endif

#endif // INC_EXTERNAL_ACL_OPS_ACL_CBLAS_H_

+ 2683
- 0
inc/external/acl/ops/acl_dvpp.h
File diff suppressed because it is too large
View File


+ 348
- 0
inc/external/acl/ops/acl_fv.h View File

@@ -0,0 +1,348 @@
/**
* Copyright 2019-2022 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_EXTERNAL_ACL_OPS_ACL_RETR_H_
#define INC_EXTERNAL_ACL_OPS_ACL_RETR_H_

#include "acl/acl.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct aclfvInitPara aclfvInitPara;
typedef struct aclfvFeatureInfo aclfvFeatureInfo;
typedef struct aclfvRepoRange aclfvRepoRange;
typedef struct aclfvQueryTable aclfvQueryTable;
typedef struct aclfvSearchInput aclfvSearchInput;
typedef struct aclfvSearchResult aclfvSearchResult;

// search operation type
enum aclfvSearchType {
SEARCH_1_N, // 1:N operation type
SEARCH_N_M // N:M operation type
};

/**
* @ingroup AscendCL
* @brief Create fv init param.
*
* @param fsNum [IN] The feature num
*
* @retval null for failed.
* @retval OtherValues success.
*/
ACL_FUNC_VISIBILITY aclfvInitPara *aclfvCreateInitPara(uint64_t fsNum);

/**
* @ingroup AscendCL
* @brief Destroy fv init param.
*
* @par Function
* Can only destroy fv init param information created
* through aclfvCreateInitPara interface.
*
* @param initPara [IN] fv init param.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclfvCreateInitPara
*/
ACL_FUNC_VISIBILITY aclError aclfvDestroyInitPara(aclfvInitPara *initPara);

/**
* @ingroup AscendCL
* @brief set value for maxTopNumFor1N which in fv init param.
*
* @param initPara [IN|OUT] fv init param.
* @param maxTopNumFor1N [IN] maxTopNumFor1N value for init param.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclfvSet1NTopNum(aclfvInitPara *initPara, uint32_t maxTopNumFor1N);

/**
* @ingroup AscendCL
* @brief set value for maxTopNumForNM which in fv init param.
*
* @param initPara [IN|OUT] fv init param.
* @param maxTopNumForNM [IN] maxTopNumForNM value for init param.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclfvSetNMTopNum(aclfvInitPara *initPara, uint32_t maxTopNumForNM);

/**
* @ingroup AscendCL
* @brief Create fv feature info.
*
* @param id0 [IN] The first level library id0
* @param id1 [IN] Secondary library id1
* @param offset [IN] The offset of the first feature in the library
* @param featureLen [IN] Single feature length
* @param featureCount [IN] Single feature count
* @param featureData [IN] Feature value list
* @param featureDataLen [IN] Feature value list length
*
* @retval null for failed.
* @retval OtherValues success.
*/
ACL_FUNC_VISIBILITY aclfvFeatureInfo *aclfvCreateFeatureInfo(uint32_t id0, uint32_t id1, uint32_t offset,
uint32_t featureLen, uint32_t featureCount,
uint8_t *featureData, uint32_t featureDataLen);

/**
* @ingroup AscendCL
* @brief Destroy fv feature info.
*
* @par Function
* Can only destroy fv feature info information created
* through aclfvCreateFeatureInfo interface.
*
* @param featureInfo [IN] fv feature info.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclfvCreateFeatureInfo
*/
ACL_FUNC_VISIBILITY aclError aclfvDestroyFeatureInfo(aclfvFeatureInfo *featureInfo);

/**
* @ingroup AscendCL
* @brief Create fv repo range.
*
* @param id0Min [IN] id0 start value
* @param id0Min [IN] id0 max
* @param id1Min [IN] id0 start value
* @param id1Max [IN] id1 max
*
* @retval null for failed. OtherValues success
*/
ACL_FUNC_VISIBILITY aclfvRepoRange *aclfvCreateRepoRange(uint32_t id0Min, uint32_t id0Max, uint32_t id1Min,
uint32_t id1Max);

/**
* @ingroup AscendCL
* @brief Destroy fv repo range.
*
* @par Function
* Can only destroy fv repo range information created
* through aclfvCreateRepoRange interface.
*
* @param repoRange [IN] fv repo range.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclfvCreateRepoRange
*/
ACL_FUNC_VISIBILITY aclError aclfvDestroyRepoRange(aclfvRepoRange *repoRange);

/**
* @ingroup AscendCL
* @brief Create query table.
*
* @param queryCnt [IN] Number of tables, the maximum number is 6
* @param tableLen [IN] Single table length, table length is 32KB
* @param tableData [IN] Feature value list
* @param tableDataLen [IN] The length of memory requested by the featureData pointer
*
* @retval null for failed. OtherValues success
*/
ACL_FUNC_VISIBILITY aclfvQueryTable *aclfvCreateQueryTable(uint32_t queryCnt, uint32_t tableLen, uint8_t *tableData,
uint32_t tableDataLen);

/**
* @ingroup AscendCL
* @brief Destroy query table.
*
* @par Function
* Can only destroy query table information created
* through aclfvCreateQueryTable interface.
*
* @param queryTable [IN] query table.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclfvCreateQueryTable
*/
ACL_FUNC_VISIBILITY aclError aclfvDestroyQueryTable(aclfvQueryTable *queryTable);

/**
* @ingroup AscendCL
* @brief Create search input.
*
* @param queryTable [IN] query table
* @param repoRange [IN] query repo range
* @param topk [IN] query topk
*
* @retval null for failed. OtherValues success
*/
ACL_FUNC_VISIBILITY aclfvSearchInput *aclfvCreateSearchInput(aclfvQueryTable *queryTable, aclfvRepoRange *repoRange,
uint32_t topk);

/**
* @ingroup AscendCL
* @brief Destroy search input.
*
* @par Function
* Can only destroy search input information created
* through aclfvCreateSearchInput interface.
*
* @param searchInput [IN] search input.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclfvCreateSearchInput
*/
ACL_FUNC_VISIBILITY aclError aclfvDestroySearchInput(aclfvSearchInput *searchInput);

/**
* @ingroup AscendCL
* @brief Create search result.
*
* @param queryCnt [IN] Retrieve the number of features
* @param resultNum [IN] The number of search results for each feature, the number is queryCnt
* @param resultNumDataLen [IN] resultNum memory length
* @param id0 [IN] Level 1 library id0
* @param id1 [IN] Secondary library id1
* @param resultOffset [IN] The offset of the bottom library corresponding
* to each feature retrieval result, total length topK * queryCnt
* @param resultDistance [IN] Distance, total length topK * queryCnt
* @param dataLen [IN] The memory size requested by
* id0\id1\reslutOffset\resultDistance
*
* @retval null for failed. OtherValues success
*/
ACL_FUNC_VISIBILITY aclfvSearchResult *aclfvCreateSearchResult(uint32_t queryCnt, uint32_t *resultNum,
uint32_t resultNumDataLen, uint32_t *id0, uint32_t *id1,
uint32_t *resultOffset, float *resultDistance,
uint32_t dataLen);

/**
* @ingroup AscendCL
* @brief Destroy search result.
*
* @par Function
* Can only destroy search result information created
* through aclfvCreateSearchResult interface.
*
* @param searchResult [IN] search result.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*
* @see aclfvCreateSearchResult
*/
ACL_FUNC_VISIBILITY aclError aclfvDestroySearchResult(aclfvSearchResult *searchResult);

/**
* @ingroup AscendCL
* @brief fv IP initialize.
*
* @param initPara [IN] fv init param.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure.
*/
ACL_FUNC_VISIBILITY aclError aclfvInit(aclfvInitPara *initPara);

/**
* @ingroup AscendCL
* @brief release fv resources.
*
* @par Function
* Can only release fv resources created
* through aclfvInit interface.
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure.
*
* @see aclfvInit
*/
ACL_FUNC_VISIBILITY aclError aclfvRelease();

/**
* @ingroup AscendCL
* @brief fv repo add.
*
* @param type [IN] repo add type
* @param featureInfo [IN] add feature information
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure.
*/
ACL_FUNC_VISIBILITY aclError aclfvRepoAdd(aclfvSearchType type, aclfvFeatureInfo *featureInfo);

/**
* @ingroup AscendCL
* @brief fv repo del.
*
* @param type [IN] repo delete type
* @param repoRange [IN] repo range information
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure.
*/
ACL_FUNC_VISIBILITY aclError aclfvRepoDel(aclfvSearchType type, aclfvRepoRange *repoRange);

/**
* @ingroup AscendCL
* @brief fv accurate del.
*
* @param featureInfo [IN] accurate delete feature information
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure.
*/
ACL_FUNC_VISIBILITY aclError aclfvDel(aclfvFeatureInfo *featureInfo);

/**
* @ingroup AscendCL
* @brief fv accurate modify.
*
* @param featureInfo [IN] accurate modify feature information
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure.
*/
ACL_FUNC_VISIBILITY aclError aclfvModify(aclfvFeatureInfo *featureInfo);

/**
* @ingroup AscendCL
* @brief fv search.
*
* @param type [IN] search type
* @param searchInput [IN] search input
* @param searchRst [OUT] search result
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure.
*/
ACL_FUNC_VISIBILITY aclError aclfvSearch(aclfvSearchType type, aclfvSearchInput *searchInput,
aclfvSearchResult *searchRst);

#ifdef __cplusplus
}
#endif

#endif // INC_EXTERNAL_ACL_OPS_ACL_RETR_H_

+ 14
- 14
inc/external/ge/ge_api.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright 2019-2022 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.
@@ -57,22 +57,22 @@ class GE_FUNC_VISIBILITY Session {

///
/// @ingroup client
/// @brief add a graph with a specific graphId
/// @param [in] graphId graph id
/// @brief add a graph with a specific graph id
/// @param [in] graph_id graph id
/// @return Status result of function
///
Status AddGraph(uint32_t graphId, const Graph &graph);
Status AddGraph(uint32_t graph_id, const Graph &graph);

///
/// @ingroup client
/// @brief add a graph with a specific graphId and graphOptions
/// @brief add a graph with a specific graph id and graphOptions
/// @param [in] graphId graph id
/// @param [in] graph the graph
/// @param [in] options graph options
/// @return Status result of function
///
ATTRIBUTED_DEPRECATED(Status AddGraph(uint32_t, const Graph &, const std::map<AscendString, AscendString> &))
Status AddGraph(uint32_t graphId, const Graph &graph, const std::map<std::string, std::string> &options);
Status AddGraph(uint32_t graph_id, const Graph &graph, const std::map<std::string, std::string> &options);

///
/// @ingroup client
@@ -82,7 +82,7 @@ class GE_FUNC_VISIBILITY Session {
/// @param [in] options graph options
/// @return Status result of function
///
Status AddGraph(uint32_t graphId, const Graph &graph, const std::map<AscendString, AscendString> &options);
Status AddGraph(uint32_t graph_id, const Graph &graph, const std::map<AscendString, AscendString> &options);

///
/// @ingroup client
@@ -106,10 +106,10 @@ class GE_FUNC_VISIBILITY Session {
///
/// @ingroup ge_graph
/// @brief remove a graph of the session with specific session id
/// @param [in] graphId graph id
/// @param [in] graph_d graph id
/// @return Status result of function
///
Status RemoveGraph(uint32_t graphId);
Status RemoveGraph(uint32_t graph_id);

///
/// @ingroup ge_graph
@@ -119,7 +119,7 @@ class GE_FUNC_VISIBILITY Session {
/// @param [out] outputs output data
/// @return Status result of function
///
Status RunGraph(uint32_t graphId, const std::vector<Tensor> &inputs, std::vector<Tensor> &outputs);
Status RunGraph(uint32_t graph_id, const std::vector<Tensor> &inputs, std::vector<Tensor> &outputs);

///
/// @ingroup ge_graph
@@ -140,9 +140,9 @@ class GE_FUNC_VISIBILITY Session {
/// @param [in] inputs: input data
/// @return Status result of function
///
Status BuildGraph(uint32_t graphId, const std::vector<InputTensorInfo> &inputs);
Status BuildGraph(uint32_t graph_id, const std::vector<InputTensorInfo> &inputs);

Status BuildGraph(uint32_t graphId, const std::vector<ge::Tensor> &inputs); /*lint !e148*/
Status BuildGraph(uint32_t graph_id, const std::vector<ge::Tensor> &inputs); /*lint !e148*/

///
/// @ingroup ge_graph
@@ -154,7 +154,7 @@ class GE_FUNC_VISIBILITY Session {
/// Please ensure that the implementation of the function is trusted.
/// @return Status result of function
///
Status RunGraphAsync(uint32_t graphId, const std::vector<ge::Tensor> &inputs, RunAsyncCallback callback);
Status RunGraphAsync(uint32_t graph_id, const std::vector<ge::Tensor> &inputs, RunAsyncCallback callback);

///
/// @ingroup ge_graph
@@ -189,7 +189,7 @@ class GE_FUNC_VISIBILITY Session {

Status RegisterCallBackFunc(const char *key, const session::pCallBackFunc &callback);

bool IsGraphNeedRebuild(uint32_t graphId);
bool IsGraphNeedRebuild(uint32_t graph_id);

private:
uint64_t sessionId_;


+ 27
- 57
inc/external/ge/ge_api_error_codes.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright 2019-2022 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.
@@ -20,14 +20,27 @@
#include <map>
#include <string>
#include "ge_error_codes.h"
#include "ge_api_types.h"

namespace ge {
#ifdef __GNUC__
#define ATTRIBUTED_DEPRECATED(replacement) __attribute__((deprecated("Please use " #replacement " instead.")))
#else
#define ATTRIBUTED_DEPRECATED(replacement) __declspec(deprecated("Please use " #replacement " instead."))
#endif

// Code compose(4 byte), runtime: 2 bit, type: 2 bit, level: 3 bit, sysid: 8 bit, modid: 5 bit, value: 12 bit
#define GE_ERRORNO(runtime, type, level, sysid, modid, name, value, desc) \
constexpr ge::Status name = (static_cast<uint32_t>(0xFFU & (static_cast<uint32_t>(runtime))) << 30U) | \
(static_cast<uint32_t>(0xFFU & (static_cast<uint32_t>(type))) << 28U) | \
(static_cast<uint32_t>(0xFFU & (static_cast<uint32_t>(level))) << 25U) | \
(static_cast<uint32_t>(0xFFU & (static_cast<uint32_t>(sysid))) << 17U) | \
(static_cast<uint32_t>(0xFFU & (static_cast<uint32_t>(modid))) << 12U) | \
(static_cast<uint32_t>(0x0FFFU) & (static_cast<uint32_t>(value))); \
const ErrorNoRegisterar g_errorno_##name((name), (desc));

#define GE_ERRORNO_EXTERNAL(name, desc) const ErrorNoRegisterar g_errorno_##name((name), (desc));

namespace ge {
class GE_FUNC_VISIBILITY StatusFactory {
public:
static StatusFactory *Instance() {
@@ -35,7 +48,7 @@ class GE_FUNC_VISIBILITY StatusFactory {
return &instance;
}

void RegisterErrorNo(uint32_t err, const std::string &desc) {
void RegisterErrorNo(const uint32_t err, const std::string &desc) {
// Avoid repeated addition
if (err_desc_.find(err) != err_desc_.end()) {
return;
@@ -43,19 +56,19 @@ class GE_FUNC_VISIBILITY StatusFactory {
err_desc_[err] = desc;
}

void RegisterErrorNo(uint32_t err, const char *desc) {
void RegisterErrorNo(const uint32_t err, const char *const desc) {
if (desc == nullptr) {
return;
}
std::string error_desc = desc;
const std::string error_desc = desc;
if (err_desc_.find(err) != err_desc_.end()) {
return;
}
err_desc_[err] = error_desc;
}

std::string GetErrDesc(uint32_t err) {
auto iter_find = err_desc_.find(err);
std::string GetErrDesc(const uint32_t err) {
const std::map<uint32_t, std::string>::const_iterator iter_find = err_desc_.find(err);
if (iter_find == err_desc_.end()) {
return "";
}
@@ -72,61 +85,18 @@ class GE_FUNC_VISIBILITY StatusFactory {

class GE_FUNC_VISIBILITY ErrorNoRegisterar {
public:
ErrorNoRegisterar(uint32_t err, const std::string &desc) { StatusFactory::Instance()->RegisterErrorNo(err, desc); }
ErrorNoRegisterar(uint32_t err, const char *desc) { StatusFactory::Instance()->RegisterErrorNo(err, desc); }
ErrorNoRegisterar(const uint32_t err, const std::string &desc) noexcept {
StatusFactory::Instance()->RegisterErrorNo(err, desc);
}
ErrorNoRegisterar(const uint32_t err, const char *const desc) noexcept {
StatusFactory::Instance()->RegisterErrorNo(err, desc);
}
~ErrorNoRegisterar() {}
};

// Code compose(4 byte), runtime: 2 bit, type: 2 bit, level: 3 bit, sysid: 8 bit, modid: 5 bit, value: 12 bit
#define GE_ERRORNO(runtime, type, level, sysid, modid, name, value, desc) \
constexpr ge::Status name = \
((0xFF & (static_cast<uint8_t>(runtime))) << 30) | ((0xFF & (static_cast<uint8_t>(type))) << 28) | \
((0xFF & (static_cast<uint8_t>(level))) << 25) | ((0xFF & (static_cast<uint8_t>(sysid))) << 17) | \
((0xFF & (static_cast<uint8_t>(modid))) << 12) | (0x0FFF & (static_cast<uint16_t>(value))); \
const ErrorNoRegisterar g_##name##_errorno(name, desc);

#define GE_ERRORNO_EXTERNAL(name, desc) const ErrorNoRegisterar g_##name##_errorno(name, desc);

using Status = uint32_t;

// General error code
GE_ERRORNO(0, 0, 0, 0, 0, SUCCESS, 0, "success");
GE_ERRORNO(0b11, 0b11, 0b111, 0xFF, 0b11111, FAILED, 0xFFF, "failed"); /*lint !e401*/

GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_PARAM_INVALID, "Parameter invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_NOT_INIT, "GE executor not initialized yet.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID, "Model file path invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "Model id invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "Data size of model invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID, "Model addr invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID, "Queue id of model invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_MODEL_REPEATED, "The model loaded repeatedly.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic input addr invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, "Dynamic input size invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, "Dynamic batch size invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_AIPP_BATCH_EMPTY, "AIPP batch parameter empty.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_AIPP_NOT_EXIST, "AIPP parameter not exist.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_AIPP_MODE_INVALID, "AIPP mode invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_OP_TASK_TYPE_INVALID, "Task type invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, "Kernel type invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_PLGMGR_PATH_INVALID, "Plugin path is invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_FORMAT_INVALID, "Format is invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_SHAPE_INVALID, "Shape is invalid.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_DATATYPE_INVALID, "Datatype is invalid.");

GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_MEMORY_ALLOCATION, "Memory allocation error.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate memory.");

GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_INTERNAL_ERROR, "Internal error.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_LOAD_MODEL, "Load model error.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_MODEL_PARTITION_FAILED, "Failed to load model partition.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED, "Failed to load weight partition.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED, "Failed to load task partition.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_KERNEL_PARTITION_FAILED, "Failed to load op kernel partition.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA, "Failed to release the model data.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_COMMAND_HANDLE, "Command handle error.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_GET_TENSOR_INFO, "Get tensor info error.");
GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_UNLOAD_MODEL, "Load model error.");
GE_ERRORNO(0b11, 0b11, 0b111, 0xFFU, 0b11111, FAILED, 0xFFFU, "failed"); /*lint !e401*/

} // namespace ge



+ 193
- 137
inc/external/ge/ge_api_types.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright 2019-2022 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.
@@ -24,96 +24,111 @@
#include <functional>
#include <memory>
#include "graph/tensor.h"
#include "graph/types.h"

namespace ge {
// Option key: graph run mode
const char *const OPTION_GRAPH_RUN_MODE = "ge.graphRunMode";
const char_t *const OPTION_GRAPH_RUN_MODE = "ge.graphRunMode";
const char_t *const OPTION_DEVICE_TYPE = "ge.deviceType";

// Option key: ome init
const char *const OPTION_EXEC_SESSION_ID = "ge.exec.sessionId";
const char *const OPTION_EXEC_DEVICE_ID = "ge.exec.deviceId";
const char *const OPTION_EXEC_JOB_ID = "ge.exec.jobId";
const char *const OPTION_EXEC_IS_USEHCOM = "ge.exec.isUseHcom";
const char *const OPTION_EXEC_IS_USEHVD = "ge.exec.isUseHvd";
const char *const OPTION_EXEC_RANK_ID = "ge.exec.rankId";
const char *const OPTION_EXEC_POD_NAME = "ge.exec.podName";
const char *const OPTION_EXEC_DEPLOY_MODE = "ge.exec.deployMode";
const char *const OPTION_EXEC_RANK_TABLE_FILE = "ge.exec.rankTableFile";
const char *const GE_AICPU_FLAG = "ge.aicpuFlag";
const char *const OPTION_EXEC_EXTERN_PLUGIN_PATH = "ge.soLoadPath";
const char_t *const OPTION_EXEC_SESSION_ID = "ge.exec.sessionId";
const char_t *const OPTION_EXEC_DEVICE_ID = "ge.exec.deviceId";
const char_t *const OPTION_EXEC_JOB_ID = "ge.exec.jobId";
const char_t *const OPTION_EXEC_IS_USEHCOM = "ge.exec.isUseHcom";
const char_t *const OPTION_EXEC_IS_USEHVD = "ge.exec.isUseHvd";
const char_t *const OPTION_EXEC_RANK_ID = "ge.exec.rankId";
const char_t *const OPTION_EXEC_POD_NAME = "ge.exec.podName";
const char_t *const OPTION_EXEC_DEPLOY_MODE = "ge.exec.deployMode";
const char_t *const OPTION_EXEC_RANK_TABLE_FILE = "ge.exec.rankTableFile";
const char_t *const GE_AICPU_FLAG = "ge.aicpuFlag";
const char_t *const OPTION_EXEC_EXTERN_PLUGIN_PATH = "ge.soLoadPath";
// Dump flag and para
const char *const OPTION_EXEC_ENABLE_DUMP = "ge.exec.enableDump";
const char *const OPTION_EXEC_DUMP_PATH = "ge.exec.dumpPath";
const char *const OPTION_EXEC_DUMP_STEP = "ge.exec.dumpStep";
const char *const OPTION_EXEC_DUMP_MODE = "ge.exec.dumpMode";
const char *const OPTION_EXEC_ENABLE_DUMP_DEBUG = "ge.exec.enableDumpDebug";
const char *const OPTION_EXEC_DUMP_DEBUG_MODE = "ge.exec.dumpDebugMode";
const char *const OPTION_EXEC_ENABLE_INCRE_BUILD = "ge.exec.enableIncreBuild";
const char *const OPTION_EXEC_INCRE_BUILD_CACHE_PATH = "ge.exec.increBuildCachePath";
const char *const OPTION_EXEC_ENABLE_EXCEPTION_DUMP = "ge.exec.enable_exception_dump";
const char *const OPTION_EXEC_ENABLE_SCOPE_FUSION_PASSES = "ge.exec.enableScopeFusionPasses";
const char *const OPTION_EXEC_PROFILING_FPPONIT_OPTIONS = "ge.exec.profilingFpPointOptions";
const char *const OPTION_EXEC_PROFILING_BPPONIT_OPTIONS = "ge.exec.profilingBpPointOptions";
const char_t *const OPTION_EXEC_ENABLE_DUMP = "ge.exec.enableDump";
const char_t *const OPTION_EXEC_DUMP_PATH = "ge.exec.dumpPath";
const char_t *const OPTION_EXEC_DUMP_STEP = "ge.exec.dumpStep";
const char_t *const OPTION_EXEC_DUMP_MODE = "ge.exec.dumpMode";
const char_t *const OPTION_EXEC_ENABLE_DUMP_DEBUG = "ge.exec.enableDumpDebug";
const char_t *const OPTION_EXEC_DUMP_DEBUG_MODE = "ge.exec.dumpDebugMode";
const char_t *const OPTION_EXEC_ENABLE_INCRE_BUILD = "ge.exec.enableIncreBuild";
const char_t *const OPTION_EXEC_INCRE_BUILD_CACHE_PATH = "ge.exec.increBuildCachePath";
const char_t *const OPTION_EXEC_ENABLE_EXCEPTION_DUMP = "ge.exec.enable_exception_dump";
const char_t *const OPTION_EXEC_ENABLE_SCOPE_FUSION_PASSES = "ge.exec.enableScopeFusionPasses";
const char_t *const OPTION_EXEC_PROFILING_FPPONIT_OPTIONS = "ge.exec.profilingFpPointOptions";
const char_t *const OPTION_EXEC_PROFILING_BPPONIT_OPTIONS = "ge.exec.profilingBpPointOptions";
// profiling flag
const char *const OPTION_EXEC_PROFILING_MODE = "ge.exec.profilingMode";
const char *const OPTION_EXEC_PROFILING_OPTIONS = "ge.exec.profilingOptions";
const char_t *const OPTION_EXEC_PROFILING_MODE = "ge.exec.profilingMode";
const char_t *const OPTION_EXEC_PROFILING_OPTIONS = "ge.exec.profilingOptions";
// Hccl flag, if ge.exec.hcclFlag =1, it means load plugin for opskernel, else:ge.exec.hcclFlag =0
const char *const OPTION_EXEC_HCCL_FLAG = "ge.exec.hcclFlag";
const char *const OPTION_EXEC_ATOMIC_FLAG = "ge.exec.enable_atomic";
const char *const OPTION_EXEC_DISABLE_REUSED_MEMORY = "ge.exec.disableReuseMemory";
const char *const OPTION_EXEC_ENABLE_TAILING_OPTIMIZATION = "ge.exec.isTailingOptimization";
const char_t *const OPTION_EXEC_HCCL_FLAG = "ge.exec.hcclFlag";
const char_t *const OPTION_EXEC_ATOMIC_FLAG = "ge.exec.enable_atomic";
const char_t *const OPTION_EXEC_DISABLE_REUSED_MEMORY = "ge.exec.disableReuseMemory";
const char_t *const OPTION_EXEC_ENABLE_TAILING_OPTIMIZATION = "ge.exec.isTailingOptimization";
// Dynamic input flag. ge.exec.dynamicInput=1, means enable dynaimc input,
// ge.exec.dynamicGraphExecuteMode, dynamic_execute[default]
const char *const OPTION_EXEC_DYNAMIC_INPUT = "ge.exec.dynamicInput";
const char *const OPTION_EXEC_DYNAMIC_EXECUTE_MODE = "ge.exec.dynamicGraphExecuteMode";
const char *const OPTION_EXEC_DATA_INPUTS_SHAPE_RANGE = "ge.exec.dataInputsShapeRange";
const char_t *const OPTION_EXEC_DYNAMIC_INPUT = "ge.exec.dynamicInput";
const char_t *const OPTION_EXEC_DYNAMIC_EXECUTE_MODE = "ge.exec.dynamicGraphExecuteMode";
const char_t *const OPTION_EXEC_DATA_INPUTS_SHAPE_RANGE = "ge.exec.dataInputsShapeRange";
const char_t *const OPTION_EXEC_ENABLE_COPY_OUTPUT_ADDR = "ge.exec.enableCopyOutputAddr";
const char_t *const OPTION_EXEC_GRAPH_EXEC_TIMEOUT = "ge.exec.graphExecTimeout";

// Option key: memory init
const char *const GRAPH_MEMORY_MAX_SIZE = "ge.graphMemoryMaxSize";
const char *const VARIABLE_MEMORY_MAX_SIZE = "ge.variableMemoryMaxSize";
const char_t *const GRAPH_MEMORY_MAX_SIZE = "ge.graphMemoryMaxSize";
const char_t *const VARIABLE_MEMORY_MAX_SIZE = "ge.variableMemoryMaxSize";
const char_t *const OPTION_EXEC_REUSE_ZERO_COPY_MEMORY = "ge.exec.reuseZeroCopyMemory";

const std::string ATOMIC_CLEAN_POLICY = "ge.exec.atomicCleanPolicy";

const char_t *const OPTION_EXEC_LOGICAL_DEVICE_CLUSTER_DEPLOY_MODE = "ge.exec.logicalDeviceClusterDeployMode";
const char_t *const OPTION_EXEC_LOGICAL_DEVICE_ID = "ge.exec.logicalDeviceId";

namespace configure_option {
const char *const STREAM_NUM = "ge.streamNum";
const char *const HEAD_STREAM = "ge.headStream";
const char *const PERF_LEVEL = "ge.perfLevel";
const char *const ENCRYPT_MODE = "ge.encryptMode";
const char *const EK_FILE = "ge.ekFile";
const char *const CERT_FILE = "ge.certFile";
const char *const HW_KEY_FILE = "ge.hwKeyFile";
const char *const PRIVATE_KEY_FILE = "ge.privateKeyFile";
const char *const FRAMEWORK_TYPE = "ge.frameworkType";
const char *const CALIBRATION_CONF_FILE = "ge.calibrationConfFile";
const char *const INSERT_OP_FILE = "ge.insertOpFile";
const char *const OUTPUT_NODE_NAME = "ge.outputNodeName";
const char *const COMPRESS_FLAG = "ge.compressFlag";
const char *const PRECISION_MODE = "ge.exec.precision_mode";
const char *const SINGLE_OP_FLAG = "ge.exec.single_op";
const char *const TRAIN_FLAG = "ge.trainFlag";
const char *const RUN_FLAG = "ge.runFlag";
const char *const LOCAL_FMKOP_FLAG = "ge.enabledLocalFmkop";
const char *const TBE_PLUGIN_PATH_FLAG = "ge.TBE_plugin_path";
const char *const DDK_VERSION_FLAG = "ge.DDK_version";
const char *const GE_FE_FLAG = "ge.feFlag";
const char *const STREAM_MAX_PARALLEL_NUM = "ge.streamMaxParallelNum";
const char *const OUTPUT_DATATYPE = "ge.outputDatatype";
const char *const OP_SELECT_IMPL_MODE = "ge.opSelectImplmode";
const char *const OPTYPELIST_FOR_IMPLMODE = "ge.optypelistForImplmode";
const char *const HCOM_PARALLEL = "ge.hcomParallel";
const char *const AUTO_TUNE_MODE = "ge.autoTuneMode";
const char *const SOC_VERSION = "ge.socVersion";
const char *const CORE_TYPE = "ge.engineType";
const char *const AICORE_NUM = "ge.aicoreNum";
const char *const L1_FUSION = "ge.l1Fusion";
const char *const BUFFER_OPTIMIZE = "ge.bufferOptimize";
const char *const ENABLE_SMALL_CHANNEL = "ge.enableSmallChannel";
const char *const ENABLE_COMPRESS_WEIGHT = "ge.enableCompressWeight";
const char *const FUSION_SWITCH_FILE = "ge.fusionSwitchFile";
const char *const SAVE_ORIGINAL_MODEL = "ge.saveOriginalModel";
const char *const ORIGINAL_MODEL_FILE = "ge.originalModelFile";
const char *const INPUT_FP16_NODES = "ge.INPUT_NODES_SET_FP16";
const char *const OP_DEBUG_LEVEL = "ge.opDebugLevel";
const char *const PERFORMANCE_MODE = "ge.performance_mode";
const char *const MODIFY_MIXLIST = "ge.exec.modify_mixlist";
const char *const OP_PRECISION_MODE = "ge.exec.op_precision_mode";
const char_t *const STREAM_NUM = "ge.streamNum";
const char_t *const HEAD_STREAM = "ge.headStream";
const char_t *const PERF_LEVEL = "ge.perfLevel";
const char_t *const ENCRYPT_MODE = "ge.encryptMode";
const char_t *const EK_FILE = "ge.ekFile";
const char_t *const CERT_FILE = "ge.certFile";
const char_t *const HW_KEY_FILE = "ge.hwKeyFile";
const char_t *const PRIVATE_KEY_FILE = "ge.privateKeyFile";
const char_t *const FRAMEWORK_TYPE = "ge.frameworkType";
const char_t *const CALIBRATION_CONF_FILE = "ge.calibrationConfFile";
const char_t *const INSERT_OP_FILE = "ge.insertOpFile";
const char_t *const OUTPUT_NODE_NAME = "ge.outputNodeName";
const char_t *const COMPRESS_FLAG = "ge.compressFlag";
const char_t *const PRECISION_MODE = "ge.exec.precision_mode";
const char_t *const SINGLE_OP_FLAG = "ge.exec.single_op";
const char_t *const TRAIN_FLAG = "ge.trainFlag";
const char_t *const RUN_FLAG = "ge.runFlag";
const char_t *const LOCAL_FMKOP_FLAG = "ge.enabledLocalFmkop";
const char_t *const TBE_PLUGIN_PATH_FLAG = "ge.TBE_plugin_path";
const char_t *const DDK_VERSION_FLAG = "ge.DDK_version";
const char_t *const GE_FE_FLAG = "ge.feFlag";
const char_t *const STREAM_MAX_PARALLEL_NUM = "ge.streamMaxParallelNum";
const char_t *const OUTPUT_DATATYPE = "ge.outputDatatype";
const char_t *const OP_SELECT_IMPL_MODE = "ge.opSelectImplmode";
const char_t *const OPTYPELIST_FOR_IMPLMODE = "ge.optypelistForImplmode";
const char_t *const HCOM_PARALLEL = "ge.hcomParallel";
const char_t *const AUTO_TUNE_MODE = "ge.autoTuneMode";
const char_t *const SOC_VERSION = "ge.socVersion";
const char_t *const VIRTUAL_TYPE = "ge.virtual_type";
const char_t *const CORE_TYPE = "ge.engineType";
const char_t *const AICORE_NUM = "ge.aicoreNum";
const char_t *const L1_FUSION = "ge.l1Fusion";
const char_t *const BUFFER_OPTIMIZE = "ge.bufferOptimize";
const char_t *const ENABLE_SMALL_CHANNEL = "ge.enableSmallChannel";
const char_t *const ENABLE_COMPRESS_WEIGHT = "ge.enableCompressWeight";
const char_t *const FUSION_SWITCH_FILE = "ge.fusionSwitchFile";
const char_t *const SAVE_ORIGINAL_MODEL = "ge.saveOriginalModel";
const char_t *const ORIGINAL_MODEL_FILE = "ge.originalModelFile";
const char_t *const INPUT_FP16_NODES = "ge.INPUT_NODES_SET_FP16";
const char_t *const OP_DEBUG_LEVEL = "ge.opDebugLevel";
const char_t *const PERFORMANCE_MODE = "ge.performance_mode";
const char_t *const SHAPE_GENERALIZED_BUILD_MODE = "ge.shape_generalized_build_mode";
const char_t *const MODIFY_MIXLIST = "ge.exec.modify_mixlist";
const char_t *const OP_PRECISION_MODE = "ge.exec.op_precision_mode";
const char_t *const CUSTOMIZE_DTYPES = "ge.customizeDtypes";
const char_t *const COMPRESSION_OPTIMIZE_CONF = "ge.compressionOptimizeConf";
} // namespace configure_option
// Configure stream num by Session constructor options param,
// its value should be int32_t type, default value is "1"
@@ -223,7 +238,7 @@ const std::string OPTYPELIST_FOR_IMPLMODE = "ge.optypelistForImplmode";
const std::string HCOM_PARALLEL = "ge.hcomParallel";

// configure whether to use dynamic batch size
const char *const kDynamicBatchSize = "ge.dynamicBatchSize";
const char_t *const kDynamicBatchSize = "ge.dynamicBatchSize";

// configure threshold of fusion data size for communication op
const std::string FUSION_TENSOR_SIZE = "ge.fusionTensorSize";
@@ -232,10 +247,10 @@ const std::string INPUT_SHAPE = "ge.inputShape";

const std::string DYNAMIC_NODE_TYPE = "ge.dynamicNodeType";
// configure whether to use dynamic image size
const char *const kDynamicImageSize = "ge.dynamicImageSize";
const char_t *const kDynamicImageSize = "ge.dynamicImageSize";

// Configure whether to use dynamic dims
const char *const kDynamicDims = "ge.dynamicDims";
const char_t *const kDynamicDims = "ge.dynamicDims";

// Configure auto tune mode, this option only take effect while AUTO_TUNE_FLAG is Y,
// example: GA|RL, support configure multiple, split by |
@@ -244,9 +259,16 @@ const std::string AUTO_TUNE_MODE = "ge.autoTuneMode";
// Configure soc version , example: "Ascend310"
const std::string SOC_VERSION = "ge.socVersion";

// configure whether to enable virtualization,
// its value should be "0" or "1", default value is "0"
const std::string VIRTUAL_TYPE = "ge.virtual_type";

// Configure core type "VectorEngine", default value is "AIcoreEngine"
const std::string CORE_TYPE = "ge.engineType";

// Configure graph exclude one or more engines
const std::string EXCLUDE_ENGINES = "ge.exec.exclude_engines";

// Configure AICORE NUM
const std::string AICORE_NUM = "ge.aicoreNum";

@@ -262,38 +284,51 @@ const std::string ENABLE_SMALL_CHANNEL = "ge.enableSmallChannel";
// Configure Compress Weight flag
const std::string ENABLE_COMPRESS_WEIGHT = "ge.enableCompressWeight";

// Configure Sparse Matrix Weight flag
const std::string ENABLE_SPARSE_MATRIX_WEIGHT = "ge.enableSparseMatrixWeight";

// Configure fusion switch file path
const std::string FUSION_SWITCH_FILE = "ge.fusionSwitchFile";

// Configure compression optimize file path
const std::string COMPRESSION_OPTIMIZE_CONF = "ge.compressionOptimizeConf";

// Configure customize dtypes path
const std::string CUSTOMIZE_DTYPES = "ge.customizeDtypes";

// Save original model
const std::string SAVE_ORIGINAL_MODEL = "ge.saveOriginalModel";

// Save original model file name
const std::string ORIGINAL_MODEL_FILE = "ge.originalModelFile";

const char *const OPTION_GE_MAX_DUMP_FILE_NUM = "ge.maxDumpFileNum";
const char *const OPTION_GE_MAX_DUMP_FILE_SIZE = "ge.maxDumpFileSize";
const char *const OPTION_GE_MAX_DUMP_OP_NUM = "ge.maxDumpOpNum";
const char_t *const OPTION_GE_MAX_DUMP_FILE_NUM = "ge.maxDumpFileNum";
const char_t *const OPTION_GE_MAX_DUMP_FILE_SIZE = "ge.maxDumpFileSize";
const char_t *const OPTION_GE_MAX_DUMP_OP_NUM = "ge.maxDumpOpNum";

// Configure for print op pass
// Its value should be "0" or "1", default value is "1"
const char *const ENABLE_PRINT_OP_PASS = "ge.enablePrintOpPass";
const char_t *const ENABLE_PRINT_OP_PASS = "ge.enablePrintOpPass";

// Configure operator compilation path
// Its value should be file path, default value is "./"
const char *const DEBUG_DIR = "ge.debugDir";
const char_t *const DEBUG_DIR = "ge.debugDir";

// Configure switch for op status check such as overflow
// Its value should be true of flase
const char_t *const STATUS_CHECK = "ge.status_check";

// Configure operator compiler cache path
// Its value should be file path, default value is "./"
const char *const OP_COMPILER_CACHE_DIR = "ge.op_compiler_cache_dir";
const char_t *const OP_COMPILER_CACHE_DIR = "ge.op_compiler_cache_dir";

// Configure operator compiler cache mode
// Its value should be "disable", "enable" or "force", default value is "disable"
const char *const OP_COMPILER_CACHE_MODE = "ge.op_compiler_cache_mode";
const char_t *const OP_COMPILER_CACHE_MODE = "ge.op_compiler_cache_mode";

// Configure whether to use single stream.
// Its value should be "true" or "false", default value is "false"
const char *const ENABLE_SINGLE_STREAM = "ge.enableSingleStream";
const char_t *const ENABLE_SINGLE_STREAM = "ge.enableSingleStream";

// Configure input fp16 nodes
const std::string INPUT_FP16_NODES = "ge.INPUT_NODES_SET_FP16";
@@ -318,17 +353,28 @@ const std::string OP_BANK_UPDATE_FLAG = "ge.op_bank_update";
const std::string HCOM_MULTI_MODE = "ge.hcomMultiMode";

// atc and ir option
const char *const INPUT_SHAPE_RANGE = "input_shape_range";
const char_t *const INPUT_SHAPE_RANGE = "input_shape_range";

// Configure express high compile performance or high execute performance
// normal: no need to compile, used saved .o files directly
// high: need to recompile, high execute performance mode
const std::string PERFORMANCE_MODE = "ge.performance_mode";

// For selecting the mode of shape generalization when build graph.
// shape_generalized: Shape will be generalized during graph build.
// shape_precise: Shape will not be generalized, use precise shape.
const std::string SHAPE_GENERALIZED_BUILD_MODE = "ge.shape_generalized_build_mode";

const std::string MODIFY_MIXLIST = "ge.exec.modify_mixlist";

const std::string OP_PRECISION_MODE = "ge.exec.op_precision_mode";

const std::string OP_WAIT_TIMEOUT = "ge.exec.opWaitTimeout";

const std::string OP_EXECUTE_TIMEOUT = "ge.exec.opExecuteTimeout";

const char_t *const FILE_CONSTANT_PATH = "ge.exec.value_bins";

// Graph run mode
enum GraphRunMode { PREDICTION = 0, TRAIN };

@@ -345,7 +391,7 @@ struct OutputTensorInfo {
std::vector<int64_t> dims; // shape description
std::unique_ptr<uint8_t[]> data; // tensor data
int64_t length; // tensor length
OutputTensorInfo() : data_type(0), dims({}), data(nullptr), length(0) {}
OutputTensorInfo() : data_type(0U), dims({}), data(nullptr), length(0) {}
OutputTensorInfo(OutputTensorInfo &&out)
: data_type(out.data_type), dims(out.dims), data(std::move(out.data)), length(out.length) {}

@@ -367,48 +413,53 @@ using RunAsyncCallback = std::function<void(Status, std::vector<ge::Tensor> &)>;

// for ir build
namespace ir_option {
static const char *const INPUT_FORMAT = "input_format";
static const char *const INPUT_SHAPE = "input_shape";
static const char *const INPUT_SHAPE_RANGE = ge::INPUT_SHAPE_RANGE;
static const char *const OP_NAME_MAP = "op_name_map";
static const char *const IS_DYNAMIC_INPUT = "is_dynamic_input";
static const char *const IS_INPUT_ADJUST_HW_LAYOUT = "is_input_adjust_hw_layout";
static const char *const IS_OUTPUT_ADJUST_HW_LAYOUT = "is_output_adjust_hw_layout";
static const char *const ENABLE_SCOPE_FUSION_PASSES = "enable_scope_fusion_passes";
static const char *const OUTPUT = "output";
static const char *const DYNAMIC_BATCH_SIZE = kDynamicBatchSize;
static const char *const DYNAMIC_IMAGE_SIZE = kDynamicImageSize;
static const char *const DYNAMIC_DIMS = kDynamicDims;
static const char *const INSERT_OP_FILE = ge::INSERT_OP_FILE.c_str();
static const char *const PRECISION_MODE = ge::PRECISION_MODE.c_str();
static const char *const TUNE_DEVICE_IDS = ge::TUNE_DEVICE_IDS.c_str();
static const char *const EXEC_DISABLE_REUSED_MEMORY = ge::OPTION_EXEC_DISABLE_REUSED_MEMORY;
static const char *const AUTO_TUNE_MODE = ge::AUTO_TUNE_MODE.c_str();
static const char *const CORE_TYPE = ge::CORE_TYPE.c_str();
static const char *const SOC_VERSION = ge::SOC_VERSION.c_str();
static const char *const ENABLE_SINGLE_STREAM = ge::ENABLE_SINGLE_STREAM;
static const char *const AICORE_NUM = ge::AICORE_NUM.c_str();
static const char *const FUSION_SWITCH_FILE = ge::FUSION_SWITCH_FILE.c_str();
static const char *const ENABLE_SMALL_CHANNEL = ge::ENABLE_SMALL_CHANNEL.c_str();
static const char *const OP_SELECT_IMPL_MODE = ge::OP_SELECT_IMPL_MODE.c_str();
static const char *const OUTPUT_TYPE = ge::OUTPUT_DATATYPE.c_str();
static const char *const BUFFER_OPTIMIZE = ge::BUFFER_OPTIMIZE.c_str();
static const char *const ENABLE_COMPRESS_WEIGHT = ge::ENABLE_COMPRESS_WEIGHT.c_str();
static const char *const COMPRESS_WEIGHT_CONF = "compress_weight_conf";
static const char *const OUT_NODES = ge::OUTPUT_NODE_NAME.c_str();
static const char *const INPUT_FP16_NODES = ge::INPUT_FP16_NODES.c_str();
static const char *const LOG_LEVEL = "log";
static const char *const OPTYPELIST_FOR_IMPLMODE = ge::OPTYPELIST_FOR_IMPLMODE.c_str();
static const char *const DEBUG_DIR = ge::DEBUG_DIR;
static const char *const OP_COMPILER_CACHE_DIR = ge::OP_COMPILER_CACHE_DIR;
static const char *const OP_COMPILER_CACHE_MODE = ge::OP_COMPILER_CACHE_MODE;
static const char *const MDL_BANK_PATH = ge::MDL_BANK_PATH_FLAG.c_str();
static const char *const OP_BANK_PATH = ge::OP_BANK_PATH_FLAG.c_str();
static const char *const OP_BANK_UPDATE = ge::OP_BANK_UPDATE_FLAG.c_str();
static const char *const OP_DEBUG_LEVEL = ge::OP_DEBUG_LEVEL.c_str();
static const char *const PERFORMANCE_MODE = ge::PERFORMANCE_MODE.c_str();
static const char *const MODIFY_MIXLIST = ge::MODIFY_MIXLIST.c_str();
static const char *const OP_PRECISION_MODE = ge::OP_PRECISION_MODE.c_str();
static const char_t *const INPUT_FORMAT = "input_format";
static const char_t *const INPUT_SHAPE = "input_shape";
static const char_t *const INPUT_SHAPE_RANGE = ge::INPUT_SHAPE_RANGE;
static const char_t *const OP_NAME_MAP = "op_name_map";
static const char_t *const IS_DYNAMIC_INPUT = "is_dynamic_input";
static const char_t *const IS_INPUT_ADJUST_HW_LAYOUT = "is_input_adjust_hw_layout";
static const char_t *const IS_OUTPUT_ADJUST_HW_LAYOUT = "is_output_adjust_hw_layout";
static const char_t *const ENABLE_SCOPE_FUSION_PASSES = "enable_scope_fusion_passes";
static const char_t *const OUTPUT = "output";
static const char_t *const DYNAMIC_BATCH_SIZE = kDynamicBatchSize;
static const char_t *const DYNAMIC_IMAGE_SIZE = kDynamicImageSize;
static const char_t *const DYNAMIC_DIMS = kDynamicDims;
static const char_t *const INSERT_OP_FILE = ge::INSERT_OP_FILE.c_str();
static const char_t *const PRECISION_MODE = ge::PRECISION_MODE.c_str();
static const char_t *const TUNE_DEVICE_IDS = ge::TUNE_DEVICE_IDS.c_str();
static const char_t *const EXEC_DISABLE_REUSED_MEMORY = ge::OPTION_EXEC_DISABLE_REUSED_MEMORY;
static const char_t *const AUTO_TUNE_MODE = ge::AUTO_TUNE_MODE.c_str();
static const char_t *const CORE_TYPE = ge::CORE_TYPE.c_str();
static const char_t *const SOC_VERSION = ge::SOC_VERSION.c_str();
static const char_t *const VIRTUAL_TYPE = ge::VIRTUAL_TYPE.c_str();
static const char_t *const ENABLE_SINGLE_STREAM = ge::ENABLE_SINGLE_STREAM;
static const char_t *const AICORE_NUM = ge::AICORE_NUM.c_str();
static const char_t *const FUSION_SWITCH_FILE = ge::FUSION_SWITCH_FILE.c_str();
static const char_t *const ENABLE_SMALL_CHANNEL = ge::ENABLE_SMALL_CHANNEL.c_str();
static const char_t *const OP_SELECT_IMPL_MODE = ge::OP_SELECT_IMPL_MODE.c_str();
static const char_t *const OUTPUT_TYPE = ge::OUTPUT_DATATYPE.c_str();
static const char_t *const BUFFER_OPTIMIZE = ge::BUFFER_OPTIMIZE.c_str();
static const char_t *const ENABLE_COMPRESS_WEIGHT = ge::ENABLE_COMPRESS_WEIGHT.c_str();
static const char_t *const SPARSITY = ge::ENABLE_SPARSE_MATRIX_WEIGHT.c_str();
static const char_t *const COMPRESS_WEIGHT_CONF = "compress_weight_conf";
static const char_t *const OUT_NODES = ge::OUTPUT_NODE_NAME.c_str();
static const char_t *const INPUT_FP16_NODES = ge::INPUT_FP16_NODES.c_str();
static const char_t *const LOG_LEVEL = "log";
static const char_t *const OPTYPELIST_FOR_IMPLMODE = ge::OPTYPELIST_FOR_IMPLMODE.c_str();
static const char_t *const DEBUG_DIR = ge::DEBUG_DIR;
static const char_t *const OP_COMPILER_CACHE_DIR = ge::OP_COMPILER_CACHE_DIR;
static const char_t *const OP_COMPILER_CACHE_MODE = ge::OP_COMPILER_CACHE_MODE;
static const char_t *const MDL_BANK_PATH = ge::MDL_BANK_PATH_FLAG.c_str();
static const char_t *const OP_BANK_PATH = ge::OP_BANK_PATH_FLAG.c_str();
static const char_t *const OP_BANK_UPDATE = ge::OP_BANK_UPDATE_FLAG.c_str();
static const char_t *const OP_DEBUG_LEVEL = ge::OP_DEBUG_LEVEL.c_str();
static const char_t *const PERFORMANCE_MODE = ge::PERFORMANCE_MODE.c_str();
static const char_t *const SHAPE_GENERALIZED_BUILD_MODE = ge::SHAPE_GENERALIZED_BUILD_MODE.c_str();
static const char_t *const MODIFY_MIXLIST = ge::MODIFY_MIXLIST.c_str();
static const char_t *const OP_PRECISION_MODE = ge::OP_PRECISION_MODE.c_str();
static const char_t *const CUSTOMIZE_DTYPES = "ge.customizeDtypes";
static const char_t *const COMPRESSION_OPTIMIZE_CONF = "ge.compressionOptimizeConf";

// for interface: aclgrphBuildModel
#ifdef __GNUC__
@@ -437,19 +488,23 @@ const std::set<std::string> ir_builder_suppported_options = {INPUT_FORMAT,
OP_BANK_PATH,
OP_BANK_UPDATE,
PERFORMANCE_MODE,
MODIFY_MIXLIST};
SHAPE_GENERALIZED_BUILD_MODE,
MODIFY_MIXLIST,
CUSTOMIZE_DTYPES};

// for interface: aclgrphParse
const std::set<std::string> ir_parser_suppported_options = {
INPUT_FP16_NODES, IS_INPUT_ADJUST_HW_LAYOUT, IS_OUTPUT_ADJUST_HW_LAYOUT, OUTPUT,
OUT_NODES, ENABLE_SCOPE_FUSION_PASSES};
INPUT_FP16_NODES, IS_INPUT_ADJUST_HW_LAYOUT, IS_OUTPUT_ADJUST_HW_LAYOUT, OUTPUT,
OUT_NODES, ENABLE_SCOPE_FUSION_PASSES};

// for interface: aclgrphBuildInitialize
const std::set<std::string> global_options = {CORE_TYPE,
SOC_VERSION,
VIRTUAL_TYPE,
BUFFER_OPTIMIZE,
ENABLE_COMPRESS_WEIGHT,
COMPRESS_WEIGHT_CONF,
SPARSITY,
PRECISION_MODE,
TUNE_DEVICE_IDS,
EXEC_DISABLE_REUSED_MEMORY,
@@ -464,7 +519,8 @@ const std::set<std::string> global_options = {CORE_TYPE,
DEBUG_DIR,
OP_COMPILER_CACHE_DIR,
OP_COMPILER_CACHE_MODE,
MODIFY_MIXLIST};
MODIFY_MIXLIST,
COMPRESSION_OPTIMIZE_CONF};
#endif
} // namespace ir_option
} // namespace ge


+ 35
- 33
inc/external/ge/ge_error_codes.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright 2019-2022 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.
@@ -32,42 +32,44 @@
#endif

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif
static const uint32_t ACL_ERROR_GE_PARAM_INVALID = 145000;
static const uint32_t ACL_ERROR_GE_EXEC_NOT_INIT = 145001;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID = 145002;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_ID_INVALID = 145003;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID = 145006;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID = 145007;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID = 145008;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_MODEL_REPEATED = 145009;
static const uint32_t ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID = 145011;
static const uint32_t ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID = 145012;
static const uint32_t ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID = 145013;
static const uint32_t ACL_ERROR_GE_AIPP_BATCH_EMPTY = 145014;
static const uint32_t ACL_ERROR_GE_AIPP_NOT_EXIST = 145015;
static const uint32_t ACL_ERROR_GE_AIPP_MODE_INVALID = 145016;
static const uint32_t ACL_ERROR_GE_OP_TASK_TYPE_INVALID = 145017;
static const uint32_t ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID = 145018;
static const uint32_t ACL_ERROR_GE_PLGMGR_PATH_INVALID = 145019;
static const uint32_t ACL_ERROR_GE_FORMAT_INVALID = 145020;
static const uint32_t ACL_ERROR_GE_SHAPE_INVALID = 145021;
static const uint32_t ACL_ERROR_GE_DATATYPE_INVALID = 145022;
static const uint32_t ACL_ERROR_GE_MEMORY_ALLOCATION = 245000;
static const uint32_t ACL_ERROR_GE_MEMORY_OPERATE_FAILED = 245001;
static const uint32_t ACL_ERROR_GE_INTERNAL_ERROR = 545000;
static const uint32_t ACL_ERROR_GE_LOAD_MODEL = 545001;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_MODEL_PARTITION_FAILED = 545002;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED = 545003;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED = 545004;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_KERNEL_PARTITION_FAILED = 545005;
static const uint32_t ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA = 545006;
static const uint32_t ACL_ERROR_GE_COMMAND_HANDLE = 545007;
static const uint32_t ACL_ERROR_GE_GET_TENSOR_INFO = 545008;
static const uint32_t ACL_ERROR_GE_UNLOAD_MODEL = 545009;
static const uint32_t ACL_ERROR_GE_PARAM_INVALID = 145000U;
static const uint32_t ACL_ERROR_GE_EXEC_NOT_INIT = 145001U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID = 145002U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_ID_INVALID = 145003U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID = 145006U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID = 145007U;
static const uint32_t ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID = 145008U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_MODEL_REPEATED = 145009U;
static const uint32_t ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID = 145011U;
static const uint32_t ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID = 145012U;
static const uint32_t ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID = 145013U;
static const uint32_t ACL_ERROR_GE_AIPP_BATCH_EMPTY = 145014U;
static const uint32_t ACL_ERROR_GE_AIPP_NOT_EXIST = 145015U;
static const uint32_t ACL_ERROR_GE_AIPP_MODE_INVALID = 145016U;
static const uint32_t ACL_ERROR_GE_OP_TASK_TYPE_INVALID = 145017U;
static const uint32_t ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID = 145018U;
static const uint32_t ACL_ERROR_GE_PLGMGR_PATH_INVALID = 145019U;
static const uint32_t ACL_ERROR_GE_FORMAT_INVALID = 145020U;
static const uint32_t ACL_ERROR_GE_SHAPE_INVALID = 145021U;
static const uint32_t ACL_ERROR_GE_DATATYPE_INVALID = 145022U;
static const uint32_t ACL_ERROR_GE_MEMORY_ALLOCATION = 245000U;
static const uint32_t ACL_ERROR_GE_MEMORY_OPERATE_FAILED = 245001U;
static const uint32_t ACL_ERROR_GE_DEVICE_MEMORY_OPERATE_FAILED = 245002U;
static const uint32_t ACL_ERROR_GE_INTERNAL_ERROR = 545000U;
static const uint32_t ACL_ERROR_GE_LOAD_MODEL = 545001U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_MODEL_PARTITION_FAILED = 545002U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED = 545003U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED = 545004U;
static const uint32_t ACL_ERROR_GE_EXEC_LOAD_KERNEL_PARTITION_FAILED = 545005U;
static const uint32_t ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA = 545006U;
static const uint32_t ACL_ERROR_GE_COMMAND_HANDLE = 545007U;
static const uint32_t ACL_ERROR_GE_GET_TENSOR_INFO = 545008U;
static const uint32_t ACL_ERROR_GE_UNLOAD_MODEL = 545009U;

#ifdef __cplusplus
} // namespace ge


+ 24
- 27
inc/external/ge/ge_ir_build.h View File

@@ -1,18 +1,18 @@
/**
* 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.
*/
* Copyright 2019-2022 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_EXTERNAL_GE_IR_BUILD_H_
#define INC_EXTERNAL_GE_IR_BUILD_H_
@@ -36,14 +36,10 @@
#include <memory>
#include "graph/graph.h"
#include "graph/ge_error_codes.h"

namespace {
const int IR_MAJOR_VERSION = 1;
const int IR_MINOR_VERSION = 0;
const int IR_PATCH_VERSION = 0;
} // namespace

namespace ge {
const int32_t IR_MAJOR_VERSION = 1;
const int32_t IR_MINOR_VERSION = 0;
const int32_t IR_PATCH_VERSION = 0;

struct ModelBufferData {
std::shared_ptr<uint8_t> data = nullptr;
@@ -102,10 +98,10 @@ GE_FUNC_VISIBILITY graphStatus aclgrphBuildModel(const ge::Graph &graph,
* @retval GRAPH_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ATTRIBUTED_DEPRECATED(GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const char *, const ModelBufferData &))
GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const string &output_file, const ModelBufferData &model);
ATTRIBUTED_DEPRECATED(GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const char_t *, const ModelBufferData &))
GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const std::string &output_file, const ModelBufferData &model);

GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const char *output_file, const ModelBufferData &model);
GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const char_t *output_file, const ModelBufferData &model);

/**
* @ingroup AscendCL
@@ -117,7 +113,8 @@ GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const char *output_file, const M
* @retval GRAPH_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
GE_FUNC_VISIBILITY graphStatus aclgrphGetIRVersion(int *major_version, int *minor_version, int *patch_version);
GE_FUNC_VISIBILITY graphStatus aclgrphGetIRVersion(int32_t *major_version, int32_t *minor_version,
int32_t *patch_version);

/**
* @ingroup AscendCL
@@ -129,7 +126,7 @@ GE_FUNC_VISIBILITY graphStatus aclgrphGetIRVersion(int *major_version, int *mino
* @retval GRAPH_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
GE_FUNC_VISIBILITY graphStatus aclgrphDumpGraph(const ge::Graph &graph, const char *file, const size_t len);
GE_FUNC_VISIBILITY graphStatus aclgrphDumpGraph(const ge::Graph &graph, const char_t *file, const size_t len);

/**
* @ingroup AscendCL
@@ -153,7 +150,7 @@ GE_FUNC_VISIBILITY graphStatus aclgrphGenerateForOp(const AscendString &op_type,
* @param cfg_path [IN] the config file path
* @return graphStatus
*/
GE_FUNC_VISIBILITY graphStatus aclgrphSetOpAttr(Graph &graph, aclgrphAttrType attr_type, const char *cfg_path);
GE_FUNC_VISIBILITY graphStatus aclgrphSetOpAttr(Graph &graph, aclgrphAttrType attr_type, const char_t *cfg_path);

}; // namespace ge
#endif // INC_EXTERNAL_GE_IR_BUILD_H_

+ 210
- 0
inc/external/hccl/hccl.h View File

@@ -0,0 +1,210 @@
/**
* Copyright 2019-2022 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 hccl.h
* @brief HCCL API
*/

#ifndef HCCL_H_
#define HCCL_H_

#include <hccl/hccl_types.h>
#include <acl/acl.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
* @brief Initialize HCCL.
*
* @param clusterInfo A string identifying the cluster info file path, include file name.
* @param rank A integer identifying the identify for the rank.
* @param comm A pointer identifying the initialized communication resource.
* @return HcclResult
* @see HcclCommDestroy()
*/
extern HcclResult HcclCommInitClusterInfo(const char *clusterInfo, uint32_t rank, HcclComm *comm);

/**
* @brief Get hccl root info.
*
* @param rootInfo A pointer identifying the hccl root info.
* @return HcclResult
*/
extern HcclResult HcclGetRootInfo(HcclRootInfo *rootInfo);

/**
* @brief Initialize HCCL with root info.
*
* @param nRanks A integer identifying the rank size of the cluster.
* @param rootInfo A struct identifying the hccl root info.
* @param rank A integer identifying the identify for the rank.
* @param comm A pointer identifying the initialized communication resource.
* @return HcclResult
* @see HcclCommDestroy()
*/
extern HcclResult HcclCommInitRootInfo(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank, HcclComm *comm);

/**
* @brief AllReduce operator.
*
* @param sendBuf A pointer identifying the input data address of the operator.
* @param recvBuf A pointer identifying the output data address of the operator.
* @param count An integer(u64) identifying the number of the output data.
* @param dataType The data type of the operator, must be one of the following types: int8, int16, int32, float16,
* float32.
* @param op The reduction type of the operator, must be one of the following types: sum, min, max, prod.
* @param comm A pointer identifying the communication resource based on.
* @param stream A pointer identifying the stream information.
* @return HcclResult
*/
extern HcclResult HcclAllReduce(void *sendBuf, void *recvBuf, uint64_t count, HcclDataType dataType, HcclReduceOp op,
HcclComm comm, aclrtStream stream);

/**
* @brief Broadcast operator.
*
* @param buf A pointer identifying the data address of the operator.
* @param count An integer(u64) identifying the number of the data.
* @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
* @param root An integer(u32) identifying the the root rank in the operator.
* @param comm A pointer identifying the communication resource based on
* @param stream A pointer identifying the stream information.
* @return HcclResult
*/
extern HcclResult HcclBroadcast(void *buf, uint64_t count, HcclDataType dataType, uint32_t root, HcclComm comm,
aclrtStream stream);

/**
* @brief ReduceScatter operator.
*
* @param sendBuf A pointer identifying the input data address of the operator.
* @param recvBuf A pointer identifying the output data address of the operator.
* @param recvCount An integer(u64) identifying the number of the output data.
* @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
* @param op The reduction type of the operator, must be one of the following types: sum, min, max, prod.
* @param comm A pointer identifying the communication resource based on.
* @param stream A pointer identifying the stream information.
* @return HcclResult
*/
extern HcclResult HcclReduceScatter(void *sendBuf, void *recvBuf, uint64_t recvCount, HcclDataType dataType,
HcclReduceOp op, HcclComm comm, aclrtStream stream);

/**
* @brief AllGather operator.
*
* @param sendBuf A pointer identifying the input data address of the operator.
* @param recvBuf A pointer identifying the output data address of the operator.
* @param sendCount An integer(u64) identifying the number of the input data.
* @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
* @param comm A pointer identifying the communication resource based on.
* @param stream A pointer identifying the stream information.
* @return HcclResult
*/
extern HcclResult HcclAllGather(void *sendBuf, void *recvBuf, uint64_t sendCount, HcclDataType dataType, HcclComm comm,
aclrtStream stream);
/**
* @brief Get the rank size of this comm.
*
* @param comm A pointer identifying the communication resource based on.
* @param rankSize A pointer identifying the rank size.
* @return HcclResult
*/
extern HcclResult HcclGetRankSize(HcclComm comm, uint32_t *rankSize);

/**
* @brief Get the rank id of this comm.
*
* @param comm A pointer identifying the communication resource based on.
* @param rankSize A pointer identifying the rank id.
* @return HcclResult
*/
extern HcclResult HcclGetRankId(HcclComm comm, uint32_t *rank);
/**
* @brief Barrier operator.
*
* @param comm A pointer identifying the communication resource based on.
* @param stream A pointer identifying the stream information.
* @return HcclResult
*/
extern HcclResult HcclBarrier(HcclComm comm, aclrtStream stream);

/**
* @brief Send operator.
*
* @param sendBuff A pointer identifying the input data address of the operator.
* @param count An integer(u64) identifying the number of the send data.
* @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
* @param destRank An integer identifying the destination rank.
* @param comm A pointer identifying the communication resource based on.
* @param stream A pointer identifying the stream information.
* @return HcclResult
*/
extern HcclResult HcclSend(void *sendBuf, uint64_t count, HcclDataType dataType, uint32_t destRank, HcclComm comm,
aclrtStream stream);
/**
* @brief Recv operator.
*
* @param recvBuff A pointer identifying the output data address of the operator.
* @param count An integer(u64) identifying the number of the receive data.
* @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
* @param srcRank An integer identifying the source rank.
* @param comm A pointer identifying the communication resource based on.
* @param stream A pointer identifying the stream information.
* @return HcclResult
*/
extern HcclResult HcclRecv(void *recvBuf, uint64_t count, HcclDataType dataType, uint32_t srcRank, HcclComm comm,
aclrtStream stream);

/**
* @brief AlltoAllV operator.
*
* @param sendBuff A pointer identifying the input data address of the operator.
* @param sendCounts Integer array, where entry i specifies the number of elements to send to rank i.
* @param sdispls Integer array, where entry i specifies the displacement (offset from sendbuf, in units of sendtype)
* from which to send data to rank i.
* @param sendType Datatype of send buffer elements, must be one of the following types: int8, int32, int64, uint64,
* float16, float32.
* @param recvBuf A pointer identifying the output data address of the operator.
* @param recvCounts Integer array, where entry j specifies the number of elements to receive from rank j.
* @param rdispls Integer array, where entry j specifies the displacement (offset from recvbuf, in units of recvtype) to
* which data from rank j should be written.
* @param recvType Datatype of receive buffer elements, must be one of the following types: int8, int32, int64, uint64,
* float16, float32.
* @param comm A pointer identifying the communication resource based on.
* @param stream A pointer identifying the stream information.
* @return HcclResult
*/

extern HcclResult HcclAlltoAllV(const void *sendBuf, const void *sendCounts, const void *sdispls, HcclDataType sendType,
const void *recvBuf, const void *recvCounts, const void *rdispls, HcclDataType recvType,
HcclComm comm, aclrtStream stream);

/**
* @brief Destroy HCCL comm
*
* @param comm A pointer identifying the communication resource targetting
* @return HcclResult
* @see HcclCommInitClusterInfo()
*/
extern HcclResult HcclCommDestroy(HcclComm comm);

#ifdef __cplusplus
}
#endif // __cplusplus
#endif // HCCL_H_

+ 101
- 0
inc/external/hccl/hccl_types.h View File

@@ -0,0 +1,101 @@
/**
* Copyright 2019-2022 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 hccl_types.h
* @brief HCCL data type definition
*
*/

#ifndef HCCL_TYPES_H_
#define HCCL_TYPES_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
* @brief HCCL functions return value definition
*/
typedef enum {
HCCL_SUCCESS = 0, /**< success */
HCCL_E_PARA = 1, /**< parameter error */
HCCL_E_PTR = 2, /**< empty pointer */
HCCL_E_MEMORY = 3, /**< memory error */
HCCL_E_INTERNAL = 4, /**< internal error */
HCCL_E_NOT_SUPPORT = 5, /**< not support feature */
HCCL_E_NOT_FOUND = 6, /**< not found specific resource */
HCCL_E_UNAVAIL = 7, /**< resource unavailable */
HCCL_E_SYSCALL = 8, /**< call system interface error */
HCCL_E_TIMEOUT = 9, /**< timeout */
HCCL_E_OPEN_FILE_FAILURE = 10, /**< open file fail */
HCCL_E_TCP_CONNECT = 11, /**< tcp connect fail */
HCCL_E_ROCE_CONNECT = 12, /**< roce connect fail */
HCCL_E_TCP_TRANSFER = 13, /**< tcp transfer fail */
HCCL_E_ROCE_TRANSFER = 14, /**< roce transfer fail */
HCCL_E_RUNTIME = 15, /**< call runtime api fail */
HCCL_E_DRV = 16, /**< call driver api fail */
HCCL_E_PROFILING = 17, /**< call profiling api fail */
HCCL_E_CCE = 18, /**< call cce api fail */
HCCL_E_NETWORK = 19, /**< call network api fail */
HCCL_E_AGAIN = 20, /**< try again */
HCCL_E_RESERVED /**< reserved */
} HcclResult;

/**
* @brief handle to HCCL communicator
*/
typedef void *HcclComm;

/**
* @brief HCCL Reduction opperation
*/
typedef enum {
HCCL_REDUCE_SUM = 0, /**< sum */
HCCL_REDUCE_PROD = 1, /**< prod */
HCCL_REDUCE_MAX = 2, /**< max */
HCCL_REDUCE_MIN = 3, /**< min */
HCCL_REDUCE_RESERVED /**< reserved */
} HcclReduceOp;

/**
* @brief HCCL data type
*/
typedef enum {
HCCL_DATA_TYPE_INT8 = 0, /**< int8 */
HCCL_DATA_TYPE_INT16 = 1, /**< int16 */
HCCL_DATA_TYPE_INT32 = 2, /**< int32 */
HCCL_DATA_TYPE_FP16 = 3, /**< fp16 */
HCCL_DATA_TYPE_FP32 = 4, /**< fp32 */
HCCL_DATA_TYPE_INT64 = 5, /**< int64 */
HCCL_DATA_TYPE_UINT64 = 6, /**< uint64 */
HCCL_DATA_TYPE_RESERVED /**< reserved */
} HcclDataType;

const uint32_t HCCL_ROOT_INFO_BYTES = 4108; // 4108: root info length
/**
* @brief HCCL root info
*/
typedef struct HcclRootInfoDef {
char internal[HCCL_ROOT_INFO_BYTES];
} HcclRootInfo;

#ifdef __cplusplus
}
#endif // __cplusplus
#endif // HCCL_TYPES_H_

+ 123
- 0
inc/external/runtime/rt_error_codes.h View File

@@ -0,0 +1,123 @@
/**
* Copyright 2019-2022 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_EXTERNEL_RT_ERROR_CODES_H__
#define __INC_EXTERNEL_RT_ERROR_CODES_H__

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

static const int32_t ACL_RT_SUCCESS = 0; // success

static const int32_t ACL_ERROR_RT_PARAM_INVALID = 107000; // param invalid
static const int32_t ACL_ERROR_RT_INVALID_DEVICEID = 107001; // invalid device id
static const int32_t ACL_ERROR_RT_CONTEXT_NULL = 107002; // current context null
static const int32_t ACL_ERROR_RT_STREAM_CONTEXT = 107003; // stream not in current context
static const int32_t ACL_ERROR_RT_MODEL_CONTEXT = 107004; // model not in current context
static const int32_t ACL_ERROR_RT_STREAM_MODEL = 107005; // stream not in model
static const int32_t ACL_ERROR_RT_EVENT_TIMESTAMP_INVALID = 107006; // event timestamp invalid
static const int32_t ACL_ERROR_RT_EVENT_TIMESTAMP_REVERSAL = 107007; // event timestamp reversal
static const int32_t ACL_ERROR_RT_ADDR_UNALIGNED = 107008; // memory address unaligned
static const int32_t ACL_ERROR_RT_FILE_OPEN = 107009; // open file failed
static const int32_t ACL_ERROR_RT_FILE_WRITE = 107010; // write file failed
static const int32_t ACL_ERROR_RT_STREAM_SUBSCRIBE = 107011; // error subscribe stream
static const int32_t ACL_ERROR_RT_THREAD_SUBSCRIBE = 107012; // error subscribe thread
static const int32_t ACL_ERROR_RT_GROUP_NOT_SET = 107013; // group not set
static const int32_t ACL_ERROR_RT_GROUP_NOT_CREATE = 107014; // group not create
static const int32_t ACL_ERROR_RT_STREAM_NO_CB_REG = 107015; // callback not register to stream
static const int32_t ACL_ERROR_RT_INVALID_MEMORY_TYPE = 107016; // invalid memory type
static const int32_t ACL_ERROR_RT_INVALID_HANDLE = 107017; // invalid handle
static const int32_t ACL_ERROR_RT_INVALID_MALLOC_TYPE = 107018; // invalid malloc type
static const int32_t ACL_ERROR_RT_WAIT_TIMEOUT = 107019; // wait timeout
static const int32_t ACL_ERROR_RT_TASK_TIMEOUT = 107020; // task timeout

static const int32_t ACL_ERROR_RT_FEATURE_NOT_SUPPORT = 207000; // feature not support
static const int32_t ACL_ERROR_RT_MEMORY_ALLOCATION = 207001; // memory allocation error
static const int32_t ACL_ERROR_RT_MEMORY_FREE = 207002; // memory free error
static const int32_t ACL_ERROR_RT_AICORE_OVER_FLOW = 207003; // aicore over flow
static const int32_t ACL_ERROR_RT_NO_DEVICE = 207004; // no device
static const int32_t ACL_ERROR_RT_RESOURCE_ALLOC_FAIL = 207005; // resource alloc fail
static const int32_t ACL_ERROR_RT_NO_PERMISSION = 207006; // no permission
static const int32_t ACL_ERROR_RT_NO_EVENT_RESOURCE = 207007; // no event resource
static const int32_t ACL_ERROR_RT_NO_STREAM_RESOURCE = 207008; // no stream resource
static const int32_t ACL_ERROR_RT_NO_NOTIFY_RESOURCE = 207009; // no notify resource
static const int32_t ACL_ERROR_RT_NO_MODEL_RESOURCE = 207010; // no model resource
static const int32_t ACL_ERROR_RT_NO_CDQ_RESOURCE = 207011; // no cdq resource
static const int32_t ACL_ERROR_RT_OVER_LIMIT = 207012; // over limit
static const int32_t ACL_ERROR_RT_QUEUE_EMPTY = 207013; // queue is empty
static const int32_t ACL_ERROR_RT_QUEUE_FULL = 207014; // queue is full
static const int32_t ACL_ERROR_RT_REPEATED_INIT = 207015; // repeated init
static const int32_t ACL_ERROR_RT_AIVEC_OVER_FLOW = 207016; // aivec over flow
static const int32_t ACL_ERROR_RT_OVER_FLOW = 207017; // common over flow

static const int32_t ACL_ERROR_RT_INTERNAL_ERROR = 507000; // runtime internal error
static const int32_t ACL_ERROR_RT_TS_ERROR = 507001; // ts internel error
static const int32_t ACL_ERROR_RT_STREAM_TASK_FULL = 507002; // task full in stream
static const int32_t ACL_ERROR_RT_STREAM_TASK_EMPTY = 507003; // task empty in stream
static const int32_t ACL_ERROR_RT_STREAM_NOT_COMPLETE = 507004; // stream not complete
static const int32_t ACL_ERROR_RT_END_OF_SEQUENCE = 507005; // end of sequence
static const int32_t ACL_ERROR_RT_EVENT_NOT_COMPLETE = 507006; // event not complete
static const int32_t ACL_ERROR_RT_CONTEXT_RELEASE_ERROR = 507007; // context release error
static const int32_t ACL_ERROR_RT_SOC_VERSION = 507008; // soc version error
static const int32_t ACL_ERROR_RT_TASK_TYPE_NOT_SUPPORT = 507009; // task type not support
static const int32_t ACL_ERROR_RT_LOST_HEARTBEAT = 507010; // ts lost heartbeat
static const int32_t ACL_ERROR_RT_MODEL_EXECUTE = 507011; // model execute failed
static const int32_t ACL_ERROR_RT_REPORT_TIMEOUT = 507012; // report timeout
static const int32_t ACL_ERROR_RT_SYS_DMA = 507013; // sys dma error
static const int32_t ACL_ERROR_RT_AICORE_TIMEOUT = 507014; // aicore timeout
static const int32_t ACL_ERROR_RT_AICORE_EXCEPTION = 507015; // aicore exception
static const int32_t ACL_ERROR_RT_AICORE_TRAP_EXCEPTION = 507016; // aicore trap exception
static const int32_t ACL_ERROR_RT_AICPU_TIMEOUT = 507017; // aicpu timeout
static const int32_t ACL_ERROR_RT_AICPU_EXCEPTION = 507018; // aicpu exception
static const int32_t ACL_ERROR_RT_AICPU_DATADUMP_RSP_ERR = 507019; // aicpu datadump response error
static const int32_t ACL_ERROR_RT_AICPU_MODEL_RSP_ERR = 507020; // aicpu model operate response error
static const int32_t ACL_ERROR_RT_PROFILING_ERROR = 507021; // profiling error
static const int32_t ACL_ERROR_RT_IPC_ERROR = 507022; // ipc error
static const int32_t ACL_ERROR_RT_MODEL_ABORT_NORMAL = 507023; // model abort normal
static const int32_t ACL_ERROR_RT_KERNEL_UNREGISTERING = 507024; // kernel unregistering
static const int32_t ACL_ERROR_RT_RINGBUFFER_NOT_INIT = 507025; // ringbuffer not init
static const int32_t ACL_ERROR_RT_RINGBUFFER_NO_DATA = 507026; // ringbuffer no data
static const int32_t ACL_ERROR_RT_KERNEL_LOOKUP = 507027; // kernel lookup error
static const int32_t ACL_ERROR_RT_KERNEL_DUPLICATE = 507028; // kernel register duplicate
static const int32_t ACL_ERROR_RT_DEBUG_REGISTER_FAIL = 507029; // debug register failed
static const int32_t ACL_ERROR_RT_DEBUG_UNREGISTER_FAIL = 507030; // debug unregister failed
static const int32_t ACL_ERROR_RT_LABEL_CONTEXT = 507031; // label not in current context
static const int32_t ACL_ERROR_RT_PROGRAM_USE_OUT = 507032; // program register num use out
static const int32_t ACL_ERROR_RT_DEV_SETUP_ERROR = 507033; // device setup error
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TIMEOUT = 507034; // vector core timeout
static const int32_t ACL_ERROR_RT_VECTOR_CORE_EXCEPTION = 507035; // vector core exception
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_EXCEPTION = 507036; // vector core trap exception
static const int32_t ACL_ERROR_RT_CDQ_BATCH_ABNORMAL = 507037; // cdq alloc batch abnormal
static const int32_t ACL_ERROR_RT_DIE_MODE_CHANGE_ERROR = 507038; // can not change die mode
static const int32_t ACL_ERROR_RT_DIE_SET_ERROR = 507039; // single die mode can not set die
static const int32_t ACL_ERROR_RT_INVALID_DIEID = 507040; // invalid die id
static const int32_t ACL_ERROR_RT_DIE_MODE_NOT_SET = 507041; // die mode not set
static const int32_t ACL_ERROR_RT_AICORE_TRAP_READ_OVERFLOW = 507042; // aic trap read overflow
static const int32_t ACL_ERROR_RT_AICORE_TRAP_WRITE_OVERFLOW = 507043; // aic trap write overflow
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_READ_OVERFLOW = 507044; // aiv trap read overflow
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_WRITE_OVERFLOW = 507045; // aiv trap write overflow

static const int32_t ACL_ERROR_RT_DRV_INTERNAL_ERROR = 507899; // drv internal error
static const int32_t ACL_ERROR_RT_AICPU_INTERNAL_ERROR = 507900; // aicpu internal error
static const int32_t ACL_ERROR_RT_SOCKET_CLOSE = 507901; // hdc disconnect

#ifdef __cplusplus
}
#endif
#endif // __INC_EXTERNEL_RT_ERROR_CODES_H__

+ 1
- 1
inc/framework/common/aicpu_op.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.


+ 64
- 44
inc/framework/common/debug/ge_log.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
#ifndef INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_
#define INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_

#include <cinttypes>
#include <cstdint>

#include "framework/common/ge_inner_error_codes.h"
@@ -33,7 +34,7 @@
extern "C" {
#endif

#define GE_MODULE_NAME static_cast<int>(GE)
#define GE_MODULE_NAME static_cast<int32_t>(GE)

// trace status of log
enum TraceStatus { TRACE_INIT = 0, TRACE_RUNNING, TRACE_WAITING, TRACE_STOP };
@@ -42,60 +43,79 @@ class GE_FUNC_VISIBILITY GeLog {
public:
static uint64_t GetTid() {
#ifdef __GNUC__
uint64_t tid = static_cast<uint64_t>(syscall(__NR_gettid));
const uint64_t tid = static_cast<uint64_t>(syscall(__NR_gettid));
#else
uint64_t tid = static_cast<uint64_t>(GetCurrentThreadId());
const uint64_t tid = static_cast<uint64_t>(GetCurrentThreadId());
#endif
return tid;
}
};

inline bool IsLogEnable(int module_name, int log_level) {
int32_t enable = CheckLogLevel(module_name, log_level);
inline bool IsLogEnable(const int32_t module_name, const int32_t log_level) {
const int32_t enable = CheckLogLevel(module_name, log_level);
// 1:enable, 0:disable
return (enable == 1);
}

#define GELOGE(ERROR_CODE, fmt, ...) \
dlog_error(GE_MODULE_NAME, "%lu %s: ErrorNo: %d(%s) %s" fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \
((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ErrorManager::GetInstance().GetLogHeader().c_str(), \
##__VA_ARGS__)
#define GELOGW(fmt, ...) \
if (IsLogEnable(GE_MODULE_NAME, DLOG_WARN)) \
dlog_warn(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
#define GELOGI(fmt, ...) \
if (IsLogEnable(GE_MODULE_NAME, DLOG_INFO)) \
dlog_info(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)
#define GELOGD(fmt, ...) \
if (IsLogEnable(GE_MODULE_NAME, DLOG_DEBUG)) \
dlog_debug(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)

#define GEEVENT(fmt, ...) dlog_event(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__)

#define GELOGT(VALUE, fmt, ...) \
do { \
TraceStatus stat = VALUE; \
const char *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \
int idx = static_cast<int>(stat); \
char *k = const_cast<char *>("status"); \
char *v = const_cast<char *>(TraceStatStr[idx]); \
KeyValue kv = {k, v}; \
DlogWithKV(static_cast<int>(GE_MODULE_NAME), DLOG_TRACE, &kv, 1, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, \
##__VA_ARGS__); \
} while (0)

#define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \
dlog_error(MOD_NAME, "%lu %s: ErrorNo: %d(%s) %s" fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \
((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ErrorManager::GetInstance().GetLogHeader().c_str(), \
##__VA_ARGS__)
#define GELOGE(ERROR_CODE, fmt, ...) \
do { \
dlog_error(GE_MODULE_NAME, "%" PRIu64 " %s: ErrorNo: %" PRIuLEAST8 "(%s) %s" fmt, GeLog::GetTid(), \
&__FUNCTION__[0], (ERROR_CODE), ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), \
ErrorManager::GetInstance().GetLogHeader().c_str(), ##__VA_ARGS__); \
} while (false)

#define GELOGW(fmt, ...) \
do { \
if (IsLogEnable(GE_MODULE_NAME, DLOG_WARN)) { \
dlog_warn(GE_MODULE_NAME, "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], ##__VA_ARGS__); \
} \
} while (false)

#define GELOGI(fmt, ...) \
do { \
if (IsLogEnable(GE_MODULE_NAME, DLOG_INFO)) { \
dlog_info(GE_MODULE_NAME, "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], ##__VA_ARGS__); \
} \
} while (false)

#define GELOGD(fmt, ...) \
do { \
if (IsLogEnable(GE_MODULE_NAME, DLOG_DEBUG)) { \
dlog_debug(GE_MODULE_NAME, "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], ##__VA_ARGS__); \
} \
} while (false)

#define GEEVENT(fmt, ...) \
do { \
dlog_event(GE_MODULE_NAME, "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], ##__VA_ARGS__); \
} while (false)

#define GELOGT(VALUE, fmt, ...) \
do { \
TraceStatus stat = (VALUE); \
const char_t *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \
const int32_t idx = static_cast<int32_t>(stat); \
char_t *k = const_cast<char_t *>("status"); \
char_t *v = const_cast<char_t *>(TraceStatStr[idx]); \
KeyValue kv = {k, v}; \
DlogWithKV(GE_MODULE_NAME, DLOG_TRACE, &kv, 1, "%" PRIu64 " %s:" fmt, GeLog::GetTid(), &__FUNCTION__[0], \
##__VA_ARGS__); \
} while (false)

#define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \
do { \
dlog_error((MOD_NAME), "%" PRIu64 " %s: ErrorNo: %" PRIuLEAST8 "(%s) %s" fmt, GeLog::GetTid(), &__FUNCTION__[0], \
(ERROR_CODE), ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), \
ErrorManager::GetInstance().GetLogHeader().c_str(), ##__VA_ARGS__); \
} while (false)

// print memory when it is greater than 1KB.
#define GE_PRINT_DYNAMIC_MEMORY(FUNC, PURPOSE, SIZE) \
do { \
if ((SIZE) > 1024) { \
GELOGI("MallocMemory, func=%s, size=%zu, purpose=%s", (#FUNC), static_cast<size_t>(SIZE), (PURPOSE)); \
} \
} while (0);
#define GE_PRINT_DYNAMIC_MEMORY(FUNC, PURPOSE, SIZE) \
do { \
if (static_cast<size_t>(SIZE) > 1024UL) { \
GELOGI("MallocMemory, func=%s, size=%" PRIu64 ", purpose=%s", (#FUNC), static_cast<size_t>(SIZE), (PURPOSE)); \
} \
} while (false)
#ifdef __cplusplus
}
#endif


+ 89
- 172
inc/framework/common/debug/log.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,17 +19,14 @@

#include <string>
#include <sstream>
#include <securec.h>

#include "runtime/rt.h"
#include "common/string_util.h"
#include "common/util.h"
#include "common/util/error_manager/error_manager.h"
#include "framework/common/string_util.h"
#include "framework/common/util.h"
#include "framework/common/debug/ge_log.h"
#include "ge/ge_api_error_codes.h"
#include "external/ge/ge_api_error_codes.h"

#if !defined(__ANDROID__) && !defined(ANDROID)
#define DOMI_LOGE(fmt, ...) GE_LOG_ERROR(GE_MODULE_NAME, ge::FAILED, fmt, ##__VA_ARGS__)
#define DOMI_LOGE(fmt, ...) GE_LOG_ERROR(GE_MODULE_NAME, (ge::FAILED), fmt, ##__VA_ARGS__)
#else
#include <android/log.h>
#if defined(BUILD_VERSION_PERF)
@@ -52,196 +49,116 @@
GELOGW(__VA_ARGS__); \
}

#define GE_LOGE_IF(condition, ...) \
if ((condition)) { \
DOMI_LOGE(__VA_ARGS__); \
#define GE_LOGE_IF(condition, ...) \
if ((condition)) { \
GELOGE((ge::FAILED), __VA_ARGS__); \
}

// If expr is not SUCCESS, print the log and return the same value
#define GE_CHK_STATUS_RET(expr, ...) \
do { \
const ge::Status _status = (expr); \
if (_status != ge::SUCCESS) { \
DOMI_LOGE(__VA_ARGS__); \
return _status; \
} \
} while (0);
#define GE_CHK_STATUS_RET(expr, ...) \
do { \
const ge::Status _chk_status = (expr); \
if (_chk_status != ge::SUCCESS) { \
GELOGE((ge::FAILED), __VA_ARGS__); \
return _chk_status; \
} \
} while (false)

// If expr is not SUCCESS, print the log and do not execute return
#define GE_CHK_STATUS(expr, ...) \
do { \
const ge::Status _status = (expr); \
if (_status != ge::SUCCESS) { \
DOMI_LOGE(__VA_ARGS__); \
} \
} while (0);
#define GE_CHK_STATUS(expr, ...) \
do { \
const ge::Status _chk_status = (expr); \
if (_chk_status != ge::SUCCESS) { \
GELOGE(_chk_status, __VA_ARGS__); \
} \
} while (false)

// If expr is not SUCCESS, return the same value
#define GE_CHK_STATUS_RET_NOLOG(expr) \
do { \
const ge::Status _status = (expr); \
if (_status != ge::SUCCESS) { \
return _status; \
} \
} while (0);
#define GE_CHK_STATUS_RET_NOLOG(expr) \
do { \
const ge::Status _chk_status = (expr); \
if (_chk_status != ge::SUCCESS) { \
return _chk_status; \
} \
} while (false)

// If expr is not GRAPH_SUCCESS, print the log and return FAILED
#define GE_CHK_GRAPH_STATUS_RET(expr, ...) \
do { \
if ((expr) != ge::GRAPH_SUCCESS) { \
REPORT_CALL_ERROR("E19999", "Operator graph failed"); \
DOMI_LOGE(__VA_ARGS__); \
return FAILED; \
GELOGE(ge::FAILED, __VA_ARGS__); \
return (ge::FAILED); \
} \
} while (0);
} while (false)

// If expr is not SUCCESS, print the log and execute a custom statement
#define GE_CHK_STATUS_EXEC(expr, exec_expr, ...) \
do { \
const ge::Status _status = (expr); \
GE_CHK_BOOL_EXEC(_status == SUCCESS, exec_expr, __VA_ARGS__); \
} while (0);
#define GE_CHK_STATUS_EXEC(expr, exec_expr, ...) \
do { \
const ge::Status _chk_status = (expr); \
GE_CHK_BOOL_EXEC(_chk_status == SUCCESS, exec_expr, __VA_ARGS__); \
} while (false)

// If expr is not true, print the log and return the specified status
#define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \
do { \
bool b = (expr); \
const bool b = (expr); \
if (!b) { \
REPORT_INNER_ERROR("E19999", __VA_ARGS__); \
GELOGE(_status, __VA_ARGS__); \
return _status; \
GELOGE((_status), __VA_ARGS__); \
return (_status); \
} \
} while (0);
} while (false)

// If expr is not true, print the log and return the specified status
#define GE_CHK_BOOL_RET_STATUS_NOLOG(expr, _status, ...) \
do { \
bool b = (expr); \
const bool b = (expr); \
if (!b) { \
return _status; \
return (_status); \
} \
} while (0);
} while (false)

// If expr is not true, print the log and execute a custom statement
#define GE_CHK_BOOL_EXEC(expr, exec_expr, ...) \
{ \
bool b = (expr); \
const bool b = (expr); \
if (!b) { \
DOMI_LOGE(__VA_ARGS__); \
GELOGE(ge::FAILED, __VA_ARGS__); \
exec_expr; \
} \
}

// If expr is not true, print the log and execute a custom statement
#define GE_CHK_BOOL_EXEC_WARN(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (!b) { \
GELOGW(__VA_ARGS__); \
exec_expr; \
} \
}
// If expr is not true, print the log and execute a custom statement
#define GE_CHK_BOOL_EXEC_INFO(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (!b) { \
GELOGI(__VA_ARGS__); \
exec_expr; \
} \
}

// If expr is not true, print the log and execute a custom statement
#define GE_CHK_BOOL_TRUE_EXEC_INFO(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (b) { \
GELOGI(__VA_ARGS__); \
exec_expr; \
} \
}

// If expr is true, print logs and execute custom statements
#define GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (b) { \
DOMI_LOGE(__VA_ARGS__); \
exec_expr; \
} \
}
// If expr is true, print the Information log and execute a custom statement
#define GE_CHK_TRUE_EXEC_INFO(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (b) { \
GELOGI(__VA_ARGS__); \
exec_expr; \
} \
}

// If expr is not SUCCESS, print the log and execute the expression + return
#define GE_CHK_BOOL_TRUE_RET_VOID(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (b) { \
DOMI_LOGE(__VA_ARGS__); \
exec_expr; \
return; \
} \
}

// If expr is not SUCCESS, print the log and execute the expression + return _status
#define GE_CHK_BOOL_TRUE_EXEC_RET_STATUS(expr, _status, exec_expr, ...) \
{ \
bool b = (expr); \
if (b) { \
REPORT_INNER_ERROR("E19999", __VA_ARGS__); \
DOMI_LOGE(__VA_ARGS__); \
exec_expr; \
return _status; \
} \
}

// If expr is not true, execute a custom statement
#define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
{ \
bool b = (expr); \
if (!b) { \
exec_expr; \
} \
}

// -----------------runtime related macro definitions-------------------------------
// If expr is not RT_ERROR_NONE, print the log
#define GE_CHK_RT(expr) \
do { \
rtError_t _rt_ret = (expr); \
if (_rt_ret != RT_ERROR_NONE) { \
DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
} \
} while (0);
#define GE_CHK_RT(expr) \
do { \
const rtError_t _rt_err = (expr); \
if (_rt_err != RT_ERROR_NONE) { \
GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_err); \
} \
} while (false)

// If expr is not RT_ERROR_NONE, print the log and execute the exec_expr expression
#define GE_CHK_RT_EXEC(expr, exec_expr) \
{ \
rtError_t _rt_ret = (expr); \
if (_rt_ret != RT_ERROR_NONE) { \
DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
exec_expr; \
} \
}
#define GE_CHK_RT_EXEC(expr, exec_expr) \
do { \
const rtError_t _rt_ret = (expr); \
if (_rt_ret != RT_ERROR_NONE) { \
GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
exec_expr; \
} \
} while (false)

// If expr is not RT_ERROR_NONE, print the log and return
#define GE_CHK_RT_RET(expr) \
do { \
rtError_t _rt_ret = (expr); \
const rtError_t _rt_ret = (expr); \
if (_rt_ret != RT_ERROR_NONE) { \
REPORT_CALL_ERROR("E19999", "Call %s fail, ret: 0x%X", #expr, _rt_ret); \
DOMI_LOGE("Call rt api failed, ret: 0x%X", _rt_ret); \
GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
return RT_ERROR_TO_GE_STATUS(_rt_ret); \
} \
} while (0);
} while (false)

// If expr is true, execute exec_expr without printing logs
#define GE_IF_BOOL_EXEC(expr, exec_expr) \
@@ -256,32 +173,32 @@
try { \
exec_expr0; \
} catch (const std::bad_alloc &) { \
DOMI_LOGE("Make shared failed"); \
GELOGE(ge::FAILED, "Make shared failed"); \
exec_expr1; \
}

#define GE_ERRORLOG_AND_ERRORMSG(_status, errormsg) \
{ \
GELOGE(_status, "[Check][InnerData]%s", errormsg); \
REPORT_INNER_ERROR("E19999", "%s", errormsg); \
}
#define GE_WARNINGLOG_AND_ERRORMSG(errormsg) \
{ \
GELOGW("%s", errormsg); \
ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {errormsg}); \
}
#define GE_CHK_LOG_AND_ERRORMSG(expr, _status, errormsg) \
do { \
bool b = (expr); \
if (!b) { \
GELOGE(_status, "%s", errormsg); \
ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {errormsg}); \
return _status; \
} \
} while (0)
#define GE_ERRORLOG_AND_ERRORMSG(_status, errormsg) \
{ \
GELOGE((_status), "[Check][InnerData]%s", (errormsg)); \
REPORT_INNER_ERROR("E19999", "%s", (errormsg)); \
}
#define GE_WARNINGLOG_AND_ERRORMSG(errormsg) \
{ \
GELOGW("%s", (errormsg)); \
ErrorManager::GetInstance().ATCReportErrMessage("E10052", {"reason"}, {(errormsg)}); \
}
#define GE_CHK_LOG_AND_ERRORMSG(expr, _status, errormsg) \
do { \
const bool b = (expr); \
if (!b) { \
GELOGE((_status), "%s", (errormsg)); \
ErrorManager::GetInstance().ATCReportErrMessage("E10052", {"reason"}, {(errormsg)}); \
return (_status); \
} \
} while (false)
namespace ge {
template <typename T>
GE_FUNC_VISIBILITY std::string FmtToStr(const T &t) {
std::string fmt;
@@ -290,5 +207,5 @@ GE_FUNC_VISIBILITY std::string FmtToStr(const T &t) {
fmt = st.str();
return fmt;
}
} // namespace ge
#endif // INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

+ 51
- 0
inc/framework/common/file_constant_util.h View File

@@ -0,0 +1,51 @@
/**
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* 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_FRAMEWORK_COMMON_FILE_CONSTANT_UTIL_H
#define INC_FRAMEWORK_COMMON_FILE_CONSTANT_UTIL_H

#include <map>
#include <string>
#include <vector>
#include "ge/ge_api_error_codes.h"
#include "nlohmann/json.hpp"
#include "graph/op_desc.h"
#include "graph/ge_tensor.h"

namespace ge {
struct FileConstantInfo {
std::string value_bin_file_id;
std::string value_bin_file_path;
};

struct OptionInfo {
std::vector<FileConstantInfo> info;
};

void from_json(const nlohmann::json &j, FileConstantInfo &info);

void from_json(const nlohmann::json &j, OptionInfo &option_info);

Status GetFilePathFromOption(std::map<std::string, std::string> &file_id_and_path_map);

Status CopyOneWeightFromFile(const void *const curr_dev_ptr, const std::string &value, const size_t file_constant_size,
size_t &left_size);

Status GetFilePath(const OpDescPtr &op_desc, const std::map<std::string, std::string> &file_id_and_path_map,
std::string &file_path);
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_FILE_CONSTANT_UTIL_H

+ 15
- 9
inc/framework/common/fmk_error_codes.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,14 +20,18 @@
#if defined(_MSC_VER)
#ifdef FUNC_VISIBILITY
#define GE_FUNC_VISIBILITY _declspec(dllexport)
#define GE_OBJECT_VISIBILITY
#else
#define GE_FUNC_VISIBILITY
#define GE_OBJECT_VISIBILITY
#endif
#else
#ifdef FUNC_VISIBILITY
#define GE_FUNC_VISIBILITY __attribute__((visibility("default")))
#define GE_OBJECT_VISIBILITY
#else
#define GE_FUNC_VISIBILITY
#define GE_OBJECT_VISIBILITY __attribute__((visibility("hidden")))
#endif
#endif

@@ -42,23 +46,23 @@
#define DECLARE_ERRORNO_OME(name, value) DECLARE_ERRORNO(SYSID_FWK, MODID_OME, name, value)
#define DECLARE_ERRORNO_CALIBRATION(name, value) DECLARE_ERRORNO(SYSID_FWK, MODID_CALIBRATION, name, value)

#define DEF_ERRORNO(name, desc) const ErrorNoRegisterar g_##name##_errorno(name, desc);
#define DEF_ERRORNO(name, desc) const ErrorNoRegisterar g_##name##_errorno((name), (desc));

// Interface for Obtaining Error Code Description
#define GET_ERRORNO_STR(value) domi::StatusFactory::Instance()->GetErrDesc(value)

const int MODID_OMG = 1; // OMG module ID
const int MODID_OME = 2; // OME module ID
const int MODID_CALIBRATION = 3; // Calibration module ID

namespace domi {
constexpr int32_t MODID_OMG = 1; // OMG module ID
constexpr int32_t MODID_OME = 2; // OME module ID
constexpr int32_t MODID_CALIBRATION = 3; // Calibration module ID

class GE_FUNC_VISIBILITY StatusFactory {
public:
static StatusFactory *Instance();

void RegisterErrorNo(uint32_t err, const std::string &desc);
void RegisterErrorNo(const uint32_t err, const std::string &desc);

std::string GetErrDesc(uint32_t err);
std::string GetErrDesc(const uint32_t err);

protected:
StatusFactory() {}
@@ -70,7 +74,9 @@ class GE_FUNC_VISIBILITY StatusFactory {

class GE_FUNC_VISIBILITY ErrorNoRegisterar {
public:
ErrorNoRegisterar(uint32_t err, const std::string &desc) { StatusFactory::Instance()->RegisterErrorNo(err, desc); }
ErrorNoRegisterar(const uint32_t err, const std::string &desc) {
StatusFactory::Instance()->RegisterErrorNo(err, desc);
}
~ErrorNoRegisterar() {}
};



+ 1
- 1
inc/framework/common/fmk_types.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.


+ 1
- 1
inc/framework/common/ge_compiler_options.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.


+ 3
- 3
inc/framework/common/ge_format_util.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@

#include <vector>

#include "common/ge_inner_error_codes.h"
#include "framework/common/ge_inner_error_codes.h"
#include "graph/tensor.h"

namespace ge {
@@ -33,7 +33,7 @@ class GE_FUNC_VISIBILITY GeFormatUtil {
/// @param [out] dst_shape destination shape
/// @return Status
///
static Status TransShape(const TensorDesc &src_desc, Format dst_format, std::vector<int64_t> &dst_shape);
static Status TransShape(const TensorDesc &src_desc, const Format dst_format, std::vector<int64_t> &dst_shape);
};
} // namespace ge



+ 54
- 42
inc/framework/common/ge_inner_error_codes.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,17 +22,57 @@
#include <string>
#include "ge/ge_api_error_codes.h"

// Each module defines error codes using the following macros, name can not be modified to (name)
#define GE_ERRORNO_COMMON(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::COMMON_MODULE, name, (value), (desc))
#define GE_ERRORNO_CLIENT(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::CLIENT_MODULE, name, (value), (desc))
#define GE_ERRORNO_INIT(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::INIT_MODULE, name, (value), (desc))
#define GE_ERRORNO_SESSION(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::SESSION_MODULE, name, (value), (desc))
#define GE_ERRORNO_GRAPH(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::GRAPH_MODULE, name, (value), (desc))
#define GE_ERRORNO_ENGINE(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::ENGINE_MODULE, name, (value), (desc))
#define GE_ERRORNO_OPS(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::OPS_MODULE, name, (value), (desc))
#define GE_ERRORNO_PLUGIN(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::PLUGIN_MODULE, name, (value), (desc))
#define GE_ERRORNO_RUNTIME(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::RUNTIME_MODULE, name, (value), (desc))
#define GE_ERRORNO_EXECUTOR(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_DEVICE, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::EXECUTOR_MODULE, name, (value), (desc))
#define GE_ERRORNO_GENERATOR(name, value, desc) \
GE_ERRORNO(ge::InnLogRuntime::RT_HOST, ge::InnErrorCodeType::ERROR_CODE, ge::InnErrorLevel::COMMON_LEVEL, \
ge::InnSystemIdType::SYSID_GE, ge::InnSubModuleId::GENERATOR_MODULE, name, (value), (desc))

// Get error code description
#define GE_GET_ERRORNO_STR(value) ge::StatusFactory::Instance()->GetErrDesc(value)

#define RT_ERROR_TO_GE_STATUS(RT_ERROR) static_cast<Status>(RT_ERROR)

namespace ge {
// System ID
enum SystemIdType { SYSID_GE = 8 };
enum class InnSystemIdType { SYSID_GE = 8 };
// Runtime location
enum LogRuntime {
enum class InnLogRuntime {
RT_HOST = 0b01,
RT_DEVICE = 0b10,
};

// Sub model
enum SubModuleId {
enum class InnSubModuleId {
COMMON_MODULE = 0,
CLIENT_MODULE = 1,
INIT_MODULE = 2,
@@ -47,13 +87,13 @@ enum SubModuleId {
};

// Error code type
enum ErrorCodeType {
enum class InnErrorCodeType {
ERROR_CODE = 0b01,
EXCEPTION_CODE = 0b10,
};

// Error level
enum ErrorLevel {
enum class InnErrorLevel {
COMMON_LEVEL = 0b000,
SUGGESTION_LEVEL = 0b001,
MINOR_LEVEL = 0b010,
@@ -61,33 +101,6 @@ enum ErrorLevel {
CRITICAL_LEVEL = 0b100,
};

// Each module defines error codes using the following macros
#define GE_ERRORNO_COMMON(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, COMMON_MODULE, name, value, desc)
#define GE_ERRORNO_CLIENT(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, CLIENT_MODULE, name, value, desc)
#define GE_ERRORNO_INIT(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, INIT_MODULE, name, value, desc)
#define GE_ERRORNO_SESSION(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, SESSION_MODULE, name, value, desc)
#define GE_ERRORNO_GRAPH(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, GRAPH_MODULE, name, value, desc)
#define GE_ERRORNO_ENGINE(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, ENGINE_MODULE, name, value, desc)
#define GE_ERRORNO_OPS(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, OPS_MODULE, name, value, desc)
#define GE_ERRORNO_PLUGIN(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, PLUGIN_MODULE, name, value, desc)
#define GE_ERRORNO_RUNTIME(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, RUNTIME_MODULE, name, value, desc)
#define GE_ERRORNO_EXECUTOR(name, value, desc) \
GE_ERRORNO(RT_DEVICE, ERROR_CODE, COMMON_LEVEL, SYSID_GE, EXECUTOR_MODULE, name, value, desc)
#define GE_ERRORNO_GENERATOR(name, value, desc) \
GE_ERRORNO(RT_HOST, ERROR_CODE, COMMON_LEVEL, SYSID_GE, GENERATOR_MODULE, name, value, desc)

// Get error code description
#define GE_GET_ERRORNO_STR(value) ge::StatusFactory::Instance()->GetErrDesc(value)

// Common module error code definition
GE_ERRORNO_COMMON(MEMALLOC_FAILED, 0, "Failed to allocate memory!"); // 1343225856
GE_ERRORNO_COMMON(PARAM_INVALID, 1, "Parameter's invalid!"); // 1343225857
@@ -125,13 +138,13 @@ GE_ERRORNO_CLIENT(GE_CLI_GE_ALREADY_INITIALIZED, 10, "GE is already initialized.
GE_ERRORNO_CLIENT(GE_CLI_GE_NOT_INITIALIZED, 11, "GE is not yet initialized or is finalized."); // 1343229963

// Init module error code definition
GE_ERRORNO_INIT(GE_MULTI_INIT, 0, "Multiple initializations are not supported."); // 1343234048
GE_ERRORNO_INIT(GE_FINALIZE_NOT_INIT, 1, "Finalize is not allowed before initialization."); // 1343234049
GE_ERRORNO_INIT(GE_MULTI_FINALIZE, 2, "Multiple finalizations are not supported."); // 1343234050
GE_ERRORNO_INIT(GE_PROF_MULTI_INIT, 3, "Multiple profiling initializations are not supported."); // 1343234051
GE_ERRORNO_INIT(GE_PROF_NOT_INIT, 4, "Profing initializations have not been done."); // 1343234052
GE_ERRORNO_INIT(GE_MULTI_INIT, 0, "Multiple initializations are not supported."); // 1343234048
GE_ERRORNO_INIT(GE_FINALIZE_NOT_INIT, 1, "Finalize is not allowed before initialization."); // 1343234049
GE_ERRORNO_INIT(GE_MULTI_FINALIZE, 2, "Multiple finalizations are not supported."); // 1343234050
GE_ERRORNO_INIT(GE_PROF_MULTI_INIT, 3, "Multiple profiling initializations are not supported."); // 1343234051
GE_ERRORNO_INIT(GE_PROF_NOT_INIT, 4, "Profing initializations have not been done."); // 1343234052
GE_ERRORNO_INIT(GE_PROF_MODE_CONFLICT, 5,
"Profiling command mode which is preferred is running, the api mode will not work."); // 1343234053
"Profiling command mode which is preferred is running, the api mode will not work."); // 1343234053

// Session module error code definition
GE_ERRORNO_SESSION(GE_SESS_INIT_FAILED, 0, "Failed to initialize session."); // 1343238144
@@ -216,8 +229,8 @@ GE_ERRORNO_ENGINE(GE_ENG_FINALIZE_FAILED, 1, "Engine finalize failed.");
GE_ERRORNO_ENGINE(GE_ENG_MEMTYPE_ERROR, 2, "Memory type HBM is necessary when engine is in device"); // 1343246338

// Optimize errocode
GE_ERRORNO_GRAPH(TO_BE_DELETED, 63, "The node of the graph to be deleted."); // 1343242303
GE_ERRORNO_GRAPH(NOT_CHANGED, 64, "The node of the graph no changed."); // 1343242304
GE_ERRORNO_GRAPH(TO_BE_DELETED, 63, "The node of the graph to be deleted."); // 1343242303
GE_ERRORNO_GRAPH(NOT_CHANGED, 64, "The node of the graph no changed."); // 1343242304

// Ops module error code definition
GE_ERRORNO_OPS(GE_OPS_KERNEL_STORE_INIT_FAILED, 0, "Failed to initialize OpsKernelInfoStore."); // 1343250432
@@ -313,7 +326,6 @@ GE_ERRORNO_GENERATOR(GE_GENERATOR_GRAPH_MANAGER_BUILD_GRAPH_FAILED, 3, "Graph ma
GE_ERRORNO_GENERATOR(GE_GENERATOR_GRAPH_MANAGER_FINALIZE_FAILED, 4, "Graph manager finalize failed.");
GE_ERRORNO_GENERATOR(GE_GENERATOR_GRAPH_MANAGER_SAVE_MODEL_FAILED, 5, "Graph manager save model failed.");

#define RT_ERROR_TO_GE_STATUS(RT_ERROR) static_cast<Status>(RT_ERROR)
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_GE_INNER_ERROR_CODES_H_

+ 106
- 34
inc/framework/common/ge_types.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,31 +17,39 @@
#ifndef INC_FRAMEWORK_COMMON_GE_TYPES_H_
#define INC_FRAMEWORK_COMMON_GE_TYPES_H_

#include <stdint.h>
#include <cstdint>

#include <string>
#include <vector>

#include "framework/common/fmk_error_codes.h"
#include "ge/ge_api_error_codes.h"
#include "external/ge/ge_api_error_codes.h"
#include "external/graph/types.h"
#include "external/ge/ge_api_types.h"

namespace ge {
enum RuntimeType { HOST = 0, DEVICE = 1 };

enum PerfLevel { GEN_TASK_WITH_FUSION = -1, GEN_TASK_WITHOUT_L2FUSION = 3, GEN_TASK_WITHOUT_FUSION = 4 };
enum class PerfLevel : int32_t {
GEN_TASK_WITH_FUSION = -1,
GEN_TASK_WITHOUT_L2FUSION = 3,
GEN_TASK_WITHOUT_FUSION = 4
};

enum FrameworkType {
CAFFE = 0,
MINDSPORE = 1,
TENSORFLOW = 3,
ANDROID_NN,
ONNX,
ANDROID_NN = 4,
ONNX = 5,
};

enum class GraphStage : int64_t { GRAPH_STAGE_FUZZ = 0, GRAPH_STAGE_RESERVED };

const char_t *const kGraphDumpStage = "DumpStage";

const std::map<std::string, std::string> kFwkTypeToStr = {
{"0", "Caffe"}, {"1", "MindSpore"}, {"3", "TensorFlow"}, {"4", "Android_NN"}, {"5", "Onnx"}};
{"0", "Caffe"}, {"1", "MindSpore"}, {"3", "TensorFlow"}, {"4", "Android_NN"}, {"5", "Onnx"}};

enum OpEngineType {
ENGINE_SYS = 0, // default engine
@@ -53,28 +61,52 @@ enum OpEngineType {

enum InputAippType { DATA_WITHOUT_AIPP = 0, DATA_WITH_STATIC_AIPP, DATA_WITH_DYNAMIC_AIPP, DYNAMIC_AIPP_NODE };

const char *const GE_ENGINE_ATTR_MEM_TYPE_HBM = "HBM";
const char *const GE_OPTION_EXEC_PLACEMENT = "ge.exec.placement";
const char_t *const GE_ENGINE_ATTR_MEM_TYPE_HBM = "HBM";
const char_t *const GE_OPTION_EXEC_PLACEMENT = "ge.exec.placement";

// profiling data

const std::string kTaskTypeAicore = "AI_CORE";
const std::string kTaskTypeAicpu = "AI_CPU";
const std::string kTaskTypeInvalid = "TASK_TYPE_INVALID";
const std::string kTaskTypeFftsPlus = "FFTS_PLUS";
const std::string kEngineNameVectorCore = "VectorEngine";

const std::string kEngineNameHccl = "ops_kernel_info_hccl";
const std::string kEngineNameRts = "DNN_VM_RTS_OP_STORE";
const std::string kEngineNameHostCpu = "DNN_VM_HOST_CPU_OP_STORE";
const std::string kEngineNameGeLocal = "DNN_VM_GE_LOCAL_OP_STORE";
const std::string kEngineNameAiCpu = "aicpu_ascend_kernel";
const std::string kEngineNameAiCpuTf = "aicpu_tf_kernel";
const std::string kEngineNameAiCore = "AIcoreEngine";
const std::string kAtomicOpType = "DynamicAtomicAddrClean";

const std::string kShapeTypeStatic = "static";
const std::string kShapeTypeDynamic = "dynamic";

constexpr uint64_t kInferSessionId = 0U;
constexpr uint64_t kReleaseFlag = 1U;
constexpr uint32_t kInvalidModelId = 0xFFFFFFFFU;
constexpr size_t kNumTaskWithAtomicAddrCleanTask = 2U;
constexpr uint32_t INVALID_MODEL_ID = 0xFFFFFFFFUL;

// dynamic execute mode
const char *const kLazyRecompile = "lazy_recompile";
const char_t *const kLazyRecompile = "lazy_recompile";

constexpr size_t kMaxHostMemInputLen = 128U; // 64 aligned

// Data cache, including data address and length
struct DataBuffer {
public:
void *data; // Data address
uint64_t length; // Data length
bool isDataSupportMemShare = false;
uint32_t placement = 0;
DataBuffer(void *dataIn, uint64_t len, bool isSupportMemShare, uint32_t placement = 0)
: data(dataIn), length(len), isDataSupportMemShare(isSupportMemShare), placement(placement) {}
uint32_t placement = 0U;

DataBuffer() : data(nullptr), length(0), isDataSupportMemShare(false) {}
DataBuffer(void *const data_in, const uint64_t data_len, const bool is_support_mem_share = false,
const uint32_t data_placement = 0U)
: data(data_in), length(data_len), isDataSupportMemShare(is_support_mem_share), placement(data_placement) {}

DataBuffer() : data(nullptr), length(0UL), isDataSupportMemShare(false), placement(0U) {}
};

///
@@ -86,7 +118,7 @@ struct InputData {
uint32_t timestamp; // Data creation time
uint32_t timeout; // Processing timeout
uint32_t model_id; // Model ID required for data processing
uint64_t request_id = 0; // Request ID
uint64_t request_id = 0UL; // Request ID
std::vector<DataBuffer> blobs; // Actual input data, currently only supports one input
bool is_dynamic_batch = false; // Whether is dynamic batch size scene, default:false
std::string batch_label; // Gear used for current inference in dynamic batch scene
@@ -113,10 +145,10 @@ struct Command {

// The definition of I/O shape description
struct ShapeDescription {
int64_t num = 0;
int64_t channel = 0;
int64_t height = 0;
int64_t width = 0;
int64_t num = 0L;
int64_t channel = 0L;
int64_t height = 0L;
int64_t width = 0L;
std::vector<int64_t> dims;
std::vector<std::pair<int64_t, int64_t>> shape_ranges;
};
@@ -186,14 +218,14 @@ struct AippConfigInfo {
int32_t mean_chn_1;
int32_t mean_chn_2;
int32_t mean_chn_3;
float min_chn_0;
float min_chn_1;
float min_chn_2;
float min_chn_3;
float var_reci_chn_0;
float var_reci_chn_1;
float var_reci_chn_2;
float var_reci_chn_3;
float32_t min_chn_0;
float32_t min_chn_1;
float32_t min_chn_2;
float32_t min_chn_3;
float32_t var_reci_chn_0;
float32_t var_reci_chn_1;
float32_t var_reci_chn_2;
float32_t var_reci_chn_3;
int8_t support_rotation;
uint32_t related_input_rank;
uint32_t max_src_image_size;
@@ -202,26 +234,42 @@ struct AippConfigInfo {
// The structure of offline Modeldata
struct ModelData {
void *model_data = nullptr; // Model binary data start addr
uint32_t model_len = 0; // Model binary data length
uint32_t model_len = 0U; // Model binary data length
int32_t priority = 0; // Model priority
std::string key; // Key path for encrypt model, Empty for unencrypt
std::string om_name; // om file name, used for data dump
};

struct ModelParam {
ModelParam() : priority(0), mem_base(0U), mem_size(0U), weight_base(0U), weight_size(0U) {}
ModelParam(const int32_t pri, const uintptr_t m_base, const size_t m_len, const uintptr_t w_base, const size_t w_len)
: priority(pri), mem_base(m_base), mem_size(m_len), weight_base(w_base), weight_size(w_len) {}
~ModelParam() = default;

int32_t priority;
uintptr_t mem_base;
size_t mem_size;
uintptr_t weight_base;
size_t weight_size;
};

// The definition of Model information
struct ModelInfo {
uint32_t version = 0;
uint32_t version = 0U;
std::string name;
bool is_encrypt = 0; // 0:unencrypt, 1:encrypt
bool is_encrypt = false; // 0:unencrypt, 1:encrypt
std::vector<ShapeDescription> input_desc;
std::vector<ShapeDescription> output_desc;
uint8_t reserved[3] = {0}; // 3-byte reserved field
uint8_t reserved[3] = {0U}; // 3-byte reserved field
};

// Asynchronous callback interface, implemented by the caller
class GE_FUNC_VISIBILITY ModelListener {
public:
virtual ~ModelListener() {}
ModelListener() = default;
ModelListener(const ModelListener &) = delete;
ModelListener &operator=(const ModelListener &) = delete;
///
/// @brief Asynchronous callback interface
/// @param [in] model_id Model ID of the callback
@@ -230,6 +278,18 @@ class GE_FUNC_VISIBILITY ModelListener {
///
virtual Status OnComputeDone(uint32_t model_id, uint32_t data_index, uint32_t result_code,
std::vector<ge::Tensor> &outputs) = 0;

virtual void SetCallback(const RunAsyncCallback &callback) {
(void)callback;
}

virtual uint32_t GetResultCode() {
return 0U;
};

virtual Status ResetResult() {
return SUCCESS;
};
};

// OMM configuration item
@@ -249,6 +309,7 @@ struct Options {
int32_t physical_device_id;
std::string profiling_mode;
std::string profiling_options;
int32_t graphExecTimeout;
};

// Profiling info of task
@@ -268,13 +329,24 @@ struct TaskDescInfo {
std::vector<Format> output_format;
std::vector<std::vector<int64_t>> output_shape;
std::vector<DataType> output_data_type;
uint32_t context_id = 0xFFFFFFFFUL;
};

struct OpDescInfo {
std::string op_name;
std::string op_type;
uint32_t task_id;
uint32_t stream_id;
uint32_t task_id = 0U;
uint32_t stream_id = 0U;
uint32_t imply_type = 0U;
uint32_t block_dim = 0U;
std::string op_file_path;
std::string dev_func;
std::string tvm_magic;
uint32_t tiling_key = 0U;
uintptr_t args = 0U;
std::string tiling_data;
std::string node_info;
std::vector<int64_t> workspace_bytes;
std::vector<Format> input_format;
std::vector<std::vector<int64_t>> input_shape;
std::vector<DataType> input_data_type;


+ 1
- 1
inc/framework/common/gflags_util.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.


+ 42
- 49
inc/framework/common/helper/model_helper.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,11 +20,10 @@
#include <memory>
#include <string>

#include "common/fmk_types.h"
#include "common/helper/om_file_helper.h"
#include "framework/common/helper/om_file_helper.h"
#include "common/model/ge_model.h"
#include "common/model/ge_root_model.h"
#include "common/types.h"
#include "framework/common/types.h"
#include "graph/model.h"

namespace ge {
@@ -34,77 +33,71 @@ class GE_FUNC_VISIBILITY ModelHelper {
~ModelHelper();

Status SaveToOmModel(const GeModelPtr &ge_model, const SaveParam &save_param, const std::string &output_file,
ge::ModelBufferData &model);
Status SaveToOmRootModel(const GeRootModelPtr &ge_root_model, const SaveParam &save_param, const string &output_file,
ModelBufferData &model, bool is_unknown_shape);
Status SaveOriginalGraphToOmModel(const ge::Graph &graph, const std::string &output_file);
ge::ModelBufferData &model) const;
Status SaveToOmRootModel(const GeRootModelPtr &ge_root_model, const SaveParam &save_param,
const std::string &output_file, ModelBufferData &model, const bool is_unknown_shape) const;
Status SaveOriginalGraphToOmModel(const ge::Graph &graph, const std::string &output_file) const;
Status LoadModel(const ge::ModelData &model_data);
Status LoadRootModel(const ge::ModelData &model_data);
Status GetModelBufferData(ge::ModelBufferData &model);

const ModelFileHeader *GetFileHeader() const {
return file_header_;
}
static void SetModelToGeModel(const GeModelPtr &ge_model, Model &model);

GeModelPtr GetGeModel();
GeRootModelPtr GetGeRootModel();
void SetSaveMode(bool val) {
void SetSaveMode(const bool val) {
is_offline_ = val;
}
bool GetSaveMode(void) const {
return is_offline_;
}

bool GetModelType() const {
return is_unknown_shape_model_;
};
}

Status GetBaseNameFromFileName(const std::string &file_name, std::string &base_name);
Status GetModelNameFromMergedGraphName(const std::string &graph_name, std::string &model_name);
Status GetBaseNameFromFileName(const std::string &file_name, std::string &base_name) const;
Status GetModelNameFromMergedGraphName(const ComputeGraphPtr &compute_graph, std::string &model_name) const;

private:
bool is_assign_model_ = false;
bool is_offline_ = true;
bool is_unknown_shape_model_ = false;
ModelFileHeader *file_header_ = nullptr;
// Encrypted model need delete temp model and unencrypted model need not delete model
uint8_t *model_addr_tmp_ = nullptr;
uint32_t model_len_tmp_ = 0;
GeModelPtr model_;
GeRootModelPtr root_model_;

ModelHelper(const ModelHelper &);
ModelHelper &operator=(const ModelHelper &);
Status GenerateGeModel(OmFileLoadHelper &om_load_helper);
Status GenerateGeRootModel(OmFileLoadHelper &om_load_helper);
Status LoadModelData(OmFileLoadHelper &om_load_helper);
void SetModelToGeModel(GeModelPtr &ge_model, Model &model);
Status LoadModelData(OmFileLoadHelper &om_load_helper, GeModelPtr &cur_model, size_t mode_index);
Status LoadWeights(OmFileLoadHelper &om_load_helper);
Status LoadWeights(OmFileLoadHelper &om_load_helper, GeModelPtr &cur_model, size_t mode_index);
Status LoadTask(OmFileLoadHelper &om_load_helper);
Status LoadTask(OmFileLoadHelper &om_load_helper, GeModelPtr &cur_model, size_t mode_index);
Status LoadTBEKernelStore(OmFileLoadHelper &om_load_helper);
Status LoadTBEKernelStore(OmFileLoadHelper &om_load_helper, GeModelPtr &cur_model, size_t mode_index);
Status LoadCustAICPUKernelStore(OmFileLoadHelper &om_load_helper);
Status LoadCustAICPUKernelStore(OmFileLoadHelper &om_load_helper, GeModelPtr &cur_model, size_t mode_index);
Status ReleaseLocalModelData() noexcept;
Status SaveModelPartition(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, ModelPartitionType type,
const uint8_t *data, size_t size, size_t model_index);
ModelHelper(const ModelHelper &) = default;
ModelHelper &operator=(const ModelHelper &) = default;

bool IsPartitionedGraph(const GeModelPtr &cur_model) const;

Status GenerateGeModel(const OmFileLoadHelper &om_load_helper, GeModelPtr &cur_model, const size_t mode_index,
const bool is_dyn_root);
Status GenerateGeRootModel(const OmFileLoadHelper &om_load_helper);

Status LoadModelData(const OmFileLoadHelper &om_load_helper, const GeModelPtr &cur_model,
const size_t mode_index) const;
Status LoadWeights(const OmFileLoadHelper &om_load_helper, const GeModelPtr &cur_model,
const size_t mode_index) const;
Status LoadTask(const OmFileLoadHelper &om_load_helper, const GeModelPtr &cur_model, const size_t mode_index) const;
Status LoadTBEKernelStore(const OmFileLoadHelper &om_load_helper, const GeModelPtr &cur_model,
const size_t mode_index) const;
Status LoadCustAICPUKernelStore(const OmFileLoadHelper &om_load_helper, const GeModelPtr &cur_model,
const size_t mode_index) const;

Status SaveModelPartition(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, const ModelPartitionType type,
const uint8_t *const data, const size_t size, const size_t model_index) const;
Status SaveModelDef(shared_ptr<OmFileSaveHelper> &om_file_save_helper, const GeModelPtr &ge_model,
Buffer &model_buffer, size_t model_index = 0);
Status SaveSizeToModelDef(const GeModelPtr &ge_model);
Buffer &model_buffer, const size_t model_index = 0U) const;
Status SaveSizeToModelDef(const GeModelPtr &ge_model) const;
Status SaveModelWeights(shared_ptr<OmFileSaveHelper> &om_file_save_helper, const GeModelPtr &ge_model,
size_t model_index = 0);
const size_t model_index = 0U) const;
Status SaveModelTbeKernel(shared_ptr<OmFileSaveHelper> &om_file_save_helper, const GeModelPtr &ge_model,
size_t model_index = 0);
const size_t model_index = 0U) const;
Status SaveModelCustAICPU(shared_ptr<OmFileSaveHelper> &om_file_save_helper, const GeModelPtr &ge_model,
size_t model_index = 0);
const size_t model_index = 0U) const;
Status SaveModelTaskDef(shared_ptr<OmFileSaveHelper> &om_file_save_helper, const GeModelPtr &ge_model,
Buffer &task_buffer, size_t model_index = 0);
Buffer &task_buffer, const size_t model_index = 0U) const;
Status SaveModelHeader(shared_ptr<OmFileSaveHelper> &om_file_save_helper, const GeModelPtr &ge_model,
size_t model_num = 1);
const size_t model_num = 1U) const;
Status SaveAllModelPartiton(shared_ptr<OmFileSaveHelper> &om_file_save_helper, const GeModelPtr &ge_model,
Buffer &model_buffer, Buffer &task_buffer, size_t model_index = 0);
Buffer &model_buffer, Buffer &task_buffer, const size_t model_index = 0U) const;
};
} // namespace ge
#endif // INC_FRAMEWORK_COMMON_HELPER_MODEL_HELPER_H_

+ 28
- 34
inc/framework/common/helper/om_file_helper.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,25 +21,20 @@
#include <vector>

#include "external/ge/ge_ir_build.h"
#include "framework/common/fmk_types.h"
#include "framework/common/types.h"
#include "framework/common/ge_types.h"

using ProcParam = struct PROC_PARAM;
using std::string;
using std::vector;

namespace ge {
struct ModelPartition {
ModelPartitionType type;
uint8_t *data = 0;
uint32_t size = 0;
const uint8_t *data = nullptr;
uint32_t size = 0U;
};

struct OmFileContext {
std::vector<ModelPartition> partition_datas_;
std::vector<char> partition_table_;
uint32_t model_data_len_ = 0;
std::vector<char_t> partition_table_;
uint32_t model_data_len_ = 0U;
};

struct SaveParam {
@@ -53,57 +48,56 @@ struct SaveParam {

class GE_FUNC_VISIBILITY OmFileLoadHelper {
public:
Status Init(const ge::ModelData &model);
Status Init(const ModelData &model);

Status Init(uint8_t *model_data, const uint32_t model_data_size);
Status Init(uint8_t *const model_data, const uint32_t model_data_size);

Status Init(uint8_t *model_data, const uint32_t model_data_size, uint32_t model_num);
Status Init(uint8_t *const model_data, const uint32_t model_data_size, const uint32_t model_num);

Status GetModelPartition(ModelPartitionType type, ModelPartition &partition);
Status GetModelPartition(const ModelPartitionType type, ModelPartition &partition);

Status GetModelPartition(ModelPartitionType type, ModelPartition &partition, size_t model_index);
Status GetModelPartition(const ModelPartitionType type, ModelPartition &partition, const size_t model_index) const;

OmFileContext context_;

vector<OmFileContext> model_contexts_;
std::vector<OmFileContext> model_contexts_;

private:
Status CheckModelValid(const ge::ModelData &model) const;

Status LoadModelPartitionTable(uint8_t *model_data, const uint32_t model_data_size);
Status LoadModelPartitionTable(uint8_t *const model_data, const uint32_t model_data_size, const size_t model_index,
size_t &mem_offset);

Status LoadModelPartitionTable(uint8_t *model_data, const uint32_t model_data_size, uint32_t model_num);
Status LoadModelPartitionTable(uint8_t *const model_data, const uint32_t model_data_size, const uint32_t model_num);

bool is_inited_{false};
};

class GE_FUNC_VISIBILITY OmFileSaveHelper {
public:
ModelFileHeader &GetModelFileHeader() { return model_header_; }
ModelFileHeader &GetModelFileHeader() {
return model_header_;
}

uint32_t GetModelDataSize() const { return context_.model_data_len_; }
uint32_t GetModelDataSize() const;

ModelPartitionTable *GetPartitionTable();

Status AddPartition(ModelPartition &partition);
Status AddPartition(const ModelPartition &partition);

Status AddPartition(ModelPartition &partition, size_t cur_index);
Status AddPartition(const ModelPartition &partition, const size_t cur_index);

const std::vector<ModelPartition> &GetModelPartitions() const;
Status SaveModel(const SaveParam &save_param, const char_t *const output_file, ModelBufferData &model,
const bool is_offline = true);

Status SaveModel(const SaveParam &save_param, const char *target_file, ge::ModelBufferData &model,
bool is_offline = true);
Status SaveModelToFile(const char_t *const output_file, ModelBufferData &model, const bool is_offline = true);

Status SaveModelToFile(const char *output_file, ge::ModelBufferData &model, bool is_offline = true);
ModelPartitionTable *GetPartitionTable(const size_t cur_ctx_index);

vector<OmFileContext> model_contexts_;
Status SaveRootModel(const SaveParam &save_param, const char_t *const output_file, ModelBufferData &model,
const bool is_offline);

private:
ModelFileHeader model_header_;
OmFileContext context_;

ModelPartitionTable *GetPartitionTable(size_t cur_ctx_index);

Status SaveRootModel(const SaveParam &save_param, const char *output_file, ModelBufferData &model, bool is_offline);
std::vector<OmFileContext> model_contexts_;
};
} // namespace ge
#endif // INC_FRAMEWORK_COMMON_HELPER_OM_FILE_HELPER_H_

+ 7
- 90
inc/framework/common/l2_cache_optimize.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,107 +17,24 @@
#ifndef INC_FRAMEWORK_COMMON_L2_CACHE_OPTIMIZE_H_
#define INC_FRAMEWORK_COMMON_L2_CACHE_OPTIMIZE_H_

#include <stdint.h>
#include <cstdint>

#include <algorithm>
#include <functional>
#include <string>
#include <vector>

#include "common/types.h"
#include "common/util.h"
#include "framework/common/types.h"
#include "framework/common/util.h"
#include "graph/compute_graph.h"

using std::vector;

namespace ge {
// Size of RC memory alignment, 2M
constexpr size_t ALIGN_SIZE = 2097152;

constexpr uint32_t RC_VALUE_DEFAULT = 1;
constexpr uint32_t RC_VALUE_MAX = 32;

// RC data type classification
enum RCType {
RC_DEFAULT, // Such as temporary workspace memory of operator, variable (including global and local variable)
RC_HCOM, // Output of gradient aggregation, RC value should be set to 0
RC_L2LOSS, // Parameter of L2 loss operator, RC value should be set to 0
RC_INPUTOUTPUT, // Input and output tensor of operator, RC value is returned by FE calculation
RC_WEIGHTS, // The weight, fp16, RC value used by FP/BP operator should be set to 1 or the actual access numbers
RC_DW, // The gradient data DW and RC value output by BP operator
// should be set to 1 or the actual access numbers
RC_ARGS // Args of FlowTable, actual access numbers
};

enum MemType { INPUT_TENSOR, OUTPUT_TENSOR, WEIGHT, WORKSPACE };

// Memory usage information < node, type, number >
struct NodeInfo {
string nodeName;
MemType memType;
size_t index;
};

// Memory block RC value
struct RCMemoryBlock {
RCType type; // RC type
size_t blockSize; // memory block size
size_t headOffset; // Start offset from base address
size_t tailOffset; // End offset from base address
uint32_t rcCount; // RC value
NodeInfo nodeInfo; // Input and output indexes of node objects to which RC belongs
};

// L2Cache optimizer
class GE_FUNC_VISIBILITY L2CacheOptimize {
public:
explicit L2CacheOptimize(ge::ComputeGraphPtr &graph);
~L2CacheOptimize();

// Collect the information L2Cache Memory optimization
Status Gath();

private:
ge::ComputeGraphPtr graph_;

// Save RC block information list
vector<RCMemoryBlock> weightRCs;
vector<RCMemoryBlock> opRCs;

// Extract RC information generated by FE from compiled graph
void RetirveRCinfo();

// Take the maximum common divisor of RC values for the duplicate address
void Merge(vector<RCMemoryBlock> &blocks);

// The RC information is aligned with the 2m address
void Align(vector<RCMemoryBlock> &blocks);

// Weight of l2loss operator, output of gradient aggregation output, RC value set to 0
void HandleOutputZeroRC(RCType type, ge::NodePtr node, vector<int64_t> &outputList, vector<RCMemoryBlock> &blocks);

// Processing operator input Tensor's RC
void HandOPInput(ge::NodePtr node, vector<int64_t> &inputList, vector<RCMemoryBlock> &blocks);

// Processing operator output Tensor's RC
void HandOPoutput(ge::NodePtr node, vector<int64_t> &outputList, vector<RCMemoryBlock> &blocks);
constexpr size_t ALIGN_SIZE = 2097152U;

// maximum common divisor
uint32_t Measure(uint32_t x, uint32_t y) {
if (x == 0 || y == 0) return RC_VALUE_DEFAULT;
uint32_t z = y;
while (x % y != 0) {
z = x % y;
x = y;
y = z;
}
return z;
}
constexpr uint32_t RC_VALUE_DEFAULT = 1U;
constexpr uint32_t RC_VALUE_MAX = 32U;

bool Contain(const RCMemoryBlock &l_block, const RCMemoryBlock &r_block);
bool Cross(const RCMemoryBlock &l_block, const RCMemoryBlock &r_block);
bool Connect(const RCMemoryBlock &l_block, const RCMemoryBlock &r_block);
};
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_L2_CACHE_OPTIMIZE_H_

+ 3
- 134
inc/framework/common/op/attr_value_util.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,141 +34,10 @@
#include <google/protobuf/map.h>
#include <unordered_map>
#include <string>

#include "graph/debug/ge_attr_define.h"
#include "proto/om.pb.h"

using domi::AttrDef;
using domi::AttrDef_ListValue;
using domi::ModelDef;
using domi::NamedAttrs;
using domi::OpDef;

namespace ge {
using AttrDefMap = ::google::protobuf::Map<::std::string, ::domi::AttrDef>;
using AttrDefPair = ::google::protobuf::MapPair<std::string, domi::AttrDef>;

GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, AttrDef &attr, OpDef *opdef);
// DEFINE_ADD_ATTR_VALUE
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const std::string &value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const char *value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttr(const char *key, const char *value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const uint32_t value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const int32_t value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const int64_t value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const float value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const double value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const bool value, AttrDefMap *attrs);

GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const AttrDef_ListValue &value, AttrDefMap *attrs);

// DEFINE_ADD_ATTR_VALUE
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const std::string &value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const char *value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttr(const char *key, const char *value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const uint32_t value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const int32_t value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const int64_t value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const float value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const double value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const bool value, OpDef *opdef);

GE_FUNC_VISIBILITY void AddOpAttr(const std::string &key, const AttrDef_ListValue &value, OpDef *opdef);

GE_FUNC_VISIBILITY void AddOpBytesAttr(const std::string &key, const void *value, size_t size, OpDef *opdef);

// DEFINE_ADD_ATTR_VALUE_LIST
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const double value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const float value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const uint32_t value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const int32_t value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const std::string value, AttrDefMap *attrs);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const double value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const float value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const uint32_t value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const int32_t value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const bool value, OpDef *opdef);
GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const int64_t value, OpDef *opdef);

GE_FUNC_VISIBILITY void AddOpAttrList(const std::string &key, const std::string &value, OpDef *opdef);

GE_FUNC_VISIBILITY bool GetOpAttr(const std::string &key, std::string *value, const OpDef *opdef);
GE_FUNC_VISIBILITY bool GetOpAttr(const std::string &key, int32_t *value, const OpDef *opdef);
GE_FUNC_VISIBILITY bool GetOpAttr(const std::string &key, int64_t *value, const OpDef *opdef);
GE_FUNC_VISIBILITY bool GetOpAttr(const std::string &key, uint32_t *value, const OpDef *opdef);
GE_FUNC_VISIBILITY bool GetOpAttr(const std::string &key, float *value, const OpDef *opdef);
GE_FUNC_VISIBILITY bool GetOpAttr(const std::string &key, double *value, const OpDef *opdef);
GE_FUNC_VISIBILITY bool GetOpAttr(const std::string &key, bool *value, const OpDef *opdef);
GE_FUNC_VISIBILITY bool GetOpAttr(const std::string &key, AttrDef_ListValue *value, const OpDef *opdef);

GE_FUNC_VISIBILITY uint32_t GetOpAttrListSize(const std::string &key, std::string value, const OpDef *opdef);
GE_FUNC_VISIBILITY uint32_t GetOpAttrListSize(const std::string &key, int32_t value, const OpDef *opdef);
GE_FUNC_VISIBILITY uint32_t GetOpAttrListSize(const std::string &key, int64_t value, const OpDef *opdef);
GE_FUNC_VISIBILITY uint32_t GetOpAttrListSize(const std::string &key, uint32_t value, const OpDef *opdef);
GE_FUNC_VISIBILITY uint32_t GetOpAttrListSize(const std::string &key, float value, const OpDef *opdef);
GE_FUNC_VISIBILITY uint32_t GetOpAttrListSize(const std::string &key, double value, const OpDef *opdef);
GE_FUNC_VISIBILITY uint32_t GetOpAttrListSize(const std::string &key, bool value, const OpDef *opdef);

GE_FUNC_VISIBILITY bool GetBytesAttr(const std::string &key, std::string *value, const OpDef *opdef);
GE_FUNC_VISIBILITY bool GetBytesAttr(const std::string &key, std::string *value, const ModelDef *model_def);

GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const std::string &value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const char *value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const char *key, const char *value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const uint32_t value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const int32_t value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const int64_t value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const float value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const double value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const bool value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const void *value, size_t size, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttr(const std::string &key, const AttrDef_ListValue &value, ModelDef *model_def);

GE_FUNC_VISIBILITY void AddModelAttrList(const std::string &key, const double value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttrList(const std::string &key, const float value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttrList(const std::string &key, const uint32_t value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttrList(const std::string &key, const int32_t value, ModelDef *model_def);
GE_FUNC_VISIBILITY void AddModelAttrList(const std::string &key, const std::string &value, ModelDef *model_def);

GE_FUNC_VISIBILITY bool GetModelAttr(const std::string &key, std::string *value, const ModelDef *model_def);
GE_FUNC_VISIBILITY bool GetModelAttr(const std::string &key, int32_t *value, const ModelDef *model_def);
GE_FUNC_VISIBILITY bool GetModelAttr(const std::string &key, int64_t *value, const ModelDef *model_def);
GE_FUNC_VISIBILITY bool GetModelAttr(const std::string &key, uint32_t *value, const ModelDef *model_def);
GE_FUNC_VISIBILITY bool GetModelAttr(const std::string &key, float *value, const ModelDef *model_def);
GE_FUNC_VISIBILITY bool GetModelAttr(const std::string &key, double *value, const ModelDef *model_def);
GE_FUNC_VISIBILITY bool GetModelAttr(const std::string &key, bool *value, const ModelDef *model_def);
GE_FUNC_VISIBILITY bool GetModelAttr(const std::string &key, AttrDef_ListValue *value, const ModelDef *model_def);

GE_FUNC_VISIBILITY bool HasOpAttr(const OpDef *opdef, const std::string &attr_name);

GE_FUNC_VISIBILITY void SetAttrDef(const std::string &value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrDef(const char *value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrDef(const uint32_t value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrDef(const int32_t value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrDef(const float value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrDef(const double value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrDef(const bool value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrList(const std::string &value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrList(const bool value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrList(const float value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrList(const double value, AttrDef *out);
GE_FUNC_VISIBILITY void SetAttrList(const uint32_t value, AttrDef *out);

GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, std::string *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, int32_t *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, int64_t *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, uint32_t *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, float *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, double *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, bool *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, AttrDef_ListValue *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, NamedAttrs *&value, AttrDefMap *attr);
GE_FUNC_VISIBILITY bool GetAttrDefValue(const std::string &key, const NamedAttrs *&value, const AttrDefMap &attr);

GE_FUNC_VISIBILITY bool GetAttrDefListValue(const std::string &key, int idx, int32_t *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefListValue(const std::string &key, int idx, uint32_t *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefListValue(const std::string &key, int idx, float *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY bool GetAttrDefListValue(const std::string &key, int idx, double *value, const AttrDefMap &attr);
GE_FUNC_VISIBILITY void SetAttrDef(const std::string &value, domi::AttrDef *const out);
}

#endif // INC_FRAMEWORK_COMMON_OP_ATTR_VALUE_UTIL_H_
#endif // INC_FRAMEWORK_COMMON_OP_ATTR_VALUE_UTIL_H_

+ 25
- 78
inc/framework/common/op/ge_op_utils.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +20,8 @@
#include <memory>
#include <vector>

#include "common/op/attr_value_util.h"
#include "register/register_types.h"
#include "register/register_error_codes.h"
#include "common/util.h"
#include "framework/common/op/attr_value_util.h"
#include "framework/common/util.h"
#include "graph/attr_value.h"
#include "graph/ge_tensor.h"
#include "graph/node.h"
@@ -31,18 +29,16 @@
#include "proto/insert_op.pb.h"

namespace ge {
using domi::Status;

// Add Sub Mul
GE_FUNC_VISIBILITY extern const uint32_t ADD_INPUT_NUM;
GE_FUNC_VISIBILITY extern const uint32_t SUB_INPUT_NUM;
GE_FUNC_VISIBILITY extern const uint32_t MUL_INPUT_NUM;

// Permute
GE_FUNC_VISIBILITY extern const int32_t PERMUTE_ORDER_NUM;

// Ssd PriroBox
GE_FUNC_VISIBILITY extern const double SSD_PRIORBOX_ASPECT_RATIO_VALUE;
GE_FUNC_VISIBILITY extern const float64_t SSD_PRIORBOX_ASPECT_RATIO_VALUE;

GE_FUNC_VISIBILITY extern const uint32_t STRIDEDSLICE_INPUT_NUM;

@@ -55,8 +51,8 @@ GE_FUNC_VISIBILITY extern const uint32_t SWITCH_DATA_INPUT;
GE_FUNC_VISIBILITY extern const uint32_t SWITCH_PRED_INPUT;

// Merge
GE_FUNC_VISIBILITY extern const uint32_t MERGE_DATA_OUTPUT;
GE_FUNC_VISIBILITY extern const uint32_t MERGE_INDEX_OUTPUT;
GE_FUNC_VISIBILITY extern const int32_t MERGE_DATA_OUTPUT;
GE_FUNC_VISIBILITY extern const int32_t MERGE_INDEX_OUTPUT;

// FunctionOp
GE_FUNC_VISIBILITY extern const uint32_t IF_COND_INPUT;
@@ -65,85 +61,36 @@ GE_FUNC_VISIBILITY extern const uint32_t FOR_LIMIT_INPUT;
GE_FUNC_VISIBILITY extern const uint32_t FOR_DELTA_INPUT;
GE_FUNC_VISIBILITY extern const uint32_t FOR_DATA_INPUT;

GE_FUNC_VISIBILITY extern const int NORMAL_TENSOR_SIZE;
GE_FUNC_VISIBILITY extern const int32_t NORMAL_TENSOR_SIZE;
/*lint -e148*/
class GE_FUNC_VISIBILITY OpUtils {
public:
///
/// @ingroup domi_ome
/// @brief Check whether check_value is in [min_enum_value, max_enum_value]
/// @return true Within
/// @return false out of range
//
static inline bool CheckEnumValid(int32_t check_value, int32_t min_enum_value, int32_t max_enum_value) {
return check_value < min_enum_value ? false : (check_value >= max_enum_value ? false : true);
}

///
/// @ingroup domi_omg
/// @brief Determine whether to manually calculate the tensor size based on the values of format and dim
/// @param [in] format, Format information of the tensor
/// @param [in] real_dim_cnt, Tensor dim
/// @return true Manually calculate the size based on dim and datatype
/// @return false skip
///
static bool IsComputDimsSize(const int32_t format, const uint32_t real_dim_cnt);

///
/// @brief Extract AIPP parameters from AttrDefMap and splice them
/// @param [in] aipp_attr attr of operator
/// @param [out] aipp_params aipp parameters
/// @return enum of tagCCAippInputFormat
///
static Status ConvertAippParams(const GeAttrValue::NamedAttrs &aipp_attr, domi::AippOpParams *aipp_params);
static Status TransferDim(const std::vector<int64_t> &dim, std::vector<int64_t> &dim_vector);

static Status ConvertAippParams(const GeAttrValue::NamedAttrs &aipp_attr, domi::AippOpParams &aipp_params);
template <typename T>
static void SliceData(const std::vector<char *> &input, int64_t chunk_size, std::vector<char *> &output,
int64_t begin, int64_t out_dim, int64_t stride);
static void SliceData(const std::vector<char_t *> &input, const int64_t chunk_size, std::vector<char_t *> &output,
const int64_t begin, const int64_t out_dim, const int64_t stride);
template <typename T>
static Status SetDataByDataType(size_t out_size, const std::vector<char *> &chunk_input,
const std::vector<char *> &chunk_output, GeTensor *output);
static Status SetDataByDataType(const size_t out_size, const std::vector<char_t *> &chunk_input,
const std::vector<char_t *> &chunk_output, GeTensor *const output);
template <typename T>
static Status SetOutputSliceDataByDataType(void *data, int64_t data_size, const std::vector<int64_t> &input_dims,
const std::vector<int64_t> &begin, const std::vector<int64_t> &output_dims,
ge::GeTensor *output, const std::vector<int64_t> &stride);
static Status SetOutputSliceData(void *data, int64_t data_size, int32_t data_type, std::vector<int64_t> &input_dims,
std::vector<int64_t> &begin, std::vector<int64_t> &output_dims, ge::GeTensor *output,
std::vector<int64_t> &stride);

///
/// @ingroup domi_omg
/// @brief Convert the convolutional weight data from [h, w, c, k] to [k, c, h, w]
/// @param [in] input Weight data in HWCK format
/// @param [in] H value of H dimension
/// @param [in] W value of W dimension
/// @param [in] C value of C dimension
/// @param [in] K value of K dimension
/// @param [out] output Data pointer after conversion. The format is KCHW.
///
static void TransDataHWCK2KCHW(const void *input, int64_t H, int64_t W, int64_t C, int64_t K, void **output);
///
/// @ingroup domi_omg
/// @brief Converts the convolutional weight data from [k, c, h, w] to [h, w, c, k].
/// @param [in] input Weight data in HWCK format
/// @param [in] K value of K dimension
/// @param [in] C value of C dimension
/// @param [in] H value of H dimension
/// @param [in] W value of W dimension
/// @param [out] output Data pointer after conversion. The format is HWCK
///
static void TransDataKCHW2HWCK(const void *input, int64_t K, int64_t C, int64_t H, int64_t W, void *output);

static vector<ConstGeTensorPtr> GetWeights(const ge::Node &node);
static vector<ConstGeTensorPtr> GetWeights(ge::ConstNodePtr node);
static vector<GeTensorPtr> MutableWeights(const ge::Node &node);
static vector<GeTensorPtr> MutableWeights(const ge::NodePtr node);
static Status SetWeights(ge::Node &node, const vector<ge::GeTensorPtr> &weights);
static Status SetWeights(ge::NodePtr node, const vector<ge::GeTensorPtr> &weights);
static Status GetShapeDataFromConstTensor(const ConstGeTensorPtr &tensor, DataType type, std::vector<int64_t> &dims);

private:
static uint32_t GetRealDimCnt(const GeTensorDesc &tensor_desc);
static Status SetOutputSliceDataByDataType(void *const data, const int64_t data_size,
const std::vector<int64_t> &input_dims, const std::vector<int64_t> &begin,
const std::vector<int64_t> &output_dims, ge::GeTensor *const output,
const std::vector<int64_t> &stride);
static Status SetOutputSliceData(void *const data, const int64_t data_size, const int32_t data_type,
const std::vector<int64_t> &input_dims, const std::vector<int64_t> &begin,
const std::vector<int64_t> &output_dims, GeTensor *const output,
const std::vector<int64_t> &stride);
static Status GetShapeDataFromConstTensor(const ConstGeTensorPtr &tensor, const DataType type,
std::vector<int64_t> &dims);
};
/*lint +e148*/
} // namespace ge
#endif // INC_FRAMEWORK_COMMON_OP_GE_OP_UTILS_H_

+ 25
- 25
inc/framework/common/op/op_parser_util.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,9 @@
#ifndef INC_FRAMEWORK_COMMON_OP_OP_PARSER_UTIL_H_
#define INC_FRAMEWORK_COMMON_OP_OP_PARSER_UTIL_H_

#include <limits.h>
#include <math.h>
#include <stdint.h>
#include <climits>
#include <cmath>
#include <cstdint>

namespace ge {
// general
@@ -30,7 +30,7 @@ const uint32_t NORMAL_OUTPUT_NUM = 1;
const uint32_t NORMAL_WORKSPACE_NUM = 0;
const int32_t NORMAL_1D_DIM_NUM = 1;
const int32_t NORMAL_SCALE_DIM_NUM = 0;
const int NORMAL_TENSOR_SIZE = 4;
const int32_t NORMAL_TENSOR_SIZE = 4;
const uint32_t DEFAULT_REAL_DIM_CNT = 4;

// const
@@ -111,8 +111,8 @@ const int32_t ROIPOOLING_DEFAULT_SAMPLING_RATIO = -1;
const int32_t DETECTIONOUTPUT_INPUT_SIZE = 3;
const int32_t DETECTIONOUTPUT_OUTPUT_SIZE = 2;
const int32_t DETECTIONOUTPUT_WORKSPACE_NUM = 1;
const int DETECTIONOUTPUT_CLASS_NUM = 20; // Number of background categories
const int DETECTIONOUTPUT_NUM_CLASSES_DEFAULT_VALUE = 21;
const int32_t DETECTIONOUTPUT_CLASS_NUM = 20; // Number of background categories
const int32_t DETECTIONOUTPUT_NUM_CLASSES_DEFAULT_VALUE = 21;
const float DETECTIONOUTPUT_NMS_THRESHOLD_DEFAULT_VALUE = 0.3;
const float DETECTIONOUTPUT_CONFIDENCE_THRESHOLD_DEFAULT_VALUE = 0.8;

@@ -128,8 +128,8 @@ const float PROPOSAL_SCALE_DIM_0_DEFAULT_VALUE = 8;
const float PROPOSAL_SCALE_DIM_1_DEFAULT_VALUE = 16;
const float PROPOSAL_SCALE_DIM_2_DEFAULT_VALUE = 32;
const float PROPOSAL_MIN_SIZE_DEFAULT_VALUE = 16;
const int PROPOSAL_PRE_NMS_TOPN_DEFAULT_VALUE = 6000;
const int PROPOSAL_POST_NMS_TOPN_DEFAULT_VALUE = 304;
const int32_t PROPOSAL_PRE_NMS_TOPN_DEFAULT_VALUE = 6000;
const int32_t PROPOSAL_POST_NMS_TOPN_DEFAULT_VALUE = 304;
const float PROPOSAL_NMS_THRESH_DEFAULT_VALUE = 0.7;
const float PROPOSAL_FILTER_THRESH_DEFAULT_VALUE = 0;

@@ -150,7 +150,7 @@ const int32_t PERMUTE_WORKSPACE_NUM = 1;
const int32_t PERMUTE_ORDER_NUM = 4;

// Ssd normalize
const int SSD_NORMALIZE_INPUT_SIZE = 1;
const int32_t SSD_NORMALIZE_INPUT_SIZE = 1;
const float SSD_NORMALIZE_EPS_DEFAULT_VALUE = 2e-7;

// SsdPriroBox
@@ -163,9 +163,9 @@ const double SSD_PRIORBOX_VARIANCE_VALUE = 0.1;
const double SSD_PRIORBOX_VARIANCE_SIZE_ONE = 1;
const double SSD_PRIORBOX_VARIANCE_SIZE_FOUR = 4;
const double SSD_PRIORBOX_ASPECT_RATIO_VALUE = 1.0;
const int SSD_PRIOR_BOX_CODETYPE_CORNER_VALUE = 1;
const int SSD_PRIOR_BOX_CODETYPE_CENTER_SIZE_VALUE = 2;
const int SSD_PRIOR_BOX_CODETYPE_CORNER_SIZE_VALUE = 3;
const int32_t SSD_PRIOR_BOX_CODETYPE_CORNER_VALUE = 1;
const int32_t SSD_PRIOR_BOX_CODETYPE_CENTER_SIZE_VALUE = 2;
const int32_t SSD_PRIOR_BOX_CODETYPE_CORNER_SIZE_VALUE = 3;

// Ssd DetectionOutput
const int32_t SSD_DETECTIONOUTPUT_INPUT_SIZE = 3;
@@ -205,8 +205,8 @@ const int32_t CHANNEL_AXPY_INPUT_DIM_SIZE = 4;
const int32_t CHANNEL_AXPY_WORKSPACE_NUM = 1;

// Psroi pooling
const int PSROI_POOLING_INPUT_COUNT = 2;
const int PSROI_POOLING_WORKSPACE_NUM = 1;
const int32_t PSROI_POOLING_INPUT_COUNT = 2;
const int32_t PSROI_POOLING_WORKSPACE_NUM = 1;

// MaxPoolWithArgmax
const uint32_t MAX_POOL_WITH_ARGMAX_OUTPUT_NUM = 2;
@@ -223,7 +223,7 @@ const int32_t ROIALIGN_DEFAULT_POOLED_W = 1;

// Correlation
const uint32_t CORRELATION_INPUT_NUM = 2;
const int CORRELATION_WORKSPACE_NUM = 1;
const int32_t CORRELATION_WORKSPACE_NUM = 1;

// Detectionpostprocess
const int32_t POSTPROCESS_INPUT_SIZE = 4;
@@ -394,15 +394,15 @@ const uint32_t ATTENTION_DECODER_WORKSPACE_NUM = 1;
const uint32_t ATTENTION_DECODER_INPUT_DECODER_INPUTS = 0;
const uint32_t ATTENTION_DECODER_INPUT_DECODER_INITIAL_HIDDEN = 1;

const int ATTENTION_DECODER_ALGO_NORMAL = 0;
const int ATTENTION_DECODER_SYMBOLS = 10000;
const int ATTENTION_DECODER_EMBEDDING_SIZE = 128;
const int ATTENTION_DECODER_ATTENTION_NUM_HIDDEN = 256;
const int ATTENTION_DECODER_DECODER_NUM_HIDDEN = 128;
const int ATTENTION_DECODER_DECODER_NUM_LAYERS = 2;
const int ATTENTION_DECODER_RNN_UNBIDIRECTIONAL = 0;
const int ATTENTION_DECODER_SEQLEN_VALUE = 57;
const int ATTENTION_DECODER_GRU = 3;
const int32_t ATTENTION_DECODER_ALGO_NORMAL = 0;
const int32_t ATTENTION_DECODER_SYMBOLS = 10000;
const int32_t ATTENTION_DECODER_EMBEDDING_SIZE = 128;
const int32_t ATTENTION_DECODER_ATTENTION_NUM_HIDDEN = 256;
const int32_t ATTENTION_DECODER_DECODER_NUM_HIDDEN = 128;
const int32_t ATTENTION_DECODER_DECODER_NUM_LAYERS = 2;
const int32_t ATTENTION_DECODER_RNN_UNBIDIRECTIONAL = 0;
const int32_t ATTENTION_DECODER_SEQLEN_VALUE = 57;
const int32_t ATTENTION_DECODER_GRU = 3;

// Logicaland
const int32_t LOGICAL_AND_INPUT_NUM = 2;


+ 12
- 16
inc/framework/common/op_types.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
#include <set>
#include <string>

#include "graph/types.h"

namespace ge {
class GE_FUNC_VISIBILITY OpTypeContainer {
public:
@@ -29,11 +31,12 @@ class GE_FUNC_VISIBILITY OpTypeContainer {
}
~OpTypeContainer() = default;

void Register(const std::string &op_type) { op_type_list_.insert(op_type); }
bool Register(const std::string &op_type) {
return op_type_list_.insert(op_type).second;
}

bool IsExisting(const std::string &op_type) {
auto iter_find = op_type_list_.find(op_type);
return iter_find != op_type_list_.end();
return op_type_list_.find(op_type) != op_type_list_.end();
}

protected:
@@ -42,21 +45,14 @@ class GE_FUNC_VISIBILITY OpTypeContainer {
private:
std::set<std::string> op_type_list_;
};

class GE_FUNC_VISIBILITY OpTypeRegistrar {
public:
explicit OpTypeRegistrar(const std::string &op_type) { OpTypeContainer::Instance()->Register(op_type); }
~OpTypeRegistrar() {}
};
} // namespace ge

#define REGISTER_OPTYPE_DECLARE(var_name, str_name) \
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *var_name;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char_t *var_name;

#define REGISTER_OPTYPE_DEFINE(var_name, str_name) \
const char *var_name = str_name; \
const OpTypeRegistrar g_##var_name##_reg(str_name);

#define IS_OPTYPE_EXISTING(str_name) (OpTypeContainer::Instance()->IsExisting(str_name))
} // namespace ge
const char_t *var_name = str_name; \
const bool g_##var_name##_reg = OpTypeContainer::Instance()->Register(str_name);

#define IS_OPTYPE_EXISTING(str_name) (ge::OpTypeContainer::Instance()->IsExisting(str_name))
#endif // INC_FRAMEWORK_COMMON_OP_TYPES_H_

+ 4
- 28
inc/framework/common/profiling/ge_profiling.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,39 +17,15 @@
#ifndef INC_FRAMEWORK_COMMON_GE_PROFILING_H_
#define INC_FRAMEWORK_COMMON_GE_PROFILING_H_

#include "ge/ge_api_error_codes.h"
#include "toolchain/prof_callback.h"
#include "external/ge/ge_api_error_codes.h"
#include "runtime/base.h"

const int MAX_DEV_NUM = 64;

enum ProfCommandHandleType {
kProfCommandhandleInit = 0,
kProfCommandhandleStart,
kProfCommandhandleStop,
kProfCommandhandleFinalize,
kProfCommandhandleModelSubscribe,
kProfCommandhandleModelUnsubscribe
};

struct ProfCommandHandleData {
uint64_t profSwitch;
uint32_t devNums; // length of device id list
uint32_t devIdList[MAX_DEV_NUM];
uint32_t modelId;
};

GE_FUNC_VISIBILITY ge::Status RegProfCtrlCallback(MsprofCtrlCallback func);
GE_FUNC_VISIBILITY ge::Status RegProfSetDeviceCallback(MsprofSetDeviceCallback func);
GE_FUNC_VISIBILITY ge::Status RegProfReporterCallback(MsprofReporterCallback func);
GE_FUNC_VISIBILITY ge::Status ProfCommandHandle(ProfCommandHandleType type, void *data, uint32_t len);

///
/// @brief Output the profiling data of single operator in Pytorch, and does not support multithreading
/// @return Status result
///
GE_FUNC_VISIBILITY ge::Status ProfSetStepInfo(uint64_t index_id, uint16_t tag_id, rtStream_t stream);
GE_FUNC_VISIBILITY ge::Status ProfSetStepInfo(const uint64_t index_id, const uint16_t tag_id, rtStream_t const stream);

GE_FUNC_VISIBILITY ge::Status ProfGetDeviceFormGraphId(uint32_t graph_id, uint32_t &device_id);
GE_FUNC_VISIBILITY ge::Status ProfGetDeviceFormGraphId(const uint32_t graph_id, uint32_t &device_id);

#endif // INC_FRAMEWORK_COMMON_GE_PROFILING_H_

+ 1
- 1
inc/framework/common/profiling/ge_runner_profiling.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.


+ 220
- 0
inc/framework/common/profiling_definitions.h View File

@@ -0,0 +1,220 @@
/**
* 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 AIR_CXX_PROFILING_DEFINITIONS_H
#define AIR_CXX_PROFILING_DEFINITIONS_H
#include <string>
#include <iostream>
#include <mutex>
#include <unordered_map>
#include "graph/profiler.h"
#include "external/ge/ge_api_types.h"
#include "toolchain/prof_callback.h"
namespace ge {
namespace profiling {
enum {
kAclCompileAndExecute,
kAclMatchOpModel,
kAclMatchStaticOpModel,
kAclMatchDynamicOpModel,
kAclExecuteAsync,
kAclLoadSingleOp,
kAclBuildOpModel,
kInferShape,
kTiling,
kUpdateShape,
kConstPrepare,
kInitHybridExecuteArgs,
kInitInferShapeContext,
kDestroyInferShapeContext,
kResetSubgraphExecutor,
kCommitInferShapeTask,
kDeviceToHost,
kPrepareTask,
kLaunchTask,
kCommitTilingTask,
kAtomic,
kKernelLaunchPrepare,
kRtKernelLaunch,
kRtEventCreateRecord,
kRtEventSync,
kRtEventDestroy,
kRtStreamSync,
kOpExecute,
kModelExecute,
kAllocMem,
kCopyH2D,
kPrepareNode,
kWaitForPrepareDone,
kPropgateOutputs,
kOnNodeDoneCallback,
kValidateInputTensor,
kAfterExecuted,
kRtEventSychronize,
kInferShapeWaitDependShape,
kInferShapeWaitInputTensor,
kInferShapeCallInferFunc,
kInferShapePropgate,
// v2 control node
kSelectBranch,
kExecuteSubGraph,
kInitSubGraphExecutor,
// fuzz compile
kSelectBin,
kFindCompileCache,
kAddCompileCache,
kFuzzCompileOp,
kCalcRuningParam,
kGenTask,
kRegisterBin,

// FFTS Plus
kFftsPlusPreThread,
kFftsPlusNodeThread,
kFftsPlusInferShape,
kOpFftsCalculateV2,
kInitThreadRunInfo,
kFftsPlusGraphSchedule,
kKnownGetAddrAndPrefCnt,
kKernelGetAddrAndPrefCnt,
kUpdateAddrAndPrefCnt,
kInitOpRunInfo,
kGetAutoThreadParam,
kAllocateOutputs,
kAllocateWorkspaces,
kInitTaskAddrs,
kInitThreadRunParam,
kUpdateTaskAndCache,
kFftsPlusTaskLaunch,

// Add new definitions here
kProfilingIndexEnd
};
constexpr uint64_t kInvalidHashId = 0UL;

class ProfilingContext {
public:
static bool IsDumpToStdEnabled();
static ProfilingContext &GetInstance();
ProfilingContext();
~ProfilingContext();

/*
* 还有一种思路是`IsEnabled`只判断profiler_是否为空指针,不再设置单独的enabled标记位,这样可以少一个标记位。
* 但是这么做就意味着,profiler_实例在未使能profiling时,必须是空指针状态。
* 为了性能考虑,profiling机制在编译和加载时,就会调用`RegisterString`,向profiler_注册字符串,后续执行时,只会使用注册好的index了。
* 因此存在一种场景:编译时并未使能profiling(因为编译时间很长,使能profiling也无法真实反应执行时的耗时状态),
* 因此编译时注册字符串的动作并没有生效。在执行时,动态的打开了profiling,这种场景下,执行时无法拿到注册后字符串
*/
bool IsEnabled() const noexcept {
return enabled_ && (profiler_ != nullptr);
}
void SetEnable() noexcept {
enabled_ = true;
}
void SetDisable() noexcept {
enabled_ = false;
}

void RecordCurrentThread(const int64_t element, const int64_t event, const EventType et,
const std::chrono::time_point<std::chrono::system_clock> time_point) {
if (IsEnabled()) {
profiler_->RecordCurrentThread(element, event, et, time_point);
}
}

void RecordCurrentThread(const int64_t element, const int64_t event, const EventType et) {
RecordCurrentThread(element, event, et, std::chrono::system_clock::now());
}

const Profiler *GetProfiler() const {
return profiler_.get();
}

void Dump(std::ostream &out_stream) const {
if (IsEnabled()) {
profiler_->Dump(out_stream);
} else {
out_stream << "Profiling not enable, skip to dump" << std::endl;
}
}

void DumpToStdOut() const {
Dump(std::cout);
}

void Reset() {
if (IsEnabled()) {
profiler_->Reset();
}
}

int64_t RegisterString(const std::string &str);
int64_t RegisterStringHash(const uint64_t hash_id, const std::string &str);
void UpdateElementHashId();
static Status QueryHashId(const std::string &src_str, uint64_t &hash_id);
size_t GetRegisterStringNum() const {
return strings_to_index_.size();
}

void Init();

private:
void UpdateHashByStr(const std::string &str, const uint64_t hash);

private:
bool inited_;
bool enabled_;
int64_t str_index_;
std::unordered_map<std::string, int64_t> strings_to_index_;
std::mutex strings_to_index_mutex_;
std::unique_ptr<Profiler> profiler_;
};

class ScopeProfiler {
public:
ScopeProfiler(const int64_t element, const int64_t event) : element_(element), event_(event) {
if (ProfilingContext::GetInstance().IsEnabled()) {
start_trace_ = std::chrono::system_clock::now();
}
}
~ScopeProfiler() {
if (ProfilingContext::GetInstance().IsEnabled()) {
ProfilingContext::GetInstance().RecordCurrentThread(element_, event_, EventType::kEventStart, start_trace_);
ProfilingContext::GetInstance().RecordCurrentThread(element_, event_, EventType::kEventEnd);
}
}
void SetElement(const int64_t element) {
element_ = element;
}

private:
std::chrono::time_point<std::chrono::system_clock> start_trace_;
int64_t element_;
int64_t event_;
};
} // namespace profiling
} // namespace ge
#define PROFILING_START(element, event) \
ge::profiling::ProfilingContext::GetInstance().RecordCurrentThread((element), (event), \
ge::profiling::EventType::kEventStart)
#define PROFILING_END(element, event) \
ge::profiling::ProfilingContext::GetInstance().RecordCurrentThread((element), (event), \
ge::profiling::EventType::kEventEnd)
#define PROFILING_SCOPE(element, event) ge::profiling::ScopeProfiler profiler((element), (event))
#define PROFILING_SCOPE_CONST(element, event) const ge::profiling::ScopeProfiler profiler((element), (event))
#define PROFILING_SCOPE_ELEMENT(element) profiler.SetElement((element))
#endif // AIR_CXX_PROFILING_DEFINITIONS_H

+ 38
- 0
inc/framework/common/runtime_tensor_desc.h View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
*
* 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_FRAMEWORK_COMMON_RUNTIME_TENSOR_DESC_H_
#define INC_FRAMEWORK_COMMON_RUNTIME_TENSOR_DESC_H_

#include <cstdint>

namespace ge {
constexpr int64_t kMaxDimSize = 32;

#pragma pack(push, 1)
struct RuntimeTensorDesc {
uint64_t data_addr;
int64_t data_offset_size;
int64_t dtype;
int64_t shape[kMaxDimSize + 1]; // shape:Dim_Num|DIM0|DIM1|...|DIM31
int64_t original_shape[kMaxDimSize + 1]; // original_shape:Dim_Num|DIM0|DIM1|...|DIM31
int64_t format;
int64_t sub_format;
uint8_t reserved[456]; // padding to 1024 bytes
};
#pragma pack(pop)
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_RUNTIME_TENSOR_DESC_H_

+ 10
- 6
inc/framework/common/scope_guard.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,14 +18,15 @@
#define INC_FRAMEWORK_COMMON_SCOPE_GUARD_H_

#include <functional>
#include <iostream>

/// Usage:
/// Acquire Resource 1
/// MAKE_GUARD([&] { Release Resource 1 })
/// Acquire Resource 2
// MAKE_GUARD([&] { Release Resource 2 })
#define GE_MAKE_GUARD(var, callback) ScopeGuard make_guard_##var(callback)
#define GE_MAKE_GUARD(var, callback) const ::ge::ScopeGuard const_guard_##var(callback)

#define GE_DISMISSABLE_GUARD(var, callback) ::ge::ScopeGuard make_guard_##var(callback)
#define GE_DISMISS_GUARD(var) make_guard_##var.Dismiss()

namespace ge {
@@ -42,13 +43,16 @@ class GE_FUNC_VISIBILITY ScopeGuard {
if (on_exit_scope_ != nullptr) {
try {
on_exit_scope_();
} catch (std::bad_function_call &e) { }
catch (...) { }
} catch (std::bad_function_call &) {
} catch (...) {
}
}
}
}

void Dismiss() { dismissed_ = true; }
void Dismiss() {
dismissed_ = true;
}

private:
std::function<void()> on_exit_scope_;


+ 30
- 24
inc/framework/common/string_util.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,24 +39,27 @@
#include <sstream>
#include <string>
#include <vector>
#include "graph/types.h"

namespace ge {
class GE_FUNC_VISIBILITY StringUtils {
public:
static std::string &Ltrim(std::string &s) {
#if __cplusplus >= 201103L
(void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); }));
(void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](const int32_t c) { return std::isspace(c) == 0; }));
#else
(void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
(void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int32_t, int32_t>(std::isspace))));
#endif
return s;
}
// lint -esym(551,*)
static std::string &Rtrim(std::string &s) { /*lint !e618*/
static std::string &Rtrim(std::string &s) { /*lint !e618*/
#if __cplusplus >= 201103L
(void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); }));
(void)s.erase(std::find_if(s.rbegin(), s.rend(), [](const int32_t c) { return std::isspace(c) == 0; }).base(),
s.end());
#else
(void)s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
(void)s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int32_t, int32_t>(std::isspace))).base(),
s.end());
#endif
return s;
}
@@ -67,7 +70,9 @@ class GE_FUNC_VISIBILITY StringUtils {
/// @param [in] string to be trimmed
/// @return string after trim
///
static std::string &Trim(std::string &s) { return Ltrim(Rtrim(s)); }
static std::string &Trim(std::string &s) {
return Ltrim(Rtrim(s));
}

///
/// @ingroup domi_common
@@ -76,8 +81,8 @@ class GE_FUNC_VISIBILITY StringUtils {
/// @param [in] delim separator
/// @return string array after segmentation
///
static std::vector<std::string> Split(const std::string &str, char delim) {
std::vector<std::string> elems;
static std::vector<std::string, std::allocator<std::string>> Split(const std::string &str, const char_t delim) {
std::vector<std::string, std::allocator<std::string>> elems;

if (str.empty()) {
elems.emplace_back("");
@@ -91,8 +96,8 @@ class GE_FUNC_VISIBILITY StringUtils {
elems.push_back(item);
}

auto str_size = str.size();
if (str_size > 0 && str[str_size - 1] == delim) {
const auto str_size = str.size();
if ((str_size > 0U) && (str[str_size - 1U] == delim)) {
elems.emplace_back("");
}

@@ -104,13 +109,13 @@ class GE_FUNC_VISIBILITY StringUtils {
/// @param [in] s path name
/// @return file name
///
static std::string GetFileName(std::string &s) {
static std::string GetFileName(const std::string &s) {
if (s.empty()) {
return "";
}
std::vector<std::string> files = StringUtils::Split(s, '/');
const std::vector<std::string> files = StringUtils::Split(s, '/');

return files.empty() ? "" : files[files.size() - 1];
return files.empty() ? "" : files[files.size() - 1U];
}
///
/// @ingroup domi_common
@@ -122,12 +127,13 @@ class GE_FUNC_VISIBILITY StringUtils {
/// @return string after replacement
///
static std::string ReplaceAll(std::string str, const std::string &old_value, const std::string &new_value) {
std::string::size_type cur_pos = 0;
std::string::size_type old_length = old_value.length();
std::string::size_type new_length = new_value.length();
std::string::size_type cur_pos = 0U;
const std::string::size_type old_length = old_value.length();
const std::string::size_type new_length = new_value.length();
// cycle replace
for (; cur_pos != std::string::npos; cur_pos += new_length) {
if ((cur_pos = str.find(old_value, cur_pos)) != std::string::npos) {
cur_pos = str.find(old_value, cur_pos);
if (cur_pos != std::string::npos) {
(void)str.replace(cur_pos, old_length, new_value);
} else {
break;
@@ -145,7 +151,7 @@ class GE_FUNC_VISIBILITY StringUtils {
/// @return if the value is a prefix, true is returned. Otherwise, false is returned
///
static bool StartWith(const std::string &str, const std::string str_x) {
return ((str.size() >= str_x.size()) && (str.compare(0, str_x.size(), str_x) == 0));
return ((str.size() >= str_x.size()) && (str.compare(0U, str_x.size(), str_x) == 0));
}

///
@@ -156,14 +162,14 @@ class GE_FUNC_VISIBILITY StringUtils {
/// @param [in] ... format Filling Content
/// @return formatted string
///
static std::string FormatString(const char *format, ...) {
const uint32_t MAX_BUFFER_LEN = 1024; // the stack memory plint check result must be less than 1024
static std::string FormatString(const char_t *const format, ...) {
const uint32_t MAX_BUFFER_LEN = 1024U; // the stack memory plint check result must be less than 1024
va_list args;
va_start(args, format);
char buffer[MAX_BUFFER_LEN] = {0};
int32_t ret = vsnprintf_s(buffer, MAX_BUFFER_LEN, MAX_BUFFER_LEN - 1, format, args);
char_t buffer[MAX_BUFFER_LEN] = {};
const int32_t ret = vsnprintf_s(&buffer[0], MAX_BUFFER_LEN, MAX_BUFFER_LEN - 1U, format, args);
va_end(args);
return ret > 0 ? buffer : "";
return (ret > 0) ? buffer : "";
}
};
} // namespace ge


+ 31
- 10
inc/framework/common/taskdown_common.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,9 +21,9 @@

namespace ge {

const int CC_FUSION_OP_MAX = 32;
const int32_t CC_FUSION_OP_MAX = 32;

typedef enum tagCcStatus {
enum class ccStatus_t {
CC_STATUS_SUCCESS = 0, /**< succ */
CC_STATUS_NOT_INITIALIZED = 1, /**< not init */
CC_STATUS_ALLOC_FAILED = 2, /**< alloc mem failed */
@@ -33,10 +33,10 @@ typedef enum tagCcStatus {
CC_STATUS_RUNTIME_ERROR = 6, /**< runtime error */
CC_STATUS_NOT_SUPPORTED = 7, /**< unsupport error */
CC_STATUS_INVALID_VALUE = 7, /**< invalid value error for blas*/
CC_STATUS_RESERVED /**< just for check */
} ccStatus_t;
CC_STATUS_RESERVED = 8, /**< just for check */
};

typedef enum tagccKernelType {
enum class ccKernelType {
CCE_AI_CORE = 0, /* cce aicore */
CCE_AI_CPU = 1, /* cce aicpu */
TE = 2, /* te operator*/
@@ -47,9 +47,9 @@ typedef enum tagccKernelType {
CUST_AI_CPU = 7, /* custom aicpu*/
HOST_CPU = 8, /* host cpu */
INVALID = 10000 /* unknown kernel type */
} ccKernelType;
};

typedef struct tagOpContext {
using ccOpContext = struct tagOpContext {
ccKernelType kernelType;
uint32_t opId;
uint32_t kernelFuncId;
@@ -66,7 +66,28 @@ typedef struct tagOpContext {
uint64_t genVariableBaseAddr;
uint64_t genVariableBaseSize;
uint64_t l2ctrlSize;
} ccOpContext;
} // namespace ge
};

enum class tagOpTensorFormat { OP_TENSOR_FORMAT_NC1HWC0 = 0, OP_TENSOR_FORMAT_ND, OP_TENSOR_FORMAT_RESERVED };

enum class tagOpDataType {
OP_DATA_FLOAT = 0, /**< float type */
OP_DATA_HALF, /**< fp16 type */
OP_DATA_INT8, /**< int8 type */
OP_DATA_INT32, /**< int32 type */
OP_DATA_UINT8, /**< uint8 type */
OP_DATA_HALF_UINT16_PROPOSAL, /**< mixed type for proposal */
OP_DATA_RESERVED
};

// AICPU Tensor
using ccAICPUTensor = struct tagOpTensor {
// real dim info
tagOpTensorFormat format;
tagOpDataType data_type;
int32_t dim_cnt;
int32_t mm;
int32_t dim[8];
};
} // namespace ge
#endif // INC_FRAMEWORK_COMMON_TASKDOWN_COMMON_H_

+ 52
- 472
inc/framework/common/types.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,28 +17,16 @@
#ifndef INC_FRAMEWORK_COMMON_TYPES_H_
#define INC_FRAMEWORK_COMMON_TYPES_H_

#include <limits.h>
#include <stdint.h>
#include <algorithm>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "framework/common/fmk_error_codes.h"
#include "framework/common/fmk_types.h"
#include "framework/common/op_types.h"
#include "register/register_types.h"

#if !defined(__ANDROID__) && !defined(ANDROID)
#define DOMI_DYNAMIC_CAST static_cast
#define DOMI_DYNAMIC_POINTER_CAST std::static_pointer_cast
#else
#define DOMI_DYNAMIC_CAST static_cast
#define DOMI_DYNAMIC_POINTER_CAST std::static_pointer_cast
#endif

namespace ge {
// dump
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string DUMP_MODEL;
@@ -51,54 +39,20 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string OP_DEB
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string OP_DEBUG_ATOMIC;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string OP_DEBUG_ALL;

// Supported public properties name
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string PROP_OME_START_TIME; // Start time
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string PROP_OME_DUMP_PATH; // Dump path
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string PROP_OME_LOG_PATH; // Log path

// Profile-related constants
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t CCE_PROFILE_ON;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t CCE_PROFILE_OFF;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string OME_PROFILE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string CCE_PROFILE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string RTS_PROFILE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string PROFILER_JOBCTX;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string PROFILER_TARGET_PATH;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string RTS_PROFILE_PATH;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string PROFILE_STOP_KEY;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string PROFILE_STOP_VALUE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::map<std::string, std::string> PROFILE_COMPONENT_MAP;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string PROFILE_CONFIG;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string PROFILE_MODEL_ID;

FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string MODEL_ATTR_TASKS;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string MODEL_ATTR_TASK_GEN_BASE_ADDR;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string MODEL_ATTR_TASK_GEN_HOST_BASE_ADDR;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string MODEL_ATTR_HOST_MEMORY_SIZE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string MODEL_ATTR_TASK_GEN_WEIGHT_ADDR;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string MODEL_ATTR_FUSION_MODEL_DEF;

FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int MODEL_MAX_SIZE; // Max size of 2 GB minus 1 byte.
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint64_t FILE_HEADER_MAX_SIZE; // Max size of 3 GB.

#if !defined(__ANDROID__) && !defined(ANDROID)
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint64_t ALLOC_MEMORY_MAX_SIZE; // Max size of 8 GB.
#else
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint64_t ALLOC_MEMORY_MAX_SIZE; // Max size of 512M.
#endif

template <typename K, typename V>
static std::pair<V, K> flip_pair(const std::pair<K, V> &p) {
return std::pair<V, K>(p.second, p.first);
}

template <typename K, typename V>
static std::map<V, K> flip_map(std::map<K, V> src) {
std::map<V, K> dst;
std::transform(src.begin(), src.end(), std::inserter(dst, dst.begin()), flip_pair<K, V>);
return dst;
}

REGISTER_OPTYPE_DECLARE(DATA, "Data");
REGISTER_OPTYPE_DECLARE(AIPPDATA, "AippData");
REGISTER_OPTYPE_DECLARE(QUEUE_DATA, "QueueData");
REGISTER_OPTYPE_DECLARE(CONVOLUTION, "Convolution");
REGISTER_OPTYPE_DECLARE(CORRELATION, "Correlation");
REGISTER_OPTYPE_DECLARE(CORRELATIONV2, "Correlation_V2");
@@ -134,6 +88,7 @@ REGISTER_OPTYPE_DECLARE(DROPOUTDOMASKV3, "DropOutDoMaskV3");
REGISTER_OPTYPE_DECLARE(DROPOUTDOMASKV3D, "DropOutDoMaskV3D");
REGISTER_OPTYPE_DECLARE(SOFTMAXV2WITHDROPOUTDOMASKV3D, "SoftmaxV2WithDropOutDoMaskV3D");
REGISTER_OPTYPE_DECLARE(DROPOUTGENMASK, "DropOutGenMask");
REGISTER_OPTYPE_DECLARE(AXPYWITHSOFTMAXANDDROPOUTDOMASK, "AxpyWithSoftmaxAndDropOutDoMask");
REGISTER_OPTYPE_DECLARE(CONCAT, "Concat");
REGISTER_OPTYPE_DECLARE(ROIPOOLING, "ROIPooling");
REGISTER_OPTYPE_DECLARE(PROPOSAL, "Proposal");
@@ -167,6 +122,10 @@ REGISTER_OPTYPE_DECLARE(SLICED, "SliceD");
REGISTER_OPTYPE_DECLARE(FLOORDIV, "FloorDiv");
REGISTER_OPTYPE_DECLARE(SQUEEZE, "Squeeze");
REGISTER_OPTYPE_DECLARE(UNSQUEEZE, "Unsqueeze");
REGISTER_OPTYPE_DECLARE(SQUEEZEV2, "SqueezeV2");
REGISTER_OPTYPE_DECLARE(UNSQUEEZEV2, "UnsqueezeV2");
REGISTER_OPTYPE_DECLARE(SQUEEZEV3, "SqueezeV3");
REGISTER_OPTYPE_DECLARE(UNSQUEEZEV3, "UnsqueezeV3");
REGISTER_OPTYPE_DECLARE(STRIDEDSLICE, "StridedSlice");
REGISTER_OPTYPE_DECLARE(RANGE, "Range");
REGISTER_OPTYPE_DECLARE(RPNPROPOSALS, "GenerateRpnProposals");
@@ -203,6 +162,7 @@ REGISTER_OPTYPE_DECLARE(_IF, "_If");
REGISTER_OPTYPE_DECLARE(STATELESSIF, "StatelessIf");
REGISTER_OPTYPE_DECLARE(IF, "If");
REGISTER_OPTYPE_DECLARE(CASE, "Case");
REGISTER_OPTYPE_DECLARE(STATELESSCASE, "StatelessCase");
REGISTER_OPTYPE_DECLARE(_WHILE, "_While");
REGISTER_OPTYPE_DECLARE(WHILE, "While");
REGISTER_OPTYPE_DECLARE(STATELESSWHILE, "StatelessWhile");
@@ -339,10 +299,15 @@ REGISTER_OPTYPE_DECLARE(PLACEHOLDER, "PlaceHolder");
REGISTER_OPTYPE_DECLARE(END, "End");
REGISTER_OPTYPE_DECLARE(BASICLSTMCELL, "BasicLSTMCell");
REGISTER_OPTYPE_DECLARE(GETNEXT, "GetNext");
REGISTER_OPTYPE_DECLARE(ITERATOR, "Iterator");
REGISTER_OPTYPE_DECLARE(ITERATORV2, "IteratorV2");
REGISTER_OPTYPE_DECLARE(INITDATA, "InitData");
REGISTER_OPTYPE_DECLARE(TRANSSHAPE, "TransShape")
REGISTER_OPTYPE_DECLARE(REFIDENTITY, "RefIdentity");
REGISTER_OPTYPE_DECLARE(BITCAST, "Bitcast");
REGISTER_OPTYPE_DECLARE(GATHERSHAPES, "GatherShapes");
REGISTER_OPTYPE_DECLARE(FLATTENV2, "FlattenV2");
REGISTER_OPTYPE_DECLARE(FILECONSTANT, "FileConstant");

// ANN dedicated operator
REGISTER_OPTYPE_DECLARE(ANN_MEAN, "AnnMean");
@@ -460,6 +425,7 @@ REGISTER_OPTYPE_DECLARE(MODELEXIT, "ModelExit");
REGISTER_OPTYPE_DECLARE(SEND, "Send");
REGISTER_OPTYPE_DECLARE(RECV, "Recv");
REGISTER_OPTYPE_DECLARE(ENDOFSEQUENCE, "EndOfSequence");
REGISTER_OPTYPE_DECLARE(STARTOFSEQUENCE, "StartOfSequence");

REGISTER_OPTYPE_DECLARE(LABELSET, "LabelSet");
REGISTER_OPTYPE_DECLARE(LABELGOTO, "LabelGoto");
@@ -483,8 +449,6 @@ REGISTER_OPTYPE_DECLARE(ELU_GRAD, "EluGrad");
REGISTER_OPTYPE_DECLARE(ADD_V2, "AddV2");
REGISTER_OPTYPE_DECLARE(DATAFORMATDIMMAP, "DataFormatDimMap");
REGISTER_OPTYPE_DECLARE(DATAFORMATVECPERMUTE, "DataFormatVecPermute");
REGISTER_OPTYPE_DECLARE(BESSELI0e, "BesselI0e");
REGISTER_OPTYPE_DECLARE(BESSELI1e, "BesselI1e");
REGISTER_OPTYPE_DECLARE(DEQUANTIZE, "Dequantize");
REGISTER_OPTYPE_DECLARE(APPLYADADELTA, "ApplyAdadelta");
REGISTER_OPTYPE_DECLARE(APPLYADAGRAD, "ApplyAdagrad");
@@ -538,29 +502,11 @@ REGISTER_OPTYPE_DECLARE(GETDYNAMICDIMS, "GetDynamicDims");
// profiling training trace node
REGISTER_OPTYPE_DECLARE(PROFILINGTRAININGTRACE, "ProfilingTrainingTrace");

enum InputMode { INPUT = 0, CONST_INPUT };

// Definition of the processing status enum of the process module
enum ModelProcessState {
INIT_STATE = 0, // init status
WAIT_EVENT_STATE, // Wait for the event status
IND_RSLT_STATE, // The model execution result is being output to the high level
STOPPED_STATE, // Model execution completed. The model enters this state after Model Manager::Stop
RESERVED_STATE, // reserved
};

// Indicates the enun definition of the execution mode of the access module
enum SysMode {
INFERENCE = 0, // Normal, that is, Inference mode
DEBUG, // Debug mode
TIME, // Model execution time mode, including the execution time of each OP
STOP, // STOP mode
RESET, // RESET mode
PERFORMANCE, // Impact of enabling the performance model: 1. The input data of the model is considered ready and does
// not need to be converted
ANDROID_DEBUG, // Exports Android platform computing data
RESERVED, // reserved
};
// Stack series
REGISTER_OPTYPE_DECLARE(STACK, "Stack");
REGISTER_OPTYPE_DECLARE(STACKPUSH, "StackPush");
REGISTER_OPTYPE_DECLARE(STACKPOP, "StackPop");
REGISTER_OPTYPE_DECLARE(STACKCLOSE, "StackClose");

// @brief encryption type of the model file
enum ModelEncryptType {
@@ -599,50 +545,22 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t MODEL_FIL
///
/// @brief model name length
///
static constexpr uint32_t MODEL_NAME_LENGTH = 32;
constexpr uint32_t MODEL_NAME_LENGTH = 32U;

///
/// @brief length of user-defined information
///
static constexpr uint32_t USER_DEFINE_INFO_LENGTH = 32;
constexpr uint32_t USER_DEFINE_INFO_LENGTH = 32U;

///
/// @brief length of the model file signature
///
static constexpr uint32_t MODEL_FILE_CHECKSUM_LENGTH = 64;
constexpr uint32_t MODEL_FILE_CHECKSUM_LENGTH = 64U;

///
/// @brief length of the reserved field in the model file header
///
static constexpr uint32_t MODEL_FILE_RESERVED_LENGTH = 75;

///
/// @ingroup domi_omg
/// @brief INPUT node type
///
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string INPUT_TYPE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string DUMMY_DATA;

///
/// @ingroup domi_omg
/// @brief AIPP flag, indicating the aipp conv operator
///
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string AIPP_CONV_FLAG;

///
/// @ingroup domi_omg
/// @brief AIPP flag, indicating the aipp data operator
///
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string AIPP_DATA_FLAG;

// flag of the Data operator, indicating that the input will be input to the dynamic AIPP operator
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string INPUT_TO_DYNAMIC_AIPP;

// records the W dimension of the model input corresponding to the dynamic AIPP
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string AIPP_RELATED_DATA_DIM_W;

// H dimension of the model input corresponding to the dynamic AIPP
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string AIPP_RELATED_DATA_DIM_H;
constexpr uint32_t MODEL_FILE_RESERVED_LENGTH = 75U;

// DATA node type
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string DATA_TYPE;
@@ -655,10 +573,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string FRAMEW

// DATA node type
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string ANN_DATA_TYPE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string ANN_NETOUTPUT_TYPE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string ANN_DEPTHCONV_TYPE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string ANN_CONV_TYPE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string ANN_FC_TYPE;
// convolution node type
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_NAME_NET_OUTPUT;

@@ -667,161 +581,31 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_N
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_NAME_OP_DEBUG;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string OP_TYPE_OP_DEBUG;

// convolution node type
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string OP_TYPE_CONVOLUTION;
// adds a convolutional node name for the hard AIPP
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string AIPP_CONV_OP_NAME;
// delimiter of operator configuration items
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string OP_CONF_DELIMITER;

// op attr name
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string ATTR_NAME_VALUE1;

// op attr name, used to 6d_2_4d C channel
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string ATTR_NAME_INPUT_CVALUE;

// op attr name
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string ATTR_NAME_VALUE1;

// alpha default value
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const float ALPHA_DEFAULT_VALUE;

// beta default value
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const float BETA_DEFAULT_VALUE;

// coef default value
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const float COEF_DEFAULT_VALUE;

// coef value of Relu6
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const float RELU6_COEF;

// stride default value
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t STRIDE_DEFAULT_VALUE;

// pad default value
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t PAD_DEFAULT_VALUE;

// dilation default value
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int DILATION_DEFAULT_VALUE;

// kernel default value
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t KERNEL_DEFAULT_VALUE;

// default conv Group Size
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t DEFAULT_CONV_GROUP;

// default deconv adj
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t DEFAULT_DECONV_ADJ;

// indicate num 1
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t NUM_ONE;

// dim default size value
static const int32_t DIM_DEFAULT_SIZE = 4;

// the shape of c must be the mutiply of 16 for depthwise
static const uint32_t DEPTHWISE_DIM_C_BASE_NUM = 16;

// C1HWNCoC0 dim size
static const int32_t DIM_C1HWNCoC0_SIZE = 6;
// C1HWNCoC0 C0 value
static const int C1HWCOC_C0_VALUE = 16;
// spatial default dim size
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int32_t SPATIAL_DIM_DEFAULT_SIZE;
constexpr int32_t DIM_DEFAULT_SIZE = 4;

// dim extension default value
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int32_t DIM_DEFAULT_VALUE;

// the first item in the weight list of opdef is filter
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int32_t WEIGHT_FILTER_INDEX;

// the second item in the weight list of opdef is bias.
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int32_t WEIGHT_BIAS_INDEX;

FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int32_t TENSOR_ND_SUPPORT_SIZE;

// default NCHW index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t NCHW_DIM_N;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t NCHW_DIM_C;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t NCHW_DIM_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t NCHW_DIM_W;

// default C1HWNCoC0 index
static const uint32_t C1HWNCoC0_DIM_C1 = 0;
static const uint32_t C1HWNCoC0_DIM_H = 1;
static const uint32_t C1HWNCoC0_DIM_W = 2;
static const uint32_t C1HWNCoC0_DIM_N = 3;
static const uint32_t C1HWNCoC0_DIM_Co = 4;
static const uint32_t C1HWNCoC0_DIM_C0 = 5;

// default KCHW index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t KCHW_DIM_K;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t KCHW_DIM_C;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t KCHW_DIM_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t KCHW_DIM_W;

// default HWCK index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t HWCK_DIM_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t HWCK_DIM_W;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t HWCK_DIM_C;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t HWCK_DIM_K;

// default NHWC index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t NHWC_DIM_N;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t NHWC_DIM_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t NHWC_DIM_W;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t NHWC_DIM_C;

// default CHWN index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t CHWN_DIM_N;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t CHWN_DIM_C;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t CHWN_DIM_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t CHWN_DIM_W;

// default CHW index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t CHW_DIM_C;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t CHW_DIM_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t CHW_DIM_W;

// default HWC index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t HWC_DIM_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t HWC_DIM_W;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t HWC_DIM_C;
// default Pad index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t PAD_H_HEAD;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t PAD_H_TAIL;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t PAD_W_HEAD;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t PAD_W_TAIL;

// default window index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t WINDOW_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t WINDOW_W;

// default stride index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t STRIDE_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t STRIDE_W;

// default dilation index
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t DILATION_H;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t DILATION_W;

// the num of XRBG channel
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t XRGB_CHN_NUM;

// default tensor format
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int DEFAULT_FORMAT;

// default global pooling
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const bool DEFAULT_GLOBAL_POOLING;

FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t MODEL_VERSION; // model version 1.0

// Number of inputs of the Eltwise operator
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int ELTWISE_MIN_INPUT_SIZE;

// flowctrl
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_NAME_STREAM_SWITCH;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_NAME_STREAM_ACTIVE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_NAME_FLOWCTRL_LOOP_PER_ITER;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_NAME_FLOWCTRL_LOOP_COND;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_NAME_FLOWCTRL_LOOP_INCREMENT;
@@ -833,41 +617,36 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t TRUE_STRE
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t STREAM_SWITCH_INPUT_NUM;

FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_NAME_GLOBAL_STEP;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const std::string NODE_NAME_GLOBAL_STEP_ASSIGNADD;

static const int PLATFORM_VERSION_LEN = 20;
constexpr uint32_t PLATFORM_VERSION_LEN = 20U;

// Definition of the file header of the model file
struct ModelFileHeader {
uint32_t magic = MODEL_FILE_MAGIC_NUM; // magic number of DOMI
uint32_t headsize = MODEL_FILE_HEAD_LEN; // length of the model header. The value is fixed at 256
uint32_t version = MODEL_VERSION; // version 1.0
uint8_t checksum[MODEL_FILE_CHECKSUM_LENGTH] = {0}; // signature
uint32_t length = 0; // Ciphertext length. In the non-encryption model, the length is the plaintext length.
uint8_t is_encrypt = ModelEncryptType::UNENCRYPTED; // whether encrypted 0:not encrypt, 1:encrypt
uint8_t is_checksum = ModelCheckType::CHECK; // whether to check the checksum
uint8_t modeltype = 0; // 0:IR model 1:standard model 2: OM Tiny model
uint8_t genmode = 0; // 0:offline generate 1:online generate
uint8_t name[MODEL_NAME_LENGTH] = {0}; // Model name, which contains 32 characters
uint32_t ops = 0; // Computing power (Kops)
uint8_t userdefineinfo[USER_DEFINE_INFO_LENGTH] = {0}; // User-defined information. The value contains 32 characters
uint32_t om_ir_version = 0;
uint32_t model_num = 0;
uint8_t platform_version[PLATFORM_VERSION_LEN] = {0};
uint8_t platform_type = {0};
uint8_t reserved[MODEL_FILE_RESERVED_LENGTH] = {0}; // Reserved field 75
uint32_t magic = MODEL_FILE_MAGIC_NUM; // magic number of DOMI
uint32_t headsize = MODEL_FILE_HEAD_LEN; // length of the model header. The value is fixed at 256
uint32_t version = MODEL_VERSION; // version 1.0
uint8_t checksum[MODEL_FILE_CHECKSUM_LENGTH] = {0U}; // signature
uint32_t length = 0U; // Ciphertext length. In the non-encryption model, the length is the plaintext length.
// whether encrypted 0:not encrypt, 1:encrypt
uint8_t is_encrypt = static_cast<uint8_t>(ModelEncryptType::UNENCRYPTED);
uint8_t is_checksum = static_cast<uint8_t>(ModelCheckType::CHECK); // whether to check the checksum
uint8_t modeltype = 0U; // 0:IR model 1:standard model 2: OM Tiny model
uint8_t genmode = 0U; // 0:offline generate 1:online generate
uint8_t name[MODEL_NAME_LENGTH] = {0U}; // Model name, which contains 32 characters
uint32_t ops = 0U; // Computing power (Kops)
uint8_t userdefineinfo[USER_DEFINE_INFO_LENGTH] = {0U}; // User-defined information. The value contains 32 characters
uint32_t om_ir_version = 0U;
uint32_t model_num = 0U;
uint8_t platform_version[PLATFORM_VERSION_LEN] = {0U};
uint8_t platform_type = {0U};
uint8_t reserved[MODEL_FILE_RESERVED_LENGTH] = {0U}; // Reserved field 75
};

static constexpr uint8_t TARGET_TYPE_LTTE_8BIT = 0;
static constexpr uint8_t TARGET_TYPE_MINI_8BIT = 1;
static constexpr uint8_t TARGET_TYPE_TINY_8BIT = 2;

static constexpr int32_t PARTITION_TYPE_MODEL_DEF = 0;
static constexpr int32_t PARTITION_TYPE_WEIGHTS = 1;
static constexpr int32_t PARTITION_TYPE_TASK_INFO = 2;
constexpr uint8_t TARGET_TYPE_LTTE_8BIT = 0U;
constexpr uint8_t TARGET_TYPE_MINI_8BIT = 1U;

// number of partitions in the current model
static constexpr uint32_t PARTITION_SIZE = 5;
constexpr uint32_t PARTITION_SIZE = 5U;

enum ModelPartitionType { MODEL_DEF = 0, WEIGHTS_DATA, TASK_INFO, TBE_KERNELS, CUST_AICPU_KERNELS };

@@ -882,24 +661,9 @@ struct ModelPartitionTable {
ModelPartitionMemInfo partition[0];
};

#define SIZE_OF_MODEL_PARTITION_TABLE(table) (sizeof(ModelPartitionTable) + sizeof(ModelPartitionMemInfo) * (table).num)

static constexpr int32_t PTHREAD_CREAT_SUCCESS = 0; // pthread_creat success

// Filter format
typedef enum tagDomiFilterFormat {
DOMI_FILTER_KCHW, // KCHW
DOMI_FILTER_HWCK, // HWCK
DOMI_FILTER_RESERVED
} domiFilterFormat_t;

// Const data trans type
typedef enum tagDomiConstDataTransType {
DOMI_CONST_DATA_NOT_CHANGE = 0, // No action is required
DOMI_CONST_DATA_TRANS_MATMUL, // The const input to MatMul and needs to be transposed
DOMI_CONST_DATA_RESERVED
} domiConstDataTransType_t;

inline uint64_t SizeOfModelPartitionTable(const ModelPartitionTable &table) {
return sizeof(ModelPartitionTable) + (sizeof(ModelPartitionMemInfo) * static_cast<uint64_t>(table.num));
}
// mode of activation
typedef enum tagDomiActivationMode {
DOMI_ACTIVATION_SIGMOID = 0, // sigmoid
@@ -919,190 +683,6 @@ typedef enum tagDomiActivationMode {
DOMI_ACTIVATION_RESERVED
} domiActivationMode_t;

// mode of batchnorm
typedef enum tagDomiBatchNormMode {
DOMI_BATCHNORM_PER_ACTIVATION = 0, // bnScale, bnBias tensor dims are 1xCxHxW
DOMI_BATCHNORM_SPATIAL, // bnScale, bnBias tensor dims are 1xCx1x1
DOMI_BATCHNORM_RESERVED
} domiBatchNormMode_t;

// eltwise mode
typedef enum tagDomiEltwiseMode {
DOMI_ELTWISE_PROD = 0, // prod
DOMI_ELTWISE_SUM, // sum
DOMI_ELTWISE_MAX, // max
DOMI_ELTWISE_RESERVED
} domiEltwiseMode_t;

// mode of padding
typedef enum tagDomiPaddingMode {
DOMI_PADDING_CEIL = 0, // Default padding mode
DOMI_PADDING_DIRECTASSIGN, // Default padding mode: NOTSET
DOMI_PADDING_VALID, // VALID padding mode
DOMI_PADDING_SAME, // Padding values of 0 are always used
DOMI_PADDING_CEIL_NEW, // Padding values of 0 are always used
DOMI_PADDING_VALID_NEW, // Padding values of 0 are always used
DOMI_PADDING_SAME_NEW, // Padding values of 0 are always used
DOMI_PADDING_RESERVED
} domiPaddingMode_t;

// algorithm of convolution forward
typedef enum tagDomiConvolutionFwdAlgo {
DOMI_CONVOLUTION_FWD_ALGO_GEMM = 0, // matrix gemm algo
DOMI_CONVOLUTION_FWD_ALGO_WINOGRAD, // Winograd Transform algo
DOMI_CONVOLUTION_FWD_ALGO_GEMM_ACCU_FLOAT32, // accumulate in L0c with FP32
DOMI_CONVOLUTION_FWD_ALGO_RESERVED
} domiConvolutionFwdAlgo_t;

typedef enum tagDomiFullConnectFwdAlgo {
DOMI_FULLCONNECT_FWD_ALGO_HALF = 0, // accumulate in L0c with FP16
DOMI_FULLCONNECT_FWD_ALGO_FLOAT32 // accumulate in L0c with FP32
} domiFullConnectFwdAlgo_t;

typedef enum tagDomiPooingFwdAlgo {
DOMI_POOLING_FWD_ALGO_HALF = 0, // accumulate in L0c with FP16
DOMI_POOLING_FWD_ALGO_FLOAT32 // accumulate in L0c with FP32
} domiPooingFwdAlgo_t;

// mode of convolution
typedef enum tagDomiConvolutionMode {
DOMI_CONV_CONVOLUTION = 0, // math convolution
DOMI_CONV_CROSS_CORRELATION, // cross-correlation convolution
DOMI_CONV_DECONVOLUTION, // deconvolution, also named transposed convolution
DOMI_CONV_MODE_DEPTHWISE, // depthwise convolution
DOMI_CONV_MODE_RESERVED
} domiConvolutionMode_t;

// softmax mode
typedef enum tagDomiSoftmaxMode {
DOMI_SOFTMAX_MODE_INSTANCE = 0, // compute the softmax over all C, H, W for each N
DOMI_SOFTMAX_MODE_CHANNEL, // compute the softmax over all C for each H, W, N
DOMI_SOFTMAX_MODE_HEIGHT, // compute the softmax over all H for each N, C, W
DOMI_SOFTMAX_MODE_WIDTH, // compute the softmax over all W for each N, C, H
DOMI_SOFTMAX_MODE_RESERVED
} domiSoftmaxMode_t;

// softmax algorithm
typedef enum tagDomiSoftmaxAlgo {
DOMI_SOFTMAX_FAST = 0, // straightforward implementation
DOMI_SOFTMAX_ACCURATE, // subtract max from every point to avoid overflow
DOMI_SOFTMAX_LOG, // perform the Log softmax operation to avoid overflow
DOMI_SOFTMAX_ACCURATE_FP32,
DOMI_SOFTMAX_RESERVED
} domiSoftmaxAlgo_t;

// algorithm of convolution backward
typedef enum tagDomiConvolutionBwdAlgo {
DOMI_CONVOLUTION_BWD_ALGO_GEMM = 0, // matrix gemm algo
DOMI_CONVOLUTION_BWD_ALGO_WINOGRAD, // Winograd Transform algo
DOMI_CONVOLUTION_BWD_ALGO_RESERVED
} domiConvolutionBwdAlgo_t;

// mode of pooling
typedef enum tagDomiPoolingMode {
DOMI_POOLING_MAX = 0, // max pooling
DOMI_POOLING_AVG, // average pooling
DOMI_POOLING_L2, // L2 pooling
DOMI_POOLING_RESERVED
} domiPoolingMode_t;

// propagate Nan
typedef enum tagDomiNanPropagation {
DOMI_NAN_NOT_PROPAGATE = 0, // Nan numbers are not propagated
DOMI_NAN_PROPAGATE, // Nan numbers are propagated
DOMI_NAN_PROPAGATE_RESERVED
} domiNanPropagation_t;

// mode of cropandresize
typedef enum tagDomiCropAndResizeMode {
DOMI_RESIZE_METHOD_BILINEAR = 0, // resize bilinear
DOMI_RESIZE_METHOD_NEAREST, // resize nearest
DOMI_RESIZE_RESERVED
} domiCropAndResizeMode_t;

// yolo version
typedef enum tagDomiYoloVersion { DOMI_YOLO_V2 = 1, DOMI_YOLO_V3, DOMI_YOLO_TRSERVED } domiYoloVersion_t;

typedef enum tagDomiRNNScopePassType {
DOMI_STATIC_BIDIRECTIONAL_RNN_GENERAL_PASS = 0,
DOMI_DYNAMIC_BIDIRECTIONAL_RNN_GENERAL_PASS,
DOMI_DYNAMIC_BIDIRECTIONAL_RNN_BIDAF_PASS
} domiRNNScopePassType;

// RNNDataLayout
typedef enum tagDomiRNNDataLayout {
DOMI_RNN_ND_TBX = 0, // data[max_time,batch_size,Xt]
DOMI_RNN_ND_BTX, // data[batch_size,max_time,Xt]
DOMI_RNN_5D_TX1BX, // data[max_time,Xt,1,batch_size,Xt]
DOMI_RNN_5D_BX1TX, // dataa[batch_size,Xt,1,max_time,Xt]
DOMI_RNN_4DTBX1,
DOMI_ENN_DL_RESERVED
} domiRNNDataLayout_t;

// RNNInputMode
typedef enum tagDomiRNNInputMode { DOMI_RNN_LINEAR_INPUT = 0, DOMI_RNN_SKIP_INPUT } domiRNNInputMode_t;

// RNNDirectionMode
typedef enum tagDomiRNNDirectionMode { DOMI_RNN_UNIDIRECTIONAL = 0, DOMI_RNN_BIDIRECTIONAL } domiDirectionMode_t;

typedef enum tagDomiPoolingCeilMode { DOMI_POOLING_FLOOR = 0, DOMI_POOLING_CEIL } domiPoolingCeilMode_t;

// RNNMode
typedef enum tagDomiRNNActivationMode {
DOMI_RNN_ACTIVATION_SIGMOID = 0, // sigmoid
DOMI_RNN_ACTIVATION_TANH, // tanh
DOMI_RNN_ACTIVATION_RELU, // ReLU
DOMI_RNN_ACTIVATION_RELU1, // ReLU1
DOMI_RNN_ACTIVATION_RELU6, // ReLU6
DOMI_RNN_ACTIVATION_RESERVED
} domiRNNActivationMode_t;

typedef enum tagDomiRNNLSTMOutMode {
DOMI_RNN_LSTM_OUT_SEPARATE = 0,
DOMI_RNN_LSTM_OUT_CONCAT,
DOMI_RNN_LSTM_OUT_RESERVED
} domiRNNLSTMOutPutMode_t;
typedef enum tagDomiRNNLSTMStateOutMode {
DOMI_RNN_LSTM_STATE_OUT_SEPARATE = 0,
DOMI_RNN_LSTM_STATE_OUT_CONCAT_ALL,
DOMI_RNN_LSTM_STATE_OUT_RESERVED
} domiRNNLSTMStateOutMode_t;

typedef enum tagDomiRNNMode {
DOMI_RNN_RELU = 0,
DOMI_RNN_TANH,
DOMI_LSTM,
DOMI_GRU,
DOMI_RNN_MODE_RESERVED
} domiRNNMode_t;

typedef enum tagDomiResizeBilinearMode {
DOMI_RESIZE_OUTPUT_DIM_BY_ZOOM_FACTOR = 0, // Output dimension specified by zoom factor
DOMI_RESIZE_OUTPUT_DIM_BY_SHRINK_FACTOR, // specified by shrink factor
DOMI_RESIZE_OUTPUT_DIM_EXPLICIT, // specified explicitly
DOMI_RESIZE_OUTPUT_DIM_RESERVED
} domiResizeOutputDimMode_t;

#pragma pack(1) // single-byte alignment
// DUMP file struct
struct FileHeader {
int32_t Version; // version
int32_t Output_Offset; // output offset address
char Reserved[24] = {0}; // 24 bytes reserved
};

struct BasicInfo {
struct FileHeader header; // file header
int32_t stream_id; // stread id
uint64_t start_time; // start time
uint64_t end_time; // end time
uint32_t input_size; // input memory size
uint32_t output_size; // output memory size
uint32_t weight_size; // weight Memory Size
uint32_t workspace_size; // workspace
uint32_t total_size; // total memory size
};
#pragma pack() // Cancels single-byte alignment
enum class MemorySizeCalcType { NORMAL = 0, ALWAYS_EMPTY };
} // namespace ge



+ 191
- 196
inc/framework/common/util.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,33 +14,32 @@
* limitations under the License.
*/

#ifndef INC_FRAMEWORK_COMMON_UTIL_H_
#define INC_FRAMEWORK_COMMON_UTIL_H_
#ifndef AIR_INC_FRAMEWORK_COMMON_UTIL_H_
#define AIR_INC_FRAMEWORK_COMMON_UTIL_H_

#include <google/protobuf/text_format.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <sstream>
#include <string>
#include <vector>

#include "framework/common/debug/ge_log.h"
#include <google/protobuf/text_format.h>
#include "external/graph/types.h"
#include "external/register/register.h"
#include "framework/common/debug/log.h"
#include "framework/common/scope_guard.h"
#include "framework/common/ge_inner_error_codes.h"
#include "mmpa/mmpa_api.h"
#include "graph/detail/attributes_holder.h"

#define GE_CHECK_POSITIVE_SIZE_RANGE(size) \
do { \
if (size <= 0) { \
DOMI_LOGE("param[%s] is not a positive number", #size); \
return PARAM_INVALID; \
} \
} while (0)
#define GE_CHECK_POSITIVE_SIZE_RANGE(size) \
do { \
if ((size) <= 0) { \
GELOGE(ge::FAILED, "param[%s] is not a positive number", #size); \
return PARAM_INVALID; \
} \
} while (false)

#define CHECK_FALSE_EXEC(expr, exec_expr, ...) \
{ \
bool b = (expr); \
const bool b = (expr); \
if (!b) { \
exec_expr; \
} \
@@ -48,189 +47,244 @@

// new ge marco
// Encapsulate common resource releases
#define GE_MAKE_GUARD_RTMEM(var) \
GE_MAKE_GUARD(var, [&] { \
if (var) GE_CHK_RT(rtFreeHost(var)); \
});
#define GE_MAKE_GUARD_RTMEM(var) \
GE_MAKE_GUARD(var, [&] { \
if ((var) != nullptr) { \
GE_CHK_RT(rtFreeHost(var)); \
} \
})

#define GE_MAKE_GUARD_RTSTREAM(var) \
GE_MAKE_GUARD(var, [&] { \
if (var) GE_CHK_RT(rtStreamDestroy(var)); \
});
#define GE_MAKE_GUARD_RTSTREAM(var) \
GE_MAKE_GUARD(var, [&] { \
if ((var) != nullptr) { \
GE_CHK_RT(rtStreamDestroy(var)); \
} \
})

// For propagating errors when calling a function.
#define GE_RETURN_IF_ERROR(expr) \
do { \
const ::ge::Status _status = (expr); \
if (_status) return _status; \
} while (0)
#define GE_RETURN_IF_ERROR(expr) \
do { \
const ge::Status _chk_status = (expr); \
if (_chk_status != ge::SUCCESS) { \
return _chk_status; \
} \
} while (false)

#define GE_RETURN_WITH_LOG_IF_ERROR(expr, ...) \
do { \
const ::ge::Status _status = (expr); \
if (_status) { \
DOMI_LOGE(__VA_ARGS__); \
return _status; \
const ge::Status _chk_status = (expr); \
if (_chk_status != ge::SUCCESS) { \
GELOGE(ge::FAILED, __VA_ARGS__); \
return _chk_status; \
} \
} while (0)
} while (false)

// check whether the parameter is true. If it is, return FAILED and record the error log
#define GE_RETURN_WITH_LOG_IF_TRUE(condition, ...) \
do { \
if (condition) { \
DOMI_LOGE(__VA_ARGS__); \
GELOGE(ge::FAILED, __VA_ARGS__); \
return ge::FAILED; \
} \
} while (0)
} while (false)

// Check if the parameter is false. If yes, return FAILED and record the error log
#define GE_RETURN_WITH_LOG_IF_FALSE(condition, ...) \
do { \
bool _condition = (condition); \
const bool _condition = (condition); \
if (!_condition) { \
DOMI_LOGE(__VA_ARGS__); \
GELOGE(ge::FAILED, __VA_ARGS__); \
return ge::FAILED; \
} \
} while (0)
} while (false)

// Checks whether the parameter is true. If so, returns PARAM_INVALID and records the error log
#define GE_RT_PARAM_INVALID_WITH_LOG_IF_TRUE(condition, ...) \
do { \
if (condition) { \
DOMI_LOGE(__VA_ARGS__); \
GELOGE(ge::FAILED, __VA_ARGS__); \
return ge::PARAM_INVALID; \
} \
} while (0)
} while (false)

// Check if the parameter is false. If yes, return PARAM_INVALID and record the error log
#define GE_RT_PARAM_INVALID_WITH_LOG_IF_FALSE(condition, ...) \
do { \
bool _condition = (condition); \
const bool _condition = (condition); \
if (!_condition) { \
DOMI_LOGE(__VA_ARGS__); \
GELOGE(ge::FAILED, __VA_ARGS__); \
return ge::PARAM_INVALID; \
} \
} while (0)
} while (false)

// Check if the parameter is null. If yes, return PARAM_INVALID and record the error
#define GE_CHECK_NOTNULL(val) \
do { \
if (val == nullptr) { \
REPORT_INNER_ERROR("E19999", "Param:%s is nullptr, check invalid", #val); \
DOMI_LOGE("[Check][Param:%s]null is invalid.", #val); \
return ge::PARAM_INVALID; \
} \
} while (0)
#define GE_CHECK_NOTNULL(val, ...) \
do { \
if ((val) == nullptr) { \
REPORT_INNER_ERROR("E19999", "Param:" #val " is nullptr, check invalid" __VA_ARGS__); \
GELOGE(ge::FAILED, "[Check][Param:" #val "]null is invalid" __VA_ARGS__); \
return ge::PARAM_INVALID; \
} \
} while (false)

// Check if the parameter is null. If yes, just return and record the error
#define GE_CHECK_NOTNULL_JUST_RETURN(val) \
do { \
if (val == nullptr) { \
DOMI_LOGE("param[%s] must not be null.", #val); \
return; \
} \
} while (0)
#define GE_CHECK_NOTNULL_JUST_RETURN(val) \
do { \
if ((val) == nullptr) { \
GELOGE(ge::FAILED, "param[%s] must not be null.", #val); \
return; \
} \
} while (false)

// Check whether the parameter is null. If so, execute the exec_expr expression and record the error log
#define GE_CHECK_NOTNULL_EXEC(val, exec_expr) \
do { \
if (val == nullptr) { \
DOMI_LOGE("param[%s] must not be null.", #val); \
exec_expr; \
} \
} while (0)
#define GE_CHECK_NOTNULL_EXEC(val, exec_expr) \
do { \
if ((val) == nullptr) { \
GELOGE(ge::FAILED, "param[%s] must not be null.", #val); \
exec_expr; \
} \
} while (false)

// Check whether the parameter is null. If yes, return directly and record the error log
#define GE_RT_VOID_CHECK_NOTNULL(val) \
do { \
if (val == nullptr) { \
DOMI_LOGE("param[%s] must not be null.", #val); \
return; \
} \
} while (0)
#define GE_RT_VOID_CHECK_NOTNULL(val) \
do { \
if ((val) == nullptr) { \
GELOGE(ge::FAILED, "param[%s] must not be null.", #val); \
return; \
} \
} while (false)

// Check if the parameter is null. If yes, return false and record the error log
#define GE_RT_FALSE_CHECK_NOTNULL(val) \
do { \
if (val == nullptr) { \
DOMI_LOGE("param[%s] must not be null.", #val); \
return false; \
} \
} while (0)
#define GE_RT_FALSE_CHECK_NOTNULL(val) \
do { \
if ((val) == nullptr) { \
GELOGE(ge::FAILED, "param[%s] must not be null.", #val); \
return false; \
} \
} while (false)

// Check if the parameter is out of bounds
#define GE_CHECK_SIZE(size) \
do { \
if (size == 0) { \
DOMI_LOGE("param[%s] is out of range", #size); \
return ge::PARAM_INVALID; \
} \
} while (0)
#define GE_CHECK_SIZE(size) \
do { \
if ((size) == 0U) { \
GELOGE(ge::FAILED, "param[%s] is out of range", #size); \
return ge::PARAM_INVALID; \
} \
} while (false)

// Check if the value on the left is greater than or equal to the value on the right
#define GE_CHECK_GE(lhs, rhs) \
do { \
if (lhs < rhs) { \
DOMI_LOGE("param[%s] is less than[%s]", #lhs, #rhs); \
return ge::PARAM_INVALID; \
} \
} while (0)
#define GE_CHECK_GE(lhs, rhs) \
do { \
if ((lhs) < (rhs)) { \
GELOGE(ge::FAILED, "param[%s] is less than[%s]", #lhs, #rhs); \
return ge::PARAM_INVALID; \
} \
} while (false)

// Check if the value on the left is less than or equal to the value on the right
#define GE_CHECK_LE(lhs, rhs) \
do { \
if (lhs > rhs) { \
DOMI_LOGE("param[%s] is greater than[%s]", #lhs, #rhs); \
return ge::PARAM_INVALID; \
} \
} while (0)
#define GE_CHECK_LE(lhs, rhs) \
do { \
if ((lhs) > (rhs)) { \
GELOGE(ge::FAILED, "param[%s] is greater than[%s]", #lhs, #rhs); \
return ge::PARAM_INVALID; \
} \
} while (false)

#define GE_DELETE_NEW_SINGLE(var) \
do { \
if (var != nullptr) { \
delete var; \
var = nullptr; \
if ((var) != nullptr) { \
delete (var); \
(var) = nullptr; \
} \
} while (0)
} while (false)

#define GE_DELETE_NEW_ARRAY(var) \
do { \
if (var != nullptr) { \
delete[] var; \
var = nullptr; \
if ((var) != nullptr) { \
delete[](var); \
(var) = nullptr; \
} \
} while (0)
} while (false)

#define GE_FREE_RT_LOG(addr) \
do { \
if (addr != nullptr) { \
rtError_t error = rtFree(addr); \
if ((addr) != nullptr) { \
const rtError_t error = rtFree(addr); \
if (error != RT_ERROR_NONE) { \
GELOGE(RT_FAILED, "Call rtFree failed, error: %#x", error); \
} \
addr = nullptr; \
(addr) = nullptr; \
} \
} while (0)
} while (false)

namespace ge {
/**
* @ingroup domi_common
* @brief version of om.proto file
*/
static constexpr int32_t OM_PROTO_VERSION = 2;

/**
* Finding an Integer Ceiling Value Without Precision Loss
*/
#define CEIL(N, n) (((N) + (n)-1) / (n))
constexpr int32_t OM_PROTO_VERSION = 2;

namespace ge {
using google::protobuf::Message;
///
/// @ingroup domi_common
/// @brief onverts Vector of a number to a string.
/// @param [in] v Vector of a number
/// @return string
///
template <typename T>
GE_FUNC_VISIBILITY std::string ToString(const std::vector<T> &v) {
bool first = true;
std::stringstream ss;
ss << "[";
for (const T &x : v) {
if (first) {
first = false;
ss << x;
} else {
ss << ", " << x;
}
}
ss << "]";
return ss.str();
}

///
/// @ingroup domi_common
/// @brief Maximum file path length
/// @brief Converts RepeatedField to String.
/// @param [in] rpd_field RepeatedField
/// @return string
///
const int32_t DOMI_MAX_PATH_LEN = 256;
template <typename T>
GE_FUNC_VISIBILITY std::string ToString(const google::protobuf::RepeatedField<T> &rpd_field) {
std::stringstream ss;
ss << "[";
for (const T x : rpd_field) {
ss << x;
ss << ", ";
}
// Delete the two extra characters at the end of the line.
std::string str = ss.str().substr(0U, ss.str().length() - 2U);
str += "]";
return str;
}

///
/// @ingroup ge_ir_utils
/// @brief RepeatedPtrField->String
/// @param [in] const rpd_field RepeatedPtrField
/// @return String
///
template <typename T>
GE_FUNC_VISIBILITY std::string ToString(const google::protobuf::RepeatedPtrField<T> &rpd_ptr_field) {
std::stringstream ss;
ss << "[";
for (const T &x : rpd_ptr_field) {
ss << x;
ss << ", ";
}
std::string str_ret = ss.str().substr(0U, ss.str().length() - 2U);
str_ret += "]";
return str_ret;
}

///
/// @ingroup domi_common
@@ -241,7 +295,8 @@ const int32_t DOMI_MAX_PATH_LEN = 256;
/// @return true success
/// @return false fail
///
GE_FUNC_VISIBILITY bool ReadProtoFromArray(const void *data, int size, Message *proto);
GE_FUNC_VISIBILITY bool ReadProtoFromArray(const void *const data, const int32_t size,
google::protobuf::Message *const proto);

///
/// @ingroup domi_proto
@@ -251,17 +306,15 @@ GE_FUNC_VISIBILITY bool ReadProtoFromArray(const void *data, int size, Message *
/// @return true success
/// @return false fail
///
GE_FUNC_VISIBILITY bool ReadProtoFromText(const char *file, google::protobuf::Message *message);

GE_FUNC_VISIBILITY bool ReadProtoFromMem(const char *data, int size, google::protobuf::Message *message);
GE_FUNC_VISIBILITY bool ReadProtoFromText(const char_t *const file, google::protobuf::Message *const message);

///
/// @ingroup: domi_common
/// @brief: get length of file
/// @param [in] input_file: path of file
/// @return long: File length. If the file length fails to be obtained, the value -1 is returned.
/// @return int64_t: File length. If the file length fails to be obtained, the value -1 is returned.
///
GE_FUNC_VISIBILITY extern long GetFileLength(const std::string &input_file);
GE_FUNC_VISIBILITY extern int64_t GetFileLength(const std::string &input_file);

///
/// @ingroup domi_common
@@ -272,9 +325,7 @@ GE_FUNC_VISIBILITY extern long GetFileLength(const std::string &input_file);
/// @return false fail
/// @return true success
///
GE_FUNC_VISIBILITY bool ReadBytesFromBinaryFile(const char *file_name, char **buffer, int &length);

GE_FUNC_VISIBILITY bool ReadBytesFromBinaryFile(const char *file_name, std::vector<char> &buffer);
GE_FUNC_VISIBILITY bool ReadBytesFromBinaryFile(const char_t *const file_name, char_t **const buffer, int32_t &length);

///
/// @ingroup domi_common
@@ -283,7 +334,7 @@ GE_FUNC_VISIBILITY bool ReadBytesFromBinaryFile(const char *file_name, std::vect
/// @return 0 success
/// @return -1 fail
///
GE_FUNC_VISIBILITY extern int CreateDirectory(const std::string &directory_path);
GE_FUNC_VISIBILITY extern int32_t CreateDirectory(const std::string &directory_path);

///
/// @ingroup domi_common
@@ -294,46 +345,6 @@ GE_FUNC_VISIBILITY std::string CurrentTimeInStr();

///
/// @ingroup domi_common
/// @brief onverts Vector of a number to a string.
/// @param [in] v Vector of a number
/// @return string
///
template <typename T>
GE_FUNC_VISIBILITY std::string ToString(std::vector<T> &v) {
std::stringstream ss;
ss << "[";
for (T x : v) {
ss << x;
ss << ", ";
}
std::string strRet =
ss.str().substr(0, ss.str().length() - 2); // Delete the two extra characters at the end of the line.
strRet += "]";
return strRet;
}

///
/// @ingroup domi_common
/// @brief Converts RepeatedField to String.
/// @param [in] rpd_field RepeatedField
/// @return string
///
template <typename T>
GE_FUNC_VISIBILITY std::string ToString(const google::protobuf::RepeatedField<T> &rpd_field) {
std::stringstream ss;
ss << "[";
for (T x : rpd_field) {
ss << x;
ss << ", ";
}
std::string strRet =
ss.str().substr(0, ss.str().length() - 2); // Delete the two extra characters at the end of the line.
strRet += "]";
return strRet;
}

///
/// @ingroup domi_common
/// @brief Obtains the absolute time (timestamp) of the current system.
/// @return Timestamp, in microseconds (US)
///
@@ -355,7 +366,7 @@ GE_FUNC_VISIBILITY uint32_t GetCurrentSecondTimestap();
/// @param [in] b
/// @return false: true: The result is within the normal int64 range.
///
GE_FUNC_VISIBILITY bool CheckInt64MulOverflow(int64_t a, int64_t b);
GE_FUNC_VISIBILITY bool CheckInt64MulOverflow(const int64_t a, const int64_t b);

///
/// @ingroup domi_common
@@ -363,7 +374,7 @@ GE_FUNC_VISIBILITY bool CheckInt64MulOverflow(int64_t a, int64_t b);
/// @param [in] path of input file
/// @param [out] Absolute path of a file. If the absolute path cannot be obtained, an empty string is returned
///
GE_FUNC_VISIBILITY std::string RealPath(const char *path);
GE_FUNC_VISIBILITY std::string RealPath(const char_t *path);

///
/// @ingroup domi_common
@@ -387,28 +398,12 @@ GE_FUNC_VISIBILITY bool CheckOutputPathValid(const std::string &file_path, const
///
/// @ingroup domi_common
/// @brief Check whether the file path meets the whitelist verification requirements.
/// @param [in] filePath file path
/// @param [out] result
///
GE_FUNC_VISIBILITY bool ValidateStr(const std::string &filePath, const std::string &mode);

///
/// @ingroup domi_common
/// @brief Check whether the file is normal file.
/// @param [in] file_path file path
/// @param [in] str file path
/// @param [out] result
///
GE_FUNC_VISIBILITY bool IsValidFile(const char *file_path);
GE_FUNC_VISIBILITY bool ValidateStr(const std::string &file_path, const std::string &mode);

///
/// @ingroup domi_common
/// @brief Check path invalid
/// @param [in] path, path to be checked
/// @param [in] length, length of path
/// @return 0 success
/// @return -1 fail
///
GE_FUNC_VISIBILITY Status CheckPath(const char *path, size_t length);
GE_FUNC_VISIBILITY Status ConvertToInt32(const std::string &str, int32_t &val);
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_UTIL_H_
#endif // AIR_INC_FRAMEWORK_COMMON_UTIL_H_

+ 30
- 11
inc/framework/engine/dnnengine.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,16 +21,17 @@
#include <string>
#include <vector>

#include "common/ge_inner_error_codes.h"
#include "common/ge_types.h"
#include "framework/common/ge_inner_error_codes.h"
#include "framework/common/ge_types.h"
#include "graph/types.h"

namespace ge {
enum PriorityEnum {
enum class PriorityEnum {
COST_0 = 0,
COST_1,
COST_2,
COST_3,
COST_1 = 1,
COST_2 = 2,
COST_3 = 3,
COST_4 = 4,
COST_9 = 9,
COST_10 = 10,
};
@@ -38,19 +39,37 @@ enum PriorityEnum {
struct DNNEngineAttribute {
std::string engine_name;
std::vector<std::string> mem_type;
uint32_t compute_cost;
PriorityEnum compute_cost;
enum RuntimeType runtime_type; // HOST, DEVICE
// If engine input format must be specific, set this attribute, else set FORMAT_RESERVED
Format engine_input_format;
Format engine_output_format;
bool atomic_engine_flag;
};

class GE_FUNC_VISIBILITY DNNEngine {
public:
DNNEngine() = default;
explicit DNNEngine(const DNNEngineAttribute &attrs) {
engine_attribute_ = attrs;
}
virtual ~DNNEngine() = default;
virtual Status Initialize(const std::map<std::string, std::string> &options) = 0;
virtual Status Finalize() = 0;
virtual void GetAttributes(DNNEngineAttribute &attr) const = 0;
Status Initialize(const std::map<std::string, std::string> &options) const {
(void)options;
return SUCCESS;
}
Status Finalize() const {
return SUCCESS;
}
void GetAttributes(DNNEngineAttribute &attr) const {
attr = engine_attribute_;
}
bool IsAtomic() const {
return engine_attribute_.atomic_engine_flag;
}

protected:
DNNEngineAttribute engine_attribute_;
};
} // namespace ge



+ 118
- 75
inc/framework/executor/ge_executor.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,42 +22,58 @@
#include <vector>

#include "common/dynamic_aipp.h"
#include "common/ge_inner_error_codes.h"
#include "common/ge_types.h"
#include "common/types.h"
#include "framework/common/ge_inner_error_codes.h"
#include "framework/common/ge_types.h"
#include "framework/common/types.h"
#include "graph/tensor.h"
#include "graph/ge_tensor.h"
#include "runtime/base.h"

namespace ge {
class SingleOp;
class DynamicSingleOp;
class GeRootModel;

struct RunModelData {
uint32_t index; // Data index
uint32_t modelId;
std::vector<DataBuffer> blobs; // All input/output data buffer
uint32_t timestamp; // Data creation time
uint32_t timeout; // Processing timeout
uint64_t request_id = 0; // Request ID
uint64_t dynamic_batch_size = 0; // Dynamic batch size scene, set dynamic size, not supported by default:0
uint64_t dynamic_image_height = 0; // Dynamic image size scene, set image height, not supported by default:0
uint64_t dynamic_image_width = 0; // Dynamic image size scene, set image width, not supported by default:0
std::vector<uint64_t> dynamic_dims; // Dynamic dims scene, set dynamic dims, not supported by default:empty
std::vector<DataBuffer> blobs; // All input/output data buffer
uint32_t timestamp; // Data creation time
uint32_t timeout; // Processing timeout
uint64_t request_id = 0UL; // Request ID
uint64_t dynamic_batch_size = 0UL; // Dynamic batch size scene, set dynamic size, not supported by default:0
uint64_t dynamic_image_height = 0UL; // Dynamic image size scene, set image height, not supported by default:0
uint64_t dynamic_image_width = 0UL; // Dynamic image size scene, set image width, not supported by default:0
std::vector<uint64_t> dynamic_dims; // Dynamic dims scene, set dynamic dims, not supported by default:empty
};

class GE_FUNC_VISIBILITY GeExecutor {
public:
GeExecutor();
~GeExecutor() = default;
ge::Status Initialize();
ge::Status Finalize();

ge::Status UnloadModel(uint32_t modelId);
Status Initialize();
Status Finalize();

///
/// @ingroup ge
/// @brief Initialize global execute environment.
/// @param [in] options: environment variables.
/// @return init result
///
static Status Initialize(const std::map<std::string, std::string> &options);

///
/// @ingroup ge
/// @brief Finalize global execute environment.
/// @return execute result
///
static Status FinalizeEx();

Status UnloadModel(const uint32_t model_id);

// Get input and output descriptor
ge::Status GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc,
std::vector<ge::TensorDesc> &output_desc, bool new_model_desc = false);
Status GetModelDescInfo(const uint32_t model_id, std::vector<TensorDesc> &input_desc,
std::vector<TensorDesc> &output_desc, const bool new_model_desc = false);

///
/// @ingroup ge
@@ -68,7 +84,8 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [in] batch_size: batch size entered by user in dynamic multi-batch scenario
/// @return execute result
///
ge::Status SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, uint64_t batch_size);
Status SetDynamicBatchSize(const uint32_t model_id, void *const dynamic_input_addr, const uint64_t length,
const uint64_t batch_size);

///
/// @ingroup ge
@@ -80,8 +97,8 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [in] image_width: image width entered by user in dynamic multi-resolution scenario
/// @return execute result
///
ge::Status SetDynamicImageSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, uint64_t image_height,
uint64_t image_width);
Status SetDynamicImageSize(const uint32_t model_id, void *const dynamic_input_addr, const uint64_t length,
const uint64_t image_height, const uint64_t image_width);

///
/// @ingroup ge
@@ -93,8 +110,8 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [in] dynamic_dims: array of dynamic dimensions
/// @return execute result
///
ge::Status SetDynamicDims(uint32_t model_id, void *dynamic_input_addr, uint64_t length,
const std::vector<uint64_t> &dynamic_dims);
Status SetDynamicDims(const uint32_t model_id, void *const dynamic_input_addr, const uint64_t length,
const std::vector<uint64_t> &dynamic_dims);

///
/// @ingroup ge
@@ -104,8 +121,8 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] cur_dynamic_dims: current dynamic dims
/// @return execute result
///
ge::Status GetCurDynamicDims(uint32_t model_id, const std::vector<uint64_t> &dynamic_dims,
std::vector<uint64_t> &cur_dynamic_dims);
Status GetCurDynamicDims(const uint32_t model_id, const std::vector<uint64_t> &dynamic_dims,
std::vector<uint64_t> &cur_dynamic_dims);

///
/// @ingroup ge
@@ -115,8 +132,8 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] dynamic_type
/// @return execute result
///
ge::Status GetDynamicBatchInfo(uint32_t model_id, std::vector<std::vector<int64_t>> &batch_info,
int32_t &dynamic_type);
Status GetDynamicBatchInfo(const uint32_t model_id, std::vector<std::vector<int64_t>> &batch_info,
int32_t &dynamic_type);

///
/// @ingroup ge
@@ -125,7 +142,7 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] batch_info
/// @return execute result
///
ge::Status GetCombinedDynamicDims(uint32_t model_id, std::vector<std::vector<int64_t>> &batch_info);
Status GetCombinedDynamicDims(const uint32_t model_id, std::vector<std::vector<int64_t>> &batch_info);

///
/// @ingroup ge
@@ -134,9 +151,9 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] user_designate_shape_order
/// @return execute result
///
ge::Status GetUserDesignateShapeOrder(uint32_t model_id, std::vector<std::string> &user_designate_shape_order);
Status GetUserDesignateShapeOrder(const uint32_t model_id, std::vector<std::string> &user_designate_shape_order);

ge::Status GetCurShape(const uint32_t model_id, std::vector<int64_t> &batch_info, int32_t &dynamic_type);
Status GetCurShape(const uint32_t model_id, std::vector<int64_t> &batch_info, int32_t &dynamic_type);

///
/// @ingroup ge
@@ -148,22 +165,22 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [in] aippParms: kAippDynamicPara by user in dynamic aipp
/// @return execute result
///
ge::Status SetDynamicAippData(uint32_t model_id, void *dynamic_input_addr, uint64_t length,
const std::vector<kAippDynamicBatchPara> &aippBatchPara,
const kAippDynamicPara &aippParms);
Status SetDynamicAippData(const uint32_t model_id, void *const dynamic_input_addr, const uint64_t length,
const std::vector<kAippDynamicBatchPara> &aipp_batch_para,
const kAippDynamicPara &aipp_parms);

ge::Status GetAIPPInfo(uint32_t model_id, uint32_t index, AippConfigInfo &aipp_info);
Status GetAIPPInfo(const uint32_t model_id, const uint32_t index, AippConfigInfo &aipp_info);

ge::Status GetOpAttr(uint32_t model_id, const std::string &op_name, const std::string &attr_name,
std::string &attr_value);
Status GetOpAttr(const uint32_t model_id, const std::string &op_name, const std::string &attr_name,
std::string &attr_value);

ge::Status GetModelAttr(uint32_t model_id, std::vector<std::string> &dynamic_output_shape_info);
Status GetModelAttr(const uint32_t model_id, std::vector<std::string> &dynamic_output_shape_info);

ge::Status GetAippType(uint32_t model_id, uint32_t index, InputAippType &type, size_t &aipp_index);
Status GetAippType(const uint32_t model_id, const uint32_t index, InputAippType &type, size_t &aipp_index);

ge::Status CommandHandle(const ge::Command &command);
Status CommandHandle(const Command &command) const;

ge::Status SetDump(const DumpConfig &dump_config);
Status SetDump(const DumpConfig &dump_config);

///
/// @ingroup ge
@@ -173,7 +190,7 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @return SUCCESS
/// @return FAILED
///
ge::Status GetMaxUsedMemory(uint32_t model_id, uint32_t &max_size);
Status GetMaxUsedMemory(const uint32_t model_id, uint32_t &max_size);

///
/// @ingroup ge
@@ -182,7 +199,7 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] ModelData &model_data: Offline model memory data
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status LoadDataFromFile(const std::string &path, ge::ModelData &model_data);
Status LoadDataFromFile(const std::string &path, ModelData &model_data);

///
/// @ingroup ge
@@ -195,8 +212,8 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] uint32_t &model_id: Corresponding identification after model loading
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status LoadModelFromData(uint32_t &model_id, const ge::ModelData &model_data, void *dev_ptr, size_t mem_size,
void *weight_ptr, size_t weight_size);
Status LoadModelFromData(uint32_t &model_id, const ModelData &model_data, void *const dev_ptr, const size_t mem_size,
void *const weight_ptr, const size_t weight_size);

///
/// @ingroup ge
@@ -207,9 +224,20 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [in] output_queue_ids: input queue ids create from user.
/// @return: 0 for success / others for fail
///
ge::Status LoadModelWithQ(uint32_t &model_id, const ge::ModelData &model_data,
const std::vector<uint32_t> &input_queue_ids,
const std::vector<uint32_t> &output_queue_ids);
Status LoadModelWithQ(uint32_t &model_id, const ModelData &model_data, const std::vector<uint32_t> &input_queue_ids,
const std::vector<uint32_t> &output_queue_ids);

///
/// @ingroup ge
/// @brief Load task list from ModelData with queue.
/// @param [out] model_id: model id allocate from manager.
/// @param [in] root_model: Instance of GeRootModel.
/// @param [in] input_queue_ids: input queue ids create from user.
/// @param [in] output_queue_ids: input queue ids create from user.
/// @return: 0 for success / others for fail
///
Status LoadModelWithQ(uint32_t &model_id, const std::shared_ptr<GeRootModel> &root_model,
const std::vector<uint32_t> &input_queue_ids, const std::vector<uint32_t> &output_queue_ids);

///
/// @ingroup ge
@@ -221,8 +249,17 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] domi::OutputData *output_data: Model output data
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status ExecModel(uint32_t model_id, void *stream, const ge::RunModelData &input_data,
ge::RunModelData &output_data, bool async_mode = false);
Status ExecModel(const uint32_t model_id, void *const stream, const RunModelData &input_data,
RunModelData &output_data, const bool async_mode = false);

///
/// @ingroup ge
/// @brief Load task list from root_model without input queue or output queue.
/// @param [out] model_id: model id allocate from manager.
/// @param [in] root_model: Instance of GeRootModel.
/// @return: 0 for success / others for fail
///
Status LoadModelWithoutQ(uint32_t &model_id, const std::shared_ptr<GeRootModel> &root_model) const;

///
/// @ingroup ge
@@ -236,9 +273,9 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] std::vector<GeTensorDesc> &output_desc: description of model output data
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status ExecModel(uint32_t model_id, void *stream, const ge::RunModelData &run_input_data,
const std::vector<GeTensorDesc> &input_desc, ge::RunModelData &run_output_data,
std::vector<GeTensorDesc> &output_desc, bool async_mode = false);
Status ExecModel(const uint32_t model_id, void *const stream, const RunModelData &run_input_data,
const std::vector<GeTensorDesc> &input_desc, RunModelData &run_output_data,
std::vector<GeTensorDesc> &output_desc, const bool async_mode = false);

///
/// @ingroup ge
@@ -248,7 +285,7 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] size_t &weight_size Weight memory space size
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status GetMemAndWeightSize(const std::string &path, size_t &mem_size, size_t &weight_size);
Status GetMemAndWeightSize(const std::string &path, size_t &mem_size, size_t &weight_size);

///
/// @ingroup ge
@@ -259,39 +296,45 @@ class GE_FUNC_VISIBILITY GeExecutor {
/// @param [out] size_t &weight_size Weight memory space size
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status GetMemAndWeightSize(const void *model_data, size_t model_size, size_t &mem_size, size_t &weight_size);
Status GetMemAndWeightSize(const void *const model_data, const size_t model_size, size_t &mem_size,
size_t &weight_size);

static Status LoadSingleOp(const std::string &model_name, const ModelData &model_data, void *const stream,
SingleOp **const single_op);

static Status LoadSingleOpV2(const std::string &model_name, const ModelData &model_data, void *const stream,
SingleOp **const single_op, const uint64_t model_id);

static ge::Status LoadSingleOp(const std::string &modelName, const ge::ModelData &modelData, void *stream,
SingleOp **single_op);
static Status ExecuteAsync(SingleOp *const executor, const std::vector<DataBuffer> &inputs,
std::vector<DataBuffer> &outputs);

static ge::Status LoadSingleOpV2(const std::string &modelName, const ge::ModelData &modelData, void *stream,
SingleOp **single_op, const uint64_t model_id);
static Status LoadDynamicSingleOp(const std::string &model_name, const ModelData &model_data, void *const stream,
DynamicSingleOp **const single_op);

static ge::Status ExecuteAsync(SingleOp *executor, const std::vector<DataBuffer> &inputs,
std::vector<DataBuffer> &outputs);
static Status LoadDynamicSingleOpV2(const std::string &model_name, const ModelData &model_data, void *const stream,
DynamicSingleOp **const single_op, const uint64_t model_id);

static ge::Status LoadDynamicSingleOp(const std::string &model_name, const ge::ModelData &modelData, void *stream,
DynamicSingleOp **single_op);
static Status UnloadSingleOp(const uint64_t op_id);

static ge::Status LoadDynamicSingleOpV2(const std::string &model_name, const ge::ModelData &modelData, void *stream,
DynamicSingleOp **single_op, const uint64_t model_id);
static Status UnloadDynamicSingleOp(const uint64_t op_id);

static ge::Status ExecuteAsync(DynamicSingleOp *executor, const std::vector<GeTensorDesc> &input_desc,
const std::vector<DataBuffer> &inputs, std::vector<GeTensorDesc> &output_desc,
std::vector<DataBuffer> &outputs);
static Status ExecuteAsync(DynamicSingleOp *const executor, const std::vector<GeTensorDesc> &input_desc,
const std::vector<DataBuffer> &inputs, std::vector<GeTensorDesc> &output_desc,
std::vector<DataBuffer> &outputs);

static ge::Status ReleaseSingleOpResource(void *stream);
static Status ReleaseSingleOpResource(void *const stream);

static ge::Status GetDeviceIdByModelId(uint32_t model_id, uint32_t &device_id);
static Status GetDeviceIdByModelId(const uint32_t model_id, uint32_t &device_id);

ge::Status GetBatchInfoSize(uint32_t model_id, size_t &shape_count);
ge::Status GetOrigInputInfo(uint32_t model_id, uint32_t index, OriginInputInfo &orig_input_info);
ge::Status GetAllAippInputOutputDims(uint32_t model_id, uint32_t index, std::vector<InputOutputDims> &input_dims,
std::vector<InputOutputDims> &output_dims);
ge::Status GetOpDescInfo(uint32_t device_id, uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info);
Status GetBatchInfoSize(const uint32_t model_id, size_t &shape_count);
Status GetOrigInputInfo(const uint32_t model_id, const uint32_t index, OriginInputInfo &orig_input_info);
Status GetAllAippInputOutputDims(const uint32_t model_id, const uint32_t index,
std::vector<InputOutputDims> &input_dims, std::vector<InputOutputDims> &output_dims);
Status GetOpDescInfo(const uint32_t device_id, const uint32_t stream_id, const uint32_t task_id,
OpDescInfo &op_desc_info);

private:
static bool isInit_;
static std::atomic_bool is_inited_;
};
} // namespace ge



+ 0
- 113
inc/framework/ge_runtime/davinci_model.h View File

@@ -1,113 +0,0 @@
/**
* Copyright 2019-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 INC_FRAMEWORK_GE_RUNTIME_DAVINCI_MODEL_H_
#define INC_FRAMEWORK_GE_RUNTIME_DAVINCI_MODEL_H_

#include <memory>
#include <vector>

#include "ge_runtime/op_info.h"
#include "ge_runtime/task_info.h"

namespace ge {
namespace model_runner {
class DavinciModel {
public:
DavinciModel(const std::vector<std::shared_ptr<TaskInfo>> &task_info_list,
const std::vector<std::shared_ptr<OpInfo>> &data_info_list,
const std::vector<std::shared_ptr<OpInfo>> &output_info_list,
const std::vector<std::shared_ptr<OpInfo>> &constant_info_list,
const std::vector<model_runner::OpInfoPtr> &variable_info_list,
const std::vector<uint32_t> &wait_active_stream_list,
const std::vector<uint32_t> &force_copy_stream_list, uint64_t mem_size = 0, uint64_t weight_size = 0,
uint64_t var_size = 0, uintptr_t logic_mem_base = 0, uintptr_t logic_weight_base = 0,
uintptr_t logic_var_base = 0, uint32_t stream_num = 0, uint32_t batch_num = 0, uint32_t event_num = 0,
int32_t priority = 0)
: task_info_list_(task_info_list),
data_info_list_(data_info_list),
output_info_list_(output_info_list),
constant_info_list_(constant_info_list),
variable_info_list_(variable_info_list),
wait_active_stream_list_(wait_active_stream_list),
force_copy_stream_list_(force_copy_stream_list),
mem_size_(mem_size),
weight_size_(weight_size),
var_size_(var_size),
logic_mem_base_(logic_mem_base),
logic_weight_base_(logic_weight_base),
logic_var_base_(logic_var_base),
stream_num_(stream_num),
batch_num_(batch_num),
event_num_(event_num),
priority_(priority) {}
~DavinciModel() {}

uint64_t GetMemSize() const { return mem_size_; }
uint64_t GetWeightSize() const { return weight_size_; }
uint64_t GetVarSize() const { return var_size_; }

uintptr_t GetLogicMemBase() const { return logic_mem_base_; }
uintptr_t GetLogicWeightBase() const { return logic_weight_base_; }
uintptr_t GetLogicVarBase() const { return logic_var_base_; }

uint32_t GetStreamNum() const { return stream_num_; }
uint32_t GetBatchNum() const { return batch_num_; }
uint32_t GetEventNum() const { return event_num_; }

const std::vector<uint32_t> &GetWaitActiveStreams() const { return wait_active_stream_list_; }
const std::vector<uint32_t> &GetForceCopyStreams() const { return force_copy_stream_list_; }

int32_t GetPriority() const { return priority_; }

const std::vector<std::shared_ptr<TaskInfo>> &GetTaskInfoList() const { return task_info_list_; }
const std::vector<std::shared_ptr<OpInfo>> &GetDataInfoList() const { return data_info_list_; }
const std::vector<std::shared_ptr<OpInfo>> &GetOutputInfoList() const { return output_info_list_; }
const std::vector<std::shared_ptr<OpInfo>> &GetConstantInfoList() const { return output_info_list_; }
const std::vector<model_runner::OpInfoPtr> &GetVariableInfoList() const { return variable_info_list_; }

private:
std::vector<std::shared_ptr<TaskInfo>> task_info_list_;
std::vector<std::shared_ptr<OpInfo>> data_info_list_;
std::vector<std::shared_ptr<OpInfo>> output_info_list_;
std::vector<std::shared_ptr<OpInfo>> constant_info_list_;
std::vector<model_runner::OpInfoPtr> variable_info_list_;

std::vector<uint32_t> wait_active_stream_list_;
std::vector<uint32_t> force_copy_stream_list_;

uint64_t mem_size_;
uint64_t weight_size_;
uint64_t var_size_;

uintptr_t logic_mem_base_;
uintptr_t logic_weight_base_;
uintptr_t logic_var_base_;

uint32_t stream_num_;
uint32_t batch_num_;
uint32_t event_num_;

int32_t priority_;

// Disable to copy constructor and assignment operator
DavinciModel &operator=(const DavinciModel &) = delete;
DavinciModel(const DavinciModel &) = delete;
};
} // namespace model_runner
} // namespace ge

#endif // INC_FRAMEWORK_GE_RUNTIME_DAVINCI_MODEL_H_

+ 0
- 68
inc/framework/ge_runtime/model_runner.h View File

@@ -1,68 +0,0 @@
/**
* Copyright 2019-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 INC_FRAMEWORK_GE_RUNTIME_MODEL_RUNNER_H_
#define INC_FRAMEWORK_GE_RUNTIME_MODEL_RUNNER_H_

#include <memory>
#include <unordered_map>
#include <vector>

#include "common/ge_inner_error_codes.h"
#include "common/ge_types.h"
#include "ge_runtime/davinci_model.h"

namespace ge {
namespace model_runner {
class RuntimeModel;
using RuntimeInfo = std::tuple<uint32_t, uint32_t, void *>;
class ModelRunner {
public:
static ModelRunner &Instance();

bool LoadDavinciModel(uint32_t device_id, uint64_t session_id, uint32_t model_id,
std::shared_ptr<DavinciModel> davinci_model, std::shared_ptr<ModelListener> listener);

bool DistributeTask(uint32_t model_id);

bool LoadModelComplete(uint32_t model_id);

const std::vector<uint32_t> &GetTaskIdList(uint32_t model_id) const;

const std::vector<uint32_t> &GetStreamIdList(uint32_t model_id) const;

const std::map<std::string, std::shared_ptr<RuntimeInfo>> &GetRuntimeInfoMap(uint32_t model_id) const;

void *GetModelHandle(uint32_t model_id) const;

bool UnloadModel(uint32_t model_id);

bool RunModel(uint32_t model_id, const InputData &input_data, OutputData *output_data);

bool GetInputOutputDescInfo(uint32_t model_id, bool zero_copy, std::vector<InputOutputDescInfo> *input_desc,
std::vector<InputOutputDescInfo> *output_desc, std::vector<uint32_t> *input_format,
std::vector<uint32_t> *output_format);

private:
ModelRunner() = default;
~ModelRunner() = default;

std::unordered_map<uint32_t, std::shared_ptr<RuntimeModel>> runtime_models_;
};
} // namespace model_runner
} // namespace ge

#endif // INC_FRAMEWORK_GE_RUNTIME_MODEL_RUNNER_H_

+ 0
- 72
inc/framework/ge_runtime/op_info.h View File

@@ -1,72 +0,0 @@
/**
* Copyright 2019-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 INC_FRAMEWORK_GE_RUNTIME_OP_INFO_H_
#define INC_FRAMEWORK_GE_RUNTIME_OP_INFO_H_

#include <memory>
#include <string>
#include <vector>

namespace ge {
namespace model_runner {
struct TensorInfo {
int64_t GetShapeSize() const {
int64_t res = 1;
if (dims.empty()) {
return 0;
}
for (auto dim : dims) {
res *= dim;
}
return res;
}

int64_t GetDim(uint32_t index) {
if (index >= dims.size()) {
return 0;
}
return dims[index];
}

std::vector<int64_t> dims;
uint32_t datatype;
uint32_t format;
uint32_t real_dim_cnt;
uint32_t size;
bool is_output;
};

struct OpInfo {
uint32_t index;
std::string name;
std::string type;
bool var_is_broadcast;
std::vector<uintptr_t> input_addrs;
std::vector<uintptr_t> output_addrs;
std::vector<TensorInfo> input_tensors;
std::vector<TensorInfo> output_tensors;
std::vector<TensorInfo> weight_tensors;
std::vector<std::string> src_name;
std::vector<int64_t> src_index;
std::string weight_data;
};

using TensorInfoPtr = std::shared_ptr<TensorInfo>;
using OpInfoPtr = std::shared_ptr<OpInfo>;
} // namespace model_runner
} // namespace ge
#endif // INC_FRAMEWORK_GE_RUNTIME_OP_INFO_H_

+ 0
- 405
inc/framework/ge_runtime/task_info.h View File

@@ -1,405 +0,0 @@
/**
* Copyright 2019-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 INC_FRAMEWORK_GE_RUNTIME_TASK_INFO_H_
#define INC_FRAMEWORK_GE_RUNTIME_TASK_INFO_H_

#include <stdint.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "cce/taskdown_api.h"

namespace ge {
namespace model_runner {
enum TaskInfoType {
CCE = 0,
TBE,
AICPU,
LABEL_SET,
LABEL_SWITCH,
LABEL_GOTO,
EVENT_RECORD,
EVENT_WAIT,
FUSION_START,
FUSION_END,
HCCL,
PROFILER_TRACE,
MEMCPY_ASYNC,
STREAM_SWITCH,
STREAM_ACTIVE,
// Insert new task type here
REVSERVED = 23
};

class TaskInfo {
public:
virtual ~TaskInfo() {}
uint32_t stream_id() const { return stream_id_; }
TaskInfoType type() const { return type_; }
std::string op_name() const { return op_name_; }
bool dump_flag() const { return dump_flag_; }

protected:
TaskInfo(const std::string &op_name, uint32_t stream_id, TaskInfoType type, bool dump_flag)
: op_name_(op_name), stream_id_(stream_id), type_(type), dump_flag_(dump_flag) {}

private:
std::string op_name_;
uint32_t stream_id_;
TaskInfoType type_;
bool dump_flag_;
};

class CceTaskInfo : public TaskInfo {
public:
CceTaskInfo(const std::string &op_name, uint32_t stream_id, const cce::ccOpContext &ctx, const std::string &stub_func,
uint32_t block_dim, const std::vector<uint8_t> &args, uint32_t args_size,
const std::vector<uint8_t> &sm_desc, const std::vector<uint8_t> &flow_table,
const std::vector<uint8_t> &args_offset, bool is_flowtable)
: TaskInfo(op_name, stream_id, TaskInfoType::CCE, false),
ctx_(ctx),
stub_func_(stub_func),
block_dim_(block_dim),
args_(args),
args_size_(args_size),
sm_desc_(sm_desc),
flow_table_(flow_table),
args_offset_(args_offset),
is_flowtable_(is_flowtable) {}
~CceTaskInfo() override {}

cce::ccOpContext cc_context() const { return ctx_; }
std::string stub_func() const { return stub_func_; }
uint32_t block_dim() const { return block_dim_; }
const std::vector<uint8_t> &args() const { return args_; }
uint32_t args_size() const { return args_size_; }
const std::vector<uint8_t> &sm_desc() const { return sm_desc_; }
const std::vector<uint8_t> &flow_table() const { return flow_table_; }
const std::vector<uint8_t> &args_offset() const { return args_offset_; }
bool is_flowtable() const { return is_flowtable_; }

private:
cce::ccOpContext ctx_;
std::string stub_func_;
uint32_t block_dim_;
std::vector<uint8_t> args_;
uint32_t args_size_;
std::vector<uint8_t> sm_desc_;
std::vector<uint8_t> flow_table_;
std::vector<uint8_t> args_offset_;
bool is_flowtable_;
};

class TbeTaskInfo : public TaskInfo {
public:
TbeTaskInfo(const std::string &op_name, uint32_t stream_id, const std::string &stub_func, uint32_t block_dim,
const std::vector<uint8_t> &args, uint32_t args_size, const std::vector<uint8_t> &sm_desc, void *binary,
uint32_t binary_size, const std::vector<uint8_t> &meta_data, const std::vector<void *> &input_data_addrs,
const std::vector<void *> &output_data_addrs, const std::vector<void *> &workspace_addrs, bool dump_flag)
: TaskInfo(op_name, stream_id, TaskInfoType::TBE, dump_flag),
stub_func_(stub_func),
block_dim_(block_dim),
args_(args),
args_size_(args_size),
sm_desc_(sm_desc),
binary_(binary),
binary_size_(binary_size),
meta_data_(meta_data),
input_data_addrs_(input_data_addrs),
output_data_addrs_(output_data_addrs),
workspace_addrs_(workspace_addrs) {}
~TbeTaskInfo() override {}

const std::string &stub_func() const { return stub_func_; }
uint32_t block_dim() const { return block_dim_; }
const std::vector<uint8_t> &args() const { return args_; }
uint32_t args_size() const { return args_size_; }
const std::vector<uint8_t> &sm_desc() const { return sm_desc_; }
void *binary() const { return binary_; }
uint32_t binary_size() const { return binary_size_; }
const std::vector<uint8_t> &meta_data() const { return meta_data_; }
const std::vector<void *> &input_data_addrs() const { return input_data_addrs_; }
const std::vector<void *> &output_data_addrs() const { return output_data_addrs_; }
const std::vector<void *> &workspace_addrs() const { return workspace_addrs_; }

void SetBinary(void *binary, uint32_t binary_size) {
binary_ = binary;
binary_size_ = binary_size;
}

private:
std::string stub_func_;
uint32_t block_dim_;
std::vector<uint8_t> args_;
uint32_t args_size_;
std::vector<uint8_t> sm_desc_;
void *binary_;
uint32_t binary_size_;
std::vector<uint8_t> meta_data_;
std::vector<void *> input_data_addrs_;
std::vector<void *> output_data_addrs_;
std::vector<void *> workspace_addrs_;
};

class AicpuTaskInfo : public TaskInfo {
public:
AicpuTaskInfo(const std::string &op_name, uint32_t stream_id, const string &so_name, const std::string &kernel_name,
const std::string &node_def, const std::string &ext_info, const std::vector<void *> &input_data_addrs,
const std::vector<void *> &output_data_addrs, bool dump_flag)
: TaskInfo(op_name, stream_id, TaskInfoType::AICPU, dump_flag),
so_name_(so_name),
kernel_name_(kernel_name),
node_def_(node_def),
ext_info_(ext_info),
input_data_addrs_(input_data_addrs),
output_data_addrs_(output_data_addrs) {}
~AicpuTaskInfo() override {}

const std::string &so_name() const { return so_name_; }
const std::string &kernel_name() const { return kernel_name_; }
const std::string &node_def() const { return node_def_; }
const std::vector<void *> &input_data_addrs() const { return input_data_addrs_; }
const std::vector<void *> &output_data_addrs() const { return output_data_addrs_; }
const std::string &ext_info() const { return ext_info_; }

private:
std::string so_name_;
std::string kernel_name_;
std::string node_def_;
std::string ext_info_;
std::vector<void *> input_data_addrs_;
std::vector<void *> output_data_addrs_;
};

class LabelSetTaskInfo : public TaskInfo {
public:
LabelSetTaskInfo(const std::string &op_name, uint32_t stream_id, uint32_t label_id)
: TaskInfo(op_name, stream_id, TaskInfoType::LABEL_SET, false), label_id_(label_id) {}
~LabelSetTaskInfo() override {}
uint32_t label_id() const { return label_id_; }

private:
uint32_t label_id_;
};

class LabelGotoTaskInfo : public TaskInfo {
public:
LabelGotoTaskInfo(const std::string &op_name, uint32_t stream_id, uint32_t label_id)
: TaskInfo(op_name, stream_id, TaskInfoType::LABEL_GOTO, false), label_id_(label_id) {}
~LabelGotoTaskInfo() override {}
uint32_t label_id() const { return label_id_; }

private:
uint32_t label_id_;
};

class LabelSwitchTaskInfo : public TaskInfo {
public:
LabelSwitchTaskInfo(const std::string &op_name, uint32_t stream_id, uint32_t label_size,
const std::vector<uint32_t> &label_list, void *cond)
: TaskInfo(op_name, stream_id, TaskInfoType::LABEL_SWITCH, false),
label_size_(label_size),
label_list_(label_list),
cond_(cond) {}
~LabelSwitchTaskInfo() override {}
uint32_t label_size() const { return label_size_; }
const std::vector<uint32_t> &label_list() const { return label_list_; }
void *cond() const { return cond_; }

private:
uint32_t label_size_;
std::vector<uint32_t> label_list_;
void *cond_;
};

class EventTaskInfo : public TaskInfo {
public:
uint32_t event_id() const { return event_id_; }

protected:
EventTaskInfo(const std::string &op_name, uint32_t stream_id, TaskInfoType type, uint32_t event_id)
: TaskInfo(op_name, stream_id, type, false), event_id_(event_id) {}
~EventTaskInfo() override {}

uint32_t event_id_;
};

class EventRecordTaskInfo : public EventTaskInfo {
public:
EventRecordTaskInfo(const std::string &op_name, uint32_t stream_id, uint32_t event_id)
: EventTaskInfo(op_name, stream_id, TaskInfoType::EVENT_RECORD, event_id) {}
~EventRecordTaskInfo() override {}
};

class EventWaitTaskInfo : public EventTaskInfo {
public:
EventWaitTaskInfo(const std::string &op_name, uint32_t stream_id, uint32_t event_id)
: EventTaskInfo(op_name, stream_id, TaskInfoType::EVENT_WAIT, event_id) {}
~EventWaitTaskInfo() override {}
};

class FusionStartTaskInfo : public TaskInfo {
public:
explicit FusionStartTaskInfo(const std::string &op_name, uint32_t stream_id)
: TaskInfo(op_name, stream_id, TaskInfoType::FUSION_START, false) {}
~FusionStartTaskInfo() override {}
};

class FusionEndTaskInfo : public TaskInfo {
public:
explicit FusionEndTaskInfo(const std::string &op_name, uint32_t stream_id)
: TaskInfo(op_name, stream_id, TaskInfoType::FUSION_END, false) {}
~FusionEndTaskInfo() override {}
};

class HcclTaskInfo : public TaskInfo {
public:
HcclTaskInfo(const std::string &op_name, uint32_t stream_id, const std::string hccl_type, void *input_data_addr,
void *output_data_addr, int64_t workspace_size, int64_t hccl_stream_num,
const std::vector<uint8_t> &private_def, void *ops_kernel_store, int32_t count, int64_t root_id,
int64_t op_type, int64_t data_type, const std::string &group, bool dump_flag)
: TaskInfo(op_name, stream_id, TaskInfoType::HCCL, dump_flag),
hccl_type_(hccl_type),
input_data_addr_(input_data_addr),
output_data_addr_(output_data_addr),
workspace_size_(workspace_size),
hccl_stream_num_(hccl_stream_num),
private_def_(private_def),
ops_kernel_store_(ops_kernel_store),
count_(count),
root_id_(root_id),
op_type_(op_type),
data_type_(data_type),
group_(group) {}
~HcclTaskInfo() override {}

const std::string &hccl_type() const { return hccl_type_; }
void *input_data_addr() const { return input_data_addr_; }
void *output_data_addr() const { return output_data_addr_; }
int64_t workspace_size() const { return workspace_size_; }
int64_t hccl_stream_num() const { return hccl_stream_num_; }
const std::vector<uint8_t> &private_def() const { return private_def_; }
void *ops_kernel_store() const { return ops_kernel_store_; }
int32_t count() const { return count_; }
int64_t root_id() const { return root_id_; }
int64_t op_type() const { return op_type_; }
int64_t data_type() const { return data_type_; }
const std::string &group() const { return group_; }

private:
std::string hccl_type_;
void *input_data_addr_;
void *output_data_addr_;
int64_t workspace_size_;
int64_t hccl_stream_num_;
std::vector<uint8_t> private_def_;
void *ops_kernel_store_;
int32_t count_;
int64_t root_id_;
int64_t op_type_;
int64_t data_type_;
std::string group_;
};

class ProfilerTraceTaskInfo : public TaskInfo {
public:
ProfilerTraceTaskInfo(const std::string &op_name, uint32_t stream_id, uint64_t log_id, bool notify, uint32_t flat)
: TaskInfo(op_name, stream_id, TaskInfoType::PROFILER_TRACE, false),
log_id_(log_id),
notify_(notify),
flat_(flat) {}
~ProfilerTraceTaskInfo() override {}

uint64_t log_id() const { return log_id_; }
bool notify() const { return notify_; }
uint32_t flat() const { return flat_; }

private:
uint64_t log_id_;
bool notify_;
uint32_t flat_;
};

class MemcpyAsyncTaskInfo : public TaskInfo {
public:
MemcpyAsyncTaskInfo(const std::string &op_name, uint32_t stream_id, void *dst, uint64_t dst_max, void *src,
uint64_t count, uint32_t kind, bool dump_flag)
: TaskInfo(op_name, stream_id, TaskInfoType::MEMCPY_ASYNC, dump_flag),
dst_(dst),
dst_max_(dst_max),
src_(src),
count_(count),
kind_(kind) {}
~MemcpyAsyncTaskInfo() override {}

void *dst() const { return dst_; }
uint64_t dst_max() const { return dst_max_; }
void *src() const { return src_; }
uint64_t count() const { return count_; }
uint32_t kind() const { return kind_; }

private:
void *dst_;
uint64_t dst_max_;
void *src_;
uint64_t count_;
int32_t kind_;
};

class StreamSwitchTaskInfo : public TaskInfo {
public:
StreamSwitchTaskInfo(const std::string &op_name, uint32_t stream_id, int64_t true_stream_id, void *input_addr,
void *value_addr, int64_t cond, int64_t data_type)
: TaskInfo(op_name, stream_id, TaskInfoType::STREAM_SWITCH, false),
true_stream_id_(true_stream_id),
input_addr_(input_addr),
value_addr_(value_addr),
cond_(cond),
data_type_(data_type) {}
~StreamSwitchTaskInfo() override {}

int64_t true_stream_id() const { return true_stream_id_; }
void *input_addr() const { return input_addr_; }
void *value_addr() const { return value_addr_; }
int64_t cond() const { return cond_; }
int64_t data_type() const { return data_type_; }

private:
int64_t true_stream_id_;
void *input_addr_;
void *value_addr_;
int64_t cond_;
int64_t data_type_;
};

class StreamActiveTaskInfo : public TaskInfo {
public:
StreamActiveTaskInfo(const std::string &op_name, uint32_t stream_id, uint32_t active_stream_id)
: TaskInfo(op_name, stream_id, TaskInfoType::STREAM_ACTIVE, false), active_stream_id_(active_stream_id) {}
~StreamActiveTaskInfo() override {}

uint32_t active_stream_id() const { return active_stream_id_; }

private:
uint32_t active_stream_id_;
};
} // namespace model_runner
} // namespace ge

#endif // INC_FRAMEWORK_GE_RUNTIME_TASK_INFO_H_

+ 42
- 20
inc/framework/generator/ge_generator.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,26 +21,31 @@
#include <memory>
#include <string>
#include <vector>
#include "ge/ge_ir_build.h"
#include "common/ge_inner_error_codes.h"
#include "common/ge_types.h"
#include "external/ge/ge_ir_build.h"
#include "framework/common/ge_inner_error_codes.h"
#include "framework/common/ge_types.h"
#include "graph/ge_tensor.h"
#include "graph/graph.h"
#include "graph/op_desc.h"
#include "graph/detail/attributes_holder.h"
#include "omg/omg_inner_types.h"
#include "framework/omg/omg_inner_types.h"

namespace ge {
const std::string kAttrSupportDynamicShape = "support_dynamicshape";

class GeRootModel;
class GE_FUNC_VISIBILITY GeGenerator {
public:
using InOutTensorRef = std::pair<const std::vector<ge::GeTensor> &, const std::vector<ge::GeTensor> &>;
static GeGenerator &GetInstance() {
static GeGenerator Instance;
return Instance;
}
GeGenerator() = default;

~GeGenerator() { (void)Finalize(); }
~GeGenerator() {
(void)Finalize();
}

GeGenerator(const GeGenerator &) = delete;

@@ -54,7 +59,7 @@ class GE_FUNC_VISIBILITY GeGenerator {
Status GenerateOfflineModel(const Graph &graph, const std::string &file_name_prefix,
const std::vector<GeTensor> &inputs = std::vector<GeTensor>());

Status GenerateOnlineModel(const Graph &graph, const vector<GeTensor> &inputs, ge::ModelBufferData &model);
Status GenerateOnlineModel(const Graph &graph, const std::vector<GeTensor> &inputs, ge::ModelBufferData &model);

Status GenerateInfershapeGraph(const Graph &graph);

@@ -81,10 +86,16 @@ class GE_FUNC_VISIBILITY GeGenerator {
/// @param [in] compile_flag: op build flag, accurate build is 0, fuzz build is 1
/// @param [out] model_buff: model buff of op.
/// @return SUCCESS or FAILED
Status BuildSingleOpModel(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs,
OpEngineType engine_type, ModelBufferData &model_buff);
Status BuildSingleOpModel(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs,
OpEngineType engine_type, int32_t compile_flag, ModelBufferData &model_buff);
Status BuildSingleOpModel(OpDescPtr &op_desc, const std::vector<GeTensor> &inputs,
const std::vector<GeTensor> &outputs, OpEngineType engine_type,
ModelBufferData &model_buff);
Status BuildSingleOpModel(OpDescPtr &op_desc, const std::vector<GeTensor> &inputs,
const std::vector<GeTensor> &outputs, OpEngineType engine_type, int32_t compile_flag,
ModelBufferData &model_buff);
Status BuildSingleOpModel(OpDescPtr &op_desc, const std::vector<GeTensor> &inputs,
const std::vector<GeTensor> &outputs, OpEngineType engine_type, int32_t compile_flag,
ModelBufferData &model_buff, GraphStage graph_stage, ComputeGraphPtr &compute_graph);

///
/// @ingroup ge
/// @brief: Build single Op into model buff.
@@ -94,22 +105,33 @@ class GE_FUNC_VISIBILITY GeGenerator {
/// @param [in] graph_name: graph name.
/// @param [out] graph: graph of single op.
/// @return SUCCESS or FAILED
Status BuildSingleOpGraph(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs,
std::string graph_name, Graph &graph);
Status BuildSingleOpGraph(const OpDescPtr &op_desc, const InOutTensorRef &inputs_outputs, std::string graph_name,
Graph &graph, std::vector<std::pair<std::string, std::string>> &inputs_name_type) const;
Status BuildOriginalGraphInfo(OpDescPtr &op_desc, const std::vector<GeTensor> &inputs,
const std::vector<GeTensor> &outputs, const std::string &model_file_name,
bool is_offline, int32_t compile_flag, GraphStage graph_stage, Graph &graph,
ComputeGraphPtr &compute_graph, bool &fuzz_compile_flag,
std::vector<std::pair<std::string, std::string>> &inputs_name_type);

private:
Status GenerateModel(const Graph &graph, const string &file_name_prefix, const vector<GeTensor> &inputs,
Status GenerateModel(const Graph &graph, const std::string &file_name_prefix, const std::vector<GeTensor> &inputs,
ge::ModelBufferData &model, bool is_offline = true);
Status BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs,
const string &model_file_name, OpEngineType engine_type, ModelBufferData &model_buff,
bool is_offline = true, int32_t compile_flag = 0);
Status BuildSingleOp(OpDescPtr &op_desc, const std::vector<GeTensor> &inputs, const std::vector<GeTensor> &outputs,
const std::string &model_file_name, OpEngineType engine_type, ModelBufferData &model_buff,
ComputeGraphPtr &comp_graph, bool is_offline = true, int32_t compile_flag = 0,
GraphStage graph_stage = GraphStage::GRAPH_STAGE_RESERVED);
bool CheckNoAicore(const ComputeGraphPtr &graph);
void RemoveConst(const vector<GeTensor> &inputs, vector<GeTensor> &outputs);
Status CheckForSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs);
Status InferFormatForSingleOp(OpDescPtr &op_desc, Graph &graph);
void RemoveConst(const std::vector<GeTensor> &inputs, std::vector<GeTensor> &outputs) const;
Status CheckForSingleOp(const OpDescPtr &op_desc, const std::vector<GeTensor> &inputs,
const std::vector<GeTensor> &outputs) const;
Status InferFormatForSingleOp(const OpDescPtr &op_desc, const Graph &graph) const;

using GeRootModelPtr = std::shared_ptr<ge::GeRootModel>;
Status SetModelNameForDump(const GeRootModelPtr &ge_root_model);
Status CreateGeneralizedBuildAttrs(const GeRootModelPtr &ge_root_model, const std::vector<GeTensor> &inputs,
const std::vector<GeTensor> &outputs,
const std::vector<std::pair<std::string, std::string>> &inputs_name_type,
std::vector<ge::NamedAttrs> &generalized_build_attrs) const;

class Impl;



+ 0
- 187
inc/framework/generator/generator_api.h View File

@@ -1,187 +0,0 @@
/**
* Copyright 2019-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 INC_FRAMEWORK_GENERATOR_GENERATOR_API_H_
#define INC_FRAMEWORK_GENERATOR_GENERATOR_API_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 <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef uint32_t Status_t;

typedef void *OpAttr_t;
typedef void *OpTensor_t;

///
/// @ingroup ge
/// @brief Generate offline model for the op.
/// @param [in] op_type: type name of the op.
/// @param [in] in_tensor: input description array (created by OpTensorCreate).
/// @param [in] in_num: number of in_tensor.
/// @param [in] out_tensor: output description array (created by OpTensorCreate).
/// @param [in] out_num: number of out_tensor.
/// @param [in] attr: the attributes of the op (created by OpAttrCreate).
/// @param [in] om_file: file name for the om to save.
/// @return 0 for success / others for fail
///
GE_FUNC_VISIBILITY extern Status_t OpTaskGernerator(const char *op_type, const OpTensor_t *in_tensor, int in_num,
const OpTensor_t *out_tensor, int out_num, const OpAttr_t attr,
const char *om_file);

///
/// @ingroup ge
/// @brief Create Tensor Description.
/// @param [in] format: tensor format of the data.
/// @param [in] datatype: tensor type of the data.
/// @param [in] shape: tensor shape array.
/// @param [in] num: number of shape.
/// @return OpTensor_t for success / nullptr for failure
///
GE_FUNC_VISIBILITY extern OpTensor_t OpTensorCreate(int format, int datatype, const int64_t *shape, int num);

///
/// @ingroup ge
/// @brief Destroy Tensor Description.
/// @param [in] OpTensor_t tensor: created by OpTensorCreate.
/// @param [out] none
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t OpTensorDestroy(OpTensor_t tensor);

///
/// @ingroup ge
/// @brief Create an attribute holder.
/// @param [in] none
/// @param [out] none
/// @return OpAttr_t for success / nullptr for failure.
///
GE_FUNC_VISIBILITY extern OpAttr_t OpAttrCreate();

///
/// @ingroup ge
/// @brief Destroy Attribute holder.
/// @param [in] OpAttr_t attr: created by OpAttrCreate.
/// @param [out] none
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t OpAttrDestroy(OpAttr_t attr);

///
/// @ingroup ge
/// @brief Set a boolean attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attributed value.
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t SetAttrBool(OpAttr_t attr, const char *name, bool value);

///
/// @ingroup ge
/// @brief Set an integer attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value.
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t SetAttrInt(OpAttr_t attr, const char *name, int64_t value);

///
/// @ingroup ge
/// @brief Set a float attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value.
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t SetAttrFloat(OpAttr_t attr, const char *name, float value);

///
/// @ingroup ge
/// @brief Set a string attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value (can`t be nullptr, end with '\0').
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t SetAttrString(OpAttr_t attr, const char *name, const char *value);

///
/// @ingroup ge
/// @brief Set a boolean array attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value array.
/// @param [in] num: number of value array.
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t SetAttrBoolList(OpAttr_t attr, const char *name, const bool *value, int num);

///
/// @ingroup ge
/// @brief Set an integer array attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value array.
/// @param [in] num: number of value array.
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t SetAttrIntList(OpAttr_t attr, const char *name, const int64_t *value, int num);

///
/// @ingroup ge
/// @brief Set a float array attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value array.
/// @param [in] num: number of value array.
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t SetAttrFloatList(OpAttr_t attr, const char *name, const float *value, int num);

///
/// @ingroup ge
/// @brief Set a string array attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value array (each value can`t be nullptr, end with '\0').
/// @param [in] num: number of value array.
/// @return 0 for success / others for failure.
///
GE_FUNC_VISIBILITY extern Status_t SetAttrStringList(OpAttr_t attr, const char *name, const char **value, int num);

#ifdef __cplusplus
}
#endif

#endif // INC_FRAMEWORK_GENERATOR_GENERATOR_API_H_

+ 2
- 6
inc/framework/memory/memory_api.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,11 +17,7 @@
#ifndef INC_FRAMEWORK_MEMORY_MEMORY_API_H_
#define INC_FRAMEWORK_MEMORY_MEMORY_API_H_

#include <string>
#include <vector>

#include "ge/ge_api_error_codes.h"
#include "graph//types.h"
#include "external/ge/ge_api_error_codes.h"
#include "runtime/mem.h"

namespace ge {


+ 3
- 3
inc/framework/memory/memory_assigner.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@

#include <utility>

#include "common/ge_inner_error_codes.h"
#include "framework/common/ge_inner_error_codes.h"
#include "graph/node.h"

namespace ge {
@@ -33,7 +33,7 @@ class GE_FUNC_VISIBILITY MemoryAssigner {

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

Status AssignMemory(bool is_loop_graph, map<uint64_t, size_t> &mem_offset, size_t &zero_copy_mem_size);
Status AssignMemory(std::map<uint64_t, size_t> &mem_offset, size_t &zero_copy_mem_size);

private:
ge::ComputeGraphPtr compute_graph_;


+ 2
- 2
inc/framework/omg/ge_init.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
#define INC_FRAMEWORK_OMG_GE_INIT_H_
#include <map>
#include <string>
#include "common/ge_inner_error_codes.h"
#include "framework/common/ge_inner_error_codes.h"

namespace ge {
class GE_FUNC_VISIBILITY GEInit {


+ 1
- 1
inc/framework/omg/model_tool.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.


+ 24
- 27
inc/framework/omg/omg.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +17,12 @@
#ifndef INC_FRAMEWORK_OMG_OMG_H_
#define INC_FRAMEWORK_OMG_OMG_H_

#include <google/protobuf/message.h>
#include <string>
#include <unordered_map>
#include <vector>

#include <google/protobuf/message.h>
#include "external/ge/ge_api_types.h"
#include "framework/omg/omg_inner_types.h"
#include "framework/omg/parser/parser_inner_ctx.h"
#include "proto/ge_ir.pb.h"
@@ -31,20 +33,14 @@
#include "graph/model.h"
#include "runtime/kernel.h"

using domi::Status;
using std::pair;
using std::string;
using std::unordered_map;
using std::vector;

namespace ge {
/**
* @ingroup domi_omg
* @brief init omg context
* @return void
*/
GE_FUNC_VISIBILITY Status InitDomiOmgContext(const string &input_shape, const string &input_format,
const string &net_format, bool is_dynamic_input);
GE_FUNC_VISIBILITY domi::Status InitDomiOmgContext(const std::string &input_shape, const std::string &input_format,
const std::string &net_format, bool is_dynamic_input);

/**
* @ingroup domi_omg
@@ -61,10 +57,10 @@ GE_FUNC_VISIBILITY Status InitDomiOmgContext(const string &input_shape, const st
* @param [in] atc_params multiply atc params
* @return Status result code
*/
GE_FUNC_VISIBILITY Status ParseGraph(ge::Graph &graph, const std::map<string, string> &atc_params,
const char *model_file, const char *weights_file, domi::FrameworkType type,
const char *op_conf = nullptr, const char *target = nullptr,
RunMode run_mode = GEN_OM_MODEL, bool is_dynamic_input = false);
GE_FUNC_VISIBILITY domi::Status ParseGraph(ge::Graph &graph, const std::map<std::string, std::string> &atc_params,
const char *model_file, const char *weights_file, domi::FrameworkType type,
const char *op_conf = nullptr, const char *target = nullptr,
RunMode run_mode = RunMode::GEN_OM_MODEL, bool is_dynamic_input = false);

/**
* @ingroup domi_omg
@@ -74,9 +70,9 @@ GE_FUNC_VISIBILITY Status ParseGraph(ge::Graph &graph, const std::map<string, st
* @param [key] encrypted key
* @return Status result code
*/
GE_FUNC_VISIBILITY Status ConvertOm(const char *model_file, const char *json_file, bool is_covert_to_json);
GE_FUNC_VISIBILITY domi::Status ConvertOm(const char *model_file, const char *json_file, bool is_covert_to_json);

GE_FUNC_VISIBILITY Status ConvertPbtxtToJson(const char *model_file, const char *json_file);
GE_FUNC_VISIBILITY domi::Status ConvertPbtxtToJson(const char *model_file, const char *json_file);
/**
* @ingroup domi_omg
* @brief convert the model file in protobuf format into a JSON file.
@@ -86,23 +82,24 @@ GE_FUNC_VISIBILITY Status ConvertPbtxtToJson(const char *model_file, const char
* @param [key] encrypted key
* @return Status result code
*/
GE_FUNC_VISIBILITY Status ConvertFwkModelToJson(domi::FrameworkType framework, const char *model_file,
const char *json_file);
GE_FUNC_VISIBILITY domi::Status ConvertFwkModelToJson(const domi::FrameworkType framework, const char *model_file,
const char *json_file);

GE_FUNC_VISIBILITY void GetGroupName(ge::proto::ModelDef &model);
GE_FUNC_VISIBILITY void GetGroupName(ge::proto::ModelDef &model_def);

GE_FUNC_VISIBILITY void FindParserSo(const string &path, vector<string> &fileList, string &caffe_parser_path);
GE_FUNC_VISIBILITY void FindParserSo(const std::string &path, std::vector<std::string> &file_list,
std::string &caffe_parser_path);

GE_FUNC_VISIBILITY Status DumpInfershapeJson(const ge::Graph &graph, const char *json_file);
GE_FUNC_VISIBILITY domi::Status DumpInfershapeJson(const ge::Graph &graph, const char *json_file);

GE_FUNC_VISIBILITY Status SetOutputNodeInfo(ge::Graph &graph, const std::string &output_type,
const std::string &output_format);
GE_FUNC_VISIBILITY domi::Status SetOutputNodeInfo(ge::Graph &graph, const std::string &output_type,
const std::string &output);

GE_FUNC_VISIBILITY Status GetOutputLeaf(ge::NodePtr node,
std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info);
GE_FUNC_VISIBILITY domi::Status GetOutputLeaf(ge::NodePtr node,
std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info);

GE_FUNC_VISIBILITY void GetOutputNodesNameAndIndex(std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info,
std::vector<std::string> &output_nodes_name);
GE_FUNC_VISIBILITY void CreateOutputNodesInfo(std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info,
std::vector<std::string> &output_nodes_name);

GE_FUNC_VISIBILITY void UpdateOmgCtxWithParserCtx();



+ 14
- 41
inc/framework/omg/omg_inner_types.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,12 +31,7 @@
using domi::DOMI_TENSOR_ND;
using domi::DOMI_TENSOR_RESERVED;
using domi::domiTensorFormat_t;
using domi::FRAMEWORK_RESERVED;
using domi::FrameworkType;
using std::map;
using std::string;
using std::unordered_map;
using std::vector;

namespace ge {
/**
@@ -51,34 +46,13 @@ enum RunMode {
DISPLAY_OM_INFO = 6 // display model info
};

///
/// @ingroup domi_omg
/// @brief high-precision mode
///
enum HighPrecisionMode {
// the FP16 high-precision function is disabled in common mode
HIGH_PRECISION_DEFAULT = 0,

// high-precision mode, enabling FP16 high-precision mode (Convolution/FullConnect/AvgPooling are involved)
HIGH_PRECISION_FP16 = 1
};

///
/// @ingroup domi_omg
/// @brief description buffer data
///
struct OMGBufferData {
void *data;
uint32_t length;
};

struct OmgContext {
OmgContext() { format = DOMI_TENSOR_ND; }
domiTensorFormat_t format;
OmgContext() : format(domi::DOMI_TENSOR_ND) {}
domi::domiTensorFormat_t format;

// format of the input specified by the command line
std::unordered_map<std::string, domiTensorFormat_t> input_nodes_format_map;
std::vector<domiTensorFormat_t> output_formats;
std::unordered_map<std::string, domi::domiTensorFormat_t> input_nodes_format_map;
std::vector<domi::domiTensorFormat_t> output_formats;

// user-designate input dims
std::vector<std::pair<std::string, std::vector<int64_t>>> user_input_dims;
@@ -96,18 +70,18 @@ struct OmgContext {
// default out nodes (this is used for determing the orders)
std::vector<std::pair<std::string, int32_t>> default_out_nodes;
// save the output node of the network, value = topName,
// topName indicates the output name of the operator.
std::vector<std::string> user_out_nodes_top_vec;
// tensorName indicates the output name of the operator.
std::vector<std::string> user_out_tensors;
// net out nodes (where user_out_nodes or leaf nodes)
std::vector<std::string> net_out_nodes;
// net out nodes top names(only caffe has top)
std::vector<std::string> out_top_names;
// net data nodes top names(only caffe has top)
std::vector<std::string> data_top_names;
// net out nodes tensor names(caffe or onnx)
std::vector<std::string> out_tensor_names;
// net data nodes tensor names(caffe or onnx)
std::vector<std::string> data_tensor_names;
// preferential format used by the entire network
domiTensorFormat_t net_format = DOMI_TENSOR_RESERVED;
domi::domiTensorFormat_t net_format = domi::DOMI_TENSOR_RESERVED;
domi::FrameworkType type = domi::FRAMEWORK_RESERVED;
RunMode run_mode = ONLY_PRE_CHECK;
RunMode run_mode = RunMode::ONLY_PRE_CHECK;
bool train_flag = false;

std::string output_type;
@@ -118,14 +92,13 @@ struct OmgContext {
std::string dynamic_image_size;
std::string dynamic_dims;
std::string dynamic_node_type;
std::vector<std::vector<int64_t>> user_real_input_dims;
std::vector<int64_t> cur_dynamic_dims;
bool need_multi_batch = false;
std::vector<NodePtr> data_nodes;
std::vector<NodePtr> getnext_nosink_nodes;
bool fuzz_compile_flag = false;
std::string atc_cmdline;
bool user_attr_index_valid = false;
bool is_online_model = false;
};
} // namespace ge



+ 1
- 1
inc/framework/omg/omg_types.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.


+ 26
- 6
inc/framework/omg/parser/model_parser.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,6 @@
#include "graph/ge_tensor.h"
#include "graph/graph.h"
#include "graph/op_desc.h"
#include "graph/operator.h"
#include "graph/range_vistor.h"
#include "graph/utils/attr_utils.h"
#include "graph/utils/graph_utils.h"
#include "graph/utils/op_desc_utils.h"
@@ -36,7 +34,7 @@ using Status = domi::Status;

namespace domi {
using GetGraphCallback = std::function<std::unique_ptr<google::protobuf::Message>(
const google::protobuf::Message *root_proto, const std::string &graph)>;
const google::protobuf::Message *root_proto, const std::string &graph)>;

using GetGraphCallbackV2 = std::function<std::string(const std::string &subgraph_name)>;

@@ -109,7 +107,11 @@ class GE_FUNC_VISIBILITY ModelParser {
* @return SUCCESS
* @return Others failed
*/
virtual Status ToJson(const char *model_file, const char *json_file) { return domi::SUCCESS; }
virtual Status ToJson(const char *model_file, const char *json_file) {
(void)model_file;
(void)json_file;
return SUCCESS;
}

/*
* @ingroup domi_omg
@@ -129,7 +131,11 @@ class GE_FUNC_VISIBILITY ModelParser {
* @return SUCCESS
* @return Others failed
*/
virtual Status ParseProto(const std::string &serialized_proto, ge::ComputeGraphPtr &graph) { return UNSUPPORTED; }
virtual Status ParseProto(const std::string &serialized_proto, ge::ComputeGraphPtr &graph) {
(void)serialized_proto;
(void)graph;
return UNSUPPORTED;
}

/**
* @ingroup domi_omg
@@ -142,8 +148,22 @@ class GE_FUNC_VISIBILITY ModelParser {
*/
virtual Status ParseProtoWithSubgraph(const std::string &serialized_proto, GetGraphCallbackV2 callback,
ge::ComputeGraphPtr &graph) {
(void)serialized_proto;
(void)callback;
(void)graph;
return UNSUPPORTED;
}

virtual bool HasError() {
return false;
}

virtual Status Save(const std::string &file) {
(void)file;
return SUCCESS;
}

virtual void Clear(){};
};
} // namespace domi



+ 6
- 8
inc/framework/omg/parser/op_parser.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,10 +19,8 @@

#include <google/protobuf/text_format.h>
#include "framework/omg/parser/parser_types.h"
#include "omg/omg_inner_types.h"
#include "framework/omg/omg_inner_types.h"
#include "proto/om.pb.h"
#include "graph/ge_tensor.h"
#include "graph/op_desc.h"
#include "graph/utils/op_desc_utils.h"

using google::protobuf::Message;
@@ -50,7 +48,7 @@ class GE_FUNC_VISIBILITY OpParser {
* @return SUCCESS
* @return FAILED
*/
virtual Status ParseParams(const Message *op_src, ge::OpDescPtr &op_desc) = 0;
virtual domi::Status ParseParams(const google::protobuf::Message *op_src, ge::OpDescPtr &op_desc) = 0;

/**
* @ingroup domi_omg
@@ -60,7 +58,7 @@ class GE_FUNC_VISIBILITY OpParser {
* @return SUCCESS
* @return FAILED
*/
virtual Status ParseParams(const Message *op_src, ge::Operator &op_dest) = 0;
virtual domi::Status ParseParams(const google::protobuf::Message *op_src, ge::Operator &op_dest) = 0;

/**
* @ingroup domi_omg
@@ -70,7 +68,7 @@ class GE_FUNC_VISIBILITY OpParser {
* @return SUCCESS
* @return FAILED
*/
virtual Status ParseWeights(const Message *op_src, ge::NodePtr &node) = 0;
virtual domi::Status ParseWeights(const google::protobuf::Message *op_src, ge::NodePtr &node) = 0;

/**
* @ingroup domi_omg
@@ -80,7 +78,7 @@ class GE_FUNC_VISIBILITY OpParser {
* @return SUCCESS
* @return FAILED
*/
virtual Status GetFormat(const Message *op_src, domi::domiTensorFormat_t &format) {
virtual domi::Status GetFormat(const google::protobuf::Message *op_src, domi::domiTensorFormat_t &format) {
(void)op_src;
// Indicates that the op does not provide a value for format
format = domi::DOMI_TENSOR_RESERVED;


+ 4
- 5
inc/framework/omg/parser/parser_api.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,15 +17,14 @@
#ifndef INC_FRAMEWORK_OMG_PARSER_PARSER_API_H_
#define INC_FRAMEWORK_OMG_PARSER_PARSER_API_H_

#include <iostream>
#include <map>
#include <string>
#include "ge/ge_api_error_codes.h"
#include "external/ge/ge_api_error_codes.h"

namespace ge {
// Initialize parser
GE_FUNC_VISIBILITY Status ParserInitialize(const std::map<std::string, std::string>& options);
GE_FUNC_VISIBILITY Status ParserInitialize(const std::map<std::string, std::string> &options);
// Finalize parser, release all resources
GE_FUNC_VISIBILITY Status ParserFinalize();
} // namespace ge
#endif // INC_FRAMEWORK_OMG_PARSER_PARSER_API_H_
#endif // INC_FRAMEWORK_OMG_PARSER_PARSER_API_H_

+ 13
- 8
inc/framework/omg/parser/parser_factory.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,14 +23,13 @@
#include <string>
#include "framework/omg/omg_inner_types.h"
#include "framework/omg/parser/parser_types.h"

using Status = domi::Status;
#include "external/register/register.h"

namespace domi {
class WeightsParser;
class ModelParser;

typedef std::shared_ptr<ModelParser> (*MODEL_PARSER_CREATOR_FUN)(void);
using MODEL_PARSER_CREATOR_FUN = std::shared_ptr<ModelParser> (*)(void);

// Create modelparser for different frameworks
class GE_FUNC_VISIBILITY ModelParserFactory {
@@ -63,7 +62,7 @@ class GE_FUNC_VISIBILITY ModelParserFactory {

class GE_FUNC_VISIBILITY ModelParserRegisterar {
public:
ModelParserRegisterar(const domi::FrameworkType type, MODEL_PARSER_CREATOR_FUN fun) {
ModelParserRegisterar(const domi::FrameworkType type, MODEL_PARSER_CREATOR_FUN const fun) noexcept {
ModelParserFactory::Instance()->RegisterCreator(type, fun);
}
~ModelParserRegisterar() {}
@@ -82,7 +81,7 @@ class GE_FUNC_VISIBILITY ModelParserRegisterar {
} \
ModelParserRegisterar g_##type##_Model_Parser_Creator(type, Creator_##type##_Model_Parser)

typedef std::shared_ptr<WeightsParser> (*WEIGHTS_PARSER_CREATOR_FUN)(void);
using WEIGHTS_PARSER_CREATOR_FUN = std::shared_ptr<WeightsParser> (*)(void);

// Create weightsparser for different frameworks
class GE_FUNC_VISIBILITY WeightsParserFactory {
@@ -115,7 +114,7 @@ class GE_FUNC_VISIBILITY WeightsParserFactory {

class GE_FUNC_VISIBILITY WeightsParserRegisterar {
public:
WeightsParserRegisterar(const domi::FrameworkType type, WEIGHTS_PARSER_CREATOR_FUN fun) {
WeightsParserRegisterar(const domi::FrameworkType type, WEIGHTS_PARSER_CREATOR_FUN const fun) noexcept {
WeightsParserFactory::Instance()->RegisterCreator(type, fun);
}
~WeightsParserRegisterar() {}
@@ -133,6 +132,12 @@ class GE_FUNC_VISIBILITY WeightsParserRegisterar {
return std::shared_ptr<WeightsParser>(ptr); \
} \
WeightsParserRegisterar g_##type##_Weights_Parser_Creator(type, Creator_##type##_Weights_Parser)
}; // namespace domi

class GE_FUNC_VISIBILITY OpRegTbeParserFactory {
public:
static OpRegTbeParserFactory *Instance();
void Finalize(const domi::OpRegistrationData &reg_data);
};
} // namespace domi

#endif // INC_FRAMEWORK_OMG_PARSER_PARSER_FACTORY_H_

+ 10
- 11
inc/framework/omg/parser/parser_inner_ctx.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "external/register/register_fmk_types.h"
#include "external/register/register_types.h"
@@ -30,8 +29,8 @@
namespace ge {
struct ParserContext {
// format of the input specified by the command line
std::unordered_map<std::string, domiTensorFormat_t> input_nodes_format_map;
std::vector<domiTensorFormat_t> output_formats;
std::unordered_map<std::string, domi::domiTensorFormat_t> input_nodes_format_map;
std::vector<domi::domiTensorFormat_t> output_formats;
// user-designate input dims
std::vector<std::pair<std::string, std::vector<int64_t>>> user_input_dims;
std::map<std::string, std::vector<int64_t>> input_dims;
@@ -46,20 +45,20 @@ struct ParserContext {
// operator
std::map<std::string, std::vector<int32_t>> out_nodes_map;
// save the output node of the network, value = topName,
// topName indicates the output name of the operator.
std::vector<std::string> user_out_nodes_top_vec;
// tensorName indicates the output name of the operator.
std::vector<std::string> user_out_tensors;
// net out nodes (where user_out_nodes or leaf nodes)
std::vector<std::string> net_out_nodes;
// net data nodes top names(only caffe has top)
std::vector<std::string> data_top_names;
// net out nodes top names(only caffe has top)
std::vector<std::string> out_top_names;
// net out nodes tensor names(caffe or onnx)
std::vector<std::string> out_tensor_names;
// net data nodes tensor names(caffe or onnx)
std::vector<std::string> data_tensor_names;
// Whether to use dynamic batch size or dynamic image size
bool is_dynamic_input = false;
bool train_flag = false;
domi::domiTensorFormat_t format = domi::DOMI_TENSOR_ND;
domi::FrameworkType type = domi::FRAMEWORK_RESERVED;
RunMode run_mode = GEN_OM_MODEL;
RunMode run_mode = RunMode::GEN_OM_MODEL;
// save caffe custom proto path, used by caffe parse
std::string custom_proto_path;
// save caffe proto path, used by caffe parse


+ 3
- 2
inc/framework/omg/parser/parser_types.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
#ifndef PARSER_COMMON_TYPES_H_
#define PARSER_COMMON_TYPES_H_

#include <stdint.h>
#include <cstdint>
#include <string>

#include "register/register_types.h"
@@ -133,6 +133,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *_IF;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *STATELESSIF;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *IF;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *CASE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *STATELESSCASE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *_WHILE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *WHILE;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *STATELESSWHILE;


+ 13
- 3
inc/framework/omg/parser/weights_parser.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,13 +17,12 @@
#ifndef INC_FRAMEWORK_OMG_PARSER_WEIGHTS_PARSER_H_
#define INC_FRAMEWORK_OMG_PARSER_WEIGHTS_PARSER_H_

#include "external/register/register_error_codes.h"
#include "graph/graph.h"
#include "graph/attr_value.h"
#include "graph/compute_graph.h"
#include "graph/ge_tensor.h"
#include "graph/op_desc.h"
#include "graph/operator.h"
#include "graph/range_vistor.h"
#include "graph/utils/attr_utils.h"
#include "graph/utils/op_desc_utils.h"
#include "graph/utils/tensor_utils.h"
@@ -68,6 +67,17 @@ class GE_FUNC_VISIBILITY WeightsParser {
* @author
*/
virtual Status ParseFromMemory(const char *input, uint32_t lengt, ge::ComputeGraphPtr &graph) = 0;

virtual bool HasError() {
return false;
}

virtual Status Save(const std::string &file) {
(void)file;
return SUCCESS;
}

virtual void Clear() {}
};
} // namespace domi



+ 5
- 8
inc/framework/omg/version.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,12 +18,9 @@
#define INC_FRAMEWORK_OMG_VERSION_H_

#include <memory>
#include <set>
#include <string>
#include <vector>

#include "common/debug/log.h"
#include "common/string_util.h"
#include "framework/common/debug/log.h"
#include "framework/common/string_util.h"
#include "framework/common/debug/ge_log.h"

namespace ge {
@@ -33,8 +30,8 @@ class GE_FUNC_VISIBILITY PlatformVersionManager {
~PlatformVersionManager() = delete;
static Status GetPlatformVersion(std::string &ver) {
ver = "1.11.z";
std::vector<std::string> version_splits = StringUtils::Split(ver, '.');
GE_IF_BOOL_EXEC(version_splits.size() < 3, GELOGW("Read platform version error!"); return FAILED;);
const std::vector<std::string> version_splits = StringUtils::Split(ver, '.');
GE_IF_BOOL_EXEC(version_splits.size() < 3U, GELOGW("Read platform version error!"); return FAILED;);

GELOGI("Read current platform version: %s.", ver.c_str());
return SUCCESS;


+ 128
- 0
inc/framework/pne/pne_model.h View File

@@ -0,0 +1,128 @@
/**
* Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
*
* 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_FRAMEWORK_PNE_MODEL_H_
#define INC_FRAMEWORK_PNE_MODEL_H_

#include <map>
#include <string>
#include <vector>

#include "graph/compute_graph.h"
#include "framework/common/debug/log.h"
#include "framework/common/ge_inner_error_codes.h"
#include "framework/common/ge_types.h"
#include "framework/engine/dnnengine.h"
#include "external/ge/ge_ir_build.h"

namespace ge {
const std::string PNE_ID_NPU = "NPU";
const std::string PNE_ID_CPU = "HOST_CPU";

struct ModelRelation;
class PneModel {
public:
PneModel() = default;
explicit PneModel(const ComputeGraphPtr &root_graph) : root_graph_(root_graph){};
virtual ~PneModel() = default;
PneModel(const PneModel &other) = delete;
PneModel &operator=(const PneModel &other) = delete;

public:
inline Status AddSubModel(const shared_ptr<PneModel> &submodel, std::string type = "") {
if (submodel == nullptr) {
GELOGE(INTERNAL_ERROR, "submodel is nullptr, type = %s", type.c_str());
return INTERNAL_ERROR;
}
submodel->SetModelType(type);
if (!submodels_.emplace(submodel->GetModelName(), submodel).second) {
GELOGE(INTERNAL_ERROR, "submodel already exist, name = %s, type = %s", submodel->GetModelName().c_str(),
type.c_str());
return INTERNAL_ERROR;
}
return SUCCESS;
}

inline const std::shared_ptr<PneModel> GetSubmodel(const std::string &name) const {
const auto &it = submodels_.find(name);
if (it == submodels_.end()) {
return nullptr;
}
return it->second;
}

inline const std::map<std::string, std::shared_ptr<PneModel>> &GetSubmodels() const {
return submodels_;
}

inline void SetModelType(const std::string &type) {
model_type_ = type;
}

inline const std::string &GetModelType() const {
return model_type_;
}

inline void SetModelName(const std::string &model_name) {
model_name_ = model_name;
}

inline const std::string &GetModelName() const {
return model_name_;
}

inline void SetRootGraph(const ComputeGraphPtr graph) {
root_graph_ = graph;
}

inline const ComputeGraphPtr &GetRootGraph() const {
return root_graph_;
}

inline void SetModelRelation(std::shared_ptr<ModelRelation> model_relation) {
model_relation_ = std::move(model_relation);
}

inline const std::shared_ptr<ModelRelation> GetModelRelation() const {
return model_relation_;
}

public:
virtual Status SerializeModel(ModelBufferData &model_buff) = 0;

virtual Status UnSerializeModel(const ModelBufferData &model_buff) = 0;

virtual void SetModelId(const uint32_t model_id) {
model_id_ = model_id;
}

virtual uint32_t GetModelId() const {
return model_id_;
}

private:
std::map<std::string, std::shared_ptr<PneModel>> submodels_;
std::shared_ptr<ModelRelation> model_relation_;
ComputeGraphPtr root_graph_ = nullptr;
std::string model_name_;
std::string model_type_;
uint32_t model_id_ = INVALID_MODEL_ID;
};

using PneModelPtr = std::shared_ptr<PneModel>;
} // namespace ge

#endif // INC_FRAMEWORK_PNE_MODEL_H_

+ 67
- 0
inc/framework/pne/process_node_engine.h View File

@@ -0,0 +1,67 @@
/**
* Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
*
* 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_FRAMEWORK_PROCESS_NODE_ENGINE_H_
#define INC_FRAMEWORK_PROCESS_NODE_ENGINE_H_

#include <map>
#include <string>
#include <vector>

#include "framework/common/ge_inner_error_codes.h"
#include "framework/common/ge_types.h"
#include "graph/manager/graph_manager_utils.h"
#include "framework/pne/pne_model.h"

namespace ge {
class ProcessNodeEngineImpl {
public:
virtual Status OptimizeGraph(const std::vector<GeTensor> &inputs, ComputeGraphPtr &compute_graph) = 0;

virtual Status BuildGraph(ComputeGraphPtr &compute_graph, PneModelPtr &model) = 0;
};

using ProcessNodeEngineImplPtr = std::shared_ptr<ProcessNodeEngineImpl>;

class ProcessNodeEngine {
public:
ProcessNodeEngine() = default;
virtual ~ProcessNodeEngine() = default;
ProcessNodeEngine(const ProcessNodeEngine &other) = delete;
ProcessNodeEngine &operator=(const ProcessNodeEngine &other) = delete;

public:
virtual Status Initialize(const std::map<std::string, std::string> &options) = 0;

virtual Status Finalize() = 0;

virtual Status OptimizeGraph(const std::vector<GeTensor> &inputs, ComputeGraphPtr &compute_graph) = 0;

virtual Status BuildGraph(ComputeGraphPtr &compute_graph, PneModelPtr &model) = 0;

virtual const std::string &GetEngineName(const ge::NodePtr &node_ptr = nullptr) const = 0;

virtual void SetImpl(ProcessNodeEngineImplPtr impl) = 0;

protected:
std::string engine_id_;
ProcessNodeEngineImplPtr impl_ = nullptr;
};

using ProcessNodeEnginePtr = std::shared_ptr<ProcessNodeEngine>;
} // namespace ge

#endif // INC_FRAMEWORK_PROCESS_NODE_ENGINE_H_

+ 27
- 0
inc/framework/runtime/gert_api.h View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
*
* 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 AIR_CXX_INC_FRAMEWORK_RUNTIME_GERT_API_H_
#define AIR_CXX_INC_FRAMEWORK_RUNTIME_GERT_API_H_
#include "model_v2_executor.h"
#include "common/ge_types.h"

namespace gert {
std::unique_ptr<ModelV2Executor> LoadExecutorFromFile(const char *file_path, ge::graphStatus &error_code);
std::unique_ptr<ModelV2Executor> LoadExecutorFromModelData(const ge::ModelData &model_data,
ge::graphStatus &error_code);
} // namespace gert
#endif // AIR_CXX_INC_FRAMEWORK_RUNTIME_GERT_API_H_

+ 94
- 0
inc/framework/runtime/model_desc.h View File

@@ -0,0 +1,94 @@
/**
* Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
*
* 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 AIR_CXX_INC_FRAMEWORK_RUNTIME_MODEL_DESC_H_
#define AIR_CXX_INC_FRAMEWORK_RUNTIME_MODEL_DESC_H_
#include "common/ge_types.h"
#include "exe_graph/runtime/shape.h"
#include "exe_graph/runtime/continuous_vector.h"
#include "exe_graph/runtime/storage_format.h"
#include "exe_graph/runtime/storage_shape.h"
namespace gert {
class ShapeRange {
public:
const Shape &GetMin() const;
const Shape &GetMax() const;
Shape &MutableMin();
Shape &MutableMax();
private:
Shape min_;
Shape max_;
};
class ModelIoDesc {
public:
const char *GetName() const;
int32_t GetDataType() const;
ge::Format GetStorageFormat() const;
ge::Format GetOriginFormat() const;
int64_t GetSize() const;
const Shape &GetStorageShape() const;
const Shape &GetOriginShape() const;
const ShapeRange &GetOriginShapeRange() const;
const ShapeRange &GetStorageShapeRange() const;
void SetName(const char *name);
void SetDataType(int32_t data_type);
void SetStorageFormat(ge::Format format);
void SetOriginFormat(ge::Format format);
Shape &MutableStorageShape();
Shape &MutableOriginShape();
ShapeRange &MutableOriginShapeRange();
ShapeRange &MutableStorageShapeRange();
private:
const char *name_;
int32_t data_type_;
StorageFormat format_;
StorageShape shape_;
ShapeRange storage_shape_range_;
ShapeRange origin_shape_range_;
};
class ModelDesc {
public:
static size_t CalcSize(size_t input_num, size_t output_num);
const ModelIoDesc *GetInputDesc(size_t index) const;
const ModelIoDesc *GetAllInputsDesc(size_t &input_num) const;
const ModelIoDesc *GetOutputDesc(size_t index) const;
const ModelIoDesc *GetAllOutputsDesc(size_t &output_num) const;
ModelIoDesc *MutableInputDesc(size_t index);
ModelIoDesc *MutableOutputDesc(size_t index);
ModelIoDesc *AllMutableIoDesc(size_t &input_num, size_t &output_num);
void SetInputNum(size_t input_num);
void SetOutputNum(size_t output_num);
ge::graphStatus GetDynamicBatchInfo(std::vector<std::vector<int64_t>> &batch_info, int32_t &dynamic_type) const;
ge::graphStatus GetUserDesignateShapeOrder(std::vector<std::string> &user_designate_shape_order) const;
ge::graphStatus GetModelAttrs(std::vector<std::string> &attrs) const;
private:
size_t input_num_;
size_t output_num_;
ContinuousVector model_io_descs_;
};
} // namespace gert
#endif // AIR_CXX_INC_FRAMEWORK_RUNTIME_MODEL_DESC_H_

+ 142
- 0
inc/framework/runtime/model_v2_executor.h View File

@@ -0,0 +1,142 @@
/**
* Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
*
* 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 AIR_CXX_RUNTIME_V2_CORE_MODEL_V_2_EXECUTOR_H_
#define AIR_CXX_RUNTIME_V2_CORE_MODEL_V_2_EXECUTOR_H_
#include <memory>
#include "graph/compute_graph.h"
#include "graph/ge_error_codes.h"
#include "model_desc.h"
#include "runtime/stream.h"
#include "exe_graph/runtime/tensor.h"

namespace gert {
enum SubExeGraphType { kInitExeGraph, kMainExeGraph, kDeInitExeGraph, kSubExeGraphTypeEnd };
static constexpr char *kSubExeGraphTypeStrs[kSubExeGraphTypeEnd] = {(char *)"Init", (char *)"Main", (char *)"DeInit"};
inline const char *GetSubExeGraphTypeStr(SubExeGraphType type) {
return kSubExeGraphTypeStrs[type];
}

class ResourceGuard {
public:
void *ResetExecutionData(std::unique_ptr<uint8_t[]> execution_data);
void ResetAnyValue(std::unique_ptr<uint8_t[]> any_values, size_t count);
void PushNode(void *node);
void PushWatcher(void *watcher);
void *ResetNodesArray(std::unique_ptr<uint8_t[]> nodes_array);
void *ResetStartNodesArray(std::unique_ptr<uint8_t[]> start_nodes_array);
void *ResetNodesIndgreeArray(std::unique_ptr<uint8_t[]> nodes_indgree_array);
void *ResetNodesWaitIndgreeArray(std::unique_ptr<uint8_t[]> nodes_indgree_array);
void *ResetInputsArray(std::unique_ptr<uint8_t[]> inputs_array);
void *ResetOutputsArray(std::unique_ptr<uint8_t[]> outputs_array);
void *ResetWatchersArray(std::unique_ptr<uint8_t[]> watchers_array);
void *ResetReadyQueue(void *ready_queue);
void *ResetBuffer(std::unique_ptr<uint8_t[]> buffer);
void *ResetComputeNodeInfo(std::unique_ptr<uint8_t[]> compute_node_info);
void *ResetKernelExtendInfo(std::unique_ptr<uint8_t[]> kernel_extend_info);
void *ResetModelDesc(std::unique_ptr<uint8_t[]> model_desc);

~ResourceGuard();

private:
std::unique_ptr<uint8_t[]> execution_data_holder_;
size_t any_values_num_;
std::unique_ptr<uint8_t[]> any_values_guard_;

std::vector<std::unique_ptr<void, decltype(&free)>> nodes_guarder_;
std::vector<std::unique_ptr<void, decltype(&free)>> watchers_guarder_;
std::unique_ptr<uint8_t[]> continuous_buffer_guarder_;
std::unique_ptr<uint8_t[]> buffer_guarder_;
std::unique_ptr<uint8_t[]> compute_node_info_guarder_;
std::unique_ptr<uint8_t[]> kernel_extend_info_guarder_;
std::unique_ptr<uint8_t[]> model_desc_guarder_;

std::unique_ptr<uint8_t[]> nodes_array_guarder_;
std::unique_ptr<uint8_t[]> start_nodes_array_guarder_;
std::unique_ptr<uint8_t[]> nodes_indgree_array_guarder_;
std::unique_ptr<uint8_t[]> nodes_wait_indgree_array_guarder_;
std::unique_ptr<uint8_t[]> inputs_array_guarder_;
std::unique_ptr<uint8_t[]> outputs_array_guarder_;
std::unique_ptr<uint8_t[]> watchers_array_guarder_;
std::unique_ptr<void, decltype(&free)> ready_queue_guarder_{nullptr, nullptr};
};

struct ModelExecuteArg {
rtStream_t stream;
};
static_assert(std::is_standard_layout<ModelExecuteArg>::value, "The class ModelExecuteArg must be a POD");

class ExeGraphExecutor {
public:
// todo unload时释放anyvalue资源
ge::graphStatus Load() {
return ge::GRAPH_SUCCESS;
}
ge::graphStatus UnLoad() {
return ge::GRAPH_SUCCESS;
}

/**
* 设置图执行的输入/输出,需要注意的是,使用者需要自己保证inputs/outputs刷新完全!!!
*/
ge::graphStatus SpecifyInputs(void **inputs, size_t start, size_t num);
ge::graphStatus SpecifyOutputs(void **outputs, size_t num);
ge::graphStatus Execute();

const void *GetExecutionData() const {
return execution_data_;
}

ResourceGuard &GetResourceGuard();
void *SetExecutionData(std::unique_ptr<uint8_t[]> execution_data);

private:
friend class ModelV2ExecutorTestHelper;

void *execution_data_;
ResourceGuard resource_guard_;
};
class ModelV2Executor {
public:
static std::unique_ptr<ModelV2Executor> Create(const ge::ComputeGraphPtr &root_graph);

ge::graphStatus Load();
ge::graphStatus Execute(const ModelExecuteArg &arg, Tensor **inputs, size_t input_num, Tensor **outputs,
size_t output_num);
ge::graphStatus ExecuteSync(Tensor **inputs, size_t input_num, Tensor **outputs, size_t output_num);
ge::graphStatus UnLoad();

const ModelDesc &GetModelDesc() const;
void SetModelDesc(ModelDesc *model_desc);
ModelV2Executor(const ModelV2Executor &) = delete;
ModelV2Executor(ModelV2Executor &&) = delete;
ModelV2Executor &operator=(const ModelV2Executor &) = delete;
ModelV2Executor &operator=(ModelV2Executor &&) = delete;

private:
friend class ModelV2ExecutorBuilder;
friend class ModelV2ExecutorTestHelper;
ModelV2Executor() = default;

private:
std::array<ExeGraphExecutor, kSubExeGraphTypeEnd> graphs_;
ResourceGuard resource_guard_;
ModelDesc *model_desc_ = nullptr;
rtStream_t default_stream_ = nullptr;
};
} // namespace gert

#endif // AIR_CXX_RUNTIME_V2_CORE_MODEL_V_2_EXECUTOR_H_

+ 1
- 1
metadef

@@ -1 +1 @@
Subproject commit a725349b65aef2940555af2ddb7b9461fbe0d5fd
Subproject commit e4d1efc47349f13af1bcdb53ba408118779fc27e

+ 107
- 0
scripts/format_source_code.sh View File

@@ -0,0 +1,107 @@
#!/bin/bash
# Copyright 2019-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.
# ============================================================================

set -e

CLANG_FORMAT=$(which clang-format) || (echo "Please install 'clang-format' tool first"; exit 1)

version=$("${CLANG_FORMAT}" --version | sed -n "s/.*\ \([0-9]*\)\.[0-9]*\.[0-9]*.*/\1/p")
if [[ "${version}" -lt "8" ]]; then
echo "clang-format's version must be at least 8.0.0"
exit 1
fi

CURRENT_PATH=$(pwd)
SCRIPTS_PATH=$(dirname "$0")

echo "CURRENT_PATH=${CURRENT_PATH}"
echo "SCRIPTS_PATH=${SCRIPTS_PATH}"

# print usage message
function usage()
{
echo "Format the specified source files to conform the code style."
echo "Usage:"
echo "bash $0 [-a] [-c] [-l] [-h]"
echo "e.g. $0 -c"
echo ""
echo "Options:"
echo " -a format of all files"
echo " -c format of the files changed compared to last commit, default case"
echo " -l format of the files changed in last commit"
echo " -h Print usage"
}

# check and set options
function checkopts()
{
# init variable
mode="changed" # default format changed files

# Process the options
while getopts 'aclh' opt
do
case "${opt}" in
a)
mode="all"
;;
c)
mode="changed"
;;
l)
mode="lastcommit"
;;
h)
usage
exit 0
;;
*)
echo "Unknown option ${opt}!"
usage
exit 1
esac
done
}

# init variable
# check options
checkopts "$@"

# switch to project root path, which contains clang-format config file '.clang-format'
cd "${SCRIPTS_PATH}/.." || exit 1

FMT_FILE_LIST='__format_files_list__'

if [[ "X${mode}" == "Xall" ]]; then
find src -type f -name "*" | grep "\.h$\|\.cc$" > "${FMT_FILE_LIST}" || true
find inc -type f -name "*" | grep "\.h$\|\.cc$" >> "${FMT_FILE_LIST}" || true
elif [[ "X${mode}" == "Xchanged" ]]; then
# --diff-filter=ACMRTUXB will ignore deleted files in commit
git diff --diff-filter=ACMRTUXB --name-only | grep "^inc\|^src" | grep "\.h$\|\.cc$" >> "${FMT_FILE_LIST}" || true
else # "X${mode}" == "Xlastcommit"
git diff --diff-filter=ACMRTUXB --name-only HEAD~ HEAD | grep "^inc\|^src" | grep "\.h$\|\.cc$" > "${FMT_FILE_LIST}" || true
fi

while read line; do
if [ -f "${line}" ]; then
${CLANG_FORMAT} -i "${line}"
fi
done < "${FMT_FILE_LIST}"

rm "${FMT_FILE_LIST}"
cd "${CURRENT_PATH}" || exit 1

echo "Specified cpp source files have been format successfully."

+ 5
- 8
third_party/fwkacllib/inc/aicpu/aicpu_schedule/aicpu_op_type_list.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
#ifndef AICPU_OP_TYPE_LIST_H_
#define AICPU_OP_TYPE_LIST_H_
extern "C" {
enum OpKernelType {
TF_KERNEL,
CPU_KERNEL
@@ -29,19 +30,13 @@ enum ReturnCode {
};
#pragma pack(push, 1)
//One byte alignment
// One byte alignment
struct SysOpInfo {
uint64_t opLen;
uint64_t opType;
OpKernelType kernelsType;
};
struct OpParamInfo {
uint64_t num;
uint64_t dtypeList;
uint64_t formatList;
};
struct SysOpCheckInfo {
uint64_t opListNum;
uint64_t offSetLen;
@@ -57,4 +52,6 @@ struct SysOpCheckResp {
uint64_t opParamInfoList;
};
#pragma pack(pop)
}
#endif // AICPU_OP_TYPE_LIST_H_

+ 72
- 3
third_party/fwkacllib/inc/aicpu/common/aicpu_task_struct.h View File

@@ -14,13 +14,15 @@
* limitations under the License.
*/

#ifndef AICPU_TASK_STRUCT_H_
#define AICPU_TASK_STRUCT_H_
#ifndef AICPU_TASK_STRUCT_H
#define AICPU_TASK_STRUCT_H

#include <cstdint>

namespace aicpu {

using char_t = char;

#pragma pack(push, 1)
struct AicpuParamHead
{
@@ -29,9 +31,76 @@ struct AicpuParamHead
uint32_t extInfoLength; // extInfo struct Length
uint64_t extInfoAddr; // extInfo address
};

enum class AicpuConfigMsgType {
AICPU_CONFIG_MSG_TYPE_BUF_FREE = 0, /* free buf */
AICPU_CONFIG_MSG_TYPE_BUF_RESET = 1, /* reset buf */
AICPU_CONFIG_MSG_TYPE_BUF_SET_ADDR = 2, /* set buf addr to aicpu */
};

enum class AicpuErrMsgType {
ERR_MSG_TYPE_NULL = 0,
ERR_MSG_TYPE_AICORE = 1,
ERR_MSG_TYPE_AICPU = 2,
};

enum class AicpuExtInfoMsgType {
EXT_MODEL_ID_MSG_TYPE = 0,
};

struct AicpuConfigMsg {
uint8_t msgType;
uint8_t reserved1;
uint16_t bufLen;
uint32_t offset;
uint64_t bufAddr;
uint32_t tsId;
uint32_t reserved2;
};

struct AicpuModelIdInfo {
uint32_t modelId;
uint32_t extendModelId;
uint32_t extendInfo[13];
};

// 64 bytes
struct AicpuExtendInfo {
uint8_t msgType;
uint8_t version;
uint8_t reserved[2];
union {
AicpuModelIdInfo modelIdMap;
};
};

struct AicoreErrMsgInfo {
uint8_t errType;
uint8_t version;
uint8_t reserved1[2]; /* reserved1, 4 byte alignment */
uint32_t errorCode;
uint32_t modelId;
uint32_t taskId;
uint32_t streamId;
uint64_t transactionId;
uint8_t reserved2[228]; /* the total byte is 256, reserved2 len = 256 - other lens */
};

struct AicpuErrMsgInfo {
uint8_t errType;
uint8_t version;
uint8_t reserved1[2]; /* reserved1, 4 byte alignment */
uint32_t errorCode;
uint32_t modelId;
uint32_t streamId;
uint64_t transactionId;
char_t opName[64]; /* op name str */
char_t errDesc[128]; /* err msg desc info */
uint8_t reserved2[40]; /* the total byte is 256, reserved2 len = 256 - other lens */
};
#pragma pack(pop)

} // namespace aicpu

#endif // AICPU_TASK_STRUCT_H_
#endif // AICPU_TASK_STRUCT_H


+ 9
- 7
third_party/fwkacllib/inc/cce/fwk_adpt_struct.h View File

@@ -21,7 +21,7 @@

namespace aicpu {
namespace FWKAdapter {
using char_t = char;
// API RETURN CODE
enum FWKAdptAPIRetCode {
FWK_ADPT_SUCCESS = 0, // success
@@ -63,6 +63,8 @@ enum FWKTaskExtInfoType {
FWK_ADPT_EXT_BITMAP,
FWK_ADPT_EXT_TOPIC_TYPE,
FWK_ADPT_EXT_ASYNCWAIT,
FWK_ADPT_EXT_UNKNOWN_SHAPE_INPUT_INDEX,
FWK_ADPT_EXT_UNKNOWN_SHAPE_OUTPUT_INDEX,
FWK_ADPT_EXT_INVALID
};

@@ -113,7 +115,7 @@ struct StrFWKKernel {
typedef StrFWKKernel FWKOperateParam;

// Extent info ShapeAndType
const uint32_t kMaxShapeDims = 8;
const uint32_t kMaxShapeDims = 8U;
#pragma pack(push, 1)
struct ShapeAndType {
int32_t type;
@@ -122,13 +124,13 @@ struct ShapeAndType {
#pragma pack(pop)

// Extend info structure for extInfoAddr
const uint32_t kExtInfoHeadSize = 8;
const uint32_t kExtInfoHeadSize = 8U;

#pragma pack(push, 1)
struct ExtInfo {
int32_t infoType; // extend type
uint32_t infoLen; // length for infoMsg
char infoMsg[0]; // extend value
char_t infoMsg[0]; // extend value
};
#pragma pack(pop)

@@ -143,9 +145,9 @@ struct ResultSummary {

#pragma pack(push, 1)
struct AsyncWait {
uint8_t waitType; // wait type, FWK_ADPT_WAIT_TYPE_EVENT: event wait
uint32_t waitId; // wait id, GE refresh
uint32_t timeOut; // reserved
uint8_t waitType; // wait type, FWk_ADPT_WAIT_TPYE_EVENT: event wait
uint32_t waitId; // wait id, GE refresh
uint32_t timeOut; // reserved
uint64_t reserved;
};
#pragma pack(pop)


+ 10
- 9
third_party/fwkacllib/inc/cce/taskdown_common.hpp View File

@@ -27,15 +27,16 @@ namespace cce {
#define CC_FUSION_OP_MAX 32

typedef enum tagccKernelType {
CCE_AI_CORE = 0, /* cce aicore */
CCE_AI_CPU = 1, /* cce aicpu */
TE = 2, /* te operator*/
CUSTOMIZED = 3, /* customized operator */
TE_AI_CORE = 4, /* te aicore operator*/
TE_AI_CPU = 5, /* te aicpu operator */
AI_CPU = 6, /* aicpu */
CUST_AI_CPU = 7, /* custom aicpu*/
INVALID = 8, /* unknown kernel type */
CCE_AI_CORE = 0, /* cce aicore */
CCE_AI_CPU = 1, /* cce aicpu */
TE = 2, /* te operator*/
CUSTOMIZED = 3, /* customized operator */
TE_AI_CORE = 4, /* te aicore operator*/
TE_AI_CPU = 5, /* te aicpu operator */
AI_CPU = 6, /* aicpu */
CUST_AI_CPU = 7, /* custom aicpu*/
HOST_CPU = 8, /* host cpu */
INVALID = 10000 /* unknown kernel type */
} ccKernelType;

typedef struct tagOpContext {


+ 52
- 0
third_party/fwkacllib/inc/common/type_def.h View File

@@ -0,0 +1,52 @@
/**
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:interface.
* Create: 2021-12-21
*/
#ifndef AICPU_TYPE_DEF_H
#define AICPU_TYPE_DEF_H

#include <cstdint>
#include <cstddef>
#ifndef char_t
typedef char char_t;
#endif

#ifndef float32_t
typedef float float32_t;
#endif

#ifndef float64_t
typedef double float64_t;
#endif

inline uint64_t PtrToValue(const void *ptr)
{
return static_cast<const uint64_t>(reinterpret_cast<const uintptr_t>(ptr));
}

inline void *ValueToPtr(const uint64_t value)
{
return reinterpret_cast<void *>(static_cast<const uintptr_t>(value));
}

template<typename TI, typename TO>
inline TO *PtrToPtr(TI *ptr)
{
return reinterpret_cast<TO *>(ptr);
}

template<typename T>
inline T *PtrAdd(T * const ptr, const size_t maxIdx, const size_t idx)
{
if ((ptr != nullptr) && (idx < maxIdx)) {
return reinterpret_cast<T *>(ptr + idx);
}
return nullptr;
}
#endif // AICPU_TYPE_DEF_H

+ 15
- 1
third_party/fwkacllib/inc/external/runtime/rt_error_codes.h View File

@@ -39,6 +39,7 @@ static const int32_t ACL_ERROR_RT_INVALID_MEMORY_TYPE = 107016; // invali
static const int32_t ACL_ERROR_RT_INVALID_HANDLE = 107017; // invalid handle
static const int32_t ACL_ERROR_RT_INVALID_MALLOC_TYPE = 107018; // invalid malloc type
static const int32_t ACL_ERROR_RT_WAIT_TIMEOUT = 107019; // wait timeout
static const int32_t ACL_ERROR_RT_TASK_TIMEOUT = 107020; // task timeout
static const int32_t ACL_ERROR_RT_FEATURE_NOT_SUPPORT = 207000; // feature not support
static const int32_t ACL_ERROR_RT_MEMORY_ALLOCATION = 207001; // memory allocation error
@@ -52,6 +53,12 @@ static const int32_t ACL_ERROR_RT_NO_STREAM_RESOURCE = 207008; // no str
static const int32_t ACL_ERROR_RT_NO_NOTIFY_RESOURCE = 207009; // no notify resource
static const int32_t ACL_ERROR_RT_NO_MODEL_RESOURCE = 207010; // no model resource
static const int32_t ACL_ERROR_RT_NO_CDQ_RESOURCE = 207011; // no cdq resource
static const int32_t ACL_ERROR_RT_OVER_LIMIT = 207012; // over limit
static const int32_t ACL_ERROR_RT_QUEUE_EMPTY = 207013; // queue is empty
static const int32_t ACL_ERROR_RT_QUEUE_FULL = 207014; // queue is full
static const int32_t ACL_ERROR_RT_REPEATED_INIT = 207015; // repeated init
static const int32_t ACL_ERROR_RT_AIVEC_OVER_FLOW = 207016; // aivec over flow
static const int32_t ACL_ERROR_RT_OVER_FLOW = 207017; // common over flow
static const int32_t ACL_ERROR_RT_INTERNAL_ERROR = 507000; // runtime internal error
static const int32_t ACL_ERROR_RT_TS_ERROR = 507001; // ts internel error
@@ -91,6 +98,14 @@ static const int32_t ACL_ERROR_RT_VECTOR_CORE_TIMEOUT = 507034; // vector
static const int32_t ACL_ERROR_RT_VECTOR_CORE_EXCEPTION = 507035; // vector core exception
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_EXCEPTION = 507036; // vector core trap exception
static const int32_t ACL_ERROR_RT_CDQ_BATCH_ABNORMAL = 507037; // cdq alloc batch abnormal
static const int32_t ACL_ERROR_RT_DIE_MODE_CHANGE_ERROR = 507038; // can not change die mode
static const int32_t ACL_ERROR_RT_DIE_SET_ERROR = 507039; // single die mode can not set die
static const int32_t ACL_ERROR_RT_INVALID_DIEID = 507040; // invalid die id
static const int32_t ACL_ERROR_RT_DIE_MODE_NOT_SET = 507041; // die mode not set
static const int32_t ACL_ERROR_RT_AICORE_TRAP_READ_OVERFLOW = 507042; // aic trap read overflow
static const int32_t ACL_ERROR_RT_AICORE_TRAP_WRITE_OVERFLOW = 507043; // aic trap write overflow
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_READ_OVERFLOW = 507044; // aiv trap read overflow
static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_WRITE_OVERFLOW = 507045; // aiv trap write overflow
static const int32_t ACL_ERROR_RT_DRV_INTERNAL_ERROR = 507899; // drv internal error
static const int32_t ACL_ERROR_RT_AICPU_INTERNAL_ERROR = 507900; // aicpu internal error
@@ -99,5 +114,4 @@ static const int32_t ACL_ERROR_RT_SOCKET_CLOSE = 507901; // hdc di
#ifdef __cplusplus
}
#endif
#endif // __INC_EXTERNEL_RT_ERROR_CODES_H__

+ 84
- 18
third_party/fwkacllib/inc/hccl/base.h View File

@@ -86,6 +86,47 @@ enum OriginalGraphShapeType {
SHAPE_RESERVED /**< reserved */
};

enum HcclEventType {
HCCL_EVENT_SEND_COMPLETION = 0,
HCCL_EVENT_RECV_REQUEST,
HCCL_EVENT_RECV_COMPLETION,
HCCL_EVENT_CONGESTION_RELIEF,
HCCL_EVENT_RESERVED /**< reserved */
};

const u32 TAG_MAX_LEN = 127; // 最大的tag 长度
using TagAttr = struct TagAttrDef {
char name[TAG_MAX_LEN + 1]; // tag标识
// tag标识的接收数据,调用者是否会主动调用接收接口,0 = 否, 1 = 会(预留,暂不支持)。
// 对于activeRecv = 0,当接收侧收到数据或者发送请求时,主动通知调用者。
uint32_t activeRecv;
uint32_t sendCredit; // 配置该tag允许inflight的send个数
uint32_t eventId;
};

using HcclEventMsg = struct HcclEventMsgDef {
HcclComm comm;
u32 peerRank;
u32 tag;
// 0:HCCL_SEND_COMPLETION; 1:HCCL_RECV_COMPLETION; 2:HCCL_RECV_REQUEST; 3:HCCL_CONGESTION_RELIEF
u32 hcclEventType;
union {
struct {
u32 reserver;
} sendCompletionItem;
struct {
u32 reserver;
} recvRequestItem;
struct {
u32 reserver;
} recvCompletionItem;
struct CongestionReliefItem {
u32 reserver;
} congestionReliefItem;
} desc;
};


/**
* @brief stream handle.
*/
@@ -124,29 +165,54 @@ struct HcomRemoteAccessAddrInfo {
};

struct HcomAllToAllVParams {
void *sendbuf;
void *sendcounts;
void *sdispls;
HcclDataType sendtype;
void *recvbuf;
void *recvcounts;
void *rdispls;
HcclDataType recvtype;
const char *group;
void *sendbuf; // device mem
void *sendcounts; // device mem; Type: uint_64
void *sdispls; // device mem; Type: uint_64
HcclDataType sendtype;
void *recvbuf; // device mem
void *recvcounts; // device mem; Type: uint_64
void *rdispls; // device mem; Type: uint_64
HcclDataType recvtype;
const char *group; // not used now
};

struct HcomGatherAllToAllVParams {
void *addrInfo;
void *addrInfoCountPerRank;
void *recvbuf;
void *recvcounts;
void *rdispls;
void *gatheredbuf;
s32 addrLength;
HcclDataType recvtype;
const char *group;
void *addrInfo; // device mem; contains host VA[uint_64]: [addr, length, addr, length, addr, length, ...]
void *addrInfoCountPerRank; // device mem; length: ranksize; contains addrInfoCounts for every rank
void *recvbuf; // device mem
void *recvcounts; // device mem; Type: uint_64
void *rdispls; // device mem; Type: uint_64
void *gatheredbuf; // device mem
s32 addrLength;
HcclDataType recvtype;
const char *group; // not used now
};

typedef enum workMode {
HCCL_MODE_NORMAL = 0, // 不支持任何Probe any,仅支持精确的probe
HCCL_MODE_ANY = 1 // 仅支持ANY_SOURCE + ANY_TAG的probe
} WorkMode;

typedef struct tagCommAttr {
WorkMode mode; // 通信域内的probe工作模式
uint32_t deviceId = 0;
} CommAttr;

typedef void* HcclMessage;
typedef void* HcclRequest;

typedef struct {
int srcRank; // 接收/探测到的msg/信封的发送端rank_id,MPI标准定义,调用者可以访问
int tag; // 接收/探测到的msg/信封的tag,MPI标准定义,调用者可以访问
int error; // 接收/探测的错误码0:no error,others:传输过程出错,MPI标准定义,调用者可以访问
int cancelled; // 指定实现,不建议调用者访问
int count; // 接收/探测到的payload大小,指定实现,不建议调用者访问
} HcclStatus;

#define HCCL_REQUEST_NULL NULL

#define HCCL_TAG_ANY (1 << 30)

#ifdef __cplusplus
}
#endif // __cplusplus


+ 0
- 101
third_party/fwkacllib/inc/hccl/hccl_types.h View File

@@ -1,101 +0,0 @@
/**
* Copyright 2019-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.
*/

/**
* @file hccl_types.h
* @brief HCCL data type definition
*
*/
#ifndef HCCL_TYPES_H_
#define HCCL_TYPES_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
* @brief HCCL functions return value definition
*/
typedef enum {
HCCL_SUCCESS = 0, /**< success */
HCCL_E_PARA = 1, /**< parameter error */
HCCL_E_PTR = 2, /**< empty pointer */
HCCL_E_MEMORY = 3, /**< memory error */
HCCL_E_INTERNAL = 4, /**< internal error */
HCCL_E_NOT_SUPPORT = 5, /**< not support feature */
HCCL_E_NOT_FOUND = 6, /**< not found specific resource */
HCCL_E_UNAVAIL = 7, /**< resource unavailable */
HCCL_E_SYSCALL = 8, /**< call system interface error */
HCCL_E_TIMEOUT = 9, /**< timeout */
HCCL_E_OPEN_FILE_FAILURE = 10, /**< open file fail */
HCCL_E_TCP_CONNECT = 11, /**< tcp connect fail */
HCCL_E_ROCE_CONNECT = 12, /**< roce connect fail */
HCCL_E_TCP_TRANSFER = 13, /**< tcp transfer fail */
HCCL_E_ROCE_TRANSFER = 14, /**< roce transfer fail */
HCCL_E_RUNTIME = 15, /**< call runtime api fail */
HCCL_E_DRV = 16, /**< call driver api fail */
HCCL_E_PROFILING = 17, /**< call profiling api fail */
HCCL_E_CCE = 18, /**< call cce api fail */
HCCL_E_NETWORK = 19, /**< call network api fail */
HCCL_E_RESERVED /**< reserved */
} HcclResult;

/**
* @brief handle to HCCL communicator
*/
typedef void *HcclComm;

/**
* @brief HCCL Reduction opperation
*/
typedef enum {
HCCL_REDUCE_SUM = 0, /**< sum */
HCCL_REDUCE_PROD = 1, /**< prod */
HCCL_REDUCE_MAX = 2, /**< max */
HCCL_REDUCE_MIN = 3, /**< min */
HCCL_REDUCE_RESERVED /**< reserved */
} HcclReduceOp;

/**
* @brief HCCL data type
*/
typedef enum {
HCCL_DATA_TYPE_INT8 = 0, /**< int8 */
HCCL_DATA_TYPE_INT16 = 1, /**< int16 */
HCCL_DATA_TYPE_INT32 = 2, /**< int32 */
HCCL_DATA_TYPE_FP16 = 3, /**< fp16 */
HCCL_DATA_TYPE_FP32 = 4, /**< fp32 */
HCCL_DATA_TYPE_INT64 = 5, /**< int64 */
HCCL_DATA_TYPE_UINT64 = 6, /**< uint64 */
HCCL_DATA_TYPE_RESERVED /**< reserved */
} HcclDataType;

const uint32_t HCCL_ROOT_INFO_BYTES = 4108; // 4108: root info length

/**
* @brief HCCL root info
*/
typedef struct HcclRootInfoDef {
char internal[HCCL_ROOT_INFO_BYTES];
} HcclRootInfo;

#ifdef __cplusplus
}
#endif // __cplusplus
#endif // HCCL_TYPES_H_

+ 0
- 52
third_party/fwkacllib/inc/hccl/hcom.h View File

@@ -126,58 +126,6 @@ extern HcclResult HcomSetGradFusionByIndex(const char *group, u32 segmentNum, co
* @return HcclResult
*/
extern HcclResult HcomSetGradFusionBySize(const char *group, u32 segmentNum, const float *sizeList);

/**
* @brief Initialize hcom executor.
*
* @param void
* @return HcclResult
*/
HcclResult HcomExecInitialize();

/**
* @brief Finalize hcom executor.
*
* @param void
* @return HcclResult
*/
HcclResult HcomExecFinalize();

/**
* @brief Put collective communication operation into hcom executor.
*
* @param opInfo information about collective communication operation.
* @param callback callback after collective communication operation.
* @return HcclResult
*/
HcclResult HcomExecEnqueueOperation(HcomOperation opInfo, std::function<void(HcclResult status)> callback);

/**
* @brief Put remote access operation into hcom executor.
*
* @param remoteAccessType operation type (read or write).
* @param addrInfos address information about collective communication operation.
* @param callback callback after collective communication operation.
* @return HcclResult
*/
HcclResult HcomExecEnqueueRemoteAccess(const std::string& remoteAccessType,
const std::vector<HcomRemoteAccessAddrInfo>& addrInfos,
std::function<void(HcclResult status)> callback);

HcclResult HcomExecEnqueueAllToAllV(HcomAllToAllVParams params, std::function<void(HcclResult status)> callback);

HcclResult HcomExecEnqueueGatherAllToAllV(HcomGatherAllToAllVParams params,
std::function<void(HcclResult status)> callback);

/**
* @brief Register memories and init resources for remote access.
*
* @param addrList memory addresses for remote access.
* @param count number of remote memory addresses.
* @return HcclResult
*/
extern HcclResult HcomRegRemoteAccessMem(const MemRegisterAddr* addrList, u32 count);

#ifdef __cplusplus
}
#endif // __cplusplus


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save