Skip to content

PERF: BSplineKernelFunction::FastEvaluate(u): a faster way to evaluate BSplineKernelFunction#2716

Merged
thewtex merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:BSplineKernelFunction-FastEvaluate
Sep 8, 2021
Merged

PERF: BSplineKernelFunction::FastEvaluate(u): a faster way to evaluate BSplineKernelFunction#2716
thewtex merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:BSplineKernelFunction-FastEvaluate

Conversation

@N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Sep 5, 2021

Added a static member function BSplineKernelFunction::FastEvaluate(u). Equivalent to the existing BSplineKernelFunction::Evaluate(u) member function. Allows writing faster code, because it is non-virtual, and
because it does not require the creation of a BSplineKernelFunction object.

Removed the dynamically allocated m_Kernel data member from BSplineInterpolationWeightFunction and replaced the virtual function call m_Kernel->Evaluate(x) by a faster static member function call, to the newly added BSplineKernelFunction::FastEvaluate member function.

Equivalent to the existing `BSplineKernelFunction::Evaluate(u)` member
function. Allows writing faster code, because it is non-virtual, and
because it does not require the creation of a `BSplineKernelFunction`
object.
Removed the dynamically allocated `m_Kernel` data member from
`BSplineInterpolationWeightFunction` and replaced the virtual function
call `m_Kernel->Evaluate(x)` by a faster static member function call, to
the newly added `BSplineKernelFunction::FastEvaluate` member function.

May significantly improve the performance of
`BSplineInterpolationWeightFunction`.
@github-actions github-actions bot added area:Core Issues affecting the Core module type:Performance Improvement in terms of compilation or execution time labels Sep 5, 2021
@N-Dekker N-Dekker marked this pull request as ready for review September 5, 2021 21:00
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment on the performance improvement @N-Dekker?

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Sep 6, 2021

Can you comment on the performance improvement @N-Dekker?

@dzenanz Not yet, but I'm pretty sure that removing both the dynamic allocation of the kernel and the virtual function call does improve the performance.

Update: I just compared old style kernel->Evaluate...

    double sum{};
    const auto kernel = BSplineKernelFunctionType::New();

    for (int i{}; i < n; ++i)
    {
      sum += kernel->Evaluate(sum);
    }

...to calling the proposed static member function, FastEvaluate:

    double sum{};

    for (int i{}; i < n; ++i)
    {
      sum += BSplineKernelFunctionType::FastEvaluate(sum);
    }

Using VS2019 x64 (Release). For SplineOrder = 3, the duration was reduced by more than 8% when calling FastEvaluate. For SplineOrder = 1, the duration was even reduced by 55%!

@thewtex thewtex requested a review from ntustison September 7, 2021 19:37
@thewtex thewtex merged commit 3f610f3 into InsightSoftwareConsortium:master Sep 8, 2021
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Sep 12, 2021
Follow-up to pull request InsightSoftwareConsortium#2716
commit 99f04d7
"ENH: Add static member function `BSplineKernelFunction::FastEvaluate(u)`"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Sep 12, 2021
Removed the two dynamically allocated "cubic kernel" data members from
`MattesMutualInformationImageToImageMetric` and replaced the virtual
`Evaluate` function calls by a faster static member function call, to
the newly added `FastEvaluate` member functions.

Follow-up to pull request InsightSoftwareConsortium#2716
commit c23944b
"PERF: Remove BSplineInterpolationWeightFunction Kernel, use FastEvaluate"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Sep 13, 2021
Removed the two dynamically allocated "cubic BSpline kernel" data
members from both `MattesMutualInformationImageToImageMetric` and
`MattesMutualInformationImageToImageMetricv4`. Replaced the virtual
`Evaluate` function calls by faster static member function calls, to
the newly added `FastEvaluate` member functions of the corresponding
`KernelFunction` classes.

Follow-up to pull request InsightSoftwareConsortium#2716
commit c23944b
"PERF: Remove BSplineInterpolationWeightFunction Kernel, use FastEvaluate"
dzenanz pushed a commit that referenced this pull request Sep 14, 2021
Follow-up to pull request #2716
commit 99f04d7
"ENH: Add static member function `BSplineKernelFunction::FastEvaluate(u)`"
dzenanz pushed a commit that referenced this pull request Sep 14, 2021
Removed the two dynamically allocated "cubic BSpline kernel" data
members from both `MattesMutualInformationImageToImageMetric` and
`MattesMutualInformationImageToImageMetricv4`. Replaced the virtual
`Evaluate` function calls by faster static member function calls, to
the newly added `FastEvaluate` member functions of the corresponding
`KernelFunction` classes.

Follow-up to pull request #2716
commit c23944b
"PERF: Remove BSplineInterpolationWeightFunction Kernel, use FastEvaluate"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jan 26, 2022
Paving the way for the introduction of `FastEvaluate` member functions, as introduced with ITK v5.3rc02:

 - ITK pull request InsightSoftwareConsortium/ITK#2716 commit InsightSoftwareConsortium/ITK@99f04d7 "ENH: Add static member function `BSplineKernelFunction::FastEvaluate(u)`"

 - ITK pull request InsightSoftwareConsortium/ITK#2731 commit InsightSoftwareConsortium/ITK@760ae12 "ENH: Add static `FastEvaluate(u)` to `BSplineDerivativeKernelFunction`"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jan 26, 2022
