forked from mindspore-Ecosystem/mindspore
Clean code for core directory
This commit is contained in:
parent
261a1d6f20
commit
9be529895c
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* Copyright 2021-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.
|
||||
|
@ -116,8 +116,8 @@ void MindIREngine::Init(const AbstractBasePtrList &args) {
|
|||
if (node->isa<CNode>()) {
|
||||
auto cnode = node->cast<CNodePtr>();
|
||||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
todo_.insert(node);
|
||||
node_input_depends_[node] = cnode->inputs().size();
|
||||
(void)todo_.insert(node);
|
||||
node_input_depends_[node] = SizeToInt(cnode->inputs().size());
|
||||
} else if (node->isa<Parameter>()) {
|
||||
auto param = node->cast<ParameterPtr>();
|
||||
MS_EXCEPTION_IF_NULL(param);
|
||||
|
@ -127,7 +127,7 @@ void MindIREngine::Init(const AbstractBasePtrList &args) {
|
|||
ready_.push_back(node);
|
||||
} else {
|
||||
node_input_depends_[node] = 1;
|
||||
todo_.insert(node);
|
||||
(void)todo_.insert(node);
|
||||
}
|
||||
} else {
|
||||
// Value Node
|
||||
|
@ -192,7 +192,7 @@ void MindIREngine::EvalCommonPrimitive(const PrimitivePtr &prim, const CNodePtr
|
|||
AbstractBasePtrList args_spec_list;
|
||||
// Args has been resolved by partial
|
||||
if (args != nullptr) {
|
||||
args_spec_list.insert(args_spec_list.end(), args->begin(), args->end());
|
||||
(void)args_spec_list.insert(args_spec_list.end(), args->begin(), args->end());
|
||||
} else {
|
||||
(void)std::transform(node->inputs().begin() + 1, node->inputs().end(), std::back_inserter(args_spec_list),
|
||||
[this](const AnfNodePtr &arg) { return infer_resut_[arg]; });
|
||||
|
@ -244,7 +244,7 @@ void MindIREngine::EvalPartialPrimitive(const CNodePtr &node, const AbstractBase
|
|||
MS_LOG(EXCEPTION) << (*args)[0]->ToString() << " is not a function abstract.";
|
||||
}
|
||||
AbstractBasePtrList partial_args_list;
|
||||
partial_args_list.insert(partial_args_list.end(), args->begin() + 1, args->end());
|
||||
(void)partial_args_list.insert(partial_args_list.end(), args->begin() + 1, args->end());
|
||||
auto partial_func = std::make_shared<abstract::PartialAbstractClosure>(real_func, partial_args_list, node);
|
||||
SaveNodeInferResult(node, partial_func);
|
||||
return;
|
||||
|
@ -270,14 +270,14 @@ void MindIREngine::EvalPartialAbastract(const abstract::PartialAbstractClosurePt
|
|||
AbstractBasePtrListPtr partial_args_list = std::make_shared<AbstractBasePtrList>();
|
||||
// Join arguments in partial and the rest arguments from args_conf_list.
|
||||
auto func_args = func->args();
|
||||
partial_args_list->insert(partial_args_list->end(), func_args.begin(), func_args.end());
|
||||
(void)partial_args_list->insert(partial_args_list->end(), func_args.begin(), func_args.end());
|
||||
if (args == nullptr) {
|
||||
// Not Recursive
|
||||
(void)std::transform(node->inputs().begin() + 1, node->inputs().end(), std::back_inserter(*partial_args_list),
|
||||
[this](const AnfNodePtr &arg) { return infer_resut_[arg]; });
|
||||
} else {
|
||||
// Recursive
|
||||
partial_args_list->insert(partial_args_list->end(), args->begin(), args->end());
|
||||
(void)partial_args_list->insert(partial_args_list->end(), args->begin(), args->end());
|
||||
}
|
||||
|
||||
// Get real function
|
||||
|
@ -337,7 +337,7 @@ bool MindIREngine::CheckCNodeNotReady(const CNodePtr &node) {
|
|||
depend += infer_resut_.find(input) != infer_resut_.end() ? 0 : 1;
|
||||
}
|
||||
this->node_input_depends_[node] = depend;
|
||||
return depend;
|
||||
return depend != 0;
|
||||
}
|
||||
|
||||
void MindIREngine::EvalFuncGraphAbastract(const abstract::FuncGraphAbstractClosurePtr &func, const CNodePtr &node,
|
||||
|
@ -364,7 +364,7 @@ void MindIREngine::EvalFuncGraphAbastract(const abstract::FuncGraphAbstractClosu
|
|||
for (size_t i = 0; i < func_inputs.size(); ++i) {
|
||||
infer_resut_[func_inputs[i]] =
|
||||
(*args)[i]; // Not use SaveNodeInferResult because this function has been evaluated.
|
||||
todo_.erase(func_inputs[i]);
|
||||
(void)todo_.erase(func_inputs[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ void MindIREngine::EvalFuncGraphAbastract(const abstract::FuncGraphAbstractClosu
|
|||
}
|
||||
for (size_t i = 0; i < func_inputs.size(); ++i) {
|
||||
infer_resut_[func_inputs[i]] = infer_resut_[cnode_inputs[i + 1]];
|
||||
todo_.erase(func_inputs[i]);
|
||||
(void)todo_.erase(func_inputs[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ void MindIREngine::EvalFuncGraphAbastract(const abstract::FuncGraphAbstractClosu
|
|||
// Be handling
|
||||
auto visitIt = func_graph_visited_.find(funcName);
|
||||
if (visitIt != func_graph_visited_.end()) {
|
||||
visitIt->second.insert(node);
|
||||
(void)visitIt->second.insert(node);
|
||||
return;
|
||||
}
|
||||
func_graph_visited_[funcName] = std::set<AnfNodePtr>({node});
|
||||
|
@ -477,7 +477,7 @@ void MindIREngine::EvalAbstractFunction(const abstract::AbstractFuncAtomPtr &fun
|
|||
}
|
||||
|
||||
void MindIREngine::UpdateReady(const AnfNodePtr &node) {
|
||||
todo_.erase(node);
|
||||
(void)todo_.erase(node);
|
||||
auto it = nodeuser_map_.find(node);
|
||||
if (it == nodeuser_map_.end()) {
|
||||
return;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
* Copyright 2020-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.
|
||||
|
@ -62,7 +62,7 @@ bool get_all_files(const std::string &dir_in, std::vector<std::string> *files) {
|
|||
return false;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
ret = get_all_files(name, files);
|
||||
ret = static_cast<int>(get_all_files(name, files));
|
||||
if (!ret) {
|
||||
MS_LOG(ERROR) << "Get files failed, ret is : " << ret;
|
||||
closedir(open_dir);
|
||||
|
@ -196,7 +196,7 @@ FuncGraphPtr MindIRLoader::LoadMindIR(const void *buffer, const size_t &size) {
|
|||
/* mindir -> func_graph
|
||||
* only support lite */
|
||||
mind_ir::ModelProto model;
|
||||
auto ret = model.ParseFromArray(buffer, size);
|
||||
auto ret = model.ParseFromArray(buffer, SizeToInt(size));
|
||||
if (!ret) {
|
||||
MS_LOG(ERROR) << "ParseFromArray failed.";
|
||||
return nullptr;
|
||||
|
@ -255,7 +255,7 @@ FuncGraphPtr MindIRLoader::LoadMindIR(const std::string &file_name) {
|
|||
std::ifstream ifs(var_path);
|
||||
if (ifs.good()) {
|
||||
MS_LOG(DEBUG) << "MindIR file has variables path, load parameter into graph.";
|
||||
get_all_files(var_path, &files);
|
||||
(void)get_all_files(var_path, &files);
|
||||
} else {
|
||||
MS_LOG(ERROR) << "Load graph's variable folder failed, please check the correctness of variable folder.";
|
||||
return nullptr;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* Copyright 2021-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.
|
||||
|
@ -80,7 +80,7 @@ class MIND_API Tensor : public Value {
|
|||
/// \brief Get tensor data size.
|
||||
///
|
||||
/// \return The total number of elements in the tensor.
|
||||
int DataSize() const;
|
||||
size_t DataSize() const;
|
||||
|
||||
/// \brief Get tensor data size in bytes.
|
||||
///
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* Copyright 2021-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.
|
||||
|
@ -154,8 +154,8 @@ std::vector<std::pair<AnfNodePtr, int>> FuncGraphManager::GetUsers(const AnfNode
|
|||
auto &users_impl = iter->second;
|
||||
std::vector<std::pair<AnfNodePtr, int>> users;
|
||||
users.reserve(users_impl.size());
|
||||
std::transform(users_impl.begin(), users_impl.end(), std::back_inserter(users),
|
||||
[](const auto &user) { return std::make_pair(ToWrapper<AnfNode>(user.first), user.second); });
|
||||
(void)std::transform(users_impl.begin(), users_impl.end(), std::back_inserter(users),
|
||||
[](const auto &user) { return std::make_pair(ToWrapper<AnfNode>(user.first), user.second); });
|
||||
return users;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* Copyright 2021-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.
|
||||
|
@ -58,7 +58,7 @@ std::unordered_map<std::string, ValuePtr> Primitive::attrs() const {
|
|||
attr_map.reserve(impl_attrs.size());
|
||||
for (auto &attr : impl_attrs) {
|
||||
auto value = ToWrapper<Value>(attr.second);
|
||||
attr_map.emplace(attr.first, value);
|
||||
(void)attr_map.emplace(attr.first, value);
|
||||
}
|
||||
return attr_map;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* Copyright 2021-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.
|
||||
|
@ -41,7 +41,7 @@ const void *Tensor::data() const { return ToRef<TensorImpl>(impl_).data_c(); }
|
|||
|
||||
void *Tensor::data() { return ToRef<TensorImpl>(impl_).data_c(); }
|
||||
|
||||
int Tensor::DataSize() const { return ToRef<TensorImpl>(impl_).DataSize(); }
|
||||
size_t Tensor::DataSize() const { return ToRef<TensorImpl>(impl_).DataSize(); }
|
||||
|
||||
size_t Tensor::Size() const { return ToRef<TensorImpl>(impl_).Size(); }
|
||||
} // namespace mindspore::api
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2019 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.
|
||||
|
@ -58,11 +58,9 @@ static std::string GetProcName() {
|
|||
}
|
||||
|
||||
static std::string GetLogLevel(MsLogLevel level) {
|
||||
#define _TO_STRING(x) #x
|
||||
static const char *const level_names[] = {
|
||||
"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL",
|
||||
};
|
||||
#undef _TO_STRING
|
||||
if (level > this_thread_max_log_level) {
|
||||
level = this_thread_max_log_level;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
* Copyright 2021-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,6 +24,7 @@
|
|||
#include <numeric>
|
||||
#include "securec/include/securec.h"
|
||||
#include "utils/log_adapter.h"
|
||||
#include "utils/convert_utils_base.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace system {
|
||||
|
@ -76,7 +77,7 @@ bool Padding(std::string *message) {
|
|||
message->push_back(0x00);
|
||||
}
|
||||
for (int i = size_append - 1; i >= 0; --i) {
|
||||
message->push_back(static_cast<uint8_t>((bits_message >> static_cast<uint32_t>(i * kBitNumber)) & 0xff));
|
||||
message->push_back(static_cast<char>((bits_message >> static_cast<uint32_t>(i * kBitNumber)) & 0xff));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -87,17 +88,17 @@ bool ProcessInner(const std::string &message, const int &bias, uint32_t *digest,
|
|||
}
|
||||
uint32_t w[kIterationNumber] = {0};
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
w[i] = (static_cast<uint32_t>(static_cast<uint8_t>(message[bias + i * 4]) & 0xff) << 24) |
|
||||
(static_cast<uint32_t>(static_cast<uint8_t>(message[bias + i * 4 + 1]) & 0xff) << 16) |
|
||||
(static_cast<uint32_t>(static_cast<uint8_t>(message[bias + i * 4 + 2]) & 0xff) << 8) |
|
||||
(static_cast<uint32_t>(static_cast<uint8_t>(message[bias + i * 4 + 3]) & 0xff));
|
||||
w[i] = (static_cast<uint32_t>(static_cast<uint8_t>(message[IntToSize(bias + i * 4)]) & 0xff) << 24) |
|
||||
(static_cast<uint32_t>(static_cast<uint8_t>(message[IntToSize(bias + i * 4 + 1)]) & 0xff) << 16) |
|
||||
(static_cast<uint32_t>(static_cast<uint8_t>(message[IntToSize(bias + i * 4 + 2)]) & 0xff) << 8) |
|
||||
(static_cast<uint32_t>(static_cast<uint8_t>(message[IntToSize(bias + i * 4 + 3)]) & 0xff));
|
||||
}
|
||||
for (int i = 16; i < kIterationNumber; ++i) {
|
||||
w[i] = sigma3(w[i - 2]) + w[i - 7] + sigma2(w[i - 15]) + w[i - 16];
|
||||
}
|
||||
|
||||
std::vector<uint32_t> hash(digest_size);
|
||||
size_t mem_size = digest_size * sizeof(uint32_t);
|
||||
size_t mem_size = IntToSize(digest_size) * sizeof(uint32_t);
|
||||
auto ret = memcpy_s(hash.data(), mem_size, digest, mem_size);
|
||||
if (ret != EOK) {
|
||||
return false;
|
||||
|
@ -107,15 +108,15 @@ bool ProcessInner(const std::string &message, const int &bias, uint32_t *digest,
|
|||
uint32_t t2 = sigma0(hash[0]) + ma(hash[0], hash[1], hash[2]);
|
||||
for (int j = digest_size - 1; j >= 0; --j) {
|
||||
if (j == 4) {
|
||||
hash[j] = hash[j - 1] + t1;
|
||||
hash[IntToSize(j)] = hash[IntToSize(j - 1)] + t1;
|
||||
} else if (j == 0) {
|
||||
hash[j] = t1 + t2;
|
||||
hash[IntToSize(j)] = t1 + t2;
|
||||
} else {
|
||||
hash[j] = hash[j - 1];
|
||||
hash[IntToSize(j)] = hash[IntToSize(j - 1)];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < digest_size; ++i) {
|
||||
for (size_t i = 0; i < IntToSize(digest_size); ++i) {
|
||||
digest[i] += hash[i];
|
||||
}
|
||||
return true;
|
||||
|
@ -188,9 +189,9 @@ std::string GetHashFromDir(const std::string &dir) {
|
|||
if (d_name == "." || d_name == ".." || filename->d_type != DT_REG) {
|
||||
continue;
|
||||
}
|
||||
file_hashes.emplace_back(GetHashFromFile(std::string(dir) + "/" + filename->d_name));
|
||||
(void)file_hashes.emplace_back(GetHashFromFile(std::string(dir) + "/" + filename->d_name));
|
||||
}
|
||||
closedir(open_dir);
|
||||
(void)closedir(open_dir);
|
||||
std::sort(file_hashes.begin(), file_hashes.end());
|
||||
auto dir_hash = std::accumulate(file_hashes.begin(), file_hashes.end(), std::string{});
|
||||
return dir_hash;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2020-2021 Huawei Technologies Co., Ltd
|
||||
* Copyright 2020-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.
|
||||
|
@ -188,14 +188,14 @@ void GetSourceLineFromDebugInfo(const DebugInfoPtr &debug_info, std::vector<std:
|
|||
|
||||
void GetFusedDebugInfos(const NodeDebugInfoSet &fused_debug_infos, std::vector<std::string> *result) {
|
||||
MS_EXCEPTION_IF_NULL(result);
|
||||
result->push_back("Corresponding code candidate:\n");
|
||||
(void)result->emplace_back("Corresponding code candidate:\n");
|
||||
// Flag to mark whether fused_debug_infos has valid print.
|
||||
bool is_empty = true;
|
||||
for (const auto &debug_info : fused_debug_infos) {
|
||||
std::vector<std::string> debug_info_vec_str;
|
||||
GetSourceLineFromDebugInfo(debug_info, &debug_info_vec_str, kSectionPrefix);
|
||||
if (!debug_info_vec_str.empty()) {
|
||||
result->insert(result->end(), debug_info_vec_str.begin(), debug_info_vec_str.end());
|
||||
(void)result->insert(result->end(), debug_info_vec_str.begin(), debug_info_vec_str.end());
|
||||
is_empty = false;
|
||||
}
|
||||
}
|
||||
|
@ -210,12 +210,12 @@ void GetPrimalDebugInfos(const CNodePtr &cnode, std::vector<std::string> *result
|
|||
MS_EXCEPTION_IF_NULL(result);
|
||||
auto primal_debug_infos = cnode->primal_debug_infos();
|
||||
if (!primal_debug_infos.empty()) {
|
||||
result->emplace_back("Corresponding forward node candidate:\n");
|
||||
(void)result->emplace_back("Corresponding forward node candidate:\n");
|
||||
for (const auto &primal_debug_info : primal_debug_infos) {
|
||||
std::vector<std::string> debug_info_vec_str;
|
||||
GetSourceLineFromDebugInfo(primal_debug_info, &debug_info_vec_str, kSectionPrefix);
|
||||
if (!debug_info_vec_str.empty()) {
|
||||
result->insert(result->end(), debug_info_vec_str.begin(), debug_info_vec_str.end());
|
||||
(void)result->insert(result->end(), debug_info_vec_str.begin(), debug_info_vec_str.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue