use of claw.tatsu.xcodeml.abstraction.DimensionDefinition in project claw-compiler by C2SM-RCM.
the class ModelConfig method readDimensions.
/**
* Read all the dimensions defined in the model configuration.
*
* The dimension can be defined as follows:<br>
* <br>
*
* [[dimensions]] # Definition of dimensions that can be used in layouts<br>
* id = "horizontal"<br>
* [dimensions.size]<br>
* lower = 1 # if not specified, 1 by default<br>
* upper = "nproma" # mandatory information<br>
* [dimensions.iteration]<br>
* lower = "pstart" # if not specified size.lower by default<br>
* upper = "pend" # if not specified size.upper by default<br>
* step = 1 # if not specified, 1 by default<br>
* <br>
*
* @param result The current TOML parse result object.
* @throws Exception If the result is not conform to the specifications.
*/
private void readDimensions(TomlParseResult result) throws Exception {
TomlArray dimensions = result.getArray(KEY_DIMENSIONS);
if (dimensions == null) {
throw new Exception(String.format(ERR_NO_DIMENSIONS, _modelName));
}
for (int i = 0; i < dimensions.size(); ++i) {
TomlTable dimension = dimensions.getTable(i);
String dimId = dimension.getString(KEY_DIMENSION_ID);
TomlTable dimSize = dimension.getTable(KEY_DIMENSION_SIZE);
if (dimSize == null) {
throw new Exception(String.format(ERR_NO_SIZE, dimId));
}
String lowerBound = readBoundOrDefault(dimSize);
String upperBound = readStringOrInt(dimSize, KEY_DIMENSION_UB);
if (upperBound.isEmpty()) {
throw new Exception(String.format(ERR_NO_UPPER, dimId));
}
TomlTable dimIt = dimension.getTable(KEY_DIMENSION_ITERATION);
if (dimIt == null) {
_dimensions.put(dimId, new DimensionDefinition(dimId, lowerBound, upperBound));
} else {
String lowerItBound = readBoundOrNull(dimIt, KEY_DIMENSION_LB);
String upperItBound = readBoundOrNull(dimIt, KEY_DIMENSION_UB);
String stepItBound = readBoundOrNull(dimIt, KEY_DIMENSION_STEP);
_dimensions.put(dimId, new DimensionDefinition(dimId, lowerBound, upperBound, lowerItBound, upperItBound, stepItBound));
}
}
}
use of claw.tatsu.xcodeml.abstraction.DimensionDefinition in project claw-compiler by C2SM-RCM.
the class Sca method insertVariableToIterateOverDimension.
/**
* Insert the declaration of the different variables needed to iterate over the
* additional dimensions.
*
* @param xcodeml Current XcodeML program unit in which element are created.
*/
private void insertVariableToIterateOverDimension(Configuration cfg, XcodeProgram xcodeml) {
// Create type and declaration for iterations over the new dimensions
FbasicType bt = xcodeml.createBasicType(FortranType.INTEGER, Intent.IN);
xcodeml.getTypeTable().add(bt);
// For each dimension defined in the directive
for (DimensionDefinition dimension : _claw.getDefaultLayout(cfg)) {
if (!forceAssumedShapedArrayPromotion) {
// Create the parameter for the lower bound
if (dimension.getLowerBound().isVar()) {
xcodeml.createIdAndDecl(dimension.getLowerBound().getValue(), bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getLowerBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
// Create parameter for the upper bound
if (dimension.getUpperBound().isVar()) {
xcodeml.createIdAndDecl(dimension.getUpperBound().getValue(), bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getUpperBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
// Create the parameter for the iteration lower bound
if (dimension.getIterationLowerBound().isVar()) {
String itLowerBound = dimension.getIterationLowerBound().getValue();
if (!itLowerBound.equals(dimension.getLowerBound().getValue())) {
xcodeml.createIdAndDecl(itLowerBound, bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getIterationLowerBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
}
// Create parameter for the upper bound
if (dimension.getIterationUpperBound().isVar()) {
String itUpperBound = dimension.getIterationUpperBound().getValue();
if (!itUpperBound.equals(dimension.getUpperBound().getValue())) {
xcodeml.createIdAndDecl(itUpperBound, bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getIterationUpperBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
}
}
// Create induction variable declaration
xcodeml.createIdAndDecl(dimension.getIdentifier(), FortranType.INTEGER, XstorageClass.F_LOCAL, _fctDef, DeclarationPosition.LAST);
}
}
use of claw.tatsu.xcodeml.abstraction.DimensionDefinition in project claw-compiler by C2SM-RCM.
the class ScaForward method propagatePromotion.
/**
* Propagate possible promotion in assignments statements in the parent
* subroutine of the function call.
*
* @param xcodeml Current XcodeML program unit.
* @param translator Current translator to store information between
* transformation.
*/
private void propagatePromotion(XcodeProgram xcodeml, ClawTranslator translator) throws IllegalTransformationException {
// Get all the assignment statements in the function definition
FfunctionDefinition parentFctDef = _fCall.findParentFunction();
// Retrieve information of previous forward transformation in the same fct
List<String> previouslyPromoted = Utility.convertToList(translator.hasElement(parentFctDef));
List<Xnode> assignments = parentFctDef.matchAll(Xcode.F_ASSIGN_STATEMENT);
// Find promotion info that can be used.
// TODO define how default promotion is encoded in xmod file. For the
// TODO moment using the first information found in fctType.
PromotionInfo defaultInfo = Function.readPromotionInfo(_fctType, InsertionPosition.BEFORE);
for (Xnode assignment : assignments) {
Xnode lhs = assignment.child(0);
Xnode rhs = assignment.child(1);
List<Xnode> varsInRhs = rhs.matchAll(Xcode.VAR);
for (Xnode var : varsInRhs) {
// Check if the assignment statement uses a promoted variable
if (_promotedVar.contains(var.value()) && var.matchAncestor(Xcode.FUNCTION_CALL) == null && Xnode.isOfCode(lhs, Xcode.F_ARRAY_REF)) {
Xnode varInLhs = lhs.matchDescendant(Xcode.VAR);
if (varInLhs == null) {
throw new IllegalTransformationException("Unable to propagate " + "promotion. Internal error.", _claw.getPragma().lineNo());
}
// Declare the induction variable if they are not present
for (DimensionDefinition dim : defaultInfo.getDimensions()) {
if (parentFctDef.getDeclarationTable().get(dim.getIdentifier()) == null) {
xcodeml.createIdAndDecl(dim.getIdentifier(), FortranType.INTEGER, XstorageClass.F_LOCAL, parentFctDef, DeclarationPosition.LAST);
}
}
// Generate the do statements and move the assignment statement in
NestedDoStatement doStmt = new NestedDoStatement(defaultInfo.getDimensions(), xcodeml);
assignment.insertAfter(doStmt.getOuterStatement());
doStmt.getInnerStatement().body().append(assignment);
PromotionInfo promotionInfo;
if (!previouslyPromoted.contains(varInLhs.value())) {
// Perform the promotion on the variable
promotionInfo = new PromotionInfo(varInLhs.value(), defaultInfo.getDimensions());
Field.promote(promotionInfo, parentFctDef, xcodeml);
_promotions.put(promotionInfo.getIdentifier(), promotionInfo);
} else {
promotionInfo = _promotions.get(varInLhs.value());
}
_promotedVar.add(varInLhs.value());
// Adapt the reference in the assignment statement
for (String id : _promotedVar) {
_promotions.get(id).resetFlags();
Field.adaptArrayRef(_promotions.get(id), assignment, false, xcodeml);
}
// If the array is a target, check if we have to promote a pointer
if (!previouslyPromoted.contains(varInLhs.value())) {
Field.adaptPointer(xcodeml, parentFctDef, _promotions, promotionInfo);
previouslyPromoted.add(varInLhs.value());
}
break;
/*
* if one var in the rhs of the assignment statement was promoted it's enough
* and we can switch to the next assignment statement.
*/
}
}
}
translator.storeElement(parentFctDef, previouslyPromoted);
}
use of claw.tatsu.xcodeml.abstraction.DimensionDefinition in project claw-compiler by C2SM-RCM.
the class ClawPragmaTest method analyzeValidOverSCA.
/**
* Assert the result for valid CLAW sca directive with data over clause.
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param datas Reference list for the data clause values.
* @param dimensions Reference list of dimensions.
*/
private void analyzeValidOverSCA(String raw, List<List<String>> datas, List<List<DimensionDefinition>> dimensions) {
ClawPragma l = analyze(raw, ClawDirective.SCA);
assertNotNull(l);
if (datas != null) {
assertEquals(datas.size(), dimensions.size());
assertTrue(l.hasClause(ClawClause.DATA_OVER));
for (int j = 0; j < datas.size(); ++j) {
List<String> data = datas.get(j);
List<DimensionDefinition> dimension = dimensions.get(j);
for (String id : data) {
assertNotNull(l.getLayoutForData(cfg, id));
List<DimensionDefinition> dims = l.getLayoutForData(cfg, id);
assertEquals(dimension.size(), dims.size());
for (int i = 0; i < dimension.size(); ++i) {
assertEquals(dimension.get(i).getIdentifier(), dims.get(i).getIdentifier());
assertEquals(dimension.get(i).getInsertionPosition(), dims.get(i).getInsertionPosition());
assertEquals(dimension.get(i).getLowerBound().isVar(), dims.get(i).getLowerBound().isVar());
assertEquals(dimension.get(i).getLowerBound().getValue(), dims.get(i).getLowerBound().getValue());
assertEquals(dimension.get(i).getLowerBound().getIntValue(), dims.get(i).getLowerBound().getIntValue());
assertEquals(dimension.get(i).getUpperBound().isVar(), dims.get(i).getUpperBound().isVar());
assertEquals(dimension.get(i).getUpperBound().getValue(), dims.get(i).getUpperBound().getValue());
assertEquals(dimension.get(i).getUpperBound().getIntValue(), dims.get(i).getUpperBound().getIntValue());
}
}
}
}
}
use of claw.tatsu.xcodeml.abstraction.DimensionDefinition in project claw-compiler by C2SM-RCM.
the class ClawPragmaTest method scaOverClauseTest.
/**
* Test various input for the CLAW sca directive.
*/
@Test
public void scaOverClauseTest() {
DimensionDefinition d1 = new DimensionDefinition("i", "1", "ni");
DimensionDefinition d2 = new DimensionDefinition("j", "1", "nj");
List<String> data1 = Arrays.asList("a", "b", "c");
List<List<String>> data1Lst = Collections.singletonList(data1);
d1.setInsertionPosition(InsertionPosition.BEFORE);
analyzeValidOverSCA("claw define dimension i(1:ni) sca " + "data(a,b,c) over (i,:)", data1Lst, Collections.singletonList(Collections.singletonList(d1)));
d1.setInsertionPosition(InsertionPosition.AFTER);
analyzeValidOverSCA("claw define dimension i(1:ni) sca " + "data(a,b,c) over (:,i)", data1Lst, Collections.singletonList(Collections.singletonList(d1)));
d1.setInsertionPosition(InsertionPosition.BEFORE);
d2.setInsertionPosition(InsertionPosition.BEFORE);
analyzeValidOverSCA("claw define dimension i(1:ni) " + "define dimension j(1:nj) sca " + "data(a,b,c) over (i,j,:)", data1Lst, Collections.singletonList(Arrays.asList(d1, d2)));
d1.setInsertionPosition(InsertionPosition.AFTER);
d2.setInsertionPosition(InsertionPosition.AFTER);
analyzeValidOverSCA("claw define dimension i(1:ni) " + "define dimension j(1:nj) sca " + "data(a,b,c) over (:,i,j)", data1Lst, Collections.singletonList(Arrays.asList(d1, d2)));
d1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
d2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
analyzeValidOverSCA("claw define dimension i(1:ni) " + "define dimension j(1:nj) sca " + "data(a,b,c) over (:,i,j,:)", data1Lst, Collections.singletonList(Arrays.asList(d1, d2)));
d1.setInsertionPosition(InsertionPosition.BEFORE);
d2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
analyzeValidOverSCA("claw define dimension i(1:ni) " + "define dimension j(1:nj) sca " + "data(a,b,c) over (i,:,j,:)", data1Lst, Collections.singletonList(Arrays.asList(d1, d2)));
d1.setInsertionPosition(InsertionPosition.BEFORE);
d2.setInsertionPosition(InsertionPosition.AFTER);
analyzeValidOverSCA("claw define dimension i(1:ni) " + "define dimension j(1:nj) sca " + "data(a,b,c) over (i,:,j)", data1Lst, Collections.singletonList(Arrays.asList(d1, d2)));
d1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
d2.setInsertionPosition(InsertionPosition.AFTER);
analyzeValidOverSCA("claw define dimension i(1:ni) " + "define dimension j(1:nj) sca " + "data(a,b,c) over (:,i,:,j)", data1Lst, Collections.singletonList(Arrays.asList(d1, d2)));
d1.setInsertionPosition(InsertionPosition.BEFORE);
d2.setInsertionPosition(InsertionPosition.AFTER);
analyzeValidOverSCA("claw define dimension i(1:ni) " + "define dimension j(1:nj) sca " + "data(a,b) over (i,:)" + "data(c) over (:,j)", Arrays.asList(Arrays.asList("a", "b"), Collections.singletonList("c")), Arrays.asList(Collections.singletonList(d1), Collections.singletonList(d2)));
}
Aggregations