use of com.jogamp.opencl.CLDevice in project jmonkeyengine by jMonkeyEngine.
the class JoglContext method initOpenCL.
@SuppressWarnings("unchecked")
protected void initOpenCL() {
logger.info("Initialize OpenCL with JOGL");
//load platforms and devices
StringBuilder platformInfos = new StringBuilder();
ArrayList<JoclPlatform> platforms = new ArrayList<JoclPlatform>();
for (CLPlatform p : CLPlatform.listCLPlatforms()) {
platforms.add(new JoclPlatform(p));
}
platformInfos.append("Available OpenCL platforms:");
for (int i = 0; i < platforms.size(); ++i) {
JoclPlatform platform = platforms.get(i);
platformInfos.append("\n * Platform ").append(i + 1);
platformInfos.append("\n * Name: ").append(platform.getName());
platformInfos.append("\n * Vendor: ").append(platform.getVendor());
platformInfos.append("\n * Version: ").append(platform.getVersion());
platformInfos.append("\n * Profile: ").append(platform.getProfile());
platformInfos.append("\n * Supports interop: ").append(platform.hasOpenGLInterop());
List<JoclDevice> devices = platform.getDevices();
platformInfos.append("\n * Available devices:");
for (int j = 0; j < devices.size(); ++j) {
JoclDevice device = devices.get(j);
platformInfos.append("\n * * Device ").append(j + 1);
platformInfos.append("\n * * Name: ").append(device.getName());
platformInfos.append("\n * * Vendor: ").append(device.getVendor());
platformInfos.append("\n * * Version: ").append(device.getVersion());
platformInfos.append("\n * * Profile: ").append(device.getProfile());
platformInfos.append("\n * * Compiler version: ").append(device.getCompilerVersion());
platformInfos.append("\n * * Device type: ").append(device.getDeviceType());
platformInfos.append("\n * * Compute units: ").append(device.getComputeUnits());
platformInfos.append("\n * * Work group size: ").append(device.getMaxiumWorkItemsPerGroup());
platformInfos.append("\n * * Global memory: ").append(device.getGlobalMemorySize()).append("B");
platformInfos.append("\n * * Local memory: ").append(device.getLocalMemorySize()).append("B");
platformInfos.append("\n * * Constant memory: ").append(device.getMaximumConstantBufferSize()).append("B");
platformInfos.append("\n * * Supports double: ").append(device.hasDouble());
platformInfos.append("\n * * Supports half floats: ").append(device.hasHalfFloat());
platformInfos.append("\n * * Supports writable 3d images: ").append(device.hasWritableImage3D());
platformInfos.append("\n * * Supports interop: ").append(device.hasOpenGLInterop());
}
}
logger.info(platformInfos.toString());
//choose devices
PlatformChooser chooser = null;
if (settings.getOpenCLPlatformChooser() != null) {
try {
chooser = (PlatformChooser) Class.forName(settings.getOpenCLPlatformChooser()).newInstance();
} catch (Exception ex) {
logger.log(Level.WARNING, "unable to instantiate custom PlatformChooser", ex);
}
}
if (chooser == null) {
chooser = new DefaultPlatformChooser();
}
List<? extends Device> choosenDevices = chooser.chooseDevices(platforms);
List<CLDevice> devices = new ArrayList<>(choosenDevices.size());
JoclPlatform platform = null;
for (Device d : choosenDevices) {
if (!(d instanceof JoclDevice)) {
logger.log(Level.SEVERE, "attempt to return a custom Device implementation from PlatformChooser: {0}", d);
return;
}
JoclDevice ld = (JoclDevice) d;
if (platform == null) {
platform = ld.getPlatform();
} else if (platform != ld.getPlatform()) {
logger.severe("attempt to use devices from different platforms");
return;
}
devices.add(ld.getDevice());
}
if (devices.isEmpty()) {
logger.warning("no devices specified, no OpenCL context created");
return;
}
logger.log(Level.INFO, "chosen platform: {0}", platform.getName());
logger.log(Level.INFO, "chosen devices: {0}", choosenDevices);
//create context
try {
CLGLContext c = CLGLContext.create(GLContext.getCurrent(), devices.toArray(new CLDevice[devices.size()]));
clContext = new com.jme3.opencl.jocl.JoclContext(c, (List<JoclDevice>) choosenDevices);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Unable to create OpenCL context", ex);
return;
}
logger.info("OpenCL context created");
}
use of com.jogamp.opencl.CLDevice in project Glowstone by GlowstoneMC.
the class GlowServer method start.
/**
* Starts this server.
*/
public void start() {
// Determine console mode and start reading input
consoleManager.startConsole(config.getBoolean(Key.USE_JLINE));
consoleManager.startFile(config.getString(Key.LOG_FILE));
if (getProxySupport()) {
if (getOnlineMode()) {
logger.warning("Proxy support is enabled, but online mode is enabled.");
} else {
logger.info("Proxy support is enabled.");
}
} else if (!getOnlineMode()) {
logger.warning("The server is running in offline mode! Only do this if you know what you're doing.");
}
int openCLMajor = 1;
int openCLMinor = 2;
if (doesUseGPGPU()) {
int maxGpuFlops = 0;
int maxIntelFlops = 0;
int maxCpuFlops = 0;
CLPlatform bestPlatform = null;
CLPlatform bestIntelPlatform = null;
CLPlatform bestCpuPlatform = null;
// gets the max flops device across platforms on the computer
for (CLPlatform platform : CLPlatform.listCLPlatforms()) {
if (platform.isAtLeast(openCLMajor, openCLMinor) && platform.isExtensionAvailable("cl_khr_fp64")) {
for (CLDevice device : platform.listCLDevices()) {
if (device.getType() == CLDevice.Type.GPU) {
int flops = device.getMaxComputeUnits() * device.getMaxClockFrequency();
logger.info("Found " + device + " with " + flops + " flops");
if (device.getVendor().contains("Intel")) {
if (flops > maxIntelFlops) {
maxIntelFlops = flops;
logger.info("Device is best platform so far, on " + platform);
bestIntelPlatform = platform;
} else if (flops == maxIntelFlops) {
if (bestIntelPlatform != null && bestIntelPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
maxIntelFlops = flops;
logger.info("Device tied for flops, but had higher version on " + platform);
bestIntelPlatform = platform;
}
}
} else {
if (flops > maxGpuFlops) {
maxGpuFlops = flops;
logger.info("Device is best platform so far, on " + platform);
bestPlatform = platform;
} else if (flops == maxGpuFlops) {
if (bestPlatform != null && bestPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
maxGpuFlops = flops;
logger.info("Device tied for flops, but had higher version on " + platform);
bestPlatform = platform;
}
}
}
} else {
int flops = device.getMaxComputeUnits() * device.getMaxClockFrequency();
logger.info("Found " + device + " with " + flops + " flops");
if (flops > maxCpuFlops) {
maxCpuFlops = flops;
logger.info("Device is best platform so far, on " + platform);
bestCpuPlatform = platform;
} else if (flops == maxCpuFlops) {
if (bestCpuPlatform != null && bestCpuPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
maxCpuFlops = flops;
logger.info("Device tied for flops, but had higher version on " + platform);
bestCpuPlatform = platform;
}
}
}
}
}
}
if (config.getBoolean(Key.GPGPU_ANY_DEVICE)) {
if (maxGpuFlops - maxIntelFlops < 0 && maxCpuFlops - maxIntelFlops <= 0) {
bestPlatform = bestIntelPlatform;
} else if (maxGpuFlops - maxCpuFlops < 0 && maxIntelFlops - maxCpuFlops < 0) {
bestPlatform = bestCpuPlatform;
}
} else {
if (maxGpuFlops == 0) {
if (maxIntelFlops == 0) {
logger.info("No Intel graphics found, best platform is the best CPU platform we could find...");
bestPlatform = bestCpuPlatform;
} else {
logger.info("No dGPU found, best platform is the best Intel graphics we could find...");
bestPlatform = bestIntelPlatform;
}
}
}
if (bestPlatform == null) {
isCLApplicable = false;
logger.info("Your system does not meet the OpenCL requirements for Glowstone. See if driver updates are available.");
logger.info("Required version: " + openCLMajor + '.' + openCLMinor);
logger.info("Required extensions: [ cl_khr_fp64 ]");
} else {
OpenCL.initContext(bestPlatform);
}
}
// Load player lists
opsList.load();
whitelist.load();
nameBans.load();
ipBans.load();
setPort(config.getInt(Key.SERVER_PORT));
setIp(config.getString(Key.SERVER_IP));
try {
LootingManager.load();
} catch (Exception e) {
GlowServer.logger.severe("Failed to load looting manager: ");
e.printStackTrace();
}
// Start loading plugins
new LibraryManager().run();
loadPlugins();
enablePlugins(PluginLoadOrder.STARTUP);
// Create worlds
String name = config.getString(Key.LEVEL_NAME);
String seedString = config.getString(Key.LEVEL_SEED);
boolean structs = getGenerateStructures();
WorldType type = WorldType.getByName(getWorldType());
if (type == null) {
type = WorldType.NORMAL;
}
long seed = new Random().nextLong();
if (!seedString.isEmpty()) {
try {
long parsed = Long.parseLong(seedString);
if (parsed != 0) {
seed = parsed;
}
} catch (NumberFormatException ex) {
seed = seedString.hashCode();
}
}
createWorld(WorldCreator.name(name).environment(Environment.NORMAL).seed(seed).type(type).generateStructures(structs));
if (getAllowNether()) {
checkTransfer(name, "_nether", Environment.NETHER);
createWorld(WorldCreator.name(name + "_nether").environment(Environment.NETHER).seed(seed).type(type).generateStructures(structs));
}
if (getAllowEnd()) {
checkTransfer(name, "_the_end", Environment.THE_END);
createWorld(WorldCreator.name(name + "_the_end").environment(Environment.THE_END).seed(seed).type(type).generateStructures(structs));
}
// Finish loading plugins
enablePlugins(PluginLoadOrder.POSTWORLD);
commandMap.registerServerAliases();
scheduler.start();
}
Aggregations