Search in sources :

Example 21 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class ClawLanguageTest method analyzeValidArrayToFctCall.

/**
   * Assert the result for valid CLAW call directive
   *
   * @param raw       Raw string value of the CLAW directive to be analyzed.
   * @param arrayName Array name to be checked.
   * @param fctName   Function name to be checked.
   * @param params    List of parameters identifier to be checked.
   */
private void analyzeValidArrayToFctCall(String raw, String arrayName, String fctName, List<String> params, List<Target> targets) {
    try {
        Xnode p = XmlHelper.createXpragma();
        p.setValue(raw);
        Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
        AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
        ClawLanguage l = ClawLanguage.analyze(p, generator, Target.GPU);
        assertEquals(ClawDirective.ARRAY_TO_CALL, l.getDirective());
        assertEquals(params.size(), l.getFctParams().size());
        for (int i = 0; i < params.size(); ++i) {
            assertEquals(params.get(i), l.getFctParams().get(i));
        }
        assertEquals(arrayName, l.getArrayName());
        assertEquals(fctName, l.getFctName());
        assertTargets(l, targets);
    } catch (IllegalDirectiveException idex) {
        System.err.print(idex.getMessage());
        fail();
    }
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode) IllegalDirectiveException(cx2x.xcodeml.exception.IllegalDirectiveException) Configuration(cx2x.translator.config.Configuration) ClawLanguage(cx2x.translator.language.base.ClawLanguage) ClawConstraint(cx2x.translator.language.common.ClawConstraint) AcceleratorGenerator(cx2x.translator.language.helper.accelerator.AcceleratorGenerator)

Example 22 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class ClawRangeTest method compareWithLoopIterationRangeTest.

@Test
public void compareWithLoopIterationRangeTest() {
    Xnode iterationRange1 = XmlHelper.createXnode(beginLoop + inductionVar1 + indexRange1 + endLoop);
    assertNotNull(iterationRange1);
    Xnode iterationRange2 = XmlHelper.createXnode(beginLoop + inductionVar1 + indexRange2 + endLoop);
    assertNotNull(iterationRange1);
    ClawRange range1 = new ClawRange("i", "1", "10", "1");
    assertTrue(range1.equals(iterationRange1));
    assertFalse(range1.equals(iterationRange2));
    ClawRange range2 = new ClawRange("i", "1", "10", "2");
    assertFalse(range2.equals(iterationRange1));
    assertFalse(range2.equals(iterationRange2));
    ClawRange range3 = new ClawRange("i", "1", "11", "1");
    assertFalse(range3.equals(iterationRange1));
    assertFalse(range3.equals(iterationRange2));
    ClawRange range4 = new ClawRange("i", "2", "10", "1");
    assertFalse(range4.equals(iterationRange1));
    assertFalse(range4.equals(iterationRange2));
    ClawRange range5 = new ClawRange("j", "1", "10", "1");
    assertFalse(range5.equals(iterationRange1));
    assertFalse(range5.equals(iterationRange2));
    ClawRange range6 = new ClawRange("i", "istart", "iend", "1");
    assertTrue(range6.equals(iterationRange2));
    assertFalse(range6.equals(iterationRange1));
    ClawRange range7 = new ClawRange("i", "istart", "iend", "2");
    assertFalse(range7.equals(iterationRange2));
    assertFalse(range7.equals(iterationRange1));
    ClawRange range8 = new ClawRange("i", "istart", "ieend", "1");
    assertFalse(range8.equals(iterationRange2));
    assertFalse(range8.equals(iterationRange1));
    ClawRange range9 = new ClawRange("i", "istarter", "iend", "1");
    assertFalse(range9.equals(iterationRange2));
    assertFalse(range9.equals(iterationRange1));
    ClawRange range10 = new ClawRange("j", "istart", "iend", "1");
    assertFalse(range10.equals(iterationRange2));
    assertFalse(range10.equals(iterationRange1));
    ClawRange range11 = new ClawRange();
    range11.setInductionVar("i");
    range11.setLowerBound("istart");
    range11.setUpperBound("iend");
    assertTrue(range11.equals(iterationRange2));
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode) ClawRange(cx2x.translator.language.common.ClawRange) Test(org.junit.Test)

Example 23 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class ClawLanguageTest 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) {
    try {
        Xnode p = XmlHelper.createXpragma();
        p.setValue(raw);
        Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
        AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
        ClawLanguage l = ClawLanguage.analyze(p, generator, Target.GPU);
        assertEquals(ClawDirective.LOOP_INTERCHANGE, l.getDirective());
        if (indexes != null) {
            assertTrue(l.hasIndexes());
            assertEquals(indexes.size(), l.getIndexes().size());
        } else {
            assertFalse(l.hasIndexes());
            assertNull(l.getIndexes());
        }
        if (parallel) {
            assertTrue(l.hasParallelClause());
        } else {
            assertFalse(l.hasParallelClause());
        }
        if (acc != null) {
            assertTrue(l.hasAcceleratorClause());
            assertEquals(acc, l.getAcceleratorClauses());
        } else {
            assertFalse(l.hasAcceleratorClause());
            assertNull(l.getAcceleratorClauses());
        }
        assertTargets(l, targets);
    } catch (IllegalDirectiveException idex) {
        fail();
    }
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode) IllegalDirectiveException(cx2x.xcodeml.exception.IllegalDirectiveException) Configuration(cx2x.translator.config.Configuration) ClawLanguage(cx2x.translator.language.base.ClawLanguage) AcceleratorGenerator(cx2x.translator.language.helper.accelerator.AcceleratorGenerator)

