Search in sources :

Example 1 with TomlArray

use of net.consensys.cava.toml.TomlArray in project claw-compiler by C2SM-RCM.

the class ModelConfig method readLayouts.

/**
 * Read all the layouts defined in the model configuration.
 *
 * The layouts can be defined as follows:
 *
 * [[layouts]] id = "id" position = [ "dim1", ":" ]
 *
 * The ":" dimension is representing the base dimension (currently present
 * dimensions)
 *
 * @param result The current TOML parse result object.
 * @throws Exception If the result is not conform to the specifications.
 */
private void readLayouts(TomlParseResult result) throws Exception {
    TomlArray layouts = result.getArray(KEY_LAYOUTS);
    if (layouts == null) {
        throw new Exception(String.format(ERR_NO_LAYOUTS, _modelName));
    }
    for (int i = 0; i < layouts.size(); ++i) {
        TomlTable layout = layouts.getTable(i);
        String layoutId = layout.getString(KEY_DIMENSION_ID);
        if (layoutId == null) {
            throw new Exception(ERR_LAYOUT_NO_ID);
        }
        TomlArray position = layout.getArray(KEY_LAYOUT_POSITION);
        if (position == null) {
            throw new Exception(String.format(ERR_LAYOUT_NO_POSITION, layoutId));
        }
        List<DimensionDefinition> dimensions = new ArrayList<>();
        for (int j = 0; j < position.size(); ++j) {
            String pos = position.getString(j);
            if (pos.equals(DimensionDefinition.BASE_DIM)) {
                dimensions.add(DimensionDefinition.BASE_DIMENSION);
            } else {
                if (!_dimensions.containsKey(pos)) {
                    throw new Exception(String.format(ERR_DIM_NOT_AVAIL, pos, layoutId));
                }
                dimensions.add(_dimensions.get(pos));
            }
        }
        if (!dimensions.contains(DimensionDefinition.BASE_DIMENSION)) {
            throw new Exception(String.format(ERR_NO_BASE_DIM, layoutId));
        }
        DimensionDefinition.flagInsertPosition(dimensions);
        dimensions.remove(DimensionDefinition.BASE_DIMENSION);
        _layouts.put(layoutId, dimensions);
    }
}
Also used : TomlTable(net.consensys.cava.toml.TomlTable) ArrayList(java.util.ArrayList) TomlArray(net.consensys.cava.toml.TomlArray) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition)

Example 2 with TomlArray

use of net.consensys.cava.toml.TomlArray 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));
        }
    }
}
Also used : TomlTable(net.consensys.cava.toml.TomlTable) TomlArray(net.consensys.cava.toml.TomlArray) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition)

Aggregations

DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 TomlArray (net.consensys.cava.toml.TomlArray)2 TomlTable (net.consensys.cava.toml.TomlTable)2 ArrayList (java.util.ArrayList)1