Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different...

18
6/9/2011 1 Mapping ForSyDe to SystemC The ForSyDe PhD Course Seyed Hosein Attarzadeh Niaki The Idea SystemC- ForSyDe ForSyDe • Language-independent modeling framework • Hierarchical process Network • Process constructors • Models of computation SystemC • C++-based system modeling library • Discrete-event simulation kernel • Support of hierarchy via modules and ports

Transcript of Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different...

Page 1: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

1

Mapping ForSyDe to SystemC The ForSyDe PhD Course

Seyed Hosein Attarzadeh Niaki

The Idea

SystemC-ForSyDe

ForSyDe

• Language-independent modeling framework

• Hierarchical process Network

• Process constructors

• Models of computation

SystemC

• C++-based system modeling library

• Discrete-event simulation kernel

• Support of hierarchy via modules and ports

Page 2: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

2

Implementing different MoCs

(Execution Semantics)

Lazy evaluation

Infinite lists

Haskell Discrete-event kernel

Finite FIFOs

SystemC

Where SystemC-ForSyDe Stands

C++

Primitive Channels

Core Language DataTypes

SystemC-AMS TLM

User Models

SFF

Page 3: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

3

Realization of Different MoCs in

SystemC-ForSyDe Different MoCs

◦ SY is ready

◦ UT(SDF) is ready

◦ DE(DT) is ready

◦ Ongoing work for CT to be integrated in the

SystemC-ForSyDe fashion

A separate tutorial for each MoC

More constructs for each MoC can be

added on demand

Mapping ForSyDe to SystemC

ForSyDe element

Process

Signal

Process Constructor

Function argument of process constructor

Value argument of process constructor

Polymorphic process or function

SystemC element

Module

Channel

Abstract modules

Pure virtual function

Value passed to class constructor

Template class or function

Page 4: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

4

A Slightly Different Naming Scheme

Haskell ForSyDe

mapSY

zipwithNSY

delaySY

SystemC ForSyDe

SY::comb

SY::combN

SY::delay

ToySDF Example – Up Sampler

Page 5: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

5

ToySDF Example – Up Sampler #ifndef UPSAMPLER_H

#define UPSAMPLER_H

#include <SDF>

using namespace ForSyDe::SDF;

class upSampler : public comb<float,float>

{

public:

upSampler(sc_module_name _name) : comb<float,float>(_name,1,2){}

protected:

std::vector<float> _func(std::vector<float> a)

{

std::vector<float> ret(2);

ret[0] = a[0];

ret[1] = a[0];

return ret;

}

};

#endif

ToySDF Example – Up Sampler #ifndef UPSAMPLER_H

#define UPSAMPLER_H

#include <SDF>

using namespace ForSyDe::SDF;

class upSampler : public comb<float,float>

{

public:

upSampler(sc_module_name _name) : comb<float,float>(_name,1,2){}

protected:

std::vector<float> _func(std::vector<float> a)

{

std::vector<float> ret(2);

ret[0] = a[0];

ret[1] = a[0];

return ret;

}

};

#endif

Each MoC has its

own namespace

Page 6: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

6

ToySDF Example – Up Sampler #ifndef UPSAMPLER_H

#define UPSAMPLER_H

#include <SDF>

using namespace ForSyDe::SDF;

class upSampler : public comb<float,float>

{

public:

upSampler(sc_module_name _name) : comb<float,float>(_name,1,2){}

protected:

std::vector<float> _func(std::vector<float> a)

{

std::vector<float> ret(2);

ret[0] = a[0];

ret[1] = a[0];

return ret;

}

};

#endif

Create a process

from a process

constructor

ToySDF Example – Up Sampler #ifndef UPSAMPLER_H

#define UPSAMPLER_H

#include <SDF>

using namespace ForSyDe::SDF;

class upSampler : public comb<float,float>

{

public:

upSampler(sc_module_name _name) : comb<float,float>(_name,1,2){}

protected:

std::vector<float> _func(std::vector<float> a)

{

std::vector<float> ret(2);

ret[0] = a[0];

ret[1] = a[0];

return ret;

}

};

#endif

Needed due to

lack of type

inference in C++

Page 7: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

7

ToySDF Example – Up Sampler #ifndef UPSAMPLER_H

#define UPSAMPLER_H

#include <SDF>

using namespace ForSyDe::SDF;

class upSampler : public comb<float,float>

{

public:

upSampler(sc_module_name _name) : comb<float,float>(_name,1,2){}

protected:

std::vector<float> _func(std::vector<float> a)

{

std::vector<float> ret(2);

ret[0] = a[0];

ret[1] = a[0];

return ret;

}

};

#endif

Initial values to the

process constructor

ToySDF Example – Up Sampler #ifndef UPSAMPLER_H

#define UPSAMPLER_H

#include <SDF>

using namespace ForSyDe::SDF;

class upSampler : public comb<float,float>

{

public:

upSampler(sc_module_name _name) : comb<float,float>(_name,1,2){}

protected:

std::vector<float> _func(std::vector<float> a)

{

std::vector<float> ret(2);

ret[0] = a[0];

ret[1] = a[0];

return ret;

}

};

#endif

The function

argument (virtual

function) is

implemented

Page 8: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

8

ToySDF Example – Up Sampler #ifndef UPSAMPLER_H

#define UPSAMPLER_H

#include <SDF>

using namespace ForSyDe::SDF;

class upSampler : public comb<float,float>

