I wonder if there is any way to improve the speed ...
# sky130
c
I wonder if there is any way to improve the speed of library importing in ngspice. I assume every time when it is invoked it imports the entire sky130 pdk library which takes about 5-10 seconds. It does not look like a big deal but if I want to have it embedded inside some optimization loop it becomes very time-consuming. Will there be any way to only import the library that I (or, more appropriately, my circuit) needs rather than importing everything? Thanks.
s
If you are using xschem add this component to the schematic:
sky130_fd_pr/corner.sym
. Specify the corner in its instance attributes (tt, ss, fs, ...) and this will provide to ngspice only the specified corner. For reasons we don't understand ngspice insists on parsing all corners, and this takes considerable time. On my laptop this makes ngspice start in 2 seconds.
c
Thanks, Stefan, do I have to only include this in the top testbench schematic or I have to include this in every single schematic? As so far if I only have it in the top testbench schematic it is having some errors towards my sub-circuit (it seems like that):
s
Remove any symbol including models in subcircuits (code.sym, corner,sym) OR add attribute
only_toplevel=true
, so these code blocks will not be netlisted if not at the toplevel.
If you still have these redefinition warnings please check directly the .spice file, there is a double inclusion of the spice models.
c
Thanks, Stefan, this significantly improves the simulation speed! To others who may also want to do this: the way I solve double inclusion is by removing the
.lib /usr/local/share/pdk/sky130A/libs.tech/ngspice/sky130.lib.spice tt
line which usually goes at the beginning of your spice script.
Hi @Stefan Schippers one more question, do you have any experience with multiprocessing/multithreading ngspice?
s
@Chris ngspice is not a parallel solver. What it can do is to split device equation evaluation and solver steps on separate processes. Add this in your .spiceinit:
set num_threads=4
. The
.spiceinit
is the file that must be present in the directory where ngspice runs. it usually contains this:
Copy code
set ngbehavior=hsa
set ng_nomodcheck 
# set filetype=ascii
set num_threads=4
with this setting a long simulation show this in my computer:
Copy code
top - 12:29:19 up  2:19,  7 users,  load average: 1.91, 1.03, 0.75
Tasks: 213 total,   2 running, 211 sleeping,   0 stopped,   0 zombie
%Cpu(s): 84.2 us,  1.1 sy,  0.0 ni, 14.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15881.4 total,   9008.8 free,   4467.2 used,   2900.6 buff/cache    
MiB Swap:  17166.0 total,  17166.0 free,      0.0 used.  11414.1 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND   
11253 schippes  20   0  161168 123632  12192 R 331.2   0.8   0:20.70 ngspice   
 9604 schippes  20   0 2852780 372872 105420 S   5.0   2.3   3:30.21 Isolated +
You see ngspice is using 331% CPU, so it is using at least 4 threads. Ngspice uses more cpu if compiled with the
--enable-openmp
flag and if using BSIM models that are OPENMP enabled. For example i tested a simulation on a design that uses old mos models that are not OPENMP enabled and cpu usage is capped at 100% (1 thread). Sky130 mos models are OPENMP aware so you can take advangare of this.
c
Thank you very much this is very helpful! I actually may also try Xyce soon as it seems it does support parallel processing.