Search in sources :

Example 1 with CompilerConfig

use of org.apache.sysml.conf.CompilerConfig in project incubator-systemml by apache.

the class OptimizerUtils method constructCompilerConfig.

public static CompilerConfig constructCompilerConfig(DMLConfig dmlconf) throws DMLRuntimeException {
    //create default compiler configuration
    CompilerConfig cconf = new CompilerConfig();
    //each script sets its own block size, opt level etc
    cconf.set(ConfigType.BLOCK_SIZE, dmlconf.getIntValue(DMLConfig.DEFAULT_BLOCK_SIZE));
    //handle optimization level
    int optlevel = dmlconf.getIntValue(DMLConfig.OPTIMIZATION_LEVEL);
    if (optlevel < 0 || optlevel > 7)
        throw new DMLRuntimeException("Error: invalid optimization level '" + optlevel + "' (valid values: 0-5).");
    // edit config file everytime he/she is trying to call the debugger.
    if (DMLScript.ENABLE_DEBUG_MODE) {
        optlevel = 5;
    }
    switch(optlevel) {
        // opt level 0: static dimensionality
        case 0:
            cconf.set(ConfigType.OPT_LEVEL, OptimizationLevel.O0_LOCAL_STATIC.ordinal());
            ALLOW_CONSTANT_FOLDING = false;
            ALLOW_COMMON_SUBEXPRESSION_ELIMINATION = false;
            ALLOW_ALGEBRAIC_SIMPLIFICATION = false;
            ALLOW_AUTO_VECTORIZATION = false;
            ALLOW_INTER_PROCEDURAL_ANALYSIS = false;
            ALLOW_IPA_SECOND_CHANCE = false;
            ALLOW_BRANCH_REMOVAL = false;
            ALLOW_SUM_PRODUCT_REWRITES = false;
            break;
        // opt level 1: memory-based (no advanced rewrites)	
        case 1:
            cconf.set(ConfigType.OPT_LEVEL, OptimizationLevel.O1_LOCAL_MEMORY_MIN.ordinal());
            ALLOW_CONSTANT_FOLDING = false;
            ALLOW_COMMON_SUBEXPRESSION_ELIMINATION = false;
            ALLOW_ALGEBRAIC_SIMPLIFICATION = false;
            ALLOW_AUTO_VECTORIZATION = false;
            ALLOW_INTER_PROCEDURAL_ANALYSIS = false;
            ALLOW_IPA_SECOND_CHANCE = false;
            ALLOW_BRANCH_REMOVAL = false;
            ALLOW_SUM_PRODUCT_REWRITES = false;
            ALLOW_LOOP_UPDATE_IN_PLACE = false;
            break;
        // opt level 2: memory-based (all advanced rewrites)
        case 2:
            cconf.set(ConfigType.OPT_LEVEL, OptimizationLevel.O2_LOCAL_MEMORY_DEFAULT.ordinal());
            break;
        // opt level 3: resource optimization, time- and memory-based (2 w/ resource optimizat)
        case 3:
            cconf.set(ConfigType.OPT_LEVEL, OptimizationLevel.O3_LOCAL_RESOURCE_TIME_MEMORY.ordinal());
            break;
        // opt level 3: global, time- and memory-based (all advanced rewrites)
        case 4:
            cconf.set(ConfigType.OPT_LEVEL, OptimizationLevel.O4_GLOBAL_TIME_MEMORY.ordinal());
            break;
        // opt level 4: debug mode (no interfering rewrites)
        case 5:
            cconf.set(ConfigType.OPT_LEVEL, OptimizationLevel.O5_DEBUG_MODE.ordinal());
            ALLOW_CONSTANT_FOLDING = false;
            ALLOW_COMMON_SUBEXPRESSION_ELIMINATION = false;
            ALLOW_ALGEBRAIC_SIMPLIFICATION = false;
            ALLOW_INTER_PROCEDURAL_ANALYSIS = false;
            ALLOW_BRANCH_REMOVAL = false;
            ALLOW_SIZE_EXPRESSION_EVALUATION = false;
            ALLOW_WORSTCASE_SIZE_EXPRESSION_EVALUATION = false;
            ALLOW_RAND_JOB_RECOMPILE = false;
            ALLOW_SUM_PRODUCT_REWRITES = false;
            ALLOW_SPLIT_HOP_DAGS = false;
            cconf.set(ConfigType.ALLOW_DYN_RECOMPILATION, false);
            cconf.set(ConfigType.ALLOW_INDIVIDUAL_SB_SPECIFIC_OPS, false);
            break;
        // be removed once SPOOF is production ready)	
        case 6:
            cconf.set(ConfigType.OPT_LEVEL, OptimizationLevel.O2_LOCAL_MEMORY_DEFAULT.ordinal());
            ALLOW_AUTO_VECTORIZATION = false;
            break;
        case 7:
            cconf.set(ConfigType.OPT_LEVEL, OptimizationLevel.O2_LOCAL_MEMORY_DEFAULT.ordinal());
            ALLOW_OPERATOR_FUSION = false;
            ALLOW_AUTO_VECTORIZATION = false;
            ALLOW_SUM_PRODUCT_REWRITES = false;
            break;
    }
    //handle parallel text io (incl awareness of thread contention in <jdk8)
    if (!dmlconf.getBooleanValue(DMLConfig.CP_PARALLEL_TEXTIO)) {
        cconf.set(ConfigType.PARALLEL_CP_READ_TEXTFORMATS, false);
        cconf.set(ConfigType.PARALLEL_CP_WRITE_TEXTFORMATS, false);
        cconf.set(ConfigType.PARALLEL_CP_READ_BINARYFORMATS, false);
        cconf.set(ConfigType.PARALLEL_CP_WRITE_BINARYFORMATS, false);
    } else if (InfrastructureAnalyzer.isJavaVersionLessThanJDK8() && InfrastructureAnalyzer.getLocalParallelism() > 1) {
        LOG.warn("Auto-disable multi-threaded text read for 'text' and 'csv' due to thread contention on JRE < 1.8" + " (java.version=" + System.getProperty("java.version") + ").");
        cconf.set(ConfigType.PARALLEL_CP_READ_TEXTFORMATS, false);
    }
    //handle parallel matrix mult / rand configuration
    if (!dmlconf.getBooleanValue(DMLConfig.CP_PARALLEL_MATRIXMULT)) {
        cconf.set(ConfigType.PARALLEL_CP_MATRIX_OPERATIONS, false);
    }
    return cconf;
}
Also used : CompilerConfig(org.apache.sysml.conf.CompilerConfig) Checkpoint(org.apache.sysml.lops.Checkpoint) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 2 with CompilerConfig

