The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 17th, 2024, 6:43pm
Pages: 1
Send Topic Print
Issue with fopen:erase first time through append afterwards (Read 6258 times)
Claude
New Member
*
Offline



Posts: 5

Issue with fopen:erase first time through append afterwards
Nov 07th, 2012, 2:13pm
 
Sir, I am beginner coder in verilog AMS. Is there a way to implement a semaphore in analog blocks? I try to open/write/close information in files for each instance using %m, but very quickly I run into the 32 max number of mcd.
I tried to add a randomize loop before doing the open/write/close to try releasing the mcd before another instance needs it but this does not seem to work.

Thank you and Regards,
Claude
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: Issue with fopen:erase first time through append afterwards
Reply #1 - Nov 8th, 2012, 7:34am
 
I don't understand what you mean; does your simulator restrict you to 32 files open per simulation?  I would have thought that each instance could open 32 files of its own.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Claude
New Member
*
Offline



Posts: 5

Re: Issue with fopen:erase first time through append afterwards
Reply #2 - Nov 8th, 2012, 9:05am
 
Ok, this seems to be correct, I did test with more than 32 instances and did not get a fail. It fail for 500+ instances, so the issue is probably in the simulator limit. So assuming that it is simulator, I would still need to find a way to avoid trying to open a file when I am getting close to that limit, any suggestions as to how this could be achieved?

Another odd issue was that one instance seemed to be writing into the file opened for another instance and I thought that the file IDs were open at simulation instance (thus my thinking of 32 limit per simulation run) and descriptors ended up re-used for several instances:

code:
inst_name = $sformat(inst_name, "%m");
handle = $fopen(inst_name,"w");
$fdisplay(handle,"this fdisplay for %m");
$fclose(handle);

output:
xm1.log:
this is fdisplay for xm1
this is fdisplay for xm2
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: Issue with fopen:erase first time through append afterwards
Reply #3 - Nov 8th, 2012, 1:34pm
 
Are you sure you want to be opening and closing 500+ files during your simulation?  That seems like a lot, and it could make your simulation run very slowly.  Also, I wonder if the operating system has a limit on number of open files.

Might you have "xm1" in two different locations in the hierarchy?  Do you have xm1 and XM1?

You may need to talk to technical support for your simulator; you may be pushing some internal limit, and maybe they can help you work around it.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Claude
New Member
*
Offline



Posts: 5

Re: Issue with fopen:erase first time through append afterwards
Reply #4 - Nov 8th, 2012, 2:44pm
 
Geoffrey,
Well, yes that is a lot, but the verilog code within the open-close is very small. I was hoping there would be a means of doing it, the alternative of writing to the same file generated 100s MB file.

I am pretty sure about the instance name difference, it is actually a 5+level deep hierarchy that I simplified to xm1 and xm2 for clarity  ;)

My IT mentioned possible issues with multi-thread and multi-cpu that could create file ID collisions and they are looking into my testcase as well.

I also saw a scheduler-like framework with one global instance that would distribute tokens to the instances that are ready towrite, but I wonder if this would work within the analog space (the semaphore did not).

PS: Is there a way to detect whether the current pass in a veriloga code is the converged pass, like $final_step, but for convergence?

Thank you,
Claude

Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: Issue with fopen:erase first time through append afterwards
Reply #5 - Nov 9th, 2012, 6:19am
 
Claude wrote on Nov 8th, 2012, 2:44pm:
PS: Is there a way to detect whether the current pass in a veriloga code is the converged pass, like $final_step, but for convergence?


No, because the solver does not know it is a converged pass until after the evaluation, when it adds up all the currents from every element and checks if Kirchoff's laws are satisfied.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Issue with fopen:erase first time through append afterwards
Reply #6 - Nov 9th, 2012, 6:36am
 
Claude wrote on Nov 8th, 2012, 2:44pm:
Geoffrey,
Well, yes that is a lot, but the verilog code within the open-close is very small. I was hoping there would be a means of doing it, the alternative of writing to the same file generated 100s MB file.

I am pretty sure about the instance name difference, it is actually a 5+level deep hierarchy that I simplified to xm1 and xm2 for clarity  ;)

