Commit e2b2a85b authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

fix memory leaks using opencl, gaussian-filter will now also work without opencl.

parent e35d9224
......@@ -4,14 +4,18 @@ import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.util.function.BiFunction;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.util.opencl.CLConvolution;
import org.vadere.util.opencl.OpenCLException;
class CLGaussianFilter extends GaussianFilter {
private final CLConvolution convolution;
private Logger logger = LogManager.getLogger(CLConvolution.class);
CLGaussianFilter(final Rectangle2D scenarioBounds, final double scale, final BiFunction<Integer, Integer, Float> f,
final boolean normalize) throws IOException {
final boolean normalize) throws IOException, OpenCLException {
super(scenarioBounds, scale, f, normalize);
this.convolution = new CLConvolution(matrixWidth, matrixHeight, kernelWidth, kernel);
this.convolution.init();
......@@ -19,11 +23,21 @@ class CLGaussianFilter extends GaussianFilter {
@Override
public void filterImage() {
outputMatrix = this.convolution.convolve(inputMatrix);
try {
outputMatrix = this.convolution.convolve(inputMatrix);
} catch (OpenCLException e) {
logger.error(e.getMessage());
e.printStackTrace();
}
}
@Override
public void destroy() {
this.convolution.clearCL();
try {
this.convolution.clearCL();
} catch (OpenCLException e) {
logger.error(e.getMessage());
e.printStackTrace();
}
}
}
......@@ -5,10 +5,13 @@ import java.io.IOException;
import java.util.Collection;
import java.util.function.BiFunction;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.simulator.models.potential.timeCostFunction.loading.IPedestrianLoadingStrategy;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Topography;
import org.vadere.util.opencl.OpenCLException;
/**
* IGaussianFilter is a refershable image processing calculator that can be used
......@@ -19,9 +22,11 @@ import org.vadere.state.scenario.Topography;
*/
public interface IGaussianFilter {
Logger logger = LogManager.getLogger(IGaussianFilter.class);
enum Type {
OpenCL, // default
NativeJava // not jet implemented
NativeJava
}
/**
......@@ -90,26 +95,26 @@ public interface IGaussianFilter {
* 0.5
/ (2 * Math.PI * standardDerivation * standardDerivation);
BiFunction<Integer, Integer, Float> f =
(centerI, i) -> (float) (Math.sqrt(scaleFactor) * Math.exp(-((centerI - i) / scale)
* ((centerI - i) / scale) / (2 * standardDerivation * standardDerivation)));
IGaussianFilter clFilter;
switch (type) {
case OpenCL: {
try {
BiFunction<Integer, Integer, Float> f =
(centerI, i) -> (float) (Math.sqrt(scaleFactor) * Math.exp(-((centerI - i) / scale)
* ((centerI - i) / scale) / (2 * standardDerivation * standardDerivation)));
IGaussianFilter clFilter = new CLGaussianFilter(scenarioBounds, scale, f, false);
return new PedestrianGaussianFilter(pedestrians, clFilter, loadingStrategy);
} catch (IOException e) {
// cannot go on, this should never happen!
throw new RuntimeException(e);
}
}
try {
clFilter = new CLGaussianFilter(scenarioBounds, scale, f, false);
} catch (IOException | OpenCLException e) {
e.printStackTrace();
logger.warn(e.getClass().getName() + " while initializing OpenCL: " + e.getMessage() + " OpenCL can not be used. Native Java implementation will be used which might cause performance issues.");
clFilter = new JGaussianFilter(scenarioBounds, scale, f, false);
}
} break;
default:
BiFunction<Integer, Integer, Float> f =
(centerI, i) -> (float) (Math.sqrt(scaleFactor) * Math.exp(-((centerI - i) / scale)
* ((centerI - i) / scale) / (2 * standardDerivation * standardDerivation)));
IGaussianFilter clFilter = new JGaussianFilter(scenarioBounds, scale, f, false);
return new PedestrianGaussianFilter(pedestrians, clFilter, loadingStrategy);
clFilter = new JGaussianFilter(scenarioBounds, scale, f, false);
}
return new PedestrianGaussianFilter(pedestrians, clFilter, loadingStrategy);
}
static IGaussianFilter create(
......@@ -121,26 +126,26 @@ public interface IGaussianFilter {
static IGaussianFilter create(
final Topography scenario, final double scale,
final boolean scenarioHasBoundary, final double standardDerivation, final Type type) {
double varianz = standardDerivation * standardDerivation;
BiFunction<Integer, Integer, Float> f = (centerI, i) -> (float) ((1.0 / (2 * Math.PI * varianz))
* Math.exp(-((centerI - i) / scale) * ((centerI - i) / scale) / (2 * varianz)));
IGaussianFilter clFilter;
switch (type) {
case OpenCL: {
try {
double varianz = standardDerivation * standardDerivation;
BiFunction<Integer, Integer, Float> f = (centerI, i) -> (float) ((1.0 / (2 * Math.PI * varianz))
* Math.exp(-((centerI - i) / scale) * ((centerI - i) / scale) / (2 * varianz)));
IGaussianFilter clFilter = new CLGaussianFilter(scenario.getBounds(), scale, f, true);
return new ObstacleGaussianFilter(scenario, clFilter);
} catch (IOException e) {
// cannot go on, this should never happen!
throw new RuntimeException(e);
}
}
try {
clFilter = new CLGaussianFilter(scenario.getBounds(), scale, f, true);
} catch (IOException | OpenCLException e) {
e.printStackTrace();
logger.warn(e.getClass().getName() + " while initializing OpenCL: " + e.getMessage() + " OpenCL can not be used. Native Java implementation will be used which might cause performance issues.");
clFilter = new JGaussianFilter(scenario.getBounds(), scale, f, true);
}
} break;
default:
double varianz = standardDerivation * standardDerivation;
BiFunction<Integer, Integer, Float> f = (centerI, i) -> (float) ((1.0 / (2 * Math.PI * varianz))
* Math.exp(-((centerI - i) / scale) * ((centerI - i) / scale) / (2 * varianz)));
IGaussianFilter clFilter = new JGaussianFilter(scenario.getBounds(), scale, f, true);
return new ObstacleGaussianFilter(scenario, clFilter);
clFilter = new JGaussianFilter(scenario.getBounds(), scale, f, true);
}
return new ObstacleGaussianFilter(scenario, clFilter);
}
static IGaussianFilter create(
......
......@@ -3,14 +3,12 @@ package org.vadere.util.opencl;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.BufferUtils;
import org.lwjgl.PointerBuffer;
import org.lwjgl.opencl.CLContextCallback;
import org.lwjgl.opencl.CLProgramCallback;
import org.lwjgl.system.Configuration;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import org.vadere.util.math.Convolution;
import java.io.IOException;
import java.nio.ByteBuffer;
......@@ -28,8 +26,6 @@ import static org.lwjgl.system.MemoryUtil.memUTF8;
public class CLConvolution {
private static Logger log = LogManager.getLogger(CLConvolution.class);
private Convolution gaussianFilter;
// CL ids
private long clPlatform;
private long clDevice;
......@@ -37,9 +33,6 @@ public class CLConvolution {
private long clQueue;
private long clProgram;
// error code buffer
private IntBuffer errcode_ret;
// CL Memory
private long clInput;
private long clOutput;
......@@ -51,8 +44,7 @@ public class CLConvolution {
private FloatBuffer hostGaussKernel;
private FloatBuffer output;
private PointerBuffer strings;
private PointerBuffer lengths;
private ByteBuffer source;
// CL callbacks
private CLContextCallback contextCB;
......@@ -70,6 +62,7 @@ public class CLConvolution {
private int kernelWidth;
private float[] kernel;
private KernelType type;
private boolean debug = false;
public enum KernelType {
Separate,
......@@ -81,7 +74,7 @@ public class CLConvolution {
public CLConvolution(
final int matrixWidth,
final int matrixHeight,
final int kernelWidth, @NotNull final float[] kernel) {
final int kernelWidth, @NotNull final float[] kernel) throws OpenCLException {
this(KernelType.Separate, matrixWidth, matrixHeight, kernelWidth, kernel);
}
......@@ -89,20 +82,23 @@ public class CLConvolution {
@NotNull final KernelType type,
final int matrixWidth,
final int matrixHeight,
final int kernelWidth, @NotNull final float[] kernel) {
final int kernelWidth, @NotNull final float[] kernel) throws OpenCLException {
this.type = type;
this.matrixHeight = matrixHeight;
this.matrixWidth = matrixWidth;
this.kernelWidth = kernelWidth;
this.kernel = kernel;
// enables debug memory operations
if(debug) {
Configuration.DEBUG.set(true);
Configuration.DEBUG_MEMORY_ALLOCATOR.set(true);
Configuration.DEBUG_STACK.set(true);
}
init();
Configuration.DEBUG.set(true);
Configuration.DEBUG_MEMORY_ALLOCATOR.set(true);
Configuration.DEBUG_STACK.set(true);
}
public void init() {
public void init() throws OpenCLException {
initCallbacks();
initCL();
buildProgram();
......@@ -127,7 +123,7 @@ public class CLConvolution {
}
}
public float[] convolve(final float[] input) {
public float[] convolve(final float[] input) throws OpenCLException {
// 1. write input to native-c-like-memory
CLUtils.toFloatBuffer(input, hostScenario);
......@@ -152,136 +148,150 @@ public class CLConvolution {
}
private void convolveSeparate() {
private void convolveSeparate() throws OpenCLException {
//init();
try (MemoryStack stack = stackPush()) {
PointerBuffer clGlobalWorkSizeEdges = BufferUtils.createPointerBuffer(2);
PointerBuffer clGlobalWorkSizeEdges = stack.callocPointer(2);
clGlobalWorkSizeEdges.put(0, matrixWidth);
clGlobalWorkSizeEdges.put(1, matrixHeight);
clGlobalWorkSizeEdges.put(1, matrixHeight);
PointerBuffer ev = stack.callocPointer(1);
// run the kernel and read the result
clEnqueueNDRangeKernel(clQueue, clKernelConvolveCol, 2, null, clGlobalWorkSizeEdges, null, null, null);
clEnqueueNDRangeKernel(clQueue, clKernelConvolveRow, 2, null, clGlobalWorkSizeEdges, null, null, null);
CLInfo.checkCLError(clEnqueueNDRangeKernel(clQueue, clKernelConvolveCol, 2, null, clGlobalWorkSizeEdges, null, null, null));
CLInfo.checkCLError(clEnqueueNDRangeKernel(clQueue, clKernelConvolveRow, 2, null, clGlobalWorkSizeEdges, null, null, null));
clFinish(clQueue);
}
}
private void convolve(final long clKernel) {
PointerBuffer clGlobalWorkSizeEdges = BufferUtils.createPointerBuffer(2);
clGlobalWorkSizeEdges.put(0, matrixWidth);
clGlobalWorkSizeEdges.put(1, matrixHeight);
private void convolve(final long clKernel) throws OpenCLException {
try (MemoryStack stack = stackPush()) {
PointerBuffer clGlobalWorkSizeEdges = stack.callocPointer(2);
clGlobalWorkSizeEdges.put(0, matrixWidth);
clGlobalWorkSizeEdges.put(1, matrixHeight);
// run the kernel and read the result
clEnqueueNDRangeKernel(clQueue, clKernel, 2, null, clGlobalWorkSizeEdges, null, null, null);
clFinish(clQueue);
// run the kernel and read the result
CLInfo.checkCLError(clEnqueueNDRangeKernel(clQueue, clKernel, 2, null, clGlobalWorkSizeEdges, null, null, null));
CLInfo.checkCLError(clFinish(clQueue));
}
}
private void setArguments(final long clKernel) {
// host memory to gpu memory
clInput = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4 * matrixWidth * matrixHeight, errcode_ret);
clOutput = clCreateBuffer(clContext, CL_MEM_WRITE_ONLY, 4 * matrixWidth * matrixHeight, errcode_ret);
clGaussianKernel = clCreateBuffer(clContext, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR, hostGaussKernel, errcode_ret);
clSetKernelArg1p(clKernel, 0, clInput);
clSetKernelArg1p(clKernel, 1, clGaussianKernel);
clSetKernelArg1p(clKernel, 2, clOutput);
clSetKernelArg1i(clKernel, 3, matrixWidth);
clSetKernelArg1i(clKernel, 4, matrixHeight);
clSetKernelArg1i(clKernel, 5, kernelWidth);
private void setArguments(final long clKernel) throws OpenCLException {
try (MemoryStack stack = stackPush()) {
IntBuffer errcode_ret = stack.callocInt(1);
// host memory to gpu memory
clInput = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4 * matrixWidth * matrixHeight, errcode_ret);
clOutput = clCreateBuffer(clContext, CL_MEM_WRITE_ONLY, 4 * matrixWidth * matrixHeight, errcode_ret);
clGaussianKernel = clCreateBuffer(clContext, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR, hostGaussKernel, errcode_ret);
CLInfo.checkCLError(clSetKernelArg1p(clKernel, 0, clInput));
CLInfo.checkCLError(clSetKernelArg1p(clKernel, 1, clGaussianKernel));
CLInfo.checkCLError(clSetKernelArg1p(clKernel, 2, clOutput));
CLInfo.checkCLError(clSetKernelArg1i(clKernel, 3, matrixWidth));
CLInfo.checkCLError(clSetKernelArg1i(clKernel, 4, matrixHeight));
CLInfo.checkCLError(clSetKernelArg1i(clKernel, 5, kernelWidth));
}
}
private void setArguments(final long clKernelConvolveCol, final long clKernelConvolveRow) {
clTmp = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4 * matrixWidth * matrixHeight, errcode_ret);
clInput = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4 * matrixWidth * matrixHeight, errcode_ret);
clOutput = clCreateBuffer(clContext, CL_MEM_WRITE_ONLY, 4 * matrixWidth * matrixHeight, errcode_ret);
clGaussianKernel = clCreateBuffer(clContext, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR, hostGaussKernel, errcode_ret);
clSetKernelArg1p(clKernelConvolveCol, 0, clInput);
clSetKernelArg1p(clKernelConvolveCol, 1, clGaussianKernel);
clSetKernelArg1p(clKernelConvolveCol, 2, clTmp);
clSetKernelArg1i(clKernelConvolveCol, 3, matrixWidth);
clSetKernelArg1i(clKernelConvolveCol, 4, matrixHeight);
clSetKernelArg1i(clKernelConvolveCol, 5, kernelWidth);
clSetKernelArg1p(clKernelConvolveRow, 0, clTmp);
clSetKernelArg1p(clKernelConvolveRow, 1, clGaussianKernel);
clSetKernelArg1p(clKernelConvolveRow, 2, clOutput);
clSetKernelArg1i(clKernelConvolveRow, 3, matrixWidth);
clSetKernelArg1i(clKernelConvolveRow, 4, matrixHeight);
clSetKernelArg1i(clKernelConvolveRow, 5, kernelWidth);
private void setArguments(final long clKernelConvolveCol, final long clKernelConvolveRow) throws OpenCLException {
try (MemoryStack stack = stackPush()) {
IntBuffer errcode_ret = stack.callocInt(1);
clTmp = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4 * matrixWidth * matrixHeight, errcode_ret);
clInput = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4 * matrixWidth * matrixHeight, errcode_ret);
clOutput = clCreateBuffer(clContext, CL_MEM_WRITE_ONLY, 4 * matrixWidth * matrixHeight, errcode_ret);
clGaussianKernel = clCreateBuffer(clContext, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR, hostGaussKernel, errcode_ret);
CLInfo.checkCLError(clSetKernelArg1p(clKernelConvolveCol, 0, clInput));
CLInfo.checkCLError(clSetKernelArg1p(clKernelConvolveCol, 1, clGaussianKernel));
CLInfo.checkCLError(clSetKernelArg1p(clKernelConvolveCol, 2, clTmp));
CLInfo.checkCLError(clSetKernelArg1i(clKernelConvolveCol, 3, matrixWidth));
CLInfo.checkCLError(clSetKernelArg1i(clKernelConvolveCol, 4, matrixHeight));
CLInfo.checkCLError(clSetKernelArg1i(clKernelConvolveCol, 5, kernelWidth));
CLInfo.checkCLError(clSetKernelArg1p(clKernelConvolveRow, 0, clTmp));
CLInfo.checkCLError(clSetKernelArg1p(clKernelConvolveRow, 1, clGaussianKernel));
CLInfo.checkCLError(clSetKernelArg1p(clKernelConvolveRow, 2, clOutput));
CLInfo.checkCLError(clSetKernelArg1i(clKernelConvolveRow, 3, matrixWidth));
CLInfo.checkCLError(clSetKernelArg1i(clKernelConvolveRow, 4, matrixHeight));
CLInfo.checkCLError(clSetKernelArg1i(clKernelConvolveRow, 5, kernelWidth));
}
}
private void clearMemory() {
private void clearMemory() throws OpenCLException {
// release memory and devices
clReleaseMemObject(clInput);
clReleaseMemObject(clOutput);
clReleaseMemObject(clGaussianKernel);
if(type == KernelType.Separate) {
clReleaseMemObject(clTmp);
}
clReleaseKernel(clKernelConvolve);
clReleaseKernel(clKernelConvolveRow);
clReleaseKernel(clKernelConvolveCol);
MemoryUtil.memFree(hostScenario);
MemoryUtil.memFree(output);
MemoryUtil.memFree(hostGaussKernel);
//CL.destroy();
// strings.free();
// lengths.free();
try {
CLInfo.checkCLError(clReleaseMemObject(clInput));
CLInfo.checkCLError(clReleaseMemObject(clOutput));
CLInfo.checkCLError(clReleaseMemObject(clGaussianKernel));
if(type == KernelType.Separate) {
CLInfo.checkCLError(clReleaseMemObject(clTmp));
}
CLInfo.checkCLError(clReleaseKernel(clKernelConvolve));
CLInfo.checkCLError(clReleaseKernel(clKernelConvolveRow));
CLInfo.checkCLError(clReleaseKernel(clKernelConvolveCol));
}
catch (OpenCLException ex) {
throw ex;
}
finally {
MemoryUtil.memFree(hostScenario);
MemoryUtil.memFree(output);
MemoryUtil.memFree(hostGaussKernel);
MemoryUtil.memFree(source);
}
}
public void clearCL() {
clearMemory();
contextCB.free();
programCB.free();
log.info("release command queue: " + (clReleaseCommandQueue(clQueue) == CL_SUCCESS));
log.info("release program: " + (clReleaseProgram(clProgram) == CL_SUCCESS));
log.info("release context: " + (clReleaseContext(clContext) == CL_SUCCESS));
public void clearCL() throws OpenCLException {
clearMemory();
CLInfo.checkCLError(clReleaseCommandQueue(clQueue));
CLInfo.checkCLError(clReleaseProgram(clProgram));
CLInfo.checkCLError(clReleaseContext(clContext));
contextCB.free();
programCB.free();
}
// private helpers
private void initCallbacks() {
contextCB = CLContextCallback.create((errinfo, private_info, cb, user_data) ->
{
log.warn("[LWJGL] cl_context_callback");
log.warn("\tInfo: " + memUTF8(errinfo));
log.debug("[LWJGL] cl_context_callback" + "\tInfo: " + memUTF8(errinfo));
});
programCB = CLProgramCallback.create((program, user_data) ->
{
log.info("The cl_program [0x"+program+"] was built " + (CLInfo.getProgramBuildInfoInt(program, clDevice, CL_PROGRAM_BUILD_STATUS) == CL_SUCCESS ? "successfully" : "unsuccessfully"));
try {
log.debug("The cl_program [0x"+program+"] was built " + (CLInfo.getProgramBuildInfoInt(program, clDevice, CL_PROGRAM_BUILD_STATUS) == CL_SUCCESS ? "successfully" : "unsuccessfully"));
} catch (OpenCLException e) {
e.printStackTrace();
}
});
}
private void initCL() {
private void initCL() throws OpenCLException {
try (MemoryStack stack = stackPush()) {
// helper for the memory allocation in java
//stack = MemoryStack.stackPush();
errcode_ret = stack.callocInt(1);
IntBuffer errcode_ret = stack.callocInt(1);
IntBuffer numberOfPlatforms = stack.mallocInt(1);
clGetPlatformIDs(null, numberOfPlatforms);
CLInfo.checkCLError(clGetPlatformIDs(null, numberOfPlatforms));
PointerBuffer platformIDs = stack.mallocPointer(numberOfPlatforms.get(0));
clGetPlatformIDs(platformIDs, numberOfPlatforms);
CLInfo.checkCLError(clGetPlatformIDs(platformIDs, numberOfPlatforms));
clPlatform = platformIDs.get(0);
IntBuffer numberOfDevices = stack.mallocInt(1);
clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_GPU, null, numberOfDevices);
CLInfo.checkCLError(clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_GPU, null, numberOfDevices));
PointerBuffer deviceIDs = stack.mallocPointer(numberOfDevices.get(0));
clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_GPU, deviceIDs, numberOfDevices);
CLInfo.checkCLError(clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_GPU, deviceIDs, numberOfDevices));
clDevice = deviceIDs.get(0);
printDeviceInfo(clDevice, "CL_DEVICE_NAME", CL_DEVICE_NAME);
log.debug("CL_DEVICE_NAME = " + CLInfo.getDeviceInfoStringUTF8(clDevice, CL_DEVICE_NAME));
PointerBuffer ctxProps = stack.mallocPointer(3);
PointerBuffer ctxProps = stack.mallocPointer(3);
ctxProps.put(CL_CONTEXT_PLATFORM)
.put(clPlatform)
.put(NULL)
......@@ -295,38 +305,32 @@ public class CLConvolution {
}
}
private void buildProgram() {
strings = BufferUtils.createPointerBuffer(1);
lengths = BufferUtils.createPointerBuffer(1);
private void buildProgram() throws OpenCLException {
try (MemoryStack stack = stackPush()) {
IntBuffer errcode_ret = stack.callocInt(1);
ByteBuffer source;
try {
source = CLUtils.ioResourceToByteBuffer("Convolve.cl", 4096);
} catch (IOException e) {
throw new RuntimeException(e);
}
PointerBuffer strings = stack.mallocPointer(1);
PointerBuffer lengths = stack.mallocPointer(1);
try {
source = CLUtils.ioResourceToByteBuffer("Convolve.cl", 4096);
} catch (IOException e) {
throw new OpenCLException(e.getMessage());
}
strings.put(0, source);
lengths.put(0, source.remaining());
clProgram = clCreateProgramWithSource(clContext, strings, lengths, errcode_ret);
strings.put(0, source);
lengths.put(0, source.remaining());
int errcode = clBuildProgram(clProgram, clDevice, "", programCB, NULL);
CLInfo.checkCLError(errcode);
clKernelConvolve = clCreateKernel(clProgram, "convolve", errcode_ret);
CLInfo.checkCLError(errcode_ret);
clKernelConvolveRow = clCreateKernel(clProgram, "convolveRow", errcode_ret);
CLInfo.checkCLError(errcode_ret);
clKernelConvolveCol = clCreateKernel(clProgram, "convolveCol", errcode_ret);
CLInfo.checkCLError(errcode_ret);
}
private static void printPlatformInfo(long platform, String param_name, int param) {
System.out.println("\t" + param_name + " = " + CLInfo.getPlatformInfoStringUTF8(platform, param));
}
clProgram = clCreateProgramWithSource(clContext, strings, lengths, errcode_ret);
CLInfo.checkCLError(clBuildProgram(clProgram, clDevice, "", programCB, NULL));
clKernelConvolve = clCreateKernel(clProgram, "convolve", errcode_ret);
CLInfo.checkCLError(errcode_ret);
clKernelConvolveRow = clCreateKernel(clProgram, "convolveRow", errcode_ret);
CLInfo.checkCLError(errcode_ret);
clKernelConvolveCol = clCreateKernel(clProgram, "convolveCol", errcode_ret);
CLInfo.checkCLError(errcode_ret);
}
private static void printDeviceInfo(long device, String param_name, int param) {
System.out.println("\t" + param_name + " = " + CLInfo.getDeviceInfoStringUTF8(device, param));
}
}
package org.vadere.util.opencl;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.lwjgl.*;
import org.lwjgl.opencl.*;
import org.lwjgl.system.*;
......@@ -20,243 +22,252 @@ import static org.lwjgl.system.Pointer.*;
*/
public final class CLDemo {
private CLDemo() {
}
public static Logger logger = LogManager.getLogger(CLDemo.class);
private CLDemo() {}
public static void main(String[] args) {
try (MemoryStack stack = stackPush()) {
demo(stack);
} catch (OpenCLException e) {
e.printStackTrace();
}
}