Commit 4356a017e6a4b73d7701b6c1ab384e2abc8e1a7f

Authored by glaville
1 parent db47aedc52
Exists in master

Cleanup warnings

Showing 2 changed files with 1 additions and 4 deletions Inline Diff

src/mcmas/plugins/axb/AXBPlugin.java View file @ 4356a01
package mcmas.plugins.axb; 1 1 package mcmas.plugins.axb;
2 2
import java.util.Arrays; 3
import java.util.Random; 4 3 import java.util.Random;
5 4
import org.jocl.Pointer; 6 5 import org.jocl.Pointer;
import org.perf4j.StopWatch; 7 6 import org.perf4j.StopWatch;
import org.perf4j.slf4j.Slf4JStopWatch; 8 7 import org.perf4j.slf4j.Slf4JStopWatch;
import org.slf4j.Logger; 9 8 import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 10 9 import org.slf4j.LoggerFactory;
11 10
import preypredator.PPGrid; 12
import mcmas.api.MCMASContext; 13 11 import mcmas.api.MCMASContext;
import mcmas.api.MCMASPlugin; 14 12 import mcmas.api.MCMASPlugin;
import mcmas.core.MCMCommandQueue; 15 13 import mcmas.core.MCMCommandQueue;
import mcmas.core.MCMCommandQueueProperty; 16 14 import mcmas.core.MCMCommandQueueProperty;
import mcmas.core.MCMContext; 17 15 import mcmas.core.MCMContext;
import mcmas.core.MCMEvent; 18 16 import mcmas.core.MCMEvent;
import mcmas.core.MCMKernel; 19 17 import mcmas.core.MCMKernel;
import mcmas.core.MCMMem; 20 18 import mcmas.core.MCMMem;
import mcmas.core.MCMProgram; 21 19 import mcmas.core.MCMProgram;
import mcmas.core.MCMProgramOptions; 22 20 import mcmas.core.MCMProgramOptions;
import mcmas.core.MCMType; 23 21 import mcmas.core.MCMType;
import mcmas.core.MCMUtils; 24 22 import mcmas.core.MCMUtils;
25 23
public class AXBPlugin extends MCMASPlugin<AXBPlugin> { 26 24 public class AXBPlugin extends MCMASPlugin<AXBPlugin> {
27 25
private final Logger logger = LoggerFactory.getLogger(AXBPlugin.class); 28 26 private final Logger logger = LoggerFactory.getLogger(AXBPlugin.class);
private final StopWatch watch = new Slf4JStopWatch().setNormalPriority(Slf4JStopWatch.DEBUG_LEVEL); 29 27 private final StopWatch watch = new Slf4JStopWatch().setNormalPriority(Slf4JStopWatch.DEBUG_LEVEL);
private final StopWatch runWatch = new Slf4JStopWatch().setNormalPriority(Slf4JStopWatch.TRACE_LEVEL); 30 28 private final StopWatch runWatch = new Slf4JStopWatch().setNormalPriority(Slf4JStopWatch.TRACE_LEVEL);
31 29
@Override 32 30 @Override
public AXBPlugin newInstance(MCMASContext context) { 33 31 public AXBPlugin newInstance(MCMASContext context) {
return null; 34 32 return null;
} 35 33 }
36 34
private static final String SOURCE = "kernels/plugins/axb.cl"; 37 35 private static final String SOURCE = "kernels/plugins/axb.cl";
38 36
private MCMKernel kernel = null; 39 37 private MCMKernel kernel = null;
40 38
public AXBPlugin(MCMASContext context) { 41 39 public AXBPlugin(MCMASContext context) {
super(context); 42 40 super(context);
} 43 41 }
44 42
public void transform(int[] vector, float a, float b) { 45 43 public void transform(int[] vector, float a, float b) {
watch.start("axb_transform"); 46 44 watch.start("axb_transform");
MCMMem vectorMem = getContext().getContext().newBuffer().Using(vector).b(); 47 45 MCMMem vectorMem = getContext().getContext().newBuffer().Using(vector).b();
transform("int", vectorMem, Pointer.to(vector), vector.length, a, b); 48 46 transform("int", vectorMem, Pointer.to(vector), vector.length, a, b);
watch.stop(); 49 47 watch.stop();
} 50 48 }
51 49
public void transform(float[] vector, float a, float b) { 52 50 public void transform(float[] vector, float a, float b) {
watch.start("axb_transform"); 53 51 watch.start("axb_transform");
MCMMem vectorMem = getContext().getContext().newBuffer().Size(vector.length, MCMType.FLOAT).b(); 54 52 MCMMem vectorMem = getContext().getContext().newBuffer().Size(vector.length, MCMType.FLOAT).b();
transform("float", vectorMem, Pointer.to(vector), vector.length, a, b); 55 53 transform("float", vectorMem, Pointer.to(vector), vector.length, a, b);
watch.stop(); 56 54 watch.stop();
} 57 55 }
58 56
private void transform(String type, MCMMem mem, Pointer pointer, int size, Object a, Object b) { 59 57 private void transform(String type, MCMMem mem, Pointer pointer, int size, Object a, Object b) {
MCMProgramOptions options = new MCMProgramOptions(); 60 58 MCMProgramOptions options = new MCMProgramOptions();
options.define("TYPE", type); 61 59 options.define("TYPE", type);
62 60
MCMContext c = getContext().getContext(); 63 61 MCMContext c = getContext().getContext();
MCMCommandQueue q = getContext().getQueue(); 64 62 MCMCommandQueue q = getContext().getQueue();
//OCLKernel kernel = null; 65 63 //OCLKernel kernel = null;
MCMProgram program = null; 66 64 MCMProgram program = null;
MCMEvent finished = null; 67 65 MCMEvent finished = null;
68 66
try { 69 67 try {
runWatch.start("axb_build"); 70 68 runWatch.start("axb_build");
if (kernel == null) { 71 69 if (kernel == null) {
c = getContext().getContext(); 72 70 c = getContext().getContext();
73 71
q = getContext().getQueue(); 74 72 q = getContext().getQueue();
program = c.createProgramFromFile(SOURCE, options); 75 73 program = c.createProgramFromFile(SOURCE, options);
76 74
kernel = program.createKernel("transform"); 77 75 kernel = program.createKernel("transform");
} 78 76 }
runWatch.stop(); 79 77 runWatch.stop();
80 78
runWatch.start("axb_kernel"); 81 79 runWatch.start("axb_kernel");
82 80
kernel.setArguments(mem, a, b); 83 81 kernel.setArguments(mem, a, b);
finished = q.enqueue1DKernel(kernel, size); 84 82 finished = q.enqueue1DKernel(kernel, size);
q.blockingReadBuffer(mem, pointer, 0, mem.getSize(), finished); 85 83 q.blockingReadBuffer(mem, pointer, 0, mem.getSize(), finished);
86 84
runWatch.stop(); 87 85 runWatch.stop();
88 86
logger.debug(MCMUtils.formatEventStats("axb_opencl", finished)); 89 87 logger.debug(MCMUtils.formatEventStats("axb_opencl", finished));
} finally { 90 88 } finally {
finished.release(); 91 89 finished.release();
mem.release(); 92 90 mem.release();
//kernel.release(); 93 91 //kernel.release();
94 92
if (program != null) { 95 93 if (program != null) {
program.release(); 96 94 program.release();
} 97 95 }
} 98 96 }
} 99 97 }
100 98
public void clampedTransform(int[] vector, float a, int b, int min, int max) { 101 99 public void clampedTransform(int[] vector, float a, int b, int min, int max) {
watch.start("axb_clamped_transform " + vector.length); 102 100 watch.start("axb_clamped_transform " + vector.length);
MCMMem vectorMem = getMCMContext().newBuffer().Using(vector).b(); 103 101 MCMMem vectorMem = getMCMContext().newBuffer().Using(vector).b();
clampedTransform("int", vectorMem, Pointer.to(vector), vector.length, a, b, min, max); 104 102 clampedTransform("int", vectorMem, Pointer.to(vector), vector.length, a, b, min, max);
watch.stop(); 105 103 watch.stop();
} 106 104 }
107 105
public void clampedTransform(float[] vector, float a, float b, float min, float max) { 108 106 public void clampedTransform(float[] vector, float a, float b, float min, float max) {
watch.start("axb_clamped_transform"); 109 107 watch.start("axb_clamped_transform");
MCMMem vectorMem = getMCMContext().newBuffer().Using(vector).b(); 110 108 MCMMem vectorMem = getMCMContext().newBuffer().Using(vector).b();
clampedTransform("float", vectorMem, Pointer.to(vector), vector.length, a, b, min, max); 111 109 clampedTransform("float", vectorMem, Pointer.to(vector), vector.length, a, b, min, max);
watch.stop(); 112 110 watch.stop();
} 113 111 }
114 112
private void clampedTransform(String type, MCMMem mem, Pointer pointer, int size, Object a, Object b, 115 113 private void clampedTransform(String type, MCMMem mem, Pointer pointer, int size, Object a, Object b,
Object min, Object max) { 116 114 Object min, Object max) {
MCMProgramOptions options = new MCMProgramOptions(); 117 115 MCMProgramOptions options = new MCMProgramOptions();
options.define("TYPE", type); 118 116 options.define("TYPE", type);
119 117
MCMContext c = getContext().getContext(); 120 118 MCMContext c = getContext().getContext();
MCMCommandQueue q = getContext().getQueue(); 121 119 MCMCommandQueue q = getContext().getQueue();
//OCLKernel kernel = null; 122 120 //OCLKernel kernel = null;
MCMProgram program = null; 123 121 MCMProgram program = null;
MCMEvent finished = null; 124 122 MCMEvent finished = null;
125 123
try { 126 124 try {
runWatch.start("axb_build"); 127 125 runWatch.start("axb_build");
if (kernel == null) { 128 126 if (kernel == null) {
c = getContext().getContext(); 129 127 c = getContext().getContext();
130 128
q = getContext().getQueue(); 131 129 q = getContext().getQueue();
program = c.createProgramFromFile(SOURCE, options); 132 130 program = c.createProgramFromFile(SOURCE, options);
133 131
kernel = program.createKernel("clamped_transform"); 134 132 kernel = program.createKernel("clamped_transform");
} 135 133 }
runWatch.stop(); 136 134 runWatch.stop();
137 135
runWatch.start("axb_kernel"); 138 136 runWatch.start("axb_kernel");
139 137
kernel.setArguments(mem, a, b, min, max); 140 138 kernel.setArguments(mem, a, b, min, max);
finished = q.enqueue1DKernel(kernel, size); 141 139 finished = q.enqueue1DKernel(kernel, size);
q.blockingReadBuffer(mem, pointer, 0, mem.getSize(), finished); 142 140 q.blockingReadBuffer(mem, pointer, 0, mem.getSize(), finished);
143 141
runWatch.stop(); 144 142 runWatch.stop();
145 143
logger.trace(MCMUtils.formatEventStats("opencl_transform", finished)); 146 144 logger.trace(MCMUtils.formatEventStats("opencl_transform", finished));
} finally { 147 145 } finally {
src/mcmas/plugins/gridsearch/GridSearchPlugin.java View file @ 4356a01
package mcmas.plugins.gridsearch; 1 1 package mcmas.plugins.gridsearch;
2 2
import java.util.Arrays; 3 3 import java.util.Arrays;
4 4
import org.jocl.Pointer; 5 5 import org.jocl.Pointer;
import org.perf4j.StopWatch; 6 6 import org.perf4j.StopWatch;
import org.perf4j.slf4j.Slf4JStopWatch; 7 7 import org.perf4j.slf4j.Slf4JStopWatch;
import org.slf4j.Logger; 8 8 import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 9 9 import org.slf4j.LoggerFactory;
10 10
import preypredator.PreyPredator2; 11
import mcmas.api.MCMASContext; 12 11 import mcmas.api.MCMASContext;
import mcmas.api.MCMASPlugin; 13 12 import mcmas.api.MCMASPlugin;
import mcmas.core.MCMChrono; 14 13 //import mcmas.core.MCMChrono;
import mcmas.core.MCMCommandQueue; 15 14 import mcmas.core.MCMCommandQueue;
import mcmas.core.MCMContext; 16 15 import mcmas.core.MCMContext;
import mcmas.core.MCMEvent; 17 16 import mcmas.core.MCMEvent;
import mcmas.core.MCMKernel; 18 17 import mcmas.core.MCMKernel;
import mcmas.core.MCMMem; 19 18 import mcmas.core.MCMMem;
import mcmas.core.MCMProgram; 20 19 import mcmas.core.MCMProgram;
import mcmas.core.MCMProgramOptions; 21 20 import mcmas.core.MCMProgramOptions;
import mcmas.core.MCMUtils; 22 21 import mcmas.core.MCMUtils;
import mcmas.utils.IntMatrix; 23 22 import mcmas.utils.IntMatrix;
24 23
public class GridSearchPlugin extends MCMASPlugin<GridSearchPlugin> { 25 24 public class GridSearchPlugin extends MCMASPlugin<GridSearchPlugin> {
26 25
public static final String KERNEL_SOURCE = "kernels/plugins/grid_search2.cl"; 27 26 public static final String KERNEL_SOURCE = "kernels/plugins/grid_search2.cl";
public static final String KERNEL_MAX = "grid_search_max"; 28 27 public static final String KERNEL_MAX = "grid_search_max";
29 28
private MCMKernel kernel = null; 30 29 private MCMKernel kernel = null;
31 30
private final static Logger logger = LoggerFactory.getLogger(GridSearchPlugin.class); 32 31 private final static Logger logger = LoggerFactory.getLogger(GridSearchPlugin.class);
private final StopWatch watch = new Slf4JStopWatch().setNormalPriority(Slf4JStopWatch.DEBUG_LEVEL); 33 32 private final StopWatch watch = new Slf4JStopWatch().setNormalPriority(Slf4JStopWatch.DEBUG_LEVEL);
private final StopWatch runWatch = new Slf4JStopWatch().setNormalPriority(Slf4JStopWatch.TRACE_LEVEL); 34 33 private final StopWatch runWatch = new Slf4JStopWatch().setNormalPriority(Slf4JStopWatch.TRACE_LEVEL);
35 34
@Override 36 35 @Override
public GridSearchPlugin newInstance(MCMASContext context) { 37 36 public GridSearchPlugin newInstance(MCMASContext context) {
return new GridSearchPlugin(context); 38 37 return new GridSearchPlugin(context);
} 39 38 }
40 39
public GridSearchPlugin(MCMASContext context) { 41 40 public GridSearchPlugin(MCMASContext context) {
super(context); 42 41 super(context);
} 43 42 }
44 43
public void findMaxCell(IntMatrix grid, int radius, int[] xPositions, int[] yPositions, int[] xResults, int[] yResults) { 45 44 public void findMaxCell(IntMatrix grid, int radius, int[] xPositions, int[] yPositions, int[] xResults, int[] yResults) {
watch.start("gridsearch_findmax"); 46 45 watch.start("gridsearch_findmax");
MCMContext c = getContext().getContext(); 47 46 MCMContext c = getContext().getContext();
MCMCommandQueue q = getContext().getQueue(); 48 47 MCMCommandQueue q = getContext().getQueue();
49 48
//OCLProgram program = null; 50 49 //OCLProgram program = null;
//OCLKernel kernel = null; 51 50 //OCLKernel kernel = null;
MCMMem gridMem = null; 52 51 MCMMem gridMem = null;
MCMMem xPositionsMem = null; 53 52 MCMMem xPositionsMem = null;
MCMMem yPositionsMem = null; 54 53 MCMMem yPositionsMem = null;
MCMMem xResultsMem = null; 55 54 MCMMem xResultsMem = null;
MCMMem yResultsMem = null; 56 55 MCMMem yResultsMem = null;
57 56
MCMProgramOptions options = new MCMProgramOptions(); 58 57 MCMProgramOptions options = new MCMProgramOptions();
options.define("WIDTH", grid.getWidth()); 59 58 options.define("WIDTH", grid.getWidth());
options.define("HEIGHT", grid.getHeight()); 60 59 options.define("HEIGHT", grid.getHeight());
options.define("TYPE", "int"); 61 60 options.define("TYPE", "int");
62 61
//System.out.println(options); 63 62 //System.out.println(options);
64 63
MCMProgram program = null; 65 64 MCMProgram program = null;
//OCLKernel kernel = null; 66 65 //OCLKernel kernel = null;
MCMEvent finished = null; 67 66 MCMEvent finished = null;
68 67
try { 69 68 try {
runWatch.start("gridsearch_build"); 70 69 runWatch.start("gridsearch_build");
if (kernel == null) { 71 70 if (kernel == null) {
program = c.createProgramFromFile(KERNEL_SOURCE, options); 72 71 program = c.createProgramFromFile(KERNEL_SOURCE, options);
kernel = program.createKernel(KERNEL_MAX); 73 72 kernel = program.createKernel(KERNEL_MAX);
} 74 73 }
runWatch.stop(); 75 74 runWatch.stop();
76 75
runWatch.start("gridsearch_kernel"); 77 76 runWatch.start("gridsearch_kernel");
78 77
gridMem = c.newBuffer().Using(grid.getStorage()).b(); 79 78 gridMem = c.newBuffer().Using(grid.getStorage()).b();
xPositionsMem = c.newBuffer().Using(xPositions).b(); 80 79 xPositionsMem = c.newBuffer().Using(xPositions).b();
yPositionsMem = c.newBuffer().Using(yPositions).b(); 81 80 yPositionsMem = c.newBuffer().Using(yPositions).b();
xResultsMem = c.newBuffer().Size(xPositionsMem.getSize()).b(); 82 81 xResultsMem = c.newBuffer().Size(xPositionsMem.getSize()).b();
yResultsMem = c.newBuffer().Size(yPositionsMem.getSize()).b(); 83 82 yResultsMem = c.newBuffer().Size(yPositionsMem.getSize()).b();
84 83
kernel.setArguments(gridMem, radius, xPositionsMem, yPositionsMem, xResultsMem, yResultsMem); 85 84 kernel.setArguments(gridMem, radius, xPositionsMem, yPositionsMem, xResultsMem, yResultsMem);
86 85
finished = q.enqueue1DKernel(kernel, xPositions.length); 87 86 finished = q.enqueue1DKernel(kernel, xPositions.length);
88 87
q.blockingReadBuffer(xResultsMem, Pointer.to(xResults), 0, xResultsMem.getSize(), finished); 89 88 q.blockingReadBuffer(xResultsMem, Pointer.to(xResults), 0, xResultsMem.getSize(), finished);
q.blockingReadBuffer(yResultsMem, Pointer.to(yResults), 0, yResultsMem.getSize(), finished); 90 89 q.blockingReadBuffer(yResultsMem, Pointer.to(yResults), 0, yResultsMem.getSize(), finished);
91 90
runWatch.stop(); 92 91 runWatch.stop();
93 92
logger.debug(MCMUtils.formatEventStats("gridsearch_opencl", finished)); 94 93 logger.debug(MCMUtils.formatEventStats("gridsearch_opencl", finished));
95 94
watch.stop(); 96 95 watch.stop();
} catch (Exception e) { 97 96 } catch (Exception e) {
System.err.println(e); 98 97 System.err.println(e);
e.printStackTrace(); 99 98 e.printStackTrace();
} finally { 100 99 } finally {
gridMem.release(); 101 100 gridMem.release();
xPositionsMem.release(); 102 101 xPositionsMem.release();
yPositionsMem.release(); 103 102 yPositionsMem.release();
xResultsMem.release(); 104 103 xResultsMem.release();
yResultsMem.release(); 105 104 yResultsMem.release();
finished.release(); 106 105 finished.release();
//kernel.release(); 107 106 //kernel.release();
if (program != null) { 108 107 if (program != null) {
program.release(); 109 108 program.release();
} 110 109 }
} 111 110 }
} 112 111 }
113 112
/* 114 113 /*
public void findNearestCellNot(float[] vector, int radius, float value, int[] xPositions, int[] yPositions, int[] xResults, int[] yResults) { 115 114 public void findNearestCellNot(float[] vector, int radius, float value, int[] xPositions, int[] yPositions, int[] xResults, int[] yResults) {
OCLContext c = getContext().getContext(); 116 115 OCLContext c = getContext().getContext();
OCLCommandQueue q = getContext().getQueue(); 117 116 OCLCommandQueue q = getContext().getQueue();
118 117
OCLProgram program = null; 119 118 OCLProgram program = null;
OCLKernel kernel = null; 120 119 OCLKernel kernel = null;
OCLMem xPositionsMem = null; 121 120 OCLMem xPositionsMem = null;
OCLMem yPositionsMem = null; 122 121 OCLMem yPositionsMem = null;
OCLMem xResultsMem = null; 123 122 OCLMem xResultsMem = null;
OCLMem yResultsMem = null; 124 123 OCLMem yResultsMem = null;
125 124
try { 126 125 try {
program = c.createProgramFromFile(SOURCE_NEAREST); 127 126 program = c.createProgramFromFile(SOURCE_NEAREST);
kernel = program.createKernel("search_float_nearest"); 128 127 kernel = program.createKernel("search_float_nearest");
129 128
xPositionsMem = c.newBuffer().Using(xPositions).b(); 130 129 xPositionsMem = c.newBuffer().Using(xPositions).b();
yPositionsMem = c.newBuffer().Using(yPositions).b(); 131 130 yPositionsMem = c.newBuffer().Using(yPositions).b();
xResultsMem = c.newBuffer().Size(xResults.length, OCLType.FLOAT).b(); 132 131 xResultsMem = c.newBuffer().Size(xResults.length, OCLType.FLOAT).b();
yResultsMem = c.newBuffer().Size(yResults.length, OCLType.FLOAT).b(); 133 132 yResultsMem = c.newBuffer().Size(yResults.length, OCLType.FLOAT).b();
134 133
kernel.setArguments(vector, radius, value, xPositionsMem, yPositionsMem, xResultsMem, yResultsMem); 135 134 kernel.setArguments(vector, radius, value, xPositionsMem, yPositionsMem, xResultsMem, yResultsMem);
OCLEvent finished = q.enqueue1DKernel(kernel, vector.length); 136 135 OCLEvent finished = q.enqueue1DKernel(kernel, vector.length);
137 136
OCLEvent r1 = q.enqueueReadBuffer(xResultsMem, Pointer.to(xResults), 0, xResultsMem.getSize(), finished); 138 137 OCLEvent r1 = q.enqueueReadBuffer(xResultsMem, Pointer.to(xResults), 0, xResultsMem.getSize(), finished);
OCLEvent r2 = q.enqueueReadBuffer(yResultsMem, Pointer.to(yResults), 0, yResultsMem.getSize(), finished); 139 138 OCLEvent r2 = q.enqueueReadBuffer(yResultsMem, Pointer.to(yResults), 0, yResultsMem.getSize(), finished);
140 139
OCLEvent.waitFor(r1, r2); 141 140 OCLEvent.waitFor(r1, r2);
} finally { 142 141 } finally {
xPositionsMem.release(); 143 142 xPositionsMem.release();