ITKElastix icon indicating copy to clipboard operation
ITKElastix copied to clipboard

No option to set number of threads for Transformix

Open Svdvoort opened this issue 2 years ago • 13 comments

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?

Svdvoort avatar Aug 19 '22 12:08 Svdvoort

@N-Dekker

thewtex avatar Aug 24 '22 13:08 thewtex

@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.

N-Dekker avatar Aug 25 '22 11:08 N-Dekker

Transformix (the command line version, and I think also the library version) by default already performs multithreading using the default ITK implementation. I think Sebastian's question is just to have a function to set the maximum number of threads, just like possible on the commandline. Cheers, stefan

From: Niels Dekker @.> Sent: Thursday, August 25, 2022 1:47 PM To: InsightSoftwareConsortium/ITKElastix @.> Cc: Subscribed @.***> Subject: Re: [InsightSoftwareConsortium/ITKElastix] No option to set number of threads for Transformix (Issue #163)

Waarschuwing: Deze e-mail is afkomstig van buiten de organisatie. Klik niet op links en open geen bijlagen, tenzij u de afzender herkent en weet dat de inhoud veilig is. Caution: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

@Svdvoorthttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FSvdvoort&data=05%7C01%7Cs.klein%40erasmusmc.nl%7Ce903426332094da9c70708da868f7509%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637970247945080288%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=7w4UOshaKFxeNZcmCAzL4cGn8eUZHcI81i7UwzZ7Pz4%3D&reserved=0 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.

Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FInsightSoftwareConsortium%2FITKElastix%2Fissues%2F163%23issuecomment-1227150677&data=05%7C01%7Cs.klein%40erasmusmc.nl%7Ce903426332094da9c70708da868f7509%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637970247945080288%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RnHq4rmZ33OY3H9mqPhRrkPaNlaiNWHcW%2Bk%2By0eYoXA%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAF2LNJY3JF3OK2ZWN4VKV3V25MJPANCNFSM57AUFIAA&data=05%7C01%7Cs.klein%40erasmusmc.nl%7Ce903426332094da9c70708da868f7509%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637970247945080288%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=k7uQbedAWFMWHIzxeyOOpn32cIOm7bjy9OoqeugsNjI%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.@.>>

stefanklein avatar Aug 25 '22 12:08 stefanklein

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.

Svdvoort avatar Aug 25 '22 12:08 Svdvoort

@Svdvoort @stefanklein OK, thank you for your clarification. 👍 Please check: https://github.com/SuperElastix/elastix/pull/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 avatar Aug 25 '22 13:08 N-Dekker

@Svdvoort @thewtex Technically, the TransformixFilter option is there in C++ now, with https://github.com/SuperElastix/elastix/pull/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 https://github.com/SuperElastix/elastix/commit/1cf92cb33a8901c08f00ec707e3695a0aee4e815 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?

N-Dekker avatar Aug 26 '22 10:08 N-Dekker

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.

dzenanz avatar Aug 26 '22 13:08 dzenanz

@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 avatar Aug 29 '22 12:08 N-Dekker

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.

thewtex avatar Oct 17 '22 13:10 thewtex

Hi Matt, Strong part of itk-elastix is indeed that we now offer the flexibility of extracting the ITKtransform so that the user can setup their own resampleimagefilter in exactly the way they like. That having said, I'm not sure if we should turn it around and use it as a reason to not expose functionality via the elastix interface: part of the added value of Elastix is that it wraps the ResampleImageFilter (and GPU accelerated versions of it) and takes care of some book-keeping etc, so that the users don't need to setup the resample image filter themselves. Cheers, Stefan

From: Matt McCormick @.> Sent: Monday, October 17, 2022 3:40 PM To: InsightSoftwareConsortium/ITKElastix @.> Cc: Stefan Klein @.>; Mention @.> Subject: Re: [InsightSoftwareConsortium/ITKElastix] No option to set number of threads for Transformix (Issue #163)

Waarschuwing: Deze e-mail is afkomstig van buiten de organisatie. Klik niet op links en open geen bijlagen, tenzij u de afzender herkent en weet dat de inhoud veilig is. Caution: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

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-Dekkerhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FN-Dekker&data=05%7C01%7Cs.klein%40erasmusmc.nl%7Cc218207d355f46ce9f7608dab0451683%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C638016108018103174%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=ra5JyC4FdRbt5DlWkBJlstrfemsr2PAvJirMeAVmqIQ%3D&reserved=0 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.

Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FInsightSoftwareConsortium%2FITKElastix%2Fissues%2F163%23issuecomment-1280878400&data=05%7C01%7Cs.klein%40erasmusmc.nl%7Cc218207d355f46ce9f7608dab0451683%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C638016108018103174%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=P6lPsvh4lsbvTZlK30AIKdTRtE3BjZGj5g6%2BwdkEK6k%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAF2LNPZZRW4KPXGB6SEP2LWDVJK7ANCNFSM57AUFIAA&data=05%7C01%7Cs.klein%40erasmusmc.nl%7Cc218207d355f46ce9f7608dab0451683%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C638016108018103174%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=g1w9X%2Faxg8s4OndCzGGfSe7ClO%2BfZU1QudO3iLExRfg%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.@.>>

stefanklein avatar Oct 17 '22 15:10 stefanklein

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 avatar Oct 17 '22 17:10 thewtex

Please see the discussion at https://github.com/SuperElastix/elastix/pull/714 on how to provide this functionality on the Transformix interface.

thewtex avatar Oct 17 '22 17:10 thewtex

Thanks for the clarification Matt! Agree. Stefan

From: Matt McCormick @.> Sent: Monday, October 17, 2022 7:15 PM To: InsightSoftwareConsortium/ITKElastix @.> Cc: Stefan Klein @.>; Mention @.> Subject: Re: [InsightSoftwareConsortium/ITKElastix] No option to set number of threads for Transformix (Issue #163)

Waarschuwing: Deze e-mail is afkomstig van buiten de organisatie. Klik niet op links en open geen bijlagen, tenzij u de afzender herkent en weet dat de inhoud veilig is. Caution: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Hi @stefankleinhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fstefanklein&data=05%7C01%7Cs.klein%40erasmusmc.nl%7Cb627bdef488c479c968008dab0631118%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C638016236775805997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=nQwrO6Kkzz9Vrwbeecv%2BLNKNfpBHt4i4RZhugfCdIKQ%3D&reserved=0 ,

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.

Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FInsightSoftwareConsortium%2FITKElastix%2Fissues%2F163%23issuecomment-1281191791&data=05%7C01%7Cs.klein%40erasmusmc.nl%7Cb627bdef488c479c968008dab0631118%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C638016236775805997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=jvxThYmUE9Lec4wSyazvYZbVYCZAOmo8AXStPG%2FRGxA%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAF2LNPRCAWJJW67P4UBC3TWDWCPVANCNFSM57AUFIAA&data=05%7C01%7Cs.klein%40erasmusmc.nl%7Cb627bdef488c479c968008dab0631118%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C638016236775805997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fThI85tKY6EYzJjaxwx5yzno0Kx0y2i%2FPFjfMHw8HZQ%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.@.>>

stefanklein avatar Oct 17 '22 19:10 stefanklein