Search in sources :

Example 36 with TestContext

use of helper.Utils.TestContext 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 37 with TestContext

use of helper.Utils.TestContext 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 38 with TestContext

use of helper.Utils.TestContext 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 39 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class XcodeProgTest method basicXcodeProgTest.

@Test
public void basicXcodeProgTest() {
    Context context = new TestContext();
    assertTrue(Files.exists(TestConstant.TEST_DATA));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DATA, context);
    assertNotNull(xcodeml);
    assertNotNull(xcodeml.getTime());
    assertNotNull(xcodeml.getCompilerInfo());
    assertNotNull(xcodeml.getVersion());
    assertNotNull(xcodeml.getLanguage());
    assertNotNull(xcodeml.getSource());
    assertNotNull(xcodeml.getSourceFileOnly());
    assertEquals("original_code.f90", xcodeml.getSourceFileOnly());
    assertEquals(8, xcodeml.getTypeTable().size());
    assertEquals(2, xcodeml.getGlobalSymbolsTable().size());
    assertEquals(2, xcodeml.getGlobalDeclarationsTable().size());
    // Try to add not meaningful messages in errors
    xcodeml.addError("");
    xcodeml.addError("", 0);
    xcodeml.addError(null, 0);
    assertFalse(xcodeml.hasErrors());
    assertTrue(xcodeml.getErrors().isEmpty());
    xcodeml.addError("Error1", 1);
    assertTrue(xcodeml.hasErrors());
    assertEquals(1, xcodeml.getErrors().size());
    // Try to add not meaningful messages in warnings
    xcodeml.addWarning("");
    xcodeml.addWarning(null, 0);
    xcodeml.addWarning("", 0);
    xcodeml.addWarning(null, Collections.emptyList());
    assertFalse(xcodeml.hasWarnings());
    assertTrue(xcodeml.getWarnings().isEmpty());
    xcodeml.addWarning("New warning 1", 1);
    assertTrue(xcodeml.hasWarnings());
    assertEquals(1, xcodeml.getWarnings().size());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Example 40 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class XnodeTest method utilityMethodTest.

@Test
public void utilityMethodTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    assertNotNull(xcodeml);
    List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
    assertFalse(pragmas.isEmpty());
    Xnode p = pragmas.get(0);
    assertNotNull(p.findParentFunction());
    assertNull(p.findParentFunction().findParentFunction());
    Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p.copyAttribute(p2, Xattr.LINENO);
    assertEquals("FpragmaStatement (children: 0) - 8", p2.toString());
    // No first child
    assertFalse(p.compareFirstChildValues(null));
    assertFalse(p.compareFirstChildValues(p2));
    // Depth
    assertTrue(p.depth() > 0);
    // Test attributes query and set
    assertNull(p2.child(10));
    p2.setBooleanAttribute(Xattr.IS_ASSUMED_SHAPE, false);
    assertFalse(p2.getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE));
    p2.removeAttribute(Xattr.IS_ASSUMED_SHAPE);
    assertFalse(p2.hasAttribute(Xattr.IS_ASSUMED_SHAPE));
    // Append/insert
    Xnode intConst = xcodeml.createIntConstant(10);
    FfunctionDefinition fctDef = p.findParentFunction();
    Xnode clone = intConst.cloneNode();
    assertNotNull(clone);
    assertNotEquals(clone.element(), intConst.element());
    fctDef.body().append(intConst);
    fctDef.body().append(clone);
    assertTrue(intConst.isDirectSibling(clone, Collections.emptyList()));
    fctDef.body().append(null);
    fctDef.body().insert(intConst, true);
    fctDef.body().insert(intConst);
    fctDef.body().insert(null);
    Xnode crt = intConst;
    while (crt != null) {
        assertNotNull(crt);
        crt = crt.prevSibling();
    }
    assertNotNull(fctDef.body().matchDirectDescendant(Xcode.F_PRAGMA_STATEMENT));
    assertNull(p.matchDirectDescendant(Xcode.F_PRAGMA_STATEMENT));
    // Methods should not crash on deleted node
    p.delete();
    assertTrue(p.depth() < 0);
    p.insertAfter(p2);
    p.insertBefore(p2);
    p.matchDescendant(Xcode.F_DO_STATEMENT);
    p.matchDirectDescendant(Xcode.F_DO_STATEMENT);
    p.matchDirectDescendant(Arrays.asList(Xcode.F_DO_STATEMENT, Xcode.F_DO_WHILE_STATEMENT));
    assertNull(p.nextSibling());
    assertNull(p.prevSibling());
    assertNull(p.matchSibling(Xcode.F_DO_STATEMENT));
    assertSame(p.matchAll(Xcode.F_PRAGMA_STATEMENT).size(), 0);
    assertFalse(p.isDirectSibling(null, Collections.emptyList()));
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Aggregations

TestContext (helper.Utils.TestContext)45 Context (claw.tatsu.common.Context)44 Test (org.junit.Test)43 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)22 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)20 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)9 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)4 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 XcodeML (claw.tatsu.xcodeml.xnode.common.XcodeML)2 TestConfiguration (helper.Utils.TestConfiguration)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 AnalyzedPragma (claw.shenron.translator.AnalyzedPragma)1 OpenAccConfiguration (claw.tatsu.directive.configuration.OpenAccConfiguration)1 OpenAcc (claw.tatsu.directive.generator.OpenAcc)1 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)1 HoistedNestedDoStatement (claw.tatsu.xcodeml.abstraction.HoistedNestedDoStatement)1 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)1 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)1 Before (org.junit.Before)1