Search in sources :

Example 1 with OpenMpConfiguration

use of claw.tatsu.directive.configuration.OpenMpConfiguration in project claw-compiler by C2SM-RCM.

the class Configuration method init.

/**
 * Constructs basic configuration object.
 *
 * @param directive Accelerator directive language.
 * @param target    Target architecture.
 */
public void init(CompilerDirective directive, Target target) {
    _parameters = new HashMap<>();
    if (directive == null) {
        directive = CompilerDirective.NONE;
    }
    _parameters.put(DEFAULT_DIRECTIVE, directive.toString());
    if (target != null) {
        _parameters.put(DEFAULT_TARGET, target.toString());
    }
    // Init specific configuration if needed
    switch(directive) {
        case OPENACC:
            _accelerator = new OpenAccConfiguration(_parameters);
            break;
        case OPENMP:
            _accelerator = new OpenMpConfiguration(_parameters);
            break;
        default:
            _accelerator = new AcceleratorConfiguration(_parameters);
            break;
    }
    _groups = new ArrayList<>();
    _availableGroups = new HashMap<>();
}
Also used : AcceleratorConfiguration(claw.tatsu.directive.configuration.AcceleratorConfiguration) OpenMpConfiguration(claw.tatsu.directive.configuration.OpenMpConfiguration) OpenAccConfiguration(claw.tatsu.directive.configuration.OpenAccConfiguration)

Example 2 with OpenMpConfiguration

use of claw.tatsu.directive.configuration.OpenMpConfiguration in project claw-compiler by C2SM-RCM.

the class Context method init.

public void init(CompilerDirective compilerDirective, Target target, AcceleratorConfiguration acceleratorConfiguration, int maxColumns) {
    if (compilerDirective != null) {
        _compilerDirective = compilerDirective;
        if (compilerDirective == CompilerDirective.OPENACC) {
            OpenAcc gen = new OpenAcc(this);
            _directiveGenerator = gen;
            if (acceleratorConfiguration != null) {
                gen.setExecutionMode(((OpenAccConfiguration) acceleratorConfiguration).getMode());
            }
        } else if (compilerDirective == CompilerDirective.OPENMP) {
            OpenMp gen = new OpenMp(this);
            _directiveGenerator = gen;
            if (acceleratorConfiguration != null) {
                gen.setExecutionMode(((OpenMpConfiguration) acceleratorConfiguration).getMode());
            }
        } else {
            _directiveGenerator = new DirectiveNone();
        }
    } else {
        _compilerDirective = CompilerDirective.NONE;
        _directiveGenerator = new DirectiveNone();
    }
    _acceleratorConfiguration = acceleratorConfiguration;
    if (target == null) {
        _target = Target.NONE;
    } else {
        _target = target;
    }
    _maxColumns = maxColumns;
    _moduleCache = new ModuleCache();
}
Also used : OpenMp(claw.tatsu.directive.generator.OpenMp) ModuleCache(claw.tatsu.xcodeml.module.ModuleCache) OpenAcc(claw.tatsu.directive.generator.OpenAcc) OpenMpConfiguration(claw.tatsu.directive.configuration.OpenMpConfiguration) DirectiveNone(claw.tatsu.directive.generator.DirectiveNone)

Example 3 with OpenMpConfiguration

use of claw.tatsu.directive.configuration.OpenMpConfiguration in project claw-compiler by C2SM-RCM.

the class OpenMp method getStartLoopDirective.

@Override
public String[] getStartLoopDirective(int value, boolean seq, boolean naked, String clauses) {
    // serial loop is the default behaviour for OpenMP
    if (seq) {
        return new String[0];
    }
    clauses = clauses.trim();
    if (clauses.length() > 0) {
        clauses += " ";
    }
    if (value > 1) {
        clauses += String.format("%s(%d) ", OPENMP_COLLAPSE, value);
    }
    OpenMpConfiguration ompConfig = (OpenMpConfiguration) context().getAcceleratorConfig();
    int chunkSize = ompConfig.getSchedulerChunkSize();
    String scheduler = "";
    if (chunkSize > 0) {
        scheduler = String.format("%s(%s, %d)", OPENMP_DIST_SCHEDULE, OPENMP_SCHEDULE_KIND, chunkSize);
    }
    if (context().isTarget(Target.GPU)) {
        // !$omp distribute [collapse(#)] [dist_schedule(static,#)]
        if (clauses.isEmpty()) {
            return new String[] { String.format(FORMAT3, OPENMP_PREFIX, OPENMP_DISTRIBUTE, scheduler) };
        } else {
            return new String[] { String.format(FORMAT3, OPENMP_PREFIX, OPENMP_DISTRIBUTE, scheduler) + " " + clauses };
        }
    } else {
        // !$omp do [collapse(#)]
        if (clauses.isEmpty()) {
            return new String[] { String.format(FORMAT2, OPENMP_PREFIX, OPENMP_DO) };
        } else {
            return new String[] { String.format(FORMAT2, OPENMP_PREFIX, OPENMP_DO) + " " + clauses };
        }
    }
}
Also used : OpenMpConfiguration(claw.tatsu.directive.configuration.OpenMpConfiguration)

Example 4 with OpenMpConfiguration

use of claw.tatsu.directive.configuration.OpenMpConfiguration in project claw-compiler by C2SM-RCM.

the class OpenMp method getStartParallelDirective.

@Override
public String[] getStartParallelDirective(String clauses) {
    // TODO handle possible clauses
    if (context().isTarget(Target.GPU)) {
        // !$omp teams [num_teams(#)] [thread_limit(#)]
        if (clauses == null) {
            clauses = "";
        } else {
            clauses = clauses.trim();
        }
        OpenMpConfiguration ompConfig = (OpenMpConfiguration) context().getAcceleratorConfig();
        int numThreads = ompConfig.getNumThreads();
        int numTeams = ompConfig.getNumTeams();
        if (numThreads > 0) {
            clauses += String.format("%s(%d)", OPENMP_THREADS_LIMIT, numThreads);
        }
        if (numTeams > 0) {
            clauses += String.format(" %s(%d)", OPENMP_NUM_TEAMS, numTeams);
        }
        if (clauses.isEmpty()) {
            return new String[] { String.format(FORMAT2, OPENMP_PREFIX, OPENMP_TARGET), String.format(FORMAT2, OPENMP_PREFIX, OPENMP_TEAMS) };
        } else {
            return new String[] { String.format(FORMAT2, OPENMP_PREFIX, OPENMP_TARGET), String.format(FORMAT2, OPENMP_PREFIX, OPENMP_TEAMS) + " " + clauses };
        }
    } else {
        // !$omp parallel
        return new String[] { String.format(FORMAT2, OPENMP_PREFIX, OPENMP_PARALLEL) };
    }
}
Also used : OpenMpConfiguration(claw.tatsu.directive.configuration.OpenMpConfiguration)

Aggregations

OpenMpConfiguration (claw.tatsu.directive.configuration.OpenMpConfiguration)4 AcceleratorConfiguration (claw.tatsu.directive.configuration.AcceleratorConfiguration)1 OpenAccConfiguration (claw.tatsu.directive.configuration.OpenAccConfiguration)1 DirectiveNone (claw.tatsu.directive.generator.DirectiveNone)1 OpenAcc (claw.tatsu.directive.generator.OpenAcc)1 OpenMp (claw.tatsu.directive.generator.OpenMp)1 ModuleCache (claw.tatsu.xcodeml.module.ModuleCache)1