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

Add support for FFI calls with side effects via ffi_call #23982

Merged
merged 1 commit into from
Sep 28, 2024

Conversation

dfm
Copy link
Collaborator

@dfm dfm commented Sep 27, 2024

As discussed in #23963, the jax.extend.ffi.ffi_call function doesn't currently support FFI calls with side effects. Since we already have support for lowering effectful custom calls, plumbing this through to ffi_call is straightforward. I think it's reasonable to stick to the the same terminology here and call the boolean parameter has_side_effect.

If needed it would also be possible to add support for ordering via tokens since support for tokens was added in #23394, but I didn't want to do too much in this PR.

@dfm dfm self-assigned this Sep 27, 2024
@dfm dfm requested a review from hawkinsp September 27, 2024 18:57
def testEffects(self):
def fun():
jex.ffi.ffi_call("test_ffi", (), has_side_effect=True)
self.assertIn("test_ffi", jax.jit(fun).lower().as_text())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably you should verify that it doesn't get DCEd from the compiled IR, not the input to the compiler?

Or at least check the input IR has the side effect annotation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good suggestion! Done.

@dfm dfm added the pull ready Ready for copybara import and testing label Sep 27, 2024
@copybara-service copybara-service bot merged commit 15024ba into jax-ml:main Sep 28, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull ready Ready for copybara import and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants