# rtkiterativefdk CUDA error

**URL:** https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913
**Category:** Engineering
**Created:** [May 1, 2023, 3:39am UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913 "2023-05-01T03:39:27Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![ma1282029525](https://discourse.itk.org/user_avatar/discourse.itk.org/ma1282029525/32/3084_2.png) [@ma1282029525](https://discourse.itk.org/u/ma1282029525)
#### Post date: [May 1, 2023, 3:39am UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/1 "2023-05-01T03:39:27Z")

</div>

```auto
D:\ITKRTK\RTK-2.4.1\utilities\ITKCudaCommon\src\itkCudaDataManager.cxx:177 @ unknown : Cuda Error : an illegal memory access was encountered

ExceptionObject caught with itk::WriteImage(IFDKOutputPointer, args_info.output_arg) in file D:\ITKRTK\RTK-2.4.1\applications\rtkiterativefdk\rtkiterativefdk.cxx line 118

itk::ExceptionObject (0000006750B6EFC0)
Location: "unknown"
File: D:\ITKRTK\RTK-2.4.1\utilities\ITKCudaCommon\src\itkCudaDataManager.cxx
Line: 196
Description: ITK ERROR: CudaImageDataManager(000001C3619BF4D0): Exception occurred during CudaDataManager::UpdateCPUBuffer
D:\ITKRTK\RTK-2.4.1\utilities\ITKCudaCommon\src\itkCudaDataManager.cxx:177:
Cuda Error : an illegal memory access was encountered

```

I tried to run this example using Varian’s reconstruction data, but there was a cuda error. How can I solve it

–hardware “cuda” --geometry D:\ITKRTK\VarlianData\varian\geometry.xml --regexp .\*.hnd --path D:\ITKRTK\VarlianData\varian\Scan0 --output slice30.mha --verbose --spacing 0.25,0.25,0.25 --dimension 1024,10,1024 --origin -127.875,30,-127.875 -n “20” --output-every “5”  
this is my command line

---

<div class="post-metadata">

### Author: ![ma1282029525](https://discourse.itk.org/user_avatar/discourse.itk.org/ma1282029525/32/3084_2.png) [@ma1282029525](https://discourse.itk.org/u/ma1282029525)
#### Post date: [May 1, 2023, 1:49pm UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/2 "2023-05-01T13:49:11Z")

</div>

Is my GPU memory too small?

---

<div class="post-metadata">

### Author: ![ma1282029525](https://discourse.itk.org/user_avatar/discourse.itk.org/ma1282029525/32/3084_2.png) [@ma1282029525](https://discourse.itk.org/u/ma1282029525)
#### Post date: [May 1, 2023, 1:52pm UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/3 "2023-05-01T13:52:14Z")

</div>

D:\ITKRTK\RTK-2.4.1\utilities\ITKCudaCommon\include\itkCudaDataManager.h:71 @ unknown : Cuda Error : an illegal memory access was encountered

ExceptionObject caught with itk::WriteImage(streamingCUDA-\>GetOutput(), args\_info.output\_arg) in file D:\ITKRTK\RTK-2.4.1\applications\rtkiterativefdk\rtkiterativefdk.cxx line 129

itk::ExceptionObject (000000CE65BDEB10)  
Location: “unknown”  
File: D:\ITKRTK\RTK-2.4.1\utilities\ITKCudaCommon\src\itkCudaDataManager.cxx  
Line: 115  
Description: ITK ERROR: CudaImageDataManager(00000207AC040660): Exception occurred during CudaDataManager::Free  
D:\ITKRTK\RTK-2.4.1\utilities\ITKCudaCommon\include\itkCudaDataManager.h:71:  
Cuda Error : an illegal memory access was encountered

---

<div class="post-metadata">

### Author: ![ma1282029525](https://discourse.itk.org/user_avatar/discourse.itk.org/ma1282029525/32/3084_2.png) [@ma1282029525](https://discourse.itk.org/u/ma1282029525)
#### Post date: [May 1, 2023, 3:19pm UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/4 "2023-05-01T15:19:30Z")

</div>

```auto
000001A78ED137C0::UpdateGPUBuffer CPU->GPU data copy 000001A781E8C880->00000007879E8C00 : 8200
000001A78ED0A900::Allocate Create GPU buffer of size 424704 Bytes : 0000000787A00000
000001A89AA782E0::Freed GPU buffer of size 917504 Bytes : 0000000787870000
Iteration 1 completed.000001A78EBD9F20::Allocate Create GPU buffer of size 2157969408 Bytes : 000000078EA00000
000001A89AA77D30::Allocate Create GPU buffer of size 5242880 Bytes : 0000000787200000
000001A78EBD9190::Freed GPU buffer of size 524288 Bytes : 0000000787968C00
D:\ITKRTK\RTK-2.4.1\utilities\ITKCudaCommon\include\itkCudaDataManager.h:71 @ unknown : Cuda Error : an illegal memory access was encountered

ExceptionObject caught with itk::WriteImage(streamingCUDA->GetOutput(), args_info.output_arg) in file D:\ITKRTK\RTK-2.4.1\applications\rtkiterativefdk\rtkiterativefdk.cxx line 130

itk::ExceptionObject (000000690E6FE830)
Location: "unknown"
File: D:\ITKRTK\RTK-2.4.1\utilities\ITKCudaCommon\src\itkCudaDataManager.cxx
Line: 115
Description: ITK ERROR: CudaImageDataManager(000001A78EA60E50): Exception occurred during CudaDataManager::Free
D:\ITKRTK\RTK-2.4.1\utilities\ITKCudaCommon\include\itkCudaDataManager.h:71:
Cuda Error : an illegal memory access was encountered

```

An error is reported after the first iteration

---

<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 1, 2023, 7:48pm UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/5 "2023-05-01T19:48:54Z")

