hi all,
this is a speech about MyHDL in python taipei meeting,
the free project code can download from git
thanks
2013年2月18日 星期一
python + GDB
PythonGDB ,
using python script to handle GDB sequence, such as dump ASM, catch segment fault exceptions, debug, trace back..., it's very useful for me. because i can use this script to catch info what i want to see... as you known, i am a lazy man, typing redundant key words in gdb is very hard for me. XD
- install
- mkdir -p ~/archer/build ~/archer/install
- git clone git://sourceware.org/git/archer.git
- git checkout archer-tromey-python
- cd build/
- ../archer/configure --prefix=$(cd ../install && pwd)
- make all install
- PATH=/Users/Apple/prj/archer/install/bin:$PATH
- gdb
- (gdb) python print 23
- example
- GDB list macro definition
- gdb
- (gdb) python import gdb
- (gdb) gdb.execute('file xx') # = file xx load xx exec file
- (gdb) gdb.execute('b main') # = set break pp in main
- (gdb) gdb.execute('list') # = list
- (gdb) gdb.execute('bt') # = bt list all frames
- (gdb) gdb.execute('disas /m
') - script in python
def gdb_dump(self): try: global DETAIL gdb.execute('file ../add_py/add_py') o = gdb.execute('disas /m add', to_string = True) print "-"*24 print "pyobject asm func(add) call" print "-"*24 if DETAIL == True: logging.info(o) print "len %d" %(len(o.split("\n"))) except IOError as e: print "pyobject gdb dump error"Ref:
PythonGDB
PythonGdbTutorial
Low level debuger
IDAPython
2013年2月12日 星期二
python + SystemC = pySystemC
Wrapper SystemC TLM models in Python
- How to install SystemC TLM models in MAC
- download SystemC2.3
- cd $
- %mkdir build
- %cd build
- %../configure
- %make install
- %export SYSTEMC_HOME=$
- cd $
/examples/tlm/build-unix - replace Makefile.config TARGET_ARCH ?= macosx64
- make install
- embedded SystemC to python env
- advantages
- script language easy to extend
- more libraries support
- more easily to reuse and rebuild(no compiler knowledge)
- swig
- download and setup
- how to do it?
- wrapper SystemC thread/method to python call back
- void sc_module_swig::method (PyObject * f){
sc_python_callback * callback =
new sc_python_callback (f);
PyObject* name = PyObject_GetAttrString (f,"__name__");
if(name == NULL || !PyString_Check(name)){
std::cerr << "python name error\n";
return;
}
sc_method_handle handle = simcontext()->
register_method_process(
PyString_AsString (name), callback,this );
sc_module::sensitive << handle;
sc_module::sensitive_pos << handle;
sc_module::sensitive_neg << handle;
} - wrapper SystemC start/end simulation
class sc_module_swig : public sc_module {
public:sc_module_swig (const char * nm): sc_module ((sc_module_name)nm){}
virtual void beforeEndOfElaboration(){}
virtual void endOfElaboration(){}
virtual void startOfSimulation(){}
virtual void endOfSimulation (){}
inline void dontInitialize ()
{sc_module::dont_initialize ();}
inline sc_sensitive & getSensitive (){return sensitive;}
...
protected:
inline void before_end_of_elaboration()
{this->beforeEndOfElaboration ();}
inline void end_of_elaboration()
{this->endOfElaboration ();}
inline void start_of_simulation()
{this->startOfSimulation ();}
inline void end_of_simulation()
{this->endOfSimulation ();}
...
};- wrapper SystemC module
- set up SystemC map table "*.i"
- %module sc_module_swig
%{
#include "systemc.h"
#include "sc_module_swig.h"
%}
%include "sc_module_swig.h" - swig -c++ -I"
-python *.i - ref
GreenScript User Manual - GreenSocs
2013年2月10日 星期日
SystemC TLM2.0 notes
TLM2.0 key notes
LT(loosely time), APT(approximate time), CAT(cycle accurate time)
- byte enable
- endianness
- generated payload (TRS)
- extension generated payload(transaction ID)
- socket base transaction
- transaction traceback (watch monitor)
- score board recorder
- assertion
- coverage
- b_transaction(blocking)[LT]
- no direction
- wait
- no method sensitive
- no pipe
- no phase
- no life time
- nb_transaction(noblocking)[APT](phase),
- nb_transaction_fw(forward) / nb_transaction_bw(backward)
- no wait
- method/thread sensitive
- pipe
- phase (req_bg/ed, data_bg/ed, resp_bg/ed)
- life time
- modify
- target (response pp, extension pp)
- initiator (address, command, data, pp)
- interconnect (address, extension pp)
- notify
- .notify() to switch event and reschedule event lists
- free/release pp(pp memory manager)
- free pp by life time
- DMA(direct mem access)
- data pointer / shared pp deep shadow copy
- interface (analysis_interface, debug_interface)
- socket
Tl3(packetize), Tl2(transaction level), Tl1(adaptor Tl1toTl2, Tl2toTl1), Tl0(pin level assign)
TRS (transaction)
TRS (transaction)
carbon design AXI TLM2.0
greensoc OCP TLM2.0
greensoc OCP TLM2.0
2013年2月7日 星期四
Python with HighPerformance
最近在讀 high performance python, 底下就隨手記錄一下吧...XD
- test env
- MacBook 2.0GHz with 4GB RAM. The GPU is a 9400M
- pypy(JIT) > pure python (~6times)
- cython(move math(complex) part to c) > pure python (1.5~30times)
- numpy(matrix vector) > pure python(30times)
- shedskin(python 2 c++ compile) > pure_python(30times)
- PyCUDA(real hardware multi cores(DSP)) > numpy(CPU 50times)
- using cprofile and dis to trace back where is the performance bottleneck
- python -cprofile
- @profie decorader in each proc call
- python dis.dis(function call)
- trace byte code linse, macro blocks, where to improve
- serialize code
- data store in cache > store in memory
- RunSnakeRun
- GUI tool(cprofile results)
- Multiprocessing: parallel process to multi cores(CPUS)
- pypy: JIT(just in time) compiler, llvm, byte code optimization, rpython(.Net), cython
- numpy: N dimension array vector to one dimension vector array(serialize memory access)
- cpython: pre-compile python to having object type(int,char...)
- PyCUDA: hardware speed up (DSPs)
tips
- a = {} > a = dict()
- "".join(st) > st = "a" + "b" + "c"
- [i.upper() for i in test] > for i in test: arr.append(i.upper())
- def test() > global test ...
- init dict > without init dict
- pre load(import modules in header) > current load(import modules in middle)
- reduce the call back counts
- xrange > range
- remap func without recursive loops
- hash(heap map) > loop searching
ref:
EuroPython2011_HighPerformanceComputing
performance tips
timecomplex
python + google GAE + checkIO
底下用就用 checkIO ATM + Google GAE(guestbook) 來當今天的玩具好了. 主要改寫 checkIO ATM 的 input/output parts 跟 GAE 的 db handle 部分. 除了可以練習一下 GAE,也可以玩 checkIO 裡的習題.
input : Web text form
output : results
output : results
def checkio_atm(data): try: data = str(data).replace(' ','').replace('[','').replace(']','') datas = [int(d) for d in data.split(",")] balance, withdrawal = datas[0], datas[1:-1] for a in (0.5 + 1.01*it for it in withdrawal if it %5 ==0): balance = floor(balance - a) if balance > a else balance return "input = %s, rst = %s" %(data,str(balance)) except: return "CheckIO ATM Error"GAE key notes
- python
- python 2.5 python2.7
- data store
- GQL
- protocol
- WSGI
- env config set
- yaml
- How to use ?
- sample code
Html key notes
- css
- html embedded query
訂閱:
文章 (Atom)