Quantcast
Channel: Cadence Functional Verification
Viewing all articles
Browse latest Browse all 652

Specman: Python Is here!

$
0
0

Do you know from where Python technology gets its name? It is not from the snake, it is named after the Monty Python comedy group. And indeed, one of the main guidelines behind it is to be fun to use (check out the Zen of Python). Therefore, Python is intuitive, readable, and easy to learn - all of these make it not only fun to use but also highly productive. Does this sound familiar? If you are an e user, it should. Apparently, e and Python share many common characteristics.

Why supporting Python?

Specman has already interfaces with C and SystemVerilog DPI. However, if you want to extract data during Specman’s runs, analyze it for either debugging or machine learning modules- Python might be the right language since there are many open source libraries for graphs, mathematical calculations, machine learning, etc.  

Can I connect to Python with old Specman?

Yes, you can. Both Specman and Python have interface to C. Therefore, you can write a C glue code to bridge the two. However, this is not trivial, and it means you need to get familiar with Python Interpreter. Since e like Python is mainly about usability and productivity - having an easy way to connect e code to Python code seems almost a MUST.

 What are we adding in 19.05?

In 19.05, all C glue code is generated behind the scenes by Specman during the run. In your e code, you just need to specify that the methods you are calling should be invoked from external Python module (a Python module is a file containing Python definitions and statements).

 

What is the syntax?

To define a method that is imported from Python, you need do two things:

  1. Add “is imported” as part of the method signature. This means that the method can be imported from either C (basic or FLI), SystemVerilog DPI or Python. (If you are already familiar with a different syntax to connect to C or DPI, note that we are adding a new syntax for all external languages, but this is a subject for a different blog).
  2. Annotate this line of code with the predefined annotation: import_python (if you are not familiar with e annotations, you can read about them here).

 

Let’s look at the following simple example:

‘<

extend sys {
   @import_python(module_name="pyModuleEx", python_name="setVal")
   setVal(inVal:int) is imported;
   run() is also {
       setVal(5);
   };
};
‘>

 

In this example, every call to setVal calls the Python setVal method defined in pyModuleEx.py:

 

# pyModuleEx.py

def setVal(val):
   print(val)

Do I need to add any configuration?

  • You need to define two environment variables for Specman: SPECMAN_PYTHON_INCLUDE_DIR and SPECMAN_PYTHON_LIB_DIR which point to the location of include and lib directories under your Python installation directory.
  • You should ensure that the location of all Python modules you are referring to form your e code are included in Python search path environment variable: PYTHONPATH. 

Can I pass a struct from e to Python?

Yes, you can pass a struct from e to Python as shown in the following example:

 

extend monitor {
    @import_python(module_name="exStruct", python_name="calc")
    calc(p:packet):int is imported;
 
    get_packet(p : packet) is also {
        check that calc(p) == 1;      
    };
};

#exStruct.py

class packet:
   def __init__(self,a,b,c,d):
       self.a = a
       self.b = b
       self.c = c
       self.d = d
  
def calc(p):
   print str(p.a) + " " + str(p.b) + " " + str(p.c)+ " " + str(p.d)
   return 1;

 

Are there limitations?

In 19.05, only Python 2 is supported and exporting e methods (calling e methods from Python) is not supported yet. These limitations will be removed in future versions.

What’s next?

There are many things you can do now that you have an easy way to export data during the run to improve your verification environment. It might be a call for you to think of using Machine Learning knowledge to make your verification a state of the art. We will publish few examples soon, stay tuned!

We fully recommend to stay up to date for more examples and updates by joining the Specman Users Groups in Linkedin or Team Specman in Facebook.

Orit Kirshenberg

Specman Team


Viewing all articles
Browse latest Browse all 652

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>