use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidLoopHoist.
/**
* Assert the result for valid CLAW loop-hoist directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param inductions List of induction variables to be checked.
* @param interchange If true, the interchange clause is set.
* @param indexes Interchange indexes values.
* @param reshape If true, the reshape clause is set.
* @param infos Reshape clause values.
* @param targets Target clause values. Null if not set.
* @param fusion If true, the fusion clause is set.
* @param group Group clause value. Null if not set.
* @param collapse Collapse clause value. 0 if not set.
*/
private void analyzeValidLoopHoist(String raw, List<String> inductions, boolean interchange, List<String> indexes, boolean reshape, List<ClawReshapeInfo> infos, List<Target> targets, boolean fusion, String group, int collapse) {
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_HOIST, l.getDirective());
assertEquals(inductions.size(), l.getHoistInductionVars().size());
for (int i = 0; i < inductions.size(); ++i) {
assertEquals(inductions.get(i), l.getHoistInductionVars().get(i));
}
if (interchange) {
assertTrue(l.hasInterchangeClause());
} else {
assertFalse(l.hasInterchangeClause());
}
if (indexes != null) {
for (int i = 0; i < indexes.size(); ++i) {
assertEquals(indexes.get(i), l.getIndexes().get(i));
}
}
if (reshape) {
assertTrue(l.hasReshapeClause());
assertEquals(infos.size(), l.getReshapeClauseValues().size());
for (int i = 0; i < infos.size(); ++i) {
assertEquals(infos.get(i).getArrayName(), l.getReshapeClauseValues().get(i).getArrayName());
assertEquals(infos.get(i).getTargetDimension(), l.getReshapeClauseValues().get(i).getTargetDimension());
List<Integer> expected = infos.get(i).getKeptDimensions();
List<Integer> actual = l.getReshapeClauseValues().get(i).getKeptDimensions();
assertEquals(expected.size(), actual.size());
for (int j = 0; j < expected.size(); ++j) {
assertEquals(expected.get(j), actual.get(j));
}
}
} else {
assertFalse(l.hasReshapeClause());
}
assertTargets(l, targets);
assertEquals(fusion, l.hasFusionClause());
if (group != null) {
assertTrue(l.hasGroupClause());
assertEquals(group, l.getGroupValue());
} else {
assertFalse(l.hasGroupClause());
}
if (collapse > 0) {
assertTrue(l.hasCollapseClause());
assertEquals(collapse, l.getCollapseValue());
} else {
assertFalse(l.hasCollapseClause());
}
} catch (IllegalDirectiveException idex) {
System.err.print(idex.getMessage());
fail();
}
}
use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidArrayTransform.
/**
* Assert the result for valid CLAW array-transform directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param fusion Set to true if the extracted option should be present.
* @param fusionGroup Name of the group in the extracted fusion option.
* @param parallel Set to true if the extracted option should be present.
* @param acc String of acc clauses that should be present.
*/
private void analyzeValidArrayTransform(String raw, boolean fusion, String fusionGroup, boolean parallel, String acc, List<String> inducNames, 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.ARRAY_TRANSFORM, l.getDirective());
if (fusion) {
assertTrue(l.hasFusionClause());
assertEquals(fusionGroup, l.getGroupValue());
} else {
assertFalse(l.hasFusionClause());
assertNull(l.getGroupValue());
}
if (parallel) {
assertTrue(l.hasParallelClause());
} else {
assertFalse(l.hasParallelClause());
}
if (acc != null) {
assertTrue(l.hasAcceleratorClause());
assertEquals(acc, l.getAcceleratorClauses());
} else {
assertFalse(l.hasAcceleratorClause());
}
if (inducNames != null) {
assertTrue(l.hasInductionClause());
assertEquals(inducNames.size(), l.getInductionValues().size());
for (int i = 0; i < inducNames.size(); ++i) {
assertEquals(inducNames.get(i), l.getInductionValues().get(i));
}
} else {
assertFalse(l.hasInductionClause());
}
assertTargets(l, targets);
} catch (IllegalDirectiveException idex) {
System.err.print(idex.getMessage());
fail();
}
}
use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeErrors.
private void analyzeErrors(String pragma, int nbExpectedToken) {
Xnode p = XmlHelper.createXpragma();
p.setValue(pragma);
p.setLine(1);
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
try {
ClawLanguage.analyze(p, generator, Target.GPU);
} catch (IllegalDirectiveException e) {
if (nbExpectedToken != 0) {
assertEquals(nbExpectedToken, e.getExpectedTokens().size());
}
assertNotNull(e.getMessage());
}
}
use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidKcache.
/**
* Assert the result for valid CLAW kcache directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param data List of identifiers to be checked.
* @param offsets List of offsets to be checked.
* @param init If true, check that ClawLanguage object has init clause
* enabled.
*/
private void analyzeValidKcache(String raw, List<String> data, List<Integer> offsets, boolean init, boolean hasPrivate, 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.KCACHE, l.getDirective());
if (data != null) {
assertTrue(l.hasDataClause());
assertEquals(data.size(), l.getDataClauseValues().size());
for (int i = 0; i < data.size(); ++i) {
assertEquals(data.get(i), l.getDataClauseValues().get(i));
}
} else {
assertFalse(l.hasDataClause());
}
if (offsets != null) {
assertEquals(offsets.size(), l.getOffsets().size());
for (int i = 0; i < offsets.size(); ++i) {
assertEquals(offsets.get(i), l.getOffsets().get(i));
}
}
if (init) {
assertTrue(l.hasInitClause());
} else {
assertFalse(l.hasInitClause());
}
if (hasPrivate) {
assertTrue(l.hasPrivateClause());
} else {
assertFalse(l.hasPrivateClause());
}
assertTargets(l, targets);
} catch (IllegalDirectiveException idex) {
System.err.print(idex.getMessage());
fail();
}
}
use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidClawLoopFusion.
/**
* Assert the result for valid loop fusion CLAW directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param groupName Group name to be found if any.
*/
private void analyzeValidClawLoopFusion(String raw, String groupName, boolean collapse, int n, List<Target> targets, ClawConstraint constraint) {
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_FUSION, l.getDirective());
if (groupName != null) {
assertTrue(l.hasGroupClause());
assertEquals(groupName, l.getGroupValue());
} else {
assertFalse(l.hasGroupClause());
assertNull(l.getGroupValue());
}
if (collapse) {
assertTrue(l.hasCollapseClause());
assertEquals(n, l.getCollapseValue());
} else {
assertFalse(l.hasCollapseClause());
}
if (constraint != null) {
assertTrue(l.hasConstraintClause());
assertEquals(constraint, l.getConstraintClauseValue());
} else {
assertFalse(l.hasConstraintClause());
}
assertTargets(l, targets);
} catch (IllegalDirectiveException idex) {
fail();
}
}
Aggregations