From 10970629c55f3a58989a029c786def07631a2b79 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sat, 20 Jan 2024 09:23:48 -0500 Subject: [PATCH] resolve "Multiplication result converted to larger type" (#3159) Follow up #3149. --------- Signed-off-by: Jinzhe Zeng --- source/api_c/include/deepmd.hpp | 42 +++++++++++++--------- source/api_c/src/c_api.cc | 2 +- source/api_cc/src/AtomMap.cc | 12 ++++--- source/api_cc/src/DeepPot.cc | 6 ++-- source/ipi/src/Convert.cc | 4 +-- source/lib/tests/test_env_mat_a.cc | 22 ++++++------ source/lib/tests/test_env_mat_a_mix.cc | 33 +++++++++-------- source/lib/tests/test_env_mat_a_nvnmd.cc | 4 +-- source/lmp/compute_deeptensor_atom.cpp | 2 +- source/op/ewald_recp.cc | 8 +++-- source/op/matmul_fitnet_nvnmd.cc | 2 +- source/op/matmul_flt_nvnmd.cc | 6 ++-- source/op/pair_tab.cc | 12 ++++--- source/op/prod_env_mat_multi_device.cc | 2 +- source/op/prod_force.cc | 3 +- source/op/prod_force_grad.cc | 4 ++- source/op/prod_force_grad_multi_device.cc | 22 +++++++----- source/op/prod_force_multi_device.cc | 18 ++++++---- source/op/prod_force_se_a_grad.cc | 4 ++- source/op/prod_force_se_a_mask.cc | 3 +- source/op/prod_force_se_a_mask_grad.cc | 4 ++- source/op/prod_force_se_r_grad.cc | 4 ++- source/op/prod_virial.cc | 7 ++-- source/op/prod_virial_grad.cc | 10 ++++-- source/op/prod_virial_grad_multi_device.cc | 28 +++++++++------ source/op/prod_virial_se_a_grad.cc | 10 ++++-- source/op/prod_virial_se_r_grad.cc | 10 ++++-- source/op/soft_min.cc | 7 ++-- source/op/soft_min_force.cc | 3 +- source/op/soft_min_force_grad.cc | 6 ++-- source/op/soft_min_virial.cc | 7 ++-- source/op/soft_min_virial_grad.cc | 12 ++++--- 32 files changed, 202 insertions(+), 117 deletions(-) diff --git a/source/api_c/include/deepmd.hpp b/source/api_c/include/deepmd.hpp index 503a4c4b4b..06a50ee3f0 100644 --- a/source/api_c/include/deepmd.hpp +++ b/source/api_c/include/deepmd.hpp @@ -1060,14 +1060,15 @@ class DeepPot { const int &nloc, const std::vector &fparam, const std::vector &aparam) const { - if (fparam.size() != dfparam && fparam.size() != nframes * dfparam) { + if (fparam.size() != dfparam && + fparam.size() != static_cast(nframes) * dfparam) { throw deepmd::hpp::deepmd_exception( "the dim of frame parameter provided is not consistent with what the " "model uses"); } - if (aparam.size() != daparam * nloc && - aparam.size() != nframes * daparam * nloc) { + if (aparam.size() != static_cast(daparam) * nloc && + aparam.size() != static_cast(nframes) * daparam * nloc) { throw deepmd::hpp::deepmd_exception( "the dim of atom parameter provided is not consistent with what the " "model uses"); @@ -1081,9 +1082,10 @@ class DeepPot { if (param.size() == dparam) { out_param.resize(static_cast(nframes) * dparam); for (int ii = 0; ii < nframes; ++ii) { - std::copy(param.begin(), param.end(), out_param.begin() + ii * dparam); + std::copy(param.begin(), param.end(), + out_param.begin() + static_cast(ii) * dparam); } - } else if (param.size() == nframes * dparam) { + } else if (param.size() == static_cast(nframes) * dparam) { out_param = param; } } @@ -1184,7 +1186,8 @@ class DeepPotModelDevi { // memory will be continous for std::vector but not std::vector std::vector energy_flat(numb_models); - std::vector force_flat(numb_models * natoms * 3); + std::vector force_flat(static_cast(numb_models) * + natoms * 3); std::vector virial_flat(numb_models * 9); double *ener_ = &energy_flat[0]; VALUETYPE *force_ = &force_flat[0]; @@ -1260,10 +1263,13 @@ class DeepPotModelDevi { const int *atype_ = &atype[0]; std::vector energy_flat(numb_models); - std::vector force_flat(numb_models * natoms * 3); + std::vector force_flat(static_cast(numb_models) * + natoms * 3); std::vector virial_flat(numb_models * 9); - std::vector atom_energy_flat(numb_models * natoms); - std::vector atom_virial_flat(numb_models * natoms * 9); + std::vector atom_energy_flat(static_cast(numb_models) * + natoms); + std::vector atom_virial_flat(static_cast(numb_models) * + natoms * 9); double *ener_ = &energy_flat[0]; VALUETYPE *force_ = &force_flat[0]; VALUETYPE *virial_ = &virial_flat[0]; @@ -1402,8 +1408,8 @@ class DeepPotModelDevi { for (unsigned ii = 0; ii < numb_models; ++ii) { for (unsigned jj = 0; jj < nloc; ++jj) { - const VALUETYPE *tmp_f = &(xx[ii][jj * stride]); - const VALUETYPE *tmp_avg = &(avg[jj * stride]); + const VALUETYPE *tmp_f = &(xx[ii][static_cast(jj) * stride]); + const VALUETYPE *tmp_avg = &(avg[static_cast(jj) * stride]); for (unsigned dd = 0; dd < stride; ++dd) { VALUETYPE vdiff = tmp_f[dd] - tmp_avg[dd]; std[jj] += vdiff * vdiff; @@ -1432,7 +1438,7 @@ class DeepPotModelDevi { assert(nloc * stride == ndof); for (unsigned ii = 0; ii < nloc; ++ii) { - const VALUETYPE *tmp_avg = &(avg[ii * stride]); + const VALUETYPE *tmp_avg = &(avg[static_cast(ii) * stride]); VALUETYPE f_norm = 0.0; for (unsigned dd = 0; dd < stride; ++dd) { f_norm += tmp_avg[dd] * tmp_avg[dd]; @@ -1477,14 +1483,15 @@ class DeepPotModelDevi { const int &nloc, const std::vector &fparam, const std::vector &aparam) const { - if (fparam.size() != dfparam && fparam.size() != nframes * dfparam) { + if (fparam.size() != dfparam && + fparam.size() != static_cast(nframes) * dfparam) { throw deepmd::hpp::deepmd_exception( "the dim of frame parameter provided is not consistent with what the " "model uses"); } - if (aparam.size() != daparam * nloc && - aparam.size() != nframes * daparam * nloc) { + if (aparam.size() != static_cast(daparam) * nloc && + aparam.size() != static_cast(nframes) * daparam * nloc) { throw deepmd::hpp::deepmd_exception( "the dim of atom parameter provided is not consistent with what the " "model uses"); @@ -1498,9 +1505,10 @@ class DeepPotModelDevi { if (param.size() == dparam) { out_param.resize(static_cast(nframes) * dparam); for (int ii = 0; ii < nframes; ++ii) { - std::copy(param.begin(), param.end(), out_param.begin() + ii * dparam); + std::copy(param.begin(), param.end(), + out_param.begin() + static_cast(ii) * dparam); } - } else if (param.size() == nframes * dparam) { + } else if (param.size() == static_cast(nframes) * dparam) { out_param = param; } } diff --git a/source/api_c/src/c_api.cc b/source/api_c/src/c_api.cc index 935e812cf0..bc6178702f 100644 --- a/source/api_c/src/c_api.cc +++ b/source/api_c/src/c_api.cc @@ -1414,7 +1414,7 @@ void DP_SelectMapInt(const int* in, int* out) { std::vector in_(in, in + stride * nall1); std::vector fwd_map_(fwd_map, fwd_map + nall1); - std::vector out_(stride * nall2); + std::vector out_(static_cast(stride) * nall2); deepmd::select_map(out_, in_, fwd_map_, stride); if (out) { std::copy(out_.begin(), out_.end(), out); diff --git a/source/api_cc/src/AtomMap.cc b/source/api_cc/src/AtomMap.cc index 0b6105c5f2..b79f848277 100644 --- a/source/api_cc/src/AtomMap.cc +++ b/source/api_cc/src/AtomMap.cc @@ -39,8 +39,10 @@ void AtomMap::forward(typename std::vector::iterator out, int gro_i = idx_map[ii]; for (int dd = 0; dd < stride; ++dd) { // out[ii*stride+dd] = in[gro_i*stride+dd]; - *(out + kk * nall * stride + ii * stride + dd) = - *(in + kk * nall * stride + gro_i * stride + dd); + *(out + static_cast(kk) * nall * stride + + static_cast(ii) * stride + dd) = + *(in + static_cast(kk) * nall * stride + + static_cast(gro_i) * stride + dd); } } } @@ -58,8 +60,10 @@ void AtomMap::backward(typename std::vector::iterator out, int gro_i = idx_map[ii]; for (int dd = 0; dd < stride; ++dd) { // out[gro_i*stride+dd] = in[ii*stride+dd]; - *(out + kk * nall * stride + gro_i * stride + dd) = - *(in + kk * nall * stride + ii * stride + dd); + *(out + static_cast(kk) * nall * stride + + static_cast(gro_i) * stride + dd) = + *(in + static_cast(kk) * nall * stride + + static_cast(ii) * stride + dd); } } } diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index feb0f283b1..083e9b091f 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -761,8 +761,8 @@ void DeepPotModelDevi::compute_std( for (unsigned ii = 0; ii < numb_models; ++ii) { for (unsigned jj = 0; jj < nloc; ++jj) { - const VALUETYPE* tmp_f = &(xx[ii][jj * stride]); - const VALUETYPE* tmp_avg = &(avg[jj * stride]); + const VALUETYPE* tmp_f = &(xx[ii][static_cast(jj) * stride]); + const VALUETYPE* tmp_avg = &(avg[static_cast(jj) * stride]); for (unsigned dd = 0; dd < stride; ++dd) { VALUETYPE vdiff = tmp_f[dd] - tmp_avg[dd]; std[jj] += vdiff * vdiff; @@ -833,7 +833,7 @@ void DeepPotModelDevi::compute_relative_std(std::vector& std, assert(nloc * stride == ndof); for (unsigned ii = 0; ii < nloc; ++ii) { - const VALUETYPE* tmp_avg = &(avg[ii * stride]); + const VALUETYPE* tmp_avg = &(avg[static_cast(ii) * stride]); VALUETYPE f_norm = 0.0; for (unsigned dd = 0; dd < stride; ++dd) { f_norm += tmp_avg[dd] * tmp_avg[dd]; diff --git a/source/ipi/src/Convert.cc b/source/ipi/src/Convert.cc index 0a98962518..7dea877e3b 100644 --- a/source/ipi/src/Convert.cc +++ b/source/ipi/src/Convert.cc @@ -30,7 +30,7 @@ void Convert::forward(std::vector& out, const int stride) const { assert(in.size() == stride * idx_map.size()); int natoms = idx_map.size(); - out.resize(stride * natoms); + out.resize(static_cast(stride) * natoms); for (int ii = 0; ii < natoms; ++ii) { int gro_i = idx_map[ii]; for (int dd = 0; dd < stride; ++dd) { @@ -45,7 +45,7 @@ void Convert::backward(std::vector& out, const int stride) const { int natoms = idx_map.size(); assert(in.size() == stride * idx_map.size()); - out.resize(stride * natoms); + out.resize(static_cast(stride) * natoms); for (int ii = 0; ii < natoms; ++ii) { int gro_i = idx_map[ii]; for (int dd = 0; dd < stride; ++dd) { diff --git a/source/lib/tests/test_env_mat_a.cc b/source/lib/tests/test_env_mat_a.cc index 89756c9fc5..d041d1a0a1 100644 --- a/source/lib/tests/test_env_mat_a.cc +++ b/source/lib/tests/test_env_mat_a.cc @@ -504,11 +504,12 @@ TEST_F(TestEnvMatA, prod_cpu) { deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); deepmd::convert_nlist(inlist, nlist_a_cpy); - std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), - rij(nloc * nnei * 3); - std::vector nlist(nloc * nnei); - std::vector avg(ntypes * ndescrpt, 0); - std::vector std(ntypes * ndescrpt, 1); + std::vector em(static_cast(nloc) * ndescrpt), + em_deriv(static_cast(nloc) * ndescrpt * 3), + rij(static_cast(nloc) * nnei * 3); + std::vector nlist(static_cast(nloc) * nnei); + std::vector avg(static_cast(ntypes) * ndescrpt, 0); + std::vector std(static_cast(ntypes) * ndescrpt, 1); deepmd::prod_env_mat_a_cpu(&em[0], &em_deriv[0], &rij[0], &nlist[0], &posi_cpy[0], &atype_cpy[0], inlist, max_nbor_size, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); @@ -538,11 +539,12 @@ TEST_F(TestEnvMatA, prod_cpu_equal_cpu) { std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); - std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), - rij(nloc * nnei * 3); - std::vector nlist(nloc * nnei); - std::vector avg(ntypes * ndescrpt, 0); - std::vector std(ntypes * ndescrpt, 1); + std::vector em(static_cast(nloc) * ndescrpt), + em_deriv(static_cast(nloc) * ndescrpt * 3), + rij(static_cast(nloc) * nnei * 3); + std::vector nlist(static_cast(nloc) * nnei); + std::vector avg(static_cast(ntypes) * ndescrpt, 0); + std::vector std(static_cast(ntypes) * ndescrpt, 1); deepmd::prod_env_mat_a_cpu(&em[0], &em_deriv[0], &rij[0], &nlist[0], &posi_cpy[0], &atype_cpy[0], inlist, max_nbor_size, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); diff --git a/source/lib/tests/test_env_mat_a_mix.cc b/source/lib/tests/test_env_mat_a_mix.cc index 909088d1e3..d7e6cc88eb 100644 --- a/source/lib/tests/test_env_mat_a_mix.cc +++ b/source/lib/tests/test_env_mat_a_mix.cc @@ -532,11 +532,12 @@ TEST_F(TestEnvMatAMix, prod_cpu) { deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); deepmd::convert_nlist(inlist, nlist_a_cpy); - std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), - rij(nloc * nnei * 3); - std::vector nlist(nloc * nnei); - std::vector ntype(nloc * nnei); - bool *nmask = new bool[nloc * nnei]; + std::vector em(static_cast(nloc) * ndescrpt), + em_deriv(static_cast(nloc) * ndescrpt * 3), + rij(static_cast(nloc) * nnei * 3); + std::vector nlist(static_cast(nloc) * nnei); + std::vector ntype(static_cast(nloc) * nnei); + bool *nmask = new bool[static_cast(nloc) * nnei]; memset(nmask, 0, sizeof(bool) * nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); @@ -575,11 +576,12 @@ TEST_F(TestEnvMatAMix, prod_cpu_equal_cpu) { std::vector firstneigh(nloc); deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); - std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), - rij(nloc * nnei * 3); - std::vector nlist(nloc * nnei); - std::vector avg(ntypes * ndescrpt, 0); - std::vector std(ntypes * ndescrpt, 1); + std::vector em(static_cast(nloc) * ndescrpt), + em_deriv(static_cast(nloc) * ndescrpt * 3), + rij(static_cast(nloc) * nnei * 3); + std::vector nlist(static_cast(nloc) * nnei); + std::vector avg(static_cast(ntypes) * ndescrpt, 0); + std::vector std(static_cast(ntypes) * ndescrpt, 1); deepmd::prod_env_mat_a_cpu(&em[0], &em_deriv[0], &rij[0], &nlist[0], &posi_cpy[0], &atype[0], inlist, max_nbor_size, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a, @@ -652,11 +654,12 @@ TEST_F(TestEnvMatAMix, prod_gpu) { deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); - std::vector em(nloc * ndescrpt, 0.0), - em_deriv(nloc * ndescrpt * 3, 0.0), rij(nloc * nnei * 3, 0.0); - std::vector nlist(nloc * nnei, 0); - std::vector ntype(nloc * nnei, 0); - bool *nmask = new bool[nloc * nnei]; + std::vector em(static_cast(nloc) * ndescrpt, 0.0), + em_deriv(nloc * ndescrpt * 3, 0.0), + rij(static_cast(nloc) * nnei * 3, 0.0); + std::vector nlist(static_cast(nloc) * nnei, 0); + std::vector ntype(static_cast(nloc) * nnei, 0); + bool *nmask = new bool[static_cast(nloc) * nnei]; memset(nmask, 0, sizeof(bool) * nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); diff --git a/source/lib/tests/test_env_mat_a_nvnmd.cc b/source/lib/tests/test_env_mat_a_nvnmd.cc index cca468829e..bf55323ee0 100644 --- a/source/lib/tests/test_env_mat_a_nvnmd.cc +++ b/source/lib/tests/test_env_mat_a_nvnmd.cc @@ -274,7 +274,7 @@ TEST_F(TestEnvMatANvnmd, prod_cpu) { deepmd::convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), - rij(nloc * nnei * 3); + rij(static_cast(nloc) * nnei * 3); std::vector nlist(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); @@ -308,7 +308,7 @@ TEST_F(TestEnvMatANvnmd, prod_cpu_equal_cpu) { deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), - rij(nloc * nnei * 3); + rij(static_cast(nloc) * nnei * 3); std::vector nlist(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); diff --git a/source/lmp/compute_deeptensor_atom.cpp b/source/lmp/compute_deeptensor_atom.cpp index 2f4486002e..6e6e9508b7 100644 --- a/source/lmp/compute_deeptensor_atom.cpp +++ b/source/lmp/compute_deeptensor_atom.cpp @@ -178,6 +178,6 @@ void ComputeDeeptensorAtom::compute_peratom() { ------------------------------------------------------------------------- */ double ComputeDeeptensorAtom::memory_usage() { - double bytes = nmax * size_peratom_cols * sizeof(double); + double bytes = static_cast(nmax) * size_peratom_cols * sizeof(double); return bytes; } diff --git a/source/op/ewald_recp.cc b/source/op/ewald_recp.cc index 72f3c3d5dc..dcad204467 100644 --- a/source/op/ewald_recp.cc +++ b/source/op/ewald_recp.cc @@ -56,10 +56,14 @@ class EwaldRecpOp : public OpKernel { // check the sizes OP_REQUIRES( - context, (nsamples * nloc * 3 == coord_tensor.shape().dim_size(0)), + context, + (static_cast(nsamples) * nloc * 3 == + coord_tensor.shape().dim_size(0)), errors::InvalidArgument("coord number of samples should match")); OP_REQUIRES( - context, (nsamples * nloc * 1 == charge_tensor.shape().dim_size(0)), + context, + (static_cast(nsamples) * nloc * 1 == + charge_tensor.shape().dim_size(0)), errors::InvalidArgument("charge number of samples should match")); OP_REQUIRES( context, (nsamples * 9 == box_tensor.shape().dim_size(0)), diff --git a/source/op/matmul_fitnet_nvnmd.cc b/source/op/matmul_fitnet_nvnmd.cc index 28795526de..b5dc32a642 100644 --- a/source/op/matmul_fitnet_nvnmd.cc +++ b/source/op/matmul_fitnet_nvnmd.cc @@ -133,7 +133,7 @@ class MatmulFitnetNvnmdOp : public OpKernel { expo_maxs.resize(K); if (normw == 0) { - find_max_expo(expo_max, (FPTYPE*)&w[0], M * K); + find_max_expo(expo_max, (FPTYPE*)&w[0], static_cast(M) * K); for (kk = 0; kk < K; kk++) { expo_maxs[kk] = expo_max; } diff --git a/source/op/matmul_flt_nvnmd.cc b/source/op/matmul_flt_nvnmd.cc index 19e7a4869e..92b6375100 100644 --- a/source/op/matmul_flt_nvnmd.cc +++ b/source/op/matmul_flt_nvnmd.cc @@ -130,7 +130,8 @@ class MatmulFltNvnmdOp : public OpKernel { for (hh = 0; hh < H; hh++) { // find x max exponnet if ((normx & 0x0f) == 0) { // normalize x[:,:] - find_max_expo(expo_max1, (FPTYPE *)&x[hh * N * M], N * M); + find_max_expo(expo_max1, (FPTYPE *)&x[hh * N * M], + static_cast(N) * M); for (ii = 0; ii < N; ii++) { expo_max1s[ii] = expo_max1; } @@ -144,7 +145,8 @@ class MatmulFltNvnmdOp : public OpKernel { // find w max exponnet if ((normw & 0x0f) == 0) { // normalize w[:,:] - find_max_expo(expo_max2, (FPTYPE *)&w[hh * M * K], M * K); + find_max_expo(expo_max2, (FPTYPE *)&w[hh * M * K], + static_cast(M) * K); for (kk = 0; kk < K; kk++) { expo_max2s[kk] = expo_max2; } diff --git a/source/op/pair_tab.cc b/source/op/pair_tab.cc index 5c16e0faa4..0b04390d5f 100644 --- a/source/op/pair_tab.cc +++ b/source/op/pair_tab.cc @@ -89,10 +89,13 @@ class PairTabOp : public OpKernel { OP_REQUIRES(context, (nall == type_tensor.shape().dim_size(1)), errors::InvalidArgument("shape of type should be nall")); OP_REQUIRES( - context, (3 * nnei * nloc == rij_tensor.shape().dim_size(1)), + context, + (3 * static_cast(nnei) * nloc == + rij_tensor.shape().dim_size(1)), errors::InvalidArgument("shape of rij should be 3 * nloc * nnei")); OP_REQUIRES( - context, (nnei * nloc == nlist_tensor.shape().dim_size(1)), + context, + (static_cast(nnei) * nloc == nlist_tensor.shape().dim_size(1)), errors::InvalidArgument("shape of nlist should be nloc * nnei")); OP_REQUIRES(context, (nloc == scale_tensor.shape().dim_size(1)), errors::InvalidArgument("shape of scale should be nloc")); @@ -134,10 +137,11 @@ class PairTabOp : public OpKernel { "ntypes provided in table does not match deeppot")); int nspline = table_info(2) + 0.1; int tab_stride = 4 * nspline; - assert(ntypes * ntypes * tab_stride == + assert(static_cast(ntypes) * ntypes * tab_stride == table_data_tensor.shape().dim_size(0)); std::vector d_table_info(4); - std::vector d_table_data(ntypes * ntypes * tab_stride); + std::vector d_table_data(static_cast(ntypes) * ntypes * + tab_stride); for (unsigned ii = 0; ii < d_table_info.size(); ++ii) { d_table_info[ii] = table_info(ii); } diff --git a/source/op/prod_env_mat_multi_device.cc b/source/op/prod_env_mat_multi_device.cc index a99804cb9e..5ee43d2af3 100644 --- a/source/op/prod_env_mat_multi_device.cc +++ b/source/op/prod_env_mat_multi_device.cc @@ -1098,7 +1098,7 @@ class ProdEnvMatAMixOp : public OpKernel { Tensor fake_type_tensor; // all zeros TensorShape fake_type_shape; - fake_type_shape.AddDim(nsamples * nall); + fake_type_shape.AddDim(static_cast(nsamples) * nall); OP_REQUIRES_OK(context, context->allocate_temp(DT_INT32, fake_type_shape, &fake_type_tensor)); diff --git a/source/op/prod_force.cc b/source/op/prod_force.cc index 57d1cd1331..20269ebef3 100644 --- a/source/op/prod_force.cc +++ b/source/op/prod_force.cc @@ -70,7 +70,8 @@ class ProdForceOp : public OpKernel { errors::InvalidArgument("number of samples should match")); OP_REQUIRES(context, - (nloc * ndescrpt * 12 == in_deriv_tensor.shape().dim_size(1)), + (static_cast(nloc) * ndescrpt * 12 == + in_deriv_tensor.shape().dim_size(1)), errors::InvalidArgument("number of descriptors should match")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match")); diff --git a/source/op/prod_force_grad.cc b/source/op/prod_force_grad.cc index c1cf63917e..acfe9145fe 100644 --- a/source/op/prod_force_grad.cc +++ b/source/op/prod_force_grad.cc @@ -81,7 +81,9 @@ class ProdForceGradOp : public OpKernel { OP_REQUIRES( context, (nloc * 3 == grad_shape.dim_size(1)), errors::InvalidArgument("input grad shape should be 3 x natoms")); - OP_REQUIRES(context, (nloc * ndescrpt * 12 == in_deriv_shape.dim_size(1)), + OP_REQUIRES(context, + (static_cast(nloc) * ndescrpt * 12 == + in_deriv_shape.dim_size(1)), errors::InvalidArgument("number of descriptors should match")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match")); diff --git a/source/op/prod_force_grad_multi_device.cc b/source/op/prod_force_grad_multi_device.cc index bbcef6bd91..ee8a29732d 100644 --- a/source/op/prod_force_grad_multi_device.cc +++ b/source/op/prod_force_grad_multi_device.cc @@ -107,11 +107,14 @@ class ProdForceSeAGradOp : public OpKernel { assert(nframes == net_deriv_tensor.shape().dim_size(0)); assert(nframes == in_deriv_tensor.shape().dim_size(0)); assert(nframes == nlist_tensor.shape().dim_size(0)); - assert(nloc * ndescrpt == grad_net_shape.dim_size(1)); + assert(static_cast(nloc) * ndescrpt == grad_net_shape.dim_size(1)); assert(nloc * 3 == grad_shape.dim_size(1)); - assert(nloc * ndescrpt == net_deriv_tensor.shape().dim_size(1)); - assert(nloc * ndescrpt * 3 == in_deriv_tensor.shape().dim_size(1)); - assert(nloc * nnei == nlist_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt == + net_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt * 3 == + in_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * nnei == + nlist_tensor.shape().dim_size(1)); assert(nnei * 4 == ndescrpt); // flat the tensors FPTYPE* p_grad_net = grad_net_tensor->flat().data(); @@ -215,11 +218,14 @@ class ProdForceSeRGradOp : public OpKernel { assert(nframes == net_deriv_tensor.shape().dim_size(0)); assert(nframes == in_deriv_tensor.shape().dim_size(0)); assert(nframes == nlist_tensor.shape().dim_size(0)); - assert(nloc * ndescrpt == grad_net_shape.dim_size(1)); + assert(static_cast(nloc) * ndescrpt == grad_net_shape.dim_size(1)); assert(nloc * 3 == grad_shape.dim_size(1)); - assert(nloc * ndescrpt == net_deriv_tensor.shape().dim_size(1)); - assert(nloc * ndescrpt * 3 == in_deriv_tensor.shape().dim_size(1)); - assert(nloc * nnei == nlist_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt == + net_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt * 3 == + in_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * nnei == + nlist_tensor.shape().dim_size(1)); assert(nnei * 1 == ndescrpt); // flat the tensors FPTYPE* p_grad_net = grad_net_tensor->flat().data(); diff --git a/source/op/prod_force_multi_device.cc b/source/op/prod_force_multi_device.cc index 20cc96dd31..d48749faa5 100644 --- a/source/op/prod_force_multi_device.cc +++ b/source/op/prod_force_multi_device.cc @@ -115,9 +115,12 @@ class ProdForceSeAOp : public OpKernel { assert(nframes == in_deriv_tensor.shape().dim_size(0)); assert(nframes == nlist_tensor.shape().dim_size(0)); assert(nall * 3 == force_shape.dim_size(1)); - assert(nloc * ndescrpt == net_deriv_tensor.shape().dim_size(1)); - assert(nloc * ndescrpt * 3 == in_deriv_tensor.shape().dim_size(1)); - assert(nloc * nnei == nlist_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt == + net_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt * 3 == + in_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * nnei == + nlist_tensor.shape().dim_size(1)); assert(nnei * 4 == ndescrpt); // flat the tensors @@ -195,7 +198,8 @@ class ProdForceSeROp : public OpKernel { OP_REQUIRES(context, (nframes == nlist_tensor.shape().dim_size(0)), errors::InvalidArgument("number of samples should match")); OP_REQUIRES(context, - (nloc * ndescrpt * 3 == in_deriv_tensor.shape().dim_size(1)), + (static_cast(nloc) * ndescrpt * 3 == + in_deriv_tensor.shape().dim_size(1)), errors::InvalidArgument("number of descriptors should match")); // Create an output tensor TensorShape force_shape; @@ -212,8 +216,10 @@ class ProdForceSeROp : public OpKernel { assert(nframes == in_deriv_tensor.shape().dim_size(0)); assert(nframes == nlist_tensor.shape().dim_size(0)); assert(nall * 3 == force_shape.dim_size(1)); - assert(nloc * ndescrpt == net_deriv_tensor.shape().dim_size(1)); - assert(nloc * ndescrpt * 3 == in_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt == + net_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt * 3 == + in_deriv_tensor.shape().dim_size(1)); assert(nloc * nnei == nlist_tensor.shape().dim_size(1)); assert(nnei * 1 == ndescrpt); // flat the tensors diff --git a/source/op/prod_force_se_a_grad.cc b/source/op/prod_force_se_a_grad.cc index 5aaf030512..05e26b5058 100644 --- a/source/op/prod_force_se_a_grad.cc +++ b/source/op/prod_force_se_a_grad.cc @@ -77,7 +77,9 @@ class ProdForceSeAGradOp : public OpKernel { OP_REQUIRES( context, (nloc * 3 == grad_shape.dim_size(1)), errors::InvalidArgument("input grad shape should be 3 x natoms")); - OP_REQUIRES(context, (nloc * ndescrpt * 3 == in_deriv_shape.dim_size(1)), + OP_REQUIRES(context, + (static_cast(nloc) * ndescrpt * 3 == + in_deriv_shape.dim_size(1)), errors::InvalidArgument("number of descriptors should match")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match")); diff --git a/source/op/prod_force_se_a_mask.cc b/source/op/prod_force_se_a_mask.cc index aa4268434d..a7b08ae664 100644 --- a/source/op/prod_force_se_a_mask.cc +++ b/source/op/prod_force_se_a_mask.cc @@ -57,7 +57,8 @@ class ProdForceSeAMaskOp : public OpKernel { OP_REQUIRES(context, (nframes == nlist_tensor.shape().dim_size(0)), errors::InvalidArgument("number of samples should match")); OP_REQUIRES(context, - (nloc * ndescrpt * 3 == in_deriv_tensor.shape().dim_size(1)), + (static_cast(nloc) * ndescrpt * 3 == + in_deriv_tensor.shape().dim_size(1)), errors::InvalidArgument("number of descriptors should match")); // Create an output tensor diff --git a/source/op/prod_force_se_a_mask_grad.cc b/source/op/prod_force_se_a_mask_grad.cc index dabe405545..a01919199f 100644 --- a/source/op/prod_force_se_a_mask_grad.cc +++ b/source/op/prod_force_se_a_mask_grad.cc @@ -71,7 +71,9 @@ class ProdForceSeAMaskGradOp : public OpKernel { OP_REQUIRES( context, (nloc * 3 == grad_shape.dim_size(1)), errors::InvalidArgument("input grad shape should be 3 x natoms")); - OP_REQUIRES(context, (nloc * ndescrpt * 3 == in_deriv_shape.dim_size(1)), + OP_REQUIRES(context, + (static_cast(nloc) * ndescrpt * 3 == + in_deriv_shape.dim_size(1)), errors::InvalidArgument("number of descriptors should match")); // Create an output tensor diff --git a/source/op/prod_force_se_r_grad.cc b/source/op/prod_force_se_r_grad.cc index 0b5338c241..44741d20fb 100644 --- a/source/op/prod_force_se_r_grad.cc +++ b/source/op/prod_force_se_r_grad.cc @@ -71,7 +71,9 @@ class ProdForceSeRGradOp : public OpKernel { OP_REQUIRES( context, (nloc * 3 == grad_shape.dim_size(1)), errors::InvalidArgument("input grad shape should be 3 x natoms")); - OP_REQUIRES(context, (nloc * ndescrpt * 3 == in_deriv_shape.dim_size(1)), + OP_REQUIRES(context, + (static_cast(nloc) * ndescrpt * 3 == + in_deriv_shape.dim_size(1)), errors::InvalidArgument("number of descriptors should match")); // Create an output tensor diff --git a/source/op/prod_virial.cc b/source/op/prod_virial.cc index 10532d74db..42e7be669d 100644 --- a/source/op/prod_virial.cc +++ b/source/op/prod_virial.cc @@ -77,9 +77,12 @@ class ProdVirialOp : public OpKernel { errors::InvalidArgument("number of samples should match")); OP_REQUIRES(context, - (nloc * ndescrpt * 12 == in_deriv_tensor.shape().dim_size(1)), + (static_cast(nloc) * ndescrpt * 12 == + in_deriv_tensor.shape().dim_size(1)), errors::InvalidArgument("number of descriptors should match")); - OP_REQUIRES(context, (nloc * nnei * 3 == rij_tensor.shape().dim_size(1)), + OP_REQUIRES(context, + (static_cast(nloc) * nnei * 3 == + rij_tensor.shape().dim_size(1)), errors::InvalidArgument("dim of rij should be nnei * 3")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match")); diff --git a/source/op/prod_virial_grad.cc b/source/op/prod_virial_grad.cc index 02feba4eee..a764e524a6 100644 --- a/source/op/prod_virial_grad.cc +++ b/source/op/prod_virial_grad.cc @@ -88,10 +88,14 @@ class ProdVirialGradOp : public OpKernel { OP_REQUIRES( context, (9 == grad_shape.dim_size(1)), errors::InvalidArgument("input grad shape should be 3 x natoms")); - OP_REQUIRES(context, (nloc * ndescrpt * 12 == in_deriv_shape.dim_size(1)), + OP_REQUIRES(context, + (static_cast(nloc) * ndescrpt * 12 == + in_deriv_shape.dim_size(1)), errors::InvalidArgument("number of descriptors should match")); - OP_REQUIRES(context, (nloc * nnei * 3 == rij_shape.dim_size(1)), - errors::InvalidArgument("dim of rij should be nnei * 3")); + OP_REQUIRES( + context, + (static_cast(nloc) * nnei * 3 == rij_shape.dim_size(1)), + errors::InvalidArgument("dim of rij should be nnei * 3")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match")); OP_REQUIRES( diff --git a/source/op/prod_virial_grad_multi_device.cc b/source/op/prod_virial_grad_multi_device.cc index 215c26f184..3d8d2a96b3 100644 --- a/source/op/prod_virial_grad_multi_device.cc +++ b/source/op/prod_virial_grad_multi_device.cc @@ -118,12 +118,16 @@ class ProdVirialSeAGradOp : public OpKernel { assert(nframes == in_deriv_tensor.shape().dim_size(0)); assert(nframes == rij_tensor.shape().dim_size(0)); assert(nframes == nlist_tensor.shape().dim_size(0)); - assert(nloc * ndescrpt == grad_net_shape.dim_size(1)); + assert(static_cast(nloc) * ndescrpt == grad_net_shape.dim_size(1)); assert(9 == grad_shape.dim_size(1)); - assert(nloc * ndescrpt == net_deriv_tensor.shape().dim_size(1)); - assert(nloc * ndescrpt * 3 == in_deriv_tensor.shape().dim_size(1)); - assert(nloc * nnei * 3 == rij_tensor.shape().dim_size(1)); - assert(nloc * nnei == nlist_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt == + net_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt * 3 == + in_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * nnei * 3 == + rij_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * nnei == + nlist_tensor.shape().dim_size(1)); assert(nnei * 4 == ndescrpt); // flat the tensors @@ -246,12 +250,16 @@ class ProdVirialSeRGradOp : public OpKernel { assert(nframes == in_deriv_tensor.shape().dim_size(0)); assert(nframes == rij_tensor.shape().dim_size(0)); assert(nframes == nlist_tensor.shape().dim_size(0)); - assert(nloc * ndescrpt == grad_net_shape.dim_size(1)); + assert(static_cast(nloc) * ndescrpt == grad_net_shape.dim_size(1)); assert(9 == grad_shape.dim_size(1)); - assert(nloc * ndescrpt == net_deriv_tensor.shape().dim_size(1)); - assert(nloc * ndescrpt * 3 == in_deriv_tensor.shape().dim_size(1)); - assert(nloc * nnei * 3 == rij_tensor.shape().dim_size(1)); - assert(nloc * nnei == nlist_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt == + net_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * ndescrpt * 3 == + in_deriv_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * nnei * 3 == + rij_tensor.shape().dim_size(1)); + assert(static_cast(nloc) * nnei == + nlist_tensor.shape().dim_size(1)); assert(nnei * 1 == ndescrpt); // flat the tensors diff --git a/source/op/prod_virial_se_a_grad.cc b/source/op/prod_virial_se_a_grad.cc index d6c55b6969..e3a9374b8f 100644 --- a/source/op/prod_virial_se_a_grad.cc +++ b/source/op/prod_virial_se_a_grad.cc @@ -84,10 +84,14 @@ class ProdVirialSeAGradOp : public OpKernel { OP_REQUIRES( context, (9 == grad_shape.dim_size(1)), errors::InvalidArgument("input grad shape should be 3 x natoms")); - OP_REQUIRES(context, (nloc * ndescrpt * 3 == in_deriv_shape.dim_size(1)), + OP_REQUIRES(context, + (static_cast(nloc) * ndescrpt * 3 == + in_deriv_shape.dim_size(1)), errors::InvalidArgument("number of descriptors should match")); - OP_REQUIRES(context, (nloc * nnei * 3 == rij_shape.dim_size(1)), - errors::InvalidArgument("dim of rij should be nnei * 3")); + OP_REQUIRES( + context, + (static_cast(nloc) * nnei * 3 == rij_shape.dim_size(1)), + errors::InvalidArgument("dim of rij should be nnei * 3")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match")); diff --git a/source/op/prod_virial_se_r_grad.cc b/source/op/prod_virial_se_r_grad.cc index 40c2828ca7..8e9b2c25b0 100644 --- a/source/op/prod_virial_se_r_grad.cc +++ b/source/op/prod_virial_se_r_grad.cc @@ -78,10 +78,14 @@ class ProdVirialSeRGradOp : public OpKernel { OP_REQUIRES( context, (9 == grad_shape.dim_size(1)), errors::InvalidArgument("input grad shape should be 3 x natoms")); - OP_REQUIRES(context, (nloc * ndescrpt * 3 == in_deriv_shape.dim_size(1)), + OP_REQUIRES(context, + (static_cast(nloc) * ndescrpt * 3 == + in_deriv_shape.dim_size(1)), errors::InvalidArgument("number of descriptors should match")); - OP_REQUIRES(context, (nloc * nnei * 3 == rij_shape.dim_size(1)), - errors::InvalidArgument("dim of rij should be nnei * 3")); + OP_REQUIRES( + context, + (static_cast(nloc) * nnei * 3 == rij_shape.dim_size(1)), + errors::InvalidArgument("dim of rij should be nnei * 3")); // Create an output tensor TensorShape grad_net_shape; diff --git a/source/op/soft_min.cc b/source/op/soft_min.cc index 85aade5e7b..07c7404bbf 100644 --- a/source/op/soft_min.cc +++ b/source/op/soft_min.cc @@ -82,10 +82,13 @@ class SoftMinSwitchOp : public OpKernel { OP_REQUIRES(context, (nall == type_tensor.shape().dim_size(1)), errors::InvalidArgument("shape of type should be nall")); OP_REQUIRES( - context, (3 * nnei * nloc == rij_tensor.shape().dim_size(1)), + context, + (3 * static_cast(nnei) * nloc == + rij_tensor.shape().dim_size(1)), errors::InvalidArgument("shape of rij should be 3 * nloc * nnei")); OP_REQUIRES( - context, (nnei * nloc == nlist_tensor.shape().dim_size(1)), + context, + (static_cast(nnei) * nloc == nlist_tensor.shape().dim_size(1)), errors::InvalidArgument("shape of nlist should be nloc * nnei")); // Create an output tensor diff --git a/source/op/soft_min_force.cc b/source/op/soft_min_force.cc index 0801170597..14cb42b993 100644 --- a/source/op/soft_min_force.cc +++ b/source/op/soft_min_force.cc @@ -65,7 +65,8 @@ class SoftMinForceOp : public OpKernel { OP_REQUIRES(context, (nloc == du_tensor.shape().dim_size(1)), errors::InvalidArgument("number of du should match")); OP_REQUIRES(context, - (nloc * nnei * 3 == sw_deriv_tensor.shape().dim_size(1)), + (static_cast(nloc) * nnei * 3 == + sw_deriv_tensor.shape().dim_size(1)), errors::InvalidArgument("number of switch deriv should match")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match")); diff --git a/source/op/soft_min_force_grad.cc b/source/op/soft_min_force_grad.cc index 752ad4f93d..e173586d22 100644 --- a/source/op/soft_min_force_grad.cc +++ b/source/op/soft_min_force_grad.cc @@ -77,8 +77,10 @@ class SoftMinForceGradOp : public OpKernel { OP_REQUIRES( context, (nloc * 3 == grad_shape.dim_size(1)), errors::InvalidArgument("input grad shape should be 3 x natoms")); - OP_REQUIRES(context, (nloc * nnei * 3 == sw_deriv_shape.dim_size(1)), - errors::InvalidArgument("number of sw deriv should match")); + OP_REQUIRES( + context, + (static_cast(nloc) * nnei * 3 == sw_deriv_shape.dim_size(1)), + errors::InvalidArgument("number of sw deriv should match")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match")); diff --git a/source/op/soft_min_virial.cc b/source/op/soft_min_virial.cc index 26daa78604..6c0e1f72f3 100644 --- a/source/op/soft_min_virial.cc +++ b/source/op/soft_min_virial.cc @@ -73,9 +73,12 @@ class SoftMinVirialOp : public OpKernel { OP_REQUIRES(context, (nloc == du_tensor.shape().dim_size(1)), errors::InvalidArgument("number of du should match")); OP_REQUIRES(context, - (nloc * nnei * 3 == sw_deriv_tensor.shape().dim_size(1)), + (static_cast(nloc) * nnei * 3 == + sw_deriv_tensor.shape().dim_size(1)), errors::InvalidArgument("number of sw_deriv should match")); - OP_REQUIRES(context, (nloc * nnei * 3 == rij_tensor.shape().dim_size(1)), + OP_REQUIRES(context, + (static_cast(nloc) * nnei * 3 == + rij_tensor.shape().dim_size(1)), errors::InvalidArgument("dim of rij should be nnei * 3")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match")); diff --git a/source/op/soft_min_virial_grad.cc b/source/op/soft_min_virial_grad.cc index bc9cb96a63..ac129b29af 100644 --- a/source/op/soft_min_virial_grad.cc +++ b/source/op/soft_min_virial_grad.cc @@ -84,10 +84,14 @@ class SoftMinVirialGradOp : public OpKernel { errors::InvalidArgument("input grad shape should be 3 x natoms")); OP_REQUIRES(context, (nloc == du_tensor.shape().dim_size(1)), errors::InvalidArgument("number of du should match")); - OP_REQUIRES(context, (nloc * nnei * 3 == sw_deriv_shape.dim_size(1)), - errors::InvalidArgument("number of descriptors should match")); - OP_REQUIRES(context, (nloc * nnei * 3 == rij_shape.dim_size(1)), - errors::InvalidArgument("dim of rij should be nnei * 3")); + OP_REQUIRES( + context, + (static_cast(nloc) * nnei * 3 == sw_deriv_shape.dim_size(1)), + errors::InvalidArgument("number of descriptors should match")); + OP_REQUIRES( + context, + (static_cast(nloc) * nnei * 3 == rij_shape.dim_size(1)), + errors::InvalidArgument("dim of rij should be nnei * 3")); OP_REQUIRES(context, (nnei == n_a_sel + n_r_sel), errors::InvalidArgument("number of neighbors should match"));