Similar to the `FastEvaluate` member functions, introduced with ITK v5.3rc02:

 - ITK pull request InsightSoftwareConsortium/ITK#2716 commit InsightSoftwareConsortium/ITK@99f04d7 "ENH: Add static member function `BSplineKernelFunction::FastEvaluate(u)`"

 - ITK pull request InsightSoftwareConsortium/ITK#2731 commit InsightSoftwareConsortium/ITK@760ae12 "ENH: Add static `FastEvaluate(u)` to `BSplineDerivativeKernelFunction`"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jan 27, 2022
Paving the way for the introduction of `FastEvaluate` member functions, as introduced with ITK v5.3rc02:

 - ITK pull request InsightSoftwareConsortium/ITK#2716 commit InsightSoftwareConsortium/ITK@99f04d7 "ENH: Add static member function `BSplineKernelFunction::FastEvaluate(u)`"

 - ITK pull request InsightSoftwareConsortium/ITK#2731 commit InsightSoftwareConsortium/ITK@760ae12 "ENH: Add static `FastEvaluate(u)` to `BSplineDerivativeKernelFunction`"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jan 27, 2022
Similar to the `FastEvaluate` member functions, introduced with ITK v5.3rc02:

 - ITK pull request InsightSoftwareConsortium/ITK#2716 commit InsightSoftwareConsortium/ITK@99f04d7 "ENH: Add static member function `BSplineKernelFunction::FastEvaluate(u)`"

 - ITK pull request InsightSoftwareConsortium/ITK#2731 commit InsightSoftwareConsortium/ITK@760ae12 "ENH: Add static `FastEvaluate(u)` to `BSplineDerivativeKernelFunction`"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Feb 20, 2022
Replaced calls to the old virtual `itk::BSplineKernelFunction` member function `Evaluate` by its static member function `FastEvaluate`. Removed unnecessary `itk::BSplineKernelFunction` objects.

May improve the performance of both `DistancePreservingRigidityPenaltyTerm` (from Metrics) and `BSplineSecondOrderDerivativeKernelFunction` (from Testing).

This `FastEvaluate` member function was introduced by ITK pull request InsightSoftwareConsortium/ITK#2716 commit InsightSoftwareConsortium/ITK@99f04d7 "PERF: `ENH: Add static member function `BSplineKernelFunction::FastEvaluate(u)`" (merged on 8 September 2021), and included with ITK v5.3rc01.
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Feb 20, 2022
Replaced calls to the old virtual `itk::BSplineDerivativeKernelFunction` member function `Evaluate` by its static member function `FastEvaluate`. Removed unnecessary `BSplineInterpolationWeightFunctionBase` data member, `m_DerivativeKernel`.

May improve the performance of both `BSplineInterpolationDerivativeWeightFunction` and `BSplineInterpolationSecondOrderDerivativeWeightFunction` (from Common/Transforms).

This `FastEvaluate` member function was introduced by ITK pull request InsightSoftwareConsortium/ITK#2716 commit InsightSoftwareConsortium/ITK@760ae12 "ENH: Add static `FastEvaluate(u)` to `BSplineDerivativeKernelFunction`" (merged on 14 September 2021), and included with ITK v5.3rc02.
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Feb 21, 2022
Replaced calls to the old virtual `itk::BSplineKernelFunction` member function `Evaluate` by its static member function `FastEvaluate`. Removed unnecessary `itk::BSplineKernelFunction` objects.

May improve the performance of both `DistancePreservingRigidityPenaltyTerm` (from Metrics) and `BSplineSecondOrderDerivativeKernelFunction` (from Testing).

This `FastEvaluate` member function was introduced by ITK pull request InsightSoftwareConsortium/ITK#2716 commit InsightSoftwareConsortium/ITK@99f04d7 "PERF: `ENH: Add static member function `BSplineKernelFunction::FastEvaluate(u)`" (merged on 8 September 2021), and included with ITK v5.3rc01.
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Feb 21, 2022
Replaced calls to the old virtual `itk::BSplineDerivativeKernelFunction` member function `Evaluate` by its static member function `FastEvaluate`. Removed unnecessary `BSplineInterpolationWeightFunctionBase` data member, `m_DerivativeKernel`.

May improve the performance of both `BSplineInterpolationDerivativeWeightFunction` and `BSplineInterpolationSecondOrderDerivativeWeightFunction` (from Common/Transforms).

This `FastEvaluate` member function was introduced by ITK pull request InsightSoftwareConsortium/ITK#2716 commit InsightSoftwareConsortium/ITK@760ae12 "ENH: Add static `FastEvaluate(u)` to `BSplineDerivativeKernelFunction`" (merged on 14 September 2021), and included with ITK v5.3rc02.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Performance Improvement in terms of compilation or execution time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants