-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexperiment.cpp
137 lines (98 loc) · 4.41 KB
/
experiment.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "experiment.hpp"
bool Experiment::start()
{
cout<<"Initialize experiment data"<< endl;
Match match=Match(gconst.TURNS,1, gconst);
match.init();
srand (time(NULL));
Graph3D ogregraph;
ogregraph.initApp();
ogregraph.gconst=gconst;
ogregraph.InitSphereList(match.players, match.constraints);
numElements = gconst.number_of_bots;
cout<<"Initialize CUDA data"<< endl;
Player *hbotList;
Player *dbotList;
size_t botListSize = numElements * sizeof(Player);
hbotList = (Player*)malloc(botListSize);
cudaMalloc((void**)&dbotList, botListSize);
GameConstants *hconst;
GameConstants *dconst;
size_t constSize = sizeof(GameConstants);
hconst = (GameConstants*)malloc(constSize);
cudaMalloc((void**)&dconst, constSize);
::memcpy(hconst, &gconst, constSize);
//hconst=&gconst;
//hconst->DEPTH =gconst.DEPTH;
//hconst->WIDTH =gconst.WIDTH;
//hconst->HEIGHT=gconst.HEIGHT;
gpuAssert(cudaMemcpy(dconst, hconst, constSize, cudaMemcpyHostToDevice));
int constrSize=(int)(match.constraints.size());
Constraint *hConstrainList;
Constraint *dConstrainList;
size_t ConstrainListSize = constrSize* sizeof(Constraint);
hConstrainList = (Constraint*)malloc(ConstrainListSize);
cudaMalloc((void**)&dConstrainList, ConstrainListSize);
int allconstrSize=(int)(match.allconstraints.size());
Constraint *hallConstrainList;
Constraint *dallConstrainList;
size_t allConstrainListSize = allconstrSize* sizeof(Constraint);
hallConstrainList = (Constraint*)malloc(allConstrainListSize);
cudaMalloc((void**)&dallConstrainList, allConstrainListSize);
::memcpy(hallConstrainList, match.allconstraints.data(), allConstrainListSize);
cudaMemcpy(dallConstrainList, hallConstrainList, allConstrainListSize, cudaMemcpyHostToDevice);
::memcpy(hbotList, match.players.data(), botListSize);
gpuAssert(cudaMemcpy(dbotList, hbotList, botListSize, cudaMemcpyHostToDevice));
initKernelParticals( dbotList, gconst.number_of_bots, dconst);
::memcpy(hConstrainList, match.constraints.data(), ConstrainListSize);
gpuAssert(cudaMemcpy(dConstrainList, hConstrainList, ConstrainListSize, cudaMemcpyHostToDevice));
thrust::host_vector<int> D1(10);
thrust::fill(D1.begin(), D1.begin() + 7, 9);
//initTrust(D1);
cout<<"Start experiment"<< endl;
for(int tick=0; tick<match.max_turns; tick++)
{
ogregraph.MoveSphere(match.players, match.constraints,match.allconstraints);
ogregraph.DrawSphere(match.players, match.constraints);
ogregraph.showInfoWidget(tick);
ogregraph.getRoot()->renderOneFrame();
if(ogregraph.gconstChange )
{
ogregraph.gconstChange=false;
gconst= ogregraph.gconst;
::memcpy(hconst, &gconst, constSize);
//hconst=&gconst;
gpuAssert(cudaMemcpy(dconst, hconst, constSize, cudaMemcpyHostToDevice));
}
//graphModule.KeyDirection=0;
clock_t startTimer = clock();
updateBallVelocity(dbotList, dallConstrainList, dconst, gconst.number_of_bots);
if(tick>45)
{
updateConstrains(dbotList, dConstrainList, dallConstrainList, dconst, gconst.number_of_bots, constrSize);
}
gpuAssert(cudaMemcpy(hbotList, dbotList, botListSize, cudaMemcpyDeviceToHost));
std::memcpy(match.players.data(), hbotList, botListSize);
gpuAssert(cudaMemcpy(hConstrainList, dConstrainList, ConstrainListSize, cudaMemcpyDeviceToHost));
std::memcpy(match.constraints.data(), hConstrainList, ConstrainListSize);
gpuAssert(cudaMemcpy(hallConstrainList, dallConstrainList, allConstrainListSize, cudaMemcpyDeviceToHost));
std::memcpy(match.allconstraints.data(), hallConstrainList, allConstrainListSize);
// sleep(1);
clock_t stopTimer = clock();
timerLoop = (int)(stopTimer - startTimer);
if(ogregraph.exitGraphLoop)
break;
}
cout<<"Free experiment data"<< endl;
cudaFree(dallConstrainList);
cudaFree(dConstrainList);
cudaFree(dbotList);
cudaFree(dconst);
free(hallConstrainList);
free(hConstrainList);
free(hbotList);
free(hconst);
cout<<"Finish experiment"<< endl;
result_exp=true;
return result_exp;
}