forked from huawei/mindspore2022
Clean code
This commit is contained in:
parent
e9b54f2466
commit
8a8aaacd32
|
|
@ -95,7 +95,7 @@ class COMMON_EXPORT ConfigManager {
|
|||
void set_iter_num(const std::string &queue_name, const int64_t num) {
|
||||
queue_name_ = queue_name;
|
||||
iter_num_ = num;
|
||||
queue_info_map[queue_name_] = num;
|
||||
queue_info_map[queue_name_] = static_cast<int16_t>(num);
|
||||
}
|
||||
|
||||
std::string dataset_phase() const { return dataset_phase_; }
|
||||
|
|
|
|||
|
|
@ -81,11 +81,11 @@ class EnsuresAccess<T, R, std::enable_if_t<std::is_pointer_v<std::remove_cv_t<T>
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct IsSharedPtr : std::false_type {};
|
||||
struct IsSharedPtr : public std::false_type {};
|
||||
template <typename T>
|
||||
struct IsSharedPtr<std::shared_ptr<T>> : std::true_type {};
|
||||
struct IsSharedPtr<std::shared_ptr<T>> : public std::true_type {};
|
||||
template <typename T>
|
||||
struct IsSharedPtr<const std::shared_ptr<T> &> : std::true_type {};
|
||||
struct IsSharedPtr<const std::shared_ptr<T> &> : public std::true_type {};
|
||||
|
||||
template <class T, class R>
|
||||
class EnsuresAccess<T, R, std::enable_if_t<IsSharedPtr<T>::value>> {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
namespace mindspore {
|
||||
namespace tensor {
|
||||
class Tensor;
|
||||
using TensorPtr = std::shared_ptr<Tensor>;
|
||||
} // namespace tensor
|
||||
|
||||
COMMON_EXPORT bool BaseRefToBool(const BaseRef &in, bool *out);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include <math.h>
|
||||
#include <array>
|
||||
#include "utils/log_adapter.h"
|
||||
#include "utils/convert_utils_base.h"
|
||||
#include "include/common/visible.h"
|
||||
|
||||
namespace mindspore {
|
||||
|
|
@ -65,7 +66,7 @@ template <class T>
|
|||
bool FillRandoms(PhiloxGenerator generator, float *output, int64_t vet_size, int64_t thread_Id) {
|
||||
T distribution;
|
||||
errno_t mem_ret;
|
||||
generator.JumpStep((vet_size * thread_Id + kResultNum - 1) / kResultNum);
|
||||
generator.JumpStep(LongToSize((vet_size * thread_Id + kResultNum - 1) / kResultNum));
|
||||
for (int32_t i = 0; i < vet_size; i += kResultNum) {
|
||||
auto outputResult = distribution(&generator);
|
||||
size_t max_length = 0;
|
||||
|
|
@ -73,7 +74,7 @@ bool FillRandoms(PhiloxGenerator generator, float *output, int64_t vet_size, int
|
|||
max_length = kResultNum * sizeof(float);
|
||||
mem_ret = memcpy_s(&output[i], max_length, &outputResult[0], max_length);
|
||||
} else {
|
||||
max_length = (vet_size - i) * sizeof(float);
|
||||
max_length = LongToSize((vet_size - i) * sizeof(float));
|
||||
mem_ret = memcpy_s(&output[i], max_length, &outputResult[0], max_length);
|
||||
}
|
||||
if (mem_ret != EOK) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class ScopedLongRunningHook {
|
|||
ScopedLongRunningHook() = default;
|
||||
virtual ~ScopedLongRunningHook() = default;
|
||||
virtual void Enter() = 0;
|
||||
virtual void Leave() = 0;
|
||||
virtual void Leave() noexcept = 0;
|
||||
};
|
||||
using ScopedLongRunningHookPtr = std::unique_ptr<ScopedLongRunningHook>;
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class GilScopedLongRunningHook : public ScopedLongRunningHook {
|
|||
release_ = std::make_unique<py::gil_scoped_release>();
|
||||
}
|
||||
}
|
||||
void Leave() override { release_ = nullptr; }
|
||||
void Leave() noexcept override { release_ = nullptr; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<py::gil_scoped_release> release_;
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@ uint32_t CheckpointSaveCallback(uint32_t graph_id, const std::map<std::string, g
|
|||
py::bool_ ret = python_adapter::CallPyFn(PYTHON_MOD_CALLBACK_MODULE, PYTHON_FUN_PROCESS_CHECKPOINT, parameter_list);
|
||||
auto bool_ret = py::cast<bool>(ret);
|
||||
|
||||
uint32_t status = Status::SUCCESS;
|
||||
uint32_t status = IntToUint(Status::SUCCESS);
|
||||
if (!bool_ret) {
|
||||
status = Status::FAILED;
|
||||
status = IntToUint(Status::FAILED);
|
||||
MS_LOG(ERROR) << "Python checkpoint return false during callback";
|
||||
}
|
||||
return status;
|
||||
|
|
@ -178,10 +178,10 @@ uint32_t SummarySaveCallback(uint32_t graph_id, const std::map<std::string, ge::
|
|||
auto bool_ret = py::cast<bool>(ret);
|
||||
if (!bool_ret) {
|
||||
MS_LOG(ERROR) << "Python checkpoint return false during callback";
|
||||
return Status::FAILED;
|
||||
return IntToUint(Status::FAILED);
|
||||
}
|
||||
MS_LOG(DEBUG) << "End the summary save callback function.";
|
||||
return Status::SUCCESS;
|
||||
return IntToUint(Status::SUCCESS);
|
||||
}
|
||||
} // namespace callbacks
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ class DefaultCommManager : public CommManager {
|
|||
~DefaultCommManager() override = default;
|
||||
|
||||
bool CreateGroupSync(const string &, const std::vector<unsigned int> &) const override { return true; }
|
||||
bool GetRankID(const string &group, unsigned int *rank_id) const override { return true; }
|
||||
bool GetRankSize(const string &group, unsigned int *rank_size) const override {
|
||||
bool GetRankID(const string &, unsigned int *) const override { return true; }
|
||||
bool GetRankSize(const string &, unsigned int *rank_size) const override {
|
||||
*rank_size = kNoCommDlibRankSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DestroyGroup(const string &group) const override { return true; }
|
||||
bool DestroyGroup(const string &) const override { return true; }
|
||||
|
||||
uint32_t GetRank() override { return 0; }
|
||||
};
|
||||
|
|
@ -53,7 +53,7 @@ bool CommManager::Register(const std::string &name, const std::shared_ptr<CommMa
|
|||
return false;
|
||||
}
|
||||
|
||||
GetInstanceMap().emplace(name, instance);
|
||||
(void)GetInstanceMap().emplace(name, instance);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,18 @@ namespace {
|
|||
// Isomorphism
|
||||
bool SameNode(const AnfNodePtr &node1, const AnfNodePtr &node2, FuncGraphPairMapEquiv *equiv_func_graph,
|
||||
NodeMapEquiv *const equiv_node);
|
||||
|
||||
bool SameValueNode(const AnfNodePtr &node1, const AnfNodePtr &node2) {
|
||||
auto a1 = GetValueNode(node1);
|
||||
auto a2 = GetValueNode(node2);
|
||||
if (a1->isa<Primitive>() && a2->isa<Primitive>()) {
|
||||
return a1->cast<PrimitivePtr>()->name() == a2->cast<PrimitivePtr>()->name();
|
||||
} else if (a1->isa<tensor::Tensor>() && a2->isa<tensor::Tensor>()) {
|
||||
return a1->cast<tensor::TensorPtr>()->ValueEqual(*(a2->cast<tensor::TensorPtr>()));
|
||||
}
|
||||
return *a1 == *a2;
|
||||
}
|
||||
|
||||
bool SameNodeShallow(const AnfNodePtr &node1, const AnfNodePtr &node2, FuncGraphPairMapEquiv *equiv_func_graph,
|
||||
NodeMapEquiv *const equiv_node) {
|
||||
if (equiv_node == nullptr) {
|
||||
|
|
@ -122,15 +134,7 @@ bool SameNodeShallow(const AnfNodePtr &node1, const AnfNodePtr &node2, FuncGraph
|
|||
equiv_node);
|
||||
}
|
||||
if (node1->isa<ValueNode>() && node2->isa<ValueNode>()) {
|
||||
auto a1 = GetValueNode(node1);
|
||||
auto a2 = GetValueNode(node2);
|
||||
if (a1->isa<Primitive>() && a2->isa<Primitive>()) {
|
||||
return a1->cast<PrimitivePtr>()->name() == a2->cast<PrimitivePtr>()->name();
|
||||
} else if (a1->isa<tensor::Tensor>() && a2->isa<tensor::Tensor>()) {
|
||||
return a1->cast<tensor::TensorPtr>()->ValueEqual(*(a2->cast<tensor::TensorPtr>()));
|
||||
} else {
|
||||
return *a1 == *a2;
|
||||
}
|
||||
return SameValueNode(node1, node2);
|
||||
}
|
||||
if (node1->isa<Parameter>() && node2->isa<Parameter>()) {
|
||||
auto para1 = node1->cast<ParameterPtr>();
|
||||
|
|
|
|||
|
|
@ -233,15 +233,15 @@ static ValueNameToConverterVector value_name_to_converter = {
|
|||
return interpreted_object->obj();
|
||||
}},
|
||||
// None
|
||||
{None::kTypeId, [](const ValuePtr &value) -> py::object { return py::none(); }},
|
||||
{None::kTypeId, [](const ValuePtr &) -> py::object { return py::none(); }},
|
||||
// AnyValue
|
||||
{AnyValue::kTypeId, [](const ValuePtr &value) -> py::object { return py::none(); }},
|
||||
{AnyValue::kTypeId, [](const ValuePtr &) -> py::object { return py::none(); }},
|
||||
// FuncGraph
|
||||
{FuncGraph::kTypeId, [](const ValuePtr &value) -> py::object { return py::none(); }},
|
||||
{FuncGraph::kTypeId, [](const ValuePtr &) -> py::object { return py::none(); }},
|
||||
// Monad
|
||||
{Monad::kTypeId, [](const ValuePtr &value) -> py::object { return py::none(); }},
|
||||
{Monad::kTypeId, [](const ValuePtr &) -> py::object { return py::none(); }},
|
||||
// Ellipsis
|
||||
{Ellipsis::kTypeId, [](const ValuePtr &value) -> py::object { return py::ellipsis(); }}};
|
||||
{Ellipsis::kTypeId, [](const ValuePtr &) -> py::object { return py::ellipsis(); }}};
|
||||
|
||||
py::object ValueToPyData(const ValuePtr &value) {
|
||||
if (value == nullptr) {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ std::array<uint32_t, kResultNum> PhiloxGenerator::Compute(const std::array<uint3
|
|||
const std::array<uint32_t, 2> &key_var) const {
|
||||
std::array<uint32_t, kResultNum> min_value;
|
||||
std::array<uint32_t, kResultNum> max_value;
|
||||
for (size_t i = 0; i < kResultNum; i += 2) {
|
||||
constexpr auto step = 2;
|
||||
for (size_t i = 0; i < kResultNum; i += step) {
|
||||
uint64_t temp = static_cast<uint64_t>(keyConstant[i]) * counter[i];
|
||||
min_value[i] = static_cast<uint32_t>(temp);
|
||||
max_value[i] = static_cast<uint32_t>(temp >> kShiftNum);
|
||||
|
|
|
|||
Loading…
Reference in New Issue