cfpgaxilinxregister-transfer-levelvivado-hls

Vitis HLS Pointer to Pointer is not supported for variable when initializing struct array


I'm trying to make a state machine that is synthesizable into a hardware description through Vitis HLS. I'm getting the error ERROR: [HLS 214-134] in function 'kernel1(char*, int)': Pointer to pointer is not supported for variable ''. This is happening in:

I don't get why that specific error pops up in these situations. I get no error when trying to do it 'manually' (without the array), like in:

transitions_occurred += testTransition(&a, stream, &stream_index);
transitions_occurred += testTransition(&b, stream, &stream_index);

Here's the full code:

#include <stdio.h>
#include <stdbool.h>
#include <string.h>

typedef struct {
    bool active;
} State;

typedef struct {
    char token;
    State *current;
    State *next;
    int stream_increment;
} Transition;

bool testTransition(Transition *t, char* stream, int *stream_index)
{
    if (!t->current->active)
        return false;
    
    if (t->token == stream[*stream_index])
    {
        t->next->active = true;
        *stream_index += t->stream_increment;
        return true;
    }

    return false;
}

#define STATE_NO 3
#define START_STATE 0
#define END_STATE 2

bool kernel1(char stream[], int stream_size)
{
    State current[STATE_NO] = {0};
    State next[STATE_NO] = {0};
    current[START_STATE].active = true;

    Transition a = {'a', &current[0], &next[1], 1};
    Transition b = {'b', &current[1], &next[2], 1};
    Transition transitions[] = {a, b};
    size_t transition_no = sizeof(transitions) / sizeof(Transition);

    int stream_index = 0;
    int transitions_occurred;

    do {
        transitions_occurred = 0;
        for (int i = 0; i < transition_no; i++)
            transitions_occurred += testTransition(&transitions[i], stream, &stream_index);

        memcpy(current, next, STATE_NO * sizeof(State));
        memset(next, 0, STATE_NO * sizeof(State));
    } while (stream_index != stream_size && transitions_occurred);

    return current[END_STATE].active;
}

Solution

  • I don't get why that specific error pops up in these situations.

    transitions is a pointer to Transition objects which contain pointers.

    I get no error when trying to do it 'manually' (without the array)

    Vivado-HLS will inline function calls with pointer-to-pointer. That is why a direct call with the reference to the object works as no pointer to that object is ever created.

    Pointer to pointer support is limited. Please check the Pointer sections in the user guides UG902 / UG1399.