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

No option to set number of threads for Transformix #163

Open
Svdvoort opened this issue Aug 19, 2022 · 13 comments
Open

No option to set number of threads for Transformix #163

Svdvoort opened this issue Aug 19, 2022 · 13 comments

Comments

@Svdvoort
Copy link

The itk.ElastixRegistrationMethod method has the SetNumberOfThreads and GetNumberOfThreads functions to set and get the number of threads respectively.

However, itk.TransformixFilter does not have such functions. Should the number of threads be set in a different way, or can a SetNumberOfThreads function be added?

@thewtex
Copy link
Member

thewtex commented Aug 24, 2022

@N-Dekker

@N-Dekker
Copy link
Collaborator

@Svdvoort Hi Sebastian, thank you for your suggestion! Do you have a particular use case that would significantly benefit from running itk.TransformixFilter multi-threaded? Would you then expect a large speed-up of the transformation process?

I'm asking, because it may not be entirely trivial to implement this option for TransformixFilter in a thread-safe way. We would have to have a closer look.

@stefanklein
Copy link
Collaborator

stefanklein commented Aug 25, 2022 via email

@Svdvoort
Copy link
Author

Indeed, as Stefan points out I would just like to set the maximum number of threads transformix uses.
I don't expect a speed-up due to using multiple cores with transformix directly.
However, I do have a lot of cores available and would like to run multiple instances of transformix in parallel.
But because I can't set the (maximum) number of threads at the moment, I'm afraid that a single instance of transformix might use all cores, therefore I would like to be able to set the (maximum) number of threads.

N-Dekker added a commit to SuperElastix/elastix that referenced this issue Aug 25, 2022
Addressed issue InsightSoftwareConsortium/ITKElastix#163 "No option to set number of threads for Transformix", submitted by Sebastian van der Voort.
@N-Dekker
Copy link
Collaborator

N-Dekker commented Aug 25, 2022

@Svdvoort @stefanklein OK, thank you for your clarification. 👍 Please check: SuperElastix/elastix#714 Of course, once it is merged into SuperElastix/elastix (develop branch), it still needs to be included with the ITKElastix Python wrapping as well.

N-Dekker added a commit to SuperElastix/elastix that referenced this issue Aug 25, 2022
Addressed issue InsightSoftwareConsortium/ITKElastix#163 "No option to set number of threads for Transformix", submitted by Sebastian van der Voort.
N-Dekker added a commit to SuperElastix/elastix that referenced this issue Aug 26, 2022
Addressed issue InsightSoftwareConsortium/ITKElastix#163 "No option to set number of threads for Transformix", submitted by Sebastian van der Voort.
N-Dekker added a commit to SuperElastix/elastix that referenced this issue Aug 26, 2022
Addressed issue InsightSoftwareConsortium/ITKElastix#163 "No option to set number of threads for Transformix", submitted by Sebastian van der Voort.
N-Dekker added a commit to SuperElastix/elastix that referenced this issue Aug 26, 2022
Addressed issue InsightSoftwareConsortium/ITKElastix#163 "No option to set number of threads for Transformix", submitted by Sebastian van der Voort.
@N-Dekker
Copy link
Collaborator

N-Dekker commented Aug 26, 2022

@Svdvoort @thewtex Technically, the TransformixFilter option is there in C++ now, with SuperElastix/elastix#714 (Still to be merged, and wrapped by ITKElastix.) Internally it adds the "-threads" option with the specified number of threads, which triggers calling itk::MultiThreaderBase::SetGlobalMaximumNumberOfThreads, just like the transformix executable does. (As was implemented by @stefanklein SuperElastix/elastix@1cf92cb in 2007).

For the transformix executable, "-threads" is certainly a useful option. However, when using ITKElastix with the itk Python wrapping, doesn't itk support calling itk::MultiThreaderBase::SetGlobalMaximumNumberOfThreads directly in Python?

@dzenanz
Copy link
Member

dzenanz commented Aug 26, 2022

itk support calling itk::MultiThreaderBase::SetGlobalMaximumNumberOfThreads directly in Python

I guess that would work, but it would affect other filters too (probably not a big deal). I guess it is more intuitive, and easier to find, if the thread limitation exists in the filter.

@N-Dekker
Copy link
Collaborator

N-Dekker commented Aug 29, 2022

@Svdvoort As a workaround, does it work for you to just call itk.MultiThreaderBase.SetGlobalMaximumNumberOfThreads yourself (in the Python/ITKElastix environment)?

We are looking into how to add a function like transformixFilter.SetNumberOfThreads(numberOfThreads), which would set the number of threads only for that specific transformixFilter instance, but it takes a little bit more time.

N-Dekker added a commit to SuperElastix/elastix that referenced this issue Sep 3, 2022
Addressed issue InsightSoftwareConsortium/ITKElastix#163 "No option to set number of threads for Transformix", submitted by Sebastian van der Voort.
@thewtex
Copy link
Member

thewtex commented Oct 17, 2022

For the transformix executable, "-threads" is certainly a useful option. However, when using ITKElastix with the itk Python wrapping, doesn't itk support calling itk::MultiThreaderBase::SetGlobalMaximumNumberOfThreads directly in Python?

@N-Dekker in the big picture, moving forward with Elastix output for itk.Transform will allow us to use itk.ResampleImageFilter. This has interfaces for setting the number of threads, etc. We can also take advantage of other GPU-optimized itk.ResampleImageFilter implementations in the works.

@stefanklein
Copy link
Collaborator

stefanklein commented Oct 17, 2022 via email

@thewtex
Copy link
Member

thewtex commented Oct 17, 2022

Hi @stefanklein ,

Yes, I agree, the flexibility of Elastix helps its adoption. To be clear, I am not suggesting that we do not add the ability to set the number of threads to the Transformix interface. We should continue to increase the flexibility of Elastix so all GPU acceleration versions of resampling, including e.g. Python / CUDA implementations, are available to Elastix users. This is possible by providing an in-memory itk.Transform output that can be used with itk.resample_image_filter.

@thewtex
Copy link
Member

thewtex commented Oct 17, 2022

Please see the discussion at SuperElastix/elastix#714 on how to provide this functionality on the Transformix interface.

@stefanklein
Copy link
Collaborator

stefanklein commented Oct 17, 2022 via email

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

5 participants