Compare View
Commits (7)
Diff
Showing 8 changed files Side-by-side Diff
ivy.xml
View file @
1d0884a
| ... | ... | @@ -3,13 +3,14 @@ |
| 3 | 3 | <configurations> |
| 4 | 4 | <conf name="default"/> |
| 5 | 5 | </configurations> |
| 6 | - | |
| 6 | + | |
| 7 | 7 | <dependencies> |
| 8 | 8 | <dependency org="org.geotools" name="gt-shapefile-ng" rev="8.6"/> |
| 9 | 9 | <dependency org="jfree" name="jfreechart" rev="1.0.13"/> |
| 10 | 10 | <dependency org="org.jocl" name="jocl" rev="0.1.9"/> |
| 11 | 11 | <dependency org="org.slf4j" name="slf4j-api" rev="1.6.6" conf="default->master"/> |
| 12 | 12 | <dependency org="org.perf4j" name="perf4j" rev="0.9.16" conf="default->master"/> |
| 13 | + <dependency org="ch.qos.logback" name="logback-core" rev="1.0.7" conf="default->master"/> | |
| 13 | 14 | <dependency org="ch.qos.logback" name="logback-classic" rev="1.0.7" conf="default->master"/> |
| 14 | 15 | <dependency org="net.sf.jopt-simple" name="jopt-simple" rev="4.3" conf="default->master"/> |
| 15 | 16 | <dependency org="it.unimi.dsi" name="fastutil" rev="6.5.15"/> |
src/mcmas/core/MCMContext.java
View file @
1d0884a
| ... | ... | @@ -17,30 +17,25 @@ public class MCMContext extends MCMObject { |
| 17 | 17 | private final cl_context context; |
| 18 | 18 | //private final static Logger logger = LoggerFactory.getLogger(OCLContext.class); |
| 19 | 19 | |
| 20 | + /** | |
| 21 | + * Create a new context using the first available hardware among | |
| 22 | + * default devices types. | |
| 23 | + */ | |
| 20 | 24 | public MCMContext() { |
| 21 | - MCMPlatform[] platforms = MCMPlatform.getPlatforms(); | |
| 22 | - | |
| 23 | - if (platforms.length <= 0) { | |
| 24 | - throw new RuntimeException("No OpenCL plaform found"); | |
| 25 | - } | |
| 26 | - | |
| 27 | - this.context = MCMHelpers.createContextFromType(platforms[0].getId(), | |
| 28 | - CL.CL_DEVICE_TYPE_GPU, CL.CL_DEVICE_TYPE_CPU); | |
| 29 | - | |
| 30 | - if (context == null) { | |
| 31 | - throw new RuntimeException("No CPU or GPU device found"); | |
| 32 | - } | |
| 33 | - } | |
| 34 | - | |
| 35 | - public MCMContext(MCMPlatform platform) { | |
| 36 | - this(platform, CL.CL_DEVICE_TYPE_GPU, CL.CL_DEVICE_TYPE_CPU); | |
| 25 | + this(getDefaultContextTypes()); | |
| 37 | 26 | } |
| 38 | 27 | |
| 28 | + /** | |
| 29 | + * Create a new context using the first available hardware among | |
| 30 | + * indicated device types. | |
| 31 | + * | |
| 32 | + * @param deviceTypes device types to search for | |
| 33 | + */ | |
| 39 | 34 | public MCMContext(long... deviceTypes) { |
| 40 | 35 | MCMPlatform[] platforms = MCMPlatform.getPlatforms(); |
| 41 | 36 | |
| 42 | 37 | if (platforms.length <= 0) { |
| 43 | - throw new RuntimeException("No OpenCL plaform found"); | |
| 38 | + throw new RuntimeException("No OpenCL platform found"); | |
| 44 | 39 | } |
| 45 | 40 | |
| 46 | 41 | this.context = MCMHelpers.createContextFromType(platforms[0].getId(), deviceTypes); |
| ... | ... | @@ -50,6 +45,21 @@ public class MCMContext extends MCMObject { |
| 50 | 45 | } |
| 51 | 46 | } |
| 52 | 47 | |
| 48 | + /** | |
| 49 | + * Create a new context using the indicated platform. | |
| 50 | + * | |
| 51 | + * @param platform platform to consider | |
| 52 | + */ | |
| 53 | + public MCMContext(MCMPlatform platform) { | |
| 54 | + this(platform, getDefaultContextTypes()); | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * Create a new context using the indicated platform and device types. | |
| 59 | + * | |
| 60 | + * @param platform platform to consider | |
| 61 | + * @param deviceTypes device types to search for | |
| 62 | + */ | |
| 53 | 63 | public MCMContext(MCMPlatform platform, long... deviceTypes) { |
| 54 | 64 | platform = Objects7.requireNonNull(platform, "Can't create an OpenCL context with a null platform"); |
| 55 | 65 | |
| ... | ... | @@ -63,6 +73,42 @@ public class MCMContext extends MCMObject { |
| 63 | 73 | } |
| 64 | 74 | } |
| 65 | 75 | |
| 76 | + /** | |
| 77 | + * Return a list of default device types to test when nothing | |
| 78 | + * is indicated at the MCMContext creation. | |
| 79 | + * | |
| 80 | + * The default list indicates to use these kind of hardware in this order: | |
| 81 | + * GPU, Accelerators (such as Xeon Phi) and CPU. | |
| 82 | + * | |
| 83 | + * It can be overriden using the MCM_CONTEXT_TYPE environment variable, | |
| 84 | + * which admits the following values: "CPU", "GPU", "ACCELERATOR", "ALL". | |
| 85 | + * | |
| 86 | + * "ALL" considers all the devices available on the system, but the | |
| 87 | + * order is not garanteed (even for the same type of device) and depends | |
| 88 | + * of the installed runtimes. | |
| 89 | + * | |
| 90 | + * @return a list of context type to try. | |
| 91 | + */ | |
| 92 | + public static long[] getDefaultContextTypes() { | |
| 93 | + String context_type = System.getenv("MCM_CONTEXT_TYPE"); | |
| 94 | + | |
| 95 | + if ("CPU".equals(context_type)) { | |
| 96 | + return new long[] { CL.CL_DEVICE_TYPE_CPU }; | |
| 97 | + } else if ("GPU".equals(context_type)) { | |
| 98 | + return new long[] { CL.CL_DEVICE_TYPE_GPU }; | |
| 99 | + } else if ("ACCELERATOR".equals(context_type)) { | |
| 100 | + return new long[] { CL.CL_DEVICE_TYPE_ACCELERATOR }; | |
| 101 | + } else if ("ALL".equals(context_type)) { | |
| 102 | + return new long[] { CL.CL_DEVICE_TYPE_ALL }; | |
| 103 | + } else { | |
| 104 | + return new long[] { | |
| 105 | + CL.CL_DEVICE_TYPE_GPU, | |
| 106 | + CL.CL_DEVICE_TYPE_ACCELERATOR, | |
| 107 | + CL.CL_DEVICE_TYPE_CPU | |
| 108 | + }; | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 66 | 112 | public cl_context getContext() { |
| 67 | 113 | return context; |
| 68 | 114 | } |
| ... | ... | @@ -131,6 +177,7 @@ public class MCMContext extends MCMObject { |
| 131 | 177 | return new MCMBufferBuilder(this); |
| 132 | 178 | } |
| 133 | 179 | |
| 180 | + @Deprecated | |
| 134 | 181 | public MCMMem createImage2d(long flags, int channelType, int width, int height) { |
| 135 | 182 | cl_image_format[] format = new cl_image_format[1]; |
| 136 | 183 | format[0].image_channel_order = CL.CL_RGBA; |
| ... | ... | @@ -139,6 +186,7 @@ public class MCMContext extends MCMObject { |
| 139 | 186 | return new MCMMem(CL.clCreateImage2D(context, flags, format, width, height, 0, null, null)); |
| 140 | 187 | } |
| 141 | 188 | |
| 189 | + @Deprecated | |
| 142 | 190 | public MCMMem createImage2d(long flags, int channelType, int width, int height, Buffer data) { |
| 143 | 191 | cl_image_format[] format = new cl_image_format[1]; |
| 144 | 192 | format[0].image_channel_order = CL.CL_RGBA; |
| ... | ... | @@ -147,6 +195,7 @@ public class MCMContext extends MCMObject { |
| 147 | 195 | return new MCMMem(CL.clCreateImage2D(context, flags, format, width, height, 0, Pointer.to(data), null)); |
| 148 | 196 | } |
| 149 | 197 | |
| 198 | + @Deprecated | |
| 150 | 199 | public MCMMem createImage2d(long flags, int channelType, int width, int height, Pointer data) { |
| 151 | 200 | cl_image_format[] format = new cl_image_format[1]; |
| 152 | 201 | format[0].image_channel_order = CL.CL_RGBA; |
src/mcmas/plugins/axb/AXBPlugin.java
View file @
1d0884a
| 1 | 1 | package mcmas.plugins.axb; |
| 2 | 2 | |
| 3 | -import java.util.Arrays; | |
| 4 | 3 | import java.util.Random; |
| 5 | 4 | |
| 6 | 5 | import org.jocl.Pointer; |
| ... | ... | @@ -9,7 +8,6 @@ import org.perf4j.slf4j.Slf4JStopWatch; |
| 9 | 8 | import org.slf4j.Logger; |
| 10 | 9 | import org.slf4j.LoggerFactory; |
| 11 | 10 | |
| 12 | -import preypredator.PPGrid; | |
| 13 | 11 | import mcmas.api.MCMASContext; |
| 14 | 12 | import mcmas.api.MCMASPlugin; |
| 15 | 13 | import mcmas.core.MCMCommandQueue; |
src/mcmas/plugins/gridsearch/GridSearchPlugin.java
View file @
1d0884a
| ... | ... | @@ -8,10 +8,9 @@ import org.perf4j.slf4j.Slf4JStopWatch; |
| 8 | 8 | import org.slf4j.Logger; |
| 9 | 9 | import org.slf4j.LoggerFactory; |
| 10 | 10 | |
| 11 | -import preypredator.PreyPredator2; | |
| 12 | 11 | import mcmas.api.MCMASContext; |
| 13 | 12 | import mcmas.api.MCMASPlugin; |
| 14 | -import mcmas.core.MCMChrono; | |
| 13 | +//import mcmas.core.MCMChrono; | |
| 15 | 14 | import mcmas.core.MCMCommandQueue; |
| 16 | 15 | import mcmas.core.MCMContext; |
| 17 | 16 | import mcmas.core.MCMEvent; |
src/preypredator/PPRuntimeGPU.java
View file @
1d0884a
| 1 | 1 | package preypredator; |
| 2 | 2 | |
| 3 | -import mcmas.api.ContextType; | |
| 4 | 3 | import mcmas.api.MCMASContext; |
| 5 | 4 | import mcmas.core.MCMCommandQueueProperty; |
| 6 | 5 | import mcmas.plugins.axb.AXBPlugin; |
| ... | ... | @@ -13,8 +12,8 @@ public class PPRuntimeGPU implements PPRuntime { |
| 13 | 12 | private final AXBPlugin axbPlugin; |
| 14 | 13 | private final GridSearchPlugin searchPlugin; |
| 15 | 14 | |
| 16 | - public PPRuntimeGPU(ContextType type) { | |
| 17 | - this.context = new MCMASContext(type, MCMCommandQueueProperty.ENABLE_PROFILING); | |
| 15 | + public PPRuntimeGPU() { | |
| 16 | + this.context = new MCMASContext(MCMCommandQueueProperty.ENABLE_PROFILING); | |
| 18 | 17 | this.axbPlugin = new AXBPlugin(context); |
| 19 | 18 | this.searchPlugin = new GridSearchPlugin(context); |
| 20 | 19 | } |
src/preypredator/PreyPredator2.java
View file @
1d0884a
| ... | ... | @@ -12,7 +12,6 @@ import org.slf4j.LoggerFactory; |
| 12 | 12 | |
| 13 | 13 | import joptsimple.OptionParser; |
| 14 | 14 | import joptsimple.OptionSet; |
| 15 | -import mcmas.api.ContextType; | |
| 16 | 15 | |
| 17 | 16 | public class PreyPredator2 { |
| 18 | 17 | |
| ... | ... | @@ -241,7 +240,7 @@ public class PreyPredator2 { |
| 241 | 240 | public static void main(String[] args) { |
| 242 | 241 | OptionParser parser = new OptionParser(); |
| 243 | 242 | |
| 244 | - parser.acceptsAll(Arrays.asList("g", "gpu"), "Enable GPU context") | |
| 243 | + parser.acceptsAll(Arrays.asList("g", "gpu", "opencl"), "Enable OpenCL support") | |
| 245 | 244 | .withOptionalArg().ofType(Boolean.class).defaultsTo(true); |
| 246 | 245 | |
| 247 | 246 | parser.acceptsAll(Arrays.asList("h", "help"), "Print this help"); |
| ... | ... | @@ -273,10 +272,10 @@ public class PreyPredator2 { |
| 273 | 272 | PPRuntime runtime; |
| 274 | 273 | |
| 275 | 274 | if ((Boolean) (options.valueOf("gpu"))) { |
| 276 | - logger.info("Use GPU Runtime"); | |
| 277 | - runtime = new PPRuntimeGPU(ContextType.ALL); | |
| 275 | + logger.info("Use OpenCL runtime on first available GPU"); | |
| 276 | + runtime = new PPRuntimeGPU(); | |
| 278 | 277 | } else { |
| 279 | - logger.info("Use CPU Runtime"); | |
| 278 | + logger.info("Use Java Runtime"); | |
| 280 | 279 | runtime = new PPRuntimeCPU(); |
| 281 | 280 | } |
| 282 | 281 |
utils/mcmas/infos.sh
View file @
1d0884a
| ... | ... | @@ -17,4 +17,4 @@ cat /etc/issue > $DEST_DIR/platform_issue |
| 17 | 17 | uname -a > $DEST_DIR/platform_kernel |
| 18 | 18 | cat /proc/cpuinfo > $DEST_DIR/platform_cpuinfo |
| 19 | 19 | free -m > $DEST_DIR/platform_memory |
| 20 | -$JAVA mcsma.core.OCLUtils > $DEST_DIR/platform_opencl | |
| 20 | +$JAVA mcmas.core.MCMUtils > $DEST_DIR/platform_opencl |