bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Linking BDPI C functions with third-party Verilog simulators

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: Other
View previous topic :: View next topic  
Author Message
arnab90



Joined: 29 May 2009
Posts: 2

PostPosted: Tue Jul 28, 2009 10:44 am    Post subject: Linking BDPI C functions with third-party Verilog simulators Reply with quote

I have a Bluespec design which uses an imported BDPI C function. I can compile, link and simulate this fine using bsc. However, if I use bsc to generate Verilog output and then try to manually link these using Synopsys VCS I get a linking error. In more detail:

File RandomTrafficSource.bsv imports C function inject_process

Code:
import "BDPI" function Bit#(64) inject_process (Count current_inject_count);

interface TrafficSourceIfc;
....
endinterface

(* synthesize *)
module mkRandomTrafficSource (TrafficSourceIfc);
....
endmodule


File inject_process.c

Code:
#include <stdio.h>
#include <stdlib.h>

unsigned long inject_process (unsigned int current_inject_count) {
....
}


I then use bsc to generate verilog output for the top level testbench mkTestRandom and all other modules using

Code:
bsc -u -verilog -g mkTestRandom TestRandom.bsv


This generates mkTestRandom.v, mkRandomTrafficSource.v and other verilog output files and vpi_wrapper_inject_process.c, vpi_wrapper_inject_process.h and vpi_startup_array.c. It also generates directc.tab containing:

Code:
$imported_inject_process call=inject_process_calltf size=64 acc=rw:%TASK


I'm then unsure as to how to link these output files with a third-party tool such as VCS. For a first attempt I tried using VCS as follows:

Code:
vcs +v2k +vpi -cc gcc -ld gcc -CFLAGS "-I$VCS_HOME/`vcs -platform`/include" \
-F verilog-source-files.txt
-P directc.tab vpi_wrapper_inject_process.c inject_process.c \
-o simv -R


This produces the following error:

Code:
vpi_wrapper_inject_process.o: In function `inject_process_calltf':
vpi_wrapper_inject_process.c:(.text+0x8f): undefined reference to `make_vpi_result'
vpi_wrapper_inject_process.c:(.text+0xa9): undefined reference to `get_vpi_arg'
vpi_wrapper_inject_process.c:(.text+0xc3): undefined reference to `get_vpi_arg'
vpi_wrapper_inject_process.c:(.text+0xdd): undefined reference to `get_vpi_arg'
vpi_wrapper_inject_process.c:(.text+0xf7): undefined reference to `get_vpi_arg'
vpi_wrapper_inject_process.c:(.text+0x125): undefined reference to `put_vpi_result'
vpi_wrapper_inject_process.c:(.text+0x12a): undefined reference to `free_vpi_args'


I notice that these might be defined in $BLUESPEC/lib/VPI/g++version/libbdpi.so. Additionally, uname -i gives x86_64 and gcc --version gives gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13). So I re-ran VCS by instructing it to include the bdpi library with:

Code:
vcs +v2k +vpi -cc gcc -ld gcc -CFLAGS "-I$VCS_HOME/`vcs -platform`/include" \
-LDFLAGS "-L$BLUESPEC/lib/VPI/g++4_64" \
-LDFLAGS "-lbdpi" \
-F verilog-source-files.txt
-P directc.tab vpi_wrapper_inject_process.c inject_process.c \
-o simv -R


However, this still doesn't work and gives:

Code:
simv up to date
simv: error while loading shared libraries: libbdpi.so: wrong ELF class: ELFCLASS32
Note: Execution of simv exited with code 127


Is there anything obvious I'm doing wrong??
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Tue Jul 28, 2009 12:28 pm    Post subject: Re: Linking BDPI C functions with third-party Verilog simula Reply with quote

arnab90 wrote:
I can compile, link and simulate this fine using bsc. However, if I use bsc to generate Verilog output and then try to manually link ...

When you say that you can link and simulate fine using BSC, do you mean link and simulate via Verilog? In which case, the difference between the two scenarios is only whether you use BSC to link or whether you link manually. Or do you mean link and simulate via Bluesim? In which case, can you try the same procedure using the "-verilog" flag, so we can see if BDPI works in that case?

If you are able to get BDPI to work in Verilog using BSC to perform the link step, then that means that it will work manually if we use the right command-line arguments.

As mentioned in Section 4.3.3 of the User Guide, "Linking with Verilog", when you link Verilog using BSC, the linking is done by a script that can be found in $(BLUESPECDIR)/bin/. In that directory are a number of scripts called "bsc_build_vsim_*", where the last part is the specific simulator that the script works for. So, in your case, the script "bsc_build_vsim_vcs" is the script that you want to look at. If this script works for you when linking with BSC, then we should see what commands it is using to invoke VCS and copy the flags.
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Tue Jul 28, 2009 2:30 pm    Post subject: Re: Linking BDPI C functions with third-party Verilog simula Reply with quote

Here's what BSC does for VCS.

It looks like you're using VCS to do the compilation of the C files, for example. It may be a good idea to get things working explicitly first and then see what steps we can simplify by having VCS do some of them for us. For example, I'm not sure what flags VCS provides to gcc when it invokes the compiler, and we'd have to check that.

What BSC does is it first compiles any C files if you haven't already made object files out of them:

Quote:
cc -O3 -g -Wall -Wno-unused -D_FILE_OFFSET_BITS=64 -fPIC -c -o inject_process.o inject_process.c


I don't think that the flags matter too much here, but those are the flags which BSC uses.

BSC does the same with the wrapper files:

Quote:
cc -O3 -g -Wall -Wno-unused -D_FILE_OFFSET_BITS=64 -I$(BLUESPECDIR)/VPI -fPIC -c -o vpi_wrapper_inject_process.o vpi_wrapper_inject_process.c


Note that the command-line here is specifying the include directory where the VPI header files can be found. I didn't see an equivalent for that in your VCS command.

Then, BSC links together the objects that it has generated, and at that point includes the VPI library:

Quote:
c++
-shared
-o directc_[topmodulename].so
-Wl,-rpath,$(BLUESPECDIR)/VPI/g++4
-L$(BLUESPECDIR)/VPI/g++4
inject_process.o
vpi_wrapper_inject_process.o
-lbdpi


This generates the shared object that will be loaded into VCS. The VCS command is then:

Quote:
vcs
-o simv +v2k +libext+.v
-y .
-y $(BLUESPECDIR)/Verilog
+vpi -P directc_[topmodulename].tab
-load ./directc_[topmodulename].so:vpi_register_tasks
directc_[topmodulename].so
...


I ran this with 32-bit libraries. For 64-bit libraries, I suspect the only difference is the directory for the library, but I can try to confirm that.
Back to top
View user's profile Send private message
arnab90



Joined: 29 May 2009
Posts: 2

PostPosted: Wed Jul 29, 2009 12:19 pm    Post subject: Reply with quote

Explicitly compiling the C source files and manually generating and loading the shared object into VCS seems to work fine. Thanks quark! Not sure what the problem was originally..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: Other All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP