-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCudaAtomGroup.h
65 lines (48 loc) · 1.45 KB
/
CudaAtomGroup.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef CUDAATOMGROUP_H
#define CUDAATOMGROUP_H
#include "AtomGroupBase.h"
//
// Cuda implementation of base class virtual methods
//
class CudaAtomGroupBase : public AtomGroupBase {
public:
CudaAtomGroupBase(const int size, const int numGroupList, const char* name) :
AtomGroupBase(size, numGroupList, name) {}
// Implementation of virtual methods
void resizeTable(const int new_numTable) {
reallocate<int>(&table, &lenTable, new_numTable, 1.2f);
}
void getGroupTableVec(std::vector<int>& tableVec) {
tableVec.resize(this->numTable);
copy_DtoH_sync<int>(this->table, tableVec.data(), this->numTable);
}
};
//
// Template class for atom groups
//
template<typename T>
class CudaAtomGroup : public CudaAtomGroupBase {
private:
// Global group list, constant. Stored in device memory
T* groupList;
public:
CudaAtomGroup(const int numGroupList, T* h_groupList, const char* name) :
CudaAtomGroupBase(T::size(), numGroupList, name) {
groupList = NULL;
if (numGroupList > 0) {
allocate<T>(&groupList, numGroupList);
copy_HtoD_sync<T>(h_groupList, groupList, numGroupList);
}
}
~CudaAtomGroup() {
if (groupList != NULL) deallocate<T>(&groupList);
if (table != NULL) deallocate<int>(&table);
}
T* get_groupList() {return groupList;}
void printGroup(const int i) {
T group;
copy_DtoH_sync<T>(&groupList[i], &group, 1);
group.printAtoms();
}
};
#endif // CUDAATOMGROUP_H