use of claw.wani.language.ClawPragma in project claw-compiler by C2SM-RCM.
the class ClawPragmaTest method extractTest.
/**
* Test various input for the CLAW loop extract directive.
*/
@Test
public void extractTest() {
// Valid directives
ClawPragma l = analyzeValidClawLoopExtract("claw loop-extract range(i=istart,iend) map(i:j)", "i", "istart", "iend", null, null);
assertNotNull(l);
assertEquals(1, l.getMappings().size());
assertNotNull(l.getMappings().get(0));
ClawMapping map = l.getMappings().get(0);
assertEquals(1, map.getMappedVariables().size());
assertEquals(1, map.getMappingVariables().size());
assertEquals("i", map.getMappedVariables().get(0).getArgMapping());
assertEquals("i", map.getMappedVariables().get(0).getFctMapping());
assertFalse(map.getMappedVariables().get(0).hasDifferentMapping());
assertEquals("j", map.getMappingVariables().get(0).getArgMapping());
assertEquals("j", map.getMappingVariables().get(0).getFctMapping());
assertFalse(map.getMappingVariables().get(0).hasDifferentMapping());
l = analyzeValidClawLoopExtract("claw loop-extract range(i=istart,iend,2) map(i:j)", "i", "istart", "iend", "2", null);
assertNotNull(l);
map = l.getMappings().get(0);
assertEquals(1, map.getMappedVariables().size());
assertEquals(1, map.getMappingVariables().size());
assertEquals("i", map.getMappedVariables().get(0).getArgMapping());
assertEquals("i", map.getMappedVariables().get(0).getFctMapping());
assertFalse(map.getMappedVariables().get(0).hasDifferentMapping());
assertEquals("j", map.getMappingVariables().get(0).getArgMapping());
assertEquals("j", map.getMappingVariables().get(0).getFctMapping());
assertFalse(map.getMappingVariables().get(0).hasDifferentMapping());
l = analyzeValidClawLoopExtract("claw loop-extract range(i=1,10) map(i:j)", "i", "1", "10", null, null);
assertNotNull(l);
map = l.getMappings().get(0);
assertEquals(1, map.getMappedVariables().size());
assertEquals(1, map.getMappingVariables().size());
assertEquals("i", map.getMappedVariables().get(0).getArgMapping());
assertEquals("i", map.getMappedVariables().get(0).getFctMapping());
assertFalse(map.getMappedVariables().get(0).hasDifferentMapping());
assertEquals("j", map.getMappingVariables().get(0).getArgMapping());
assertEquals("j", map.getMappingVariables().get(0).getFctMapping());
assertFalse(map.getMappingVariables().get(0).hasDifferentMapping());
l = analyzeValidClawLoopExtract("claw loop-extract range(i=1,10,2) map(i:j) parallel", "i", "1", "10", "2", null);
assertNotNull(l);
map = l.getMappings().get(0);
assertTrue(l.hasClause(ClawClause.PARALLEL));
assertEquals(1, map.getMappedVariables().size());
assertEquals(1, map.getMappingVariables().size());
assertEquals("i", map.getMappedVariables().get(0).getArgMapping());
assertEquals("i", map.getMappedVariables().get(0).getFctMapping());
assertFalse(map.getMappedVariables().get(0).hasDifferentMapping());
assertEquals("j", map.getMappingVariables().get(0).getArgMapping());
assertEquals("j", map.getMappingVariables().get(0).getFctMapping());
assertFalse(map.getMappingVariables().get(0).hasDifferentMapping());
l = analyzeValidClawLoopExtract("claw loop-extract range(i=istart,iend) map(i:j) fusion", "i", "istart", "iend", null, null);
assertNotNull(l);
assertEquals(1, l.getMappings().size());
assertNotNull(l.getMappings().get(0));
assertTrue(l.hasClause(ClawClause.FUSION));
assertFalse(l.hasClause(ClawClause.GROUP));
assertFalse(l.hasClause(ClawClause.PARALLEL));
map = l.getMappings().get(0);
assertEquals(1, map.getMappedVariables().size());
assertEquals(1, map.getMappingVariables().size());
assertEquals("i", map.getMappedVariables().get(0).getArgMapping());
assertEquals("i", map.getMappedVariables().get(0).getFctMapping());
assertFalse(map.getMappedVariables().get(0).hasDifferentMapping());
assertEquals("j", map.getMappingVariables().get(0).getArgMapping());
assertEquals("j", map.getMappingVariables().get(0).getFctMapping());
assertFalse(map.getMappingVariables().get(0).hasDifferentMapping());
l = analyzeValidClawLoopExtract("claw loop-extract range(i=istart,iend) map(i:j) fusion group(j1)", "i", "istart", "iend", null, null);
assertNotNull(l);
assertEquals(1, l.getMappings().size());
assertNotNull(l.getMappings().get(0));
assertTrue(l.hasClause(ClawClause.FUSION));
assertTrue(l.hasClause(ClawClause.GROUP));
assertEquals("j1", l.value(ClawClause.GROUP));
map = l.getMappings().get(0);
assertEquals(1, map.getMappedVariables().size());
assertEquals(1, map.getMappingVariables().size());
assertEquals("i", map.getMappedVariables().get(0).getArgMapping());
assertEquals("i", map.getMappedVariables().get(0).getFctMapping());
assertFalse(map.getMappedVariables().get(0).hasDifferentMapping());
assertEquals("j", map.getMappingVariables().get(0).getArgMapping());
assertEquals("j", map.getMappingVariables().get(0).getFctMapping());
assertFalse(map.getMappingVariables().get(0).hasDifferentMapping());
l = analyzeValidClawLoopExtract("claw loop-extract range(i=istart,iend) map(i:j) fusion group(j1) " + "acc(loop gang vector)", "i", "istart", "iend", null, null);
assertNotNull(l);
assertEquals(1, l.getMappings().size());
assertNotNull(l.getMappings().get(0));
assertTrue(l.hasClause(ClawClause.FUSION));
assertTrue(l.hasClause(ClawClause.GROUP));
assertTrue(l.hasClause(ClawClause.ACC));
assertEquals("loop gang vector", l.value(ClawClause.ACC));
assertEquals("j1", l.value(ClawClause.GROUP));
map = l.getMappings().get(0);
assertEquals(1, map.getMappedVariables().size());
assertEquals(1, map.getMappingVariables().size());
assertEquals("i", map.getMappedVariables().get(0).getArgMapping());
assertEquals("i", map.getMappedVariables().get(0).getFctMapping());
assertFalse(map.getMappedVariables().get(0).hasDifferentMapping());
assertEquals("j", map.getMappingVariables().get(0).getArgMapping());
assertEquals("j", map.getMappingVariables().get(0).getFctMapping());
assertFalse(map.getMappingVariables().get(0).hasDifferentMapping());
l = analyzeValidClawLoopExtract("claw loop-extract range(j1=ki1sc,ki1ec) " + "map(pduh2oc,pduh2of:j1,ki3sc/j3) " + "map(pduco2,pduo3,palogp,palogt,podsc,podsf,podac," + "podaf:j1,ki3sc/j3) " + "map(pbsff,pbsfc:j1,ki3sc/j3) " + "map(pa1c,pa1f,pa2c,pa2f,pa3c,pa3f:j1) " + "fusion group(coeth-j1) parallel acc(loop gang vector)", "j1", "ki1sc", "ki1ec", null, null);
assertNotNull(l);
assertEquals(4, l.getMappings().size());
ClawMapping map1 = l.getMappings().get(0);
assertNotNull(map1);
assertEquals(2, map1.getMappedVariables().size());
assertEquals(2, map1.getMappingVariables().size());
assertEquals("pduh2oc", map1.getMappedVariables().get(0).getArgMapping());
assertEquals("pduh2oc", map1.getMappedVariables().get(0).getFctMapping());
assertEquals("pduh2of", map1.getMappedVariables().get(1).getArgMapping());
assertEquals("pduh2of", map1.getMappedVariables().get(1).getFctMapping());
assertEquals("j1", map1.getMappingVariables().get(0).getArgMapping());
assertEquals("j1", map1.getMappingVariables().get(0).getFctMapping());
assertEquals("ki3sc", map1.getMappingVariables().get(1).getArgMapping());
assertEquals("j3", map1.getMappingVariables().get(1).getFctMapping());
ClawMapping map2 = l.getMappings().get(1);
assertNotNull(map2);
assertEquals(8, map2.getMappedVariables().size());
assertEquals(2, map2.getMappingVariables().size());
assertEquals("pduco2", map2.getMappedVariables().get(0).getArgMapping());
assertEquals("pduco2", map2.getMappedVariables().get(0).getFctMapping());
assertEquals("pduo3", map2.getMappedVariables().get(1).getArgMapping());
assertEquals("pduo3", map2.getMappedVariables().get(1).getFctMapping());
assertEquals("palogp", map2.getMappedVariables().get(2).getArgMapping());
assertEquals("palogp", map2.getMappedVariables().get(2).getFctMapping());
assertEquals("palogt", map2.getMappedVariables().get(3).getArgMapping());
assertEquals("palogt", map2.getMappedVariables().get(3).getFctMapping());
assertEquals("podsc", map2.getMappedVariables().get(4).getArgMapping());
assertEquals("podsc", map2.getMappedVariables().get(4).getFctMapping());
assertEquals("podsf", map2.getMappedVariables().get(5).getArgMapping());
assertEquals("podsf", map2.getMappedVariables().get(5).getFctMapping());
assertEquals("podac", map2.getMappedVariables().get(6).getArgMapping());
assertEquals("podac", map2.getMappedVariables().get(6).getFctMapping());
assertEquals("podaf", map2.getMappedVariables().get(7).getArgMapping());
assertEquals("podaf", map2.getMappedVariables().get(7).getFctMapping());
assertEquals("j1", map2.getMappingVariables().get(0).getArgMapping());
assertEquals("j1", map2.getMappingVariables().get(0).getFctMapping());
assertEquals("ki3sc", map2.getMappingVariables().get(1).getArgMapping());
assertEquals("j3", map2.getMappingVariables().get(1).getFctMapping());
ClawMapping map3 = l.getMappings().get(2);
assertNotNull(map3);
assertEquals(2, map3.getMappedVariables().size());
assertEquals(2, map3.getMappingVariables().size());
assertEquals("pbsff", map3.getMappedVariables().get(0).getArgMapping());
assertEquals("pbsff", map3.getMappedVariables().get(0).getFctMapping());
assertEquals("pbsfc", map3.getMappedVariables().get(1).getArgMapping());
assertEquals("pbsfc", map3.getMappedVariables().get(1).getFctMapping());
assertEquals("j1", map3.getMappingVariables().get(0).getArgMapping());
assertEquals("j1", map3.getMappingVariables().get(0).getFctMapping());
assertEquals("ki3sc", map3.getMappingVariables().get(1).getArgMapping());
assertEquals("j3", map3.getMappingVariables().get(1).getFctMapping());
ClawMapping map4 = l.getMappings().get(3);
assertNotNull(map4);
assertEquals(6, map4.getMappedVariables().size());
assertEquals(1, map4.getMappingVariables().size());
assertEquals("pa1c", map4.getMappedVariables().get(0).getArgMapping());
assertEquals("pa1c", map4.getMappedVariables().get(0).getFctMapping());
assertEquals("pa1f", map4.getMappedVariables().get(1).getArgMapping());
assertEquals("pa1f", map4.getMappedVariables().get(1).getFctMapping());
assertEquals("pa2c", map4.getMappedVariables().get(2).getArgMapping());
assertEquals("pa2c", map4.getMappedVariables().get(2).getFctMapping());
assertEquals("pa2f", map4.getMappedVariables().get(3).getArgMapping());
assertEquals("pa2f", map4.getMappedVariables().get(3).getFctMapping());
assertEquals("pa3c", map4.getMappedVariables().get(4).getArgMapping());
assertEquals("pa3c", map4.getMappedVariables().get(4).getFctMapping());
assertEquals("pa3f", map4.getMappedVariables().get(5).getArgMapping());
assertEquals("pa3f", map4.getMappedVariables().get(5).getFctMapping());
assertEquals("j1", map4.getMappingVariables().get(0).getArgMapping());
assertEquals("j1", map4.getMappingVariables().get(0).getFctMapping());
assertTrue(l.hasClause(ClawClause.FUSION));
assertTrue(l.hasClause(ClawClause.GROUP));
assertEquals("coeth-j1", l.value(ClawClause.GROUP));
assertTrue(l.hasClause(ClawClause.ACC));
assertEquals("loop gang vector", l.value(ClawClause.ACC));
analyzeValidClawLoopExtract("claw loop-extract range(i=istart,iend) map(i:j) target(gpu) fusion " + "group(j1)", "i", "istart", "iend", null, Collections.singletonList(Target.GPU));
analyzeValidClawLoopExtract("claw loop-extract range(i=istart,iend) map(i:j) fusion group(j1) " + "target(gpu)", "i", "istart", "iend", null, Collections.singletonList(Target.GPU));
// Invalid directives
analyzeInvalidClawLanguage("claw loop-extract");
analyzeInvalidClawLanguage("claw loop - extract ");
}
use of claw.wani.language.ClawPragma in project claw-compiler by C2SM-RCM.
the class ClawPragmaTest method analyzeValidClawLoopInterchange.
/**
* Assert the result for valid loop interchange CLAW directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param indexes List of indexes to be found if any.
*/
private void analyzeValidClawLoopInterchange(String raw, List<String> indexes, boolean parallel, String acc, List<Target> targets) {
ClawPragma l = analyze(raw, ClawDirective.LOOP_INTERCHANGE);
assertNotNull(l);
if (indexes != null) {
assertTrue(l.hasClause(ClawClause.INTERCHANGE_INDEXES));
assertEquals(indexes.size(), l.values(ClawClause.INTERCHANGE_INDEXES).size());
} else {
assertFalse(l.hasClause(ClawClause.INTERCHANGE_INDEXES));
assertNull(l.values(ClawClause.INTERCHANGE_INDEXES));
}
if (parallel) {
assertTrue(l.hasClause(ClawClause.PARALLEL));
} else {
assertFalse(l.hasClause(ClawClause.PARALLEL));
}
if (acc != null) {
assertTrue(l.hasClause(ClawClause.ACC));
assertEquals(acc, l.value(ClawClause.ACC));
} else {
assertFalse(l.hasClause(ClawClause.ACC));
assertNull(l.value(ClawClause.ACC));
}
assertTargets(l, targets);
}
use of claw.wani.language.ClawPragma in project claw-compiler by C2SM-RCM.
the class ClawPragmaTest method simpleTest.
@Test
public void simpleTest() {
ClawPragma cp = new ClawPragma();
cp.setValue(ClawClause.GROUP, "g1");
assertTrue(cp.hasClause(ClawClause.GROUP));
assertEquals("g1", cp.value(ClawClause.GROUP));
assertNull(cp.values(ClawClause.GROUP));
assertFalse(cp.hasClause(ClawClause.INTERCHANGE));
assertNull(cp.value(ClawClause.INTERCHANGE));
cp.setValue(null, null);
}
use of claw.wani.language.ClawPragma in project claw-compiler by C2SM-RCM.
the class ClawPragmaTest method analyzeValidSCA.
/**
* Assert the result for valid CLAW SCA directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param data Reference list for the data 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 analyzeValidSCA(String raw, List<String> data, List<DimensionDefinition> dimensions, DataMovement copyClause, DataMovement updateClause, List<String> scalarData, boolean isModelConfig) {
ClawPragma l = analyze(raw, ClawDirective.SCA);
assertNotNull(l);
assertEquals(0, l.getErrors().size());
if (data != null) {
assertTrue(l.hasClause(ClawClause.DATA_OVER));
assertEquals(data.size(), l.getDataOverClauseValues().size());
for (String d : data) {
assertTrue(l.getDataOverClauseValues().contains(d));
assertTrue(l.getLocalModelConfig().hasLayout(d));
}
}
if (dimensions != null) {
assertEquals(dimensions.size(), l.getLocalModelConfig().getNbDimensions());
for (DimensionDefinition expected : dimensions) {
DimensionDefinition actual = l.getLocalModelConfig().getDimension(expected.getIdentifier());
assertNotNull(actual);
assertEquals(expected.getIdentifier(), actual.getIdentifier());
assertEquals(expected.getLowerBound().isVar(), actual.getLowerBound().isVar());
assertEquals(expected.getUpperBound().isVar(), actual.getUpperBound().isVar());
assertEquals(expected.getLowerBound().getIntValue(), actual.getLowerBound().getIntValue());
assertEquals(expected.getUpperBound().getIntValue(), actual.getUpperBound().getIntValue());
assertEquals(expected.getLowerBound().getValue(), actual.getLowerBound().getValue());
assertEquals(expected.getUpperBound().getValue(), actual.getUpperBound().getValue());
}
}
if (scalarData != null) {
assertTrue(l.hasClause(ClawClause.SCALAR));
assertEquals(scalarData.size(), l.values(ClawClause.SCALAR).size());
for (int i = 0; i < scalarData.size(); ++i) {
assertEquals(scalarData.get(i), l.values(ClawClause.SCALAR).get(i));
}
}
if (data == null && dimensions == null && !isModelConfig) {
assertTrue(l.hasClause(ClawClause.FORWARD) || l.hasClause(ClawClause.ROUTINE));
}
if (copyClause == null) {
assertFalse(l.hasClause(ClawClause.COPY));
assertNull(l.getCopyClauseValue());
} else {
assertTrue(l.hasClause(ClawClause.COPY));
assertEquals(copyClause, l.getCopyClauseValue());
}
if (updateClause == null) {
assertFalse(l.hasClause(ClawClause.UPDATE));
assertNull(l.getUpdateClauseValue());
} else {
assertTrue(l.hasClause(ClawClause.UPDATE));
assertEquals(updateClause, l.getUpdateClauseValue());
}
}
use of claw.wani.language.ClawPragma in project claw-compiler by C2SM-RCM.
the class ClawPragmaTest method assertModelDataDirective.
/**
* Assert the result for model-data directive
*
* @param raw Raw directive.
* @param layoutId Optional layout id to check for.
*/
private void assertModelDataDirective(String raw, String layoutId) {
ClawPragma l = analyze(raw, ClawDirective.MODEL_DATA);
assertNotNull(l);
if (layoutId == null) {
assertFalse(l.hasClause(ClawClause.LAYOUT));
assertNull(l.value(ClawClause.LAYOUT));
} else {
assertTrue(l.hasClause(ClawClause.LAYOUT));
assertEquals(layoutId, l.value(ClawClause.LAYOUT));
}
}
Aggregations