From 85791ed1ab756b469a612398ca1d99cf7f7d3720 Mon Sep 17 00:00:00 2001 From: Benedikt Zoennchen Date: Fri, 6 Oct 2017 16:06:13 +0200 Subject: [PATCH] renaming of some classes and packages --- .../models/density/CLGaussianFilter.java | 2 +- .../src/org/vadere/util/math/CLUtils.java | 27 -------- .../util/{math => opencl}/CLConvolution.java | 20 +++--- .../vadere/util/{math => opencl}/CLFFT.java | 2 +- .../opencl/{InfoUtils.java => CLInfo.java} | 8 ++- .../util/opencl/{IOUtil.java => CLUtils.java} | 64 +++++++++++++------ .../org/vadere/util/math/TestConvolution.java | 1 + 7 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 VadereUtils/src/org/vadere/util/math/CLUtils.java rename VadereUtils/src/org/vadere/util/{math => opencl}/CLConvolution.java (93%) rename VadereUtils/src/org/vadere/util/{math => opencl}/CLFFT.java (60%) rename VadereUtils/src/org/vadere/util/opencl/{InfoUtils.java => CLInfo.java} (96%) rename VadereUtils/src/org/vadere/util/opencl/{IOUtil.java => CLUtils.java} (55%) diff --git a/VadereSimulator/src/org/vadere/simulator/models/density/CLGaussianFilter.java b/VadereSimulator/src/org/vadere/simulator/models/density/CLGaussianFilter.java index 25ee91393..f3d72715c 100644 --- a/VadereSimulator/src/org/vadere/simulator/models/density/CLGaussianFilter.java +++ b/VadereSimulator/src/org/vadere/simulator/models/density/CLGaussianFilter.java @@ -4,7 +4,7 @@ import java.awt.geom.Rectangle2D; import java.io.IOException; import java.util.function.BiFunction; -import org.vadere.util.math.CLConvolution; +import org.vadere.util.opencl.CLConvolution; class CLGaussianFilter extends GaussianFilter { diff --git a/VadereUtils/src/org/vadere/util/math/CLUtils.java b/VadereUtils/src/org/vadere/util/math/CLUtils.java deleted file mode 100644 index a1674f1dd..000000000 --- a/VadereUtils/src/org/vadere/util/math/CLUtils.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.vadere.util.math; - - -import org.jetbrains.annotations.NotNull; -import org.lwjgl.system.MemoryUtil; -import java.nio.FloatBuffer; - - -public class CLUtils { - - public static FloatBuffer toFloatBuffer(@NotNull final float[] floats) { - FloatBuffer floatBuffer = MemoryUtil.memAllocFloat(floats.length); - - for(int i = 0; i < floats.length; i++) { - floatBuffer.put(i, floats[i]); - } - return floatBuffer; - } - - public static float[] toFloatArray(@NotNull FloatBuffer floatBuffer, final int size) { - float[] result = new float[size]; - for(int i = 0; i < size; i++) { - result[i] = floatBuffer.get(i); - } - return result; - } -} diff --git a/VadereUtils/src/org/vadere/util/math/CLConvolution.java b/VadereUtils/src/org/vadere/util/opencl/CLConvolution.java similarity index 93% rename from VadereUtils/src/org/vadere/util/math/CLConvolution.java rename to VadereUtils/src/org/vadere/util/opencl/CLConvolution.java index d791c8395..fa66611d1 100644 --- a/VadereUtils/src/org/vadere/util/math/CLConvolution.java +++ b/VadereUtils/src/org/vadere/util/opencl/CLConvolution.java @@ -1,4 +1,4 @@ -package org.vadere.util.math; +package org.vadere.util.opencl; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; @@ -7,8 +7,6 @@ import org.lwjgl.PointerBuffer; import org.lwjgl.opencl.CLContextCallback; import org.lwjgl.opencl.CLProgramCallback; import org.lwjgl.system.MemoryStack; -import org.vadere.util.opencl.IOUtil; -import org.vadere.util.opencl.InfoUtils; import java.io.IOException; import java.nio.ByteBuffer; @@ -20,13 +18,13 @@ import static org.lwjgl.system.MemoryUtil.NULL; import static org.lwjgl.system.MemoryUtil.memUTF8; /** + * Class to compute the (separate) convolutions on the GPU. + * * @author Benedikt Zoennchen */ public class CLConvolution { private static Logger log = LogManager.getLogger(CLConvolution.class); - private Convolution gaussianFilter; - // CL ids private MemoryStack stack; private long clPlatform; @@ -206,7 +204,7 @@ public class CLConvolution { programCB = CLProgramCallback.create((program, user_data) -> { - log.info("The cl_program [0x"+program+"] was built " + (InfoUtils.getProgramBuildInfoInt(program, clDevice, CL_PROGRAM_BUILD_STATUS) == CL_SUCCESS ? "successfully" : "unsuccessfully")); + log.info("The cl_program [0x"+program+"] was built " + (CLInfo.getProgramBuildInfoInt(program, clDevice, CL_PROGRAM_BUILD_STATUS) == CL_SUCCESS ? "successfully" : "unsuccessfully")); }); } @@ -238,7 +236,7 @@ public class CLConvolution { .flip(); clContext = clCreateContext(ctxProps, clDevice, contextCB, NULL, errcode_ret); - InfoUtils.checkCLError(errcode_ret); + CLInfo.checkCLError(errcode_ret); clQueue = clCreateCommandQueue(clContext, clDevice, 0, errcode_ret); } @@ -249,7 +247,7 @@ public class CLConvolution { ByteBuffer source; try { - source = IOUtil.ioResourceToByteBuffer("Convolve.cl", 4096); + source = CLUtils.ioResourceToByteBuffer("Convolve.cl", 4096); } catch (IOException e) { throw new RuntimeException(e); } @@ -261,17 +259,17 @@ public class CLConvolution { clProgram = clCreateProgramWithSource(clContext, strings, lengths, errcode_ret); int errcode = clBuildProgram(clProgram, clDevice, "", programCB, NULL); - InfoUtils.checkCLError(errcode); + CLInfo.checkCLError(errcode); clKernelConvolve = clCreateKernel(clProgram, "convolve", errcode_ret); clKernelConvolveRow = clCreateKernel(clProgram, "convolveRow", errcode_ret); clKernelConvolveCol = clCreateKernel(clProgram, "convolveCol", errcode_ret); } private static void printPlatformInfo(long platform, String param_name, int param) { - System.out.println("\t" + param_name + " = " + InfoUtils.getPlatformInfoStringUTF8(platform, param)); + System.out.println("\t" + param_name + " = " + CLInfo.getPlatformInfoStringUTF8(platform, param)); } private static void printDeviceInfo(long device, String param_name, int param) { - System.out.println("\t" + param_name + " = " + InfoUtils.getDeviceInfoStringUTF8(device, param)); + System.out.println("\t" + param_name + " = " + CLInfo.getDeviceInfoStringUTF8(device, param)); } } diff --git a/VadereUtils/src/org/vadere/util/math/CLFFT.java b/VadereUtils/src/org/vadere/util/opencl/CLFFT.java similarity index 60% rename from VadereUtils/src/org/vadere/util/math/CLFFT.java rename to VadereUtils/src/org/vadere/util/opencl/CLFFT.java index 3587534b5..a7968c530 100644 --- a/VadereUtils/src/org/vadere/util/math/CLFFT.java +++ b/VadereUtils/src/org/vadere/util/opencl/CLFFT.java @@ -1,4 +1,4 @@ -package org.vadere.util.math; +package org.vadere.util.opencl; //TODO: implement FFT! public class CLFFT { diff --git a/VadereUtils/src/org/vadere/util/opencl/InfoUtils.java b/VadereUtils/src/org/vadere/util/opencl/CLInfo.java similarity index 96% rename from VadereUtils/src/org/vadere/util/opencl/InfoUtils.java rename to VadereUtils/src/org/vadere/util/opencl/CLInfo.java index c5ba3f737..7d7f8b74a 100644 --- a/VadereUtils/src/org/vadere/util/opencl/InfoUtils.java +++ b/VadereUtils/src/org/vadere/util/opencl/CLInfo.java @@ -13,11 +13,13 @@ import static org.lwjgl.system.MemoryUtil.memASCII; import static org.lwjgl.system.MemoryUtil.memUTF8; /** - * Created by bzoennchen on 06.10.17. + * Utility-class without a state. This class offers method to read OpenCL debug-information. + * + * @author Benedikt Zoennchen */ -public final class InfoUtils { +public final class CLInfo { - private InfoUtils() {} + private CLInfo() {} public static String getPlatformInfoStringASCII(long cl_platform_id, int param_name) { try (MemoryStack stack = stackPush()) { diff --git a/VadereUtils/src/org/vadere/util/opencl/IOUtil.java b/VadereUtils/src/org/vadere/util/opencl/CLUtils.java similarity index 55% rename from VadereUtils/src/org/vadere/util/opencl/IOUtil.java rename to VadereUtils/src/org/vadere/util/opencl/CLUtils.java index 9c9cc2f74..6bf3ceabe 100644 --- a/VadereUtils/src/org/vadere/util/opencl/IOUtil.java +++ b/VadereUtils/src/org/vadere/util/opencl/CLUtils.java @@ -1,34 +1,36 @@ package org.vadere.util.opencl; -import org.lwjgl.*; -import java.io.*; -import java.nio.*; -import java.nio.channels.*; -import java.nio.file.*; +import org.jetbrains.annotations.NotNull; +import org.lwjgl.BufferUtils; +import org.lwjgl.system.MemoryUtil; -import static org.lwjgl.BufferUtils.*; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; -public final class IOUtil { +import static org.lwjgl.BufferUtils.createByteBuffer; - private IOUtil() { - } - - private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) { - ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity); - buffer.flip(); - newBuffer.put(buffer); - return newBuffer; - } +/** + * Utility-class without a state. This class offers method to interact with OpenCL e.g. memory management methods. + * + * @author Benedikt Zoennchen + */ +public class CLUtils { /** * Reads the specified resource and returns the raw data as a ByteBuffer. * * @param resource the resource to read * @param bufferSize the initial buffer size - * * @return the resource data - * * @throws IOException if an IO error occurs */ public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException { @@ -44,7 +46,7 @@ public final class IOUtil { } } else { try ( - InputStream source = IOUtil.class.getClassLoader().getResourceAsStream(resource); + InputStream source = CLUtils.class.getClassLoader().getResourceAsStream(resource); ReadableByteChannel rbc = Channels.newChannel(source) ) { buffer = createByteBuffer(bufferSize); @@ -64,4 +66,28 @@ public final class IOUtil { buffer.flip(); return buffer; } + + public static FloatBuffer toFloatBuffer(@NotNull final float[] floats) { + FloatBuffer floatBuffer = MemoryUtil.memAllocFloat(floats.length); + + for(int i = 0; i < floats.length; i++) { + floatBuffer.put(i, floats[i]); + } + return floatBuffer; + } + + public static float[] toFloatArray(@NotNull FloatBuffer floatBuffer, final int size) { + float[] result = new float[size]; + for(int i = 0; i < size; i++) { + result[i] = floatBuffer.get(i); + } + return result; + } + + private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) { + ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity); + buffer.flip(); + newBuffer.put(buffer); + return newBuffer; + } } diff --git a/VadereUtils/tests/org/vadere/util/math/TestConvolution.java b/VadereUtils/tests/org/vadere/util/math/TestConvolution.java index 67f9c6a33..80ebceaa6 100644 --- a/VadereUtils/tests/org/vadere/util/math/TestConvolution.java +++ b/VadereUtils/tests/org/vadere/util/math/TestConvolution.java @@ -4,6 +4,7 @@ import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.junit.Before; import org.junit.Test; +import org.vadere.util.opencl.CLConvolution; import java.io.IOException; -- GitLab