My IT mentioned possible issues with multi-thread and multi-cpu that could create file ID collisions and they are looking into my testcase as well.

I also saw a scheduler-like framework with one global instance that would distribute tokens to the instances that are ready towrite, but I wonder if this would work within the analog space (the semaphore did not).

PS: Is there a way to detect whether the current pass in a veriloga code is the converged pass, like $final_step, but for convergence?

Thank you,
Claude


Hi Claude,
I'd like to add that according to the Verilog-AMS LRM (v2.3.1) sec. 9.5.1 "[t]he most significant bit (bit 31) of a multichannel descriptor is reserved and shall always be cleared, limiting an implementation to at most 31 files opened for output via multichannel descriptors."

- B O E
Back to top
 
 
View Profile   IP Logged
Claude
New Member
*
Offline



Posts: 5

Re: Issue with fopen:erase first time through append afterwards
Reply #7 - Nov 9th, 2012, 9:51am
 
Geoffrey_Coram wrote on Nov 9th, 2012, 6:19am:
Claude wrote on Nov 8th, 2012, 2:44pm:
PS: Is there a way to detect whether the current pass in a veriloga code is the converged pass, like $final_step, but for convergence?


No, because the solver does not know it is a converged pass until after the evaluation, when it adds up all the currents from every element and checks if Kirchoff's laws are satisfied.


Geoffrey, I was referring to the mechanism used by $display/$fdisplay (as opposed to $debug/$fdebug), using $debug/$fdebug, I found that the $fopen failure happens during the convergence phase. I used $display before and kept wondering why I could not print at least the first 30 fopen file IDs, switching to $debug showed me why, now I can see the IDs and sure enough I get to MCD=1073741824, then $fopen() fails.
Back to top
 
 
View Profile   IP Logged
Claude
New Member
*
Offline



Posts: 5

Re: Issue with fopen:erase first time through append afterwards
Reply #8 - Nov 27th, 2012, 1:26pm
 
So apparently, I was mis-reading the documentation, there seem to be provision in Verilog-2001 for 2**31 available file descriptors and when specifying:
           $sformat(inst_filename, "EVL_DBG_%m.log");
           // mcd = $fopen("%m"); MCD only 30 channel since now MSB of MCD is reserved to identify multi-channel vs file descriptors
            handle = $fopen(inst_filename, "w"); // Should have 2**31 possibilities
           $fdisplay(handle, "tran %d:%b", handle, handle);
           $debug("tran %d:%b %m", handle, handle);
           $fclose(handle);
           $debug("     --> should be closing %d:%b", handle, handle);
           
           tmp = $fopen(inst_filename, "w");
           $debug("     --> should be able to reuse %d:%b, getting %d:%b", handle, handle, tmp, tmp);
           $fdisplay(tmp, "tran %d:%b", tmp, tmp);
           $fclose(tmp);

I do get results going up to larger number of file ID:

tran -32:-100000 xi0.xi0.xi0.xdd6.xdd0.a_evl_2tak
    --> should be closing -32:-100000
    --> should be able to reuse -32:-100000, getting -33:-100001

This is the odd part, although I closed descriptor '-32', I cannot re-use it

... continues until ...

tran -1030:-10000000110 xi0.xi0.xi15.xi45.xi0.xi25.xmmp1.xmm0.xdsub.a_evl_2tak
    --> should be closing -1030:-10000000110
    --> should be able to reuse -1030:-10000000110, getting -1031:-10000000111
* ERROR * $fopen() failed. There were not any available file descriptors ...

which is expected because my verilog-AMS vendor indicates in its manual that they have set the limit to 999.

So I am starting to wonder if this is not actually working as per Verilog-2001 and I only did not realize that $fclose() is only executed when a step has converged similarly to how $display() is implemented.

If not, then it is a vendor implementation issue. i am also following-up with them, but hoped someone might already know the answer here,

PS: Re-reading the post I realized that we had already discussed the working 500+ open file test, but at some point I went back to multi-channel (as opposed to file descriptor) thinking that it would work better and thus the apparent disconnect, at least now I know exactly why I only have 999 possibilities  ;)

Thank you,
Claude
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.