</div>

@simon.rit might answer some of your questions.

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [May 1, 2023, 8:31pm UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/6 "2023-05-01T20:31:32Z")

</div>

I tried your command line on my linux computer. Initially, I had `Cuda Error : out of memory`. After using every 10 projections (with --regexp .\*0.hnd) it worked. Can you try with less projections? Have you tried rtkfdk first?

---

<div class="post-metadata">

### Author: ![ma1282029525](https://discourse.itk.org/user_avatar/discourse.itk.org/ma1282029525/32/3084_2.png) [@ma1282029525](https://discourse.itk.org/u/ma1282029525)
#### Post date: [May 2, 2023, 1:02am UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/7 "2023-05-02T01:02:54Z")

</div>

> [@simon.rit](#):
>
> rtkfdk

after i use “–regexp .\*0.hnd” it is become ok. Is my GPU memory too small? my gpu memory is 6GB , projection image is 1GB.

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [May 2, 2023, 3:44am UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/8 "2023-05-02T03:44:09Z")

</div>

It’s probably too small. According to the log you’ve sent, there is a 2157969408 (2.1 GB) buffer which probably contains your float projections. The forward projection will have the same size. With the rest, it’s probably too much memory. There is no streaming mechanism for this iterative algorithm which is rarely used, sorry… It would be great if you find where there is a GPU allocation which is not handled properly, you should normally get a more meaningful message.

---

<div class="post-metadata">

### Author: ![ma1282029525](https://discourse.itk.org/user_avatar/discourse.itk.org/ma1282029525/32/3084_2.png) [@ma1282029525](https://discourse.itk.org/u/ma1282029525)
#### Post date: [May 2, 2023, 3:48am UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/9 "2023-05-02T03:48:09Z")

</div>

Sorry, I’m not familiar with CUDA, the log above is what I found.He did work after I reduced the projected image.

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [May 2, 2023, 3:52am UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/10 "2023-05-02T03:52:04Z")

</div>

Another solution to reduce the projection size is to bin the projections with the option `--binning 2,2`.

---

<div class="post-metadata">

### Author: ![2002priyaa](https://discourse.itk.org/user_avatar/discourse.itk.org/2002priyaa/32/4541_2.png) [@2002priyaa](https://discourse.itk.org/u/2002priyaa)
#### Post date: [June 12, 2025, 10:47am UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/11 "2025-06-12T10:47:02Z")

</div>

hello, I am facing the same error after running the code,  
i am working on rtk::CudaIterativeFDKConeBeamReconstructionFilter

```
 typedef
      rtk::LUTbasedVariableI0RawToAttenuationImageFilter<ImageType,volumeType> ConvertFilterType;
       ConvertFilterType::Pointer convert = ConvertFilterType::New();
       convert->SetInput(ioFilter->GetOutput());
       try
       {
       convert->Update();
       qDebug() << "lut updated";
       }
       catch(itk::ExceptionObject e)
       {
       throw(e);
       return 0;
       }

```

// using DDFOFFFOVType =rtk::CudaDisplacedDetectorImageFilter;  
using DDFOFFFOVType =rtk::DisplacedDetectorForOffsetFieldOfViewImageFilter;  
DDFOFFFOVType::Pointer ddf;  
ddf = DDFOFFFOVType::New();  
ddf-\>SetInput(convert-\>GetOutput());  
ddf-\>SetGeometry(geo);

// using PSSFType= rtk::CudaParkerShortScanImageFilter;  
typedef rtk::ParkerShortScanImageFilter PSSFType;  
PSSFType::Pointer pssf = PSSFType::New();  
pssf-\>SetInput(ddf-\>GetOutput());  
pssf-\>SetGeometry(geo);  
pssf-\>InPlaceOff();

```
         TRY_AND_EXIT_ON_ITK_EXCEPTION(pssf->Update());
 // try
// {

```

// pssf-\>Update();  
// qDebug() \<\< “pssf updated”;  
// }  
// catch(itk::ExceptionObject e)  
// {  
// throw(e);  
// return 0;  
// }  
std::cout \<\< "Volume spacing: " \<\< constVolume-\>GetOutput()-\>GetSpacing() \<\< std::endl;  
std::cout \<\< "Projection spacing: " \<\< ddf-\>GetOutput()-\>GetSpacing() \<\< std::endl;

QTime time1;  
time1.start();

// using IterativeFDKType = rtk::IterativeFDKConeBeamReconstructionFilter;

```
        using IterativeFDKType = rtk::CudaIterativeFDKConeBeamReconstructionFilter;
        volumeType::Pointer currentvol =constVolume->GetOutput();

```

for(int i=0;i\<1;++i)  
{

```
        IterativeFDKType::Pointer IterativeFDK = IterativeFDKType::New();

        IterativeFDK->SetInput(0, currentvol/*->GetOutput()*/);
        IterativeFDK->SetInput(1, pssf->GetOutput());
        IterativeFDK->SetGeometry(geo);

        //IterativeFDK->SetProjectionSubsetSize(1);
        IterativeFDK->SetLambda(1.0f);

        IterativeFDK->SetNumberOfIterations(1);

        IterativeFDK->SetForwardProjectionFilter(2);
        IterativeFDK->SetBackProjectionFilter(2);

        //IterativeFDK->SetEnforcePositivity(true);

        IterativeFDK->SetHannCutFrequency(0.3);
        //IterativeFDK->SetTruncationCorrection(1.0);
       // IterativeFDK->SetGPUEnabled(true); // Make sure GPU is enabled (usually default)

        IterativeFDK->UpdateOutputInformation(); // before .Update()

         qDebug() << "iterativeFDK parameter is set" << i;

```

// TRY\_AND\_EXIT\_ON\_ITK\_EXCEPTION(IterativeFDK-\>Update());

// try {  
IterativeFDK-\>Update();  
qDebug() \<\< “CUDA Iterative FDK completed successfully.”;  
currentvol=IterativeFDK-\>GetOutput();  
// } catch (itk::ExceptionObject &e) {  
// qCritical() \<\< “Error during CUDA Iterative FDK:” \<\< e.GetDescription();  
// return nullptr;

}  
int timetook1=time1.elapsed();  
qDebug() \<\< “timetook1” \<\< timetook1;

```
         typedef rtk::FieldOfViewImageFilter<volumeType,volumeType>
         FOVFilterType;

         FOVFilterType::Pointer fov=FOVFilterType::New();
         fov->SetInput(0, currentvol/*->GetOutput()*/);
         fov->SetProjectionsStack(pssf->GetOutput());
         fov->SetGeometry(geo);
         try
         {
         fov->Update();
         }
         catch(itk::ExceptionObject e)
         {
         throw(e);
         }

```

this is snippet of my code, please help me to solve this error

the error is,

ExceptionObject caught with pssf-\>Update() in file mainwindow.cpp line 412

itk::ExceptionObject (000000B9710FE7E0)

Location: “unknown”

File: D:/vs3/rtk/code/rtkCudaParkerShortScanImageFilter.cu

Line: 165

Description: itk::ERROR: CUDA ERROR: an illegal memory access was encountered

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [June 16, 2025, 5:39am UTC](https://discourse.itk.org/t/rtkiterativefdk-cuda-error/5913/12 "2025-06-16T05:39:29Z")

</div>

Thanks for the report. The easiest would be to have a minimal but complete example and to post it on [GitHub · Where software is built](https://github.com/RTKConsortium/RTK/issues/). Would you be able to provide this?
