Search in sources :

Example 1 with Configuration

use of cx2x.translator.config.Configuration in project claw-compiler by C2SM-RCM.

the class ClawLanguageTest method analyzeValidLoopHoist.

/**
   * Assert the result for valid CLAW loop-hoist directive
   *
   * @param raw         Raw string value of the CLAW directive to be analyzed.
   * @param inductions  List of induction variables to be checked.
   * @param interchange If true, the interchange clause is set.
   * @param indexes     Interchange indexes values.
   * @param reshape     If true, the reshape clause is set.
   * @param infos       Reshape clause values.
   * @param targets     Target clause values. Null if not set.
   * @param fusion      If true, the fusion clause is set.
   * @param group       Group clause value. Null if not set.
   * @param collapse    Collapse clause value. 0 if not set.
   */
private void analyzeValidLoopHoist(String raw, List<String> inductions, boolean interchange, List<String> indexes, boolean reshape, List<ClawReshapeInfo> infos, List<Target> targets, boolean fusion, String group, int collapse) {
    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_HOIST, l.getDirective());
        assertEquals(inductions.size(), l.getHoistInductionVars().size());
        for (int i = 0; i < inductions.size(); ++i) {
            assertEquals(inductions.get(i), l.getHoistInductionVars().get(i));
        }
        if (interchange) {
            assertTrue(l.hasInterchangeClause());
        } else {
            assertFalse(l.hasInterchangeClause());
        }
        if (indexes != null) {
            for (int i = 0; i < indexes.size(); ++i) {
                assertEquals(indexes.get(i), l.getIndexes().get(i));
            }
        }
        if (reshape) {
            assertTrue(l.hasReshapeClause());
            assertEquals(infos.size(), l.getReshapeClauseValues().size());
            for (int i = 0; i < infos.size(); ++i) {
                assertEquals(infos.get(i).getArrayName(), l.getReshapeClauseValues().get(i).getArrayName());
                assertEquals(infos.get(i).getTargetDimension(), l.getReshapeClauseValues().get(i).getTargetDimension());
                List<Integer> expected = infos.get(i).getKeptDimensions();
                List<Integer> actual = l.getReshapeClauseValues().get(i).getKeptDimensions();
                assertEquals(expected.size(), actual.size());
                for (int j = 0; j < expected.size(); ++j) {
                    assertEquals(expected.get(j), actual.get(j));
                }
            }
        } else {
            assertFalse(l.hasReshapeClause());
        }
        assertTargets(l, targets);
        assertEquals(fusion, l.hasFusionClause());
        if (group != null) {
            assertTrue(l.hasGroupClause());
            assertEquals(group, l.getGroupValue());
        } else {
            assertFalse(l.hasGroupClause());
        }
        if (collapse > 0) {
            assertTrue(l.hasCollapseClause());
            assertEquals(collapse, l.getCollapseValue());
        } else {
            assertFalse(l.hasCollapseClause());
        }
    } 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 2 with Configuration

use of cx2x.translator.config.Configuration in project claw-compiler by C2SM-RCM.

the class ClawLanguageTest method analyzeValidArrayTransform.

/**
   * Assert the result for valid CLAW array-transform directive
   *
   * @param raw         Raw string value of the CLAW directive to be analyzed.
   * @param fusion      Set to true if the extracted option should be present.
   * @param fusionGroup Name of the group in the extracted fusion option.
   * @param parallel    Set to true if the extracted option should be present.
   * @param acc         String of acc clauses that should be present.
   */
private void analyzeValidArrayTransform(String raw, boolean fusion, String fusionGroup, boolean parallel, String acc, List<String> inducNames, 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_TRANSFORM, l.getDirective());
        if (fusion) {
            assertTrue(l.hasFusionClause());
            assertEquals(fusionGroup, l.getGroupValue());
        } else {
            assertFalse(l.hasFusionClause());
            assertNull(l.getGroupValue());
        }
        if (parallel) {
            assertTrue(l.hasParallelClause());
        } else {
            assertFalse(l.hasParallelClause());
        }
        if (acc != null) {
            assertTrue(l.hasAcceleratorClause());
            assertEquals(acc, l.getAcceleratorClauses());
        } else {
            assertFalse(l.hasAcceleratorClause());
        }
        if (inducNames != null) {
            assertTrue(l.hasInductionClause());
            assertEquals(inducNames.size(), l.getInductionValues().size());
            for (int i = 0; i < inducNames.size(); ++i) {
                assertEquals(inducNames.get(i), l.getInductionValues().get(i));
            }
        } else {
            assertFalse(l.hasInductionClause());
        }
        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 3 with Configuration

