use of cx2x.translator.config.Configuration in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidClawLoopExtract.
/**
* Assert the result for valid loop extract CLAW directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param induction Induction var to be found.
* @param lower Lower bound value to be found.
* @param upper Upper bound value to be found.
* @param step Step valu to be found if any.
*/
private ClawLanguage analyzeValidClawLoopExtract(String raw, String induction, String lower, String upper, String step, 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_EXTRACT, l.getDirective());
assertEquals(induction, l.getRange().getInductionVar());
assertEquals(lower, l.getRange().getLowerBound());
assertEquals(upper, l.getRange().getUpperBound());
if (step != null) {
assertEquals(step, l.getRange().getStep());
}
assertTargets(l, targets);
return l;
} catch (IllegalDirectiveException idex) {
System.err.println(idex.getMessage());
fail();
return null;
}
}
use of cx2x.translator.config.Configuration in project claw-compiler by C2SM-RCM.
the class Cx2x method main.
/**
* Main point of entry of the program.
*
* @param args Arguments of the program.
* @throws Exception if translation failed.
*/
public static void main(String[] args) throws Exception {
String input;
String xcodeMlOutput = null;
String fortranOutput = null;
String target_option = null;
String directive_option = null;
String configuration_path = null;
String schema_path = null;
int maxColumns = 0;
boolean forcePure = false;
CommandLine cmd;
try {
cmd = processCommandArgs(args);
} catch (ParseException pex) {
error(pex.getMessage());
return;
}
// Help option
if (cmd.hasOption("h")) {
usage();
return;
}
// Display target list option
if (cmd.hasOption("tl")) {
listTarget();
return;
}
// Display directive list option
if (cmd.hasOption("dl")) {
listDirectiveLanguage();
return;
}
// Target option
if (cmd.hasOption("t")) {
target_option = cmd.getOptionValue("t");
}
// Directive option
if (cmd.hasOption("dir")) {
directive_option = cmd.getOptionValue("dir");
}
// Suppressing line directive option
if (cmd.hasOption("l")) {
XmOption.setIsSuppressLineDirective(true);
}
// Debug option
if (cmd.hasOption("d")) {
XmOption.setDebugOutput(true);
}
// XcodeML/F output file option
if (cmd.hasOption("o")) {
xcodeMlOutput = cmd.getOptionValue("o");
}
// FORTRAN output file option
if (cmd.hasOption("f")) {
fortranOutput = cmd.getOptionValue("f");
}
if (cmd.hasOption("w")) {
maxColumns = Integer.parseInt(cmd.getOptionValue("w"));
}
if (cmd.hasOption("c")) {
configuration_path = cmd.getOptionValue("c");
}
if (cmd.hasOption("s")) {
schema_path = cmd.getOptionValue("s");
}
// Check that configuration file exists
if (configuration_path == null) {
error("Configuration file missing.");
return;
}
File configFile = new File(configuration_path);
if (!configFile.exists()) {
error("Configuration file not found. " + configuration_path);
}
if (cmd.hasOption("sc")) {
showConfig(configuration_path, schema_path);
return;
}
if (cmd.getArgs().length == 0) {
error("no input file");
return;
} else {
input = cmd.getArgs()[0];
}
// Module search path options
if (cmd.hasOption("M")) {
for (String value : cmd.getOptionValues("M")) {
XcodeMLtools_Fmod.addSearchPath(value);
}
}
// Read the configuration file
Configuration config;
try {
config = new Configuration(configuration_path, schema_path);
config.setUserDefinedTarget(target_option);
config.setUserDefineDirective(directive_option);
config.setMaxColumns(maxColumns);
} catch (Exception ex) {
error(ex.getMessage());
return;
}
// Force pure option
if (cmd.hasOption("fp")) {
config.setForcePure();
}
// Call the translator to apply transformation on XcodeML/F
ClawXcodeMlTranslator translator = new ClawXcodeMlTranslator(input, xcodeMlOutput, config);
translator.analyze();
translator.transform();
translator.flush(config);
// Produce report
if (cmd.hasOption("r")) {
ClawTransformationReport report = new ClawTransformationReport(cmd.getOptionValue("r"));
report.generate(config, args, translator);
}
// Decompile XcodeML/F to Fortran
FortranDecompiler decompiler = new FortranDecompiler();
if (!decompiler.decompile(fortranOutput, xcodeMlOutput, maxColumns, XmOption.isSuppressLineDirective())) {
error("Unable to decompile XcodeML to Fortran");
}
}
use of cx2x.translator.config.Configuration in project claw-compiler by C2SM-RCM.
the class Cx2x method showConfig.
/**
* Read the configuration file and output the information for user.
*
* @param configPath Path to the configuration file.
* @param schemaPath Path to the XSD schema for configuration file validation.
*/
private static void showConfig(String configPath, String schemaPath) {
try {
Configuration config = new Configuration(configPath, schemaPath);
System.out.println("- CLAW translator configuration -\n");
System.out.println("Default accelerator directive: " + config.getCurrentDirective() + "\n");
System.out.println("Default target: " + config.getCurrentTarget() + "\n");
System.out.println("Current transformation order:");
int i = 0;
for (GroupConfiguration g : config.getGroups()) {
System.out.printf(" %1d) %-20s - type:%-15s, class:%-60s\n", i++, g.getName(), g.getType(), g.getTransformationClassName());
}
} catch (Exception e) {
error("Could not read the configuration file.\n" + e.getMessage());
}
}
use of cx2x.translator.config.Configuration 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() {
// Load test data file
File f = new File(TestConstant.TEST_DEPENDENCE_3D);
assertTrue(f.exists());
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DEPENDENCE_3D);
assertNotNull(xcodeml);
// Match all the function definitions
List<Xnode> functions = xcodeml.matchAll(Xcode.FFUNCTIONDEFINITION);
assertEquals(2, functions.size());
// Match all the pragmas
List<Xnode> pragmas = xcodeml.matchAll(Xcode.FPRAGMASTATEMENT);
assertEquals(1, pragmas.size());
// Analyze the pragma
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
configuration.setMaxColumns(80);
ClawTransformer transformer = new ClawTransformer(configuration);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
ClawLanguage main = null;
try {
main = ClawLanguage.analyze(pragmas.get(0), generator, Target.GPU);
} catch (Exception e) {
fail();
}
// 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.FDOSTATEMENT);
assertEquals(11, loops.size());
// Create an iteration space
try {
IterationSpace is = new IterationSpace(loops);
is.tryFusion(xcodeml, transformer, main);
System.out.println();
System.out.println("Iteration space before fusion");
is.printDebug(true);
loops = fctDef.matchAll(Xcode.FDOSTATEMENT);
assertEquals(8, loops.size());
is.reload(loops);
System.out.println();
System.out.println("Iteration space after fusion");
is.printDebug(true);
} catch (Exception e) {
fail();
}
}
use of cx2x.translator.config.Configuration in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidParallelize.
/**
* Assert the result for valid CLAW parallelize directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param data Reference list for the data clause values.
* @param over Reference list for the over clause values.
* @param dimensions Reference list of dimensions.
* @param copyClause Expected value for copy clause (Null if no copy clause)
* @param updateClause Expected value for update clause
* (Null if no update clause)
*/
private void analyzeValidParallelize(String raw, List<List<String>> data, List<List<String>> over, List<ClawDimension> dimensions, ClawDMD copyClause, ClawDMD updateClause) {
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.PARALLELIZE, l.getDirective());
if (data != null) {
assertTrue(l.hasOverDataClause());
assertEquals(data.size(), l.getOverDataClauseValues().size());
for (int i = 0; i < data.size(); ++i) {
assertEquals(data.get(i).size(), l.getOverDataClauseValues().get(i).size());
for (int j = 0; j < data.get(i).size(); ++j) {
assertEquals(data.get(i).get(j), l.getOverDataClauseValues().get(i).get(j));
}
}
}
if (over != null) {
assertTrue(l.hasOverClause());
assertEquals(over.size(), l.getOverClauseValues().size());
for (int i = 0; i < over.size(); ++i) {
assertEquals(over.get(i).size(), l.getOverClauseValues().get(i).size());
for (int j = 0; j < over.get(i).size(); ++j) {
assertEquals(over.get(i).get(j), l.getOverClauseValues().get(i).get(j));
}
}
}
if (dimensions != null) {
assertEquals(dimensions.size(), l.getDimensionValues().size());
for (int i = 0; i < dimensions.size(); ++i) {
assertEquals(dimensions.get(i).getIdentifier(), l.getDimensionValues().get(i).getIdentifier());
assertEquals(dimensions.get(i).lowerBoundIsVar(), l.getDimensionValues().get(i).lowerBoundIsVar());
assertEquals(dimensions.get(i).upperBoundIsVar(), l.getDimensionValues().get(i).upperBoundIsVar());
assertEquals(dimensions.get(i).getLowerBoundInt(), l.getDimensionValues().get(i).getLowerBoundInt());
assertEquals(dimensions.get(i).getUpperBoundInt(), l.getDimensionValues().get(i).getUpperBoundInt());
assertEquals(dimensions.get(i).getLowerBoundId(), l.getDimensionValues().get(i).getLowerBoundId());
assertEquals(dimensions.get(i).getUpperBoundId(), l.getDimensionValues().get(i).getUpperBoundId());
}
}
if (data == null && over == null && dimensions == null) {
assertTrue(l.hasForwardClause());
}
if (copyClause == null) {
assertFalse(l.hasCopyClause());
assertNull(l.getCopyClauseValue());
} else {
assertTrue(l.hasCopyClause());
assertEquals(copyClause, l.getCopyClauseValue());
}
if (updateClause == null) {
assertFalse(l.hasUpdateClause());
assertNull(l.getUpdateClauseValue());
} else {
assertTrue(l.hasUpdateClause());
assertEquals(updateClause, l.getUpdateClauseValue());
}
} catch (IllegalDirectiveException idex) {
System.err.print(idex.getMessage());
fail();
}
}
Aggregations