Skip to content

Commit

Permalink
ENH: Add default factory initialization
Browse files Browse the repository at this point in the history
Leverages the `InitFactory` mechanism introduced in ITK commit c266651
to register VkFFT GPU-accelerated implementation classes as the default
backends for ITK FFT classes via the object factory.
  • Loading branch information
tbirdso committed Apr 12, 2022
1 parent a846aa2 commit 3f1083e
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/itkVkComplexToComplexFFTImageFilter.h
Expand Up @@ -127,6 +127,7 @@ struct FFTImageFilterTraits<VkComplexToComplexFFTImageFilter>
using InputPixelType = std::complex<TUnderlying>;
template <typename TUnderlying>
using OutputPixelType = std::complex<TUnderlying>;
using FilterDimensions = std::integer_sequence<unsigned int, 3, 2, 1>;
};

} // namespace itk
Expand Down
74 changes: 74 additions & 0 deletions include/itkVkFFTImageFilterInitFactory.h
@@ -0,0 +1,74 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkVkFFTImageFilterInitFactory_h
#define itkVkFFTImageFilterInitFactory_h
#include "VkFFTBackendExport.h"

#include "itkLightObject.h"

namespace itk
{
/**
*\class VkFFTImageFilterInitFactory
* \brief Initialize Vk FFT image filter factory backends.
*
* The purpose of VkFFTImageFilterInitFactory is to perform
* one-time registration of factory objects that handle
* creation of Vk-backend FFT image filter classes
* through the ITK object factory singleton mechanism.
*
* \ingroup FourierTransform
* \ingroup ITKFFT
* \ingroup ITKSystemObjects
* \ingroup VkFFTBackend
*/
class VkFFTBackend_EXPORT VkFFTImageFilterInitFactory : public LightObject
{
public:
ITK_DISALLOW_COPY_AND_MOVE(VkFFTImageFilterInitFactory);

/** Standard class type aliases. */
using Self = VkFFTImageFilterInitFactory;
using Superclass = LightObject;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;

/** Method for class instantiation. */
itkFactorylessNewMacro(Self);

/** Run-time type information (and related methods). */
itkTypeMacro(VkFFTImageFilterInitFactory, LightObject);

/** Mimic factory interface for Python initialization */
static void
RegisterOneFactory()
{
RegisterFactories();
}

/** Register all Vk FFT factories */
static void
RegisterFactories();

protected:
VkFFTImageFilterInitFactory();
~VkFFTImageFilterInitFactory() override = default;
};
} // end namespace itk

#endif
1 change: 1 addition & 0 deletions include/itkVkForward1DFFTImageFilter.h
Expand Up @@ -134,6 +134,7 @@ struct FFTImageFilterTraits<VkForward1DFFTImageFilter>
using InputPixelType = TUnderlying;
template <typename TUnderlying>
using OutputPixelType = std::complex<TUnderlying>;
using FilterDimensions = std::integer_sequence<unsigned int, 3, 2, 1>;
};

} // namespace itk
Expand Down
1 change: 1 addition & 0 deletions include/itkVkForwardFFTImageFilter.h
Expand Up @@ -132,6 +132,7 @@ struct FFTImageFilterTraits<VkForwardFFTImageFilter>
using InputPixelType = TUnderlying;
template <typename TUnderlying>
using OutputPixelType = std::complex<TUnderlying>;
using FilterDimensions = std::integer_sequence<unsigned int, 3, 2, 1>;
};

} // namespace itk
Expand Down
1 change: 1 addition & 0 deletions include/itkVkHalfHermitianToRealInverseFFTImageFilter.h
Expand Up @@ -133,6 +133,7 @@ struct FFTImageFilterTraits<VkHalfHermitianToRealInverseFFTImageFilter>
using InputPixelType = std::complex<TUnderlying>;
template <typename TUnderlying>
using OutputPixelType = TUnderlying;
using FilterDimensions = std::integer_sequence<unsigned int, 3, 2, 1>;
};

} // namespace itk
Expand Down
1 change: 1 addition & 0 deletions include/itkVkInverse1DFFTImageFilter.h
Expand Up @@ -135,6 +135,7 @@ struct FFTImageFilterTraits<VkInverse1DFFTImageFilter>
using InputPixelType = std::complex<TUnderlying>;
template <typename TUnderlying>
using OutputPixelType = TUnderlying;
using FilterDimensions = std::integer_sequence<unsigned int, 3, 2, 1>;
};

} // namespace itk
Expand Down
1 change: 1 addition & 0 deletions include/itkVkInverseFFTImageFilter.h
Expand Up @@ -132,6 +132,7 @@ struct FFTImageFilterTraits<VkInverseFFTImageFilter>
using InputPixelType = std::complex<TUnderlying>;
template <typename TUnderlying>
using OutputPixelType = TUnderlying;
using FilterDimensions = std::integer_sequence<unsigned int, 3, 2, 1>;
};

} // namespace itk
Expand Down
1 change: 1 addition & 0 deletions include/itkVkRealToHalfHermitianForwardFFTImageFilter.h
Expand Up @@ -133,6 +133,7 @@ struct FFTImageFilterTraits<VkRealToHalfHermitianForwardFFTImageFilter>
using InputPixelType = TUnderlying;
template <typename TUnderlying>
using OutputPixelType = std::complex<TUnderlying>;
using FilterDimensions = std::integer_sequence<unsigned int, 3, 2, 1>;
};

} // namespace itk
Expand Down
2 changes: 2 additions & 0 deletions itk-module.cmake
Expand Up @@ -25,6 +25,8 @@ itk_module(VkFFTBackend
ITKImageIntensity
DESCRIPTION
"${DOCUMENTATION}"
FACTORY_NAMES
"FFTImageFilterInit::Vk"
EXCLUDE_FROM_DEFAULT
ENABLE_SHARED
)
1 change: 1 addition & 0 deletions src/CMakeLists.txt
@@ -1,6 +1,7 @@
set(VkFFTBackend_SRCS
itkVkCommon.cxx
itkVkGlobalConfiguration.cxx
itkVkFFTImageFilterInitFactory.cxx
)

