Search in sources :

Example 6 with GPUContext

use of org.apache.sysml.runtime.instructions.gpu.context.GPUContext in project incubator-systemml by apache.

the class ScriptExecutorUtils method executeRuntimeProgram.

/**
	 * Execute the runtime program. This involves execution of the program
	 * blocks that make up the runtime program and may involve dynamic
	 * recompilation.
	 * 
	 * @param rtprog
	 *            runtime program
	 * @param ec
	 *            execution context
	 * @param dmlconf
	 *            dml configuration
	 * @param statisticsMaxHeavyHitters
	 *            maximum number of statistics to print
	 * @throws DMLRuntimeException
	 *             if error occurs
	 */
public static void executeRuntimeProgram(Program rtprog, ExecutionContext ec, DMLConfig dmlconf, int statisticsMaxHeavyHitters) throws DMLRuntimeException {
    // Whether extra statistics useful for developers and others interested
    // in digging into performance problems are recorded and displayed
    GPUStatistics.DISPLAY_STATISTICS = dmlconf.getBooleanValue(DMLConfig.EXTRA_GPU_STATS);
    LibMatrixDNN.DISPLAY_STATISTICS = dmlconf.getBooleanValue(DMLConfig.EXTRA_DNN_STATS);
    // Sets the maximum number of GPUs per process, -1 for all available
    // GPUs
    GPUContextPool.PER_PROCESS_MAX_GPUS = dmlconf.getIntValue(DMLConfig.MAX_GPUS_PER_PROCESS);
    Statistics.startRunTimer();
    GPUContext gCtx = null;
    try {
        // run execute (w/ exception handling to ensure proper shutdown)
        if (DMLScript.USE_ACCELERATOR && ec != null) {
            gCtx = GPUContextPool.getFromPool();
            if (gCtx == null) {
                throw new DMLRuntimeException("GPU : Could not create GPUContext, either no GPU or all GPUs currently in use");
            }
            gCtx.initializeThread();
            ec.setGPUContext(gCtx);
        }
        rtprog.execute(ec);
    } finally {
        // ensure cleanup/shutdown
        if (DMLScript.USE_ACCELERATOR && ec.getGPUContext() != null) {
            ec.getGPUContext().clearTemporaryMemory();
            GPUContextPool.returnToPool(ec.getGPUContext());
        }
        if (dmlconf.getBooleanValue(DMLConfig.CODEGEN))
            SpoofCompiler.cleanupCodeGenerator();
        // display statistics (incl caching stats if enabled)
        Statistics.stopRunTimer();
        if (statisticsMaxHeavyHitters > 0)
            System.out.println(Statistics.display(statisticsMaxHeavyHitters));
        else
            System.out.println(Statistics.display());
    }
}
Also used : GPUContext(org.apache.sysml.runtime.instructions.gpu.context.GPUContext) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

GPUContext (org.apache.sysml.runtime.instructions.gpu.context.GPUContext)6 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)4 GPUObject (org.apache.sysml.runtime.instructions.gpu.context.GPUObject)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MutableBoolean (org.apache.commons.lang.mutable.MutableBoolean)2 ArrayList (java.util.ArrayList)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 LocalParWorker (org.apache.sysml.runtime.controlprogram.parfor.LocalParWorker)1 LocalTaskQueue (org.apache.sysml.runtime.controlprogram.parfor.LocalTaskQueue)1 Task (org.apache.sysml.runtime.controlprogram.parfor.Task)1 TaskPartitioner (org.apache.sysml.runtime.controlprogram.parfor.TaskPartitioner)1 Timing (org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)1 Pair (org.apache.sysml.runtime.matrix.data.Pair)1