Skip to content

Commit 0ea22d7

Browse files
committed
Add timestep to destination times
1 parent a270103 commit 0ea22d7

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

external/Stats.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
void updateStats(sycl::queue myQueue, sycl::buffer<Actor> actorBuf,
55
std::vector<float> &averageForces,
6-
std::vector<int> &destinationTimes,
7-
std::chrono::high_resolution_clock::time_point startPoint) {
6+
std::vector<std::array<int, 2>> &destinationTimes,
7+
std::chrono::high_resolution_clock::time_point startPoint, int timestep) {
88
try {
99
float forceSum = 0;
1010
auto forceSumBuf = sycl::buffer<float>(&forceSum, 1);
@@ -58,7 +58,8 @@ void updateStats(sycl::queue myQueue, sycl::buffer<Actor> actorBuf,
5858
// Find actors which have reached their destination and record how long
5959
// it took them
6060
auto destinationTimesBuf =
61-
sycl::buffer<int>(destinationTimes.data(), destinationTimes.size());
61+
sycl::buffer<std::array<int, 2>>(destinationTimes.data(), destinationTimes.size());
62+
auto timestepBuf = sycl::buffer<int>(&timestep, 1);
6263

6364
myQueue
6465
.submit([&](sycl::handler &cgh) {
@@ -67,6 +68,7 @@ void updateStats(sycl::queue myQueue, sycl::buffer<Actor> actorBuf,
6768
auto destinationTimesAcc =
6869
destinationTimesBuf
6970
.get_access<sycl::access::mode::read_write>(cgh);
71+
auto timestepAcc = timestepBuf.get_access<sycl::access::mode::read>(cgh);
7072

7173
auto end = std::chrono::high_resolution_clock::now();
7274
auto duration =
@@ -77,8 +79,8 @@ void updateStats(sycl::queue myQueue, sycl::buffer<Actor> actorBuf,
7779
cgh.parallel_for(sycl::range<1>{destinationTimesAcc.size()},
7880
[=](sycl::id<1> index) {
7981
if (actorAcc[index].getAtDestination() &&
80-
destinationTimesAcc[index] == 0) {
81-
destinationTimesAcc[index] = duration;
82+
destinationTimesAcc[index][0] == 0) {
83+
destinationTimesAcc[index] = {int(duration), timestepAcc[0]};
8284
}
8385
});
8486
});
@@ -91,7 +93,7 @@ void updateStats(sycl::queue myQueue, sycl::buffer<Actor> actorBuf,
9193
}
9294

9395
void finalizeStats(sycl::queue myQueue, std::vector<float> averageForces,
94-
std::vector<int> destinationTimes,
96+
std::vector<std::array<int,2>> destinationTimes,
9597
std::vector<int> kernelDurations, int numActors,
9698
int totalExecutionTime) {
9799
try {
@@ -143,17 +145,22 @@ void finalizeStats(sycl::queue myQueue, std::vector<float> averageForces,
143145
<< std::endl;
144146
outputFile << std::endl << std::endl;
145147

146-
outputFile << "Actor ID | Time to Reach Destination (ms)"
148+
outputFile << "Actor ID | Time to Reach Destination (ms) | Timestep"
147149
<< std::endl;
148-
outputFile << "-----------------------------------------"
150+
outputFile << "----------------------------------------------------"
149151
<< std::endl;
150152
for (int x = 0; x < destinationTimes.size(); x++) {
151153
outputFile << std::setprecision(2) << std::fixed;
152154
outputFile << std::setw(8) << x << " |";
153-
if (destinationTimes[x] == 0) {
154-
outputFile << std::setw(30) << "NA";
155+
if (destinationTimes[x][0] == 0) {
156+
outputFile << std::setw(31) << "NA" << " |";
155157
} else {
156-
outputFile << std::setw(30) << destinationTimes[x];
158+
outputFile << std::setw(31) << destinationTimes[x][0] << " |";
159+
}
160+
if (destinationTimes[x][1] == 0) {
161+
outputFile << std::setw(8) << "NA";
162+
} else {
163+
outputFile << std::setw(8) << destinationTimes[x][1];
157164
}
158165
outputFile << std::endl;
159166
}
@@ -193,10 +200,10 @@ void finalizeStats(sycl::queue myQueue, std::vector<float> averageForces,
193200
std::ios::out);
194201
for (int x = 0; x < destinationTimes.size(); x++) {
195202
outputDestinationTimesCSV << x << ", ";
196-
if (destinationTimes[x] == 0) {
203+
if (destinationTimes[x][0] == 0) {
197204
outputDestinationTimesCSV << "-1" << std::endl;
198205
} else {
199-
outputDestinationTimesCSV << destinationTimes[x]
206+
outputDestinationTimesCSV << destinationTimes[x][0]
200207
<< std::endl;
201208
}
202209
}

external/Stats.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
void updateStats(sycl::queue myQueue, sycl::buffer<Actor> actorBuf,
1010
std::vector<float> &averageForces,
11-
std::vector<int> &destinationTimes,
12-
std::chrono::high_resolution_clock::time_point startPoint);
11+
std::vector<std::array<int, 2>> &destinationTimes,
12+
std::chrono::high_resolution_clock::time_point startPoint, int timestep);
1313

1414
void finalizeStats(sycl::queue myQueue, std::vector<float> averageForces,
15-
std::vector<int> destinationTimes,
15+
std::vector<std::array<int, 2>> destinationTimes,
1616
std::vector<int> kernelDurations, int numActors,
1717
int totalExecutionTime);
1818
#endif

src/main.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ int main(int argc, char *argv[]) {
194194

195195
int delayCounter = 0;
196196
int updateBBoxCounter = 0;
197-
int iterationCounter = 0;
197+
int profilingCounter = 0;
198+
int timestepCounter = 0;
198199
bool isPause = false;
199200
#ifndef PROFILING_MODE
200201
SDL_Event event;
@@ -205,19 +206,19 @@ int main(int argc, char *argv[]) {
205206
std::vector<float> averageForces;
206207
int updateStatsCounter = 49;
207208
auto startTime = std::chrono::high_resolution_clock::now();
208-
std::vector<int> destinationTimes;
209+
std::vector<std::array<int, 2>> destinationTimes;
209210
for (int x = 0; x < actors.size(); x++) {
210-
destinationTimes.push_back(0);
211+
destinationTimes.push_back({0, 0});
211212
}
212213
std::vector<int> kernelDurations;
213214
auto globalStart = std::chrono::high_resolution_clock::now();
214215
#endif
215216

216-
while (iterationCounter <= 500) {
217+
while (profilingCounter <= 500) {
217218
#ifndef PROFILING_MODE
218219
if (SDL_PollEvent(&event)) {
219220
if (event.type == SDL_QUIT) {
220-
iterationCounter = 501;
221+
profilingCounter = 501;
221222
} else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) {
222223
isPause = !isPause;
223224
}
@@ -245,7 +246,7 @@ int main(int argc, char *argv[]) {
245246
kernelDurations.push_back(kernelDuration.count());
246247

247248
if (updateStatsCounter >= 100) {
248-
updateStats(myQueue, actorBuf, averageForces, destinationTimes, startTime);
249+
updateStats(myQueue, actorBuf, averageForces, destinationTimes, startTime, timestepCounter);
249250
updateStatsCounter = 0;
250251
} else {
251252
updateStatsCounter++;
@@ -260,8 +261,9 @@ int main(int argc, char *argv[]) {
260261

261262
updateBBoxCounter--;
262263

264+
timestepCounter++;
263265
#ifdef PROFILING_MODE
264-
iterationCounter++;
266+
profilingCounter++;
265267
#endif
266268
} else {
267269
delayCounter++;

0 commit comments

Comments
 (0)