Skip to content

Commit 2435418

Browse files
committed
formatting
1 parent 0ea22d7 commit 2435418

File tree

4 files changed

+108
-106
lines changed

4 files changed

+108
-106
lines changed

external/Actor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ SYCL_EXTERNAL void Actor::setBBox(std::array<int, 2> newBBox) {
6060

6161
SYCL_EXTERNAL void Actor::setSeed(uint newSeed) { seed = newSeed; }
6262

63-
SYCL_EXTERNAL void Actor::setForce(float newForce) {
64-
force = newForce;
65-
}
63+
SYCL_EXTERNAL void Actor::setForce(float newForce) { force = newForce; }
6664

6765
SYCL_EXTERNAL void Actor::checkAtDestination(std::array<vecType, 2> destination,
6866
int pathSize) {

external/Stats.cpp

Lines changed: 75 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
void updateStats(sycl::queue myQueue, sycl::buffer<Actor> actorBuf,
55
std::vector<float> &averageForces,
66
std::vector<std::array<int, 2>> &destinationTimes,
7-
std::chrono::high_resolution_clock::time_point startPoint, int timestep) {
7+
std::chrono::high_resolution_clock::time_point startPoint,
8+
int timestep) {
89
try {
910
float forceSum = 0;
1011
auto forceSumBuf = sycl::buffer<float>(&forceSum, 1);
@@ -13,87 +14,83 @@ void updateStats(sycl::queue myQueue, sycl::buffer<Actor> actorBuf,
1314
auto activeActorsBuf = sycl::buffer<int>(&activeActors, 1);
1415

1516
// Calculate average force applied to actors this iteration
16-
myQueue
17-
.submit([&](sycl::handler &cgh) {
18-
auto actorAcc =
19-
actorBuf.get_access<sycl::access::mode::read>(cgh);
20-
21-
auto forceSumReduction =
22-
sycl::reduction(forceSumBuf, cgh, sycl::plus<float>());
23-
24-
cgh.parallel_for(sycl::range<1>{actorAcc.size()},
25-
forceSumReduction,
26-
[=](sycl::id<1> index, auto &sum) {
27-
if (!actorAcc[index].getAtDestination()) {
28-
sum += actorAcc[index].getForce();
29-
}
30-
});
31-
});
17+
myQueue.submit([&](sycl::handler &cgh) {
18+
auto actorAcc = actorBuf.get_access<sycl::access::mode::read>(cgh);
19+
20+
auto forceSumReduction =
21+
sycl::reduction(forceSumBuf, cgh, sycl::plus<float>());
22+
23+
cgh.parallel_for(sycl::range<1>{actorAcc.size()}, forceSumReduction,
24+
[=](sycl::id<1> index, auto &sum) {
25+
if (!actorAcc[index].getAtDestination()) {
26+
sum += actorAcc[index].getForce();
27+
}
28+
});
29+
});
3230
myQueue.throw_asynchronous();
3331

34-
myQueue
35-
.submit([&](sycl::handler &cgh) {
36-
auto actorAcc =
37-
actorBuf.get_access<sycl::access::mode::read>(cgh);
38-
39-
auto activeActorsReduction =
40-
sycl::reduction(activeActorsBuf, cgh, sycl::plus<int>());
41-
42-
cgh.parallel_for(sycl::range<1>{actorAcc.size()},
43-
activeActorsReduction,
44-
[=](sycl::id<1> index, auto &sum) {
45-
if (!actorAcc[index].getAtDestination()) {
46-
sum += 1;
47-
}
48-
});
49-
});
32+
myQueue.submit([&](sycl::handler &cgh) {
33+
auto actorAcc = actorBuf.get_access<sycl::access::mode::read>(cgh);
34+
35+
auto activeActorsReduction =
36+
sycl::reduction(activeActorsBuf, cgh, sycl::plus<int>());
37+
38+
cgh.parallel_for(sycl::range<1>{actorAcc.size()},
39+
activeActorsReduction,
40+
[=](sycl::id<1> index, auto &sum) {
41+
if (!actorAcc[index].getAtDestination()) {
42+
sum += 1;
43+
}
44+
});
45+
});
5046
myQueue.throw_asynchronous();
5147

5248
sycl::host_accessor<float, 1, sycl::access::mode::read> forceSumHostAcc(
5349
forceSumBuf);
5450
sycl::host_accessor<int, 1, sycl::access::mode::read>
5551
activeActorsHostAcc(activeActorsBuf);
56-
averageForces.push_back(forceSumHostAcc[0] / float(activeActorsHostAcc[0]));
52+
averageForces.push_back(forceSumHostAcc[0] /
53+
float(activeActorsHostAcc[0]));
5754

5855
// Find actors which have reached their destination and record how long
5956
// it took them
60-
auto destinationTimesBuf =
61-
sycl::buffer<std::array<int, 2>>(destinationTimes.data(), destinationTimes.size());
57+
auto destinationTimesBuf = sycl::buffer<std::array<int, 2>>(
58+
destinationTimes.data(), destinationTimes.size());
6259
auto timestepBuf = sycl::buffer<int>(&timestep, 1);
6360

64-
myQueue
65-
.submit([&](sycl::handler &cgh) {
66-
auto actorAcc =
67-
actorBuf.get_access<sycl::access::mode::read>(cgh);
68-
auto destinationTimesAcc =
69-
destinationTimesBuf
70-
.get_access<sycl::access::mode::read_write>(cgh);
71-
auto timestepAcc = timestepBuf.get_access<sycl::access::mode::read>(cgh);
72-
73-
auto end = std::chrono::high_resolution_clock::now();
74-
auto duration =
75-
std::chrono::duration_cast<std::chrono::milliseconds>(
76-
end - startPoint)
77-
.count();
78-
79-
cgh.parallel_for(sycl::range<1>{destinationTimesAcc.size()},
80-
[=](sycl::id<1> index) {
81-
if (actorAcc[index].getAtDestination() &&
82-
destinationTimesAcc[index][0] == 0) {
83-
destinationTimesAcc[index] = {int(duration), timestepAcc[0]};
84-
}
85-
});
86-
});
61+
myQueue.submit([&](sycl::handler &cgh) {
62+
auto actorAcc = actorBuf.get_access<sycl::access::mode::read>(cgh);
63+
auto destinationTimesAcc =
64+
destinationTimesBuf.get_access<sycl::access::mode::read_write>(
65+
cgh);
66+
auto timestepAcc =
67+
timestepBuf.get_access<sycl::access::mode::read>(cgh);
68+
69+
auto end = std::chrono::high_resolution_clock::now();
70+
auto duration =
71+
std::chrono::duration_cast<std::chrono::milliseconds>(
72+
end - startPoint)
73+
.count();
74+
75+
cgh.parallel_for(sycl::range<1>{destinationTimesAcc.size()},
76+
[=](sycl::id<1> index) {
77+
if (actorAcc[index].getAtDestination() &&
78+
destinationTimesAcc[index][0] == 0) {
79+
destinationTimesAcc[index] = {
80+
int(duration), timestepAcc[0]};
81+
}
82+
});
83+
});
8784
myQueue.throw_asynchronous();
88-
85+
8986
} catch (const sycl::exception &e) {
9087
std::cout << "SYCL exception caught:\n"
9188
<< e.what() << "\n[updateStats]";
9289
}
9390
}
9491

9592
void finalizeStats(sycl::queue myQueue, std::vector<float> averageForces,
96-
std::vector<std::array<int,2>> destinationTimes,
93+
std::vector<std::array<int, 2>> destinationTimes,
9794
std::vector<int> kernelDurations, int numActors,
9895
int totalExecutionTime) {
9996
try {
@@ -106,21 +103,18 @@ void finalizeStats(sycl::queue myQueue, std::vector<float> averageForces,
106103
sycl::buffer<int>(kernelDurations.data(), kernelDurations.size());
107104

108105
// Calculate average kernel duration
109-
myQueue
110-
.submit([&](sycl::handler &cgh) {
111-
auto durationAcc =
112-
kernelDurationsBuf.get_access<sycl::access::mode::read>(
113-
cgh);
114-
115-
auto sumReduction =
116-
sycl::reduction(durationSumBuf, cgh, sycl::plus<int>());
117-
118-
cgh.parallel_for(sycl::range<1>{durationAcc.size()},
119-
sumReduction,
120-
[=](sycl::id<1> index, auto &sum) {
121-
sum += durationAcc[index];
122-
});
123-
});
106+
myQueue.submit([&](sycl::handler &cgh) {
107+
auto durationAcc =
108+
kernelDurationsBuf.get_access<sycl::access::mode::read>(cgh);
109+
110+
auto sumReduction =
111+
sycl::reduction(durationSumBuf, cgh, sycl::plus<int>());
112+
113+
cgh.parallel_for(sycl::range<1>{durationAcc.size()}, sumReduction,
114+
[=](sycl::id<1> index, auto &sum) {
115+
sum += durationAcc[index];
116+
});
117+
});
124118
myQueue.throw_asynchronous();
125119

126120
sycl::host_accessor<int, 1, sycl::access::mode::read>
@@ -153,11 +147,13 @@ void finalizeStats(sycl::queue myQueue, std::vector<float> averageForces,
153147
outputFile << std::setprecision(2) << std::fixed;
154148
outputFile << std::setw(8) << x << " |";
155149
if (destinationTimes[x][0] == 0) {
156-
outputFile << std::setw(31) << "NA" << " |";
150+
outputFile << std::setw(31) << "NA"
151+
<< " |";
157152
} else {
158-
outputFile << std::setw(31) << destinationTimes[x][0] << " |";
153+
outputFile << std::setw(31) << destinationTimes[x][0]
154+
<< " |";
159155
}
160-
if (destinationTimes[x][1] == 0) {
156+
if (destinationTimes[x][1] == 0) {
161157
outputFile << std::setw(8) << "NA";
162158
} else {
163159
outputFile << std::setw(8) << destinationTimes[x][1];

external/Stats.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
void updateStats(sycl::queue myQueue, sycl::buffer<Actor> actorBuf,
1010
std::vector<float> &averageForces,
1111
std::vector<std::array<int, 2>> &destinationTimes,
12-
std::chrono::high_resolution_clock::time_point startPoint, int timestep);
12+
std::chrono::high_resolution_clock::time_point startPoint,
13+
int timestep);
1314

1415
void finalizeStats(sycl::queue myQueue, std::vector<float> averageForces,
1516
std::vector<std::array<int, 2>> destinationTimes,

src/main.cpp

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ int main(int argc, char *argv[]) {
197197
int profilingCounter = 0;
198198
int timestepCounter = 0;
199199
bool isPause = false;
200-
#ifndef PROFILING_MODE
200+
#ifndef PROFILING_MODE
201201
SDL_Event event;
202-
#endif
202+
#endif
203203

204204
// Initialise stats variables if STATS flag is true
205205
#ifdef STATS
@@ -215,23 +215,24 @@ int main(int argc, char *argv[]) {
215215
#endif
216216

217217
while (profilingCounter <= 500) {
218-
#ifndef PROFILING_MODE
218+
#ifndef PROFILING_MODE
219219
if (SDL_PollEvent(&event)) {
220220
if (event.type == SDL_QUIT) {
221221
profilingCounter = 501;
222-
} else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) {
222+
} else if (event.type == SDL_KEYDOWN &&
223+
event.key.keysym.sym == SDLK_SPACE) {
223224
isPause = !isPause;
224225
}
225226
}
226-
#endif
227+
#endif
227228

228229
if (!isPause) {
229230
if (delayCounter >= DELAY) {
230231
delayCounter = 0;
231232

232-
#ifdef STATS
233+
#ifdef STATS
233234
auto kernelStart = std::chrono::high_resolution_clock::now();
234-
#endif
235+
#endif
235236

236237
if (updateBBoxCounter <= 0) {
237238
updateBBox(myQueue, actorBuf);
@@ -240,47 +241,53 @@ int main(int argc, char *argv[]) {
240241

241242
update(myQueue, actorBuf, wallsBuf, pathsBuf);
242243

243-
#ifdef STATS
244+
#ifdef STATS
244245
auto kernelEnd = std::chrono::high_resolution_clock::now();
245-
auto kernelDuration = std::chrono::duration_cast<std::chrono::microseconds>(kernelEnd - kernelStart);
246+
auto kernelDuration =
247+
std::chrono::duration_cast<std::chrono::microseconds>(
248+
kernelEnd - kernelStart);
246249
kernelDurations.push_back(kernelDuration.count());
247250

248251
if (updateStatsCounter >= 100) {
249-
updateStats(myQueue, actorBuf, averageForces, destinationTimes, startTime, timestepCounter);
252+
updateStats(myQueue, actorBuf, averageForces,
253+
destinationTimes, startTime, timestepCounter);
250254
updateStatsCounter = 0;
251255
} else {
252256
updateStatsCounter++;
253257
}
254-
#endif
258+
#endif
255259

256-
sycl::host_accessor<Actor, 1, sycl::access::mode::read> actorHostAcc(actorBuf);
260+
sycl::host_accessor<Actor, 1, sycl::access::mode::read>
261+
actorHostAcc(actorBuf);
257262

258-
#ifndef PROFILING_MODE
263+
#ifndef PROFILING_MODE
259264
draw(SCALE, BGCOLOR, WALLCOLOR, render, actorHostAcc, room);
260-
#endif
265+
#endif
261266

262267
updateBBoxCounter--;
263268

264269
timestepCounter++;
265-
#ifdef PROFILING_MODE
270+
#ifdef PROFILING_MODE
266271
profilingCounter++;
267-
#endif
272+
#endif
268273
} else {
269274
delayCounter++;
270275
}
271276
}
272277
}
273278

274-
#ifdef STATS
279+
#ifdef STATS
275280
auto globalEnd = std::chrono::high_resolution_clock::now();
276-
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(globalEnd - globalStart);
277-
278-
finalizeStats(myQueue, averageForces, destinationTimes, kernelDurations, actors.size(), duration.count());
279-
#endif
281+
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
282+
globalEnd - globalStart);
280283

281-
#ifndef PROFILING_MODE
284+
finalizeStats(myQueue, averageForces, destinationTimes, kernelDurations,
285+
actors.size(), duration.count());
286+
#endif
287+
288+
#ifndef PROFILING_MODE
282289
close(win, render);
283-
#endif
290+
#endif
284291

285292
return 0;
286293
}

0 commit comments

Comments
 (0)