Constructor with Reference to an Array - 2024.1 English

Vitis Model Composer User Guide (UG1483)

Document ID
UG1483
Release Date
2024-05-30
Version
2024.1 English
Consider the following example that declares the constructor with reference to an array as argument.

fir.h

class FIR
{
    private:
        int32 (&coeffs)[NUM_COEFFS];
        int32 tapDelayLine[NUM_COEFFS];
        uint32 numSamples;
    public:
        FIR(int32(&coefficients)[NUM_COEFFS], uint32 samples);
        void filter(input_buffer<int32> & in, output_buffer<int32> & out);
        static void registerKernelClass()
        {
            REGISTER_FUNCTION(FIR::filter);
            REGISTER_PARAMETER(coeffs);
        }
};

fir.cpp

#include "fir.h"
FIR::FIR(int32(&coefficients)[NUM_COEFFS], uint32 samples)
: coeffs(coefficients)
{
    for (int i = 0; i < NUM_COEFFS; i++)
    tapDelayLine[i] = 0;
    numSamples = samples;
}
void FIR::filter(input_buffer<int32> & in, output_buffer<int32> & out)
{
    ...
}

Here, member variable coeffs is an int32 (&)[NUM_COEFFS] data type. The constructor initializer coeffs(coefficients) initializes coeffs to the reference to an array allocated externally to the class object. To let the aiecompiler know that the coeffs member variable is intended to be allocated by the compiler, you must use REGISTER_PARAMETER to register an array reference member variable inside the registerKernelClass() method. The aiecompiler throws an appropriate error if the constructors with reference to an array are not registered.