Search in sources :

Example 21 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class DependenceAnalysisTest method perfectlyNestedNoDependencyTest.

@Test
public void perfectlyNestedNoDependencyTest() {
    Context context = new TestContext();
    // Load test data file
    assertTrue(Files.exists(TestConstant.TEST_PERFECTLY_NESTED_NO_DEP));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PERFECTLY_NESTED_NO_DEP, context);
    assertNotNull(xcodeml);
    // Match all the function definitions
    List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
    assertEquals(1, functions.size());
    // Match all the pragmas
    List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
    assertEquals(1, pragmas.size());
    // Analyze the pragma
    context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
    // Get the function definition that interests us
    Xnode fctDef = functions.get(0);
    // Match all the do statements in the function
    List<Xnode> loops = fctDef.matchAll(Xcode.F_DO_STATEMENT);
    assertEquals(2, loops.size());
    // Create an iteration space
    try {
        IterationSpace is = new IterationSpace(loops);
        System.out.println();
        assertEquals(2, is.getNbLevel());
        is.printDebug(true);
        assertTrue(is.isPerfectlyNested());
    } catch (Exception e) {
        fail();
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 22 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class DependenceAnalysisTest method analyzeTest3d.

/**
 * Test the IterationSpace feature of fusion and check the results.
 */
@Test
public void analyzeTest3d() {
    Context context = new TestContext();
    // Load test data file
    assertTrue(Files.exists(TestConstant.TEST_DEPENDENCE_3D));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DEPENDENCE_3D, context);
    assertNotNull(xcodeml);
    // Match all the function definitions
    List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
    assertEquals(2, functions.size());
    // Match all the pragmas
    List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
    assertEquals(1, pragmas.size());
    // Analyze the pragma
    context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
    // Get the function definition that interests us
    Xnode fctDef = functions.get(0);
    // Match all the do statements in the function
    List<Xnode> loops = fctDef.matchAll(Xcode.F_DO_STATEMENT);
    assertEquals(11, loops.size());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 23 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class DependenceAnalysisTest method analyzeTest.

/**
 * Test the analysis feature of the DependenceAnalysis class.
 */
@Test
public void analyzeTest() {
    Context context = new TestContext();
    // Load test data file
    assertTrue(Files.exists(TestConstant.TEST_DEPENDENCE));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DEPENDENCE, context);
    assertNotNull(xcodeml);
    // Match all the function definitions
    List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
    assertEquals(2, functions.size());
    // Match all the pragma
    List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
    assertEquals(1, pragmas.size());
    // Get the function definition that interests us
    Xnode fctDef = functions.get(0);
    List<Xnode> loops = fctDef.matchAll(Xcode.F_DO_STATEMENT);
    assertEquals(10, loops.size());
    // Create dependence analysis object for each do statement
    List<DependenceAnalysis> dependencies = new ArrayList<>();
    for (Xnode loop : loops) {
        try {
            dependencies.add(new DependenceAnalysis(loop));
        } catch (Exception e) {
            fail();
        }
    }
    // Assert the information for each do statement
    assertTrue(dependencies.get(0).isIndependent());
    assertTrue(dependencies.get(1).isIndependent());
    assertTrue(dependencies.get(2).isIndependent());
    assertFalse(dependencies.get(3).isIndependent());
    assertEquals(1, dependencies.get(3).getDistanceVector());
    assertEquals(DependenceDirection.BACKWARD, dependencies.get(3).getDirectionVector());
    assertFalse(dependencies.get(4).isIndependent());
    assertEquals(1, dependencies.get(4).getDistanceVector());
    assertEquals(DependenceDirection.FORWARD, dependencies.get(4).getDirectionVector());
    assertFalse(dependencies.get(5).isIndependent());
    assertEquals(1, dependencies.get(5).getDistanceVector());
    assertEquals(DependenceDirection.FORWARD, dependencies.get(5).getDirectionVector());
    assertFalse(dependencies.get(6).isIndependent());
    assertEquals(1, dependencies.get(6).getDistanceVector());
    assertEquals(DependenceDirection.BACKWARD, dependencies.get(6).getDirectionVector());
    assertTrue(dependencies.get(7).isIndependent());
    assertTrue(dependencies.get(8).isIndependent());
    assertTrue(dependencies.get(9).isIndependent());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) ArrayList(java.util.ArrayList) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 24 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class ConditionTest method dependsOnTest.

@Test
public void dependsOnTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ASSIGN_STMT, context);
    assertNotNull(xcodeml);
    List<Xnode> nodes = xcodeml.matchAll(Xcode.F_IF_STATEMENT);
    assertEquals(1, nodes.size());
    Xnode ifStmt = nodes.get(0);
    assertEquals(Xcode.F_IF_STATEMENT, ifStmt.opcode());
    Xnode condition = ifStmt.matchDirectDescendant(Xcode.CONDITION);
    assertNotNull(condition);
    assertFalse(Condition.dependsOn(condition, Collections.emptySet()));
    assertFalse(Condition.dependsOn(null, Collections.singleton("t")));
    assertFalse(Condition.dependsOn(ifStmt, Collections.singleton("t")));
    assertTrue(Condition.dependsOn(condition, Collections.singleton("t")));
    assertFalse(Condition.dependsOn(condition, Collections.singleton("k")));
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 25 with XcodeProgram

use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.

the class DimensionTest method boundDefinitionTest.

@Test
public void boundDefinitionTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    BoundDefinition lowerBound = new BoundDefinition("1", BoundDefinition.BoundType.LOWER);
    BoundDefinition upperBound = new BoundDefinition("nend", BoundDefinition.BoundType.LOWER);
    BoundDefinition step = new BoundDefinition("1", BoundDefinition.BoundType.STEP);
    assertFalse(lowerBound.isVar());
    assertTrue(upperBound.isVar());
    assertFalse(step.isVar());
    assertEquals(1, lowerBound.getIntValue());
    assertEquals("nend", upperBound.getValue());
    assertEquals(1, step.getIntValue());
    Xnode lowerNode = lowerBound.generate(xcodeml);
    assertNotNull(lowerNode);
    assertNotNull(lowerNode.firstChild());
    assertEquals(Xcode.F_INT_CONSTANT, lowerNode.firstChild().opcode());
    assertEquals("1", lowerNode.firstChild().value());
    Xnode upperNode = upperBound.generate(xcodeml);
    assertNotNull(upperNode);
    assertNotNull(upperNode.firstChild());
    assertEquals(Xcode.VAR, upperNode.firstChild().opcode());
    assertEquals("nend", upperNode.firstChild().value());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Aggregations

XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)25 Context (claw.tatsu.common.Context)24 TestContext (helper.Utils.TestContext)22 Test (org.junit.Test)22 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)20 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)7 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)4 ArrayList (java.util.ArrayList)3 Transformation (claw.shenron.transformation.Transformation)2 Translator (claw.shenron.translator.Translator)2 Target (claw.tatsu.common.Target)2 DataMovement (claw.tatsu.directive.common.DataMovement)2 Directive (claw.tatsu.directive.common.Directive)2 Range (claw.tatsu.primitive.Range)2 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)2 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)2 XnodeUtil (claw.tatsu.xcodeml.xnode.XnodeUtil)2 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)2 Xcode (claw.tatsu.xcodeml.xnode.common.Xcode)2 Xid (claw.tatsu.xcodeml.xnode.common.Xid)2