use of org.apache.sysml.conf.CompilerConfig in project incubator-systemml by apache.

the class PreparedScript method enableFunctionRecompile.

/**
 * Enables function recompilation, selectively for the given functions.
 * If dynamic recompilation is globally enabled this has no additional
 * effect; otherwise the given functions are dynamically recompiled once
 * on every entry but not at the granularity of individually last-level
 * program blocks. Use this fine-grained recompilation option for important
 * functions in small-data scenarios where dynamic recompilation overheads
 * might not be amortized.
 *
 * @param fnamespace function namespace, null for default namespace
 * @param fnames function name
 */
public void enableFunctionRecompile(String fnamespace, String... fnames) {
    // handle default name space
    if (fnamespace == null)
        fnamespace = DMLProgram.DEFAULT_NAMESPACE;
    // enable dynamic recompilation (note that this does not globally enable
    // dynamic recompilation because the program has been compiled already)
    CompilerConfig cconf = ConfigurationManager.getCompilerConfig();
    cconf.set(ConfigType.ALLOW_DYN_RECOMPILATION, true);
    ConfigurationManager.setLocalConfig(cconf);
    // build function call graph (to probe for recursive functions)
    FunctionCallGraph fgraph = _prog.getProgramBlocks().isEmpty() ? null : new FunctionCallGraph(_prog.getProgramBlocks().get(0).getStatementBlock().getDMLProg());
    // enable requested functions for recompile once
    for (String fname : fnames) {
        String fkey = DMLProgram.constructFunctionKey(fnamespace, fname);
        if (fgraph != null && !fgraph.isRecursiveFunction(fkey)) {
            FunctionProgramBlock fpb = _prog.getFunctionProgramBlock(fnamespace, fname);
            if (fpb != null)
                fpb.setRecompileOnce(true);
            else
                LOG.warn("Failed to enable function recompile for non-existing '" + fkey + "'.");
        } else if (fgraph != null) {
            LOG.warn("Failed to enable function recompile for recursive '" + fkey + "'.");
        }
    }
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) FunctionCallGraph(org.apache.sysml.hops.ipa.FunctionCallGraph) CompilerConfig(org.apache.sysml.conf.CompilerConfig)

