Search in sources :

Example 26 with TestContext

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

the class TransformationAndGroupTest method basicTransformationTest.

@Test
public void basicTransformationTest() {
    Transformation t1 = new T1();
    assertTrue(t1.abortOnFailedAnalysis());
    assertEquals(0, t1.getStartLine());
    t1.setStartLine(10);
    assertEquals(10, t1.getStartLine());
    assertNull(t1.getDirective());
    assertFalse(t1.isTransformed());
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    Xnode pragma = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    pragma.setLine(10);
    t1 = new T1(new AnalyzedPragma(pragma));
    assertNotNull(t1.getDirective());
    assertNotNull(t1.getDirective().getPragma());
    assertEquals(10, t1.getStartLine());
}
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) AnalyzedPragma(claw.shenron.translator.AnalyzedPragma) Test(org.junit.Test)

Example 27 with TestContext

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

the class TransformationAndGroupTest method transformationGroupBaseTest.

@Test
public void transformationGroupBaseTest() {
    TransformationGroup ig = new IndependentTransformationGroup("loop-hoist");
    TransformationGroup dg = new DependentTransformationGroup("loop-fusion");
    groupTest(dg, "loop-fusion");
    groupTest(ig, "loop-hoist");
    Transformation t1 = new T1();
    ig.add(t1);
    assertEquals(1, ig.count());
    assertFalse(t1.isTransformed());
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    assertNotNull(xcodeml);
    try {
        ig.applyTransformations(xcodeml, null);
    } catch (Exception e) {
        fail();
    }
    assertTrue(t1.isTransformed());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 28 with TestContext

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

the class FieldTest method promoteTest.

@Test
public void promoteTest() {
    DimensionDefinition dim1 = new DimensionDefinition("dim1", "1", "30");
    DimensionDefinition dim2 = new DimensionDefinition("dim2", "1", "40");
    List<DimensionDefinition> dimensions1 = Collections.singletonList(dim1);
    List<DimensionDefinition> dimensions2 = Arrays.asList(dim1, dim2);
    Context context = new TestContext();
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PROMOTION, context);
    assertNotNull(xcodeml);
    List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
    assertEquals(1, fctDefs.size());
    FfunctionDefinition fctDef = fctDefs.get(0);
    assertEquals("sub1", fctDef.getName());
    // Scalar to array promotion with 1 additional dimension
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("s1", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("s2", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("s3", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
    // Scalar to array promotion with 2 additional dimension
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("s4", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("s5", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("s6", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
    // Promotion with 1 additional dimension
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("a", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 30, 1, 10, 1, 20 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("b", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 10, 1, 20, 1, 30 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("c", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 10, 1, 30, 1, 20 });
    // Promotion with 2 additional dimensions at the same position
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("d", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 40, 1, 10, 1, 20 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("e", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 20, 1, 30, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("f", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 30, 1, 40, 1, 20 });
    // Promotion with 2 additional dimensions at different position
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("g", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 30, 1, 20, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("h", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 10, 1, 40, 1, 20 });
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("i", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 10, 1, 20, 1, 40 });
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 29 with TestContext

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

the class PragmaTest method getCompilerDirectiveTest.

@Test
public void getCompilerDirectiveTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    Xnode n1 = xcodeml.createNode(Xcode.F_DO_STATEMENT);
    p1.setValue("claw loop-fusion");
    assertEquals(CompilerDirective.CLAW, Pragma.getCompilerDirective(p1));
    p1.setValue("omp teams distribute");
    assertEquals(CompilerDirective.OPENMP, Pragma.getCompilerDirective(p1));
    p1.setValue("acc parallel");
    assertEquals(CompilerDirective.OPENACC, Pragma.getCompilerDirective(p1));
    p1.setValue("ivdep");
    assertEquals(CompilerDirective.NONE, Pragma.getCompilerDirective(p1));
    assertEquals(CompilerDirective.NONE, Pragma.getCompilerDirective(null));
    assertEquals(CompilerDirective.NONE, Pragma.getCompilerDirective(n1));
}
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 30 with TestContext

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

the class PragmaTest method splitByContTest.

@Test
public void splitByContTest() {
    Context context = new TestContext();
    context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
    assertFalse(fctDefs.isEmpty());
    FfunctionDefinition fd = fctDefs.get(0);
    assertNotNull(fd.body());
    List<Xnode> previous = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
    Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    fd.body().append(p1);
    p1.setValue("acc data present(q,acc& p,acc& h)acc& create(pt)");
    try {
        Pragma.splitByCont(p1, CompilerDirective.OPENACC.getPrefix(), xcodeml);
        List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
        assertEquals(previous.size() + 4, splittedPragma.size());
    } catch (IllegalTransformationException e) {
        fail();
    }
    Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    fd.body().append(p2);
    p2.setValue("omp target teams omp& distribute simd");
    try {
        Pragma.splitByCont(p2, CompilerDirective.OPENMP.getPrefix(), xcodeml);
        List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
        assertEquals(previous.size() + 6, splittedPragma.size());
    } catch (IllegalTransformationException e) {
        fail();
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) 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