Skip to content

Commit

Permalink
Get rid of duplicate definitions of DPErrcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
galeselee committed Jul 20, 2021
1 parent eea2ab1 commit c0f57f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 36 deletions.
37 changes: 1 addition & 36 deletions source/api_cc/src/DeepPot.cc
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
#include "DeepPot.h"
#include "AtomMap.h"
#include <stdexcept>
#include "device.h"

using namespace tensorflow;
using namespace deepmd;

#if GOOGLE_CUDA
#include "cuda_runtime.h"

#define DPErrcheck(res) { DPAssert((res), __FILE__, __LINE__); }
inline void DPAssert(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);
}
}

void DPGetDeviceCount(int &gpu_num) { cudaGetDeviceCount(&gpu_num) ;}

cudaError_t DPSetDevice(int rank) { return cudaSetDevice(rank); }
#endif

#if TENSORFLOW_USE_ROCM
#include<hip/hip_runtime.h>

#define DPErrcheck(res) { DPAssert((res), __FILE__, __LINE__); }
inline void DPAssert(hipError_t code, const char *file, int line, bool abort=true)
{
if (code != hipSuccess)
{
fprintf(stderr,"hip assert: %s %s %d\n", hipGetErrorString(code), file, line);
if (abort) exit(code);
}
}

void DPGetDeviceCount(int &gpu_num) { hipGetDeviceCount(&gpu_num) ;}
hipError_t DPSetDevice(int rank) { return hipSetDevice(rank); }

#endif //TENSORFLOW_USE_ROCM

static
std::vector<int> cum_sum (const std::vector<int32> & n_sel) {
std::vector<int> sec;
Expand Down
5 changes: 5 additions & 0 deletions source/lib/include/gpu_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ static __inline__ __device__ double atomicAdd(
#endif

namespace deepmd {

inline void DPGetDeviceCount(int &gpu_num) { cudaGetDeviceCount(&gpu_num) ;}

inline cudaError_t DPSetDevice(int rank) { return cudaSetDevice(rank); }

template <typename FPTYPE>
void memcpy_host_to_device(
FPTYPE * device,
Expand Down
5 changes: 5 additions & 0 deletions source/lib/include/gpu_rocm.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ inline void nborAssert(hipError_t code, const char *file, int line, bool abort=t
}
}


namespace deepmd {
inline void DPGetDeviceCount(int &gpu_num) { hipGetDeviceCount(&gpu_num) ;}

inline hipError_t DPSetDevice(int rank) { return hipSetDevice(rank); }

template <typename FPTYPE>
void memcpy_host_to_device(
FPTYPE * device,
Expand Down

0 comments on commit c0f57f6

Please sign in to comment.