# itkGPUDemonsRegistrationFilterTest fails

**URL:** https://discourse.itk.org/t/itkgpudemonsregistrationfiltertest-fails/3160
**Category:** Beginner Questions
**Tags:** registration
**Created:** [June 9, 2020, 9:53pm UTC](https://discourse.itk.org/t/itkgpudemonsregistrationfiltertest-fails/3160 "2020-06-09T21:53:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ktsumura](https://discourse.itk.org/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@ktsumura](https://discourse.itk.org/u/ktsumura)
#### Post date: [June 9, 2020, 9:53pm UTC](https://discourse.itk.org/t/itkgpudemonsregistrationfiltertest-fails/3160/1 "2020-06-09T21:53:49Z")

</div>

Hi,

I run itkGPUDemonsRegistrationFilterTest via ITKGPUPDEDeformableRegistrationTestDriver, and the GPU registration seemed not working. The result of GPU is almost the same as the moving image, even though the result of CPU looks good. I used the following arguments, which uses .png files in the external data folder.

itkGPUDemonsRegistrationFilterTest 2 500 PATH\TO\InsightToolkit-5.0.1-bin7\ExternalData\Modules\Registration\GPUPDEDeformable\test\Input\LenaFix.png PATH\TO\InsightToolkit-5.0.1-bin7\ExternalData\Modules\Registration\GPUPDEDeformable\test\Input\LenaMov.png PATH\TO\InsightToolkit-5.0.1-bin7\ExternalData\Modules\Registration\GPUPDEDeformable\test\Input\LenaOut.png

My environment is…  
ITK 5.0.1  
CMake 3.16.4  
Cuda 10.2  
Windows 10

The followings are checked in CMake configuration.  
BUILD\_EXAMPLES  
BUILD\_SHARED\_LIB  
BUILD\_TESTING  
ITK\_USE\_GPU

I would appreciate any advice.  
Thank you,

Kenji

> **log**
>
> * * *
> 
> Starting GPU Demons  
> Platform : NVIDIA CUDA  
> Total # of platform : 2  
> Platform 0 : NVIDIA CUDA  
> Platform 1 : Intel® OpenCL  
> GeForce GTX 1070  
> Maximum Work Item Sizes : { 1024, 1024, 64 }  
> Maximum Work Group Size : 1024  
> Alignment in bits of the base address : 4096  
> Smallest alignment in bytes for any data type : 128  
> cl\_khr\_global\_int32\_base\_atomics cl\_khr\_global\_int32\_extended\_atomics cl\_khr\_local\_int32\_base\_atomics cl\_khr\_local\_int32\_extended\_atomics cl\_khr\_fp64 cl\_khr\_byte\_addressable\_store cl\_khr\_icd cl\_khr\_gl\_sharing cl\_nv\_compiler\_options cl\_nv\_device\_attribute\_query cl\_nv\_pragma\_unroll cl\_nv\_d3d10\_sharing cl\_khr\_d3d10\_sharing cl\_nv\_d3d11\_sharing cl\_nv\_copy\_opts cl\_nv\_create\_buffer cl\_khr\_int64\_base\_atomics cl\_khr\_int64\_extended\_atomics  
> Defines: #define DIM\_2  
> #define BUFPIXELTYPE float  
> #define OUTPIXELTYPE float  
> #define PIXELDIM 2
> 
> Defines: #define DIM\_2  
> #define OUTPIXELTYPE float
> 
> Defines: #define DIM\_2  
> #define IMGPIXELTYPE float  
> #define BUFPIXELTYPE float  
> #define OUTPIXELTYPE float
> 
> Defines: #define blockSize 128  
> #define nIsPow2 1  
> #define T int
> 
> Defines: #define blockSize 128  
> #define nIsPow2 1  
> #define T float
> 
> Defines: #define blockSize 128  
> #define nIsPow2 1  
> #define T float
> 
> Debug: In D:\workspace\_itk\InsightToolkit-5.0.1\Modules\Registration\GPUPDEDeformable\test\itkGPUDemonsRegistrationFilterTest.cxx, line 66  
> Object (0000009EEECFF110): Progress: 0 Iter: 0 Metric: 1.79769e+308 RMSChange: 0
> 
> Debug: In D:\workspace\_itk\InsightToolkit-5.0.1\Modules\Registration\GPUPDEDeformable\test\itkGPUDemonsRegistrationFilterTest.cxx, line 66  
> Object (0000009EEECFF110): Progress: 0.002 Iter: 1 Metric: 592.802 RMSChange: 0.327976
> 
> GPU InitTime in seconds = 0.0194838  
> GPU ComputeUpdateTime in seconds = 0.00176787  
> GPU ApplyUpdateTime in seconds = 7.29561e-05  
> GPU SmoothFieldTime in seconds = 0.00223136  
> Debug: In D:\workspace\_itk\InsightToolkit-5.0.1\Modules\Core\Common\src\itkObject.cxx, line 609  
> Object (0000009EEECFF110): Destructing!
> 
> WARNING: In D:\workspace\_itk\InsightToolkit-5.0.1\Modules\Core\Common\src\itkLightObject.cxx, line 206  
> LightObject (0000009EEECFF110): Trying to delete object with non-zero reference count.
> 
> ## Finished GPU Demons
> 
> Starting CPU Demons  
> WARNING: In D:\workspace\_itk\InsightToolkit-5.0.1\Modules\Core\Common\src\itkLightObject.cxx, line 206  
> LightObject (0000009EEECFF170): Trying to delete object with non-zero reference count.
> 
> Finished CPU Demons  
> Average GPU registration time in seconds = 0.794806  
> Average CPU registration time in seconds = 14.9423  
> Maximum displacement difference = 6.18324  
> Average displacement difference = 2.25719  
> Test failed
> 
> D:\workspace\_itk\InsightToolkit-5.0.1-bin7\bin\Debug\ITKGPUPDEDeformableRegistrationTestDriver.exe (process 31472) exited with code 1.  
> To automatically close the console when debugging stops, enable Tools-\>Options-\>Debugging-\>Automatically close the console when debugging stops.  
> Press any key to close this window . . .

---

<div class="post-metadata">

### Author: ![ktsumura](https://discourse.itk.org/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@ktsumura](https://discourse.itk.org/u/ktsumura)
#### Post date: [June 10, 2020, 4:55pm UTC](https://discourse.itk.org/t/itkgpudemonsregistrationfiltertest-fails/3160/2 "2020-06-10T16:55:41Z")

</div>

Hi

I found m\_RMSChange in GPUFiniteDifferenceImageFilter is 0.0, which terminated the process. Instead, m\_RMSChange in FiniteDifferenceImageFilter was set in ApplyUpdate method of GPUDemonsRegistrationFilter. Here is the screen shot.

 ![m_RMSChange](https://discourse.itk.org/uploads/default/original/2X/c/c3bb355878efbd103f3b0160e67fd1c562530d34.png)

I added the following in GPUFiniteDifferenceImageFilter.h. I am not sure this is the best solution, but the GPU registration worked.

> /\*\* Set/Get the maximum error allowed in the solution. This may not be  
> defined for all solvers and its meaning may change with the application. \*/  
> itkSetMacro( MaximumRMSError, double );  
> itkGetConstReferenceMacro( MaximumRMSError, double );
> 
> /\*\* Set/Get the root mean squared change of the previous iteration. May not  
> be used by all solvers. \*/  
> itkSetMacro( RMSChange, double );  
> itkGetConstReferenceMacro( RMSChange, double );

Thank you,  
Kenji

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [June 10, 2020, 5:36pm UTC](https://discourse.itk.org/t/itkgpudemonsregistrationfiltertest-fails/3160/3 "2020-06-10T17:36:40Z")

</div>

Hi Kenji,

Welcome to the ITK community! ☀

Thanks for discussing your issues and posting the follow-up.

Could your change be [submitted as a patch](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md)?

---

<div class="post-metadata">

### Author: ![ktsumura](https://discourse.itk.org/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@ktsumura](https://discourse.itk.org/u/ktsumura)
#### Post date: [June 10, 2020, 5:43pm UTC](https://discourse.itk.org/t/itkgpudemonsregistrationfiltertest-fails/3160/4 "2020-06-10T17:43:33Z")

</div>

I will.

Kenji
