Search in sources :

Example 1 with DimensionDefinition

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

the class ClawPragma method generateLayoutFromOver.

/**
 * Generate a layout from the over clause information.
 *
 * @param over Over clause as a list of String (dimension ids).
 * @return A list of dimension definition used as a layout.
 */
private List<DimensionDefinition> generateLayoutFromOver(List<String> over) {
    boolean hasMiddleInsertion = getNbOfBaseDimensions(over) > 1;
    List<DimensionDefinition> overLayout = new ArrayList<>();
    InsertionPosition crt = InsertionPosition.BEFORE;
    for (String d : over) {
        if (d.equals(DimensionDefinition.BASE_DIM)) {
            crt = crt.getNext(hasMiddleInsertion);
        } else {
            if (_localModelConfig.hasDimension(d)) {
                DimensionDefinition newDimension = _localModelConfig.getDimension(d).copy();
                newDimension.setInsertionPosition(crt);
                overLayout.add(newDimension);
            } else {
                _errors.add(String.format("Dimension %s is not defined", d));
            }
        }
    }
    return overLayout;
}
Also used : ArrayList(java.util.ArrayList) InsertionPosition(claw.tatsu.xcodeml.abstraction.InsertionPosition) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition)

Example 2 with DimensionDefinition

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

the class FieldTest method formattedDimensionsTest.

@Test
public void formattedDimensionsTest() {
    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);
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    PromotionInfo p1 = new PromotionInfo("a", dimensions1);
    assertEquals("dim1(1:30),:", p1.getFormattedDimensions());
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    assertEquals(":,dim1(1:30),:", p1.getFormattedDimensions());
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(":,dim1(1:30)", p1.getFormattedDimensions());
    PromotionInfo p2 = new PromotionInfo("a", dimensions2);
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.BEFORE);
    assertEquals("dim1(1:30),dim2(1:40),:", p2.getFormattedDimensions());
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(":,dim1(1:30),dim2(1:40)", p2.getFormattedDimensions());
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    assertEquals(":,dim1(1:30),dim2(1:40),:", p2.getFormattedDimensions());
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals("dim1(1:30),:,dim2(1:40)", p2.getFormattedDimensions());
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(":,dim1(1:30),:,dim2(1:40)", p2.getFormattedDimensions());
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    assertEquals("dim1(1:30),:,dim2(1:40),:", p2.getFormattedDimensions());
    PromotionInfo p3 = new PromotionInfo("c");
    assertEquals("", p3.getFormattedDimensions());
}
Also used : PromotionInfo(claw.tatsu.xcodeml.abstraction.PromotionInfo) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) Test(org.junit.Test)

Example 3 with DimensionDefinition

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

the class ModelConfigTest method dimensionsTest.

@Test
public void dimensionsTest() {
    ModelConfig cfg = new ModelConfig();
    assertEquals(0, cfg.getNbDimensions());
    DimensionDefinition d = new DimensionDefinition("dim1", "0", "ndim1");
    assertFalse(cfg.hasDimension(d.getIdentifier()));
    cfg.putDimension(d);
    assertTrue(cfg.hasDimension(d.getIdentifier()));
    assertEquals(d, cfg.getDimension(d.getIdentifier()));
}
Also used : DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) Test(org.junit.Test)

Example 4 with DimensionDefinition

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

the class Field method adaptArrayRef.

/**
 * Adapt all the array references of the variable in the data clause in the
 * current function/subroutine definition.
 *
 * @param promotionInfo   Promotion information used for the promotion of the
 *                        field.
 * @param parent          Root node of the tree in which the adaptation is done.
 * @param adaptNakedArray Adapt arrayRef with no index (e.g. p instead of p(:))
 * @param xcodeml         Current XcodeML translation unit.
 */
public static void adaptArrayRef(PromotionInfo promotionInfo, Xnode parent, boolean adaptNakedArray, XcodeProgram xcodeml) {
    if (promotionInfo.isRefAdapted()) {
        return;
    }
    // Scalar to array reference
    if (promotionInfo.wasScalar()) {
        List<Xnode> refs = XnodeUtil.getAllVarReferences(parent, promotionInfo.getIdentifier());
        for (Xnode ref : refs) {
            if (Function.isArgOfFunction(ref, Xintrinsic.PRESENT)) {
                continue;
            }
            Xnode arrayRef = convertVarToArrayRef(promotionInfo, ref, xcodeml);
            // Simply generate all arrayIndex in order
            for (DimensionDefinition dim : promotionInfo.getDimensions()) {
                arrayRef.append(dim.generateArrayIndex(xcodeml));
            }
        }
    } else {
        // Array reference to array reference
        List<Xnode> refs = XnodeUtil.getAllArrayReferences(parent, promotionInfo.getIdentifier());
        for (Xnode ref : refs) {
            if (ref.matchAncestor(Xcode.F_ALLOCATE_STATEMENT) != null) {
                continue;
            }
            insertPromotionDimensions(promotionInfo, ref, xcodeml);
        }
        if (adaptNakedArray) {
            List<Xnode> assumedRefs = XnodeUtil.getAllVarReferences(parent, promotionInfo.getIdentifier());
            for (Xnode ref : assumedRefs) {
                // Fortran array passed without assumed dimensions
                if (ref.isNotArrayRef()) {
                    Xnode arrayRef = convertVarToArrayRef(promotionInfo, ref, xcodeml);
                    for (int i = 0; i < promotionInfo.getBaseDimension(); ++i) {
                        arrayRef.append(xcodeml.createEmptyAssumedShaped());
                    }
                    insertPromotionDimensions(promotionInfo, arrayRef, xcodeml);
                }
            }
        }
    }
    promotionInfo.setRefAdapted();
}
Also used : DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition)

Example 5 with DimensionDefinition

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

the class Field method insertPromotionDimensions.

/**
 * Insert newly added dimension from promotion information at the right place.
 *
 * @param promotionInfo Promotion information used for the promotion of the
 *                      field.
 * @param ref           Current array reference.
 * @param xcodeml       Current XcodeML translation unit.
 */
private static void insertPromotionDimensions(PromotionInfo promotionInfo, Xnode ref, XcodeML xcodeml) {
    // First arrayIndex after varRef at pos 0
    int beforePositionIndex = 0;
    int inMiddlePositionIndex = 1;
    for (DimensionDefinition dim : promotionInfo.getDimensions()) {
        switch(dim.getInsertionPosition()) {
            case BEFORE:
                ref.child(beforePositionIndex).insertAfter(dim.generateArrayIndex(xcodeml));
                ++beforePositionIndex;
                ++inMiddlePositionIndex;
                break;
            case IN_MIDDLE:
                ref.child(inMiddlePositionIndex).insertAfter(dim.generateArrayIndex(xcodeml));
                ++inMiddlePositionIndex;
                break;
            case AFTER:
                ref.append(dim.generateArrayIndex(xcodeml));
                break;
        }
    }
}
Also used : DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition)

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