2013年4月24日 星期三

UVM notes

UVM
  • virtual interface
    • interface define
      • modports(define the port type for master/slave)
        • master (input,output), slave(input, output)...
    • task trigger
      • task req;
        `uvm_info(get_full_name(),"start req",UVM_LOW);
        vif.req <= 1b'1;
        @(posedge vif.clk);
        while(!vif.ack) @(posedge vif.clk)
        vif.req <= 1'b0;
        `uvm_info(get_full_name(),"end req",UVM_LOW);
        end_task
    • protocol assertion
      • assert
    • timing constrain
      • setup time, hold time, sample rate, clock rate
        • http://learn-systemverilog.blogspot.tw/2010/07/writing-systemverilog-assertion-for.html
  • UVM_Transfer
    • transfer type, contain definition
      • common
        • transaction id, transaction type, begin time, end time
      • base extends common
        • such as : address, RW type, Data byte array, burst size
  • UVM_Agent
    • support monitor, (driver, sequencer) if the active option is on
  • UVM_monitor
    • collect pin level info to transaction level info
    • export transaction analysis port to TLM2.0 SystemC or scoreboard 
    • protocol coverage like burst len need to support 1,2,4,8,16....
  • UVM_driver
    • driver the test sequence lib to virtual interface
  • UVM_sequencer
    • task item manager 
      • sort the sequences by it's own priority or set it's dependence condition or it's spawn event
  • UVM_scoreboard
    • check transaction is completed from master to slave or slave to master
  • UVM_test
    • define testsuites like "read_after_write", "normal test", "critical test"...
  • UVM_env
    • test env build up.
      • modules
  • config
    • module
      • config address range, RGM
    • transaction
      • config type, info, address, data, len...
    • system
      • whole design config
  • UVM_package
    • pack lib 

Assertions

  • coverage assertion
    • coverage group
    • FSM group
    • pattern group
  • functional assertion
    • c/c++ co-sim 
      • phase to phase check
        • DPI wrapper interface
    • SystemC TL0/TL1 co-sim
      • use TLM2.0 analysis port export 
  • protocol assertion
    • req/grant
      • @(posedge clk) req |-> [1:3]gt;


2013年4月14日 星期日

