Skip to content

Conversation

@LonelyCat124
Copy link
Collaborator

@LonelyCat124 LonelyCat124 commented Dec 9, 2025

Example and doc TODO

Basic implementation of PSyDirective including reading and writing.

At the moment I implemented it as a Standalone Directive (as it doesn't make sense to me to be a RegionDirective) but that could be more difficult to use in some ways, but I'll put together an example and see.

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.95%. Comparing base (2823f9d) to head (c541e7f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3255   +/-   ##
=======================================
  Coverage   99.95%   99.95%           
=======================================
  Files         376      377    +1     
  Lines       53545    53580   +35     
=======================================
+ Hits        53523    53558   +35     
  Misses         22       22           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sergisiso
Copy link
Collaborator

I still don't think we need psyclone (!$psy) specific directives, I thought the plan was to add a generic Directive node, so that we could do psyir.walk(Directive) as an slight improvement to the current psyir.walk(Codeblock) (which tbh is almost the same as this PR implements, just with a slighly different _directive_handler)

@LonelyCat124
Copy link
Collaborator Author

We could do that instead, but it would mean more false positives when people are looking for something specific to their script, e.g. after psyir.walk(???Directive) (name is not straightforward as we can't make it Directive since thats a necessary abstract class, along with StandaloneDirective and RegionDirective nodes. The other pain point is taking things out of CodeBlocks is it could be misinterpreted as support for them, and having non-RegionDirective nodes having to be StandaloneDirective subclasses.

I would maybe with ok with doing some GenericDirective and excluding all directives that start omp, ompx, omx, acc if you think that would be better?

@sergisiso
Copy link
Collaborator

sergisiso commented Dec 9, 2025

name is not straightforward as we can't make it Directive since thats a necessary abstract class, ...
The other pain point is taking things out of CodeBlocks is it could be misinterpreted as support for them
I would maybe with ok with doing some GenericDirective

Good points, what about [Unrecognised/Unsupported/Unknown]Directive (being sibling of Standalone/RegionDirective)?

So it is clear that we don't support them and if we ever try to parse OpenMP, OpenACC into their own Directive the name will still make sense for those that we have not done yet. (my preferd is UnknownDirective, but I am unsure)

but it would mean more false positives when people are looking for something specific to their script

I don't understand this. It will be better than the current Codeblock, and it would allow searching for "ivdep" or other know compiler directive that may exist in the code.

excluding all directives that start omp, ompx, omx, acc

Why excluding those?

@LonelyCat124
Copy link
Collaborator Author

Yeah I agree with most of that, so I'll modify this PR towards that.

My reasoning for ignoring omp/acc/etc. directives is party that keeping them as CodeBlocks means they'd keep any current properties that CodeBlocks have (i.e. disabling transformations etc.) and also make it clear that they're not meant to be used as part of any tree manipulation programming, but are just for keeping elements of the source code that PSyclone doesn't or can't support.

@LonelyCat124
Copy link
Collaborator Author

@sergisiso this is ready for review, but no rush to do so.

@LonelyCat124 LonelyCat124 marked this pull request as ready for review December 15, 2025 10:33
Copy link
Collaborator

@sergisiso sergisiso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LonelyCat124 I like how this is implemented now, and especially having an example to showcase it. There are just minor comments now.

Directive representing PSyclone-specific directives in the tree.
:param directive_string: The content after the !$psy part of this
node in the tree.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param kwargs is missing

Copy link
Collaborator Author

@LonelyCat124 LonelyCat124 Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thats just up to examining parent classes docs - I don't think I want to document kwargs here right? I think they just result in the base Node class keyword arguments here so are simply provided for internal use wherever the node is constructed if required.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically have :param kwargs: additional keyword arguments provided to the PSyIR node., I will add it myself if there is nothing else.

@LonelyCat124
Copy link
Collaborator Author

@sergisiso This is probably ready for another look now

Copy link
Collaborator

@sergisiso sergisiso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LonelyCat124 Almost there. The Directive part is all good now, but the example Makefile does not recurse to the directories and doesn't test some files that previously were tested and the README needs updating.

Comment on lines 53 to 56
for loop in routine.walk(Loop):
if loop in loops_to_skip:
continue
OMPLoopTrans(omp_directive="paralleldo").apply(loop)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be indented in (otherwise it just parallelises the last routine)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -0,0 +1,56 @@
# -----------------------------------------------------------------------------
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also change the name of this file to something more descriptive like: identify_custom_directives.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# ------------------------------------------------------------------------------
# Authors: A. R. Porter and S. Siso, STFC Daresbury Laboratory

include ../common.mk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is broken now (so make transform in this folder does not work)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, two of the examples in this folder's README should not be here, and instead should be in a parent readme

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and moved the README sections into their own examples readme's (not in the parent).


run: compile
@echo "No run targets for PSyIR creation examples"
EXAMPLES=custom_directives
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also list the new create_and_modify_psyir as this was tested before (it was what this Makefile was doing). Also test the matmul and transpose directories (they both work fine for me)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed those and added them too.

@sergisiso
Copy link
Collaborator

sergisiso commented Jan 13, 2026

And not your fault but the examples/psyir/matmul|transpose do not remove the output files with make clean (they do, it is the make clean is not recursively propagated) a ideally this output files should also be .gitignored

@LonelyCat124
Copy link
Collaborator Author

@sergisiso I think I added everything and the gitignore should ignore the .F90 files generated in those directories now.

# We don't turn OpenMP, OpenACC or directives we can't output
# correctly into Directive nodes. PSyclone currently always
# outputs directives starting with !$
dont_match = ["!$omp", "!$acc", "!$ompx", "!dir$"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LonelyCat124 I was a bit on the fence on these and wanted to wait for a use case. With what we discussed today: add profiling hooks around openmp in existing directives maybe it sways my opinion that these should be UnknownDirective so they are easier to identify. What do you think?

The !dir$ (and other !xxx$ ?) should still be CodeBlocks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main resoning for this is preventing them occurring in parallel loops. I could also add UnknownDirective into excluded_node_types in ParallelLoopTrans if you'd prefer, though this would block compiler directives appearing inside Parallel loops.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also add UnknownDirective into excluded_node_types in ParallelLoopTrans if you'd prefer, though this would block compiler directives appearing inside Parallel loops.

I am ok with this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still disallowing ompx extensions since we don't know at the moment what these might be and thus they're not useful to keep I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergisiso This is done now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants