Skip to content
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
28 changes: 17 additions & 11 deletions source/api_cc/src/DeepPotPT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
#ifdef BUILD_PYTORCH
#include "DeepPotPT.h"

#include <cstdint>

#include "common.h"
#include "device.h"

using namespace deepmd;

torch::Tensor createNlistTensor(const std::vector<std::vector<int>>& data) {
std::vector<torch::Tensor> row_tensors;

Expand Down Expand Up @@ -155,7 +159,7 @@ void DeepPotPT::compute(ENERGYVTYPE& ener,
at::Tensor coord_wrapped_Tensor =
torch::from_blob(coord_wrapped.data(), {1, nall_real, 3}, options)
.to(device);
std::vector<int64_t> atype_64(datype.begin(), datype.end());
std::vector<std::int64_t> atype_64(datype.begin(), datype.end());
at::Tensor atype_Tensor =
torch::from_blob(atype_64.data(), {1, nall_real}, int_option).to(device);
if (ago == 0) {
Expand Down Expand Up @@ -199,17 +203,18 @@ void DeepPotPT::compute(ENERGYVTYPE& ener,
if (!fparam.empty()) {
fparam_tensor =
torch::from_blob(const_cast<VALUETYPE*>(fparam.data()),
{1, static_cast<long int>(fparam.size())}, options)
{1, static_cast<std::int64_t>(fparam.size())}, options)
.to(device);
}
c10::optional<torch::Tensor> aparam_tensor;
if (!aparam_.empty()) {
aparam_tensor = torch::from_blob(
const_cast<VALUETYPE*>(aparam_.data()),
{1, lmp_list.inum,
static_cast<long int>(aparam_.size()) / lmp_list.inum},
options)
.to(device);
aparam_tensor =
torch::from_blob(
const_cast<VALUETYPE*>(aparam_.data()),
{1, lmp_list.inum,
static_cast<std::int64_t>(aparam_.size()) / lmp_list.inum},
options)
.to(device);
}
c10::Dict<c10::IValue, c10::IValue> outputs =
(do_message_passing == 1)
Expand Down Expand Up @@ -340,7 +345,7 @@ void DeepPotPT::compute(ENERGYVTYPE& ener,
torch::from_blob(coord_wrapped.data(), {1, natoms, 3}, options)
.to(device);
inputs.push_back(coord_wrapped_Tensor);
std::vector<int64_t> atype_64(atype.begin(), atype.end());
std::vector<std::int64_t> atype_64(atype.begin(), atype.end());
at::Tensor atype_Tensor =
torch::from_blob(atype_64.data(), {1, natoms}, int_options).to(device);
inputs.push_back(atype_Tensor);
Expand All @@ -355,7 +360,7 @@ void DeepPotPT::compute(ENERGYVTYPE& ener,
if (!fparam.empty()) {
fparam_tensor =
torch::from_blob(const_cast<VALUETYPE*>(fparam.data()),
{1, static_cast<long int>(fparam.size())}, options)
{1, static_cast<std::int64_t>(fparam.size())}, options)
.to(device);
}
inputs.push_back(fparam_tensor);
Expand All @@ -364,7 +369,8 @@ void DeepPotPT::compute(ENERGYVTYPE& ener,
aparam_tensor =
torch::from_blob(
const_cast<VALUETYPE*>(aparam.data()),
{1, natoms, static_cast<long int>(aparam.size()) / natoms}, options)
{1, natoms, static_cast<std::int64_t>(aparam.size()) / natoms},
options)
.to(device);
}
inputs.push_back(aparam_tensor);
Expand Down
3 changes: 2 additions & 1 deletion source/api_cc/src/DeepPotTF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifdef BUILD_TENSORFLOW
#include "DeepPotTF.h"

#include <cstdint>
#include <stdexcept>

#include "AtomMap.h"
Expand Down Expand Up @@ -549,7 +550,7 @@ void DeepPotTF::tile_fparam_aparam(std::vector<VALUETYPE>& out_param,
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() + static_cast<unsigned long>(ii) * dparam);
out_param.begin() + static_cast<std::uint64_t>(ii) * dparam);
}
} else if (param.size() == static_cast<size_t>(nframes) * dparam) {
out_param = param;
Expand Down
20 changes: 14 additions & 6 deletions source/op/pt/comm.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
#if defined(GOOGLE_CUDA) || defined(TENSORFLOW_USE_ROCM)
#include "device.h"
#endif
#include <torch/torch.h>

#ifdef USE_MPI
#include <mpi.h>
#ifdef OMPI_MPI_H
#include <mpi-ext.h>
#endif
#endif
#include <torch/torch.h>

#include <cstdint>

#if defined(GOOGLE_CUDA) || defined(TENSORFLOW_USE_ROCM)
#include "device.h"
#endif

#ifdef USE_MPI
template <typename T>
static MPI_Datatype get_mpi_type();

Expand All @@ -21,6 +28,7 @@ MPI_Datatype get_mpi_type<double>() {
return MPI_DOUBLE;
}
#endif

class Border : public torch::autograd::Function<Border> {
public:
static torch::autograd::variable_list forward(
Expand Down Expand Up @@ -321,9 +329,9 @@ class Border : public torch::autograd::Function<Border> {
static void unpack_communicator(const torch::Tensor& communicator_tensor,
MPI_Comm& mpi_comm) {
#ifdef OMPI_MPI_H
long int* communicator = communicator_tensor.data_ptr<long int>();
std::int64_t* communicator = communicator_tensor.data_ptr<std::int64_t>();
#else
long int* ptr = communicator_tensor.data_ptr<long int>();
std::int64_t* ptr = communicator_tensor.data_ptr<std::int64_t>();
int* communicator = reinterpret_cast<int*>(ptr);
#endif
mpi_comm = reinterpret_cast<MPI_Comm>(*communicator);
Expand Down