forked from huawei/mindspore2022
fix code check
This commit is contained in:
parent
c5142f742d
commit
4838e8f6bd
|
|
@ -54,7 +54,7 @@ static size_t GenFusionJsonHash(const nlohmann::json &fusion_json) {
|
|||
|
||||
std::map<int64_t, KernelModPtr> KernelFusion(const std::vector<FusionScopeInfo> &fusion_scopes) {
|
||||
std::map<int64_t, KernelModPtr> kernel_mod_ret;
|
||||
static std::set<std::string> processed_fusion_kernel;
|
||||
static std::set<std::string> processed_fusion_kernel = {};
|
||||
auto build_manger = std::make_shared<ParallelBuildManager>();
|
||||
MS_EXCEPTION_IF_NULL(build_manger);
|
||||
auto context_ptr = MsContext::GetInstance();
|
||||
|
|
@ -94,8 +94,7 @@ std::map<int64_t, KernelModPtr> KernelFusion(const std::vector<FusionScopeInfo>
|
|||
// search cache
|
||||
auto kernel_pack = TbeUtils::SearchCache(json_name, tbe::kProcessorAiCore);
|
||||
if (kernel_pack != nullptr && ((!offline_tune.empty() && offline_tune != "true") || tune_mode == "NO_TUNE")) {
|
||||
auto kernel_mod =
|
||||
build_manger->GenKernelMod(json_name, tbe::kProcessorAiCore, input_size_list, output_size_list, kernel_pack);
|
||||
auto kernel_mod = build_manger->GenKernelMod(input_size_list, output_size_list, kernel_pack);
|
||||
if (kernel_mod != nullptr) {
|
||||
kernel_mod_ret[fusion_scope_iter.scope_id] = kernel_mod;
|
||||
continue;
|
||||
|
|
@ -118,7 +117,7 @@ std::map<int64_t, KernelModPtr> KernelFusion(const std::vector<FusionScopeInfo>
|
|||
nlohmann::json fusion_json;
|
||||
fusion_json["fusion_op"] = fusion_op;
|
||||
fusion_json["SocInfo"] = soc_info_json;
|
||||
auto task_id = build_manger->StartCompileOp(fusion_json);
|
||||
auto task_id = ParallelBuildManager::StartCompileOp(fusion_json);
|
||||
TbeUtils::SaveJsonInfo(json_name, fusion_json.dump());
|
||||
if (task_id < 0) {
|
||||
MS_EXCEPTION(ArgumentError) << "start compile failed.";
|
||||
|
|
@ -132,7 +131,7 @@ std::map<int64_t, KernelModPtr> KernelFusion(const std::vector<FusionScopeInfo>
|
|||
int task_id = -1;
|
||||
std::string task_result;
|
||||
std::string build_result;
|
||||
auto ret = build_manger->WaitOne(&task_id, &task_result, &build_result);
|
||||
auto ret = ParallelBuildManager::WaitOne(&task_id, &task_result, &build_result);
|
||||
if (!ret) {
|
||||
MS_EXCEPTION(ArgumentError) << "Build Failed. wait one ret:" << ret << ", task id:" << task_id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,15 +108,15 @@ void TbeAdapter::FusionDataOrderPass(const std::string &op_name, const std::vect
|
|||
(void)std::copy(data_layer.begin(), data_layer.end(), std::back_inserter((*reorder_data_layer)));
|
||||
} else {
|
||||
if (op_name == "MinimumGrad" || op_name == "MaximumGrad") {
|
||||
reorder_data_layer->emplace_back(data_layer[INPUT2]);
|
||||
reorder_data_layer->emplace_back(data_layer[INPUT0]);
|
||||
reorder_data_layer->emplace_back(data_layer[INPUT1]);
|
||||
(void)reorder_data_layer->emplace_back(data_layer[INPUT2]);
|
||||
(void)reorder_data_layer->emplace_back(data_layer[INPUT0]);
|
||||
(void)reorder_data_layer->emplace_back(data_layer[INPUT1]);
|
||||
for (size_t i = 3; i < data_layer.size(); ++i) {
|
||||
reorder_data_layer->emplace_back(data_layer[i]);
|
||||
(void)reorder_data_layer->emplace_back(data_layer[i]);
|
||||
}
|
||||
} else {
|
||||
reorder_data_layer->emplace_back(data_layer[INPUT1]);
|
||||
reorder_data_layer->emplace_back(data_layer[INPUT0]);
|
||||
(void)reorder_data_layer->emplace_back(data_layer[INPUT1]);
|
||||
(void)reorder_data_layer->emplace_back(data_layer[INPUT0]);
|
||||
for (size_t i = 2; i < data_layer.size(); ++i) {
|
||||
reorder_data_layer->emplace_back(data_layer[i]);
|
||||
}
|
||||
|
|
@ -169,24 +169,32 @@ void TbeAdapter::MaxiOrMinimumGradAttrJsonPass(const AnfNodePtr &anf_node,
|
|||
}
|
||||
|
||||
static int TypeStrToDstType(const std::string &type_str) {
|
||||
constexpr int kInvalid = -1;
|
||||
constexpr int kFloat = 0;
|
||||
constexpr int kFloat16 = 1;
|
||||
constexpr int kInt8 = 2;
|
||||
constexpr int kInt32 = 3;
|
||||
constexpr int kUint8 = 4;
|
||||
constexpr int kUint64 = 10;
|
||||
constexpr int kBool = 12;
|
||||
if (type_str == "Float" || type_str == "Float32") {
|
||||
return 0;
|
||||
return kFloat;
|
||||
} else if (type_str == "Float16") {
|
||||
return 1;
|
||||
return kFloat16;
|
||||
} else if (type_str == "Int8") {
|
||||
return 2;
|
||||
return kInt8;
|
||||
} else if (type_str == "Int32") {
|
||||
return 3;
|
||||
return kInt32;
|
||||
} else if (type_str == "UInt8") {
|
||||
return 4;
|
||||
return kUint8;
|
||||
} else if (type_str == "UInt64") {
|
||||
return 10;
|
||||
return kUint64;
|
||||
} else if (type_str == "Bool") {
|
||||
return 12;
|
||||
return kBool;
|
||||
} else {
|
||||
MS_LOG(INFO) << "Error type str is invailed: " << type_str;
|
||||
}
|
||||
return -1;
|
||||
return kInvalid;
|
||||
}
|
||||
|
||||
void TbeAdapter::CastAttrJsonPass(const mindspore::AnfNodePtr &anf_node,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#include "utils/ms_context.h"
|
||||
#include "runtime/dev.h"
|
||||
#include "utils/trace_base.h"
|
||||
#include "utils/convert_utils_base.h"
|
||||
#include "utils/ms_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
|
|
@ -469,7 +470,7 @@ void TbeKernelJsonCreator::GenOutputList(const std::shared_ptr<AnfNode> &anf_nod
|
|||
}
|
||||
}
|
||||
|
||||
bool TbeKernelJsonCreator::GenTbeAttrJson(const std::shared_ptr<AnfNode> &anf_node,
|
||||
void TbeKernelJsonCreator::GenTbeAttrJson(const std::shared_ptr<AnfNode> &anf_node,
|
||||
const std::shared_ptr<OpInfo> &op_info, nlohmann::json *attrs_json) {
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
MS_EXCEPTION_IF_NULL(op_info);
|
||||
|
|
@ -477,7 +478,7 @@ bool TbeKernelJsonCreator::GenTbeAttrJson(const std::shared_ptr<AnfNode> &anf_no
|
|||
auto attrs_ptr = op_info->attrs_ptr();
|
||||
std::string op_name = AnfAlgo::GetCNodeName(anf_node);
|
||||
if (TbeAdapter::RunAttrPass(anf_node, attrs_ptr, attrs_json)) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
auto primitive = AnfAlgo::GetCNodePrimitive(anf_node);
|
||||
MS_EXCEPTION_IF_NULL(primitive);
|
||||
|
|
@ -491,7 +492,10 @@ bool TbeKernelJsonCreator::GenTbeAttrJson(const std::shared_ptr<AnfNode> &anf_no
|
|||
if (primitive->GetAttr(attr_name) != nullptr) {
|
||||
auto value = primitive->GetAttr(attr_name);
|
||||
std::string type = attr_ptr->type();
|
||||
ParseAttrValue(type, value, &attr_obj);
|
||||
if (!ParseAttrValue(type, value, &attr_obj)) {
|
||||
MS_LOG(EXCEPTION) << "Op name: " << op_info->op_name() << " attr: " << attr_name
|
||||
<< ", node debug: " << anf_node->DebugString(2);
|
||||
}
|
||||
attr_obj[kJValid] = true;
|
||||
} else {
|
||||
auto default_value = attr_ptr->default_value();
|
||||
|
|
@ -515,12 +519,11 @@ bool TbeKernelJsonCreator::GenTbeAttrJson(const std::shared_ptr<AnfNode> &anf_no
|
|||
}
|
||||
(*attrs_json).push_back(attr_obj);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string TbeKernelJsonCreator::GetSocVersion() {
|
||||
// Get default soc version.
|
||||
static std::string version;
|
||||
static std::string version = "";
|
||||
if (version.empty()) {
|
||||
const int kSocVersionLen = 50;
|
||||
char soc_version[kSocVersionLen] = {0};
|
||||
|
|
@ -550,10 +553,43 @@ string TbeKernelJsonCreator::GetSocVersion() {
|
|||
return version;
|
||||
}
|
||||
|
||||
void TbeKernelJsonCreator::ParseAttrValue(const std::string &type, const mindspore::ValuePtr &value,
|
||||
bool ParseListIntAttrValue(const mindspore::ValuePtr &value, nlohmann::json *attr_obj) {
|
||||
std::vector<int64_t> attr_value;
|
||||
auto value_type = value->type();
|
||||
if (!value_type) {
|
||||
MS_LOG(ERROR) << "value_type is null.";
|
||||
return false;
|
||||
}
|
||||
auto value_type_str = value_type->ToString();
|
||||
if (value_type_str == kVTypeInt64) {
|
||||
auto data = GetValue<int64_t>(value);
|
||||
attr_value.push_back(data);
|
||||
} else {
|
||||
auto vec = value->isa<ValueTuple>() ? value->cast<ValueTuplePtr>()->value() : value->cast<ValueListPtr>()->value();
|
||||
if (!vec.empty()) {
|
||||
if (vec[0]->isa<Int32Imm>()) {
|
||||
std::vector<int32_t> attr_value_me = GetValue<std::vector<int32_t>>(value);
|
||||
(void)std::transform(attr_value_me.begin(), attr_value_me.end(), std::back_inserter(attr_value),
|
||||
[](const int &value) { return static_cast<int64_t>(value); });
|
||||
} else {
|
||||
attr_value = GetValue<std::vector<int64_t>>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
(*attr_obj)[kJValue] = attr_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TbeKernelJsonCreator::ParseAttrValue(const std::string &type, const mindspore::ValuePtr &value,
|
||||
nlohmann::json *attr_obj) {
|
||||
MS_EXCEPTION_IF_NULL(value);
|
||||
MS_EXCEPTION_IF_NULL(attr_obj);
|
||||
if (!value) {
|
||||
MS_LOG(ERROR) << "value ptr is null.";
|
||||
return false;
|
||||
}
|
||||
if (!attr_obj) {
|
||||
MS_LOG(ERROR) << "attr_obj ptr is null.";
|
||||
return false;
|
||||
}
|
||||
if (type == kVTypeInt) {
|
||||
if (value->isa<Int32Imm>()) {
|
||||
(*attr_obj)[kJValue] = GetValue<int>(value);
|
||||
|
|
@ -573,31 +609,16 @@ void TbeKernelJsonCreator::ParseAttrValue(const std::string &type, const mindspo
|
|||
} else if (type == kVTypeFloat) {
|
||||
(*attr_obj)[kJValue] = GetValue<float>(value);
|
||||
} else if (type == kVTypeListInt) {
|
||||
std::vector<int64_t> attr_value;
|
||||
auto value_type = value->type();
|
||||
MS_EXCEPTION_IF_NULL(value_type);
|
||||
auto value_type_str = value_type->ToString();
|
||||
if (value_type_str == kVTypeInt64) {
|
||||
auto data = GetValue<int64_t>(value);
|
||||
attr_value.push_back(data);
|
||||
} else {
|
||||
auto vec =
|
||||
value->isa<ValueTuple>() ? value->cast<ValueTuplePtr>()->value() : value->cast<ValueListPtr>()->value();
|
||||
if (!vec.empty()) {
|
||||
if (vec[0]->isa<Int32Imm>()) {
|
||||
std::vector<int32_t> attr_value_me = GetValue<std::vector<int32_t>>(value);
|
||||
(void)std::transform(attr_value_me.begin(), attr_value_me.end(), std::back_inserter(attr_value),
|
||||
[](const int &value) { return static_cast<int64_t>(value); });
|
||||
} else {
|
||||
attr_value = GetValue<std::vector<int64_t>>(value);
|
||||
}
|
||||
}
|
||||
if (!ParseListIntAttrValue(value, attr_obj)) {
|
||||
return false;
|
||||
}
|
||||
(*attr_obj)[kJValue] = attr_value;
|
||||
} else if (type == kVTypeListFloat) {
|
||||
std::vector<float> attr_value;
|
||||
auto value_type = value->type();
|
||||
MS_EXCEPTION_IF_NULL(value_type);
|
||||
if (!attr_obj) {
|
||||
MS_LOG(ERROR) << "attr_obj ptr is null.";
|
||||
return false;
|
||||
}
|
||||
auto value_type_str = value_type->ToString();
|
||||
if (value_type_str == kVTypeFloat) {
|
||||
auto data = GetValue<float>(value);
|
||||
|
|
@ -611,8 +632,10 @@ void TbeKernelJsonCreator::ParseAttrValue(const std::string &type, const mindspo
|
|||
} else if (type == kVTypeListListInt) {
|
||||
(*attr_obj)[kJValue] = GetValue<std::vector<std::vector<int64_t>>>(value);
|
||||
} else {
|
||||
MS_LOG(EXCEPTION) << "Type: " << type << "not support";
|
||||
MS_LOG(ERROR) << "Type: " << type << "not support";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TbeKernelJsonCreator::ParseAttrDefaultValue(const std::string &type, const std::string &value,
|
||||
|
|
@ -733,7 +756,6 @@ void GetInputSizeList(const nlohmann::json &input_json, std::vector<size_t> *inp
|
|||
for (size_t m = 0; m < input_json[i].size(); m++) {
|
||||
size_t size_i = 1;
|
||||
if (input_json[i][m][kJValid] == false) {
|
||||
std::string input_name = input_json[i][m][kJName];
|
||||
continue;
|
||||
}
|
||||
for (size_t j = 0; j < input_json[i][m][kJShape].size(); ++j) {
|
||||
|
|
@ -743,7 +765,7 @@ void GetInputSizeList(const nlohmann::json &input_json, std::vector<size_t> *inp
|
|||
MS_LOG(EXCEPTION) << "Invalid Dynamic Shape Max Shape";
|
||||
}
|
||||
MS_LOG(INFO) << "Change -1 Shape to Max Shape:" << input_max_shape[j];
|
||||
size_i *= input_max_shape[j];
|
||||
size_i *= LongToSize(input_max_shape[j]);
|
||||
continue;
|
||||
}
|
||||
size_i *= static_cast<size_t>(input_json[i][m][kJShape][j]);
|
||||
|
|
@ -773,7 +795,7 @@ void GetOutputSizeList(const nlohmann::json &output_json, std::vector<size_t> *o
|
|||
MS_LOG(EXCEPTION) << "Invalid Dynamic Shape Max Shape";
|
||||
}
|
||||
MS_LOG(INFO) << "Change -1 Shape to Max Shape:" << output_max_shape[j];
|
||||
size_i *= output_max_shape[j];
|
||||
size_i *= LongToSize(output_max_shape[j]);
|
||||
continue;
|
||||
}
|
||||
size_i *= static_cast<size_t>(output_json[i][m][kJShape][j]);
|
||||
|
|
@ -874,9 +896,7 @@ void TbeKernelBuild::GenFusionComputeCommonJson(const mindspore::CNodePtr &cnode
|
|||
// attr_desc
|
||||
TbeKernelJsonCreator json_creater(SINGLE_BUILD);
|
||||
nlohmann::json json_attr_args;
|
||||
if (!json_creater.GenTbeAttrJson(cnode, op_info_ptr, &json_attr_args)) {
|
||||
MS_LOG(INFO) << "Fusion warning: get prebuild args of attr failed.";
|
||||
}
|
||||
json_creater.GenTbeAttrJson(cnode, op_info_ptr, &json_attr_args);
|
||||
nlohmann::json attr_desc;
|
||||
for (const auto &attr : json_attr_args) {
|
||||
if (attr[kJName] != "isRef" && attr[kJValid] == true) {
|
||||
|
|
@ -950,17 +970,17 @@ void TbeKernelBuild::GenDescJson(const std::shared_ptr<mindspore::AnfNode> &anf_
|
|||
constexpr size_t C0 = 16;
|
||||
if ((fusion_data_type == kFusionAddN || fusion_data_type == kFusionAdd) && shape.size() == 5) {
|
||||
std::vector<size_t> spec_shape = {};
|
||||
spec_shape.emplace_back(shape[DIM0]);
|
||||
spec_shape.emplace_back(shape[DIM1]);
|
||||
spec_shape.emplace_back(shape[DIM2] * shape[DIM3]);
|
||||
spec_shape.emplace_back(shape[DIM4]);
|
||||
(void)spec_shape.emplace_back(shape[DIM0]);
|
||||
(void)spec_shape.emplace_back(shape[DIM1]);
|
||||
(void)spec_shape.emplace_back(shape[DIM2] * shape[DIM3]);
|
||||
(void)spec_shape.emplace_back(shape[DIM4]);
|
||||
(*output_desc)[kJShape] = spec_shape;
|
||||
} else if (fusion_data_type == kFusionReLUGradV2) {
|
||||
std::vector<size_t> spec_shape = {};
|
||||
spec_shape.emplace_back(shape[DIM0]);
|
||||
spec_shape.emplace_back(shape[DIM1]);
|
||||
spec_shape.emplace_back(shape[DIM2] * shape[DIM3]);
|
||||
spec_shape.emplace_back(C0);
|
||||
(void)spec_shape.emplace_back(shape[DIM0]);
|
||||
(void)spec_shape.emplace_back(shape[DIM1]);
|
||||
(void)spec_shape.emplace_back(shape[DIM2] * shape[DIM3]);
|
||||
(void)spec_shape.emplace_back(C0);
|
||||
(*output_desc)[kJShape] = spec_shape;
|
||||
(*output_desc)[kJDataType] = kVTypeBool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class TbeKernelJsonCreator {
|
|||
~TbeKernelJsonCreator() = default;
|
||||
bool GenTbeSingleKernelJson(const std::shared_ptr<AnfNode> &anf_node, nlohmann::json *kernel_json);
|
||||
std::string json_name() { return json_name_; }
|
||||
bool GenTbeAttrJson(const std::shared_ptr<AnfNode> &anf_node, const std::shared_ptr<OpInfo> &op_info,
|
||||
void GenTbeAttrJson(const std::shared_ptr<AnfNode> &anf_node, const std::shared_ptr<OpInfo> &op_info,
|
||||
nlohmann::json *attrs_json);
|
||||
static string GetSocVersion();
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ class TbeKernelJsonCreator {
|
|||
bool GenTbeOutputsJson(const std::shared_ptr<AnfNode> &anf_node, const std::shared_ptr<OpInfo> &op_info,
|
||||
nlohmann::json *outputs_json);
|
||||
void GenSocInfo(nlohmann::json *soc_info_json);
|
||||
static void ParseAttrValue(const std::string &type, const ValuePtr &value, nlohmann::json *attr_obj);
|
||||
static bool ParseAttrValue(const std::string &type, const ValuePtr &value, nlohmann::json *attr_obj);
|
||||
static void ParseAttrDefaultValue(const std::string &type, const std::string &value, nlohmann::json *attr_obj);
|
||||
bool GenInputDescJson(const std::shared_ptr<AnfNode> &anf_node, size_t real_input_index, bool value,
|
||||
const std::shared_ptr<OpIOInfo> &input_ptr, const string &op_input_name, size_t input_i,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ using mindspore::kernel::tbe::TbeUtils;
|
|||
bool TbeOpParallelBuild(const std::vector<AnfNodePtr> &anf_nodes) {
|
||||
auto build_manger = std::make_shared<ParallelBuildManager>();
|
||||
MS_EXCEPTION_IF_NULL(build_manger);
|
||||
static std::set<std::string> processed_kernel;
|
||||
static std::set<std::string> processed_kernel = {};
|
||||
auto context_ptr = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context_ptr);
|
||||
auto tune_mode = context_ptr->get_param<std::string>(MS_CTX_TUNE_MODE);
|
||||
|
|
@ -82,14 +82,14 @@ bool TbeOpParallelBuild(const std::vector<AnfNodePtr> &anf_nodes) {
|
|||
(void)processed_kernel.insert(json_name);
|
||||
// op build
|
||||
TbeUtils::SaveJsonInfo(kernel_json["op_info"]["kernel_name"], kernel_json.dump());
|
||||
auto task_id = build_manger->StartCompileOp(kernel_json);
|
||||
auto task_id = ParallelBuildManager::StartCompileOp(kernel_json);
|
||||
build_manger->SaveTaskInfo(task_id, anf_node, json_name, input_size_list, output_size_list);
|
||||
}
|
||||
while (!build_manger->IsAllTaskFinish()) {
|
||||
int task_id = -1;
|
||||
std::string task_result;
|
||||
std::string build_result;
|
||||
auto ret = build_manger->WaitOne(&task_id, &task_result, &build_result);
|
||||
auto ret = ParallelBuildManager::WaitOne(&task_id, &task_result, &build_result);
|
||||
if (!ret) {
|
||||
MS_EXCEPTION(ArgumentError) << "Build Failed. wait one ret:" << ret << ", task id:" << task_id
|
||||
<< " trace: " << trace::DumpSourceLines(build_manger->GetAnfNodeByTaskID(task_id));
|
||||
|
|
@ -108,7 +108,7 @@ ParallelBuildManager::~ParallelBuildManager() { ResetTaskInfo(); }
|
|||
|
||||
void ParallelBuildManager::SaveTaskInfo(int32_t task_id, const mindspore::AnfNodePtr &anf_node,
|
||||
const std::string &json_name, const std::vector<size_t> &input_size_list,
|
||||
const std::vector<size_t> &output_size_list, int32_t scope_id) {
|
||||
const std::vector<size_t> &output_size_list, int64_t scope_id) {
|
||||
MS_LOG(INFO) << "SaveTaskInfo, task id: " << task_id;
|
||||
struct KernelBuildTaskInfo task_info;
|
||||
task_info.node = anf_node;
|
||||
|
|
@ -139,9 +139,9 @@ void ParallelBuildManager::PreTaskFinishProcess(int32_t task_id, const std::stri
|
|||
std::make_shared<kernel::KernelBuildInfo::KernelBuildInfoBuilder>(AnfAlgo::GetSelectKernelBuildInfo(node));
|
||||
std::string start_flag = "fusion_pattern_start";
|
||||
std::string end_flag = "fusion_pattern_end";
|
||||
int start = pre_build_result.find(start_flag);
|
||||
int end = pre_build_result.find(end_flag);
|
||||
if (start != -1 && end != -1 && end >= start) {
|
||||
auto start = pre_build_result.find(start_flag);
|
||||
auto end = pre_build_result.find(end_flag);
|
||||
if (start != std::string::npos && end != std::string::npos && end >= start) {
|
||||
std::string result = pre_build_result.substr(start + start_flag.size(), end - start - start_flag.size());
|
||||
if (result.empty()) {
|
||||
(void)pre_task_map_.erase(task_iter);
|
||||
|
|
@ -175,8 +175,7 @@ std::pair<int32_t, KernelModPtr> ParallelBuildManager::TaskFinishProcess(int32_t
|
|||
return fusion_kernel_mod;
|
||||
}
|
||||
}
|
||||
auto kernel_mod = GenKernelMod(json_name, processor, task_iter->second.input_size_list,
|
||||
task_iter->second.output_size_list, kernel_pack);
|
||||
auto kernel_mod = GenKernelMod(task_iter->second.input_size_list, task_iter->second.output_size_list, kernel_pack);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod);
|
||||
if (set_kernel_mod) {
|
||||
AnfAlgo::SetKernelMod(kernel_mod, task_iter->second.node.get());
|
||||
|
|
@ -231,8 +230,7 @@ bool ParallelBuildManager::GenSameFusionOpKernelMod(std::map<int64_t, KernelModP
|
|||
for (const auto &task_info : same_op_list_) {
|
||||
auto kernel_pack = TbeUtils::SearchCache(task_info.json_name, tbe::kProcessorAiCore);
|
||||
if (kernel_pack != nullptr) {
|
||||
auto kernel_mode = GenKernelMod(task_info.json_name, tbe::kProcessorAiCore, task_info.input_size_list,
|
||||
task_info.output_size_list, kernel_pack);
|
||||
auto kernel_mode = GenKernelMod(task_info.input_size_list, task_info.output_size_list, kernel_pack);
|
||||
if (kernel_mode != nullptr) {
|
||||
(*kernel_mode_ret)[task_info.scope_id] = kernel_mode;
|
||||
continue;
|
||||
|
|
@ -249,7 +247,7 @@ bool ParallelBuildManager::SearchInCache(const std::string &json_name, const std
|
|||
const std::vector<size_t> &output_size_list, mindspore::AnfNode *node) const {
|
||||
auto cached_kernel_pack = TbeUtils::SearchCache(json_name, processor);
|
||||
if (cached_kernel_pack != nullptr) {
|
||||
auto kernel_mod_ptr = GenKernelMod(json_name, processor, input_size_list, output_size_list, cached_kernel_pack);
|
||||
auto kernel_mod_ptr = GenKernelMod(input_size_list, output_size_list, cached_kernel_pack);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod_ptr);
|
||||
AnfAlgo::SetKernelMod(kernel_mod_ptr, node);
|
||||
return true;
|
||||
|
|
@ -258,8 +256,7 @@ bool ParallelBuildManager::SearchInCache(const std::string &json_name, const std
|
|||
}
|
||||
}
|
||||
|
||||
KernelModPtr ParallelBuildManager::GenKernelMod(const string &json_name, const string &processor,
|
||||
const std::vector<size_t> &input_size_list,
|
||||
KernelModPtr ParallelBuildManager::GenKernelMod(const std::vector<size_t> &input_size_list,
|
||||
const std::vector<size_t> &output_size_list,
|
||||
const mindspore::kernel::KernelPackPtr &kernel_pack) const {
|
||||
MS_EXCEPTION_IF_NULL(kernel_pack);
|
||||
|
|
@ -282,7 +279,7 @@ bool ParallelBuildManager::WaitOne(int *task_id, std::string *task_result, std::
|
|||
return AscendKernelBuildClient::Instance().TbeWait(task_id, task_result, pre_build_result);
|
||||
}
|
||||
|
||||
void ParallelBuildManager::ResetTaskInfo() {
|
||||
void ParallelBuildManager::ResetTaskInfo() noexcept {
|
||||
if (task_map_.empty()) {
|
||||
MS_LOG(INFO) << "All tasks are compiled success.";
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class ParallelBuildManager {
|
|||
~ParallelBuildManager();
|
||||
void SaveTaskInfo(int32_t task_id, const AnfNodePtr &anf_node, const std::string &json_name,
|
||||
const std::vector<size_t> &input_size_list, const std::vector<size_t> &output_size_list,
|
||||
int32_t scope_id = 0);
|
||||
int64_t scope_id = 0);
|
||||
void SaveSameOpInfo(const AnfNodePtr &anf_node, const std::string &json_name,
|
||||
const std::vector<size_t> &input_size_list, const std::vector<size_t> &output_size_list);
|
||||
void SaveSameFusionOpInfo(const int64_t scope_id, const std::string &json_name, const std::string &processor,
|
||||
|
|
@ -59,14 +59,13 @@ class ParallelBuildManager {
|
|||
void PreTaskFinishProcess(int32_t task_id, const std::string &pre_build_result);
|
||||
std::pair<int32_t, KernelModPtr> TaskFinishProcess(int32_t task_id, const std::string &build_ret,
|
||||
bool set_kernel_mod = true);
|
||||
KernelModPtr GenKernelMod(const string &json_name, const string &processor,
|
||||
const std::vector<size_t> &input_size_list, const std::vector<size_t> &output_size_list,
|
||||
KernelModPtr GenKernelMod(const std::vector<size_t> &input_size_list, const std::vector<size_t> &output_size_list,
|
||||
const KernelPackPtr &kernel_pack) const;
|
||||
|
||||
// Interactive with real backend, who could be implemented by Python.
|
||||
static int StartCompileOp(const nlohmann::json &kernel_json);
|
||||
static bool WaitOne(int *task_id, std::string *task_result, std::string *build_result);
|
||||
void ResetTaskInfo();
|
||||
void ResetTaskInfo() noexcept;
|
||||
AnfNodePtr GetAnfNodeByTaskID(int32_t task_id);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include "backend/session/anf_runtime_algorithm.h"
|
||||
#include "backend/session/kernel_build_client.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "utils/convert_utils_base.h"
|
||||
|
||||
namespace mindspore::kernel {
|
||||
constexpr auto kName = "name";
|
||||
|
|
@ -185,7 +186,7 @@ void TbeKernelSelect::FilterInVaildKernelInfo(const OpInfo &op_info) {
|
|||
MS_LOG(INFO) << "Warning: get kernel build info failed.";
|
||||
return;
|
||||
}
|
||||
std::vector<std::shared_ptr<KernelBuildInfo>> new_kernel_info_list;
|
||||
std::vector<std::shared_ptr<KernelBuildInfo>> kernel_info_list;
|
||||
auto dynamic_inputs = GetNodeDynamicInputs();
|
||||
for (auto iter = kernel_info_list_->begin(); iter != kernel_info_list_->end(); ++iter) {
|
||||
if (!FilterInVaildShape(iter, !dynamic_inputs.empty())) {
|
||||
|
|
@ -196,9 +197,9 @@ void TbeKernelSelect::FilterInVaildKernelInfo(const OpInfo &op_info) {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
new_kernel_info_list.emplace_back(*iter);
|
||||
kernel_info_list.emplace_back(*iter);
|
||||
}
|
||||
(*kernel_info_list_) = new_kernel_info_list;
|
||||
(*kernel_info_list_) = kernel_info_list;
|
||||
}
|
||||
|
||||
bool TbeKernelSelect::FilterInVaildShape(const KernelBuildInfoIter &kernel_build_info_iter, bool is_dynamic_input) {
|
||||
|
|
@ -229,7 +230,7 @@ bool TbeKernelSelect::IsShapeMatchFormat(const std::vector<size_t> &shape, const
|
|||
if (format == kOpFormat_DEFAULT) {
|
||||
return true;
|
||||
}
|
||||
static std::set<std::string> kServerNotSupportFormat = {kOpFormat_NC1HWC0_C04, kOpFormat_FRACTAL_Z_C04};
|
||||
static const std::set<std::string> kServerNotSupportFormat = {kOpFormat_NC1HWC0_C04, kOpFormat_FRACTAL_Z_C04};
|
||||
// if format is default, it remarkes support all format
|
||||
if (kOpFormatList.find(format) == kOpFormatList.end()) {
|
||||
MS_LOG(EXCEPTION) << "Got the unknown format " << format;
|
||||
|
|
@ -324,7 +325,7 @@ bool TbeKernelSelect::GenBuilderItem(bool is_input, size_t kernel_build_info_ind
|
|||
reshape_types->emplace_back(reshape_type);
|
||||
}
|
||||
dynamic_input_index++;
|
||||
real_io_tensor_index += dynamic_input_size;
|
||||
real_io_tensor_index += LongToSize(dynamic_input_size);
|
||||
} else {
|
||||
if (ios_info.size() != 1) {
|
||||
MS_LOG(EXCEPTION) << "if output is dynamic, so output must has one output.";
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ void TbeUtils::SaveJsonInfo(const std::string &json_name, const std::string &inf
|
|||
void TbeUtils::LoadCache() {
|
||||
static bool has_load = false;
|
||||
if (!has_load) {
|
||||
KernelMeta *bin_map = KernelMeta::GetInstance();
|
||||
if (bin_map != nullptr && !bin_map->ReadIndex(kCceKernelMeta)) {
|
||||
auto bin_map = KernelMeta::GetInstance();
|
||||
if (!bin_map->ReadIndex(kCceKernelMeta)) {
|
||||
MS_LOG(INFO) << "Cache initialize failed[" << kCceKernelMeta << "]";
|
||||
}
|
||||
has_load = true;
|
||||
|
|
|
|||
|
|
@ -18,13 +18,12 @@
|
|||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "utils/utils.h"
|
||||
#include "utils/ms_context.h"
|
||||
#include "utils/check_convert_utils.h"
|
||||
#include "utils/convert_utils_base.h"
|
||||
#include "backend/optimizer/common/helper.h"
|
||||
#include "runtime/device/kernel_info.h"
|
||||
#include "backend/session/anf_runtime_algorithm.h"
|
||||
|
|
@ -84,7 +83,7 @@ std::vector<std::vector<float>> GetAssistInputMatrix(const std::vector<int64_t>
|
|||
std::vector<float> tmp_one_vector(in_shape_after_padding_2d[1], 1.0);
|
||||
for (int64_t i = 0; i < in_shape_after_padding_2d[1]; ++i) {
|
||||
if (i < pad_left || i >= (in_shape_after_padding_2d[1] - pad_right)) {
|
||||
tmp_one_vector[i] = 0.0;
|
||||
tmp_one_vector[LongToSize(i)] = 0.0;
|
||||
}
|
||||
}
|
||||
for (int64_t i = 0; i < in_shape_after_padding_2d[0]; ++i) {
|
||||
|
|
@ -118,11 +117,11 @@ ValueNodePtr CreateMeanMatrixValueNode(const FuncGraphPtr &func_graph, const std
|
|||
float curr_sum = 0;
|
||||
for (int64_t i = h * stride[DIM2]; i < h * stride[DIM2] + k_size[DIM2]; ++i) {
|
||||
for (int64_t j = w * stride[DIM3]; j < w * stride[DIM3] + k_size[DIM3]; ++j) {
|
||||
curr_sum += assist_input_matrix[i][j];
|
||||
curr_sum += assist_input_matrix[LongToSize(i)][LongToSize(j)];
|
||||
}
|
||||
}
|
||||
if (curr_sum > 0) {
|
||||
hw_output[h * w_output + w] = 1.0 / curr_sum;
|
||||
hw_output[LongToSize(h * w_output + w)] = 1.0 / curr_sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -133,8 +132,8 @@ ValueNodePtr CreateMeanMatrixValueNode(const FuncGraphPtr &func_graph, const std
|
|||
std::vector<float> output(output_size, 0.0);
|
||||
for (int64_t i = 0; i < output_shape[0] * output_shape[1]; ++i) {
|
||||
size_t src_size = hw_output.size() * kFloat32Len;
|
||||
size_t dst_size = output_shape[DIM2] * output_shape[DIM3] * kFloat32Len;
|
||||
auto ret = memcpy_s(&output[i * hw_output.size()], dst_size, &hw_output[0], src_size);
|
||||
auto dst_size = LongToSize(output_shape[DIM2] * output_shape[DIM3] * kFloat32Len);
|
||||
auto ret = memcpy_s(&output[LongToSize(i * hw_output.size())], dst_size, &hw_output[0], src_size);
|
||||
if (ret != 0) {
|
||||
MS_LOG(EXCEPTION) << "memcpy_s error, errorno(" << ret << ")";
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ void SetConv2DBackpropInputAttrs(const CNodePtr &conv2d_backin, const CNodePtr &
|
|||
auto stride = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(conv2d_backin, kAttrStride);
|
||||
constexpr size_t kStrideSize = 2;
|
||||
if (stride.size() == kStrideSize) {
|
||||
stride.insert(stride.begin(), kStrideSize, 1);
|
||||
(void)stride.insert(stride.begin(), kStrideSize, 1);
|
||||
}
|
||||
AnfAlgo::SetNodeAttr(kAttrStride, MakeValue(stride), depth_conv_backin);
|
||||
}
|
||||
|
|
@ -251,7 +251,7 @@ void SetConv2DBackpropFilterAttrs(const CNodePtr &conv2d_backfil, const CNodePtr
|
|||
auto stride = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(conv2d_backfil, kAttrStride);
|
||||
constexpr size_t kStrideSize = 2;
|
||||
if (stride.size() == kStrideSize) {
|
||||
stride.insert(stride.begin(), kStrideSize, 1);
|
||||
(void)stride.insert(stride.begin(), kStrideSize, 1);
|
||||
}
|
||||
AnfAlgo::SetNodeAttr(kAttrStride, MakeValue(stride), depth_conv_backfil);
|
||||
}
|
||||
|
|
@ -305,7 +305,7 @@ const AnfNodePtr Conv2DBackpropInputUnifyMindIR::Process(const FuncGraphPtr &gra
|
|||
// In pynative mode, input_sizes input will be convert to attr if Conv2DBackpropInput is a forward op.
|
||||
if (input_size != kConv2DBackpropInputNum && input_size != kConv2DBackpropInputNum - 1) {
|
||||
MS_LOG(EXCEPTION) << "Conv2DBackpropInput's input number should be " << (kConv2DBackpropInputNum - 1) << " or "
|
||||
<< (kConv2DBackpropInputNum - 2) << ", but got " << input_size - 1;
|
||||
<< (kConv2DBackpropInputNum - 2) << ", but got " << (input_size - 1);
|
||||
}
|
||||
auto transpose = CreateTranspose(graph, conv2d_backin, conv2d_backin->input(kInput2), true);
|
||||
auto depth_conv_backin = CreateDepthwiseConv2DBackpropInput(graph, conv2d_backin, transpose);
|
||||
|
|
|
|||
|
|
@ -85,8 +85,9 @@ ValueNodePtr CreateKeepPorbValueNode(const FuncGraphPtr &func_graph, const AnfNo
|
|||
MS_EXCEPTION_IF_NULL(data_ptr);
|
||||
// keep_prob's datatype is same with input data
|
||||
if (type_id == kNumberTypeFloat16) {
|
||||
auto half_data = float16(keep_prob);
|
||||
auto ret_code = memcpy_s(data_ptr, static_cast<size_t>(keep_prob_tensor->data().nbytes()), &half_data, kFloat16Len);
|
||||
std::vector<float16> half_data = {float16(keep_prob)};
|
||||
auto ret_code =
|
||||
memcpy_s(data_ptr, static_cast<size_t>(keep_prob_tensor->data().nbytes()), half_data.data(), kFloat16Len);
|
||||
if (ret_code != 0) {
|
||||
MS_LOG(EXCEPTION) << "Failed to copy data into Tensor.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ CNodePtr CreateOneHot(const FuncGraphPtr &graph, const CNodePtr &sparse_softmax_
|
|||
|
||||
std::vector<size_t> logits_shape = AnfAlgo::GetPrevNodeOutputInferShape(sparse_softmax_node, 0);
|
||||
int64_t depth = 0;
|
||||
if (logits_shape.size() >= 1) {
|
||||
if (!logits_shape.empty()) {
|
||||
size_t index = logits_shape.size() - 1;
|
||||
depth = SizeToLong(logits_shape[index]);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ static int GetSVarStartIndex(const VectorRef &values) {
|
|||
}
|
||||
|
||||
void UpdateEquivMap(const VectorRef &values_pattern, const BaseRef &expr_ref, const PrimitiveVarMap &primitive_vars,
|
||||
EquivPtr equiv) {
|
||||
const EquivPtr &equiv) {
|
||||
if (equiv == nullptr || values_pattern.empty() || !utils::isa<AnfNodePtr>(values_pattern[0]) ||
|
||||
!utils::isa<AnfNodePtr>(expr_ref)) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -424,8 +424,7 @@ kernel::KernelModPtr AscendDeviceAddress::CompileTransDataAndObtainKernelMod(con
|
|||
// search cache
|
||||
auto cached_kernel_pack = TbeUtils::SearchCache(json_name, processor);
|
||||
MS_EXCEPTION_IF_NULL(cached_kernel_pack);
|
||||
auto kernel_mod_ptr =
|
||||
build_manager->GenKernelMod(json_name, processor, input_size_list, output_size_list, cached_kernel_pack);
|
||||
auto kernel_mod_ptr = build_manager->GenKernelMod(input_size_list, output_size_list, cached_kernel_pack);
|
||||
return kernel_mod_ptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue