ermig1979 / Simd

C++ image processing and machine learning library with using of SIMD: SSE, AVX, AVX-512, AMX for x86/x64, VMX(Altivec) and VSX(Power7) for PowerPC, NEON for ARM.
http://ermig1979.github.io/Simd
MIT License
2.03k stars 406 forks source link

SimdResizerInit overhead? #187

Closed mikeversteeg closed 2 years ago

mikeversteeg commented 2 years ago

Should I assume SimdResizerInit/SimdRelease adds noticeable overhead to SimdResizerRun, which is the reason it is not combined into one function? I have a function called by many threads which (also) resizes an YUV bitmap, and each call may require different sizes. I'm wondering how best to implement this.

ermig1979 commented 2 years ago

SimdResizerInit creates precalculated resize coefficients for current sizes of input and output image. SimdResizerInit ~ dstH + dstW, SimdResizerRun ~ dstH * dstW. Separation of SimdResizerInit/SimdRelease/SimdResizerRun is mainly useful for video processing.

mikeversteeg commented 2 years ago

I don't understand. If it's a simple calculation then I assume there is no noticeable overhead in calculating this every time (especially with HD video) and so this could be just one function? I thought maybe there was some time consuming table construction going on..

ermig1979 commented 2 years ago

Of course it can be one function. For example see function Simd::Resize :

template<template<class> class A> SIMD_INLINE void Resize(const View<A> & src, View<A> & dst, ::SimdResizeMethodType method = ::SimdResizeMethodBilinear)
{
    assert(src.format == dst.format && (src.format == View<A>::Float || src.ChannelSize() == 1));

    if (EqualSize(src, dst))
    {
        Copy(src, dst);
    }
    else
    {
        SimdResizeChannelType type = src.format == View<A>::Float ? SimdResizeChannelFloat : SimdResizeChannelByte;
        void * resizer = SimdResizerInit(src.width, src.height, dst.width, dst.height, src.ChannelCount(), type, method);
        if (resizer)
        {
            SimdResizerRun(resizer, src.data, src.stride, dst.data, dst.stride);
            SimdRelease(resizer);
        }
        else
            assert(0);
    }
}