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

FP slow, dominated by MemcpyD2H #2

Open
clemisch opened this issue Mar 22, 2023 · 2 comments
Open

FP slow, dominated by MemcpyD2H #2

clemisch opened this issue Mar 22, 2023 · 2 comments

Comments

@clemisch
Copy link
Owner

When profiling FP, runtime seems to be dominated by MemcpyD2H as seen in the Perfetto UI. The actual computations take only very little time in between.

image

I think this could be related to JAX calling each step in jax.lax.scan from host, requiring some synchronization at each iteration. This is discussed here and here.

I don't know how to resolve this in pure JAX. Alternatives to current implementation is vmap'ing instead of scan, or using some unroll in scan. IIRC both led to longer runtime.

Ultimately we should avoid the Memcpy at each projection -- which is what I think is happening. We could switch the levels of scan and vmap, i.e. vmap over angles, but scan over detector rows. I would expect that to be slower, but we could try it.

@clemisch
Copy link
Owner Author

clemisch commented Jun 1, 2023

Currenty, FP is ~6x slower than BP on CPU:

$ python3 timing.py --fp --bp --size=128
gpu      : None
prealloc : False
pmap     : False
fp       : True
bp       : True
size     : 128
dtype    : 'float32'
==== FP ====
(128, 128, 128) -> (128, 128, 128) :  1098 ms ,  0.52 µs per pixel , 0.002 GRays/s
==== BP ====
(128, 128, 128) -> (128, 128, 128) :   181 ms ,  0.09 µs per voxel , 0.012 GRays/s

@clemisch
Copy link
Owner Author

clemisch commented Jun 1, 2023

For JAX performance tips, see jax-ml/jax#2940

@clemisch clemisch changed the title FP dominated by MemcpyD2H FP slow, dominated by MemcpyD2H Jun 1, 2023
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

No branches or pull requests

1 participant