-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntArray error #27
Comments
Can you show me the code where you call the DPI function? Especially the array definition. |
Ok, in python side:
In sv side:
|
|
Thanks, the queue can not be used here. But the same error occurs when I use dynamic array or static array:
And i still think the reason of this error is usage of svSize function in c file. The similar error occurs when I take another experiment that I try to use svLow(h,0) function to get the lower bound of the first dimension of the array passed from sv to c: Error-[DPI-ASSERT] Assertion failure in DPI call Maybe the dimension parameter of these functions(likes svLow,svHigh,svSize) should start from 1 rather than 0? In addition, i want to know what the code looks like if i pass a 3d array to python from sv. Here i was going to pass an array(3x8x8) to python. If i know how to do, i will do not use flatten in sv and reshape in python. |
That's a good point. I will double check the spec. In the meantime, can you try to modify the generated C++ code and see if it works?
Once the bug is fixed, the C++ you posted should produce a 3d Python array to the binding, at least that's the intention. I haven't extensively tested it thought. |
Only modifying the generated c++ code doesn't work, and maybe the shared library need to be recompiled. But i do not know how to recompile due to dependency issues.
Actually, I want to know what the code looks like in python side, and just using IntArray as parameter type maybe can't generate sv binding as: |
Ok, i modify the code in pysv package installed and it works. The code modified is in file snippets/buffer_impl.cc:
But the 3x8x8 array data is not correct. The data printed in sv is: '{126, 99, 120, 153, 229, 203, 121, 53, 202, 178, 172, 25, 106, 179, 187, 133, 55, 41, 168, 119, 200, 132, 47, 146, 215, 42, 70, 22, 118, 58, 60, 201, 7, 185, 65, 42, 201, 144, 100, 97, 233, 82, 227, 232, 255, 104, 176, 39, 70, 122, 94, 29, 154, 240, 54, 127, 185, 160, 23, 6, 36, 237, 230, 115, 232, 31, 95, 24, 68, 170, 197, 31, 31, 162, 168, 38, 97, 58, 241, 206, 27, 203, 7, 63, 39, 105, 172, 200, 229, 59, 71, 46, 182, 161, 68, 37, 195, 239, 198, 81, 99, 227, 100, 96, 188, 39, 173, 235, 61, 146, 242, 196, 136, 150, 39, 13, 52, 210, 206, 208, 165, 0, 205, 208, 9, 199, 63, 221, 193, 29, 40, 29, 1, 124, 146, 173, 101, 204, 108, 244, 149, 233, 220, 38, 29, 137, 182, 251, 53, 137, 189, 242, 241, 206, 254, 7, 247, 76, 132, 193, 192, 45, 96, 83, 216, 158, 156, 109, 126, 13, 40, 36, 180, 149, 46, 67, 132, 81, 223, 103, 168, 116, 209, 178, 191, 229, 71, 157, 9, 56, 84, 229} The data printed in python is: 126,0,0,0,0,0,0,0,0,0,1272250368,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65535,0,0,0,0,0,0,0,0,0,0,0,0,0,0,355991751,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1146307414,543515759,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1272067408,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, Maybe the code in to_buffer function is not correct? |
You're right about this. The type info is not properly encoded and thus only 1D array is generated. I have some ideas on how to add type annotation on the multi-d array. and I will work on that next.
It might be. I only tested the code with Verilator (the one I have access to on my laptop) and using Thanks again for finding the issues. |
Looking forward to improvements in future |
Should be fixed in the latest commit/release. Please reopen this issue if it doesn't work for you (I only tested it with Verilator). Example usage for a 3D array: DataType.IntArray[3] |
Emmm, maybe i have not access to reopen this issue. A new problem is the static multi-dimensional array defined can't be passed to function in sv binding(maybe it doesn't has the conception of multi-dimensional dynamic array). As follows: Incompatible complex type usage in task or function call. If i define a multi-dimensional dynamic array (maybe called open array, likes data[][][]) and pass it to function in sv binding, a new error occurs: Incompatible complex type usage in task or function call. Finally, after i modify parameter type to static array in sv binding function and define a static array to pass it, everything works. the example code is: // my array
int data[3][8][8];
Img2colVerificationTools m_gen=new();
m_gen.get_fea(data);
//import c functoin, dosn't modify
import "DPI-C" function void Img2colVerificationTools_get_fea(input chandle self,
input int fea_array[][][]);
//modify to static array
class Img2colVerificationTools extends PySVObject;
......
function void get_fea(input int fea_array[3][8][8]);
Img2colVerificationTools_get_fea(pysv_ptr, fea_array);
endfunction
endclass |
What simulator are you using? I tested the open array DPI interface with all big three simulators (VCS, Xcelium, and Questa), and Verilator. They all work with static-sized array. See the EDA playground example here: https://www.edaplayground.com/x/jrga module dpi_tb;
import "DPI-C" context function void test_array(input int array[][]);
int value[2][4];
initial
begin
test_array(value);
end
endmodule #include <stdio.h>
#include <iostream>
#include <svdpi.h>
using namespace std;
extern "C" {
void test_array(svOpenArrayHandle array) {
printf("works\n");
}
} |
I use the vcs to run. And i mean that static-sized array actually works, but error occurs in systemverilog binding. When a class is used in python, c++ file uses many static functions to map this class and systemverilog binding wraps these static functions into a sv class. Finally, we call this sv class for using as like calling python class. A this class example in sv binding generated is: class Img2colVerificationTools extends PySVObject;
function new();
pysv_ptr = Img2colVerificationTools_pysv_init();
endfunction
function void get_fea(input int fea_array[][][]);
Img2colVerificationTools_get_fea(pysv_ptr, fea_array);
endfunction
endclass As like the above code, the formal parameter of |
Got it. Thanks for the explanation. I am able to reproduce the error. I didn't realize that the class method is causing the issue. I don't know a quick workaround at the moment so unfortunately you have to use top-level functions instead of a python class. I will see if there is any workaround. Reopen this issue for tracking. |
Hi,
I use IntArray as funtion parameter in python side and compile passed. But a error occurs when I simulate by vcs:
Error-[DPI-ASSERT] Assertion failure in DPI call
Assertion failure in DPI function/task call: dimension 0 query is not supported. (svSize)
Please check the parameter passing in a DPI function/task call
And I find that the svSize is used in c file, which generated by compile_lib:
Maybe this (dim in for loop begins from 0 ) causes the error?
The text was updated successfully, but these errors were encountered: