11.08., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit f6015986 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

The choice which device is used (GPU or CPU) is now configurable via...

The choice which device is used (GPU or CPU) is now configurable via Attributes i.e. the UpdateScheme types/UpdateType.java.
parent ff21ff95
Pipeline #264111 failed with stages
in 2 minutes and 44 seconds
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN_CL",
"updateType" : "EVENT_DRIVEN_CL_CPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN_CL",
"updateType" : "EVENT_DRIVEN_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN_CL",
"updateType" : "EVENT_DRIVEN_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN_CL",
"updateType" : "EVENT_DRIVEN_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "PARALLEL_CL",
"updateType" : "PARALLEL_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "PARALLEL_CL",
"updateType" : "PARALLEL_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "PARALLEL_CL",
"updateType" : "PARALLEL_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN_CL",
"updateType" : "EVENT_DRIVEN_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN_CL",
"updateType" : "EVENT_DRIVEN_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN_CL",
"updateType" : "EVENT_DRIVEN_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "PARALLEL_CL",
"updateType" : "PARALLEL_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "PARALLEL_CL",
"updateType" : "PARALLEL_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -53,7 +53,7 @@
"minimumStepLength" : false,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : false,
"updateType" : "PARALLEL_CL",
"updateType" : "PARALLEL_CL_GPU",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
......
......@@ -62,8 +62,6 @@ import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.stream.Collectors;
import static org.vadere.state.types.UpdateType.PARALLEL_OPEN_CL;
@ModelClass(isMainModel = true)
public class OptimalStepsModel implements MainModel, PotentialFieldModel {
......@@ -161,10 +159,12 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel {
@NotNull final Topography topography,
@NotNull final AttributesOSM attributesOSM) {
switch (attributesOSM.getUpdateType()) {
case PARALLEL_OPEN_CL:
case PARALLEL_CL:
case PARALLEL_SHARED_MEM_CL:
case EVENT_DRIVEN_CL: {
case PARALLEL_CL_CPU:
case PARALLEL_CL_GPU:
case PARALLEL_SHARED_MEM_CL_CPU:
case PARALLEL_SHARED_MEM_CL_GPU:
case EVENT_DRIVEN_CL_CPU:
case EVENT_DRIVEN_CL_GPU: {
//throw new UnsupportedOperationException("not jet implemented.");
return UpdateSchemeOSM.createOpenCLUpdateScheme(
topography,
......
package org.vadere.simulator.models.osm.opencl;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.PointerBuffer;
import org.lwjgl.opencl.CLContextCallback;
......@@ -11,12 +12,14 @@ import org.vadere.util.logging.Logger;
import org.vadere.util.opencl.CLInfo;
import org.vadere.util.opencl.CLUtils;
import org.vadere.util.opencl.OpenCLException;
import org.vadere.util.opencl.UnsupportedOpenCLException;
import org.vadere.util.opencl.examples.InfoUtils;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.util.Optional;
import static org.lwjgl.opencl.CL10.CL_CONTEXT_PLATFORM;
import static org.lwjgl.opencl.CL10.CL_DEVICE_LOCAL_MEM_SIZE;
......@@ -24,6 +27,7 @@ import static org.lwjgl.opencl.CL10.CL_DEVICE_MAX_WORK_GROUP_SIZE;
import static org.lwjgl.opencl.CL10.CL_DEVICE_NAME;
import static org.lwjgl.opencl.CL10.CL_DEVICE_TYPE_ALL;
import static org.lwjgl.opencl.CL10.CL_DEVICE_TYPE_CPU;
import static org.lwjgl.opencl.CL10.CL_DEVICE_TYPE_DEFAULT;
import static org.lwjgl.opencl.CL10.CL_DEVICE_TYPE_GPU;
import static org.lwjgl.opencl.CL10.CL_PROFILING_COMMAND_END;
import static org.lwjgl.opencl.CL10.CL_PROFILING_COMMAND_START;
......@@ -66,15 +70,17 @@ public abstract class CLAbstract {
protected long clContext;
protected long clQueue;
protected long clProgram;
protected final int deviceType;
protected boolean profiling;
protected boolean debug;
private long maxWorkGroupSize;
private long maxLocalMemorySize;
public CLAbstract() {
public CLAbstract(int deviceType) {
profiling = false;
debug = false;
this.deviceType = deviceType;
if(debug) {
Configuration.DEBUG.set(true);
......@@ -131,14 +137,26 @@ public abstract class CLAbstract {
PointerBuffer platformIDs = stack.mallocPointer(numberOfPlatforms.get(0));
CLInfo.checkCLError(clGetPlatformIDs(platformIDs, numberOfPlatforms));
clPlatform = platformIDs.get(1);
// if all, find the possibly best
Optional<Pair<Long, Long>> platformAndDevice;
if(deviceType == CL_DEVICE_TYPE_ALL) {
platformAndDevice = CLUtils.getFirstSupportedPlatformAndDevice(CL_DEVICE_TYPE_DEFAULT);
if(!platformAndDevice.isPresent()) {
platformAndDevice = CLUtils.getFirstSupportedPlatformAndDevice(CL_DEVICE_TYPE_ALL);
}
}
else {
platformAndDevice = CLUtils.getFirstSupportedPlatformAndDevice(deviceType);
}
IntBuffer numberOfDevices = stack.mallocInt(1);
CLInfo.checkCLError(clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_CPU, null, numberOfDevices));
PointerBuffer deviceIDs = stack.mallocPointer(numberOfDevices.get(0));
CLInfo.checkCLError(clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_CPU, deviceIDs, numberOfDevices));
if(!platformAndDevice.isPresent()) {
log.debug("No support for OpenCl found.");
throw new UnsupportedOpenCLException("No support for OpenCl found.");
}
clDevice = deviceIDs.get(0);
clPlatform = platformAndDevice.get().getLeft();
clDevice = platformAndDevice.get().getRight();
log.debug("CL_DEVICE_NAME = " + CLInfo.getDeviceInfoStringUTF8(clDevice, CL_DEVICE_NAME));
......
......@@ -109,7 +109,6 @@ public abstract class CLAbstractOSM extends CLAbstract implements ICLOptimalStep
protected AttributesOSM attributesOSM;
protected AttributesFloorField attributesFloorField;
protected VRectangle bound;
protected final int deviceType;
protected EikonalSolver targetPotential;
protected EikonalSolver obstaclePotential;
protected int[] iGridSize;
......@@ -151,13 +150,12 @@ public abstract class CLAbstractOSM extends CLAbstract implements ICLOptimalStep
@NotNull final EikonalSolver obstaclePotential,
final int device,
final double cellSize) throws OpenCLException {
super();
super(device);
this.counter = 0;
this.pedestrianSet = false;
this.attributesOSM = attributesOSM;
this.attributesFloorField = attributesFloorField;
this.bound = bound;
this.deviceType = device;
this.targetPotential = targetPotential;
this.obstaclePotential = obstaclePotential;
......
......@@ -725,10 +725,10 @@ __kernel void move (
CLInfo.checkCLError(clReleaseKernel(clFilterIds));
CLInfo.checkCLError(clReleaseKernel(clMove));
CLInfo.checkCLError(clReleaseKernel(clAlign));
CLInfo.checkCLError(clReleaseMemObject(cl_scan_pow2));
CLInfo.checkCLError(clReleaseMemObject(cl_scan_pad_to_pow2));
CLInfo.checkCLError(clReleaseMemObject(cl_scan_subarrays));
CLInfo.checkCLError(clReleaseMemObject(cl_scan_inc_subarrays));
CLInfo.checkCLError(clReleaseKernel(cl_scan_pow2));
CLInfo.checkCLError(clReleaseKernel(cl_scan_pad_to_pow2));
CLInfo.checkCLError(clReleaseKernel(cl_scan_subarrays));
CLInfo.checkCLError(clReleaseKernel(cl_scan_inc_subarrays));
}
@Override
......
......@@ -10,6 +10,7 @@ import org.vadere.util.opencl.OpenCLException;
import java.nio.IntBuffer;
import static org.lwjgl.opencl.CL10.CL_DEVICE_TYPE_GPU;
import static org.lwjgl.opencl.CL10.CL_MEM_READ_WRITE;
import static org.lwjgl.opencl.CL10.clCreateBuffer;
import static org.lwjgl.opencl.CL10.clCreateKernel;
......@@ -34,6 +35,7 @@ public class CLScan extends CLAbstract {
private final String fileName;
public CLScan(@NotNull final String fileName) throws OpenCLException {
super(CL_DEVICE_TYPE_GPU);
this.fileName = fileName;
}
......
......@@ -10,6 +10,7 @@ import org.vadere.util.opencl.OpenCLException;
import java.nio.IntBuffer;
import static org.lwjgl.opencl.CL10.CL_DEVICE_TYPE_GPU;
import static org.lwjgl.opencl.CL10.CL_MEM_READ_WRITE;
import static org.lwjgl.opencl.CL10.clCreateBuffer;
import static org.lwjgl.opencl.CL10.clCreateKernel;
......@@ -33,6 +34,7 @@ public class CLScanDirectional extends CLAbstract {
private final String fileName;
public CLScanDirectional(@NotNull final String fileName) throws OpenCLException {
super(CL_DEVICE_TYPE_GPU);
this.fileName = fileName;
}
......
......@@ -25,6 +25,9 @@ import org.vadere.simulator.models.potential.solver.calculators.EikonalSolver;
import java.util.List;
import java.util.Random;
import static org.lwjgl.opencl.CL10.CL_DEVICE_TYPE_CPU;
import static org.lwjgl.opencl.CL10.CL_DEVICE_TYPE_GPU;
public interface UpdateSchemeOSM extends DynamicElementRemoveListener<Pedestrian>, DynamicElementAddListener<Pedestrian> {
enum CallMethod {
......@@ -69,28 +72,32 @@ public interface UpdateSchemeOSM extends DynamicElementRemoveListener<Pedestrian
double cellSize = new AttributesPotentialCompact().getPedPotentialWidth() + maxStepSize + 0.4;
switch (updateType) {
case EVENT_DRIVEN_CL: {
case EVENT_DRIVEN_CL_CPU:
case EVENT_DRIVEN_CL_GPU: {
CLParallelEventDrivenOSM clOptimalStepsModel = new CLParallelEventDrivenOSM(
attributesOSM,
attributesFloorField,
new VRectangle(topography.getBounds()),
targetEikonalSolver,
distanceEikonalSolver,
updateType.isGPUScheme() ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU,
cellSize);
return new CLUpdateSchemeEventDriven(topography, clOptimalStepsModel);
}
case PARALLEL_CL:
case PARALLEL_OPEN_CL: {
case PARALLEL_CL_CPU:
case PARALLEL_CL_GPU: {
CLParallelOSM clOptimalStepsModel = new CLParallelOSM(
attributesOSM,
attributesFloorField,
new VRectangle(topography.getBounds()),
targetEikonalSolver,
distanceEikonalSolver,
updateType.isGPUScheme() ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU,
cellSize);
return new CLUpdateSchemeParallel(topography, clOptimalStepsModel);
}
case PARALLEL_SHARED_MEM_CL:
case PARALLEL_SHARED_MEM_CL_CPU:
case PARALLEL_SHARED_MEM_CL_GPU:
default : {
CLParallelOSMLocalMem clOptimalStepsModel = new CLParallelOSMLocalMem(
attributesOSM,
......@@ -98,6 +105,7 @@ public interface UpdateSchemeOSM extends DynamicElementRemoveListener<Pedestrian
new VRectangle(topography.getBounds()),
targetEikonalSolver,
distanceEikonalSolver,
updateType.isGPUScheme() ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU,
cellSize);
return new CLUpdateSchemeParallel(topography, clOptimalStepsModel);
}
......
package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.OSMBehaviorController;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.simulator.models.potential.combinedPotentials.CombinedPotentialStrategy;
import org.vadere.state.behavior.SalientBehavior;
import org.vadere.state.events.types.*;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public class UpdateSchemeSequential implements UpdateSchemeOSM {
private final Topography topography;
private final OSMBehaviorController osmBehaviorController;
public UpdateSchemeSequential(@NotNull final Topography topography) {
this.topography = topography;
this.osmBehaviorController = new OSMBehaviorController();
}
@Override
public void update(double timeStepInSec, double currentTimeInSec) {
clearStrides(topography);
update(topography.getElements(Pedestrian.class), timeStepInSec);
}
protected void update(@NotNull final Collection<Pedestrian> pedestrianOSMS, final double timeStepInSec) {
for (Pedestrian pedestrian : pedestrianOSMS) {
update((PedestrianOSM) pedestrian, timeStepInSec);
//pedestrian.update(timeStepInSec, -1, CallMethod.SEQUENTIAL);
}
}
protected void update(@NotNull final PedestrianOSM pedestrian, final double timeStepInSec) {
Event mostImportantEvent = pedestrian.getMostImportantEvent();
if (mostImportantEvent instanceof ElapsedTimeEvent) {
VPoint oldPosition = pedestrian.getPosition();
pedestrian.clearStrides();
pedestrian.setTimeCredit(pedestrian.getTimeCredit() + timeStepInSec);
<<<<<<< HEAD
if (pedestrian.getSalientBehavior() == SalientBehavior.TARGET_ORIENTED) {
while (pedestrian.getTimeCredit() > pedestrian.getDurationNextStep()) {
pedestrian.updateNextPosition();
osmBehaviorController.makeStep(pedestrian, topography, timeStepInSec);
}
} else if (pedestrian.getSalientBehavior() == SalientBehavior.COOPERATIVE) {
osmBehaviorController.swapWithClosestCooperativePedestrian(pedestrian, topography);
=======
while (pedestrian.getTimeCredit() > pedestrian.getDurationNextStep()) {
pedestrian.updateNextPosition();
double stepDuration = pedestrian.getDurationNextStep();
osmBehaviorController.makeStep(pedestrian, topography, timeStepInSec);
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + stepDuration);
>>>>>>> master
}
} else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
osmBehaviorController.wait(pedestrian);
} else if (mostImportantEvent instanceof BangEvent) {
osmBehaviorController.reactToBang(pedestrian, topography);
}
}
@Override
public void elementAdded(Pedestrian element) {}
@Override
public void elementRemoved(Pedestrian element) {}
}
......@@ -168,7 +168,7 @@ public class TestCLOSMEventDriven {
targetPotentialField.preLoop(0.4f);
pedestrians = new ArrayList<>();
for(int i = 0; i < numberOfElements-1; i++) {
for(int i = 0; i < numberOfElements; i++) {
VPoint randomPosition = new VPoint(
(float)(bound.getMinX() + random.nextDouble() * bound.getWidth()),
(float)(bound.getMinY() + random.nextDouble() * bound.getHeight()));
......@@ -179,12 +179,11 @@ public class TestCLOSMEventDriven {
pedestrians.add(pedestrianOSM);
}
PedestrianOSM lastPedestrian = pedestrians.get(pedestrians.size()-1);
/*PedestrianOSM lastPedestrian = pedestrians.get(pedestrians.size()-1);
PedestrianOSM pedestrianOSM = mock(PedestrianOSM.class);
when(pedestrianOSM.getPosition()).thenReturn(lastPedestrian.getPosition().add(new VPoint(-0.001, -0.001)));
when(pedestrianOSM.getDesiredStepSize()).thenReturn(maxStepSize);
pedestrians.add(pedestrianOSM);
pedestrians.add(pedestrianOSM);*/
}
//@Ignore
......
package org.vadere.state.types;
public enum UpdateType {
SEQUENTIAL, EVENT_DRIVEN, PARALLEL, SHUFFLE, PARALLEL_OPEN_CL, PARALLEL_CL, PARALLEL_SHARED_MEM_CL, EVENT_DRIVEN_CL, EVENT_DRIVEN_PARALLEL;
SEQUENTIAL, EVENT_DRIVEN, PARALLEL, SHUFFLE,
PARALLEL_CL_CPU, PARALLEL_CL_GPU,
PARALLEL_SHARED_MEM_CL_CPU, PARALLEL_SHARED_MEM_CL_GPU,
EVENT_DRIVEN_CL_CPU, EVENT_DRIVEN_CL_GPU,
EVENT_DRIVEN_PARALLEL;
public boolean isGPUScheme() {
switch (this) {
case PARALLEL_SHARED_MEM_CL_GPU:
case EVENT_DRIVEN_CL_GPU:
case PARALLEL_CL_GPU: return true;
default:return false;
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment