use of cx2x.translator.language.base.ClawLanguage in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidClawLoopExtract.
/**
* Assert the result for valid loop extract CLAW directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param induction Induction var to be found.
* @param lower Lower bound value to be found.
* @param upper Upper bound value to be found.
* @param step Step valu to be found if any.
*/
private ClawLanguage analyzeValidClawLoopExtract(String raw, String induction, String lower, String upper, String step, List<Target> targets) {
try {
Xnode p = XmlHelper.createXpragma();
p.setValue(raw);
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
ClawLanguage l = ClawLanguage.analyze(p, generator, Target.GPU);
assertEquals(ClawDirective.LOOP_EXTRACT, l.getDirective());
assertEquals(induction, l.getRange().getInductionVar());
assertEquals(lower, l.getRange().getLowerBound());
assertEquals(upper, l.getRange().getUpperBound());
if (step != null) {
assertEquals(step, l.getRange().getStep());
}
assertTargets(l, targets);
return l;
} catch (IllegalDirectiveException idex) {
System.err.println(idex.getMessage());
fail();
return null;
}
}
use of cx2x.translator.language.base.ClawLanguage in project claw-compiler by C2SM-RCM.
the class ClawXcodeMlTranslator method analyze.
/**
* Analysis the XcodeML code and produce a list of applicable transformation.
*/
public void analyze() {
_program = XcodeProgram.createFromFile(_xcodemlInputFile);
if (_program == null) {
abort();
}
// Check all pragma found in the program
for (Xnode pragma : _program.getAllStmt(Xcode.FPRAGMASTATEMENT)) {
// pragma does not start with the CLAW prefix
if (!ClawLanguage.startsWithClaw(pragma)) {
// Compile guard removal
if (_generator != null && _generator.isCompileGuard(pragma.value())) {
pragma.delete();
} else // Handle special transformation of OpenACC line continuation
if (pragma.value().toLowerCase().startsWith(ClawConstant.OPENACC_PREFIX)) {
OpenAccContinuation t = new OpenAccContinuation(new AnalyzedPragma(pragma));
addOrAbort(t);
}
// Not CLAW pragma, we do nothing
continue;
}
try {
// Analyze the raw pragma with the CLAW language parser
ClawLanguage analyzedPragma = ClawLanguage.analyze(pragma, _generator, _target);
// Create transformation object based on the directive
switch(analyzedPragma.getDirective()) {
case ARRAY_TO_CALL:
addOrAbort(new ArrayToFctCall(analyzedPragma));
break;
case KCACHE:
addOrAbort(new Kcaching(analyzedPragma));
break;
case LOOP_FUSION:
addOrAbort(new LoopFusion(analyzedPragma));
break;
case LOOP_INTERCHANGE:
addOrAbort(new LoopInterchange(analyzedPragma));
break;
case LOOP_EXTRACT:
addOrAbort(new LoopExtraction(analyzedPragma));
break;
case LOOP_HOIST:
HandleBlockDirective(analyzedPragma);
break;
case ARRAY_TRANSFORM:
HandleBlockDirective(analyzedPragma);
break;
case REMOVE:
HandleBlockDirective(analyzedPragma);
break;
case PARALLELIZE:
if (analyzedPragma.hasForwardClause()) {
addOrAbort(new ParallelizeForward(analyzedPragma));
} else {
addOrAbort(new Parallelize(analyzedPragma));
}
break;
case PRIMITIVE:
addOrAbort(new DirectivePrimitive(analyzedPragma));
break;
case IF_EXTRACT:
addOrAbort(new IfExtract(analyzedPragma));
break;
// driver handled directives
case IGNORE:
case VERBATIM:
break;
default:
_program.addError("Unrecognized CLAW directive", pragma.lineNo());
abort();
}
} catch (IllegalDirectiveException ex) {
System.err.println(ex.getMessage());
abort();
}
}
// Clean up block transformation map
for (Map.Entry<ClawDirectiveKey, ClawLanguage> entry : _blockDirectives.entrySet()) {
createBlockDirectiveTransformation(entry.getValue(), null);
}
// Add utility transformation
addOrAbort(new XcodeMLWorkaround(new ClawLanguage(_program)));
// Analysis done, the transformation can be performed.
_canTransform = true;
}
use of cx2x.translator.language.base.ClawLanguage in project claw-compiler by C2SM-RCM.
the class IterationSpace method tryFusion.
/**
* Analyze the dependence information at each level and try to merge
* independent do statements.
*
* @param xcodeml Current XcodeML/F program unit.
* @param transformer Current transformer.
* @param master ClawLanguage that triggered this transformation.
* @throws Exception If the fusion fails.
*/
public void tryFusion(XcodeProgram xcodeml, Transformer transformer, ClawLanguage master) throws Exception {
for (int i = _levels.size() - 1; i >= 0; --i) {
List<DependenceAnalysis> loopsAtLevel = getLevel(i);
DependentTransformationGroup fusions = new DependentTransformationGroup("parallelize-fusion");
for (DependenceAnalysis dep : loopsAtLevel) {
if (dep.isIndependent()) {
ClawLanguage l = ClawLanguage.createLoopFusionLanguage(master);
LoopFusion fusion = new LoopFusion(dep.getDoStmt(), l);
fusions.add(fusion);
}
}
fusions.applyTranslations(xcodeml, transformer);
}
}
use of cx2x.translator.language.base.ClawLanguage in project claw-compiler by C2SM-RCM.
the class DependenceAnalysisTest method analyzeTest3d.
/**
* Test the IterationSpace feature of fusion and check the results.
*/
@Test
public void analyzeTest3d() {
// Load test data file
File f = new File(TestConstant.TEST_DEPENDENCE_3D);
assertTrue(f.exists());
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DEPENDENCE_3D);
assertNotNull(xcodeml);
// Match all the function definitions
List<Xnode> functions = xcodeml.matchAll(Xcode.FFUNCTIONDEFINITION);
assertEquals(2, functions.size());
// Match all the pragmas
List<Xnode> pragmas = xcodeml.matchAll(Xcode.FPRAGMASTATEMENT);
assertEquals(1, pragmas.size());
// Analyze the pragma
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
configuration.setMaxColumns(80);
ClawTransformer transformer = new ClawTransformer(configuration);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
ClawLanguage main = null;
try {
main = ClawLanguage.analyze(pragmas.get(0), generator, Target.GPU);
} catch (Exception e) {
fail();
}
// Get the function definition that interests us
Xnode fctDef = functions.get(0);
// Match all the do statements in the function
List<Xnode> loops = fctDef.matchAll(Xcode.FDOSTATEMENT);
assertEquals(11, loops.size());
// Create an iteration space
try {
IterationSpace is = new IterationSpace(loops);
is.tryFusion(xcodeml, transformer, main);
System.out.println();
System.out.println("Iteration space before fusion");
is.printDebug(true);
loops = fctDef.matchAll(Xcode.FDOSTATEMENT);
assertEquals(8, loops.size());
is.reload(loops);
System.out.println();
System.out.println("Iteration space after fusion");
is.printDebug(true);
} catch (Exception e) {
fail();
}
}
use of cx2x.translator.language.base.ClawLanguage in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidParallelize.
/**
* Assert the result for valid CLAW parallelize directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param data Reference list for the data clause values.
* @param over Reference list for the over clause values.
* @param dimensions Reference list of dimensions.
* @param copyClause Expected value for copy clause (Null if no copy clause)
* @param updateClause Expected value for update clause
* (Null if no update clause)
*/
private void analyzeValidParallelize(String raw, List<List<String>> data, List<List<String>> over, List<ClawDimension> dimensions, ClawDMD copyClause, ClawDMD updateClause) {
try {
Xnode p = XmlHelper.createXpragma();
p.setValue(raw);
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
ClawLanguage l = ClawLanguage.analyze(p, generator, Target.GPU);
assertEquals(ClawDirective.PARALLELIZE, l.getDirective());
if (data != null) {
assertTrue(l.hasOverDataClause());
assertEquals(data.size(), l.getOverDataClauseValues().size());
for (int i = 0; i < data.size(); ++i) {
assertEquals(data.get(i).size(), l.getOverDataClauseValues().get(i).size());
for (int j = 0; j < data.get(i).size(); ++j) {
assertEquals(data.get(i).get(j), l.getOverDataClauseValues().get(i).get(j));
}
}
}
if (over != null) {
assertTrue(l.hasOverClause());
assertEquals(over.size(), l.getOverClauseValues().size());
for (int i = 0; i < over.size(); ++i) {
assertEquals(over.get(i).size(), l.getOverClauseValues().get(i).size());
for (int j = 0; j < over.get(i).size(); ++j) {
assertEquals(over.get(i).get(j), l.getOverClauseValues().get(i).get(j));
}
}
}
if (dimensions != null) {
assertEquals(dimensions.size(), l.getDimensionValues().size());
for (int i = 0; i < dimensions.size(); ++i) {
assertEquals(dimensions.get(i).getIdentifier(), l.getDimensionValues().get(i).getIdentifier());
assertEquals(dimensions.get(i).lowerBoundIsVar(), l.getDimensionValues().get(i).lowerBoundIsVar());
assertEquals(dimensions.get(i).upperBoundIsVar(), l.getDimensionValues().get(i).upperBoundIsVar());
assertEquals(dimensions.get(i).getLowerBoundInt(), l.getDimensionValues().get(i).getLowerBoundInt());
assertEquals(dimensions.get(i).getUpperBoundInt(), l.getDimensionValues().get(i).getUpperBoundInt());
assertEquals(dimensions.get(i).getLowerBoundId(), l.getDimensionValues().get(i).getLowerBoundId());
assertEquals(dimensions.get(i).getUpperBoundId(), l.getDimensionValues().get(i).getUpperBoundId());
}
}
if (data == null && over == null && dimensions == null) {
assertTrue(l.hasForwardClause());
}
if (copyClause == null) {
assertFalse(l.hasCopyClause());
assertNull(l.getCopyClauseValue());
} else {
assertTrue(l.hasCopyClause());
assertEquals(copyClause, l.getCopyClauseValue());
}
if (updateClause == null) {
assertFalse(l.hasUpdateClause());
assertNull(l.getUpdateClauseValue());
} else {
assertTrue(l.hasUpdateClause());
assertEquals(updateClause, l.getUpdateClauseValue());
}
} catch (IllegalDirectiveException idex) {
System.err.print(idex.getMessage());
fail();
}
}
Aggregations