Skip to content

Commit 2cae562

Browse files
committed
use sycl::float2 instead of std::array
1 parent 9a45917 commit 2cae562

17 files changed

+88
-223
lines changed

external/Actor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525

2626
#include "Actor.hpp"
2727

28-
Actor::Actor(vecType pPos, vecType pVelocity, float pDesiredSpeed, int pPathId,
28+
Actor::Actor(sycl::float2 pPos, sycl::float2 pVelocity, float pDesiredSpeed, int pPathId,
2929
float pMass, float pRadius, bool pAtDestination,
3030
std::array<int, 3> pColor)
3131
: pos(pPos), velocity(pVelocity), desiredSpeed(pDesiredSpeed),
3232
pathId(pPathId), mass(pMass), radius(pRadius),
3333
atDestination(pAtDestination), color(pColor),
3434
destinationIndex(0), bBox({0, 0}) {}
3535

36-
SYCL_EXTERNAL vecType Actor::getPos() const { return pos; }
36+
SYCL_EXTERNAL sycl::float2 Actor::getPos() const { return pos; }
3737

38-
SYCL_EXTERNAL vecType Actor::getVelocity() const { return velocity; }
38+
SYCL_EXTERNAL sycl::float2 Actor::getVelocity() const { return velocity; }
3939

4040
SYCL_EXTERNAL float Actor::getDesiredSpeed() const { return desiredSpeed; }
4141

@@ -59,9 +59,9 @@ SYCL_EXTERNAL uint Actor::getSeed() const { return seed; }
5959

6060
SYCL_EXTERNAL float Actor::getForce() const { return force; }
6161

62-
SYCL_EXTERNAL void Actor::setPos(vecType newPos) { pos = newPos; }
62+
SYCL_EXTERNAL void Actor::setPos(sycl::float2 newPos) { pos = newPos; }
6363

64-
SYCL_EXTERNAL void Actor::setVelocity(vecType newVelocity) {
64+
SYCL_EXTERNAL void Actor::setVelocity(sycl::float2 newVelocity) {
6565
velocity = newVelocity;
6666
}
6767

@@ -85,7 +85,7 @@ SYCL_EXTERNAL void Actor::setSeed(uint newSeed) { seed = newSeed; }
8585

8686
SYCL_EXTERNAL void Actor::setForce(float newForce) { force = newForce; }
8787

88-
SYCL_EXTERNAL void Actor::checkAtDestination(std::array<vecType, 2> destination,
88+
SYCL_EXTERNAL void Actor::checkAtDestination(std::array<sycl::float2, 2> destination,
8989
int pathSize) {
9090
// Destinations are defined as rectangular regions
9191
if (pos[0] >= destination[0][0] && pos[0] <= destination[1][0] &&

external/Actor.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
#include "Path.hpp"
3030
#include "RandomNumber.hpp"
31-
#include "VectorMaths.hpp"
3231
#include <array>
3332
#include <iostream>
3433
#include <random>
@@ -37,8 +36,8 @@
3736

3837
class Actor {
3938
private:
40-
vecType pos;
41-
vecType velocity;
39+
sycl::float2 pos;
40+
sycl::float2 velocity;
4241
float desiredSpeed;
4342
int pathId;
4443
int destinationIndex;
@@ -51,12 +50,12 @@ class Actor {
5150
float force;
5251

5352
public:
54-
Actor(vecType pPos, vecType pVelocity, float pdesiredSpeed, int pPathId,
53+
Actor(sycl::float2 pPos, sycl::float2 pVelocity, float pdesiredSpeed, int pPathId,
5554
float pMass, float pRadius, bool pAtDestination,
5655
std::array<int, 3> pColor);
5756

58-
SYCL_EXTERNAL vecType getPos() const;
59-
SYCL_EXTERNAL vecType getVelocity() const;
57+
SYCL_EXTERNAL sycl::float2 getPos() const;
58+
SYCL_EXTERNAL sycl::float2 getVelocity() const;
6059
SYCL_EXTERNAL float getDesiredSpeed() const;
6160
SYCL_EXTERNAL int getPathId() const;
6261
SYCL_EXTERNAL int getDestinationIndex() const;
@@ -68,16 +67,16 @@ class Actor {
6867
SYCL_EXTERNAL uint getSeed() const;
6968
SYCL_EXTERNAL float getForce() const;
7069

71-
SYCL_EXTERNAL void setPos(vecType newPos);
72-
SYCL_EXTERNAL void setVelocity(vecType newVelocity);
70+
SYCL_EXTERNAL void setPos(sycl::float2 newPos);
71+
SYCL_EXTERNAL void setVelocity(sycl::float2 newVelocity);
7372
SYCL_EXTERNAL void setDesiredSpeed(float newDesiredSpeed);
7473
SYCL_EXTERNAL void setAtDestination(bool param);
7574
SYCL_EXTERNAL void setColor(std::array<int, 3> newColor);
7675
SYCL_EXTERNAL void setBBox(std::array<int, 2> newBBox);
7776
SYCL_EXTERNAL void setSeed(uint newSeed);
7877
SYCL_EXTERNAL void setForce(float newForce);
7978

80-
SYCL_EXTERNAL void checkAtDestination(std::array<vecType, 2> destination,
79+
SYCL_EXTERNAL void checkAtDestination(std::array<sycl::float2, 2> destination,
8180
int pathSize);
8281
};
8382

external/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ add_library(external Actor.cpp
55
Path.cpp
66
MathHelper.cpp
77
DifferentialEq.cpp
8-
VectorMaths.cpp
98
Heatmap.cpp
109
ParseInputFile.cpp
1110
RandomNumber.cpp

external/DifferentialEq.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@
2828
SYCL_EXTERNAL void differentialEq(
2929
int actorIndex,
3030
sycl::accessor<Actor, 1, sycl::access::mode::read_write> actors,
31-
sycl::accessor<std::array<vecType, 2>, 1, sycl::access::mode::read> walls,
31+
sycl::accessor<std::array<sycl::float2, 2>, 1, sycl::access::mode::read> walls,
3232
sycl::accessor<Path, 1, sycl::access::mode::read> paths,
3333
sycl::accessor<bool, 1, sycl::access::mode::read> heatmapEnabled) {
3434
Actor *currentActor = &actors[actorIndex];
3535

36-
vecType pos = currentActor->getPos();
36+
sycl::float2 pos = currentActor->getPos();
3737

3838
// Calculate personal impulse
3939
float mi = currentActor->getMass();
4040
float v0i = currentActor->getDesiredSpeed();
41-
std::array<vecType, 2> destination =
41+
std::array<sycl::float2, 2> destination =
4242
paths[currentActor->getPathId()]
4343
.getCheckpoints()[currentActor->getDestinationIndex()];
4444

4545
// Find direction vector to nearest point in destination region
46-
std::pair<float, vecType> minRegionDistance;
47-
std::array<vecType, 4> destinationRect = {
46+
std::pair<float, sycl::float2> minRegionDistance;
47+
std::array<sycl::float2, 4> destinationRect = {
4848
destination[0],
4949
{destination[1][0], destination[0][1]},
5050
destination[1],
@@ -60,11 +60,11 @@ SYCL_EXTERNAL void differentialEq(
6060
}
6161
}
6262
minRegionDistance.second = normalize(minRegionDistance.second);
63-
vecType e0i = {-minRegionDistance.second[0], -minRegionDistance.second[1]};
63+
sycl::float2 e0i = {-minRegionDistance.second[0], -minRegionDistance.second[1]};
6464

65-
vecType vi = currentActor->getVelocity();
65+
sycl::float2 vi = currentActor->getVelocity();
6666

67-
vecType personalImpulse = mi * (((v0i * e0i) - vi) / Ti);
67+
sycl::float2 personalImpulse = mi * (((v0i * e0i) - vi) / Ti);
6868

6969
// Collect neighbouring bounding boxes
7070
std::array<int, 2> currentBBox = currentActor->getBBox();
@@ -81,7 +81,7 @@ SYCL_EXTERNAL void differentialEq(
8181
}};
8282

8383
// Calculate forces applied by neighbouring actors (in valid bounding boxes)
84-
vecType peopleForces = {0, 0};
84+
sycl::float2 peopleForces = {0, 0};
8585
for (int x = 0; x < actors.size(); x++) {
8686
Actor neighbour = actors[x];
8787

@@ -93,11 +93,11 @@ SYCL_EXTERNAL void differentialEq(
9393
});
9494

9595
if (actorIndex != x && !neighbour.getAtDestination() && bBoxFlag) {
96-
vecType currentToNeighbour = pos - neighbour.getPos();
96+
sycl::float2 currentToNeighbour = pos - neighbour.getPos();
9797
float dij = magnitude(currentToNeighbour);
9898
float rij = neighbour.getRadius() + currentActor->getRadius();
99-
vecType nij = (currentToNeighbour) / dij;
100-
vecType tij = getTangentialVector(nij);
99+
sycl::float2 nij = (currentToNeighbour) / dij;
100+
sycl::float2 tij = getTangentialVector(nij);
101101
float g = dij > rij ? 0 : rij - dij;
102102
float deltavtij = dotProduct(
103103
(neighbour.getVelocity() - currentActor->getVelocity()), tij);
@@ -109,21 +109,21 @@ SYCL_EXTERNAL void differentialEq(
109109
}
110110

111111
// Calculate forces applied by walls
112-
vecType wallForces = {0, 0};
112+
sycl::float2 wallForces = {0, 0};
113113
for (int x = 0; x < walls.size(); x++) {
114-
std::array<vecType, 2> currentWall = walls[x];
114+
std::array<sycl::float2, 2> currentWall = walls[x];
115115
float ri = currentActor->getRadius();
116-
std::pair<float, vecType> dAndn = getDistanceAndNiw(pos, currentWall);
116+
std::pair<float, sycl::float2> dAndn = getDistanceAndNiw(pos, currentWall);
117117
float diw = dAndn.first;
118118
float g = diw > ri ? 0 : ri - diw;
119-
vecType niw = normalize(dAndn.second);
120-
vecType tiw = getTangentialVector(niw);
119+
sycl::float2 niw = normalize(dAndn.second);
120+
sycl::float2 tiw = getTangentialVector(niw);
121121

122122
wallForces += (WALLAi * sycl::exp((ri - diw) / Bi) + K1 * g) * niw -
123123
(K2 * g * dotProduct(vi, tiw) * tiw);
124124
}
125125

126-
vecType forceSum = personalImpulse + peopleForces + wallForces;
126+
sycl::float2 forceSum = personalImpulse + peopleForces + wallForces;
127127

128128
#ifdef STATS
129129
if (!currentActor->getAtDestination()) {
@@ -154,7 +154,7 @@ SYCL_EXTERNAL void differentialEq(
154154
}
155155

156156
// Perform integration
157-
vecType acceleration = forceSum / mi;
157+
sycl::float2 acceleration = forceSum / mi;
158158
currentActor->setVelocity(vi + acceleration * TIMESTEP);
159159
currentActor->setPos(pos + currentActor->getVelocity() * TIMESTEP);
160160

external/DifferentialEq.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "Heatmap.hpp"
3131
#include "MathHelper.hpp"
3232
#include "Path.hpp"
33-
#include "VectorMaths.hpp"
3433
#include <algorithm>
3534
#include <array>
3635
#include <iostream>
@@ -55,7 +54,7 @@ constexpr float TIMESTEP = 0.001;
5554
SYCL_EXTERNAL void differentialEq(
5655
int actorIndex,
5756
sycl::accessor<Actor, 1, sycl::access::mode::read_write> actors,
58-
sycl::accessor<std::array<vecType, 2>, 1, sycl::access::mode::read> walls,
57+
sycl::accessor<std::array<sycl::float2, 2>, 1, sycl::access::mode::read> walls,
5958
sycl::accessor<Path, 1, sycl::access::mode::read> paths,
6059
sycl::accessor<bool, 1, sycl::access::mode::read> heatmapEnabled);
6160

external/MathHelper.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,47 @@
2626

2727
#include "MathHelper.hpp"
2828

29-
SYCL_EXTERNAL vecType getDirectionVector(vecType from, vecType to) {
29+
SYCL_EXTERNAL sycl::float2 getDirectionVector(sycl::float2 from, sycl::float2 to) {
3030
return to - from;
3131
}
3232

33-
SYCL_EXTERNAL vecType velFromSpeedAndDir(float speed, vecType direction) {
33+
SYCL_EXTERNAL sycl::float2 velFromSpeedAndDir(float speed, sycl::float2 direction) {
3434
return direction * (speed * inverseMagnitude(direction));
3535
}
3636

37-
SYCL_EXTERNAL vecType velToPoint(float speed, vecType pos,
38-
vecType destination) {
37+
SYCL_EXTERNAL sycl::float2 velToPoint(float speed, sycl::float2 pos,
38+
sycl::float2 destination) {
3939
return velFromSpeedAndDir(speed, getDirectionVector(pos, destination));
4040
}
4141

42-
SYCL_EXTERNAL float magnitude(vecType inp) {
42+
SYCL_EXTERNAL float magnitude(sycl::float2 inp) {
4343
return sycl::sqrt((inp[0] * inp[0]) + (inp[1] * inp[1]));
4444
}
4545

4646
// Fast inverse square root optimisation
4747
// https://en.wikipedia.org/wiki/Fast_inverse_square_root
48-
SYCL_EXTERNAL float inverseMagnitude(vecType inp) {
48+
SYCL_EXTERNAL float inverseMagnitude(sycl::float2 inp) {
4949
return sycl::rsqrt((inp[0] * inp[0]) + (inp[1] * inp[1]));
5050
}
5151

52-
SYCL_EXTERNAL float dotProduct(vecType a, vecType b) {
52+
SYCL_EXTERNAL float dotProduct(sycl::float2 a, sycl::float2 b) {
5353
return (a[0] * b[0]) + (a[1] * b[1]);
5454
}
5555

56-
SYCL_EXTERNAL float distance(vecType from, vecType to) {
56+
SYCL_EXTERNAL float distance(sycl::float2 from, sycl::float2 to) {
5757
return magnitude(from - to);
5858
}
5959

60-
SYCL_EXTERNAL vecType normalize(vecType inp) {
60+
SYCL_EXTERNAL sycl::float2 normalize(sycl::float2 inp) {
6161
return inp * inverseMagnitude(inp);
6262
}
6363

6464
// Returns pair of distance to line and normalised direction from wall to point
65-
SYCL_EXTERNAL std::pair<float, vecType>
66-
getDistanceAndNiw(vecType point, std::array<vecType, 2> wall) {
67-
vecType AB = getDirectionVector(wall[0], wall[1]);
68-
vecType BP = getDirectionVector(wall[1], point);
69-
vecType AP = getDirectionVector(wall[0], point);
65+
SYCL_EXTERNAL std::pair<float, sycl::float2>
66+
getDistanceAndNiw(sycl::float2 point, std::array<sycl::float2, 2> wall) {
67+
sycl::float2 AB = getDirectionVector(wall[0], wall[1]);
68+
sycl::float2 BP = getDirectionVector(wall[1], point);
69+
sycl::float2 AP = getDirectionVector(wall[0], point);
7070

7171
float ABdotBP = dotProduct(AB, BP);
7272
float ABdotAP = dotProduct(AB, AP);
@@ -88,6 +88,6 @@ getDistanceAndNiw(vecType point, std::array<vecType, 2> wall) {
8888
}
8989
}
9090

91-
SYCL_EXTERNAL vecType getTangentialVector(vecType normal) {
91+
SYCL_EXTERNAL sycl::float2 getTangentialVector(sycl::float2 normal) {
9292
return {-normal[1], normal[0]};
9393
}

external/MathHelper.hpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,29 @@
2727
#ifndef MathHelper_hpp
2828
#define MathHelper_hpp
2929

30-
#include "VectorMaths.hpp"
3130
#include <array>
3231
#include <iostream>
3332
#include <sycl/sycl.hpp>
3433

35-
SYCL_EXTERNAL vecType getDirectionVector(vecType a, vecType b);
34+
SYCL_EXTERNAL sycl::float2 getDirectionVector(sycl::float2 a, sycl::float2 b);
3635

37-
SYCL_EXTERNAL vecType velFromSpeedAndDir(float speed, vecType direction);
36+
SYCL_EXTERNAL sycl::float2 velFromSpeedAndDir(float speed, sycl::float2 direction);
3837

39-
SYCL_EXTERNAL vecType velToPoint(float speed, vecType pos, vecType destination);
38+
SYCL_EXTERNAL sycl::float2 velToPoint(float speed, sycl::float2 pos, sycl::float2 destination);
4039

41-
SYCL_EXTERNAL float magnitude(vecType inp);
40+
SYCL_EXTERNAL float magnitude(sycl::float2 inp);
4241

43-
SYCL_EXTERNAL float inverseMagnitude(vecType inp);
42+
SYCL_EXTERNAL float inverseMagnitude(sycl::float2 inp);
4443

45-
SYCL_EXTERNAL float dotProduct(vecType a, vecType b);
44+
SYCL_EXTERNAL float dotProduct(sycl::float2 a, sycl::float2 b);
4645

47-
SYCL_EXTERNAL float distance(vecType a, vecType b);
46+
SYCL_EXTERNAL float distance(sycl::float2 a, sycl::float2 b);
4847

49-
SYCL_EXTERNAL vecType normalize(vecType inp);
48+
SYCL_EXTERNAL sycl::float2 normalize(sycl::float2 inp);
5049

51-
SYCL_EXTERNAL std::pair<float, vecType>
52-
getDistanceAndNiw(vecType point, std::array<vecType, 2> wall);
50+
SYCL_EXTERNAL std::pair<float, sycl::float2>
51+
getDistanceAndNiw(sycl::float2 point, std::array<sycl::float2, 2> wall);
5352

54-
SYCL_EXTERNAL vecType getTangentialVector(vecType normal);
53+
SYCL_EXTERNAL sycl::float2 getTangentialVector(sycl::float2 normal);
5554

5655
#endif

external/ParseInputFile.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ void parseInputFile(std::string filename, std::vector<Actor> &actors,
109109

110110
// Room
111111
auto jsonWalls = jsonDoc["room"]["walls"].GetArray();
112-
std::vector<std::array<vecType, 2>> walls;
112+
std::vector<std::array<sycl::float2, 2>> walls;
113113
for (auto &w : jsonWalls) {
114-
walls.push_back({vecType({w[0].GetFloat(), w[1].GetFloat()}),
115-
vecType({w[2].GetFloat(), w[3].GetFloat()})});
114+
walls.push_back({sycl::float2({w[0].GetFloat(), w[1].GetFloat()}),
115+
sycl::float2({w[2].GetFloat(), w[3].GetFloat()})});
116116
}
117117
room.setWalls(walls);
118118

@@ -121,17 +121,17 @@ void parseInputFile(std::string filename, std::vector<Actor> &actors,
121121
for (auto &p : jsonPaths) {
122122
int id = p["id"].GetInt();
123123
auto jsonCheckpoints = p["checkpoints"].GetArray();
124-
std::array<std::array<vecType, 2>, PATHALLOCATIONSIZE> checkpoints;
124+
std::array<std::array<sycl::float2, 2>, PATHALLOCATIONSIZE> checkpoints;
125125
if (jsonCheckpoints.Size() > PATHALLOCATIONSIZE) {
126126
throw JSONException(
127127
"Path Size exceeds amount allocated in memory\nEither reduce "
128128
"path size or increase PATHALLOCATIONSIZE in 'Path.hpp'");
129129
}
130130
for (int i = 0; i < jsonCheckpoints.Size(); i++) {
131-
std::array<vecType, 2> region;
132-
region[0] = vecType({jsonCheckpoints[i][0][0].GetFloat(),
131+
std::array<sycl::float2, 2> region;
132+
region[0] = sycl::float2({jsonCheckpoints[i][0][0].GetFloat(),
133133
jsonCheckpoints[i][0][1].GetFloat()});
134-
region[1] = vecType({jsonCheckpoints[i][1][0].GetFloat(),
134+
region[1] = sycl::float2({jsonCheckpoints[i][1][0].GetFloat(),
135135
jsonCheckpoints[i][1][1].GetFloat()});
136136
checkpoints[i] = region;
137137
}
@@ -142,8 +142,8 @@ void parseInputFile(std::string filename, std::vector<Actor> &actors,
142142
// Actor
143143
auto jsonActors = jsonDoc["actors"].GetArray();
144144
for (auto &a : jsonActors) {
145-
vecType pos = {a["pos"][0].GetFloat(), a["pos"][1].GetFloat()};
146-
vecType velocity = {a["velocity"][0].GetFloat(),
145+
sycl::float2 pos = {a["pos"][0].GetFloat(), a["pos"][1].GetFloat()};
146+
sycl::float2 velocity = {a["velocity"][0].GetFloat(),
147147
a["velocity"][1].GetFloat()};
148148
float desiredSpeed = a["desiredSpeed"].GetFloat();
149149
int pathId = a["pathId"].GetInt();

external/ParseInputFile.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "Actor.hpp"
3030
#include "Path.hpp"
3131
#include "Room.hpp"
32-
#include "VectorMaths.hpp"
3332
#include <array>
3433
#include <fstream>
3534
#include <iostream>

0 commit comments

Comments
 (0)