private NativeOpsHolder() { try { Properties props = Nd4jContext.getInstance().getConf(); String name = System.getProperty(Nd4j.NATIVE_OPS, props.get(Nd4j.NATIVE_OPS).toString()); Class<? extends NativeOps> nativeOpsClazz = Class.forName(name).asSubclass(NativeOps.class); deviceNativeOps = nativeOpsClazz.newInstance(); deviceNativeOps.initializeDevicesAndFunctions(); int numThreads; String numThreadsString = System.getenv("OMP_NUM_THREADS"); if (numThreadsString != null && !numThreadsString.isEmpty()) { numThreads = Integer.parseInt(numThreadsString); deviceNativeOps.setOmpNumThreads(numThreads); } else { int cores = Loader.totalCores(); int chips = Loader.totalChips(); if (chips > 0 && cores > 0) { deviceNativeOps.setOmpNumThreads(Math.max(1, cores / chips)); } else deviceNativeOps.setOmpNumThreads( deviceNativeOps.getCores(Runtime.getRuntime().availableProcessors())); } //deviceNativeOps.setOmpNumThreads(4); log.info("Number of threads used for NativeOps: {}", deviceNativeOps.ompGetMaxThreads()); } catch (Exception | Error e) { throw new RuntimeException( "ND4J is probably missing dependencies. For more information, please refer to: http://nd4j.org/getstarted.html", e); } }
private NativeOpsHolder() { try { Properties props = Nd4jContext.getInstance().getConf(); String name = System.getProperty(Nd4j.NATIVE_OPS, props.get(Nd4j.NATIVE_OPS).toString()); Class<? extends NativeOps> nativeOpsClazz = Class.forName(name).asSubclass(NativeOps.class); deviceNativeOps = nativeOpsClazz.newInstance(); deviceNativeOps.initializeDevicesAndFunctions(); int numThreads; String numThreadsString = System.getenv("OMP_NUM_THREADS"); if (numThreadsString != null && !numThreadsString.isEmpty()) { numThreads = Integer.parseInt(numThreadsString); deviceNativeOps.setOmpNumThreads(numThreads); } else { int cores = Loader.totalCores(); int chips = Loader.totalChips(); if (chips > 0 && cores > 0) { deviceNativeOps.setOmpNumThreads(Math.max(1, cores / chips)); } else deviceNativeOps.setOmpNumThreads( deviceNativeOps.getCores(Runtime.getRuntime().availableProcessors())); } //deviceNativeOps.setOmpNumThreads(4); log.info("Number of threads used for NativeOps: {}", deviceNativeOps.ompGetMaxThreads()); } catch (Exception | Error e) { throw new RuntimeException( "ND4J is probably missing dependencies. For more information, please refer to: http://nd4j.org/getstarted.html", e); } }