Search in sources :

Example 16 with DimensionDefinition

use of claw.tatsu.xcodeml.abstraction.DimensionDefinition in project claw-compiler by C2SM-RCM.

the class ClawPragmaTest method getDimDef.

private DimensionDefinition getDimDef(String id, String start, String end, InsertionPosition pos) {
    DimensionDefinition dimDef = new DimensionDefinition(id, start, end);
    dimDef.setInsertionPosition(pos);
    return dimDef;
}
Also used : DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition)

Example 17 with DimensionDefinition

use of claw.tatsu.xcodeml.abstraction.DimensionDefinition in project claw-compiler by C2SM-RCM.

the class ClawPragmaTest method scaTest.

/**
 * Test various input for the CLAW SCA directive.
 */
@Test
public void scaTest() {
    // Valid directives
    DimensionDefinition d1 = new DimensionDefinition("i", "1", "nx");
    List<String> data1 = Arrays.asList("t", "qc", "qv");
    DimensionDefinition dimI = getDimDef("i", "1", "nx", InsertionPosition.BEFORE);
    List<String> layout1 = Arrays.asList("i", ":");
    List<String> ijc = Arrays.asList("i", "j", ":");
    List<String> icj = Arrays.asList("i", ":", "j");
    List<String> cij = Arrays.asList(":", "i", "j");
    List<List<String>> layouts1 = Arrays.asList(layout1, layout1, layout1);
    List<List<String>> over2 = Collections.singletonList(icj);
    List<List<String>> over3 = Collections.singletonList(cij);
    analyzeValidSCA("claw sca", null, null, null, null, null, true);
    analyzeValidSCA("claw define dimension i(1:nx)" + " sca data(t,qc,qv) over (i,:)", data1, Collections.singletonList(d1), null, null, null, false);
    DimensionDefinition d2 = new DimensionDefinition("j", "1", "ny");
    analyzeValidSCA("claw define dimension j(1:ny)" + "sca data(t,qc,qv) over (j,:)", data1, Collections.singletonList(d2), null, null, null, false);
    DimensionDefinition d3 = new DimensionDefinition("j", "1", "10");
    analyzeValidSCA("claw define dimension j(1:10) " + "sca data(t,qc,qv) over (j,:)", data1, Collections.singletonList(d3), null, null, null, false);
    DimensionDefinition d4 = new DimensionDefinition("j", "jstart", "10");
    analyzeValidSCA("claw define dimension j(jstart:10) " + "sca data(t,qc,qv) over (j,:)", data1, Collections.singletonList(d4), null, null, null, false);
    DimensionDefinition d5 = new DimensionDefinition("j", "jstart", "ny");
    analyzeValidSCA("claw define dimension j(jstart:ny) " + "sca data(t,qc,qv) over (j,:)", data1, Collections.singletonList(d5), null, null, null, false);
    DimensionDefinition d6 = new DimensionDefinition("j", "jstart", "ny");
    analyzeValidSCA("claw define dimension j(jstart:ny) sca", null, Collections.singletonList(d6), null, null, null, false);
    analyzeValidSCA("claw define dimension i(1:nx) sca scalar(s1,s2)", null, Collections.singletonList(d1), null, null, Arrays.asList("s1", "s2"), false);
    analyzeValidSCA("claw sca forward", null, null, null, null, null, false);
    analyzeValidSCA("claw sca routine", null, null, null, null, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t,qc,qv) over (i,j,:)", data1, Arrays.asList(d1, d2), null, null, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t,qc,qv) over (:,i,j)", data1, Arrays.asList(d1, d2), null, null, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t,qc,qv) over (i,:,j)", data1, Arrays.asList(d1, d2), null, null, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t , qc , qv) over (i,:,j)", data1, Arrays.asList(d1, d2), null, null, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t , qc , qv) over (i,:,j) " + "copy", data1, Arrays.asList(d1, d2), DataMovement.TWO_WAY, null, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t , qc , qv) over (i,:,j) " + "copy(in)", data1, Arrays.asList(d1, d2), DataMovement.HOST_TO_DEVICE, null, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t , qc , qv) over (i,:,j) " + "copy(out)", data1, Arrays.asList(d1, d2), DataMovement.DEVICE_TO_HOST, null, null, false);
    DimensionDefinition d7 = new DimensionDefinition("c", "1", "nc");
    analyzeValidSCA("claw define dimension c(1:nc) sca copy", null, Collections.singletonList(d7), DataMovement.TWO_WAY, null, null, false);
    analyzeValidSCA("claw define dimension c(1:nc) " + "sca copy(in)", null, Collections.singletonList(d7), DataMovement.HOST_TO_DEVICE, null, null, false);
    analyzeValidSCA("claw define dimension c(1:nc) " + "sca copy(out)", null, Collections.singletonList(d7), DataMovement.DEVICE_TO_HOST, null, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t , qc , qv) over (i,:,j) " + "update", data1, Arrays.asList(d1, d2), null, DataMovement.TWO_WAY, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t , qc , qv) over (i,:,j) " + "update(in)", data1, Arrays.asList(d1, d2), null, DataMovement.HOST_TO_DEVICE, null, false);
    analyzeValidSCA("claw " + "define dimension i(1:nx) " + "define dimension j(1:ny) " + "sca data(t , qc , qv) over (i,:,j) " + "update(out)", data1, Arrays.asList(d1, d2), null, DataMovement.DEVICE_TO_HOST, null, false);
    analyzeValidSCA("claw define dimension c(1:nc) sca update", null, Collections.singletonList(d7), null, DataMovement.TWO_WAY, null, false);
    analyzeValidSCA("claw define dimension c(1:nc) " + "sca update(in)", null, Collections.singletonList(d7), null, DataMovement.HOST_TO_DEVICE, null, false);
    analyzeValidSCA("claw define dimension c(1:nc) " + "sca update(out)", null, Collections.singletonList(d7), null, DataMovement.DEVICE_TO_HOST, null, false);
    analyzeValidSCA("claw sca forward copy", null, null, DataMovement.TWO_WAY, null, null, false);
    analyzeValidSCA("claw sca forward copy(in)", null, null, DataMovement.HOST_TO_DEVICE, null, null, false);
    analyzeValidSCA("claw sca forward copy(out)", null, null, DataMovement.DEVICE_TO_HOST, null, null, false);
    analyzeValidSCA("claw sca forward update", null, null, null, DataMovement.TWO_WAY, null, false);
    analyzeValidSCA("claw sca forward update(in)", null, null, null, DataMovement.HOST_TO_DEVICE, null, false);
    analyzeValidSCA("claw sca forward update(out)", null, null, null, DataMovement.DEVICE_TO_HOST, null, false);
    List<String> dataLst2 = Arrays.asList("t", "q");
    List<String> ic = Arrays.asList("i", ":");
    List<String> ci = Arrays.asList(":", "i");
    List<List<String>> over4 = Arrays.asList(ic, ci);
    analyzeValidSCA("claw  define dimension i(1:nx) " + "sca data(t) over (i,:) data(q) over(:,i)", dataLst2, Collections.singletonList(d1), null, null, null, false);
    // Invalid directives
    analyzeInvalidClawLanguage("claw sca data over ");
    analyzeInvalidClawLanguage("claw sca data");
    analyzeInvalidClawLanguage("claw sca over");
    analyzeInvalidClawLanguage("claw parallelite data() over ()");
}
Also used : List(java.util.List) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) Test(org.junit.Test)

