!16836 Fix code check

From: @zuochuanyong
Reviewed-by: @jjfeing,@kisnwang
Signed-off-by: @jjfeing
This commit is contained in:
mindspore-ci-bot 2021-05-26 09:00:55 +08:00 committed by Gitee
commit b9d98b3f35
3 changed files with 25 additions and 25 deletions

View File

@ -44,7 +44,8 @@ bool CPUDeviceAddress::DumpMemToFile(const std::string &filepath, const std::str
return ret; return ret;
} }
bool CPUDeviceAddress::SyncDeviceToHost(const ShapeVector & /*shape*/, size_t size, TypeId type, void *host_ptr) const { bool CPUDeviceAddress::SyncDeviceToHost(const ShapeVector & /* shape */, size_t size, TypeId type,
void *host_ptr) const {
if (ptr_ == nullptr) { if (ptr_ == nullptr) {
MS_LOG(ERROR) << "The pointer ptr_ is null!"; MS_LOG(ERROR) << "The pointer ptr_ is null!";
return false; return false;
@ -60,11 +61,11 @@ bool CPUDeviceAddress::SyncDeviceToHost(const ShapeVector & /*shape*/, size_t si
return false; return false;
} }
} else if (type == kNumberTypeFloat16 && type_id_ == kNumberTypeFloat32) { } else if (type == kNumberTypeFloat16 && type_id_ == kNumberTypeFloat32) {
FloatToHalf(host_ptr, ptr_, size / 2); FloatToHalf(host_ptr, ptr_, size >> 1);
} else if (type == kNumberTypeFloat64 && type_id_ == kNumberTypeFloat32) { } else if (type == kNumberTypeFloat64 && type_id_ == kNumberTypeFloat32) {
FloatToDouble(host_ptr, ptr_, size / sizeof(double)); FloatToDouble(host_ptr, ptr_, size / sizeof(double));
} else if (type == kNumberTypeInt16 && type_id_ == kNumberTypeInt32) { } else if (type == kNumberTypeInt16 && type_id_ == kNumberTypeInt32) {
IntToShort(host_ptr, ptr_, size / 2); IntToShort(host_ptr, ptr_, size >> 1);
} else if (type == kNumberTypeInt64 && type_id_ == kNumberTypeInt32) { } else if (type == kNumberTypeInt64 && type_id_ == kNumberTypeInt32) {
IntToLong(host_ptr, ptr_, size / sizeof(int64_t)); IntToLong(host_ptr, ptr_, size / sizeof(int64_t));
} else { } else {
@ -75,7 +76,7 @@ bool CPUDeviceAddress::SyncDeviceToHost(const ShapeVector & /*shape*/, size_t si
return true; return true;
} }
bool CPUDeviceAddress::SyncHostToDevice(const ShapeVector & /*shape*/, size_t size, TypeId type, bool CPUDeviceAddress::SyncHostToDevice(const ShapeVector & /* shape */, size_t size, TypeId type,
const void *host_ptr) const { const void *host_ptr) const {
if (ptr_ == nullptr) { if (ptr_ == nullptr) {
MS_LOG(ERROR) << "The pointer ptr_ is null!"; MS_LOG(ERROR) << "The pointer ptr_ is null!";
@ -86,11 +87,11 @@ bool CPUDeviceAddress::SyncHostToDevice(const ShapeVector & /*shape*/, size_t si
return true; return true;
} }
if (type_id_ == kNumberTypeFloat32 && type == kNumberTypeFloat16) { if (type_id_ == kNumberTypeFloat32 && type == kNumberTypeFloat16) {
HalfToFloat(ptr_, host_ptr, size / 2); HalfToFloat(ptr_, host_ptr, size >> 1);
} else if (type_id_ == kNumberTypeFloat32 && type == kNumberTypeFloat64) { } else if (type_id_ == kNumberTypeFloat32 && type == kNumberTypeFloat64) {
DoubleToFloat(ptr_, host_ptr, size / sizeof(double)); DoubleToFloat(ptr_, host_ptr, size / sizeof(double));
} else if (type_id_ == kNumberTypeInt32 && type == kNumberTypeInt16) { } else if (type_id_ == kNumberTypeInt32 && type == kNumberTypeInt16) {
ShortToInt(ptr_, host_ptr, size / 2); ShortToInt(ptr_, host_ptr, size >> 1);
} else if (type_id_ == kNumberTypeInt32 && type == kNumberTypeInt64) { } else if (type_id_ == kNumberTypeInt32 && type == kNumberTypeInt64) {
LongToInt(ptr_, host_ptr, size / sizeof(int64_t)); LongToInt(ptr_, host_ptr, size / sizeof(int64_t));
} else { } else {

View File

@ -43,7 +43,6 @@
namespace mindspore { namespace mindspore {
namespace device { namespace device {
namespace cpu { namespace cpu {
bool CPUKernelRuntime::Init() { bool CPUKernelRuntime::Init() {
if (initialized_) { if (initialized_) {
return true; return true;

View File

@ -33,19 +33,19 @@ std::shared_ptr<MPIAdapter> MPIAdapter::Instance() {
return instance_; return instance_;
} }
#define RAISE_EXCEPTION(message) \ #define RAISE_EXCEPTION(message) \
{ \ do { \
std::ostringstream oss; \ std::ostringstream oss; \
oss << "[" << __FILE__ << "] [" << __LINE__ << "] " << message; \ oss << "[" << __FILE__ << "] [" << __LINE__ << "] " << (message); \
pybind11::pybind11_fail(oss.str()); \ pybind11::pybind11_fail(oss.str()); \
} } while (0)
#define RAISE_EXCEPTION_WITH_PARAM(message, param) \ #define RAISE_EXCEPTION_WITH_PARAM(message, param) \
{ \ do { \
std::ostringstream oss; \ std::ostringstream oss; \
oss << "[" << __FILE__ << "] [" << __LINE__ << "] " << message << param; \ oss << "[" << __FILE__ << "] [" << __LINE__ << "] " << (message) << (param); \
pybind11::pybind11_fail(oss.str()); \ pybind11::pybind11_fail(oss.str()); \
} } while (0)
namespace { namespace {
MPI_Op GetMpiOp(const std::string &op_type) { MPI_Op GetMpiOp(const std::string &op_type) {
@ -109,8 +109,8 @@ void MPIAdapter::Init() {
RAISE_EXCEPTION("Check mpi initialized fail!"); RAISE_EXCEPTION("Check mpi initialized fail!");
} }
if (init_flag == 0) { if (init_flag == 0) {
auto ret = MPI_Init(nullptr, nullptr); auto ret_init = MPI_Init(nullptr, nullptr);
if (ret != MPI_SUCCESS) { if (ret_init != MPI_SUCCESS) {
RAISE_EXCEPTION("Failed to init mpi!"); RAISE_EXCEPTION("Failed to init mpi!");
} }
} }
@ -126,7 +126,7 @@ void MPIAdapter::Init() {
ret = MPI_Comm_size(MPI_COMM_WORLD, &rank_size_); ret = MPI_Comm_size(MPI_COMM_WORLD, &rank_size_);
if (ret != MPI_SUCCESS) { if (ret != MPI_SUCCESS) {
RAISE_EXCEPTION_WITH_PARAM("Failed to init mpi rank size!rankid:", rank_id_) RAISE_EXCEPTION_WITH_PARAM("Failed to init mpi rank size!rankid:", rank_id_);
} }
init = true; init = true;
} }
@ -153,7 +153,7 @@ MPI_Group MPIAdapter::AddGroup(const std::vector<int> &ranks) {
MPI_Group group = MPI_GROUP_NULL; MPI_Group group = MPI_GROUP_NULL;
MPI_Group_incl(comm_group_world_, ranks.size(), ranks_input.data(), &group); MPI_Group_incl(comm_group_world_, ranks.size(), ranks_input.data(), &group);
if (group == MPI_GROUP_NULL) { if (group == MPI_GROUP_NULL) {
RAISE_EXCEPTION_WITH_PARAM("create mpi group fail!rankid:", rank_id_) RAISE_EXCEPTION_WITH_PARAM("create mpi group fail!rankid:", rank_id_);
} }
ranks_group_[ranks] = group; ranks_group_[ranks] = group;
@ -169,7 +169,7 @@ bool MPIAdapter::ReduceScatter(const float *input, float *output, const std::vec
auto group = AddGroup(ranks_group); auto group = AddGroup(ranks_group);
if (group == MPI_GROUP_NULL) { if (group == MPI_GROUP_NULL) {
RAISE_EXCEPTION_WITH_PARAM("Get mpi group fail!rankid:", rank_id_) RAISE_EXCEPTION_WITH_PARAM("Get mpi group fail!rankid:", rank_id_);
} }
MPI_Comm comm; MPI_Comm comm;
MPI_Comm_create_group(MPI_COMM_WORLD, group, 0, &comm); MPI_Comm_create_group(MPI_COMM_WORLD, group, 0, &comm);
@ -233,7 +233,7 @@ bool MPIAdapter::ReduceScatterOverwriteInput(float *input, const std::vector<int
if (output_size < data_size) { if (output_size < data_size) {
std::ostringstream exception_msg; std::ostringstream exception_msg;
exception_msg << "output buffer size " << output_size << " < input size " << data_size; exception_msg << "output buffer size " << output_size << " < input size " << data_size;
RAISE_EXCEPTION(exception_msg.str()) RAISE_EXCEPTION(exception_msg.str());
} }
auto copy_ret = memcpy_s(output, output_size, input + scatter_index * input_data_num, data_size); auto copy_ret = memcpy_s(output, output_size, input + scatter_index * input_data_num, data_size);
if (copy_ret != 0) { if (copy_ret != 0) {