Example 24 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class IterationSpace method load.

/**
   * Create and categorize do statements based on their nesting level.
   *
   * @param doStatements List of do statements to categorize.
   * @throws Exception If a node is not a do statement.
   */
private void load(List<Xnode> doStatements) throws Exception {
    // Init the level 0
    _levels.add(0, new ArrayList<DependenceAnalysis>());
    DependenceAnalysis baseLoopLevel0 = null;
    for (Xnode doStmt : doStatements) {
        if (doStmt.opcode() != Xcode.FDOSTATEMENT) {
            throw new Exception("Only do statements node can be part of an " + "iteration space");
        }
        if (baseLoopLevel0 == null) {
            baseLoopLevel0 = new DependenceAnalysis(doStmt);
            _levels.get(0).add(baseLoopLevel0);
        } else {
            int crtLevel = 0;
            int insertedLevel = -1;
            while (_levels.size() > crtLevel) {
                for (DependenceAnalysis dep : _levels.get(crtLevel)) {
                    if (doStmt.isNestedIn(dep.getDoStmt())) {
                        insertedLevel = crtLevel + 1;
                        break;
                    }
                }
                ++crtLevel;
            }
            if (insertedLevel != -1) {
                addAtLevel(insertedLevel, new DependenceAnalysis(doStmt));
            } else {
                addAtLevel(0, new DependenceAnalysis(doStmt));
            }
        }
    }
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode)

Example 25 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class IfExtract method transform.

@Override
public void transform(XcodeProgram xcodeml, Transformer transformer, Transformation other) throws Exception {
    // Copy the body of the if statement inside the body of the do statement
    Xnode thenBlock = _ifStmt.matchDirectDescendant(Xcode.THEN);
    Xnode thenDoStmt = _doStmt.cloneNode();
    XnodeUtil.appendBody(thenDoStmt.body(), thenBlock.body());
    // Copy the if statement and clean its body
    Xnode newIfStmt = _ifStmt.cloneNode();
    Xnode newThen = newIfStmt.matchDirectDescendant(Xcode.THEN);
    for (Xnode n : newThen.body().children()) {
        n.delete();
    }
    // Add the new if statement after the do statement
    XnodeUtil.insertAfter(_doStmt.element(), newIfStmt.element());
    // Insert the do statement in the new if-then statement
    newThen.body().insert(thenDoStmt, false);
    Xnode elseBlock = _ifStmt.matchDirectDescendant(Xcode.ELSE);
    if (elseBlock != null) {
        Xnode elseDoStmt = _doStmt.cloneNode();
        XnodeUtil.appendBody(elseDoStmt.body(), elseBlock.body());
        Xnode newElse = newIfStmt.matchDirectDescendant(Xcode.ELSE);
        for (Xnode n : newElse.body().children()) {
            n.delete();
        }
        newElse.body().insert(elseDoStmt, false);
        Xnode duplicateIf = elseDoStmt.body().matchDirectDescendant(Xcode.FIFSTATEMENT);
        XnodeUtil.safeDelete(duplicateIf);
    }
    // Delete the old statements and pragma
    Xnode duplicateIf = thenDoStmt.body().matchDirectDescendant(Xcode.FIFSTATEMENT);
    duplicateIf.delete();
    XnodeUtil.safeDelete(_ifStmt);
    XnodeUtil.safeDelete(_doStmt);
    XnodeUtil.safeDelete(_claw.getPragma());
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode)

Aggregations

Xnode (cx2x.xcodeml.xnode.Xnode)31 Configuration (cx2x.translator.config.Configuration)12 AcceleratorGenerator (cx2x.translator.language.helper.accelerator.AcceleratorGenerator)12 IllegalDirectiveException (cx2x.xcodeml.exception.IllegalDirectiveException)12 ClawLanguage (cx2x.translator.language.base.ClawLanguage)11 ClawConstraint (cx2x.translator.language.common.ClawConstraint)6 Test (org.junit.Test)3 IllegalTransformationException (cx2x.xcodeml.exception.IllegalTransformationException)2 XcodeProgram (cx2x.xcodeml.xnode.XcodeProgram)2 File (java.io.File)2 ClawRange (cx2x.translator.language.common.ClawRange)1 ClawReshapeInfo (cx2x.translator.language.common.ClawReshapeInfo)1 ArrayToFctCall (cx2x.translator.transformation.claw.ArrayToFctCall)1 Kcaching (cx2x.translator.transformation.claw.Kcaching)1 Parallelize (cx2x.translator.transformation.claw.parallelize.Parallelize)1 ParallelizeForward (cx2x.translator.transformation.claw.parallelize.ParallelizeForward)1 DirectivePrimitive (cx2x.translator.transformation.openacc.DirectivePrimitive)1 OpenAccContinuation (cx2x.translator.transformation.openacc.OpenAccContinuation)1 XcodeMLWorkaround (cx2x.translator.transformation.utility.XcodeMLWorkaround)1 ClawTransformer (cx2x.translator.transformer.ClawTransformer)1