diff options
author | Michael Bien <[email protected]> | 2010-05-01 22:52:11 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-05-01 22:52:11 +0200 |
commit | 37401c35717505b79ab203881b86534bb7098ee8 (patch) | |
tree | 338d66ca2d1696cba9d838913150781479af1484 /src/com | |
parent | 2c85c416d85205ab98b33e1a0b0daab32d4d81ff (diff) |
MultiDeviceFractal is now... multi device again.
Julia3d + AMD: Fixed segfault on exit.
minor misc improvements.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/jogamp/opencl/demos/fractal/MultiDeviceFractal.java | 17 | ||||
-rw-r--r-- | src/com/jogamp/opencl/demos/julia3d/Julia3d.java | 21 | ||||
-rw-r--r-- | src/com/jogamp/opencl/demos/julia3d/Renderer.java | 20 |
3 files changed, 42 insertions, 16 deletions
diff --git a/src/com/jogamp/opencl/demos/fractal/MultiDeviceFractal.java b/src/com/jogamp/opencl/demos/fractal/MultiDeviceFractal.java index 26770b6..9420c6d 100644 --- a/src/com/jogamp/opencl/demos/fractal/MultiDeviceFractal.java +++ b/src/com/jogamp/opencl/demos/fractal/MultiDeviceFractal.java @@ -41,6 +41,7 @@ import javax.swing.SwingUtilities; import static com.jogamp.common.nio.Buffers.*; import static javax.media.opengl.GL2.*; import static com.jogamp.opencl.CLMemory.Mem.*; +import static com.jogamp.opencl.CLDevice.Type.*; import static com.jogamp.opencl.CLEvent.ProfilingCommand.*; import static com.jogamp.opencl.CLCommandQueue.Mode.*; import static java.lang.Math.*; @@ -102,7 +103,7 @@ public class MultiDeviceFractal implements GLEventListener { canvas.addGLEventListener(this); initSceneInteraction(); - JFrame frame = new JFrame("JOCL Multi GPU Mandelbrot Set"); + JFrame frame = new JFrame("JOCL Multi Device Mandelbrot Set"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); canvas.setPreferredSize(new Dimension(width, height)); frame.add(canvas); @@ -139,11 +140,12 @@ public class MultiDeviceFractal implements GLEventListener { private void initCL(GLContext glCtx){ try { - // create context managing all available GPUs -// clContext = CLGLContext.create(glCtx, GPU); - clContext = CLGLContext.create(glCtx, CLPlatform.getDefault().listCLDevices()[0]); - - + // SLI on NV platform wasn't very fast (or did not work at all) + if(CLPlatform.getDefault().getName().toLowerCase().contains("nvidia")) { + clContext = CLGLContext.create(glCtx, CLPlatform.getDefault().getMaxFlopsDevice(GPU)); + }else{ + clContext = CLGLContext.create(glCtx, ALL); + } CLDevice[] devices = clContext.getDevices(); slices = min(devices.length, MAX_PARRALLELISM_LEVEL); @@ -375,10 +377,11 @@ public class MultiDeviceFractal implements GLEventListener { textRenderer.draw("precision: "+ (doublePrecision?"64bit":"32bit"), 10, height-15); for (int i = 0; i < slices; i++) { + CLDevice device = queues[i].getDevice(); CLEvent event = probes.getEvent(i); long start = event.getProfilingInfo(START); long end = event.getProfilingInfo(END); - textRenderer.draw("GPU"+i +" "+(int)((end-start)/1000000.0f)+"ms", 10, height-(20+16*(slices-i))); + textRenderer.draw(device.getType().toString()+i +" "+(int)((end-start)/1000000.0f)+"ms", 10, height-(20+16*(slices-i))); } textRenderer.endRendering(); diff --git a/src/com/jogamp/opencl/demos/julia3d/Julia3d.java b/src/com/jogamp/opencl/demos/julia3d/Julia3d.java index 38633c6..f4bf392 100644 --- a/src/com/jogamp/opencl/demos/julia3d/Julia3d.java +++ b/src/com/jogamp/opencl/demos/julia3d/Julia3d.java @@ -43,15 +43,18 @@ public class Julia3d { this.config = renderConfig; updateCamera(); - //setup - CLDevice gpu = CLPlatform.getDefault().getMaxFlopsDevice(); - context = CLContext.create(gpu); + //setup, prefere GPUs + CLDevice device = CLPlatform.getDefault().getMaxFlopsDevice(CLDevice.Type.GPU); + if(device == null) { + device = CLPlatform.getDefault().getMaxFlopsDevice(); + } + context = CLContext.create(device); workGroupSize = 256; //allocate buffers configBuffer = context.createBuffer(config.getBuffer(), READ_ONLY); - commandQueue = gpu.createCommandQueue(); + commandQueue = device.createCommandQueue(); // update(true); try { @@ -63,7 +66,7 @@ public class Julia3d { julia = program.createCLKernel("JuliaGPU"); multiply = program.createCLKernel("multiply"); - System.out.println(program.getBuildStatus(gpu)); + System.out.println(program.getBuildStatus(device)); System.out.println(program.getBuildLog()); } @@ -179,6 +182,10 @@ public class Julia3d { vmul(camY, .5135f, camY); } + CLDevice getDevice() { + return commandQueue.getDevice(); + } + public static void main(String[] args) { @@ -208,5 +215,9 @@ public class Julia3d { return pixelBuffer.getBuffer(); } + void release() { + context.release(); + } + } diff --git a/src/com/jogamp/opencl/demos/julia3d/Renderer.java b/src/com/jogamp/opencl/demos/julia3d/Renderer.java index ce97e4a..6fe2309 100644 --- a/src/com/jogamp/opencl/demos/julia3d/Renderer.java +++ b/src/com/jogamp/opencl/demos/julia3d/Renderer.java @@ -1,9 +1,13 @@ package com.jogamp.opencl.demos.julia3d; +import com.jogamp.opencl.CLDevice; import com.jogamp.opencl.demos.julia3d.structs.RenderingConfig; import com.jogamp.opengl.util.awt.TextRenderer; import java.awt.Dimension; import java.awt.Font; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.nio.FloatBuffer; import java.util.Timer; import java.util.TimerTask; @@ -37,11 +41,11 @@ public class Renderer implements GLEventListener { private TimerTask task; private final Timer timer; - public Renderer(Julia3d julia3d) { + public Renderer(final Julia3d julia3d) { this.julia3d = julia3d; this.config = julia3d.config; - timer = new Timer(); + timer = new Timer(true); juliaSlice = newDirectFloatBuffer(MU_RECT_SIZE * MU_RECT_SIZE * 4); @@ -51,8 +55,16 @@ public class Renderer implements GLEventListener { usi = new UserSceneController(); usi.init(this, canvas, config); - JFrame frame = new JFrame("Java OpenCL - Julia3D GPU"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + CLDevice device = julia3d.getDevice(); + JFrame frame = new JFrame("Java OpenCL - Julia3D "+device.getType()+" "+device.getName()); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + julia3d.release(); + System.exit(0); + } + }); canvas.setPreferredSize(new Dimension(config.getWidth(), config.getHeight())); frame.add(canvas); frame.pack(); |