[ITK-users] Problems Using GPU Filters

Matt McCormick matt.mccormick at kitware.com
Thu Sep 14 15:32:17 EDT 2017


Thank you for example code and description.


To improve performance and reduce memory usage, ITK re-uses memory
when possible. For example, many filters have an option to run in
place on their inputs.


The VTK bridge and GPU filters are special cases that may be
conflicting here. The GPU data manager moves ITK memory from the CPU
to GPU when required. However, the VTK bridge tries to prevent copying
the memory allocated by VTK.


There are a few approaches that can be taken.


First, consider using itk::ImageFileReader instead of vtkPNGReader
then VTKImageToImageFilter. This has the added advantage that it will
automatically also support many other file formats.

Second, place an ITK filter, like CastImageFilter, after the VTK
bridge filter and before the GPU filter. However, may sure to call
.InPlaceOff().


If you are considering writing your own GPU filters, you may also be
interested in this module [1]. This is a work in progress, but it will
allow writing filters that use ArrayFire underneath the hood.
ArrayFire is easier to program with than OpenCL, and it is optimized
for many GPGPU architectures.


[1] https://github.com/InsightSoftwareConsortium/ITKArrayFire

On Wed, Sep 13, 2017 at 9:46 PM, Andaharoo <andx_roo at live.com> wrote:
> I pulled the latest branch on github and this issue is still present on all
> my systems. Here is a clear example of code that does not work.
>
> typedef itk::GPUImage<unsigned char, 3> GPUImage;
> typedef itk::Image<unsigned char, 3> Image;
>
> // Read image with VTK
> vtkSmartPointer<vtkPNGReader> reader = vtkSmartPointer<vtkPNGReader>::New();
> reader->SetFileName("test.png");
> reader->Update();
>
> // Convert VTK to ITK
> typedef itk::VTKImageToImageFilter<Image> VtkToItkFilter;
> VtkToItkFilter::Pointer vtkToItkFilter = VtkToItkFilter::New();
> vtkToItkFilter->SetInput(cast->GetOutput());
> vtkToItkFilter->Update();
>
> // GPU Binary Thresholding
> typedef itk::GPUBinaryThresholdImageFilter<Image, GPUImage>
> GPUBinaryThresholdFilterType;
> GPUBinaryThresholdFilterType::Pointer binaryThresholdFilter =
> GPUBinaryThresholdFilterType::New();
> binaryThresholdFilter->SetInput(vtkToItkFilter->GetOutput());
> binaryThresholdFilter->SetLowerThreshold(150.0);
> binaryThresholdFilter->SetUpperThreshold(250.0);
> binaryThresholdFilter->SetOutsideValue(0);
> binaryThresholdFilter->SetInsideValue(355.0);
> binaryThresholdFilter->Update();
>
> GPU Gradient Anisotropic is the only gpu filter that works in this example.
> Probably because it's the only in place gpu filter. I've tried replacing
> "<Image>" with "<GPUImage>" as well.
>
> With the <Image, GPUImage> scenario I get read access violation as
> GPUDataManager is null. Expect when using gpu gradient anisotropic.
>
> With <GPUImage, GPUImage> and <GPUImage> on the conversion filter, the
> conversion filter fails to generate data.
>
> And as stated in earlier messages, if I first use gpu gradient anisotropic
> (only gpu filter that works after vtktoitk) I can then successfully apply
> gpu binary thresholding.
> I'd look further into the issue but I'm not really sure where gpu images
> even get allocated so it would be hard for me to debug. Perhaps I can write
> my own gpu filters using gradient anisotropic as reference.
>
>
>
> --
> Sent from: http://itk-insight-users.2283740.n2.nabble.com/
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users


More information about the Insight-users mailing list