itk_module_add_library(VkFFTBackend ${VkFFTBackend_SRCS})
Expand Down
67 changes: 67 additions & 0 deletions src/itkVkFFTImageFilterInitFactory.cxx
@@ -0,0 +1,67 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "ITKFFTExport.h"

#include "itkVkComplexToComplex1DFFTImageFilter.h"
#include "itkVkComplexToComplexFFTImageFilter.h"
#include "itkFFTImageFilterFactory.h"
#include "itkVkForward1DFFTImageFilter.h"
#include "itkVkForwardFFTImageFilter.h"
#include "itkVkHalfHermitianToRealInverseFFTImageFilter.h"
#include "itkVkInverse1DFFTImageFilter.h"
#include "itkVkInverseFFTImageFilter.h"
#include "itkVkRealToHalfHermitianForwardFFTImageFilter.h"

#include "itkVkFFTImageFilterInitFactory.h"

namespace itk
{
VkFFTImageFilterInitFactory::VkFFTImageFilterInitFactory()
{
VkFFTImageFilterInitFactory::RegisterFactories();
}

void VkFFTImageFilterInitFactory::RegisterFactories()
{
itk::ObjectFactoryBase::RegisterFactory(FFTImageFilterFactory<VkComplexToComplex1DFFTImageFilter>::New(),
itk::ObjectFactoryEnums::InsertionPosition::INSERT_AT_FRONT);
itk::ObjectFactoryBase::RegisterFactory(FFTImageFilterFactory<VkComplexToComplexFFTImageFilter>::New(),
itk::ObjectFactoryEnums::InsertionPosition::INSERT_AT_FRONT);
itk::ObjectFactoryBase::RegisterFactory(FFTImageFilterFactory<VkForward1DFFTImageFilter>::New(),
itk::ObjectFactoryEnums::InsertionPosition::INSERT_AT_FRONT);
itk::ObjectFactoryBase::RegisterFactory(FFTImageFilterFactory<VkForwardFFTImageFilter>::New(),
itk::ObjectFactoryEnums::InsertionPosition::INSERT_AT_FRONT);
itk::ObjectFactoryBase::RegisterFactory(FFTImageFilterFactory<VkHalfHermitianToRealInverseFFTImageFilter>::New(),
itk::ObjectFactoryEnums::InsertionPosition::INSERT_AT_FRONT);
itk::ObjectFactoryBase::RegisterFactory(FFTImageFilterFactory<VkInverse1DFFTImageFilter>::New(),
itk::ObjectFactoryEnums::InsertionPosition::INSERT_AT_FRONT);
itk::ObjectFactoryBase::RegisterFactory(FFTImageFilterFactory<VkInverseFFTImageFilter>::New(),
itk::ObjectFactoryEnums::InsertionPosition::INSERT_AT_FRONT);
itk::ObjectFactoryBase::RegisterFactory(FFTImageFilterFactory<VkRealToHalfHermitianForwardFFTImageFilter>::New(),
itk::ObjectFactoryEnums::InsertionPosition::INSERT_AT_FRONT);
}

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.
void VkFFTBackend_EXPORT
VkFFTImageFilterInitFactoryRegister__Private()
{
VkFFTImageFilterInitFactory::RegisterFactories();
}

} // end namespace itk
11 changes: 11 additions & 0 deletions test/itkVkFFTImageFilterFactoryTest.cxx
Expand Up @@ -22,6 +22,7 @@
#include "itkComplexToComplex1DFFTImageFilter.h"
#include "itkVkComplexToComplex1DFFTImageFilter.h"
#include "itkVnlComplexToComplex1DFFTImageFilter.h"
#include "itkVkFFTImageFilterInitFactory.h"

#include "itkFFTImageFilterFactory.h"
#include "itkTestingMacros.h"
Expand Down Expand Up @@ -63,5 +64,15 @@ itkVkFFTImageFilterFactoryTest(int, char *[])
ITK_TEST_EXPECT_TRUE(vnlFFT != nullptr);
ITK_EXERCISE_BASIC_OBJECT_METHODS(vnlFFT, VnlComplexToComplex1DFFTImageFilter, ComplexToComplex1DFFTImageFilter);

// Verify factory initialization successfully registers factories
using FactoryInitializerType = itk::VkFFTImageFilterInitFactory;
FactoryInitializerType::RegisterFactories();

fft = FFTBaseType::New();
vkFFT = dynamic_cast<FFTVkSubclassType *>(fft.GetPointer());
ITK_TEST_EXPECT_TRUE(vkFFT != nullptr);
ITK_EXERCISE_BASIC_OBJECT_METHODS(vkFFT, VkComplexToComplex1DFFTImageFilter, ComplexToComplex1DFFTImageFilter);


return EXIT_SUCCESS;
}
1 change: 1 addition & 0 deletions wrapping/itkVkFFTImageFilterInitFactory.wrap
@@ -0,0 +1 @@
itk_wrap_simple_class("itk::VkFFTImageFilterInitFactory" POINTER)

0 comments on commit 3f1083e

Please sign in to comment.