{

public:

upSampler(sc_module_name _name) : comb<float,float>(_name,1,2){}

protected:

std::vector<float> _func(std::vector<float> a)

{

std::vector<float> ret(2);

ret[0] = a[0];

ret[1] = a[0];

return ret;

}

};

#endif

ToySDF Example – Composite

Averager

Page 9: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

9

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

Uses another

process

Page 10: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

10

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

A

composite

process

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

Defining

the ports

Page 11: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

11

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

Instantiating

a sub-

process

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

Process constructors

without function

arguments can be

instantiated directly

Page 12: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

12

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

FIFOs used

for inter-

connection

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

Wiring

up

Page 13: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

13

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

Port names

based on

convention

ToySDF Example – Composite

Averager #ifndef COMPAVG_H

#define COMPAVG_H

#include <SDF>

#include "averager.h"

using namespace ForSyDe::SDF;

SC_MODULE(compAvg)

{

sc_fifo_in<float> iport;

sc_fifo_out<float> oport;

averager avg1;

delayn<float> avginit;

sc_fifo<float> din, dout;

SC_CTOR(compAvg): avg1("avg1"), avginit("avginit1",0,2)

{

avg1.iport1(iport);

avg1.iport2(dout);

avg1.oport(oport);

avg1.oport(din);

avginit.iport(din);

avginit.oport(dout);

}

};

#endif

Page 14: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

14

ToySDF Example

ToySDF – Top Level and Testbench I

#include "compAvg.h"

#include "upSampler.h"

#include "downSampler.h"

#include <iostream>

using namespace ForSyDe::SDF;

class stimuli : public source<float>

{

public:

stimuli(sc_module_name _name) : source<float>(_name, 0){}

protected:

float _func(float inp)

{

return inp+1;

}

};

class report : public sink<float>

{

public:

report(sc_module_name _name) : sink<float>(_name){}

protected:

void _func(float inp)

{

std::cout << "output value: " << inp << std::endl;

}

};

Page 15: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

15

ToySDF – Top Level and Testbench I

#include "compAvg.h"

#include "upSampler.h"

#include "downSampler.h"

#include <iostream>

using namespace ForSyDe::SDF;

class stimuli : public source<float>

{

public:

stimuli(sc_module_name _name) : source<float>(_name, 0){}

protected:

float _func(float inp)

{

return inp+1;

}

};

class report : public sink<float>

{

public:

report(sc_module_name _name) : sink<float>(_name){}

protected:

void _func(float inp)

{

std::cout << "output value: " << inp << std::endl;

}

};

Generate

s a ramp

ToySDF – Top Level and Testbench I

#include "compAvg.h"

#include "upSampler.h"

#include "downSampler.h"

#include <iostream>

using namespace ForSyDe::SDF;

class stimuli : public source<float>

{

public:

stimuli(sc_module_name _name) : source<float>(_name, 0){}

protected:

float _func(float inp)

{

return inp+1;

}

};

class report : public sink<float>

{

public:

report(sc_module_name _name) : sink<float>(_name){}

protected:

void _func(float inp)

{

std::cout << "output value: " << inp << std::endl;

}

};

Outputs

the values

Page 16: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

16

ToySDF – Top Level and Testbench I

#include "compAvg.h"

#include "upSampler.h"

#include "downSampler.h"

#include <iostream>

using namespace ForSyDe::SDF;

class stimuli : public source<float>

{

public:

stimuli(sc_module_name _name) : source<float>(_name, 0){}

protected:

float _func(float inp)

{

return inp+1;

}

};

class report : public sink<float>

{

public:

report(sc_module_name _name) : sink<float>(_name){}

protected:

void _func(float inp)

{

std::cout << "output value: " << inp << std::endl;

}

};

ToySDF – Top Level and Testbench II

SC_MODULE(Top)

{

sc_fifo<float> src, upsrc, res,

downres;

stimuli stim1;

report report1;

upSampler us1;

downSampler ds1;

compAvg ca1;

SC_CTOR(Top): stim1("stim1"),

us1("us1"), ds1("ds1"),

ca1("ca1"), report1("report1")

{

stim1.oport(src);

us1.iport(src);

us1.oport(upsrc);

ca1.iport(upsrc);

ca1.oport(res);

ds1.iport(res);

ds1.oport(downres);

report1.iport(downres);

}

};

Page 17: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

17

ToySDF Example – Main File #include "Top.h"

int sc_main(int argc,

char **argv)

{

Top top("top");

sc_start();

return 0;

}

> make

> ./run.x

output value: 0

output value: 0.333333

output value: 1.44444

output value: 2.33333

output value: 3.77778

output value: 4.27161

output value: 5.7572

output value: 6.75309

output value: 8.25103

output value: 8.7508

output value: 10.2503

output value: 11.2501

output value: 12.75

...

Supporting Documentation

API Documentation

Design Guides/Tutorials

Methodology Specification

Page 18: Mapping ForSyDe to SystemC - KTHingo/forsyde-phd-course... · 6/9/2011 3 Realization of Different MoCs in SystemC-ForSyDe Different MoCs SY is ready UT(SDF) is ready DE(DT) is ready

6/9/2011

18

MoC Tutorials

Brief introduction to the SFF

◦ Assume a beginner’s knowledge in SystemC

◦ No assumption on ForSyDe or the formal

framework

Installation

Modeling

◦ Constructing Processes

◦ Interconnection and hierarchy

◦ Examples

Doxygen-Generated

Documentation API documentation at the same time as

code development

◦ Shipped together with the code

◦ Updated together with the library

Generated in HTML and Latex (PDF)

formats

◦ Easy to browse with references to the code