-
Notifications
You must be signed in to change notification settings - Fork 1
/
group.cu
62 lines (45 loc) · 1.48 KB
/
group.cu
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
#include "globals.h"
#include "group.h"
// Allocate *index and *d_index for
// max possible sites since that is biggest group
// could be.
void Group::Initialize() {
// Allocate memory for group indices on host
this->nsites = ns;
this->index = (int*)calloc(ns, sizeof(int));
// Allocate memory for group indices on device
cudaMalloc(&this->d_index, ns * sizeof(int));
device_mem_use += ns * sizeof(int);
// Initialize GPU grid, block size to ns sizes
this->grid = ns_Grid;
this->block = ns_Block;
}
Group::Group() {
}
Group::~Group() {
}
void make_group_all() {
for (int i = 0; i < ns; i++) {
Groups.at(0).index[i] = i;
}
Groups.at(0).nsites = ns;
Groups.at(0).block = threads;
Groups.at(0).grid = (int)ceil((float)(ns) / threads);
cudaMemcpy(Groups.at(0).d_index, Groups.at(0).index, Groups.at(0).nsites * sizeof(int), cudaMemcpyHostToDevice);
Groups.at(0).name = "all";
Groups.at(0).command_line = "NONE";
}
void make_group_type(int grp_index, int type_id) {
int ntype = 0;
for (int i = 0; i < ns; i++) {
if (tp[i] == type_id) {
Groups[grp_index].index[ntype] = i;
ntype++;
}
}
Groups[grp_index].nsites = ntype;
Groups[grp_index].block = threads;
Groups[grp_index].grid = (int)ceil((float)(ntype) / threads);
int gid = grp_index;
cudaMemcpy(Groups[gid].d_index, Groups[gid].index, Groups[gid].nsites * sizeof(int), cudaMemcpyHostToDevice);
}