# got OpenCL Error when using itkGPUDemonsRegistrationFilter

**URL:** https://discourse.itk.org/t/got-opencl-error-when-using-itkgpudemonsregistrationfilter/5961
**Category:** Beginner Questions
**Tags:** registration
**Created:** [May 23, 2023, 2:06am UTC](https://discourse.itk.org/t/got-opencl-error-when-using-itkgpudemonsregistrationfilter/5961 "2023-05-23T02:06:41Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![zx-lhb](https://discourse.itk.org/user_avatar/discourse.itk.org/zx-lhb/32/3082_2.png) [@zx-lhb](https://discourse.itk.org/u/zx-lhb)
#### Post date: [May 23, 2023, 2:06am UTC](https://discourse.itk.org/t/got-opencl-error-when-using-itkgpudemonsregistrationfilter/5961/1 "2023-05-23T02:06:41Z")

</div>

hi, I used DemonsRegistrationFilter to do registration, and it workd fine. Then I noticed there has GPUDemonsRegistrationFilter, So I replaced the itkImage to itkGPUImage, everything runs well until it came to the code “filter-\>Update();”, the command window report erros:

```cpp
OpenCL Error : CL_MEM_OBJECT_ALLOCATION_FAILURE

```

Here is the all output:

```cpp
Total # of platform : 2
Platform 0 : Intel(R) OpenCL HD Graphics
Platform 1 : NVIDIA CUDA
NVIDIA GeForce GTX 1660 SUPER
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_3d_image_writes 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 cl_khr_device_uuid
fixed_image spacing: [0.1073, 0.1073, 0.107296]
moving_image spacing: [0.275, 0.275, 0.747253]
here
D:\lib\itk53_20230522\source\Modules\Core\GPUCommon\src\itkGPUDataManager.cxx:151:
OpenCL Error : CL_MEM_OBJECT_ALLOCATION_FAILURE

E:\projectFiles\CPPcodes\GPURegistration\x64\Release\proj001.exe (process 46136) exited with code 0.
Press any key to close this window . . .

```

How cant I to fix the error? Thank you very much for your suggestions!

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 23, 2023, 1:25pm UTC](https://discourse.itk.org/t/got-opencl-error-when-using-itkgpudemonsregistrationfilter/5961/2 "2023-05-23T13:25:56Z")

</div>

What is your dedicated GPU memory? How big are the images you are trying to register? If they are bigger than GPU memory, you need a better graphics card.

Also, your OpenCL devices are:

```plaintext
Platform 0 : Intel(R) OpenCL HD Graphics
Platform 1 : NVIDIA CUDA

```

I don’t know whether we can make OpenCL choose nVidia instead of Intel as the preferred one.

---

<div class="post-metadata">

### Author: ![zx-lhb](https://discourse.itk.org/user_avatar/discourse.itk.org/zx-lhb/32/3082_2.png) [@zx-lhb](https://discourse.itk.org/u/zx-lhb)
#### Post date: [May 24, 2023, 1:04am UTC](https://discourse.itk.org/t/got-opencl-error-when-using-itkgpudemonsregistrationfilter/5961/3 "2023-05-24T01:04:18Z")

</div>

Thank you for your reply! My dedicated GPU memory is 6G, and fixed image’ s size is [515, 506, 496]. So, does the problem came out because OpenCL choose nVidia instead of Intel?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 24, 2023, 1:17pm UTC](https://discourse.itk.org/t/got-opencl-error-when-using-itkgpudemonsregistrationfilter/5961/4 "2023-05-24T13:17:21Z")

</div>

It is easy to check whether the memory is the issue: try downscaling your images 4x (to e.g. 130x125x120). If you still have the problem, it is not related to size of the images.

I expect nVidia to perform better as a GPU accelerator.

---

<div class="post-metadata">

### Author: ![zx-lhb](https://discourse.itk.org/user_avatar/discourse.itk.org/zx-lhb/32/3082_2.png) [@zx-lhb](https://discourse.itk.org/u/zx-lhb)
#### Post date: [May 26, 2023, 1:02am UTC](https://discourse.itk.org/t/got-opencl-error-when-using-itkgpudemonsregistrationfilter/5961/5 "2023-05-26T01:02:07Z")

</div>

I have checked the memory is not the issue. Still have the problem, thank you anyway, I think I need to write orginal cuda codes. By the way, does ITK has GPU accelerating souce codes for reference?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 26, 2023, 1:05pm UTC](https://discourse.itk.org/t/got-opencl-error-when-using-itkgpudemonsregistrationfilter/5961/6 "2023-05-26T13:05:53Z")

</div>

Some filters are implemented, e.g. [GradientNDAnisotropicDiffusion](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/GPUAnisotropicSmoothing/src/GPUGradientNDAnisotropicDiffusionFunction.cl). You can find more by looking at [folders with GPU in the name](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/Filtering) in filtering group and elsewhere, or by [searching for GPU](https://github.com/search?q=repo%3AInsightSoftwareConsortium%2FITK%20GPU&type=code).

---

<div class="post-metadata">

### Author: ![zx-lhb](https://discourse.itk.org/user_avatar/discourse.itk.org/zx-lhb/32/3082_2.png) [@zx-lhb](https://discourse.itk.org/u/zx-lhb)
#### Post date: [May 27, 2023, 1:57am UTC](https://discourse.itk.org/t/got-opencl-error-when-using-itkgpudemonsregistrationfilter/5961/7 "2023-05-27T01:57:32Z")

</div>

I’l try, thank you for your help!