use of cx2x.translator.config.Configuration in project claw-compiler by C2SM-RCM.

the class ClawLanguageTest method analyzeErrors.

private void analyzeErrors(String pragma, int nbExpectedToken) {
    Xnode p = XmlHelper.createXpragma();
    p.setValue(pragma);
    p.setLine(1);
    Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
    AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
    try {
        ClawLanguage.analyze(p, generator, Target.GPU);
    } catch (IllegalDirectiveException e) {
        if (nbExpectedToken != 0) {
            assertEquals(nbExpectedToken, e.getExpectedTokens().size());
        }
        assertNotNull(e.getMessage());
    }
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode) IllegalDirectiveException(cx2x.xcodeml.exception.IllegalDirectiveException) Configuration(cx2x.translator.config.Configuration) AcceleratorGenerator(cx2x.translator.language.helper.accelerator.AcceleratorGenerator)

Example 4 with Configuration

use of cx2x.translator.config.Configuration in project claw-compiler by C2SM-RCM.

the class ClawLanguageTest method analyzeValidKcache.

/**
   * Assert the result for valid CLAW kcache directive
   *
   * @param raw     Raw string value of the CLAW directive to be analyzed.
   * @param data    List of identifiers to be checked.
   * @param offsets List of offsets to be checked.
   * @param init    If true, check that ClawLanguage object has init clause
   *                enabled.
   */
private void analyzeValidKcache(String raw, List<String> data, List<Integer> offsets, boolean init, boolean hasPrivate, 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.KCACHE, l.getDirective());
        if (data != null) {
            assertTrue(l.hasDataClause());
            assertEquals(data.size(), l.getDataClauseValues().size());
            for (int i = 0; i < data.size(); ++i) {
                assertEquals(data.get(i), l.getDataClauseValues().get(i));
            }
        } else {
            assertFalse(l.hasDataClause());
        }
        if (offsets != null) {
            assertEquals(offsets.size(), l.getOffsets().size());
            for (int i = 0; i < offsets.size(); ++i) {
                assertEquals(offsets.get(i), l.getOffsets().get(i));
            }
        }
        if (init) {
            assertTrue(l.hasInitClause());
        } else {
            assertFalse(l.hasInitClause());
        }
        if (hasPrivate) {
            assertTrue(l.hasPrivateClause());
        } else {
            assertFalse(l.hasPrivateClause());
        }
        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 5 with Configuration

use of cx2x.translator.config.Configuration in project claw-compiler by C2SM-RCM.

the class ClawLanguageTest method analyzeValidClawLoopFusion.

/**
   * Assert the result for valid loop fusion CLAW directive
   *
   * @param raw       Raw string value of the CLAW directive to be analyzed.
   * @param groupName Group name to be found if any.
   */
private void analyzeValidClawLoopFusion(String raw, String groupName, boolean collapse, int n, List<Target> targets, ClawConstraint constraint) {
    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_FUSION, l.getDirective());
        if (groupName != null) {
            assertTrue(l.hasGroupClause());
            assertEquals(groupName, l.getGroupValue());
        } else {
            assertFalse(l.hasGroupClause());
            assertNull(l.getGroupValue());
        }
        if (collapse) {
            assertTrue(l.hasCollapseClause());
            assertEquals(n, l.getCollapseValue());
        } else {
            assertFalse(l.hasCollapseClause());
        }
        if (constraint != null) {
            assertTrue(l.hasConstraintClause());
            assertEquals(constraint, l.getConstraintClauseValue());
        } else {
            assertFalse(l.hasConstraintClause());
        }
        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)

Aggregations

Configuration (cx2x.translator.config.Configuration)14 AcceleratorGenerator (cx2x.translator.language.helper.accelerator.AcceleratorGenerator)12 Xnode (cx2x.xcodeml.xnode.Xnode)12 IllegalDirectiveException (cx2x.xcodeml.exception.IllegalDirectiveException)11 ClawLanguage (cx2x.translator.language.base.ClawLanguage)10 ClawConstraint (cx2x.translator.language.common.ClawConstraint)5 GroupConfiguration (cx2x.translator.config.GroupConfiguration)2 File (java.io.File)2 FortranDecompiler (cx2x.decompiler.FortranDecompiler)1 ClawXcodeMlTranslator (cx2x.translator.ClawXcodeMlTranslator)1 ClawTransformationReport (cx2x.translator.report.ClawTransformationReport)1 ClawTransformer (cx2x.translator.transformer.ClawTransformer)1 XcodeProgram (cx2x.xcodeml.xnode.XcodeProgram)1 Test (org.junit.Test)1