use of org.apache.sysml.conf.CompilerConfig in project 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;
}
use of org.apache.sysml.conf.CompilerConfig in project systemml by apache.
the class FrameReadWriteTest method runFrameReadWriteTest.
/**
* @param sparseM1
* @param sparseM2
* @param instType
*/
private void runFrameReadWriteTest(OutputInfo oinfo, ValueType[] schema1, ValueType[] schema2, boolean parallel) {
boolean oldParText = CompilerConfig.FLAG_PARREADWRITE_TEXT;
boolean oldParBin = CompilerConfig.FLAG_PARREADWRITE_BINARY;
try {
CompilerConfig.FLAG_PARREADWRITE_TEXT = parallel;
CompilerConfig.FLAG_PARREADWRITE_BINARY = parallel;
ConfigurationManager.setGlobalConfig(new CompilerConfig());
// data generation
double[][] A = getRandomMatrix(rows, schema1.length, -10, 10, 0.9, 2373);
double[][] B = getRandomMatrix(rows, schema2.length, -10, 10, 0.9, 129);
// Initialize the frame data.
// init data frame 1
FrameBlock frame1 = new FrameBlock(schema1);
initFrameData(frame1, A, schema1);
// init data frame 2
FrameBlock frame2 = new FrameBlock(schema2);
initFrameData(frame2, B, schema2);
// Write frame data to disk
CSVFileFormatProperties fprop = new CSVFileFormatProperties();
fprop.setDelim(DELIMITER);
fprop.setHeader(HEADER);
writeAndVerifyData(oinfo, frame1, frame2, fprop);
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
} finally {
CompilerConfig.FLAG_PARREADWRITE_TEXT = oldParText;
CompilerConfig.FLAG_PARREADWRITE_BINARY = oldParBin;
ConfigurationManager.setGlobalConfig(new CompilerConfig());
}
}
use of org.apache.sysml.conf.CompilerConfig in project 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 + "'.");
}
}
}
Aggregations