A Brief on SystemC

Embed Size (px)

Citation preview

  • 8/4/2019 A Brief on SystemC

    1/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -1 -AA 2004-2005

    SystemC Tutorial

    Federico AngioliniDEIS Universita' di Bologna, Italy

    [email protected]

    L. Benini Metodologie di Progettazione Hardware-Software Slide -2 -AA 2004-2005

    Layers of Hardware Design

    Algorithmic model

    UnTimed Functional (UTF) model

    Timed Functional (TF) model

    Ab

    stractionlevel

    Simulationspeed

    Simu

    lationaccuracy

    Sy

    nthesizability

    Bus Cycle Accurate (BCA) model

    Cycle Accurate (CA) model

    Register Transfer Level (RTL) model

    Tra

    nsactionLevel

    M

    odels(TLM)

  • 8/4/2019 A Brief on SystemC

    2/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -3 -AA 2004-2005

    Scope of Layers

    Algorithmic model

    UnTimed Functional (UTF) model

    Timed Functional (TF) model

    Bus Cycle Accurate (BCA) model

    Cycle Accurate (CA) model

    Register Transfer Level (RTL) model

    G No notion of time (processesand data transfers)

    G Cycle accuracy, signalaccuracy

    G Notion of time (processesand data transfers)

    L. Benini Metodologie di Progettazione Hardware-Software Slide -4 -AA 2004-2005

    Purpose of Layers

    Algorithmic model

    UnTimed Functional (UTF) model

    Timed Functional (TF) model

    Bus Cycle Accurate (BCA) model

    Cycle Accurate (CA) model

    Register Transfer Level (RTL) model

    Functional verification

    Algorithm validation

    Coarse benchmarking

    Application SW development

    Architectural analysis

    Detailed benchmarking

    Driver development

    Microarchitectural analysis

  • 8/4/2019 A Brief on SystemC

    3/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -5 -AA 2004-2005

    What language?

    G Problem: very different levels of abstractionG Modeling language to use?G High-level: Java, Visual Basic, C++G Low-level: HDLs (VHDL, Verilog)G Huge modeling gapG Need to translate models

    L. Benini Metodologie di Progettazione Hardware-Software Slide -6 -AA 2004-2005

    Design Overhead

    System Specification

    (C++)

    HW

    (VHDL)

    SW

    (C++)

    0101011110100010111001010010011110000111101010010001100110101011. . .

    Tran

    slate

    Refine

    Refine

  • 8/4/2019 A Brief on SystemC

    4/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -7 -AA 2004-2005

    Why not just C++?

    Concurrency support is missing (HW is inherently parallel) No notion of time (clock, delays) Communication model is very different from actual HW

    model (signals)

    Weak/complex reactivity to events Missing data types (logic values, bit vectors, fixed point

    math)

    Plain vanilla C++ not viable!

    L. Benini Metodologie di Progettazione Hardware-Software Slide -8 -AA 2004-2005

    SystemC paradigm

    System Specification

    (SystemC)

    HW

    (SystemC)

    SW

    (SystemC)

    0101011110100010111001010010011110000111101010010001100110101011. . .

    Refine

    Refine

  • 8/4/2019 A Brief on SystemC

    5/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -9 -AA 2004-2005

    How can this be achieved?

    G C++ extensions!G New library (libsystemc.a) providing additional

    functionality

    G Building upon C++ features (inheritance!) and data typesto better express HW behavior

    G SystemC HW-modeling code is actually C++ code andcan be freely mixed with plain C++

    L. Benini Metodologie di Progettazione Hardware-Software Slide -10 -AA 2004-2005

    SystemC Infrastructure

    SystemC

    Description

    SystemC

    Class

    Library

    C++ Compiler

    (debugger)

    Executable = Simulator

    Heade

    rFiles

    Simulation Kernel

  • 8/4/2019 A Brief on SystemC

    6/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -11 -AA 2004-2005

    SystemC Advantages

    G Unified language across all stages of platform design(easier tool interoperability, designer training)

    G Unified language across HW and SW development(promoting co-design)

    G Allows faster simulation/refinement/reworking of modulesG Builds upon one of the most widespread programming

    languages (many tools, programmers)

    G Lightweight

    L. Benini Metodologie di Progettazione Hardware-Software Slide -12 -AA 2004-2005

    SystemC Toolchain

    SW implementationChip verification HW synthesis

    C/SystemC

    SystemC

    Exec. Specification

    SW

    C-code

    SystemC

    Synthesizable Model

    Processor

    ModelHW/SW co-design

    Performance Exploration

  • 8/4/2019 A Brief on SystemC

    7/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -13 -AA 2004-2005

    SystemC Features

    Concurrency support: modules

    Notion of time: clocks, custom wait() calls

    Communication model: signals, protocols, handshakes

    Reactivity to events: support for events, sensitivity list,watching() construct

    Data types: logic values, bit vectors, fixed point

    C ++/SystemC results in a suitable platform!

    L. Benini Metodologie di Progettazione Hardware-Software Slide -14 -AA 2004-2005

    SystemC Core Language

    C++

    Core language

    Modules/Processes

    Ports/Interfaces

    EventsChannels

    Event-driven simulation kernel

    Data types

    4-valued logic types (01XZ)

    Bit/logic vectors

    Arbitrary precision integersFixed point

    C++ user-defined

    Elementary channels

    Signals, Timers, Mutexes, Semaphores, FIFOs,

    High-Level Channels

    Kahn Process Networks, Master/Slave libraries,

  • 8/4/2019 A Brief on SystemC

    8/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -15 -AA 2004-2005

    Modules

    G They map functionality of HW/SW blocksG Derived from SystemC class sc_moduleG They represent the basic building block of every systemG Modules can contain a whole hierarchy of sub-modules

    and provide private variables/signals

    G Modules need:I Communication: Modules can interface to each other via

    ports/interfaces/channels

    I Functionality: achieved by means ofprocesses

    L. Benini Metodologie di Progettazione Hardware-Software Slide -16 -AA 2004-2005

    Modules

    Module

    Module

    Module

    Module

    Module

    Latch

    Latch

    Counter

    Mux

    ALU

    Module

  • 8/4/2019 A Brief on SystemC

    9/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -17 -AA 2004-2005

    Modules

    //my_module.h#include systemc.h

    SC_MODULE(my_module){

    //port declarations//internal data//process declarations

    SC_CTOR(my_module){

    //map processes to member functions

    //sensitivity lists//initialization code}

    };

    Basically a C++ class

    with member variables,

    member functions and

    constructor!

    L. Benini Metodologie di Progettazione Hardware-Software Slide -18 -AA 2004-2005

    Interfaces, Ports, Channels

    Module Channel

    Port Interface

    Module

    G Need to exchange data among modulesG Give ports to modulesG At initialization time, ports are bound to channels via

    interfaces

  • 8/4/2019 A Brief on SystemC

    10/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -19 -AA 2004-2005

    Interfaces

    G They provide just the prototype of a set of operations(typically, at least readand write)

    G Implementation is a burden of channelsG Derived from the sc_interface classG Two are widely used:

    I sc_signal_in_ifprovides a read() returning data of type T

    I sc_signal_inout_ifderives from the first, thus providing read();

    additionally declares a write() function taking areference to T as its input

    G (The out version is just the same as inout)

    L. Benini Metodologie di Progettazione Hardware-Software Slide -20 -AA 2004-2005

    Ports

    G They provide communication functions to modulesG Derived from SystemC class sc_port(type of interface, number of connected interfaces)

    G On the outside, they connect to channels by means ofinterfaces

    G Typical channel (in RTL models): sc_signal. In this case,shortcuts exist for specialized classes: sc_in,sc_out, sc_inout(ports connected to

    N=1 interfaces of type sc_signal_in_ifetc.)

    G Simple instantiation:I sc_inout my_port;

    G Methods are made available by the underlying interface:Imy_port.read(),my_port.write(),

  • 8/4/2019 A Brief on SystemC

    11/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -21 -AA 2004-2005

    Channels

    G They implement the prototypes described by interfacesG Actual data shufflingG Between modules, or between processes in a moduleG Typical example: the hardware signal sc_signal,

    derived from the interface sc_signal_inout_if

    G Arbitrary complexity, up to whole interconnectsG Other examples:

    I sc_fifoimplementing the interfacessc_fifo_in_ifand sc_fifo_out_if(blocking

    and non-blocking versions of access)I sc_mutex

    L. Benini Metodologie di Progettazione Hardware-Software Slide -22 -AA 2004-2005

    Port instantiation

    //my_module.h#include systemc.h

    SC_MODULE(my_module){

    sc_in id;sc_in in_a;sc_in in_b;sc_out out_c;//process declarations

    SC_CTOR(my_module){

    //process configuration//initialization code

    }};

    Ports can have

    any of the SystemC

    data types! sc_uint

    is a 3-bit unsigned int

  • 8/4/2019 A Brief on SystemC

    12/39

  • 8/4/2019 A Brief on SystemC

    13/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -25 -AA 2004-2005

    SC_METHOD

    //my_module.h#include systemc.h

    SC_MODULE(my_module){sc_in id;sc_in in_a;sc_in in_b;sc_out out_c;

    void my_method();SC_CTOR(my_module) {SC_METHOD(my_method);

    sensitive

  • 8/4/2019 A Brief on SystemC

    14/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -27 -AA 2004-2005

    SC_THREAD

    //my_module.h#include systemc.h

    SC_MODULE(my_module){

    sc_in id;sc_in clock;sc_in in_a;sc_in in_b;sc_out out_c;

    void my_thread();SC_CTOR(my_module){SC_THREAD(my_thread);

    sensitive

  • 8/4/2019 A Brief on SystemC

    15/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -29 -AA 2004-2005

    wait_until()

    dowait();

    while (in_a.read() != true ||in_b.read() != true);

    wait_until(in_a.delayed() == true &&in_b.delayed() == true);

    L. Benini Metodologie di Progettazione Hardware-Software Slide -30 -AA 2004-2005

    watching()

    //my_module.cpp

    void my_module::my_thread() {while(true) {

    if (reset.read())[reset code]

    []if (reset.read())[reset code]

    []wait();

    }}

    //my_module.h

    SC_CTOR(my_module){SC_CTHREAD(my_cthread, clock.pos());watching(reset.delayed() == true);

    }

    //my_module.cpp

    void my_module::my_cthread(){

    [reset code]while(true){

    []wait();

    }}

    //my_module.h

    SC_CTOR(my_module) {SC_THREAD(my_thread);sensitive

  • 8/4/2019 A Brief on SystemC

    16/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -31 -AA 2004-2005

    Process Summary

    G SC_METHOD: method processI sensitive to a set of signalsI executed until it returns

    G SC_THREAD: thread processI sensitive to a set of signalsI executed until a wait()

    G SC_CTHREAD: clocked thread processI sensitive only to one edge of clockI execute until a wait() or a wait_until()Iwatching() restarts from top of process body (reset evaluatedon active edge)

    L. Benini Metodologie di Progettazione Hardware-Software Slide -32 -AA 2004-2005

    Signals

    G The most common type of channels (in RTL designs)G Derived from sc_prim_channelG Are bound to ports by means of interfacesG Used to connect modules through portsG May be local inside of a specific moduleG Special signal: clock (sc_clock). Multiple clocks can be

    instantiated at once, with arbitrary phase relationship

  • 8/4/2019 A Brief on SystemC

    17/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -33 -AA 2004-2005

    Signal Instantiation and Binding

    my_module_type_1 my_module_1;my_module_type_2 my_module_2;

    sc_signal my_signal1;sc_signal my_signal2;sc_clock my_clock(my_clock", 20, 0.5, 2, true);

    my_module_1.clock_port(my_clock);my_module_1.out_port(my_signal1);my_module_1.in_port(my_signal2);

    my_module_2.clock_port(my_clock);

    my_module_2.out_port(my_signal2);my_module_2.in_port(my_signal1);

    my_module1

    my_module2

    my_clock

    my_signal1 my_signal2

    periodname

    dutycycle

    starttime

    startphase

    L. Benini Metodologie di Progettazione Hardware-Software Slide -34 -AA 2004-2005

    Data Types

    G Can be applied to signals and portsG All of what C++ supports, including user-defined types

    (typedef )

    G SystemC custom typesI Scalar: sc_bit (i.e.bool), sc_logic (i.e. 01XZ)I Integer: sc_int, sc_uint, sc_bigint, sc_biguintI Bit and logic vector: sc_bv, sc_lvI Fixed point: sc_fixed, sc_ufixed, sc_fix, sc_ufix

    G Special operatorsI bit select: x[i]I part select: x.range(4, 2)I concatenation: (x.range(2, 1), y)I or reduction: x.or_reduce()

  • 8/4/2019 A Brief on SystemC

    18/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -35 -AA 2004-2005

    Signal Tracing

    G Very useful for debug purposes, especially at the RTLlevel

    G Waveform dumpingG Produces .VCD output file, to be opened with waveform

    analyzers

    // main.cppsc_signal my_signal;sc_trace_file *tf;tf = sc_create_vcd_trace_file(my_waveform_filename);sc_trace(tf, my_signal, my_signal_name);

    sc_start(-1); // run until error/spontaneous exitsc_close_vcd_trace_file(tf);return(0);

    L. Benini Metodologie di Progettazione Hardware-Software Slide -36 -AA 2004-2005

    Waveform Example

  • 8/4/2019 A Brief on SystemC

    19/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -37 -AA 2004-2005

    SystemC Scheduler

    G Two different time steps:I Discrete simulation cycle (i.e. clock period)I Delta cycle (i.e. virtual delay, without actual length)

    G Evaluate then update semantics

    G Similar to HDL schedulersG Problem of concurrency (execution order??)G Actual execution must be sequential!!

    0x0 0x1 0x2 0x3 0x4

    CK

    D Q D Q D Q D Q

    L. Benini Metodologie di Progettazione Hardware-Software Slide -38 -AA 2004-2005

    Scheduler Timings

    1. Major timing step (clock cycle, specified delay, )

    2. Resume processes waiting for this event and execute

    their body (evaluate stage) until they all suspend again.

    Output signal updates are only queued

    3. Minor timing step (Delta cycle: simulation time does

    not actually go on)

    4. Update all of the output signals (update stage)

    5. Check whether this resumes other processes. If yes,back to 2

    6. Back to 1

  • 8/4/2019 A Brief on SystemC

    20/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -39 -AA 2004-2005

    Scheduler Timings

    G Order of process resumption, while actually deterministic,is unspecified

    G Designer must not rely on peculiar behavior (like inhardware!)

    G SystemC semantics allow for designs independent ofspecific order of process execution (concurrency support)

    L. Benini Metodologie di Progettazione Hardware-Software Slide -40 -AA 2004-2005

    Events and Dynamic Sensitivity

    G Events are pervasive in SystemCG Event objects: derived from class sc_eventG Event objects are not event occurrences: they represent

    the what-if scenario

    G Event objects keep a list of processes waiting for themG Event generators (processes, channels) notify event

    objects of event occurrences

    G Event objects, checking their list, tell the scheduler whichprocesses to resumeG This is how sensitivity lists are made (static sensitivity)

    G Dynamic sensitivity: at runtime, making processessensitive to events other than those in their sensitivity list(this makes no sense at RTL level)

  • 8/4/2019 A Brief on SystemC

    21/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -41 -AA 2004-2005

    Events and Dynamic Sensitivity

    // Process P1 (SC_THREAD, sensitive to clock.pos())

    wait(); // wait for static sensitivity list

    wait(e1); // wait for event

    wait(e1 | e2 | e3); // wait for first event

    wait(e1 & e2 & e3); // wait for all events

    wait(200, SC_NS); // wait for 200 ns

    wait(200, SC_NS, e1 | e2); // wait, 200 ns timeout

    sc_event e1, e2, e3;

    // Process P2

    e1.notify();

    Dynamic

    sensitivy

    L. Benini Metodologie di Progettazione Hardware-Software Slide -42 -AA 2004-2005

    Events and Dynamic Sensitivity

    G Notification can be either:I Immediate (DANGEROUS!!!): e1.notify() (This may trigger an

    unpredictable amount of executions of the sensitive process,

    depending on scheduling)

    I After a Delta cycle: e1.notify(SC_ZERO_TIME)I After a specified time interval: e1.notify(sc_time(20,SC_NS))

    GEspecially useful for:I RTL level design (back-annotation of delays)I Behavioral level design (asynchronous/conditional event

    management without much effort)

  • 8/4/2019 A Brief on SystemC

    22/39

  • 8/4/2019 A Brief on SystemC

    23/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -45 -AA 2004-2005

    Purpose of Layers

    Algorithmic model

    UnTimed Functional (UTF) model

    Timed Functional (TF) model

    Bus Cycle Accurate (BCA) model

    Cycle Accurate (CA) model

    Register Transfer Level (RTL) model

    Functional verification

    Algorithm validation

    Coarse benchmarking

    Application SW development

    Architectural analysis

    Detailed benchmarking

    Driver development Microarchitectural analysis

    L. Benini Metodologie di Progettazione Hardware-Software Slide -46 -AA 2004-2005

    What Tools Do We Need?

    G Low-level layers:I Clock management (sc_clock), signal support (sc_signal),

    01XZ values (sc_lv), flexible synchronization of modules(SC_METHOD, SC_THREAD), VHDL-like scheduling

    G High-level layers:I Powerful object-oriented features (C++ roots), easy

    synchronization of modules (SC_THREAD, SC_CTHREAD),reconfigurable sensitivity according to circumstances (sc_event),

    high-level abstractions of HW resources (FIFOs, mutexes,

    semaphores)

  • 8/4/2019 A Brief on SystemC

    24/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -47 -AA 2004-2005

    High-Level Abstractions of HW Resources

    G SystemC channels do not just translate into sc_signalG Other channels are available, e.g.:

    I sc_fifoI sc_mutexI sc_semaphore

    G These channels can be bound to ports like sc_signalchannels do, but...

    I Very useful high-level functionalityI Not cycle accurate!G Custom channels can be built (whole interconnects!)

    L. Benini Metodologie di Progettazione Hardware-Software Slide -48 -AA 2004-2005

    SystemC Philosophy

    G Language is very richG While features can be intermixed, SystemC extensions to

    C++ are mostly aimed at different design domains:

    I RTL designers can write VHDL-like codeI System designers (HW/SW designers) can write C++ code while

    taking advantage of some bonus features like concurrency, powerful

    synchronization mechanisms, and abstractions of actual hardware

    G Design refinement can be done while staying within theSystemC framework, without learning new languages/tools

  • 8/4/2019 A Brief on SystemC

    25/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -49 -AA 2004-2005

    Communication Refinement

    G SystemC provides a very powerful mechanism to refinecommunication protocols:I Modules only have portsI Communication happens through channelsI Ports are connected to channels via interfacesI Interfaces just declare channel functionality, actual

    implementation is inside of channel itself

    G If two channels expose the same interface, they can bereplaced with full plug-'n'-play

    G Cycle-accurate and purely functional channels could beinterchanged!

    L. Benini Metodologie di Progettazione Hardware-Software Slide -50 -AA 2004-2005

    Channel Binding

    ModuleChannel

    (Behavioral)Module

    Channel

    (RTL, cycle

    accurate)

    Plug-'n'-Play

    sc_port< my_if >sc_port< my_if >

    my_if my_if

  • 8/4/2019 A Brief on SystemC

    26/39

  • 8/4/2019 A Brief on SystemC

    27/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -53 -AA 2004-2005

    Implementing an Interface

    G To be able to implement a read/write connection to thechannel, we need a derived interface:

    class my_readwrite_if :public my_read_if,public my_write_if

    {};

    G Now both read() and write() will be available to amodule port connected tomy_readwrite_if

    G If a port uses directlymy_read_if andmy_write_if, it willbe a unidirectional port

    G The channel can choose whether to inherit frommy_readwrite_if or from bothmy_read_if ANDmy_write_if

    L. Benini Metodologie di Progettazione Hardware-Software Slide -54 -AA 2004-2005

    Implementing a Channel

    G The channel must provide communication functionalityG The channel must provide the implementation of the

    methods declared in its interfaces

    G The channel inherits from sc_prim_channel and thus canaccess its API, especially:Ivoid request_update()Ivirtual void update() = 0 (mandatorily requires an

    implementation inside of the channel!)

    GThe channel also inherits from sc_interface (through itsinterfaces) and thus can access its API, especially:Ivirtual const sc_event& default_event() (tells the

    simulation kernel which is the event on which to enqueue

    processes waiting on their sensitivity list)

  • 8/4/2019 A Brief on SystemC

    28/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -55 -AA 2004-2005

    Request-Update Semantics

    G The channel must comply with the Evaluate then update(VHDL-like) paradigm of SystemC! To do so:

    I When some channel method is invoked (typically writes), thechannel calls the simulation kernel via sc_prim_channelsrequest_update()

    I The simulation kernel schedules the channel for update in thenext Delta cycle. When such time arrives, the kernel calls thechannels update() method

    I update() is still inherited by sc_prim_channel, but itsimplementation is channel-specific

    L. Benini Metodologie di Progettazione Hardware-Software Slide -56 -AA 2004-2005

    Implementing a Channel

    class my_channel :

    public sc_prim_channel, public my_read_if, public my_write_if

    {

    public:

    []

    virtual char read() { return curr_val };

    virtual void write(char val) { next_val = val;

    if (next_val != curr_val) request_update(); }

    virtual const sc_event& default_event() const

    { return val_chg_event; }

    protected:

    virtual void update() { curr_val = next_val;val_chg_event.notify(SC_ZERO_TIME); }

    char curr_val, next_val;

    sc_event val_chg_event;

    };

    Evaluate then update semantics

    Sensitivity support

    (called by the

    simulation kernelat initialization)

    One Delta cycle

    Inherits both interfaces

  • 8/4/2019 A Brief on SystemC

    29/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -57 -AA 2004-2005

    Instantiating a Channel

    // my_module.h

    #include systemc.h

    SC_MODULE (my_module)

    {

    sc_port in;

    void my_function();

    SC_CTOR(my_module)

    {

    SC_METHOD(my_function);

    sensitive

  • 8/4/2019 A Brief on SystemC

    30/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -59 -AA 2004-2005

    An RTL Model Example

    G RTL level: signal accurate, cycle accurate, resourceaccurate

    G Can not use abstractions (functional units, communicationinfrastructures, )

    ShifterCounter

    Data In Data Out

    Clock

    Load Clear Load LR

    L. Benini Metodologie di Progettazione Hardware-Software Slide -60 -AA 2004-2005

    An RTL Model Example

    G An 8 bit counter. This counter can be loaded on a clkrising edge by setting the input loadto 1 and placing a

    value on input din. The counter can be cleared by setting

    input clear high.

    G A very basic 8 bit shifter. The shifter can be loaded on aclk rising edge by placing a value on input din and setting

    input loadto 1. The shifter will shift the data left or right

    depending on the value of input LR. IfLRis low the shifter

    will shift right by one bit, otherwise left by one bit.

    G Local temporary values are needed because the value ofoutput ports cannot be read.

  • 8/4/2019 A Brief on SystemC

    31/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -61 -AA 2004-2005

    An RTL Model Example

    // counter.h

    SC_MODULE(counter) {

    sc_in clk;

    sc_in load;

    sc_in clear;

    sc_in din;

    sc_out dout;

    sc_uint countval;

    void counting();

    SC_CTOR(counter) {

    SC_METHOD(counting);

    sensitive

  • 8/4/2019 A Brief on SystemC

    32/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -63 -AA 2004-2005

    An RTL Model Example

    // shifter.h

    SC_MODULE(shifter) {

    sc_in din;

    sc_in clk;

    sc_in load;

    sc_in LR; // shift left if truesc_out dout;

    sc_uint shiftval;

    void shifting();

    SC_CTOR(shifter) {

    SC_METHOD(shifting);

    sensitive

  • 8/4/2019 A Brief on SystemC

    33/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -65 -AA 2004-2005

    Layers of Hardware Design

    Algorithmic model

    UnTimed Functional (UTF) model

    Timed Functional (TF) model

    Abstractionlevel

    Simulationspeed

    Simulationaccuracy

    Synthesizability

    Bus Cycle Accurate (BCA) model

    Cycle Accurate (CA) model

    Register Transfer Level (RTL) model

    Bus Cycle Accurate (BCA) model

    L. Benini Metodologie di Progettazione Hardware-Software Slide -66 -AA 2004-2005

    A Bus Cycle Accurate Model Example

    G Pin-accurate like RTL, but not cycle-accurateG Does not imply mapping of computation onto HW

    resources

    G Euclids algorithm to find the Greatest Common Divisor(GCD) of two numbers:

    I Given a, b, with a 0, b > 0,I Ifb divides a, then GCD(a, b) = b;I Else, GCD(a, b) = GCD(b, a mod b).

  • 8/4/2019 A Brief on SystemC

    34/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -67 -AA 2004-2005

    A Bus Cycle Accurate Model Example

    // euclid.h

    SC_MODULE (euclid) {

    sc_in_clk clock;

    sc_in reset;

    sc_in a, b;

    sc_out c;

    sc_out ready;

    void compute();

    SC_CTOR(euclid) {

    SC_CTHREAD(compute, clock.pos());

    watching(reset.delayed() == true);

    }

    };

    L. Benini Metodologie di Progettazione Hardware-Software Slide -68 -AA 2004-2005

    A Bus Cycle Accurate Model Example

    // euclid.cpp

    void euclid::compute()

    {

    unsigned int tmp_a = 0, tmp_b; // reset section

    while (true) {

    c.write(tmp_a); // signaling output

    ready.write(true);

    wait(); // moving to next cycle

    tmp_a = a.read(); // sampling input

    tmp_b = b.read();

    ready.write(false);

    wait(); // moving to next cycle

    while (tmp_b != 0) { // computing

    unsigned int r = tmp_a;

    tmp_a = tmp_b;

    r = r % tmp_b;

    tmp_b = r;

    }

    }

    }

    Recursive: how many

    cycles will it take?

    % operator: how

    to do in HW?

  • 8/4/2019 A Brief on SystemC

    35/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -69 -AA 2004-2005

    Layers of Hardware Design

    Algorithmic model

    UnTimed Functional (UTF) model

    Timed Functional (TF) model

    Abstractionlevel

    Simulationspeed

    Simulationaccuracy

    Synthesizability

    Bus Cycle Accurate (BCA) model

    Cycle Accurate (CA) model

    Register Transfer Level (RTL) model

    UnTimed Functional (UTF) model

    L. Benini Metodologie di Progettazione Hardware-Software Slide -70 -AA 2004-2005

    An UnTimed Functional (UTF) Model Example

    G Very widespread modeling levelG Describes functionality, but not timingG Most general form of UTF model: Kahn Process

    Networks (KPN)

    G But often implemented as Dataflow model: modulescommunicating with each other via blocking FIFOs

    Constant

    generatorAdder Fork Printer

  • 8/4/2019 A Brief on SystemC

    36/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -71 -AA 2004-2005

    An UnTimed Functional (UTF) Model Example

    // constgen.h

    SC_MODULE(constgen) {

    {

    sc_fifo_out output;

    SC_CTOR(constgen) {

    SC_THREAD(generating());

    }

    void generating() {

    while (true) {

    output.write(0.7);

    }

    }

    }

    L. Benini Metodologie di Progettazione Hardware-Software Slide -72 -AA 2004-2005

    An UnTimed Functional (UTF) Model Example

    // adder.h

    SC_MODULE(adder) {

    {

    sc_fifo_in input1, input2;

    sc_fifo_out output;

    SC_CTOR(adder) {

    SC_THREAD(adding());

    }

    void adding() {

    while (true) {

    output.write(input1.read() + input2.read());

    }

    }

    }

  • 8/4/2019 A Brief on SystemC

    37/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -73 -AA 2004-2005

    An UnTimed Functional (UTF) Model Example

    // forker.h

    SC_MODULE(forker) {

    {

    sc_fifo_in input;

    sc_fifo_out output1, output2;

    SC_CTOR(forker) {

    SC_THREAD(forking());

    }

    void forking() {

    while (true) {

    float value = input.read();

    output1.write(value);

    output2.write(value);

    }

    }

    }

    L. Benini Metodologie di Progettazione Hardware-Software Slide -74 -AA 2004-2005

    An UnTimed Functional (UTF) Model Example

    // printer.h

    SC_MODULE(printer) {

    {

    sc_fifo_in input;

    SC_CTOR(printer) {

    SC_THREAD(printing());

    }

    void printing() {

    for (unsigned int i = 0; i < 100; i++) {

    float value = input.read();

    printf(%f\n, value);

    }

    return; // this indirectly stops the simulation

    // (no data will be flowing any more)

    }

    }

  • 8/4/2019 A Brief on SystemC

    38/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -75 -AA 2004-2005

    An UnTimed Functional (UTF) Model Example

    // main.cppint sc_main(int, char**) {

    constgen my_constgen(my_constgen_name); // module

    adder my_adder(my_adder_name); // instantiation

    forker my_forker(my_forker_name);

    printer my_printer(my_printer_name);

    sc_fifo constgen_adder(constgen_adder, 5); // FIFO

    sc_fifo adder_fork(adder_fork, 1); // instantiation

    sc_fifo fork_adder(fork_adder, 1);

    sc_fifo fork_printer(fork_printer, 1);

    fork_adder.write(2.3); // initial setup

    my_constgen.output(constgen_adder); my_adder.input1(constgen_adder);

    my_adder.input2(fork_adder); my_adder.output(adder_fork);

    my_fork.input(adder_fork); my_fork.output1(fork_adder); // binding my_fork.output2(fork_printer); my_printer.input(fork_printer);

    sc_start(-1); // simulate forever. Will exit

    return 0; // when no events are queued

    } // (printer exits, fifos saturate)

    L. Benini Metodologie di Progettazione Hardware-Software Slide -76 -AA 2004-2005

    Layers of Hardware Design

    Algorithmic model

    UnTimed Functional (UTF) model

    Timed Functional (TF) model

    Abstractionlevel

    S

    imulationspeed

    Sim

    ulationaccuracy

    S

    ynthesizability

    Bus Cycle Accurate (BCA) model

    Cycle Accurate (CA) model

    Register Transfer Level (RTL) model

    Timed Functional (TF) model

  • 8/4/2019 A Brief on SystemC

    39/39

    L. Benini Metodologie di Progettazione Hardware-Software Slide -77 -AA 2004-2005

    Refining to Timed Functional (TF) Model

    // constgen.h

    SC_MODULE(constgen) {

    {

    sc_fifo_out output;

    SC_CTOR(constgen) {

    SC_THREAD(generating());

    }

    void generating() {

    while (true) {

    wait(200, SC_NS);

    output.write(0.7);}

    }

    }

    Of course a bit

    simplistic, but