Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve "Multiplication result converted to larger type" #3149

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions source/api_c/include/deepmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,8 @@ class DeepPot {
const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr;
const int *atype_ = &atype[0];
double *ener_ = _DP_Get_Energy_Pointer(ener, nframes);
force.resize(nframes * natoms * 3);
virial.resize(nframes * 9);
force.resize(static_cast<size_t>(nframes) * natoms * 3);
virial.resize(static_cast<size_t>(nframes) * 9);
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
std::vector<VALUETYPE> fparam_, aparam_;
Expand Down Expand Up @@ -706,10 +706,10 @@ class DeepPot {
const int *atype_ = &atype[0];

double *ener_ = _DP_Get_Energy_Pointer(ener, nframes);
force.resize(nframes * natoms * 3);
virial.resize(nframes * 9);
atom_energy.resize(nframes * natoms);
atom_virial.resize(nframes * natoms * 9);
force.resize(static_cast<size_t>(nframes) * natoms * 3);
virial.resize(static_cast<size_t>(nframes) * 9);
atom_energy.resize(static_cast<size_t>(nframes) * natoms);
atom_virial.resize(static_cast<size_t>(nframes) * natoms * 9);
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
VALUETYPE *atomic_ener_ = &atom_energy[0];
Expand Down Expand Up @@ -774,8 +774,8 @@ class DeepPot {
const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr;
const int *atype_ = &atype[0];
double *ener_ = _DP_Get_Energy_Pointer(ener, nframes);
force.resize(nframes * natoms * 3);
virial.resize(nframes * 9);
force.resize(static_cast<size_t>(nframes) * natoms * 3);
virial.resize(static_cast<size_t>(nframes) * 9);
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
std::vector<VALUETYPE> fparam_, aparam_;
Expand Down Expand Up @@ -845,10 +845,10 @@ class DeepPot {
const int *atype_ = &atype[0];

double *ener_ = _DP_Get_Energy_Pointer(ener, nframes);
force.resize(nframes * natoms * 3);
virial.resize(nframes * 9);
atom_energy.resize(nframes * natoms);
atom_virial.resize(nframes * natoms * 9);
force.resize(static_cast<size_t>(nframes) * natoms * 3);
virial.resize(static_cast<size_t>(nframes) * 9);
atom_energy.resize(static_cast<size_t>(nframes) * natoms);
atom_virial.resize(static_cast<size_t>(nframes) * natoms * 9);
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
VALUETYPE *atomic_ener_ = &atom_energy[0];
Expand Down Expand Up @@ -910,8 +910,8 @@ class DeepPot {
const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr;
const int *atype_ = &atype[0];
double *ener_ = _DP_Get_Energy_Pointer(ener, nframes);
force.resize(nframes * natoms * 3);
virial.resize(nframes * 9);
force.resize(static_cast<size_t>(nframes) * natoms * 3);
virial.resize(static_cast<size_t>(nframes) * 9);
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
std::vector<VALUETYPE> fparam_, aparam_;
Expand Down Expand Up @@ -972,10 +972,10 @@ class DeepPot {
const int *atype_ = &atype[0];

double *ener_ = _DP_Get_Energy_Pointer(ener, nframes);
force.resize(nframes * natoms * 3);
virial.resize(nframes * 9);
atom_energy.resize(nframes * natoms);
atom_virial.resize(nframes * natoms * 9);
force.resize(static_cast<size_t>(nframes) * natoms * 3);
virial.resize(static_cast<size_t>(nframes) * 9);
atom_energy.resize(static_cast<size_t>(nframes) * natoms);
atom_virial.resize(static_cast<size_t>(nframes) * natoms * 9);
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
VALUETYPE *atomic_ener_ = &atom_energy[0];
Expand Down Expand Up @@ -1079,7 +1079,7 @@ class DeepPot {
const int &dparam,
const std::vector<VALUETYPE> &param) const {
if (param.size() == dparam) {
out_param.resize(nframes * dparam);
out_param.resize(static_cast<size_t>(nframes) * dparam);
for (int ii = 0; ii < nframes; ++ii) {
std::copy(param.begin(), param.end(), out_param.begin() + ii * dparam);
}
Expand Down Expand Up @@ -1210,7 +1210,7 @@ class DeepPotModelDevi {
virial.resize(numb_models);
for (int i = 0; i < numb_models; i++) {
ener[i] = energy_flat[i];
force[i].resize(natoms * 3);
force[i].resize(static_cast<size_t>(natoms) * 3);
virial[i].resize(9);
for (int j = 0; j < natoms * 3; j++) {
force[i][j] = force_flat[i * natoms * 3 + j];
Expand Down Expand Up @@ -1292,10 +1292,10 @@ class DeepPotModelDevi {
atom_virial.resize(numb_models);
for (int i = 0; i < numb_models; i++) {
ener[i] = energy_flat[i];
force[i].resize(natoms * 3);
force[i].resize(static_cast<size_t>(natoms) * 3);
virial[i].resize(9);
atom_energy[i].resize(natoms);
atom_virial[i].resize(natoms * 9);
atom_virial[i].resize(static_cast<size_t>(natoms) * 9);
for (int j = 0; j < natoms * 3; j++) {
force[i][j] = force_flat[i * natoms * 3 + j];
}
Expand Down Expand Up @@ -1496,7 +1496,7 @@ class DeepPotModelDevi {
const int &dparam,
const std::vector<VALUETYPE> &param) const {
if (param.size() == dparam) {
out_param.resize(nframes * dparam);
out_param.resize(static_cast<size_t>(nframes) * dparam);
for (int ii = 0; ii < nframes; ++ii) {
std::copy(param.begin(), param.end(), out_param.begin() + ii * dparam);
}
Expand Down Expand Up @@ -1653,8 +1653,8 @@ class DeepTensor {
const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr;
const int *atype_ = &atype[0];
global_tensor.resize(odim);
force.resize(odim * natoms * 3);
virial.resize(odim * 9);
force.resize(static_cast<size_t>(odim) * natoms * 3);
virial.resize(static_cast<size_t>(odim) * 9);
VALUETYPE *global_tensor_ = &global_tensor[0];
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
Expand Down Expand Up @@ -1697,9 +1697,9 @@ class DeepTensor {
const int *atype_ = &atype[0];

global_tensor.resize(odim);
force.resize(odim * natoms * 3);
virial.resize(odim * 9);
atom_virial.resize(odim * natoms * 9);
force.resize(static_cast<size_t>(odim) * natoms * 3);
virial.resize(static_cast<size_t>(odim) * 9);
atom_virial.resize(static_cast<size_t>(odim) * natoms * 9);
VALUETYPE *global_tensor_ = &global_tensor[0];
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
Expand Down Expand Up @@ -1752,8 +1752,8 @@ class DeepTensor {
const VALUETYPE *box_ = !box.empty() ? &box[0] : nullptr;
const int *atype_ = &atype[0];
global_tensor.resize(odim);
force.resize(odim * natoms * 3);
virial.resize(odim * 9);
force.resize(static_cast<size_t>(odim) * natoms * 3);
virial.resize(static_cast<size_t>(odim) * 9);
VALUETYPE *global_tensor_ = &global_tensor[0];
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
Expand Down Expand Up @@ -1800,9 +1800,9 @@ class DeepTensor {
const int *atype_ = &atype[0];

global_tensor.resize(odim);
force.resize(odim * natoms * 3);
virial.resize(odim * 9);
atom_virial.resize(odim * natoms * 9);
force.resize(static_cast<size_t>(odim) * natoms * 3);
virial.resize(static_cast<size_t>(odim) * 9);
atom_virial.resize(static_cast<size_t>(odim) * natoms * 9);
VALUETYPE *global_tensor_ = &global_tensor[0];
VALUETYPE *force_ = &force[0];
VALUETYPE *virial_ = &virial[0];
Expand Down Expand Up @@ -1954,7 +1954,7 @@ class DipoleChargeModifier {
const int *dpairs = reinterpret_cast<const int *>(&pairs[0]);
const VALUETYPE *delef = &delef_[0];

dfcorr_.resize(natoms * 3);
dfcorr_.resize(static_cast<size_t>(natoms) * 3);
dvcorr_.resize(9);
VALUETYPE *dfcorr = &dfcorr_[0];
VALUETYPE *dvcorr = &dvcorr_[0];
Expand Down Expand Up @@ -2071,7 +2071,7 @@ void select_map(std::vector<VT> &out,
nall2++;
}
}
out.resize(nall2 * stride);
out.resize(static_cast<size_t>(nall2) * stride);
DP_SelectMapInt(&in[0], &fwd_map[0], stride, nall1, nall2, &out[0]);
};

Expand Down
2 changes: 1 addition & 1 deletion source/api_c/tests/test_deepdipole_hpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class TestInferDeepDipoleNew : public ::testing::Test {
}
}

expected_gv.resize(odim * 9);
expected_gv.resize(static_cast<size_t>(odim) * 9);
for (int kk = 0; kk < odim; ++kk) {
for (int ii = 0; ii < natoms; ++ii) {
for (int dd = 0; dd < 9; ++dd) {
Expand Down
2 changes: 1 addition & 1 deletion source/api_c/tests/test_deeppolar_hpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class TestInferDeepPolarNew : public ::testing::Test {
}
}

expected_gv.resize(odim * 9);
expected_gv.resize(static_cast<size_t>(odim) * 9);
for (int kk = 0; kk < odim; ++kk) {
for (int ii = 0; ii < natoms; ++ii) {
for (int dd = 0; dd < 9; ++dd) {
Expand Down
4 changes: 2 additions & 2 deletions source/api_c/tests/test_deeppot_a_fparam_aparam_nframes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class TestInferDeepPotAFparamAparamNFrames : public ::testing::Test {
EXPECT_EQ(nframes * natoms * 3, expected_f.size());
EXPECT_EQ(nframes * natoms * 9, expected_v.size());
expected_tot_e.resize(nframes);
expected_tot_v.resize(nframes * 9);
expected_tot_v.resize(static_cast<size_t>(nframes) * 9);
std::fill(expected_tot_e.begin(), expected_tot_e.end(), 0.);
std::fill(expected_tot_v.begin(), expected_tot_v.end(), 0.);
for (int kk = 0; kk < nframes; ++kk) {
Expand Down Expand Up @@ -767,7 +767,7 @@ class TestInferDeepPotAFparamAparamNFramesSingleParam : public ::testing::Test {
EXPECT_EQ(nframes * natoms * 3, expected_f.size());
EXPECT_EQ(nframes * natoms * 9, expected_v.size());
expected_tot_e.resize(nframes);
expected_tot_v.resize(nframes * 9);
expected_tot_v.resize(static_cast<size_t>(nframes) * 9);
std::fill(expected_tot_e.begin(), expected_tot_e.end(), 0.);
std::fill(expected_tot_v.begin(), expected_tot_v.end(), 0.);
for (int kk = 0; kk < nframes; ++kk) {
Expand Down
4 changes: 2 additions & 2 deletions source/api_c/tests/test_deeppot_a_nframes_hpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class TestInferDeepPotANFrames : public ::testing::Test {
EXPECT_EQ(nframes * natoms * 3, expected_f.size());
EXPECT_EQ(nframes * natoms * 9, expected_v.size());
expected_tot_e.resize(nframes);
expected_tot_v.resize(nframes * 9);
expected_tot_v.resize(static_cast<size_t>(nframes) * 9);
std::fill(expected_tot_e.begin(), expected_tot_e.end(), 0.);
std::fill(expected_tot_v.begin(), expected_tot_v.end(), 0.);
for (int kk = 0; kk < nframes; ++kk) {
Expand Down Expand Up @@ -728,7 +728,7 @@ class TestInferDeepPotANFramesNoPbc : public ::testing::Test {
EXPECT_EQ(nframes * natoms * 3, expected_f.size());
EXPECT_EQ(nframes * natoms * 9, expected_v.size());
expected_tot_e.resize(nframes);
expected_tot_v.resize(nframes * 9);
expected_tot_v.resize(static_cast<size_t>(nframes) * 9);
std::fill(expected_tot_e.begin(), expected_tot_e.end(), 0.);
std::fill(expected_tot_v.begin(), expected_tot_v.end(), 0.);
for (int kk = 0; kk < nframes; ++kk) {
Expand Down
2 changes: 1 addition & 1 deletion source/api_c/tests/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inline void _fold_back(std::vector<VALUETYPE> &out,
const int nall,
const int ndim,
const int nframes = 1) {
out.resize(nframes * nloc * ndim);
out.resize(static_cast<size_t>(nframes) * nloc * ndim);
_fold_back<VALUETYPE>(out.begin(), in.begin(), mapping, nloc, nall, ndim,
nframes);
}
Expand Down
8 changes: 4 additions & 4 deletions source/api_cc/src/DataModifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void DipoleChargeModifier::run_model(
auto of = output_f.flat<MODELTYPE>();
auto ov = output_v.flat<MODELTYPE>();

dforce.resize(nall * 3);
dforce.resize(static_cast<size_t>(nall) * 3);
dvirial.resize(9);
for (int ii = 0; ii < nall * 3; ++ii) {
dforce[ii] = of(ii);
Expand Down Expand Up @@ -186,7 +186,7 @@ void DipoleChargeModifier::compute(
int nall_real = real_bkw_map.size();
int nloc_real = nall_real - nghost_real;
if (nloc_real == 0) {
dfcorr_.resize(nall * 3);
dfcorr_.resize(static_cast<size_t>(nall) * 3);
dvcorr_.resize(9);
fill(dfcorr_.begin(), dfcorr_.end(), (VALUETYPE)0.0);
fill(dvcorr_.begin(), dvcorr_.end(), (VALUETYPE)0.0);
Expand All @@ -196,8 +196,8 @@ void DipoleChargeModifier::compute(
std::vector<VALUETYPE> dcoord_real;
std::vector<VALUETYPE> delef_real;
std::vector<int> datype_real;
dcoord_real.resize(nall_real * 3);
delef_real.resize(nall_real * 3);
dcoord_real.resize(static_cast<size_t>(nall_real) * 3);
delef_real.resize(static_cast<size_t>(nall_real) * 3);
datype_real.resize(nall_real);
// fwd map
select_map<VALUETYPE>(dcoord_real, dcoord_, real_fwd_map, 3);
Expand Down
4 changes: 2 additions & 2 deletions source/api_cc/src/DeepTensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void DeepTensor::run_model(
}

// component-wise virial
dvirial_.resize(odim * 9);
dvirial_.resize(static_cast<size_t>(odim) * 9);
for (unsigned ii = 0; ii < odim * 9; ++ii) {
dvirial_[ii] = ov(ii);
}
Expand All @@ -266,7 +266,7 @@ void DeepTensor::run_model(
std::vector<int> sel_srt = sel_fwd;
select_map<int>(sel_srt, sel_fwd, atommap.get_fwd_map(), 1);
std::remove(sel_srt.begin(), sel_srt.end(), -1);
datom_tensor_.resize(nsel * odim);
datom_tensor_.resize(static_cast<size_t>(nsel) * odim);
select_map<VALUETYPE>(datom_tensor_, datom_tensor, sel_srt, odim);

// component-wise atomic virial
Expand Down
11 changes: 6 additions & 5 deletions source/api_cc/src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,15 @@ void deepmd::select_real_atoms_coord(std::vector<VALUETYPE>& dcoord,
// resize to nall_real
nall_real = bkw_map.size();
nloc_real = nall_real - nghost_real;
dcoord.resize(nframes * nall_real * 3);
dcoord.resize(static_cast<size_t>(nframes) * nall_real * 3);
datype.resize(nall_real);
// fwd map
select_map<VALUETYPE>(dcoord, dcoord_, fwd_map, 3, nframes, nall_real, nall);
select_map<int>(datype, datype_, fwd_map, 1);
// aparam
if (daparam > 0) {
aparam.resize(nframes * (aparam_nall ? nall_real : nloc_real));
aparam.resize(static_cast<size_t>(nframes) *
(aparam_nall ? nall_real : nloc_real));
select_map<VALUETYPE>(aparam, aparam_, fwd_map, daparam, nframes,
(aparam_nall ? nall_real : nloc_real),
(aparam_nall ? nall : (nall - nghost)));
Expand Down Expand Up @@ -396,7 +397,7 @@ int deepmd::session_input_tensors(

TensorShape coord_shape;
coord_shape.AddDim(nframes);
coord_shape.AddDim(nall * 3);
coord_shape.AddDim(static_cast<int64_t>(nall) * 3);
TensorShape type_shape;
type_shape.AddDim(nframes);
type_shape.AddDim(nall);
Expand Down Expand Up @@ -540,7 +541,7 @@ int deepmd::session_input_tensors(

TensorShape coord_shape;
coord_shape.AddDim(nframes);
coord_shape.AddDim(nall * 3);
coord_shape.AddDim(static_cast<int64_t>(nall) * 3);
TensorShape type_shape;
type_shape.AddDim(nframes);
type_shape.AddDim(nall);
Expand Down Expand Up @@ -675,7 +676,7 @@ int deepmd::session_input_tensors_mixed_type(

TensorShape coord_shape;
coord_shape.AddDim(nframes);
coord_shape.AddDim(nall * 3);
coord_shape.AddDim(static_cast<int64_t>(nall) * 3);
TensorShape type_shape;
type_shape.AddDim(nframes);
type_shape.AddDim(nall);
Expand Down
2 changes: 1 addition & 1 deletion source/api_cc/tests/test_deepdipole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class TestInferDeepDipoleNew : public ::testing::Test {
}
}

expected_gv.resize(odim * 9);
expected_gv.resize(static_cast<size_t>(odim) * 9);
for (int kk = 0; kk < odim; ++kk) {
for (int ii = 0; ii < natoms; ++ii) {
for (int dd = 0; dd < 9; ++dd) {
Expand Down
2 changes: 1 addition & 1 deletion source/api_cc/tests/test_deeppolar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class TestInferDeepPolarNew : public ::testing::Test {
}
}

expected_gv.resize(odim * 9);
expected_gv.resize(static_cast<size_t>(odim) * 9);
for (int kk = 0; kk < odim; ++kk) {
for (int ii = 0; ii < natoms; ++ii) {
for (int dd = 0; dd < 9; ++dd) {
Expand Down
4 changes: 2 additions & 2 deletions source/api_cc/tests/test_deeppot_a_fparam_aparam_nframes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class TestInferDeepPotAFparamAparamNFrames : public ::testing::Test {
EXPECT_EQ(nframes * natoms * 3, expected_f.size());
EXPECT_EQ(nframes * natoms * 9, expected_v.size());
expected_tot_e.resize(nframes);
expected_tot_v.resize(nframes * 9);
expected_tot_v.resize(static_cast<size_t>(nframes) * 9);
std::fill(expected_tot_e.begin(), expected_tot_e.end(), 0.);
std::fill(expected_tot_v.begin(), expected_tot_v.end(), 0.);
for (int kk = 0; kk < nframes; ++kk) {
Expand Down Expand Up @@ -768,7 +768,7 @@ class TestInferDeepPotAFparamAparamNFramesSingleParam : public ::testing::Test {
EXPECT_EQ(nframes * natoms * 3, expected_f.size());
EXPECT_EQ(nframes * natoms * 9, expected_v.size());
expected_tot_e.resize(nframes);
expected_tot_v.resize(nframes * 9);
expected_tot_v.resize(static_cast<size_t>(nframes) * 9);
std::fill(expected_tot_e.begin(), expected_tot_e.end(), 0.);
std::fill(expected_tot_v.begin(), expected_tot_v.end(), 0.);
for (int kk = 0; kk < nframes; ++kk) {
Expand Down
4 changes: 2 additions & 2 deletions source/api_cc/tests/test_deeppot_a_nframes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class TestInferDeepPotANFrames : public ::testing::Test {
EXPECT_EQ(nframes * natoms * 3, expected_f.size());
EXPECT_EQ(nframes * natoms * 9, expected_v.size());
expected_tot_e.resize(nframes);
expected_tot_v.resize(nframes * 9);
expected_tot_v.resize(static_cast<size_t>(nframes) * 9);
std::fill(expected_tot_e.begin(), expected_tot_e.end(), 0.);
std::fill(expected_tot_v.begin(), expected_tot_v.end(), 0.);
for (int kk = 0; kk < nframes; ++kk) {
Expand Down Expand Up @@ -732,7 +732,7 @@ class TestInferDeepPotANFramesNoPbc : public ::testing::Test {
EXPECT_EQ(nframes * natoms * 3, expected_f.size());
EXPECT_EQ(nframes * natoms * 9, expected_v.size());
expected_tot_e.resize(nframes);
expected_tot_v.resize(nframes * 9);
expected_tot_v.resize(static_cast<size_t>(nframes) * 9);
std::fill(expected_tot_e.begin(), expected_tot_e.end(), 0.);
std::fill(expected_tot_v.begin(), expected_tot_v.end(), 0.);
for (int kk = 0; kk < nframes; ++kk) {
Expand Down
Loading
Loading