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

FuncPtrCall #4

Merged
merged 5 commits into from
Jan 8, 2024
Merged

FuncPtrCall #4

merged 5 commits into from
Jan 8, 2024

Conversation

ZoeLeibowitz
Copy link
Owner

No description provided.

@ZoeLeibowitz
Copy link
Owner Author

In PETSc, I need to be able generate the following command:

PetscCall(MatShellSetOperation(A_matfree,MATOP_MULT,(void (*)(void))MyMatShellMult));

where MyMatShellMult is the name of the callback function. Whenever you have time, please take a look at my attempt at generating this. Thank you!

Copy link
Collaborator

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

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

bunch of minor comments but otherwise GTG

@@ -337,6 +337,19 @@ def writes(self):
return self._writes


class FuncPtrCall(Call):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would call it "CallablePtr" or simply "Callback" ?

Also, I don't think it should inherit from Call. Why should it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also (nitpicking) move this class further down in this file, ideally somewhere around the "second level IET nodes" (https://github.com/devitocodes/devito/blob/master/devito/ir/iet/nodes.py#L832)

perhaps after Lambda?

Copy link
Owner Author

Choose a reason for hiding this comment

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

It seemed to be the simplest/easiest way to bind the callback to an actual call

name = o.name
return_type = o.return_type
parameter_type = o.parameter_type
return FuncPtrArg(name, return_type, parameter_type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

simply return FuncPtrArg(o.name, o.rettype, ...)


super().__init__(name=name)

self.return_type = return_type
Copy link
Collaborator

Choose a reason for hiding this comment

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

since we have retobj in a lot of places in this module, how about rettype?
we also use the word "rettype" here https://github.com/devitocodes/devito/blob/master/devito/ir/iet/visitors.py#L268
so for homogeneity...

(clearly still nitpicking here)

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually we call it retval here, sigh:

https://github.com/devitocodes/devito/blob/master/devito/ir/iet/nodes.py#L687

so up to u I guess

super().__init__(name=name)

self.return_type = return_type
self.parameter_type = parameter_type
Copy link
Collaborator

Choose a reason for hiding this comment

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

parameterS ?
or simply "signature" or "param_types"?

use as_tuple for flexibility

@ZoeLeibowitz
Copy link
Owner Author

Adding a comment for clarity:

The reason Callback is an IET type rather than a SymPy type is due to the fact that, when represented at the SymPy level, the IET engine fails to bind the callback to a specific Call. Consequently, errors occur during the creation of the call graph because dag.size does not match len(efuncs).

code0 = CGen().visit(foo0_arg)
assert str(code0) == '(void (*)(int))foo0'

# test nested calls with a Callback as an argument.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: start comments with a captial

@@ -1097,6 +1097,36 @@ def defines(self):
return tuple(self.parameters)


class Callback(Call):

Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpicking: no blank line here

"""

def __init__(self, name, retval, param_types):

Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpicking: no blank line here

@ZoeLeibowitz ZoeLeibowitz merged commit 2b5b74b into master Jan 8, 2024
22 checks passed
@ZoeLeibowitz ZoeLeibowitz deleted the FuncPtrCall branch January 8, 2024 10:54
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.

4 participants