Commit 85791ed1 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

renaming of some classes and packages

parent c6e15f01
......@@ -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 {
......
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;
}
}
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));
}
}
package org.vadere.util.math;
package org.vadere.util.opencl;
//TODO: implement FFT!
public class CLFFT {
......
......@@ -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()) {
......
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;
}
}
......@@ -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;
......
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