Java Code Examples for org.bytedeco.javacpp.Loader#totalCores()

The following examples show how to use org.bytedeco.javacpp.Loader#totalCores() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Nd4jBlas.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public Nd4jBlas() {
    int numThreads;
    String skipper = System.getenv("ND4J_SKIP_BLAS_THREADS");
    if (skipper == null || skipper.isEmpty()) {
        String numThreadsString = System.getenv("OMP_NUM_THREADS");
        if (numThreadsString != null && !numThreadsString.isEmpty()) {
            numThreads = Integer.parseInt(numThreadsString);
            setMaxThreads(numThreads);
        } else {
            int cores = Loader.totalCores();
            int chips = Loader.totalChips();
            if (cores > 0 && chips > 0)
                numThreads = Math.max(1, cores / chips);
            else
                numThreads = NativeOps.getCores(Runtime.getRuntime().availableProcessors());
            setMaxThreads(numThreads);
        }
        log.info("Number of threads used for BLAS: {}", getMaxThreads());
    }
}
 
Example 2
Source File: Nd4jBlas.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public Nd4jBlas() {
    int numThreads;
    String skipper = System.getenv(ND4JEnvironmentVars.ND4J_SKIP_BLAS_THREADS);
    if (skipper == null || skipper.isEmpty()) {
        String numThreadsString = System.getenv(ND4JEnvironmentVars.OMP_NUM_THREADS);
        if (numThreadsString != null && !numThreadsString.isEmpty()) {
            numThreads = Integer.parseInt(numThreadsString);
            setMaxThreads(numThreads);
        } else {
            int cores = Loader.totalCores();
            int chips = Loader.totalChips();
            if (cores > 0 && chips > 0)
                numThreads = Math.max(1, cores / chips);
            else
                numThreads = NativeOpsHolder.getCores(Runtime.getRuntime().availableProcessors());
            setMaxThreads(numThreads);
        }

        String logInit = System.getProperty(ND4JSystemProperties.LOG_INITIALIZATION);
        if(logOpenMPBlasThreads() && (logInit == null || logInit.isEmpty() || Boolean.parseBoolean(logInit))) {
            log.info("Number of threads used for OpenMP BLAS: {}", getMaxThreads());
        }
    }
}
 
Example 3
Source File: NativeOpsHolder.java    From nd4j with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 4
Source File: NativeOpsHolder.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
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(ND4JEnvironmentVars.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(
                                getCores(Runtime.getRuntime().availableProcessors()));
        }
        //deviceNativeOps.setOmpNumThreads(4);

        String logInitProperty = System.getProperty(ND4JSystemProperties.LOG_INITIALIZATION, "true");
        boolean logInit = Boolean.parseBoolean(logInitProperty);

        if(logInit) {
            log.info("Number of threads used for linear algebra: {}", deviceNativeOps.ompGetMaxThreads());
        }
    } catch (Exception | Error e) {
        throw new RuntimeException(
                        "ND4J is probably missing dependencies. For more information, please refer to: https://deeplearning4j.konduit.ai/nd4j/backend",
                        e);
    }
}