use of claw.tatsu.xcodeml.abstraction.Xblock in project claw-compiler by C2SM-RCM.
the class ScaGPU method applySpecificTransformation.
/**
* Apply specific transformation steps for GPU target.
*
* @param xcodeml Current translation unit.
* @throws IllegalTransformationException If any transformation fails.
*/
private void applySpecificTransformation(Configuration cfg, XcodeProgram xcodeml) throws IllegalTransformationException {
final Context context = xcodeml.context();
AcceleratorConfiguration config = cfg.accelerator();
if (_fctDef.hasEmptyBody()) {
// Nothing to do in this function
return;
}
/*
* Create a nested loop with the new defined dimensions and wrap it around the
* whole subroutine's body. This is for the moment a really naive transformation
* idea but it is our start point. Use the first over clause to create it.
*/
NestedDoStatement loops;
if (forceAssumedShapedArrayPromotion) {
if (_promotions.isEmpty()) {
throw new IllegalTransformationException("Cannot assume shape of " + "array in elemental function/subroutine.", _claw.getPragma().lineNo());
}
PromotionInfo pi = _promotions.entrySet().iterator().next().getValue();
loops = new NestedDoStatement(_claw.getDefaultLayoutReversed(cfg), pi, xcodeml);
} else {
loops = new NestedDoStatement(_claw.getDefaultLayoutReversed(cfg), xcodeml);
}
/*
* Subroutine/function can have a contains section with inner subroutines or
* functions. The newly created (nested) do statements should stop before this
* contains section if it exists.
*/
Xnode contains = _fctDef.body().matchSeq(Xcode.F_CONTAINS_STATEMENT);
if (contains != null) {
Xnode parallelRegionStart;
if (_specialParallelRegionStart == null) {
parallelRegionStart = Directive.findParallelRegionStart(context, _fctDef, null);
} else {
parallelRegionStart = _specialParallelRegionStart;
}
Xnode parallelRegionEnd = Directive.findParallelRegionEnd(context, _fctDef, contains);
Body.shiftIn(parallelRegionStart, parallelRegionEnd, loops.getInnerStatement().body(), true);
contains.insertBefore(loops.getOuterStatement());
} else {
// No contains section, all the body is copied to the do statements.
Xnode parallelRegionStart;
if (_specialParallelRegionStart == null) {
parallelRegionStart = Directive.findParallelRegionStart(context, _fctDef, null);
} else {
parallelRegionStart = _specialParallelRegionStart;
}
Xnode parallelRegionEnd = Directive.findParallelRegionEnd(context, _fctDef, null);
// Define a hook from where we can insert the new do statement
Xnode hook = parallelRegionEnd != null ? parallelRegionEnd.nextSibling() : null;
Body.shiftIn(parallelRegionStart, parallelRegionEnd, loops.getInnerStatement().body(), true);
// Hook is null then we append the do statement to the current fct body
if (hook == null) {
_fctDef.body().append(loops.getOuterStatement());
} else {
// Insert new do statement before the hook element
hook.insertBefore(loops.getOuterStatement());
}
}
// TODO nodep passing!
int collapse = Directive.generateLoopSeq(xcodeml, loops.getInnerStatement().body(), CompilerDirective.CLAW.getPrefix() + " nodep");
// Prepare variables list for present/pcreate clauses and handle
// promotion/privatize local strategy
List<String> presentList = _fctDef.getPresentVariables(xcodeml);
List<String> privateList = Collections.emptyList();
List<String> createList = Collections.emptyList();
if (config.getLocalStrategy() == AcceleratorLocalStrategy.PRIVATE) {
privateList = applyPrivateStrategy(xcodeml);
} else if (config.getLocalStrategy() == AcceleratorLocalStrategy.PROMOTE) {
createList = applyPromoteStrategy(cfg, xcodeml);
}
// Generate the data region
Xblock doStmtBlock = new Xblock(loops.getOuterStatement());
Directive.generateDataRegionClause(xcodeml, presentList, createList, doStmtBlock);
// Generate the parallel region
Directive.generateParallelLoopClause(xcodeml, privateList, loops.getOuterStatement(), loops.getOuterStatement(), null, loops.size() + collapse);
Directive.generateRoutineDirectives(xcodeml, _fctDef);
}
use of claw.tatsu.xcodeml.abstraction.Xblock in project claw-compiler by C2SM-RCM.
the class Directive method generateParallelLoopClause.
/**
* Generate directive directive for a parallel loop.
*
* @param xcodeml Object representation of the current XcodeML representation
* in which the pragmas will be generated.
* @param privates List of variables to be set privates.
* @param startStmt Start statement representing the beginning of the parallel
* region.
* @param endStmt End statement representing the end of the parallel region.
* @param collapse If value bigger than 0, a corresponding collapse constructs
* can be generated.
* @return Block with start and end directive if generated.
*/
public static Xblock generateParallelLoopClause(XcodeProgram xcodeml, List<String> privates, Xnode startStmt, Xnode endStmt, String extraDirective, int collapse) {
if (xcodeml.context().getGenerator().getDirectiveLanguage() == CompilerDirective.NONE) {
return null;
}
DirectiveGenerator dg = xcodeml.context().getGenerator();
Xnode startBlock = addPragmasBefore(xcodeml, dg.getStartParallelDirective(null), startStmt);
addPragmasBefore(xcodeml, dg.getStartLoopDirective(collapse, false, false, format(dg.getPrivateClause(privates), extraDirective)), startStmt);
Xnode endBlock = addPragmaAfter(xcodeml, dg.getEndParallelDirective(), endStmt);
addPragmaAfter(xcodeml, dg.getEndLoopDirective(), endStmt);
return new Xblock(startBlock, endBlock);
}
use of claw.tatsu.xcodeml.abstraction.Xblock in project claw-compiler by C2SM-RCM.
the class Directive method insertPragmas.
/**
* Generate corresponding pragmas to surround the code with a parallel
* accelerated region.
*
* @param xcodeml Current XcodeML program unit. representation in which
* the pragmas will be generated.
* @param hook Hook node to insert pragmas around.
* @param startDirective String value of the start directive.
* @param endDirective String value of the end directive.
* @return Last stmt inserted or null if nothing is inserted.
*/
private static Xblock insertPragmas(XcodeProgram xcodeml, Xblock hook, String[] startDirective, String[] endDirective) {
if (xcodeml.context().getGenerator().getDirectiveLanguage() == CompilerDirective.NONE) {
return null;
}
Xnode begin = addPragmasBefore(xcodeml, startDirective, hook.getStart());
Xnode end = addPragmaAfter(xcodeml, endDirective, hook.getEnd());
return new Xblock(begin, end);
}
Aggregations