UVM systemverilog assertion(SVA)


  • assertion
    • assert in C/C++, pointer check 
      • A *a = new A();
      • assert(a!=NULL);
      • a->do_some_thing()...
    • main purpose
      • performance hazards
        • performance requirement throughput for real time issue
      • wrong functionality
        • functional error when the transaction is miss-match for each condition description
        • Assertion active at both clock edges
          • a2: assert property(@(posedge clk)a|->b[*8]); 
        • Sequence used as clocking event 
          • sequence s;
            @(posedge clk) a[*5];

            endsequence
            a3: assert property (@(s) b |-> ##3 c); 
        • Complex Boolean expression used for clock 
          • a5: assert property (@(clk iff en) p1);    
        • Wrong argument type or size
          • `ASSERTS_ONE_HOT(a7, {sig1, sig2, sig3} ...);    
        • short circuit 
          • function bit legal_state(
          • bit [0:3] current, bit valid);
          • a12: assert #0 (valid |-> current != '0);
          • legal_state = valid && $onehot(current);
          • endfunction
          • if (status || legal_state(valid, state)) 
          •   
        • Action block without functional call
          • `define MY_MUTEX(sig) \
          • assert #0($onehot0(sig))
          • always @(posedge clk) begin
          • ...
          • `MY_MUTEX(fsm_1_state)
          • `MY_MUTEX(fsm_2_state); 
          • end
        • req/grant protocol check
          • a14: assert property
          • (@clk req |-> strong(##[1:$] gnt));
        • assertion for coverage
          • c16: cover property (@clk 
          • (state==REQ)##1 (state==SEND));
        •  possibly ignored assertions
        • low coverage(pattern valid/invalid, critical case, how to inc the coverage value)



2013年4月8日 星期一

llvm analysis notes

refs:
http://163.25.101.87/~yen3/wiki/doku.php?id=llvm:llvm_notes



  • llvm commands



  • Convert C/C++ code to llvm IR
    llvm-g++ -emit-llvm -S test.cpp -o test.ll
  • Convert llvm IR to llvm bitcode
    llvm-as test.ll -o test.bc
  • Print Control Flow Graph
    opt -dot-cfg test.bc
  • Print Dominator Tree Graph
    opt -dot-dom test.bc
  • Conver C++ code to C code
    llvm-g++ -emit-llvm test.cpp -o program.bc -c
    llc -march=c program.bc -o program.c

  • analysis(ADT analysis, rule check, redundant check, frame remap)
    • Alias analysis
      • alias memory/register (immutable/mutable) label 
      • check different two frames when the input arg is depended from another? 
    • CFG analysis
      • domain tree, basic block(entry, exist, loop, if/else), operator, reg/mem location
      • loop (vector)
        • for(i=0;i<10 a1="" a2="" b1="" b2="" c1="" c2="" i="" li="" nbsp="">
        • vector(c1,c2) <= {a1,b1} {a2,b2}
    • register analysis
      • virtual register to physical register(arm r0~r10) , rega, regb, regc
    • memory analysis
      • load/store analysis(store is depended on load?)
      • parallel load/store with different address block in the same BB 
    • dependent analysis
      • (depend memory? load/store check)
        • a[0] = 1; # load from constant input
        • b = a[0]; # b is depend from previous assignment, store to output
      • split iterator
        • for(i=0; i<10 ...="" a="" i="" li="" nbsp="" org="">
        • fcheck each unit memory block dependence

2013年4月2日 星期二

LLVM + ZeroMQ = Remote Compiler flow plan

flow plan

  • portable for different platform (client arm, server x86) balance tasks
    • arm for low power mobile device
    • x86 for high performance server device
  • using zeroMQ to our communication handshaking
    • balance the loading
    • multi protocols(TCP/UDP)
    • distribution communication
    • internal broadcast
  • client part
    • method
      • application to llvm byte code or llvm-IR
      • pull llvm byte code or llvm-IR to server by zeroMQ request
      • get server response when the pull-task is done by zeroMQ response
    • require
      • llvm compiler
  • server part
    • method
      • get llvm byte code or llvm-IR from client request
      • do task reassign based on it's server utility, like 2cores CPU(client) to 64 cores CPU(server)
      • put result to client
    • require
      • listen port to link client request
      • byte / IR ADT remap to physical hardware
      • multi requests/ multi tasks balance timeout issue
      • llvm compiler

Ta-lib + bigdata = stock analysis tool

  • 如何用30分鐘, 打造出自己獨特程式交易系統. 話不多說,我們就直接開始吧!!!!
  • requirements
    • Ta-lib(support finance indicators)
    • bigdata(pandas, numpy, scipy, matplotlib...)
    • Ta-lib Cython wrapper (wrapper Ta-lib to python)
  • how to install in Mac 
    • install Ta-lib (port install ta-lib)
    • install bigdata 
      • port install py27-pandas
      • port install py27-numpy
      • port install py27-matplotlib
      • ...
    • setup python search path for mac port
      • add the below info to "~/.bashrc"
        • "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages"
      • source ~/.bashrc
    • install Ta-lib(wrapper)
      • https://github.com/funningboy/ta-lib
  • example case
    • 買點
      • 利用5日平均線大於10日平均線
    • 賣點
      • 持有天數最多只能有三天
    •  結論
      • 還是實在賺錢比較重要
    • ref:
      • https://github.com/funningboy/ta-lib/blob/master/tools/tdr_jump.py
    • results:
total profit is : -20.26
----------------------------------------------------------------------------------------------------
               ma10      ma5   close    high     low    open   volume  entry  leave  profit
2013-01-02      NaN      NaN  723.25  727.00  716.55  719.42  2541300      0      0    0.00
2013-01-03      NaN      NaN  723.67  731.93  720.72  724.93  2318200      0      0    0.00

import sys                                                                                                                                                                           
from datetime import datetime

import numpy as np
import talib
import matplotlib.finance as fin 
from pylab import show

from pandas import Index, DataFrame, Series
from pandas.core.datetools import BMonthEnd
from pandas import ols 


def getQuotes(symbol, start, end):
    """ get stock Quotes from Yahoo """

    quotes = fin.quotes_historical_yahoo(symbol, start, end)
    dates, open, close, high, low, volume = zip(*quotes)

    data = { 
        'open': open,
        'close': close,
        'high': high,
        'low': low,
        'volume': volume
    }   

    dates = Index([datetime.fromordinal(int(d)) for d in dates])
    return DataFrame(data, index=dates)


def getMA(quotes):
    """ get mv_avg indicator and update org quotes by joining two DataFrame """

    ma5 = talib.MA(quotes['close'],5)
    ma10 = talib.MA(quotes['close'],10)

    data = { 
            'ma5' : ma5,
            'ma10': ma10,
            }   

    update = DataFrame(data, index=quotes.index)
    return update.join(quotes)

def setEntryRule1(quotes):
    """ set entry rule when ma5 is cross-over ma10 """

    def rule1(quotes, index):
        rst = 1 if quotes['ma5'][index] > quotes['ma10'][index] else 0
        return rst

    quotes['entry'] = [rule1(quotes, index) for index in quotes.index]
    return quotes


def setLeaveRule1(quotes):
    """ set leave rule when the holding day is large than 3 days"""

    def rule1(quotes, position):
        if position - 3 >= 0:
            if quotes['entry'][position-3] == 1:
                return [1, quotes['close'][position] - quotes['close'][position-3]]
        return [0, 0]

    quotes['leave'], quotes['profit'] = zip(*[rule1(quotes, position) for position, index in enumerate(quotes.index)])
    return quotes


def getProfit(quotes):
    """ get profit report """

    print "total profit is : %s" %(sum(quotes['profit']))
    print "-" * 100
    print quotes


def main():
    # get stock info from start to end
    startDate = datetime(2013, 1, 1)
    endDate = datetime(2013, 1, 30)

    # get stock id
    goog = getQuotes('GOOG', startDate, endDate)
    goog = getMA(goog)

    goog = setEntryRule1(goog)
    goog = setLeaveRule1(goog)
    getProfit(goog)

if __name__ == '__main__':                                                                                                                                                           
    main()