Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite pyccel omp handling for better support for other versions #1226

Draft
wants to merge 56 commits into
base: devel
Choose a base branch
from

Conversation

Hellio404
Copy link
Contributor

@Hellio404 Hellio404 commented Nov 1, 2022

This is an attempt to rewrite the way we are handling OpenMP annotated comments.

The main reason for the PR is to enable us to better support multiple versions of the OpenMP standards.
The other reason is to enable us to catch user errors before generating code and without "hardcoding" that in the semantic stage of the _visit_OmpAnnotatedComment function (here)

explain

This is a small explanation of how the new implementation works.

  • The main thing is we have multiple Openmp classes in the omp_versions directory each one represents the support for a OpenMP version
  • Openmp class has multiple subclasses representing every Omp Construct / Clause supported
  • Each Openmp class can inherit from a previous version so it is required to implement only the subclasses that represent the changed Omp Construct / Clause on that version.
  • Each subclass has 5 methods
    • visit_syntactic (called in the syntactic stage (used to get the FST and AST of the expressions inside clauses, call visit_syntactic for inner clauses, ...))
    • visit_sementic (called in the semantic stage (used to check if the variables inside clauses are already declared, validate the type of expression, and make sure a construct is in the right position / has the correct ending)
    • visit_cprint (called in the printing stage of C language and it returns the string to print in C)
    • visit_fprint
    • visit_pyprint

We select an Openmp class (from the omp_versions directory) that corresponds to the syntax version we need, then we use a function to extract all the subclasses related to an OpenMP Construct/Clause (subclasses starting with 'Omp') and provide those subclasses to Textx

the support for exit is limited to calls with integral arguments
or without arguments (same as exit(0))
Replace every class in the ast/omp.py with new classes
the new classes have the same name as the textx grammar rules
because these classes are used as the base classes for the textx
instead of the ones found in pyccel/parser/syntax/openmp.py
the version field will be used to store the version of the omp grammer
used for a Construct/Clause
this is done by making the grammer sets a version field for the Clause/Construct if there are multile versions of the grammer
the grammer is not finished an only supports parallel constructs and its clauses
instead of hardcoding the rules in the syntactic/semantic/printing stages we just delegate the work to the omp class new functions
there will be 5 functions _visit_syntatic, _visit_semantic, _cprint, _fprint, _pprint
those functions will be called from the syntactic/semantic/printing stages
and the omp class will be responsible for checking the if everything is corrent and provide the correct printing
this way we can support multiple version of omp withouth having to
duplicate the code and just use inheritance and override the methods
to change the behavior of the previous version
- add a version setter for the OmpAnnotatedComment class to be able to check if the syntax is supported by the version of omp
- fixing liter errors
@EmilyBourne
Copy link
Member

Is this a new problem compared to the previous implementation?

I think both implementations have this problem. Yes I will work on this.

Ok great. It looks like it's been a while since this branch was merged. Let me know if there's anything unfamiliar that you need a hand merging in

@EmilyBourne EmilyBourne removed the stale label Aug 3, 2023
@EmilyBourne EmilyBourne closed this Aug 3, 2023
@EmilyBourne EmilyBourne reopened this Aug 3, 2023
@pyccel-bot
Copy link

pyccel-bot bot commented Aug 3, 2023

Hello! Welcome to Pyccel! Thank you very much for your contribution ❤️.

I am the GitHub bot. I will help guide you through the different stages necessary to validate a review in Pyccel. If you haven't yet seen our developer docs make sure you check them out here. Amongst other things they describe the review process that we have just started. You can also get in touch with our other developers on our Pyccel Discord Server.

To begin with I will give you a short checklist to make sure your pull request is complete. Please tick items off when you have completed them or determined that they are not necessary for this pull request. If you want me to run any specific tests to check out corner cases that you can't easily check on your computer, you can request this using the command /bot run X. Use the command /bot show tests to see a full list of the tests I can run. Once you have finished preparing your pull request and are ready to request reviews just take your PR out of draft, or let me know with the command /bot mark as ready. I will then run the full suite of tests to check that everything is as neat as you think before asking other contributors for reviews. You can get a full list of commands that I understand using /bot commands.

Here is your checklist:

  • Update AUTHORS file
  • Write a clear PR description
  • Add tests to check your code works as expected
  • Update documentation if necessary
  • Update Changelog
  • Ensure any relevant issues are linked
  • Ensure new tests are passing

# Conflicts:
#	pyccel/ast/omp.py
#	pyccel/parser/semantic.py
- Implement omp syntax and semantic parser
- Implement omp c printer
- Make omp constructs aware of thier associated block.
- Defferentiate between construct and directive notions
…osition_end of omp elements inside the pragma, change directives and clauses description, semantic checks were skipped before this commit
…le allowed clauses in grammar to avoid duplicated data
…ctive may require a diffent syntax of the same clause, this is to allow grouping all forms of each clause in one single place
- Dynamically extend parsers and printers with openmp parsers and
  printers.
- Group functionalities common across omp versions.
- Implement Python and Fortran printers.
@rmahjoubi
Copy link
Member

Hello @EmilyBourne,

I'm looking for an overall feedback this new design, which is still in need of some polishing, documentation, and refactoring. Below is an overview of the current design and its status:

Status

  • Grammar: Majority of OpenMP 4.5 features are now supported.
  • Syntactic Parsing: Compatible with OpenMP 4.5 and OpenMP 5.0.
  • Semantic Parsing: Basic functionality has been implemented. I'm uncertain if implementing all semantic validations of OpenMP is feasible.
  • Printers: Compatible with OpenMP 4.5 and OpenMP 5.0.

Design Overview

  • OmpAnnotatedComment: This component groups functionalities common to all OpenMP objects.
  • OmpConstruct: Represents a directive associated with a code block and, optionally, an end directive.
  • Version-Specific Tools: Each OpenMP version has dedicated syntactic/semantic parsers and printers.
  • Parsing: Utilizes classes that dynamically inherit from Pyccel's parsers and those from an OpenMP version.
  • Specialized Directives and Clauses: OpenMP versions can define more specialized directive and clause classes to handle exceptional cases.
  • Inheritance Hierarchy:
    • Directive classes should inherit from OmpDirective.
    • Clause classes should inherit from OmpClause.
  • Printers Functionality: These use the raw statement of an OpenMP object provided in the comment. The segmentation of these statements allows for the suppression or tweaking of printing of segments correlated to the desired OpenMP object.
  • Printers: Similar to parsers, classes dynamically inherit from Pyccel's printers and those specific to an OpenMP version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants