Skip to content

Commit 3db5919

Browse files
committed
Compile for spir-gen
1 parent 370355e commit 3db5919

File tree

6 files changed

+24
-40
lines changed

6 files changed

+24
-40
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ find_package(SDL2 REQUIRED)
1212
include_directories(${SDL2_INCLUDE_DIRS})
1313

1414
add_executable(crowdsim src/main.cpp)
15-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl")
15+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl -fsycl-targets=spir64-gen")
1616

1717
add_subdirectory(external)
1818

external/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ SYCL_EXTERNAL void Actor::checkAtDestination(vecType destination, int pathSize)
9595
void Actor::refreshVariation() {
9696
std::random_device rd;
9797
std::mt19937 gen(rd());
98-
std::normal_distribution<float> distr{0.0f, 1.0f};
98+
std::normal_distribution<float> distr{0.0f, 2.0f};
9999
this->setVariation({distr(gen), distr(gen)});
100100
}

external/DifferentialEq.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ SYCL_EXTERNAL void differentialEq(int currentIndex, sycl::accessor<Actor, 1, syc
55

66
vecType pos = currentActor->getPos();
77

8+
// Calculate personal impulse
89
float mi = currentActor->getMass();
910
float v0i = currentActor->getDesiredSpeed();
1011
vecType destination = paths[currentActor->getPathId()].getCheckpoints()[currentActor->getDestinationIndex()];
1112
vecType e0i = normalize(getDirectionVector(currentActor->getPos(), destination));
1213
vecType vi = currentActor->getVelocity();
1314

1415
vecType personalImpulse = mi * (((v0i * e0i) - vi) / Ti);
15-
16-
out << pos[0] << ", " << pos[1] << " -> " << destination[0] << ", " << destination[1] << sycl::endl;
1716

17+
// Calculate forces applied by neighbouring actors
1818
vecType peopleForces = {0, 0};
1919
for (int x = 0; x < actors.size(); x++) {
2020
Actor neighbour = actors[x];
@@ -31,6 +31,7 @@ SYCL_EXTERNAL void differentialEq(int currentIndex, sycl::accessor<Actor, 1, syc
3131
}
3232
}
3333

34+
// Calculate forces applied by walls
3435
vecType wallForces = {0, 0};
3536
for (int x = 0; x < walls.size(); x++) {
3637
std::array<vecType, 2> currentWall = walls[x];
@@ -45,22 +46,24 @@ SYCL_EXTERNAL void differentialEq(int currentIndex, sycl::accessor<Actor, 1, syc
4546
}
4647

4748
vecType forceSum = personalImpulse + peopleForces + wallForces;
49+
50+
// Apply random force variations
4851
forceSum += currentActor->getVariation();
4952

53+
// Color actor according to heatmap
5054
if (currentActor->getHeatmapEnabled()) {
51-
auto colorVal = std::fabs((forceSum[0] + forceSum[1]) / 700.0f);
55+
auto colorVal = sycl::fabs((forceSum[0] + forceSum[1]) / 700.0f);
5256
if (colorVal > 1) { colorVal = 1.0f; }
5357
auto color = findColor(colorVal);
5458
currentActor->setColor({int(color[0]), int(color[1]), int(color[2])});
5559
}
5660

57-
vecType acceleration = forceSum / mi;
58-
59-
//out << "People Forces: (" << peopleForces[0] << ", " << peopleForces[1] << ") " << z << sycl::endl;
60-
//out << "Wall Forces: (" << wallForces[0] << ", " << wallForces[1] << ") " << z << sycl::endl;
61-
//out << "Acceleration: (" << acceleration[0] << ", " << acceleration[1] << ") " << z << sycl::endl;
62-
//out << "-----------------------" << sycl::endl;
61+
// out << "People Forces: (" << peopleForces[0] << ", " << peopleForces[1] << ") " << z << sycl::endl;
62+
// out << "Wall Forces: (" << wallForces[0] << ", " << wallForces[1] << ") " << z << sycl::endl;
63+
// out << "Acceleration: (" << acceleration[0] << ", " << acceleration[1] << ") " << z << sycl::endl;
64+
// out << "-----------------------" << sycl::endl;
6365

66+
vecType acceleration = forceSum / mi;
6467
currentActor->setVelocity(vi + acceleration * TIMESTEP);
6568
currentActor->setPos(pos + currentActor->getVelocity() * TIMESTEP);
6669

external/Heatmap.cpp

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

33
SYCL_EXTERNAL std::array<float, 3> HSVtoRGB(float h, float s, float v) {
44
float c = v * s;
5-
float scaledH = std::fmod(h / 60.0, 6);
6-
float x = c * (1 - std::fabs(std::fmod(scaledH, 2) - 1));
5+
double scaledH = sycl::fmod(h / 60.0, 6.0);
6+
float x = c * (1 - sycl::fabs(sycl::fmod(scaledH, 2.0) - 1));
77
float m = v - c;
88

99
std::array<float, 3> rgb = {};
@@ -15,7 +15,7 @@ SYCL_EXTERNAL std::array<float, 3> HSVtoRGB(float h, float s, float v) {
1515
else if (4 <= scaledH && scaledH < 5) { rgb[0] = x; rgb[1] = 0; rgb[2] = c; }
1616
else if (5 <= scaledH && scaledH < 6) { rgb[0] = c; rgb[1] = 0; rgb[2] = x; }
1717
else { rgb[0] = 0; rgb[1] = 0; rgb[2] = 0; }
18-
18+
1919
return rgb;
2020
}
2121

external/MathHelper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYCL_EXTERNAL vecType velToPoint(float speed, vecType pos, vecType destination)
1313
}
1414

1515
SYCL_EXTERNAL float magnitude(vecType inp) {
16-
return std::sqrt((inp[0] * inp[0]) + (inp[1] * inp[1]));
16+
return sycl::sqrt((inp[0] * inp[0]) + (inp[1] * inp[1]));
1717
}
1818

1919
SYCL_EXTERNAL float inverseMagnitude(vecType inp) {
@@ -51,8 +51,8 @@ SYCL_EXTERNAL std::pair<float, vecType> getDistanceAndNiw(vecType point, std::ar
5151
float lSquared = dotProduct(AB, AB);
5252
if (lSquared == 0.0) {
5353
return {0, {0, 0}};
54-
}
55-
float t = std::max(0.0f, std::min(1.0f, dotProduct(AP, AB) / lSquared));
54+
}
55+
float t = sycl::max(0.0f, sycl::min(1.0f, dotProduct(AP, AB) / lSquared));
5656
auto projection = t * AB;
5757

5858
return {distance(AP, projection), normalize(AP - projection)};

src/main.cpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ int SCALE;
1919
int DELAY;
2020

2121
void init(SDL_Window* &win, SDL_Renderer* &render, std::vector<Actor> &actors, Room &room, std::vector<Path> &paths, int argc, char **argv) {
22+
// Read from input file path JSON
2223
if (argc > 1) {
2324
std::string inputPath = argv[1];
2425
parseInputFile(inputPath, actors, room, paths, WIDTH, HEIGHT, SCALE, DELAY);
2526
}
2627

28+
// Initialise SDL
2729
SDL_Init(SDL_INIT_VIDEO);
2830
win = SDL_CreateWindow("SYCL Crowd Simulation", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * SCALE, HEIGHT * SCALE, SDL_WINDOW_SHOWN);
2931
render = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
@@ -97,8 +99,8 @@ void close(SDL_Window* win, SDL_Renderer* render) {
9799
}
98100

99101
int main(int argc, char *argv[]) {
100-
SDL_Window* win = NULL;
101-
SDL_Renderer* render = NULL;
102+
SDL_Window* win;
103+
SDL_Renderer* render;
102104

103105
std::vector<Actor> actors;
104106
Room room = Room({});
@@ -114,34 +116,13 @@ int main(int argc, char *argv[]) {
114116
bool isQuit = false;
115117
SDL_Event event;
116118

117-
// const float dt = 0.00001f;
118-
// float accumulator = 0.0f;
119-
// float currentTime = SDL_GetTicks();
120-
121119
while(!isQuit) {
122120
if (SDL_PollEvent(&event)) {
123121
if (event.type == SDL_QUIT) {
124122
isQuit = true;
125123
}
126124
}
127125

128-
// float newTime = SDL_GetTicks();
129-
// float frameTime = newTime - currentTime;
130-
// currentTime = 0.2f * newTime;
131-
// accumulator += frameTime;
132-
133-
// while (accumulator >= dt) {
134-
// if (SDL_PollEvent(&event)) {
135-
// if (event.type == SDL_QUIT) {
136-
// isQuit = true;
137-
// break;
138-
// }
139-
// }
140-
// update(myQueue, actors, room);
141-
// draw(render, actors, room);
142-
// accumulator -= dt;
143-
// }
144-
145126
if (delayCounter >= DELAY) {
146127
delayCounter = 0;
147128
update(myQueue, actors, room, paths);

0 commit comments

Comments
 (0)