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

[JAX] Use a hand-written Python wrapper for CompiledFunction. #42

Merged
merged 1 commit into from
Apr 6, 2021

Conversation

copybara-service[bot]
Copy link

[JAX] Use a hand-written Python wrapper for CompiledFunction.

A hand-written Python wrapper gives us a number of benefits:

  • it makes it cheaper to cast self to a CompiledFunction in the __call__ method, since we no longer need to use pybind11's dynamic casting logic.
  • we can avoid building an empty kwarg dict even when no kwargs are passed, which is something pybind11 does behind the scenes.
  • the change allows us to prepare for using faster calling conventions, e.g. METH_FASTCALL in Python 3.7 or newer, which would allow the interpreter to avoid forming a tuple for the positional arguments.

In passing, remove unused arguments from PopulateCacheEntry.

Benchmarks (N.B. incorporating the PyBuffer hand-written PyObject change as well):

name                 old cpu/op  new cpu/op  delta
jit_simple_dispatch  11.3µs ± 6%  10.0µs ± 8%  -11.17%  (p=0.000 n=20+20)

name                 old time/op             new time/op             delta
jit_simple_dispatch  11.3µs ± 6%             10.0µs ±10%  -11.25%        (p=0.000 n=20+19)

@google-cla google-cla bot added the cla: yes copybara label for automatic import label Apr 6, 2021
A hand-written Python wrapper gives us a number of benefits:
* it makes it cheaper to cast `self` to a `CompiledFunction` in the `__call__` method, since we no longer need to use pybind11's dynamic casting logic.
* we can avoid building an empty kwarg dict even when no kwargs are passed, which is something pybind11 does behind the scenes.
* the change allows us to prepare for using faster calling conventions, e.g. METH_FASTCALL in Python 3.7 or newer, which would allow the interpreter to avoid forming a tuple for the positional arguments.

In passing, remove unused arguments from PopulateCacheEntry.

Benchmarks (N.B. incorporating the PyBuffer hand-written PyObject change as well):
```
name                 old cpu/op  new cpu/op  delta
jit_simple_dispatch  11.3µs ± 6%  10.0µs ± 8%  -11.17%  (p=0.000 n=20+20)

name                 old time/op             new time/op             delta
jit_simple_dispatch  11.3µs ± 6%             10.0µs ±10%  -11.25%        (p=0.000 n=20+19)
```

PiperOrigin-RevId: 367010792
@copybara-service copybara-service bot merged commit 2d72681 into master Apr 6, 2021
@copybara-service copybara-service bot deleted the test_366498581 branch April 6, 2021 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes copybara label for automatic import
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant