Arrays in DPI-C

Hi, everyone!
i wonder, what is the proper way to pass arrays in and out of C functions? Should i only stick to open arrays? Right now im trying to do it like this:


import "DPI-C" context function void equalizer_training (																					input int h_re[2][8][2048],																										input int h_im[2][8][2048],																										input int sigma0,																											input int sigma1,																											input int	pilots_idx [2048],																									input int data_idx [2048],																										input int n_data,																											input int n_pilots,																											input int fft_size,																														input int num_rx,																														input int N_ss,																														input int N_ss_total,																														input int P_ss,																														input int N_ss_pilots,
																														output int b0[2048],																														output int b1[2048],																														output int fft_mat_outp_re [2][2][2048],																	 													output int fft_mat_outp_im [2][2][2048],																	 													output int llrw_lshift0[2048],																	 													output int llrw_lshift1[2048],																	 													output int llrw_val0[2048],																	 													output int llrw_val1[2048],																	 													output int w_lshift[2048]																													);

the header i get looks like this:


DPI_LINK_DECL DPI_DLLESPEC
void
equalizer_training(
    const int* h_re,
    const int* h_im,
    int sigma0,
    int sigma1,
    const int* pilots_idx,
    const int* data_idx,
    int n_data,
    int n_pilots,
    int fft_size,
    int num_rx,
    int N_ss,
    int N_ss_total,
    int P_ss,
    int N_ss_pilots,
    int* b0,
    int* b1,
    int* fft_mat_outp_re,
    int* fft_mat_outp_im,
    int* llrw_lshift0,
    int* llrw_lshift1,
    int* llrw_val0,
    int* llrw_val1,
    int* w_lshift);

and cpp file is:

void equalizer_training (
int h_re[2][8][2048],
int h_im[2][8][2048],
int sigma0,
int sigma1,
int	pilots_idx [2048],
int data_idx [2048],
int n_data,
int n_pilots,
int fft_size,
int num_rx,
int N_ss,
int N_ss_total,
int P_ss,
int N_ss_pilots,

int* b0[2048],
int* b1[2048],
int* fft_mat_outp_re [2][2][2048],
int* fft_mat_outp_im [2][2][2048],
int* llrw_lshift0[2048],
int* llrw_lshift1[2048],
int* llrw_val0[2048],
int* llrw_val1[2048],
int* w_lshift[2048]
) {...

when i simulate, i get this warning:

Failed to find user specified function ‘equalizer_training’ in DPI precompiled library search list "./c_model/equalizer_training_c_model.so

i wonder if the reason of this warnning (wihc leads to simulation crush) is that declarations in DPI-C export … and header file are different.

Thank you!

In reply to boryah:

Are you actually include’ing the header file? If you are compiling C++ code, the function needs to be extern to C.

You might want to look at this page for converting between the different array references.

In reply to dave_59:

Thank you for reply.
Not sure, that I understood you.
What do you mean by “function extern to C”? in dpiheader these lines were formed automatically:


#ifdef __cplusplus
#define DPI_LINK_DECL  extern "C" 
#else
#define DPI_LINK_DECL 
#endif

In cpp file I do have line

#include " dpiheader.h"

i’ve read an article you’ve sent.
So in cpp file i should not use

int h_re[2][8][2048]

and instead write as in dpiheader:

const int* h_re

right?
But what happens on verilog side? May i still pass an array in this function “as is”?