vpiSubmitHostFunction example

Hello, where can I find an example for a host function using vpiSubmitHostFunction with parameters?

Hi ilya9,

Thanks for reaching out!

The following steps worked for me,

Step 1 - Include the <vpi/HostFunction.h> header.

#include <vpi/HostFunction.h>

Step 2 - Define the host function.

We’ll create one that prints an integer argument.

void printIntArgument(void *args) {
   int *valuePtr = reinterpret_cast<int*>(args);
   std::cout << "value = " << *valuePtr << std::endl;
}

Step 3 - Submit the host function.

We’ll assume you already have a VPIStream named stream and a variable status to hold the returned VPIStatus.

int value = 123;
status = vpiSubmitHostFunction(stream, printIntArgument, reinterpret_cast<void*>(&value));

Please let me know if this helps or you run into any issues or have any questions!

Best,
John

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.