use of claw.tatsu.directive.configuration.AcceleratorConfiguration 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.directive.configuration.AcceleratorConfiguration in project claw-compiler by C2SM-RCM.
the class Configuration method init.
/**
* Constructs basic configuration object.
*
* @param directive Accelerator directive language.
* @param target Target architecture.
*/
public void init(CompilerDirective directive, Target target) {
_parameters = new HashMap<>();
if (directive == null) {
directive = CompilerDirective.NONE;
}
_parameters.put(DEFAULT_DIRECTIVE, directive.toString());
if (target != null) {
_parameters.put(DEFAULT_TARGET, target.toString());
}
// Init specific configuration if needed
switch(directive) {
case OPENACC:
_accelerator = new OpenAccConfiguration(_parameters);
break;
case OPENMP:
_accelerator = new OpenMpConfiguration(_parameters);
break;
default:
_accelerator = new AcceleratorConfiguration(_parameters);
break;
}
_groups = new ArrayList<>();
_availableGroups = new HashMap<>();
}
Aggregations