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

Simple GPU tracking #576

Merged
merged 18 commits into from
May 19, 2022
Merged

Simple GPU tracking #576

merged 18 commits into from
May 19, 2022

Conversation

CHrlS98
Copy link
Contributor

@CHrlS98 CHrlS98 commented Apr 13, 2022

Script to compute a probabilistic tractogram on the GPU. The ODF image and mask are interpolated using nearest-neighbor interpolation. The script also incorporates ideas from Ensemble Tractography. Given a list of maximum angles, a different angle drawn at random from the set will be used for each streamline.

Here's a log showing the execution time on a Tractoflow-processed HCP subject.

>>> scil_compute_short_tracks.py FODF_Metrics/100206__fodf.nii.gz \
... Local_Tracking_Mask/100206__local_tracking_mask.nii.gz \
... a_big_short_tracks_tractogram.trk -v -f --nt 2000000

INFO:root:Generated 2000000 seed positions in 9.58s.
INFO:root:  100000/2000000 streamlines generated
INFO:root:  200000/2000000 streamlines generated
INFO:root:  300000/2000000 streamlines generated
INFO:root:  400000/2000000 streamlines generated
INFO:root:  500000/2000000 streamlines generated
INFO:root:  600000/2000000 streamlines generated
INFO:root:  700000/2000000 streamlines generated
INFO:root:  800000/2000000 streamlines generated
INFO:root:  900000/2000000 streamlines generated
INFO:root: 1000000/2000000 streamlines generated
INFO:root: 1100000/2000000 streamlines generated
INFO:root: 1200000/2000000 streamlines generated
INFO:root: 1300000/2000000 streamlines generated
INFO:root: 1400000/2000000 streamlines generated
INFO:root: 1500000/2000000 streamlines generated
INFO:root: 1600000/2000000 streamlines generated
INFO:root: 1700000/2000000 streamlines generated
INFO:root: 1800000/2000000 streamlines generated
INFO:root: 1900000/2000000 streamlines generated
INFO:root: 2000000/2000000 streamlines generated
INFO:root:Tracked 1081556 streamlines in 16.56s.
INFO:root:Saved tractogram to a_big_short_tracks_tractogram.trk in 25.90s.
INFO:root:Total runtime of 53.86s

And a visualization of the output tractogram.
image

Because it runs on the GPU and uses pyopencl which is an optional dependency of scilpy, there is not much I can test with pytest apart from the --help command.

@scil-admin scil-admin requested a review from arnaudbore April 13, 2022 20:09
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

1 similar comment
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

1 similar comment
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@EmmaRenauld
Copy link
Contributor

It could possibly be useful to us eventually in dwiml!

What is the reason for creating short streamlines only? Memory restriction, or that was actually your initial goal?
@ppoulin91, I have not ported your GPU tracking to dwiml yet. Maybe at some point we could sit together with Charles to see if your two ideas can be compatible.

@CHrlS98
Copy link
Contributor Author

CHrlS98 commented May 16, 2022

@EmmaRenauld

What is the reason for creating short streamlines only? Memory restriction, or that was actually your initial goal?

I just needed short streamlines and didn't need backward tracking so I didn't take the time to implement it. But it is not a memory limitation; you can increase the max_length to 300 and it will work (ish, because there is no backward tracking so WM-seeded tracks will end in the WM).

But, I think I will mark the PR as WIP and eventually rename to scil_compute_local_tracking_gpu.py (or something), implement the backward pass and change default values for min and max length.

Then we would have:

  • scil_compute_local_tracking.py (dipy)
  • scil_compute_local_tracking_dev.py (python)
  • scil_compute_local_tracking_gpu.py (gpu)

For clarity, maybe we should rename scil_compute_local_tracking.py -> scil_compute_local_tracking_dipy.py.

@EmmaRenauld
Copy link
Contributor

Are the args so very different? Couldn't it be in the same script _dev and add option '--use_gpu'? Then the initialisation would call another Propagator class?

@CHrlS98
Copy link
Contributor Author

CHrlS98 commented May 16, 2022

A lot of options would not be supported though:

  • Interpolation method for the sh field and mask is only NN,
  • Runge-Kutta interpolation is not implemented,
  • Deterministic tracking is not available,
  • There are no sf_threshold (although maybe there should be) and sf_init_threshold,
  • Etc.

I feel like it would just make the _dev script harder to read and understand. I'd prefer having a separate script with adequate description describing what GPU tracking does and doesn't do.

Or I could support all the options the _dev script supports, but that's a bigger job because everything has to be translated into OpenCL code.

I'll see how GPU tracking would fit in our tracking code structure. The propagator is 100% GPU code, as is the dataset, but I will at least write a proper GPUTracker class in the tracker.py file, with a track method for launching the GPU tracking.

@CHrlS98 CHrlS98 changed the title Compute short-tracks tractogram (GPU tracking!) [WIP] Compute short-tracks tractogram (GPU tracking!) May 16, 2022
@EmmaRenauld
Copy link
Contributor

Nice!

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

Copy link
Contributor

@mdesco mdesco left a comment

Choose a reason for hiding this comment

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

Minor help edit to do. Otherwise, just to leave a trace, I'm having an error running it.

pyopencl._cl.RuntimeError: clBuildProgram failed: BUILD_PROGRAM_FAILURE - clBuildProgram failed: BUILD_PROGRAM_FAILURE - clBuildProgram failed: BUILD_PROGRAM_FAILURE

Build on <pyopencl.Device 'GeForce GTX 1080' on 'NVIDIA CUDA' at 0x2ef8f10>:

:174:55: error: implicit conversion from address space "global" to address space "private" is not supported when passing to parameter of destination type
sh_to_sf(odf_sh, sh_to_sf_mat, is_first_step, vertices,
^~~~~~~~
:30:54: note: passing argument to parameter 'vertices' here
const bool is_first_step, const float* vertices,
^

(options: -I /home/local/USHERBROOKE/desm2239/my_env/scilpy_master/lib/python3.7/site-packages/pyopencl/cl)

@@ -0,0 +1,161 @@
#!/usr/bin/env python3
"""
Perform probabilistic short-tracks tractography[1] on a ODF field inside a
Copy link
Contributor

Choose a reason for hiding this comment

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

Add space before [1] please

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

1 similar comment
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

Copy link
Contributor

@mdesco mdesco left a comment

Choose a reason for hiding this comment

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

Watatatow! Ça torpille cette affaire! npv10 en 155 seconds.
Bravo @CHrlS98 !!!

Copy link
Contributor

@arnaudbore arnaudbore left a comment

Choose a reason for hiding this comment

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

Appart from the two comments I would say Great Job @CHrlS98
Maybe it need more testing but otherwise LGTM

scilpy/tracking/short_tracks.py Outdated Show resolved Hide resolved
scripts/scil_compute_short_tracks.py Outdated Show resolved Hide resolved
@CHrlS98 CHrlS98 changed the title [WIP] Compute short-tracks tractogram (GPU tracking!) Simple GPU tracking May 19, 2022
@scil-admin scil-admin requested a review from arnaudbore May 19, 2022 19:45
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

2 similar comments
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@arnaudbore arnaudbore merged commit b162b8b into scilus:master May 19, 2022
@CHrlS98 CHrlS98 deleted the short-tracks-gpu branch May 19, 2022 20:33
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.

5 participants