Example 3 with CompilerConfig

use of org.apache.sysml.conf.CompilerConfig in project incubator-systemml by apache.

the class MLContextUtil method setCompilerConfig.

/**
 * Set SystemML compiler configuration properties for MLContext
 */
public static void setCompilerConfig() {
    CompilerConfig compilerConfig = new CompilerConfig();
    compilerConfig.set(ConfigType.IGNORE_UNSPECIFIED_ARGS, true);
    compilerConfig.set(ConfigType.REJECT_READ_WRITE_UNKNOWNS, false);
    compilerConfig.set(ConfigType.ALLOW_CSE_PERSISTENT_READS, false);
    compilerConfig.set(ConfigType.MLCONTEXT, true);
    ConfigurationManager.setGlobalConfig(compilerConfig);
}
Also used : CompilerConfig(org.apache.sysml.conf.CompilerConfig)

Example 4 with CompilerConfig

use of org.apache.sysml.conf.CompilerConfig in project incubator-systemml by apache.

the class ProgramConverter method parseParForBody.

// //////////////////////////////
// PARSING
// //////////////////////////////
public static ParForBody parseParForBody(String in, int id) {
    ParForBody body = new ParForBody();
    // header elimination
    // normalization
    String tmpin = in.replaceAll(NEWLINE, "");
    // remove start/end
    tmpin = tmpin.substring(PARFORBODY_BEGIN.length(), tmpin.length() - PARFORBODY_END.length());
    HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(tmpin, COMPONENTS_DELIM);
    // handle DMLScript UUID (NOTE: set directly in DMLScript)
    // (master UUID is used for all nodes (in order to simply cleanup))
    DMLScript.setUUID(st.nextToken());
    // handle DML config (NOTE: set directly in ConfigurationManager)
    String confStr = st.nextToken();
    JobConf job = ConfigurationManager.getCachedJobConf();
    if (!InfrastructureAnalyzer.isLocalMode(job)) {
        if (confStr != null && !confStr.trim().isEmpty()) {
            DMLConfig dmlconf = DMLConfig.parseDMLConfig(confStr);
            CompilerConfig cconf = OptimizerUtils.constructCompilerConfig(dmlconf);
            ConfigurationManager.setLocalConfig(dmlconf);
            ConfigurationManager.setLocalConfig(cconf);
        }
        // init internal configuration w/ parsed or default config
        ParForProgramBlock.initInternalConfigurations(ConfigurationManager.getDMLConfig());
    }
    // handle additional configs
    String aconfs = st.nextToken();
    parseAndSetAdditionalConfigurations(aconfs);
    // handle program
    String progStr = st.nextToken();
    Program prog = parseProgram(progStr, id);
    // handle result variable names
    String rvarStr = st.nextToken();
    ArrayList<ResultVar> rvars = parseResultVariables(rvarStr);
    body.setResultVariables(rvars);
    // handle execution context
    String ecStr = st.nextToken();
    ExecutionContext ec = parseExecutionContext(ecStr, prog);
    // handle program blocks
    String spbs = st.nextToken();
    ArrayList<ProgramBlock> pbs = rParseProgramBlocks(spbs, prog, id);
    body.setChildBlocks(pbs);
    body.setEc(ec);
    return body;
}
Also used : DMLConfig(org.apache.sysml.conf.DMLConfig) DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) ResultVar(org.apache.sysml.parser.ParForStatementBlock.ResultVar) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) JobConf(org.apache.hadoop.mapred.JobConf) CompilerConfig(org.apache.sysml.conf.CompilerConfig)

