Skip to content

Commit

Permalink
fix max_nbor_size related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
denghuilu committed Jan 20, 2024
1 parent d915a91 commit 9c95657
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions source/op/prod_env_mat_multi_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,15 @@ class ProdEnvMatAOp : public OpKernel {
mesh_tensor.flat<int>().data(), mesh_tensor_size, nloc, nei_mode,
rcut_r, max_cpy_trial, max_nnei_trial);

// max_nbor_size may be changed after _prepare_coord_nlist_gpu
// So we need to update the uint64_temp tensor if necessary
if (uint64_temp.NumElements() < int_64(nloc) * max_nbor_size * 2) {
TensorShape uint64_shape;
uint64_shape.AddDim(int_64(nloc) * max_nbor_size * 2);
OP_REQUIRES_OK(context, context->allocate_temp(
DT_UINT64, uint64_shape, &uint64_temp));
array_longlong = uint64_temp.flat<unsigned long long>().data();
}
// launch the gpu(nv) compute function
deepmd::prod_env_mat_a_gpu(em, em_deriv, rij, nlist, coord, type,
gpu_inlist, array_int, array_longlong,
Expand Down Expand Up @@ -875,6 +884,16 @@ class ProdEnvMatROp : public OpKernel {
mesh_tensor.flat<int>().data(), mesh_tensor_size, nloc, nei_mode,
rcut, max_cpy_trial, max_nnei_trial);

// max_nbor_size may be changed after _prepare_coord_nlist_gpu
// So we need to update the uint64_temp tensor if necessary
if (uint64_temp.NumElements() < int_64(nloc) * max_nbor_size * 2) {
TensorShape uint64_shape;
uint64_shape.AddDim(int_64(nloc) * max_nbor_size * 2);
OP_REQUIRES_OK(context, context->allocate_temp(
DT_UINT64, uint64_shape, &uint64_temp));
array_longlong = uint64_temp.flat<unsigned long long>().data();
}

// launch the gpu(nv) compute function
deepmd::prod_env_mat_r_gpu(em, em_deriv, rij, nlist, coord, type,
gpu_inlist, array_int, array_longlong,
Expand Down Expand Up @@ -1221,6 +1240,16 @@ class ProdEnvMatAMixOp : public OpKernel {
mesh_tensor.flat<int>().data(), mesh_tensor_size, nloc, nei_mode,
rcut_r, max_cpy_trial, max_nnei_trial);

// max_nbor_size may be changed after _prepare_coord_nlist_gpu
// So we need to update the uint64_temp tensor if necessary
if (uint64_temp.NumElements() < int_64(nloc) * max_nbor_size * 2) {
TensorShape uint64_shape;
uint64_shape.AddDim(int_64(nloc) * max_nbor_size * 2);
OP_REQUIRES_OK(context, context->allocate_temp(
DT_UINT64, uint64_shape, &uint64_temp));
array_longlong = uint64_temp.flat<unsigned long long>().data();
}

// launch the gpu(nv) compute function
deepmd::prod_env_mat_a_gpu(em, em_deriv, rij, nlist, coord, type,
gpu_inlist, array_int, array_longlong,
Expand Down

0 comments on commit 9c95657

Please sign in to comment.