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 

compiling bluesim-generated c++ -> out-of-memory with -O3

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



Joined: 14 Jun 2007
Posts: 14

PostPosted: Thu Oct 15, 2009 1:26 am    Post subject: compiling bluesim-generated c++ -> out-of-memory with -O3 Reply with quote

Hi folks,

I'm having a slight problem with compiling a bluespec module (into Bluesim) where I've replicated a large number of modules.

Specifically, I have something like this:
Vector#(256, ObjIfc) objs <- replicateM(mkObj());

For large replication values (128 or above), gcc basically runs out of memory (taking > 2GB) when it tries to compile the bluespec-generated schedule.cxx file. (Also, I notice that the generated schedule.cxx file is huge, about 60,000L).

Just FYI, each of the objects are of medium complexity (~5-10 rules). To prevent the compiler from flattening, I use the "synthesize" pragma for the object.

One work-around that I've found is to pass in "-Xc++ -O0", which tells gcc to disable all optimizations. Once I do this, the compilation finishes in seconds. Unfortunately, it would be nice to get the GCC optimizations as well to keep the simulator fast. I am currently using gcc 4.1.0.

Any advice?

Thanks,
--Eric
Back to top
View user's profile Send private message
jnewbern



Joined: 18 Jul 2007
Posts: 71

PostPosted: Fri Oct 16, 2009 5:20 pm    Post subject: Reply with quote

Eric,

We have seen this problem before (most often with g++ 4.2), and it is written up as KPNS #28.

As you say, the simplest workaround is to lower the optimization level used with the g++ compilation. By default we use -O3 to achieve the best performance, but this also enables some optimizations that don't necessarily scale as well as the lower optimization levels.

One thing you can try is to use an intermediate level of optimization, like -O1 or -O2. This may give almost equivalent performance without blowing up the compilation.

A long term solution is for us to restructure the code we generate for Bluesim to avoid creating large functions for g++ to work on. Until that happens, however, I'm afraid that reducing the -O level is the best workaround.
Back to top
View user's profile Send private message
eschung



Joined: 14 Jun 2007
Posts: 14

PostPosted: Mon Oct 19, 2009 12:05 am    Post subject: thanks Reply with quote

Jeff,

Thanks, I should've checked that list first =D.

Just a follow-up question. Is there an easy way for me to just disable -O3 optimizations for schedule.cxx? I am compiling in some other C-imported files (by passing the C filenames as arguments) but those should have no problem compiling at the highest optimization level.

--Eric
Back to top
View user's profile Send private message
jnewbern



Joined: 18 Jul 2007
Posts: 71

PostPosted: Mon Oct 19, 2009 7:30 am    Post subject: Reply with quote

Eric,

When incorporating external C/C++ code you have the option of compiling the code yourself, with whatever options are appropriate, and then naming the .o files on the bsc command line instead of the .c files. As long as the files are compiled with the correct linkage and ABI version, there should be no problem incorporating pre-compiled object files and even external libraries.

Hope that helps,
Jeff
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: Bluesim 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