Example 5 with CompilerConfig

use of org.apache.sysml.conf.CompilerConfig in project incubator-systemml by apache.

the class ParForProgramBlock method createParallelWorker.

/**
 * Creates a new or partially recycled instance of a parallel worker. Therefore the symbol table, and child
 * program blocks are deep copied. Note that entries of the symbol table are not deep copied because they are replaced
 * anyway on the next write. In case of recycling the deep copies of program blocks are recycled from previous
 * executions of this parfor.
 *
 * @param pwID parworker id
 * @param queue task queue
 * @param ec execution context
 * @param index the index of the worker
 * @return local parworker
 */
private LocalParWorker createParallelWorker(long pwID, LocalTaskQueue<Task> queue, ExecutionContext ec, int index) {
    LocalParWorker pw = null;
    try {
        // create deep copies of required elements child blocks
        ArrayList<ProgramBlock> cpChildBlocks = null;
        HashSet<String> fnNames = new HashSet<>();
        if (USE_PB_CACHE) {
            if (_pbcache.containsKey(pwID)) {
                cpChildBlocks = _pbcache.get(pwID);
            } else {
                cpChildBlocks = ProgramConverter.rcreateDeepCopyProgramBlocks(_childBlocks, pwID, _IDPrefix, new HashSet<String>(), fnNames, false, false);
                _pbcache.put(pwID, cpChildBlocks);
            }
        } else {
            cpChildBlocks = ProgramConverter.rcreateDeepCopyProgramBlocks(_childBlocks, pwID, _IDPrefix, new HashSet<String>(), fnNames, false, false);
        }
        // deep copy execution context (including prepare parfor update-in-place)
        ExecutionContext cpEc = ProgramConverter.createDeepCopyExecutionContext(ec);
        // and sets it in the ExecutionContext of the parfor
        if (DMLScript.USE_ACCELERATOR) {
            cpEc.setGPUContexts(Arrays.asList(ec.getGPUContext(index)));
        }
        // prepare basic update-in-place variables (vars dropped on result merge)
        prepareUpdateInPlaceVariables(cpEc, pwID);
        // copy compiler configuration (for jmlc w/o global config)
        CompilerConfig cconf = ConfigurationManager.getCompilerConfig();
        // create the actual parallel worker
        ParForBody body = new ParForBody(cpChildBlocks, _resultVars, cpEc);
        pw = new LocalParWorker(pwID, queue, body, cconf, MAX_RETRYS_ON_ERROR, _monitor);
        pw.setFunctionNames(fnNames);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return pw;
}
Also used : ParForBody(org.apache.sysml.runtime.controlprogram.parfor.ParForBody) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) LocalParWorker(org.apache.sysml.runtime.controlprogram.parfor.LocalParWorker) CompilerConfig(org.apache.sysml.conf.CompilerConfig) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

CompilerConfig (org.apache.sysml.conf.CompilerConfig)18 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)8 ExecutionContext (org.apache.sysml.runtime.controlprogram.context.ExecutionContext)7 IOException (java.io.IOException)5 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)5 DMLConfig (org.apache.sysml.conf.DMLConfig)4 DMLProgram (org.apache.sysml.parser.DMLProgram)4 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)4 Program (org.apache.sysml.runtime.controlprogram.Program)4 HashSet (java.util.HashSet)3 LocalParWorker (org.apache.sysml.runtime.controlprogram.parfor.LocalParWorker)3 ParForBody (org.apache.sysml.runtime.controlprogram.parfor.ParForBody)3 JobConf (org.apache.hadoop.mapred.JobConf)2 FunctionCallGraph (org.apache.sysml.hops.ipa.FunctionCallGraph)2 DMLTranslator (org.apache.sysml.parser.DMLTranslator)2 ResultVar (org.apache.sysml.parser.ParForStatementBlock.ResultVar)2 ParserWrapper (org.apache.sysml.parser.ParserWrapper)2 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)2 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)2 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)2