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

device independence for deepmd-kit #254

Merged
merged 4 commits into from
Sep 16, 2020
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
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ else()
endif()
endif()
if (USE_CUDA_TOOLKIT)
add_definitions("-DUSE_CUDA_TOOLKIT")
add_definitions("-D GOOGLE_CUDA")
endif()

# define USE_TTM
Expand Down
572 changes: 572 additions & 0 deletions source/lib/include/CustomeOperation.h

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions source/lib/include/DeviceFunctor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once
#include <vector>
#include <climits>
#include <stdio.h>
#include <iostream>
#include <cuda_runtime.h>

typedef unsigned long long int_64;
#define SQRT_2_PI 0.7978845608028654

#define cudaErrcheck(res) {cudaAssert((res), __FILE__, __LINE__);}
inline void cudaAssert(cudaError_t code, const char *file, int line, bool abort=true) {
if (code != cudaSuccess) {
fprintf(stderr,"cuda assert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}

template<typename FPTYPE>
struct DescrptSeAGPUExecuteFunctor {
void operator()(const FPTYPE * coord, const int * type, const int * ilist, const int * jrange, const int * jlist, int * array_int, unsigned long long * array_longlong, const FPTYPE * avg, const FPTYPE * std, FPTYPE * descript, FPTYPE * descript_deriv, FPTYPE * rij, int * nlist, const int nloc, const int nall, const int nnei, const int ndescrpt, const float rcut_r, const float rcut_r_smth, const std::vector<int> sec_a, const bool fill_nei_a, const int MAGIC_NUMBER);
};

template<typename FPTYPE>
struct DescrptSeRGPUExecuteFunctor {
void operator()(const FPTYPE * coord, const int * type, const int * ilist, const int * jrange, const int * jlist, int * array_int, unsigned long long * array_longlong, const FPTYPE * avg, const FPTYPE * std, FPTYPE * descript, FPTYPE * descript_deriv, FPTYPE * rij, int * nlist, const int nloc, const int nall, const int nnei, const int ndescrpt, const float rcut_r, const float rcut_r_smth, const std::vector<int> sec_a, const bool fill_nei_a, const int MAGIC_NUMBER);
};

template<typename FPTYPE>
struct ProdForceSeAGPUExecuteFunctor {
void operator()(FPTYPE * force, const FPTYPE * net_derive, const FPTYPE * in_deriv, const int * nlist, const int nloc, const int nall, const int nnei, const int ndescrpt, const int n_a_sel, const int n_a_shift);
};

template<typename FPTYPE>
struct ProdForceSeRGPUExecuteFunctor {
void operator()(FPTYPE * force, const FPTYPE * net_derive, const FPTYPE * in_deriv, const int * nlist, const int nloc, const int nall, const int nnei, const int ndescrpt);
};

template<typename FPTYPE>
struct ProdVirialSeAGPUExecuteFunctor {
void operator()(FPTYPE * virial, FPTYPE * atom_virial, const FPTYPE * net_deriv, const FPTYPE * in_deriv, const FPTYPE * rij, const int * nlist, const int nloc, const int nall, const int nnei, const int ndescrpt, const int n_a_sel, const int n_a_shift);
};

template<typename FPTYPE>
struct ProdVirialSeRGPUExecuteFunctor {
void operator()(FPTYPE * virial, FPTYPE * atom_virial, const FPTYPE * net_deriv, const FPTYPE * in_deriv, const FPTYPE * rij, const int * nlist, const int nloc, const int nall, const int nnei, const int ndescrpt);
};

template<typename FPTYPE>
struct GeluGPUExecuteFunctor {
void operator()(const FPTYPE * in, FPTYPE * out, const int size);
};

template<typename FPTYPE>
struct GeluGradGPUExecuteFunctor {
void operator()(const FPTYPE * dy, const FPTYPE * in, FPTYPE * out, const int size);
};

template<typename FPTYPE>
struct GeluGradGradGPUExecuteFunctor {
void operator()(const FPTYPE * dy, const FPTYPE * dy_, const FPTYPE * in, FPTYPE * out, const int size);
};
6 changes: 0 additions & 6 deletions source/lib/include/NNPInter.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ class NNPInter

// function used for neighbor list copy
vector<int> get_sel_a() const;
#ifdef USE_CUDA_TOOLKIT
void update_nbor(const InternalNeighborList & nlist, const int nloc);
#endif
};

class NNPInterModelDevi
Expand Down Expand Up @@ -195,9 +192,6 @@ class NNPInterModelDevi
// function used for nborlist copy
vector<vector<int> > get_sel() const;
void cum_sum(const std::vector<std::vector<int32> > n_sel);
#ifdef USE_CUDA_TOOLKIT
void update_nbor(const InternalNeighborList & nlist, const int nloc);
#endif
};


20 changes: 20 additions & 0 deletions source/lib/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@

using namespace tensorflow;
using namespace std;
#include <tensorflow/core/graph/default_device.h>
#include <tensorflow/core/graph/graph_def_builder.h>

#include "NNPAtomMap.h"
#include <vector>
#include <string>
#include <iostream>
#include "version.h"

using CPUDevice = Eigen::ThreadPoolDevice;
using GPUDevice = Eigen::GpuDevice;
#ifdef HIGH_PREC
typedef double VALUETYPE;
typedef double ENERGYTYPE;
Expand Down Expand Up @@ -122,6 +128,20 @@ session_input_tensors (std::vector<std::pair<string, Tensor>> & input_tensors,
const int nghost = 0,
const string scope = "");

int
session_input_tensors (std::vector<std::pair<string, Tensor>> & input_tensors,
const vector<VALUETYPE> & dcoord_,
const int & ntypes,
const vector<int> & datype_,
const vector<VALUETYPE> & dbox,
InternalNeighborList & dlist,
const vector<VALUETYPE> & fparam_,
const vector<VALUETYPE> & aparam_,
const NNPAtomMap<VALUETYPE>& nnpmap,
const int nghost,
const int ago,
const string scope = "");

int
session_input_tensors (std::vector<std::pair<string, Tensor>> & input_tensors,
const vector<VALUETYPE> & dcoord_,
Expand Down
Loading