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());
}
}
Aggregations