Example 18 with DimensionDefinition

use of claw.tatsu.xcodeml.abstraction.DimensionDefinition in project claw-compiler by C2SM-RCM.

the class FieldTest method readFromFormattedDimensionTest.

@Test
public void readFromFormattedDimensionTest() {
    DimensionDefinition dim1 = new DimensionDefinition("dim1", "1", "30");
    DimensionDefinition dim2 = new DimensionDefinition("dim2", "1", "nproma");
    PromotionInfo p1 = new PromotionInfo("a");
    p1.readDimensionsFromString("dim1(1:30),:");
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    assertEquals(1, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    p1.readDimensionsFromString(":,dim1(1:30)");
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(1, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    p1.readDimensionsFromString(":,dim1(1:30),:");
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    assertEquals(1, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    p1.readDimensionsFromString("dim1(1:30),dim2(1:nproma),:");
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.BEFORE);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString(":,dim1(1:30),dim2(1:nproma),:");
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString(":,dim1(1:30),dim2(1:nproma)");
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString("dim1(1:30),:,dim2(1:nproma)");
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString("dim1(1:30),:,dim2(1:nproma),:");
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString(":,dim1(1:30),:,dim2(1:nproma)");
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
}
Also used : PromotionInfo(claw.tatsu.xcodeml.abstraction.PromotionInfo) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) Test(org.junit.Test)

Example 19 with DimensionDefinition

use of claw.tatsu.xcodeml.abstraction.DimensionDefinition in project claw-compiler by C2SM-RCM.

the class FieldTest method promoteTest.

@Test
public void promoteTest() {
    DimensionDefinition dim1 = new DimensionDefinition("dim1", "1", "30");
    DimensionDefinition dim2 = new DimensionDefinition("dim2", "1", "40");
    List<DimensionDefinition> dimensions1 = Collections.singletonList(dim1);
    List<DimensionDefinition> dimensions2 = Arrays.asList(dim1, dim2);
    Context context = new TestContext();
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PROMOTION, context);
    assertNotNull(xcodeml);
    List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
    assertEquals(1, fctDefs.size());
    FfunctionDefinition fctDef = fctDefs.get(0);
    assertEquals("sub1", fctDef.getName());
    // Scalar to array promotion with 1 additional dimension
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("s1", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("s2", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("s3", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
    // Scalar to array promotion with 2 additional dimension
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("s4", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("s5", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("s6", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
    // Promotion with 1 additional dimension
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("a", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 30, 1, 10, 1, 20 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("b", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 10, 1, 20, 1, 30 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("c", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 10, 1, 30, 1, 20 });
    // Promotion with 2 additional dimensions at the same position
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("d", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 40, 1, 10, 1, 20 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("e", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 20, 1, 30, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("f", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 30, 1, 40, 1, 20 });
    // Promotion with 2 additional dimensions at different position
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("g", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 30, 1, 20, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("h", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 10, 1, 40, 1, 20 });
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("i", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 10, 1, 20, 1, 40 });
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 20 with DimensionDefinition

use of claw.tatsu.xcodeml.abstraction.DimensionDefinition 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());
    }
}
Also used : DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) ClawPragma(claw.wani.language.ClawPragma) ClawConstraint(claw.wani.language.ClawConstraint)

Aggregations

DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)23 Test (org.junit.Test)9 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)4 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)4 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)3 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)3 ArrayList (java.util.ArrayList)3 Context (claw.tatsu.common.Context)2 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)2 ClawConstraint (claw.wani.language.ClawConstraint)2 ClawPragma (claw.wani.language.ClawPragma)2 TestContext (helper.Utils.TestContext)2 List (java.util.List)2 TomlArray (net.consensys.cava.toml.TomlArray)2 TomlTable (net.consensys.cava.toml.TomlTable)2 InsertionPosition (claw.tatsu.xcodeml.abstraction.InsertionPosition)1 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)1 XcodeML (claw.tatsu.xcodeml.xnode.common.XcodeML)1 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)1