Dataset Viewer
text
stringlengths 41
20k
|
---|
/*
============================================================================
Name : displayYUV.c
Author : mpelcat & kdesnos & jheulot
Modified by : jserot (for use in the HoCL framework)
Version :
Copyright : CECILL-C
Description : Displaying YUV frames one next to another in a row
============================================================================
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "yuvDisplay.h"
//#include "clock.h"
#include <SDL.h>
#include <SDL_ttf.h>
#ifdef SYSTEMC_TARGET
#include <systemc.h>
#endif
//#define FPS_MEAN 49
int quitViewer = 0;
/**
* Structure representing one display
*/
typedef struct YuvDisplay
{
SDL_Texture* textures[NB_DISPLAY]; // One overlay per frame
SDL_Window *screen; // SDL surface where to display
SDL_Renderer *renderer;
TTF_Font *text_font;
int currentXMin; // Position for next display
int initialized; // Initialization done ?
int stampId;
int frameCnt;
} YuvDisplay;
// Initialize
static YuvDisplay display;
int exitCallBack(void* userdata, SDL_Event* event){
if (event->type == SDL_QUIT){
printf("Exit request from GUI.\n");
#ifdef SYSTEMC_TARGET
sc_stop();
#else
quitViewer = 1;
#endif
return 0;
}
return 1;
}
/**
* Initializes a display frame. Be careful, once a window size has been chosen,
* all videos must share the same window size
*
* @param id display unique identifier
* @param width width
* @param height heigth
*/
void yuvDisplayInit(int id, int width, int height)
{
if (display.initialized == 0)
{
display.currentXMin = 0;
}
if (height > DISPLAY_H)
{
fprintf(stderr, "SDL screen is not high enough for display %d.\n", id);
exit(1);
}
else if (id >= NB_DISPLAY)
{
fprintf(stderr, "The number of displays is limited to %d.\n", NB_DISPLAY);
exit(1);
}
else if (display.currentXMin + width > DISPLAY_W)
{
fprintf(stderr, "The number is not wide enough for display %d.\n", NB_DISPLAY);
exit(1);
}
#ifdef VERBOSE
printf("SDL screen height OK, width OK, number of displays OK.\n");
#endif
if (display.initialized == 0)
{
// Generating window name
char* name = "Display";
display.initialized = 1;
printf("SDL_Init_Start\n");
if (SDL_Init(SDL_INIT_VIDEO))
{
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
printf("SDL_Init_end\n");
/* Initialize SDL TTF for text display */
if (TTF_Init())
{
printf("TTF initialization failed: %s\n", TTF_GetError());
}
printf("TTF_Init\n");
/* Initialize Font for text display */
display.text_font = TTF_OpenFont(PATH_TTF, 20);
if (!display.text_font)
{
printf("TTF_OpenFont: %s\n", TTF_GetError());
}
display.screen = SDL_CreateWindow(name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
DISPLAY_W, DISPLAY_H, SDL_WINDOW_SHOWN);
if (!display.screen)
{
fprintf(stderr, "SDL: could not set video mode - exiting\n");
exit(1);
}
display.renderer = SDL_CreateRenderer(display.screen, -1, SDL_RENDERER_ACCELERATED);
if (!display.renderer)
{
fprintf(stderr, "SDL: could not create renderer - exiting\n");
exit(1);
}
}
if (display.textures[id] == NULL)
{
display.textures[id] = SDL_CreateTexture(display.renderer,
SDL_PIXELFORMAT_IYUV,
SDL_TEXTUREACCESS_STREAMING,
width, height);
if (!display.textures[id])
{
fprintf(stderr, "SDL: could not create texture - exiting\n");
exit(1);
}
display.currentXMin += width;
}
display.stampId = 0;
display.frameCnt = 0;
/* for (int i = 0; i<FPS_MEAN; i++){ */
/* startTiming(i + 1); */
/* } */
SDL_SetEventFilter(exitCallBack, NULL);
printf("yuvDisplayInit done\n");
}
void yuvDisplay(int id, int width, int height, unsigned char *y, unsigned char *u, unsigned char *v){
yuvDisplayWithNbSlice(id, -1, y, u, v);
display.frameCnt++;
}
void yuvDisplayWithNbSlice(int id, int nbSlice, unsigned char *y, unsigned char *u, unsigned char *v)
{
SDL_Texture* texture = display.textures[id];
int w, h;
// Retrieve texture attribute
SDL_QueryTexture(texture, NULL, NULL, &w, &h);
SDL_UpdateYUVTexture(
texture, NULL,
y, w,
u, w / 2,
v, w / 2
);
SDL_Rect screen_rect;
screen_rect.w = w;
screen_rect.h = h;
screen_rect.x = w*id;
screen_rect.y = 0;
SDL_RenderCopy(display.renderer, texture, NULL, &screen_rect);
SDL_Color colorWhite = { 255, 255, 255, 255 };
/* /\* Draw FPS text *\/ */
/* char fps_text[20]; */
/* int time = stopTiming(display.stampId + 1); */
/* sprintf(fps_text, "FPS: %.2f", 1. / (time / 1000000. / FPS_MEAN)); */
/* startTiming(display.stampId + 1); */
/* display.stampId = (display.stampId + 1) % FPS_MEAN; */
/* SDL_Surface* fpsText = TTF_RenderText_Blended(display.text_font, fps_text, colorWhite); */
/* SDL_Texture* fpsTexture = SDL_CreateTextureFromSurface(display.renderer, fpsText); */
/* int fpsWidth, fpsHeight; */
/* SDL_QueryTexture(fpsTexture, NULL, NULL, &fpsWidth, &fpsHeight); */
/* SDL_Rect fpsTextRect; */
/* fpsTextRect.x = 0; */
/* fpsTextRect.y = 0; */
/* fpsTextRect.w = fpsWidth; */
/* fpsTextRect.h = fpsHeight; */
/* SDL_RenderCopy(display.renderer, fpsTexture, NULL, &fpsTextRect); */
/* /\* Free resources *\/ */
/* SDL_FreeSurface(fpsText); */
/* SDL_DestroyTexture(fpsTexture); */
/* Draw frame cnt Text */
char frame_text[20];
sprintf(frame_text, "frame #%4d", display.frameCnt);
SDL_Surface* frameText = TTF_RenderText_Blended(display.text_font, frame_text, colorWhite);
SDL_Texture* frameTexture = SDL_CreateTextureFromSurface(display.renderer, frameText);
int frameWidth, frameHeight;
SDL_QueryTexture(frameTexture, NULL, NULL, &frameWidth, &frameHeight);
SDL_Rect frameTextRect;
frameTextRect.x = 0;
frameTextRect.y = 0;
frameTextRect.w = frameWidth;
frameTextRect.h = frameHeight;
SDL_RenderCopy(display.renderer, frameTexture, NULL, &frameTextRect);
/* Free resources */
SDL_FreeSurface(frameText);
SDL_DestroyTexture(frameTexture);
SDL_RenderPresent(display.renderer);
SDL_Event event;
// Grab all the events off the queue.
while (SDL_PollEvent(&event))
{
// printf("Goto SDL event %d\n", event.type);
switch (event.type)
{
default: break;
}
}
}
void yuvFinalize(int id)
{
SDL_DestroyTexture(display.textures[id]);
SDL_DestroyRenderer(display.renderer);
SDL_DestroyWindow(display.screen);
}
|
/*******************************************************************************
* tpencoder.cpp -- Copyright 2019 (c) Glenn Ramalho - RFIDo Design
*******************************************************************************
* Description:
* This is a testbench module to emulate a rotary quad encoder with a button.
* This encoder encodes the button by forcing pin B high.
*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************
*/
#include <systemc.h>
#include "tpencoder.h"
void tpencoder::press(bool pb) {
if (pb) {
pinA.write(GN_LOGIC_1);
buttonpressed = true;
}
else {
pinA.write(GN_LOGIC_Z);
buttonpressed = false;
}
}
void tpencoder::turnleft(int pulses, bool pressbutton) {
/* We start by raising the button, if requested. */
if (pressbutton) press(true);
/* If the last was a left turn, we need to do the direction change glitch.
* Note that if the button is pressed, we only toggle pin B. */
if (!lastwasright) {
wait(speed, SC_MS);
pinB.write(GN_LOGIC_1);
wait(speed, SC_MS);
pinB.write(GN_LOGIC_Z);
}
/* And we apply the pulses, again, watching for the button. */
wait(phase, SC_MS);
while(pulses > 0) {
wait(speed-phase, SC_MS);
if (!buttonpressed) pinA.write(GN_LOGIC_1);
wait(phase, SC_MS);
pinB.write(GN_LOGIC_1);
wait(speed-phase, SC_MS);
if (!buttonpressed) pinA.write(GN_LOGIC_Z);
if (edges == 2) wait(phase, SC_MS);
pinB.write(GN_LOGIC_Z);
if (edges != 2) wait(phase, SC_MS);
pulses = pulses - 1;
}
/* If the customer requested us to press the button with a turn, we release
* it now.
*/
if (pressbutton) {
wait(speed, SC_MS);
press(false);
}
/* And we tag that the last was a right turn as when we shift to the left
* we can have some odd behaviour.
*/
lastwasright = true;
}
void tpencoder::turnright(int pulses, bool pressbutton) {
/* We start by raising the button, if requested. */
if (pressbutton) press(true);
/* If the last was a right turn, we need to do the direction change glitch.
* Note that if the button is pressed, we only toggle pin A. */
if (lastwasright) {
wait(speed, SC_MS);
if (!buttonpressed) pinA.write(GN_LOGIC_1);
wait(speed, SC_MS);
pinB.write(GN_LOGIC_1);
wait(speed, SC_MS);
pinB.write(GN_LOGIC_Z);
wait(speed, SC_MS);
if (!buttonpressed) pinA.write(GN_LOGIC_Z);
}
/* And we apply the pulses, again, watching for the button. */
wait(phase, SC_MS);
while(pulses > 0) {
wait(speed-phase, SC_MS);
pinB.write(GN_LOGIC_1);
wait(phase, SC_MS);
if (!buttonpressed) pinA.write(GN_LOGIC_1);
wait(speed-phase, SC_MS);
pinB.write(GN_LOGIC_Z);
if (edges == 2) wait(phase, SC_MS);
if (!buttonpressed) pinA.write(GN_LOGIC_Z);
if (edges != 2) wait(phase, SC_MS);
pulses = pulses - 1;
}
/* If the customer requested us to press the button with a turn, we release
* it now.
*/
if (pressbutton) {
wait(speed, SC_MS);
press(false);
}
/* And we tag that the last was a left turn, so we can do the left turn to
* right turn glitch.
*/
lastwasright = false;
}
void tpencoder::start_of_simulation() {
pinA.write(GN_LOGIC_Z);
pinB.write(GN_LOGIC_Z);
}
void tpencoder::trace(sc_trace_file *tf) {
sc_trace(tf, buttonpressed, buttonpressed.name());
sc_trace(tf, pinA, pinA.name());
sc_trace(tf, pinB, pinB.name());
}
|
#include <systemc.h>
class sc_mutexx : public sc_prim_channel
{
public:
sc_event _free;
bool _locked;
// blocks until mutex could be locked
void lock()
{
while( _locked ) {
wait( _free );
}
_locked = true;
}
// returns false if mutex could not be locked
bool trylock()
{
if( _locked )
return false;
else
return true;
}
// unlocks mutex
void unlock()
{
_locked = false;
_free.notify();
}
// constructor
sc_mutexx(){
// _locked = false;
}
};
|
#include "systemc.h"
#include "../cnm_base.h"
SC_MODULE(cu_driver) {
#if MIXED_SIM
sc_out<sc_logic> rst;
sc_out<sc_logic> RD; // DRAM read command
sc_out<sc_logic> WR; // DRAM write command
sc_out<sc_logic> ACT; // DRAM activate command
// sc_out<sc_logic> RSTB; //
sc_out<sc_logic> AB_mode; // Signals if the All-Banks mode is enabled
sc_out<sc_logic> pim_mode; // Signals if the PIM mode is enabled
sc_out<sc_lv<BANK_BITS> > bank_addr; // Address of the bank
sc_out<sc_lv<ROW_BITS> > row_addr; // Address of the bank row
sc_out<sc_lv<COL_BITS> > col_addr; // Address of the bank column
sc_out<sc_lv<64> > DQ; // Data input from DRAM controller (output makes no sense
sc_out<sc_lv<32> > instr; // Instruction input from CRF
#else
sc_out<bool> rst;
sc_out<bool> RD; // DRAM read command
sc_out<bool> WR; // DRAM write command
sc_out<bool> ACT; // DRAM activate command
// sc_out<bool> RSTB; //
sc_out<bool> AB_mode; // Signals if the All-Banks mode is enabled
sc_out<bool> pim_mode; // Signals if the PIM mode is enabled
sc_out<sc_uint<BANK_BITS> > bank_addr; // Address of the bank
sc_out<sc_uint<ROW_BITS> > row_addr; // Address of the bank row
sc_out<sc_uint<COL_BITS> > col_addr; // Address of the bank column
sc_out<uint64_t> DQ; // Data input from DRAM controller (output makes no sense
sc_out<uint32_t> instr; // Instruction input from CRF
#endif
SC_CTOR(cu_driver) {
SC_THREAD(driver_thread);
}
void driver_thread();
};
|
/**************************************************************************
* *
* Catapult(R) Machine Learning Reference Design Library *
* *
* Software Version: 1.8 *
* *
* Release Date : Sun Jul 16 19:01:51 PDT 2023 *
* Release Type : Production Release *
* Release Build : 1.8.0 *
* *
* Copyright 2021 Siemens *
* *
**************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
* implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
**************************************************************************
* *
* The most recent version of this package is available at github. *
* *
*************************************************************************/
#pragma once
#include <systemc.h>
#include "rocket_subsystem.h"
SC_MODULE(rocket_wrapper)
{
//== Ports
sc_in<bool> clock;
sc_in<bool> reset;
sc_out<sc_lv<44>> periph_aw_msg;
sc_out<bool> periph_aw_valid;
sc_in<bool> periph_aw_ready;
sc_out<sc_lv<37>> periph_w_msg;
sc_out<bool> periph_w_valid;
sc_in<bool> periph_w_ready;
sc_in<sc_lv<6>> periph_b_msg;
sc_in<bool> periph_b_valid;
sc_out<bool> periph_b_ready;
sc_out<sc_lv<44>> periph_ar_msg;
sc_out<bool> periph_ar_valid;
sc_in<bool> periph_ar_ready;
sc_in<sc_lv<39>> periph_r_msg;
sc_in<bool> periph_r_valid;
sc_out<bool> periph_r_ready;
//== Signals
sc_signal<sc_logic> my_sc_clock;
sc_signal<sc_logic> my_sc_reset;
sc_signal<sc_lv<44>> sc_periph_aw_msg;
sc_signal<sc_logic> sc_periph_aw_valid;
sc_signal<sc_logic> sc_periph_aw_ready;
sc_signal<sc_lv<37>> sc_periph_w_msg;
sc_signal<sc_logic> sc_periph_w_valid;
sc_signal<sc_logic> sc_periph_w_ready;
sc_signal<sc_lv<6>> sc_periph_b_msg;
sc_signal<sc_logic> sc_periph_b_valid;
sc_signal<sc_logic> sc_periph_b_ready;
sc_signal<sc_lv<44>> sc_periph_ar_msg;
sc_signal<sc_logic> sc_periph_ar_valid;
sc_signal<sc_logic> sc_periph_ar_ready;
sc_signal<sc_lv<39>> sc_periph_r_msg;
sc_signal<sc_logic> sc_periph_r_valid;
sc_signal<sc_logic> sc_periph_r_ready;
//sc_logic sc_periph_r_ready;
//== Instances
sc_module_name rocket_sc_module_name{"rocket"};
rocket_subsystem rocket{rocket_sc_module_name, "rocket_subsystem"};
//== Assignment routines
void set_clock() { sc_logic e = (sc_logic) clock.read(); my_sc_clock.write(e); }
void set_reset() { sc_logic e = (sc_logic) reset.read(); my_sc_reset.write(e); }
void set_aw_msg() { sc_lv<44> e = sc_periph_aw_msg.read(); periph_aw_msg.write(e); }
void set_aw_vld() { sc_logic e = sc_periph_aw_valid.read(); periph_aw_valid.write(e.to_bool()); }
void set_aw_rdy() { sc_logic e = (sc_logic) periph_aw_ready.read(); sc_periph_aw_ready.write(e); }
void set_w_msg() { sc_lv<37> e = sc_periph_w_msg.read(); periph_w_msg.write(e); }
void set_w_vld() { sc_logic e = sc_periph_w_valid.read(); periph_w_valid.write(e.to_bool()); }
void set_w_rdy() { sc_logic e = (sc_logic) periph_w_ready.read(); sc_periph_w_ready.write(e); }
void set_b_msg() { sc_lv<6> e = periph_b_msg.read(); sc_periph_b_msg.write(e); }
void set_b_vld() { sc_logic e = (sc_logic) periph_b_valid.read(); sc_periph_b_valid.write(e); }
void set_b_rdy() { sc_logic e = sc_periph_b_ready.read(); periph_b_ready.write(e.to_bool()); }
void set_ar_msg() { sc_lv<44> e = sc_periph_ar_msg.read(); periph_ar_msg.write(e); }
void set_ar_vld() { sc_logic e = sc_periph_ar_valid.read(); periph_ar_valid.write(e.to_bool()); }
void set_ar_rdy() { sc_logic e = (sc_logic) periph_ar_ready.read(); sc_periph_ar_ready.write(e); }
void set_r_msg() { sc_lv<39> e = periph_r_msg.read(); sc_periph_r_msg.write(e); }
void set_r_vld() { sc_logic e = (sc_logic) periph_r_valid.read(); sc_periph_r_valid.write(e); }
void set_r_rdy() { sc_logic e = sc_periph_r_ready.read(); periph_r_ready.write(e.to_bool()); }
//== Constructor
SC_CTOR(rocket_wrapper)
{
rocket.clock(my_sc_clock);
rocket.reset(my_sc_reset);
rocket.periph_aw_msg (sc_periph_aw_msg);
rocket.periph_aw_valid (sc_periph_aw_valid);
rocket.periph_aw_ready (sc_periph_aw_ready);
rocket.periph_w_msg (sc_periph_w_msg);
rocket.periph_w_valid (sc_periph_w_valid);
rocket.periph_w_ready (sc_periph_w_ready);
rocket.periph_b_msg (sc_periph_b_msg);
rocket.periph_b_valid (sc_periph_b_valid);
rocket.periph_b_ready (sc_periph_b_ready);
rocket.periph_ar_msg (sc_periph_ar_msg);
rocket.periph_ar_valid (sc_periph_ar_valid);
rocket.periph_ar_ready (sc_periph_ar_ready);
rocket.periph_r_msg (sc_periph_r_msg);
rocket.periph_r_valid (sc_periph_r_valid);
rocket.periph_r_ready (sc_periph_r_ready);
SC_THREAD(set_clock); sensitive << clock;
SC_THREAD(set_reset); sensitive << reset;
SC_THREAD(set_aw_msg); sensitive << periph_aw_msg;
SC_THREAD(set_aw_vld); sensitive << periph_aw_valid;
SC_THREAD(set_aw_rdy); sensitive << sc_periph_aw_ready;
SC_THREAD(set_w_msg); sensitive << periph_w_msg;
SC_THREAD(set_w_vld); sensitive << periph_w_valid;
SC_THREAD(set_w_rdy); sensitive << sc_periph_w_ready;
SC_THREAD(set_b_msg); sensitive << sc_periph_b_msg;
SC_THREAD(set_b_vld); sensitive << sc_periph_b_valid;
SC_THREAD(set_b_rdy); sensitive << periph_b_ready;
SC_THREAD(set_ar_msg); sensitive << periph_ar_msg;
SC_THREAD(set_ar_vld); sensitive << periph_ar_valid;
SC_THREAD(set_ar_rdy); sensitive << sc_periph_ar_ready;
SC_THREAD(set_r_msg); sensitive << sc_periph_r_msg;
SC_THREAD(set_r_vld); sensitive << sc_periph_r_valid;
SC_THREAD(set_r_rdy); sensitive << periph_r_ready;
}
};
|
/*******************************************************************************
Vendor: GoodKook, goodkook@gmail.com
Associated Filename: sc_shifter_TB.cpp
Purpose: Testbench
Revision History: Aug. 1, 2024
*******************************************************************************/
#ifndef _SC_SHIFTER_TB_H_
#define _SC_SHIFTER_TB_H_
#include <systemc.h>
#include "Vshifter.h" // Verilated DUT
SC_MODULE(sc_shifter_TB)
{
sc_clock clk;
sc_signal<bool> rst,
sc_signal<sc_bv<7> > rst, din, qout;
Vshifter* u_Vshifter;
sc_trace_file* fp; // SystemC VCD file
SC_CTOR(sc_shifter_TB): // constructor
clk("clk", 100, SC_NS, 0.5, 0.0, SC_NS, false)
{
// instantiate DUT
u_Vshifter = new Vshifter("u_Vshifter");
// Binding
u_Vshifter->clk(clk);
u_Vshifter->rst(rst);
u_Vshifter->din(din);
u_Vshifter->qout(qout);
SC_THREAD(test_generator);
sensitive << clk;
// VCD Trace
fp = sc_create_vcd_trace_file("sc_shifter_TB");
sc_trace(fp, clk, "clk");
sc_trace(fp, rst, "rst");
sc_trace(fp, din, "din");
sc_trace(fp, qout, "qout");
}
void test_generator()
{
int test_count =0;
din.write(0);
rst.write(0);
wait(clk.posedge_event());
wait(clk.posedge_event());
rst.write(1);
wait(clk.posedge_event());
while(true)
{
din.write(1);
wait(clk.posedge_event());
if (test_count>6)
{
sc_close_vcd_trace_file(fp);
sc_stop();
}
else
test_count++;
}
}
};
#endif
|
/*
$Id: ticks.h,v 1.3 2010/11/23 22:42:02 scott Exp $
Description: Macros for timing
Usage: Define the timer call desired (e.g. #define FTIME, TIMEOFDAY, GETTIME)
before including "ticks.h"
Example:
#define TIMEOFDAY 1
#include "ticks.h"
void benchmark(void)
{
tick_t start, finish;
tget(start);
timed_section();
tget(finish);
printf("time in seconds:%f\n", tsec(finish, start));
}
$Log: ticks.h,v $
Revision 1.3 2010/11/23 22:42:02 scott
Add RDTSC (Read Time-Stamp Counter) option that uses the x86 instruction.
By default, use signed long for faster int to float conversion.
Change TICKS_SEC type to unsigned long (nUL).
Revision 1.2 2010/05/12 23:25:24 scott
Update comments for version control
*/
#ifndef _TICKS_H
#define _TICKS_H
/*
Casting the ticks to a signed value allows a more efficient
conversion to a float on x86 CPUs, but it limits the count to one
less high-order bit. Uncomment "unsigned" to use a full tick count.
*/
#define _uns /*unsigned*/
#if defined(FTIME)
/* deprecated */
#include <sys/timeb.h>
typedef struct timeb tick_t;
#define TICKS_SEC 1000U
#define tget(t) ftime(&(t))
#define tval(t) ((unsigned long long)t.time*TICKS_SEC+t.millitm)
#elif defined(TIMEOFDAY)
#include <sys/time.h>
typedef struct timeval tick_t;
#define TICKS_SEC 1000000UL
#define tget(t) gettimeofday(&(t),NULL)
#define tval(t) ((unsigned long long)t.tv_sec*TICKS_SEC+t.tv_usec)
#elif defined(GETTIME)
/* may need to link with lib -lrt */
#include <time.h>
typedef struct timespec tick_t;
#define TICKS_SEC 1000000000UL
#ifndef CLOCK_TYPE
#error CLOCK_TYPE must be defined as one of: \
CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID
#endif
#define tget(t) clock_gettime(CLOCK_TYPE,&(t))
#define tval(t) ((unsigned long long)t.tv_sec*TICKS_SEC+t.tv_nsec)
#elif defined(RDTSC)
typedef union {
unsigned long long ui64;
struct {unsigned int lo, hi;} ui32;
} tick_t;
#ifndef TICKS_SEC
#error TICKS_SEC must be defined to match the CPU clock frequency
#endif
#define tget(t) __asm__ __volatile__ ("lfence\n\trdtsc" : "=a" ((t).ui32.lo), "=d"((t).ui32.hi))
#define tval(t) ((t).ui64)
#elif defined(XILTIME)
#include <xtime_l.h>
typedef XTime tick_t;
#ifndef TICKS_SEC
#define TICKS_SEC COUNTS_PER_SECOND
#endif
#define tget(t) XTime_GetTime(&(t))
#define tval(t) (t)
#elif defined(M5RPNS)
/* must link with m5op_<arch>.o */
#include <m5op.h>
typedef uint64_t tick_t;
#define TICKS_SEC 1000000000UL
#define tget(t) t = rpns()
#define tval(t) (t)
#elif defined(SYSTEMC)
#include <systemc.h>
typedef uint64 tick_t;
#define TICKS_SEC 1000000000000ULL
#define tget(t) t = sc_time_stamp().value()
#define tval(t) (t)
#else
#include <time.h>
typedef clock_t tick_t;
#define TICKS_SEC CLOCKS_PER_SEC
#define tget(t) t = clock()
#define tval(t) (t)
#endif
#define tinc(a,b) ((a) += (b))
#define tdec(a,b) ((a) -= (b))
#define tdiff(f,s) (tval(f)-tval(s))
#define tsec(f,s) ((_uns long long)tdiff(f,s)/(double)TICKS_SEC)
#define tvsec(v) ((_uns long long)(v)/(double)TICKS_SEC)
#endif /* _TICKS_H */
|
/**
#define meta ...
prInt32f("%s\n", meta);
**/
/*
All rights reserved to Alireza Poshtkohi (c) 1999-2023.
Email: arp@poshtkohi.info
Website: http://www.poshtkohi.info
*/
#ifndef DEFINE_H
#define DEFINE_H
#include "systemc.h"
//#include <iostream>
#include "stdio.h"
#define SIZE 16
#define NB 4
#define NBb 16
#define nk 4
#define nr 10
#define INFILENAME "aes_cipher_input.txt"
#define INFILENAME_KEY "aes_cipher_key.txt"
#define OUTFILENAME_GOLDEN "aes_cipher_output_golden.txt"
#define OUTFILENAME "aes_cipher_output.txt"
#define DIFFFILENAME "diff.txt"
//#define WAVE_DUMP // set do dump waveform or set as compile option -DWAVE_DUMP
#endif // DEFINE_H
|
// ================================================================
// NVDLA Open Source Project
//
// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the
// NVDLA Open Hardware License; Check "LICENSE" which comes with
// this distribution for more information.
// ================================================================
// File Name: nvdla_accu2pp_if_iface.h
#if !defined(_nvdla_accu2pp_if_iface_H_)
#define _nvdla_accu2pp_if_iface_H_
#include <systemc.h>
#include <stdint.h>
#ifndef _nvdla_cc2pp_pkg_struct_H_
#define _nvdla_cc2pp_pkg_struct_H_
typedef struct nvdla_cc2pp_pkg_s {
sc_int<32> data [16];
uint8_t batch_end ;
uint8_t layer_end ;
} nvdla_cc2pp_pkg_t;
#endif
// union nvdla_accu2pp_if_u {
struct nvdla_accu2pp_if_u {
nvdla_cc2pp_pkg_t nvdla_cc2pp_pkg;
};
typedef struct nvdla_accu2pp_if_s {
// union nvdla_accu2pp_if_u pd ;
nvdla_accu2pp_if_u pd ;
} nvdla_accu2pp_if_t;
#endif // !defined(_nvdla_accu2pp_if_iface_H_)
|
// ================================================================
// NVDLA Open Source Project
//
// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the
// NVDLA Open Hardware License; Check "LICENSE" which comes with
// this distribution for more information.
// ================================================================
// File Name: nvdla_accu2pp_if_iface.h
#if !defined(_nvdla_accu2pp_if_iface_H_)
#define _nvdla_accu2pp_if_iface_H_
#include <systemc.h>
#include <stdint.h>
#ifndef _nvdla_cc2pp_pkg_struct_H_
#define _nvdla_cc2pp_pkg_struct_H_
typedef struct nvdla_cc2pp_pkg_s {
sc_int<32> data [16];
uint8_t batch_end ;
uint8_t layer_end ;
} nvdla_cc2pp_pkg_t;
#endif
// union nvdla_accu2pp_if_u {
struct nvdla_accu2pp_if_u {
nvdla_cc2pp_pkg_t nvdla_cc2pp_pkg;
};
typedef struct nvdla_accu2pp_if_s {
// union nvdla_accu2pp_if_u pd ;
nvdla_accu2pp_if_u pd ;
} nvdla_accu2pp_if_t;
#endif // !defined(_nvdla_accu2pp_if_iface_H_)
|
/*****************************************************************************
Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
more contributor license agreements. See the NOTICE file distributed
with this work for additional information regarding copyright ownership.
Accellera licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
*****************************************************************************/
/*****************************************************************************
sender.h - This is the interface file for the synchronous process "sender".
Original Author: Rashmi Goswami, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
#ifndef SENDER_H_INCLUDED
#define SENDER_H_INCLUDED
#include "systemc.h"
#include "pkt.h"
struct sender: sc_module {
sc_out<pkt> pkt_out;
sc_in<sc_int<4> > source_id;
sc_in_clk CLK;
SC_CTOR(sender)
{
SC_CTHREAD(entry, CLK.pos());
}
void entry();
};
#endif // SENDER_H_INCLUDED
|
/*****************************************************************************
Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
more contributor license agreements. See the NOTICE file distributed
with this work for additional information regarding copyright ownership.
Accellera licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
*****************************************************************************/
/*****************************************************************************
sender.h - This is the interface file for the synchronous process "sender".
Original Author: Rashmi Goswami, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
#ifndef SENDER_H_INCLUDED
#define SENDER_H_INCLUDED
#include "systemc.h"
#include "pkt.h"
struct sender: sc_module {
sc_out<pkt> pkt_out;
sc_in<sc_int<4> > source_id;
sc_in_clk CLK;
SC_CTOR(sender)
{
SC_CTHREAD(entry, CLK.pos());
}
void entry();
};
#endif // SENDER_H_INCLUDED
|
/*****************************************************************************
Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
more contributor license agreements. See the NOTICE file distributed
with this work for additional information regarding copyright ownership.
Accellera licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
*****************************************************************************/
/*****************************************************************************
sender.h - This is the interface file for the synchronous process "sender".
Original Author: Rashmi Goswami, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
#ifndef SENDER_H_INCLUDED
#define SENDER_H_INCLUDED
#include "systemc.h"
#include "pkt.h"
struct sender: sc_module {
sc_out<pkt> pkt_out;
sc_in<sc_int<4> > source_id;
sc_in_clk CLK;
SC_CTOR(sender)
{
SC_CTHREAD(entry, CLK.pos());
}
void entry();
};
#endif // SENDER_H_INCLUDED
|
/*
Problem 3 Testbench
*/
#include<systemc.h>
#include<comm.cpp>
SC_MODULE(communicationInterfaceTB) {
sc_signal<sc_uint<12> > inData;
sc_signal<bool> clock , reset , clear;
sc_signal<sc_uint<4> > payloadOut;
sc_signal<sc_uint<8> > countOut , errorOut;
void clockSignal();
void clearSignal();
void resetSignal();
void inDataSignal();
communicationInterface* cI;
SC_CTOR(communicationInterfaceTB) {
cI = new communicationInterface ("CI");
cI->clock(clock);
cI->inData(inData);
cI->reset(reset);
cI->clear(clear);
cI->payloadOut(payloadOut);
cI->countOut(countOut);
cI->errorOut(errorOut);
SC_THREAD(clockSignal);
SC_THREAD(clearSignal);
SC_THREAD(resetSignal);
SC_THREAD(inDataSignal);
}
};
void communicationInterfaceTB::clockSignal() {
while (true){
wait(20 , SC_NS);
clock = false;
wait(20 , SC_NS);
clock = true;
}
}
void communicationInterfaceTB::clearSignal() {
while (true){
wait(10 , SC_NS);
clear = false;
wait(100 , SC_NS);
clear = true;
wait(10 , SC_NS);
clear = false;
wait(100 , SC_NS);
}
}
void communicationInterfaceTB::resetSignal() {
while (true) {
wait(10 , SC_NS);
reset = true;
wait(70 , SC_NS);
reset = false;
wait(10 , SC_NS);
reset = true;
wait(1000 , SC_NS);
}
}
void communicationInterfaceTB::inDataSignal() {
while (true) {
wait(10 , SC_NS);
inData = 497;
wait(30 , SC_NS);
inData = 224;
wait(50 , SC_NS);
inData = 369;
wait(30 , SC_NS);
inData = 224;
wait(30 , SC_NS);
}
}
int sc_main(int argc , char* argv[]) {
cout<<"@ "<<sc_time_stamp()<<"----------Start---------"<<endl;
communicationInterfaceTB* cITB = new communicationInterfaceTB ("CITB");
cout<<"@ "<<sc_time_stamp()<<"----------Testbench Instance Created---------"<<endl;
sc_trace_file* VCDFile;
VCDFile = sc_create_vcd_trace_file("communication-interface");
cout<<"@ "<<sc_time_stamp()<<"----------VCD File Created---------"<<endl;
sc_trace(VCDFile, cITB->clock, "Clock");
sc_trace(VCDFile, cITB->inData, "inData");
sc_trace(VCDFile, cITB->reset, "reset");
sc_trace(VCDFile, cITB->clear, "clear");
sc_trace(VCDFile, cITB->payloadOut, "payloadOut");
sc_trace(VCDFile, cITB->countOut, "countOut");
sc_trace(VCDFile, cITB->errorOut, "errorOut");
cout<<"@ "<<sc_time_stamp()<<"----------Start Simulation---------"<<endl;
sc_start(4000, SC_NS);
cout<<"@ "<<sc_time_stamp()<<"----------End Simulation---------"<<endl;
return 0;
}
|
/*****************************************************************************
Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
more contributor license agreements. See the NOTICE file distributed
with this work for additional information regarding copyright ownership.
Accellera licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
*****************************************************************************/
/*****************************************************************************
sender.h - This is the interface file for the synchronous process "sender".
Original Author: Rashmi Goswami, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
#ifndef SENDER_H_INCLUDED
#define SENDER_H_INCLUDED
#include "systemc.h"
#include "pkt.h"
struct sender: sc_module {
sc_out<pkt> pkt_out;
sc_in<sc_int<4> > source_id;
sc_in_clk CLK;
SC_CTOR(sender)
{
SC_CTHREAD(entry, CLK.pos());
}
void entry();
};
#endif // SENDER_H_INCLUDED
|
/*
* Copyright 2019 Google, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Gabe Black
*/
#include "../../systemc.h"
|
/*****************************************************************************
Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
more contributor license agreements. See the NOTICE file distributed
with this work for additional information regarding copyright ownership.
Accellera licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
*****************************************************************************/
/*****************************************************************************
fir_top.h --
Original Author: Rocco Jonack, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
#include <systemc.h>
#include "fir_fsm.h"
#include "fir_data.h"
SC_MODULE(fir_top) {
sc_in<bool> CLK;
sc_in<bool> RESET;
sc_in<bool> IN_VALID;
sc_in<int> SAMPLE;
sc_out<bool> OUTPUT_DATA_READY;
sc_out<int> RESULT;
sc_signal<unsigned> state_out;
fir_fsm *fir_fsm1;
fir_data *fir_data1;
SC_CTOR(fir_top) {
fir_fsm1 = new fir_fsm("FirFSM");
fir_fsm1->clock(CLK);
fir_fsm1->reset(RESET);
fir_fsm1->in_valid(IN_VALID);
fir_fsm1->state_out(state_out);
fir_data1 = new fir_data("FirData");
fir_data1 -> reset(RESET);
fir_data1 -> state_out(state_out);
fir_data1 -> sample(SAMPLE);
fir_data1 -> result(RESULT);
fir_data1 -> output_data_ready(OUTPUT_DATA_READY);
}
};
|
// ================================================================
// NVDLA Open Source Project
//
// Copyright(c) 2016 - 2017 NVIDIA Corporation. Licensed under the
// NVDLA Open Hardware License; Check "LICENSE" which comes with
// this distribution for more information.
// ================================================================
// File Name: nvdla_container_number_8_bit_width_32_iface.h
#if !defined(_nvdla_container_number_8_bit_width_32_iface_H_)
#define _nvdla_container_number_8_bit_width_32_iface_H_
#include <systemc.h>
#include <stdint.h>
typedef struct nvdla_container_number_8_bit_width_32_s {
uint8_t mask ;
sc_uint<32> data [8];
uint8_t last ;
} nvdla_container_number_8_bit_width_32_t;
#endif // !defined(_nvdla_container_number_8_bit_width_32_iface_H_)
|
// -------------------------------------------------
// Contact: contact@lubis-eda.com
// Author: Tobias Ludwig, Michael Schwarz
// -------------------------------------------------
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "systemc.h"
#include "Interfaces.h"
#include "../hmac_core.h"
#include "sha_algo_masked.h"
#include "hmac_sha_join.h"
SC_MODULE(top)
{
HMAC hmc;
SHA512_masked sha384_1;
SHA512_masked sha384_2;
hmac_sha hmacsha;
blocking_in<block> top_hmac;
blocking_out<sc_biguint<KEY_WIDTH>> top_tag;
Blocking<block> hmac_msg;
Blocking<sc_biguint<KEY_WIDTH>> tag;
Blocking<sha_splitter> sha_msg_split_1, sha_msg_split_2;
Blocking<sc_biguint<DIGEST_WIDTH>> H1_setup_digest, hmac_1_digest, hmac_2_digest;
Blocking<sha_block> h_sha_msg_1, h_sha_msg_2;
Blocking<sc_biguint<DIGEST_WIDTH>> sha_1_digest, sha_2_digest;
SC_CTOR(top) : hmc("hmc"),
sha384_1("sha384_1"),
sha384_2("sha384_2"),
hmacsha("hmacsha"),
top_hmac("top_in"),
top_tag("top_out"),
hmac_msg("hmac_msg"),
tag("tag"),
sha_msg_split_1("sha_msg_split_1"),
sha_msg_split_2("sha_msg_split_2"),
//sha_msg_split_2("sha_msg_split_2"),
H1_setup_digest("H1_setup_digest"),
hmac_1_digest("hmac_1_digest"),
hmac_2_digest("hmac_2_digest"),
h_sha_msg_1("h_sha_msg_1"),
h_sha_msg_2("h_sha_msg_2"),
sha_1_digest("sha_1_digest"),
sha_2_digest("sha_2_digest")
{
hmc.hmac_msg(top_hmac);
hmc.sha_msg_1(sha_msg_split_1);
hmacsha.sha_msg_split_1(sha_msg_split_1);
hmacsha.h_sha_msg_1(h_sha_msg_1);
sha384_1.SHA_Input(h_sha_msg_1);
sha384_1.out(sha_1_digest);
hmacsha.hmac_setup_digest(H1_setup_digest);
hmc.H1_setup_digest(H1_setup_digest);
// hmc.sha_msg_2(sha_msg_split_2);
// hmacsha.sha_msg_split_2(sha_msg_split_2);
hmacsha.sha_1_digest(sha_1_digest);
hmacsha.hmac_1_digest(hmac_1_digest);
hmc.H1_digest(hmac_1_digest);
hmc.sha_msg_2(sha_msg_split_2);
hmacsha.sha_msg_split_2(sha_msg_split_2);
hmacsha.h_sha_msg_2(h_sha_msg_2);
sha384_2.SHA_Input(h_sha_msg_2);
sha384_2.out(sha_2_digest);
hmacsha.sha_2_digest(sha_2_digest);
hmacsha.hmac_2_digest(hmac_2_digest);
hmc.H2_digest(hmac_2_digest);
hmc.tag(top_tag);
}
}; |
/// \file transmitter.h
/// \brief File containing the entity of the transmitter component.
///
/// See also transmitter.cpp
#ifndef TRANSMITTER_H
#define TRANSMITTER_H
#include <systemc.h>
#include "NOC_package.h"
/*! \class transmitter
\brief SystemC description of the transmitter module.
It is the transmitter bolck of the GRLS wrapper.
*/
SC_MODULE(transmitter)
//class transmitter : public sc_module
{
/// Input port for datas from the switch
sc_in<Packet> datain;
/// reset port
sc_in<bool> rst_n;
/// clk port
sc_in<bool> clk;
/// full port. If it's set it indicates that the fifo of the transmitter is to small to contain all datas
sc_out<sc_bit> full;
/// strobe output port.It changes with datac
sc_out<sc_bit> strobe;
/// data to the receiver sub-block of the wrapper
sc_out<Packet> datac;
/// main process of the transmitter module
void evaluate();
//Packet FIFO[FIFO_TX_DIM];
/// fifo used to manage case of fast transmitter
Packet* FIFO;
int i,last_pos,c;
ofstream tx_file;
//SC_CTOR(transmitter)
/// constructor of the transmitter
SC_HAS_PROCESS(transmitter);
transmitter(sc_module_name name_ , int N_R , int N_T, int fifo_tx_dim) : sc_module(name_), m_N_R(N_R), m_N_T(N_T),m_fifo_tx_dim(fifo_tx_dim)
{
SC_METHOD(evaluate);
sensitive<<clk.pos()<<rst_n.neg();
FIFO= new Packet[m_fifo_tx_dim];
for (i=0;i<m_fifo_tx_dim;i++)
FIFO[i]=empty_NL_PDU;
last_pos=0;
if(m_N_R > m_N_T)
c=m_N_R;
tx_file.open ("tx_file.txt",ios::trunc);
tx_file << "SIMULATION STARTS NOW: "<<endl<<endl;
tx_file.close();
}
private:
int m_N_R,m_N_T,m_fifo_tx_dim;
};
#endif
|
/*
* breg_if.h
*
* Created on: 14 de mai de 2017
* Author: drcfts
*/
#ifndef BREG_IF_H_
#define BREG_IF_H_
#include "systemc.h"
#include <stdint.h>
struct breg_if : public sc_interface{
virtual int32_t
read(const unsigned address) = 0;
virtual void
write(const unsigned address, int32_t dado) = 0;
virtual void
dump_breg() = 0;
};
#endif /* BREG_IF_H_ */
|
/*******************************************************************************
* adc_types.h -- Copyright 2019 (c) Glenn Ramalho - RFIDo Design
*******************************************************************************
* Description:
* Defines types of ESP32 ADC being used.
*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************
*/
#ifndef _ADC_TYPES_H
#define _ADC_TYPES_H
#include <systemc.h>
#include "esp32adc1.h"
#include "esp32adc2.h"
typedef esp32adc1 adc1;
typedef esp32adc2 adc2;
extern adc1 *adc1ptr;
extern adc2 *adc2ptr;
#endif
|
//
// Created by tobias on 29.11.17.
//
#ifndef PROJECT_EXAMPLE2_H
#define PROJECT_EXAMPLE2_H
#include "systemc.h"
#include "Interfaces.h"
#include "types.h"
struct Example4 : public sc_module {
SC_HAS_PROCESS(Example4);
Example4(sc_module_name name) :
master_in1("master_in1"),
value_in("value_in"),
report_out("report_out"),
var(10),
section(idle),
value(false),
nextsection(idle){SC_THREAD(fsm); }
//Blocking interface
blocking_in<int> value_in;
master_in <bool> master_in1;
master_in <bool> master_in2;
master_out <bool> report_out;
//Variables
int var;
bool value;
bool succ;
//Sections
enum Sections{idle,reading};
Sections section,nextsection;
//Behavior
void fsm() {
while (true) {
section = nextsection;
if(section == idle){
report_out->write(false);
succ = value_in->nb_read(var);
nextsection = reading;
}
if(section == reading) {
if(var == 0) master_in1->read(value);
if(value == true){
report_out->write(true);
}
nextsection=idle;
}
}
};
};
#endif //PROJECT_EXAMPLE1_H
|
/**********************************************************************
Filename: sc_fir8.h
Purpose : Core of 8-Tab Systolic FIR filter
Author : goodkook@gmail.com
History : Mar. 2024, First release
***********************************************************************/
#ifndef _SC_FIR8_H_
#define _SC_FIR8_H_
#include <systemc.h>
// Includes for accessing Arduino via serial port
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include "../c_untimed/fir8.h"
SC_MODULE(sc_fir8)
{
sc_in<bool> clk;
sc_in<sc_uint<8> > Xin;
sc_out<sc_uint<8> > Xout;
sc_in<sc_uint<16> > Yin;
sc_out<sc_uint<16> > Yout;
sc_signal<sc_uint<8> > X[FILTER_TAP_NUM]; // Shift Register X
void fir8_thread(void)
{
uint8_t x;
uint8_t yL, yH;
uint16_t y;
while(true)
{
wait(clk.posedge_event());
x = (uint8_t)Xin.read();
while(write(fd, &x, 1)<=0) // Send Byte
usleep(100);
for (int i=0; i<FILTER_TAP_NUM; i++)
{
while(read(fd, &x, 1)<=0) // Receive Byte: Shift Register of X
usleep(100);
X[i].write(sc_uint<8>(x));
}
while(read(fd, &yL, 1)<=0) // Receive Byte:LSB of y
usleep(100);
while(read(fd, &yH, 1)<=0) // Receive Byte:MSB of y
usleep(100);
y = (uint16_t)(yH<<8) | (uint16_t)(yL);
Yout.write(y);
}
}
// Arduino Serial IF
int fd; // Serial port file descriptor
struct termios options; // Serial port setting
#ifdef VCD_TRACE_FIR8
sc_trace_file* fp; // VCD file
#endif
SC_CTOR(sc_fir8):
clk("clk"),
Xin("Xin"),
Xout("Xout"),
Yin("Yin"),
Yout("Yout")
{
SC_THREAD(fir8_thread);
sensitive << clk;
// Arduino DUT
//fd = open("/dev/ttyACM0", O_RDWR | O_NDELAY | O_NOCTTY);
fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY);
if (fd < 0)
{
perror("Error opening serial port");
//return -1;
}
// Set up serial port
options.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
options.c_iflag = IGNPAR;
options.c_oflag = 0;
options.c_lflag = 0;
// Apply the settings
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &options);
// Establish Contact
int len = 0;
char rx;
while(!len)
len = read(fd, &rx, 1);
if (rx=='A')
write(fd, &rx, 1);
printf("Connection established...\n");
#ifdef VCD_TRACE_FIR8
// WAVE
fp = sc_create_vcd_trace_file("sc_fir8");
fp->set_time_unit(100, SC_PS); // resolution (trace) ps
sc_trace(fp, clk, "clk");
sc_trace(fp, Xin, "Xin");
sc_trace(fp, Xout, "Xout");
sc_trace(fp, Yin, "Yin");
sc_trace(fp, Yout, "Yout");
char szTrace[8];
for (int i=0; i<FILTER_TAP_NUM; i++)
{
sprintf(szTrace, "X_%d", i);
sc_trace(fp, X[i], szTrace);
}
#endif
}
~sc_fir8(void)
{
close(fd);
}
};
#endif
|
/**************************************************************************
* *
* Catapult(R) Machine Learning Reference Design Library *
* *
* Software Version: 1.8 *
* *
* Release Date : Sun Jul 16 19:01:51 PDT 2023 *
* Release Type : Production Release *
* Release Build : 1.8.0 *
* *
* Copyright 2021 Siemens *
* *
**************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
* implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
**************************************************************************
* *
* The most recent version of this package is available at github. *
* *
*************************************************************************/
#include <systemc.h>
#include "types.h"
#include "axi/axi4.h"
#include "axi4_segment.h"
#include "sysbus_axi_struct.h"
#include "systemc_subsystem.h"
class systemc_subsystem_wrapper : public sc_module, public sysbus_axi {
public:
//== Ports
sc_in <bool> clk;
sc_in <bool> reset_bar;
sc_in <sc_lv<44>> aw_msg_port;
sc_in <bool> aw_valid_port;
sc_out<bool> aw_ready_port;
sc_in <sc_lv<37>> w_msg_port;
sc_in <bool> w_valid_port;
sc_out<bool> w_ready_port;
sc_out<sc_lv<6>> b_msg_port;
sc_out<bool> b_valid_port;
sc_in <bool> b_ready_port;
sc_in <sc_lv<44>> ar_msg_port;
sc_in <bool> ar_valid_port;
sc_out<bool> ar_ready_port;
sc_out<sc_lv<39>> r_msg_port;
sc_out<bool> r_valid_port;
sc_in <bool> r_ready_port;
sc_clock connections_clk;
sc_event check_event;
virtual void start_of_simulation() {
Connections::get_sim_clk().add_clock_alias(
connections_clk.posedge_event(), clk.posedge_event());
}
void check_clock() { check_event.notify(2, SC_PS);} // Let SC and Vlog delta cycles settle.
void check_event_method() {
if (connections_clk.read() == clk.read()) return;
CCS_LOG("clocks misaligned!:" << connections_clk.read() << " " << clk.read());
}
systemc_subsystem CCS_INIT_S1(scs);
SC_CTOR(systemc_subsystem_wrapper)
: connections_clk("connections_clk", CLOCK_PERIOD, SC_NS, 0.5, 0, SC_NS, true)
{
SC_METHOD(check_clock);
sensitive << connections_clk;
sensitive << clk;
SC_METHOD(check_event_method);
sensitive << check_event;
scs.clk(connections_clk);
scs.reset_bar(reset_bar);
scs.w_cpu.aw.dat(aw_msg_port);
scs.w_cpu.aw.vld(aw_valid_port);
scs.w_cpu.aw.rdy(aw_ready_port);
scs.w_cpu.w.dat(w_msg_port);
scs.w_cpu.w.vld(w_valid_port);
scs.w_cpu.w.rdy(w_ready_port);
scs.w_cpu.b.dat(b_msg_port);
scs.w_cpu.b.vld(b_valid_port);
scs.w_cpu.b.rdy(b_ready_port);
scs.r_cpu.ar.dat(ar_msg_port);
scs.r_cpu.ar.vld(ar_valid_port);
scs.r_cpu.ar.rdy(ar_ready_port);
scs.r_cpu.r.dat(r_msg_port);
scs.r_cpu.r.vld(r_valid_port);
scs.r_cpu.r.rdy(r_ready_port);
}
};
#ifdef QUESTA
SC_MODULE_EXPORT(systemc_subsystem_wrapper);
#endif
|
#include <systemc.h>
SC_MODULE( fir ) {
sc_in<bool> clk;
sc_in<bool> rst;
sc_in<sc_int<16>> inp;
sc_out<sc_int<16>> out;
// Handshake signals
sc_in<bool> inp_vld;
sc_out<bool> inp_rdy;
sc_out<bool> out_vld;
sc_in<bool> out_rdy;
void fir_main();
SC_CTOR( fir ) {
SC_CTHREAD(fir_main, clk.pos());
reset_signal_is(rst, true);
}
}; |
#ifndef COUNTER_H
#define COUNTER_H
#include <systemc.h>
#include "constants.h"
SC_MODULE(CounterModule){
// Inputs
sc_in<bool> clk;
sc_in<bool> reset;
sc_in<bool> up_down_ctrl;
sc_in<bool> count_enable;
//Outputs
sc_out<sc_uint<N> > count_out;
sc_out<bool> overflow_intr;
sc_out<bool> underflow_intr;
// Variables
sc_uint<N> count;
// Main function of the module
void do_count();
SC_CTOR(CounterModule){
SC_METHOD(do_count);
sensitive << clk.pos();
}
};
#endif
|
#ifndef __I2C_CONTROLLER_TB_H
#define __I2C_CONTROLLER_TB_H
#include <systemc.h>
#include <i2c_controller.h>
#include <i2c_slave_controller.h>
SC_MODULE(i2c_controller_tb)
{
sc_clock *clk;
sc_signal<bool> rst;
sc_signal<sc_uint<7>> addr;
sc_signal<sc_uint<8>> data_in;
sc_signal<bool> enable;
sc_signal<bool> rw;
sc_signal<sc_lv<8>> data_out;
sc_signal<bool> ready;
sc_signal<sc_logic, SC_MANY_WRITERS> i2c_sda;
sc_signal<sc_logic> i2c_scl;
i2c_controller *master;
i2c_slave_controller *slave;
SC_CTOR(i2c_controller_tb)
{
clk = new sc_clock("clk",2,SC_NS);
master = new i2c_controller("i2c_controller");
master->clk(*clk);
master->rst(rst);
master->addr(addr);
master->data_in(data_in);
master->enable(enable);
master->rw(rw);
master->data_out(data_out);
master->ready(ready);
master->i2c_sda(i2c_sda);
master->i2c_scl(i2c_scl);
slave = new i2c_slave_controller("i2c_slave_controller");
slave->sda(i2c_sda);
slave->scl(i2c_scl);
SC_THREAD(stimuli);
sensitive << *clk << rst;
}
~i2c_controller_tb()
{
delete master;
delete slave;
}
void stimuli();
};
#endif
|
/*******************************************************************************
Poorman's Standard-Emulator
---------------------------
Vendor: GoodKook, goodkook@gmail.com
Associated Filename: sc_DUT_TB.h
Purpose: Testbench for DUT
Revision History: Jun. 1, 2024
*******************************************************************************/
#ifndef _SC_DUT_TB_H_
#define _SC_DUT_TB_H_
#include <systemc.h>
#include "VDUT.h"
#ifdef CO_EMULATION
#include "DUT.h"
#endif
SC_MODULE(sc_DUT_TB)
{
sc_clock CLK;
sc_signal<bool> nCLR;
sc_signal<bool> nLOAD;
sc_signal<bool> ENP;
sc_signal<bool> ENT;
sc_signal<bool> RCO;
// Verilator treats all Verilog's vector as <uint32_t>
sc_signal<uint32_t> Digit;
sc_signal<uint32_t> Din;
sc_signal<uint32_t> Dout;
// Exact DUT ports' vector width
sc_signal<sc_uint<2> > Digit_n2;
sc_signal<sc_uint<4> > Din_n4;
sc_signal<sc_uint<16> > Dout_n16;
// Verilated DUT or Foreign Verilog
VDUT* u_VDUT;
#ifdef CO_EMULATION
// Emulator DUT
DUT* u_DUT;
sc_signal<sc_uint<16> > Dout_emu;
sc_signal<bool> RCO_emu;
#endif
// Convert Verilator's ports to DUT's ports
void conv_method()
{
Digit_n2.write((sc_uint<2>)Digit);
Din_n4.write((sc_uint<4>)Din);
Dout_n16.write((sc_uint<16>)Dout);
}
void test_generator();
void monitor();
sc_trace_file* fp; // VCD file
SC_CTOR(sc_DUT_TB) : // Constructor
CLK("CLK", 100, SC_NS, 0.5, 0.0, SC_NS, false)
{
SC_THREAD(test_generator);
sensitive << CLK;
SC_THREAD(monitor);
sensitive << CLK;
SC_METHOD(conv_method);
sensitive << Din << Dout << Digit;
// DUT Instantiation
u_VDUT = new VDUT("u_VDUT");
// Binding
u_VDUT->CLK(CLK);
u_VDUT->nCLR(nCLR);
u_VDUT->nLOAD(nLOAD);
u_VDUT->Digit(Digit);
u_VDUT->ENP(ENP);
u_VDUT->ENT(ENT);
u_VDUT->Din(Din);
u_VDUT->Dout(Dout);
u_VDUT->RCO(RCO);
#ifdef CO_EMULATION
u_DUT = new DUT("u_DUT");
// Binding
u_DUT->CLK(CLK);
u_DUT->nCLR(nCLR);
u_DUT->nLOAD(nLOAD);
u_DUT->Digit(Digit_n2);
u_DUT->Din(Din_n4);
u_DUT->Dout(Dout_emu);
u_DUT->RCO(RCO_emu);
#endif
// VCD Trace
fp = sc_create_vcd_trace_file("sc_DUT_TB");
fp->set_time_unit(100, SC_PS);
sc_trace(fp, CLK, "CLK");
sc_trace(fp, nCLR, "nCLR");
sc_trace(fp, nLOAD, "nLOAD");
sc_trace(fp, Digit_n2, "Digit");
sc_trace(fp, ENP, "ENP");
sc_trace(fp, ENT, "ENT");
sc_trace(fp, Din_n4, "Din");
sc_trace(fp, Dout_n16, "Dout");
sc_trace(fp, RCO, "RCO");
#ifdef CO_EMULATION
sc_trace(fp, Dout_emu, "Dout_emu");
sc_trace(fp, RCO_emu, "RCO_emu");
#endif
}
// Destructor
~sc_DUT_TB()
{}
};
#endif // _SC_DUT_H_
|
/****************************************************************************
*
* Copyright (c) 2015, Cadence Design Systems. All Rights Reserved.
*
* This file contains confidential information that may not be
* distributed under any circumstances without the written permision
* of Cadence Design Systems.
*
***************************************************************************/
#ifndef _DUT_CYCSIM_INCLUDED_
#define _DUT_CYCSIM_INCLUDED_
#include "systemc.h"
#include "cynthhl.h"
SC_MODULE(dut_cycsim)
{
// Port declarations.
sc_in< bool > clk;
sc_in< bool > rst;
sc_out< bool > din_busy;
sc_in< bool > din_vld;
sc_in< sc_uint< 8 > > din_data_a;
sc_in< sc_uint< 8 > > din_data_b;
sc_in< sc_uint< 8 > > din_data_c;
sc_in< sc_uint< 8 > > din_data_d;
sc_in< sc_uint< 8 > > din_data_e;
sc_in< sc_uint< 8 > > din_data_f;
sc_in< sc_uint< 8 > > din_data_g;
sc_in< sc_uint< 8 > > din_data_h;
sc_in< bool > dout_busy;
sc_out< bool > dout_vld;
sc_out< sc_uint< 32 > > dout_data;
dut_cycsim( sc_module_name in_name=sc_module_name(sc_gen_unique_name(" dut") ) )
: sc_module(in_name)
,clk("clk")
,rst("rst")
,din_busy("din_busy")
,din_vld("din_vld")
,din_data_a("din_data_a"),
din_data_b("din_data_b"),
din_data_c("din_data_c"),
din_data_d("din_data_d"),
din_data_e("din_data_e"),
din_data_f("din_data_f"),
din_data_g("din_data_g"),
din_data_h("din_data_h")
,dout_busy("dout_busy")
,dout_vld("dout_vld")
,dout_data("dout_data")
{
};
};
#endif
|
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2017 Cadence Design Systems, Inc. All rights reserved worldwide.
//
// The code contained herein is the proprietary and confidential information
// of Cadence or its licensors, and is supplied subject to a previously
// executed license and maintenance agreement between Cadence and customer.
// This code is intended for use with Cadence high-level synthesis tools and
// may not be used with other high-level synthesis tools. Permission is only
// granted to distribute the code as indicated. Cadence grants permission for
// customer to distribute a copy of this code to any partner to aid in designing
// or verifying the customer's intellectual property, as long as such
// distribution includes a restriction of no additional distributions from the
// partner, unless the partner receives permission directly from Cadence.
//
// ALL CODE FURNISHED BY CADENCE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, AND CADENCE SPECIFICALLY DISCLAIMS ANY WARRANTY OF NONINFRINGEMENT,
// FITNESS FOR A PARTICULAR PURPOSE OR MERCHANTABILITY. CADENCE SHALL NOT BE
// LIABLE FOR ANY COSTS OF PROCUREMENT OF SUBSTITUTES, LOSS OF PROFITS,
// INTERRUPTION OF BUSINESS, OR FOR ANY OTHER SPECIAL, CONSEQUENTIAL OR
// INCIDENTAL DAMAGES, HOWEVER CAUSED, WHETHER FOR BREACH OF WARRANTY,
// CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef DUT_H
#define DUT_H
/* This file defines the module "dut", which is synthesizable. It is
instantiated in the top-level module System (see system.h). */
#include <systemc.h> /* SystemC definitions. */
#include <esc.h> /* Cadence ESC functions and utilities. */
#include <stratus_hls.h> /* Cadence Stratus definitions. */
#include <cynw_p2p.h> /* The cynw_p2p communication channel. */
#include "stream_16X8.h" /* Generated stream interface classes */
#include "defines.h" /* definitions common to the TB and DUT. */
#include "directives.h" /* Synthesis directives. */
SC_MODULE( dut )
{
sc_in_clk clk;
sc_in< bool > rst;
cynw_p2p< input_data, ioConfig >::in in;
cynw_p2p< output_data, ioConfig >::out out;
stream_16X8::in<ioConfig> streamin;
stream_16X8::out<ioConfig> streamout;
SC_CTOR( dut )
: clk( "clk" )
, rst( "rst" )
, in( "in" )
, out( "out" )
, streamin( "streamin" )
, streamout( "streamout" )
{
SC_CTHREAD( thread1, clk.pos() );
reset_signal_is( rst, false );
in.clk_rst( clk, rst );
out.clk_rst( clk, rst );
streamin.clk_rst( clk, rst );
streamout.clk_rst( clk, rst );
}
sc_uint<8> x[8];
sc_uint<8> y[4];
sc_uint<8> data[16];
void thread1();
};
#endif /* DUT_H */
|
#include <systemc.h>
SC_MODULE( tb )
{
sc_in<bool> clk;
sc_out<bool> rst;
sc_out< sc_int<16> > inp;
sc_out<bool> inp_vld;
sc_in<bool> inp_rdy;
sc_in< sc_int<16> > outp;
sc_in<bool> outp_vld;
sc_out<bool> outp_rdy;
void source();
void sink();
FILE *outfp;
sc_time start_time[64], end_time[64], clock_period;
SC_CTOR( tb ){
SC_CTHREAD( source, clk.pos() );
SC_CTHREAD( sink, clk.pos() );
}
};
|
/**
#define meta ...
prInt32f("%s\n", meta);
**/
/*
All rights reserved to Alireza Poshtkohi (c) 1999-2023.
Email: arp@poshtkohi.info
Website: http://www.poshtkohi.info
*/
#ifndef __s3_h__
#define __s3_h__
#include <systemc.h>
SC_MODULE(s3)
{
sc_in<sc_uint<6> > stage1_input;
sc_out<sc_uint<4> > stage1_output;
void s3_box();
SC_CTOR(s3)
{
SC_METHOD(s3_box);
sensitive << stage1_input;
}
};
#endif
|
#include <systemc.h>
SC_MODULE ( half_adder ) {
sc_in< sc_logic > augend;
sc_in< sc_logic > addend;
sc_out< sc_logic > sum;
sc_out< sc_logic > carry_out;
void func();
SC_CTOR ( half_adder ) {
SC_METHOD ( func );
sensitive << augend << addend;
};
};
|
/********************************************************************************
* University of L'Aquila - HEPSYCODE Source Code License *
* *
* *
* (c) 2018-2019 Centre of Excellence DEWS All rights reserved *
********************************************************************************
* <one line to give the program's name and a brief idea of what it does.> *
* Copyright (C) 2022 Vittoriano Muttillo, Luigi Pomante * *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
********************************************************************************
* *
* Created on: 09/May/2022 *
* Authors: Vittoriano Muttillo, Luigi Pomante *
* *
* email: vittoriano.muttillo@guest.univaq.it *
* luigi.pomante@univaq.it *
* *
********************************************************************************
* This code has been developed from an HEPSYCODE model used as demonstrator by *
* University of L'Aquila. *
* *
* The code is used as a working example in the 'Embedded Systems' course of *
* the Master in Conputer Science Engineering offered by the *
* University of L'Aquila *
*******************************************************************************/
/********************************************************************************
* display : FirFirGCD Display.
*
* Display: Display (feedback) file
*
********************************************************************************/
/*! \file display.h
\brief Display Documented file.
Display: Display (feedback) file
*/
/** @defgroup firfirgcd_display_group FirFirGCD Display.
*
* Display Implementation
*
* @author V. Muttillo, L. Pomante
* @date Apr. 2022
* @{
*/ // start firfirgcd_display_group
#ifndef __DISPLAY_H__
#define __DISPLAY_H__
/********************************************************************************
*** Includes ***
*******************************************************************************/
#include <systemc.h>
#include "sc_csp_channel_ifs.h"
/********************************************************************************
*** Functions ***
*******************************************************************************/
////////////////////////////
// SBM DEPENDENT
////////////////////////////
////////////////////////////
// DISPLAY: PRINTS TO THE SCREEN DATA FROM THE SYSTEM
////////////////////////////
SC_MODULE(display)
{
// Port for input by channel
sc_port< sc_csp_channel_in_if< sc_uint<8> > > result_channel_port;
SC_CTOR(display)
{
SC_THREAD(output);
}
// Main method
void output();
};
/** @} */ // end of firfirgcd_display_group
#endif
/********************************************************************************
*** EOF ***
********************************************************************************/
|
/********************************************************************************
* University of L'Aquila - HEPSYCODE Source Code License *
* *
* *
* (c) 2018-2019 Centre of Excellence DEWS All rights reserved *
********************************************************************************
* <one line to give the program's name and a brief idea of what it does.> *
* Copyright (C) 2022 Vittoriano Muttillo, Luigi Pomante * *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
********************************************************************************
* *
* Created on: 09/May/2022 *
* Authors: Vittoriano Muttillo, Luigi Pomante *
* *
* email: vittoriano.muttillo@guest.univaq.it *
* luigi.pomante@univaq.it *
* *
********************************************************************************
* This code has been developed from an HEPSYCODE model used as demonstrator by *
* University of L'Aquila. *
* *
* The code is used as a working example in the 'Embedded Systems' course of *
* the Master in Conputer Science Engineering offered by the *
* University of L'Aquila *
*******************************************************************************/
/********************************************************************************
* SystemManager : System Manager file.
*
* System Manager: HEPSIM System Manager
*
********************************************************************************/
/*! \file SystemManager.cpp
\brief System Manager Documented file.
System Manager: HEPSIM System Manager.
*/
/********************************************************************************
*** Includes ***
*******************************************************************************/
#include <systemc.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <string.h>
#include "tl.h"
#include "pugixml.hpp"
#include "SystemManager.h"
using namespace std;
using namespace pugi;
////////////////////////////
// SBM INDEPENDENT
////////////////////////////
/********************************************************************************
*** Functions ***
*******************************************************************************/
// Constructor
SystemManager::SystemManager()
{
VPS = generateProcessInstances();
VCH = generateChannelInstances();
VBB = generateBBInstances();
VPL = generatePhysicalLinkInstances();
mappingPS();
mappingCH();
}
// Fill process data structure VPS from xml file (application.xml)
vector<Process> SystemManager:: generateProcessInstances(){
vector<Process> vps2;
int exp_id = 0;
int processId;
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(APPLICATION);
xml_node instancesPS2 = doc.child("instancesPS");
for (pugi::xml_node xn_process = instancesPS2.first_child(); !xn_process.empty(); xn_process = xn_process.next_sibling()){
Process pi;
// Process Name
pi.setName(xn_process.child_value("name"));
// Process id
processId = atoi((char*) xn_process.child_value("id"));
pi.setId(processId);
// Process Priority
pi.setPriority(atoi((char*) xn_process.child_value("priority")));
// Process Criticality
pi.setCriticality(atoi((char*) xn_process.child_value("criticality")));
// Process eqGate (HW size)
xml_node eqGate = xn_process.child("eqGate");
pi.setEqGate((float)eqGate.attribute("value").as_int());
// Process dataType
pi.setDataType(atoi((char*) xn_process.child_value("dataType")));
// Process MemSize (SW Size)
xml_node memSize = xn_process.child("memSize");
xml_node codeSize = memSize.child("codeSize");
for (pugi::xml_node processorModel = codeSize.child("processorModel"); processorModel; processorModel = processorModel.next_sibling()) {
pi.setCodeSize( processorModel.attribute("name").as_string(), processorModel.attribute("value").as_int() );
}
xml_node dataSize = memSize.child("dataSize");
for (pugi::xml_node processorModel = dataSize.child("processorModel"); processorModel; processorModel = processorModel.next_sibling()) {
pi.setDataSize( processorModel.attribute("name").as_string(), processorModel.attribute("value").as_int() );
}
// Process Affinity
xml_node affinity = xn_process.child("affinity");
for (pugi::xml_node processorType = affinity.child("processorType"); processorType; processorType = processorType.next_sibling()) {
string processorType_name = processorType.attribute("name").as_string();
float affinity_value = processorType.attribute("value").as_float();
pi.setAffinity(processorType_name, affinity_value);
}
// Process Concurrency
xml_node concurrency = xn_process.child("concurrency");
for (pugi::xml_node xn_cprocessId = concurrency.child("processId"); xn_cprocessId; xn_cprocessId = xn_cprocessId.next_sibling()) {
unsigned int process_id_n = xn_cprocessId.attribute("id").as_int();
float process_concurrency_value = xn_cprocessId.attribute("value").as_float();
pi.setConcurrency(process_id_n, process_concurrency_value);
}
// Process Load
xml_node load = xn_process.child("load");
for (pugi::xml_node processorId = load.child("processorId"); processorId; processorId = processorId.next_sibling()) {
unsigned int processor_id_n = processorId.attribute("id").as_int();
float process_load_value = processorId.attribute("value").as_float();
pi.setLoad(processor_id_n, process_load_value);
}
// Process time (init)
pi.processTime = sc_time(0, SC_MS);
// Process energy (init)
pi.setEnergy(0);
// Process Communication
// TO DO
if(processId == exp_id){
vps2.push_back(pi);
exp_id++;
} else {
cout << "XML for application is corrupted\n";
exit(11);
}
}
if(exp_id != NPS){
cout << "XML for application is corrupted (NPS)\n";
exit(11);
}
doc.reset();
return vps2;
}
// Fill channel data structure VCH from xml file
vector<Channel> SystemManager:: generateChannelInstances()
{
vector<Channel> vch;
// parsing xml file
xml_document myDoc;
xml_parse_result myResult = myDoc.load_file(APPLICATION);
xml_node instancesLL = myDoc.child("instancesLL");
//channel parameters
xml_node_iterator seqChannel_it;
for (seqChannel_it=instancesLL.begin(); seqChannel_it!=instancesLL.end(); ++seqChannel_it){
xml_node_iterator channel_node_it = seqChannel_it->begin();
Channel ch;
char* temp;
// CH-NAME
string name = channel_node_it->child_value();
ch.setName(name);
// CH-ID
channel_node_it++;
temp = (char*) channel_node_it->child_value();
int id = atoi(temp);
ch.setId(id);
// writer ID
channel_node_it++;
temp = (char*) channel_node_it->child_value();
int w_id = atoi(temp);
ch.setW_id(w_id);
// reader ID
channel_node_it++;
temp = (char*) channel_node_it->child_value();
int r_id = atoi(temp);
ch.setR_id(r_id);
// CH-width (logical width)
channel_node_it++;
temp = (char*) channel_node_it->child_value();
int width = atoi(temp);
ch.setWidth(width);
ch.setNum(0);
vch.push_back(ch);
}
return vch;
}
/*
* for a given processID, increments the profiling variable
* (the number of "loops" executed by the process)
*/
void SystemManager::PS_Profiling(int processId)
{
VPS[processId].profiling++;
}
// Check if a process is allocated on a SPP
bool SystemManager::checkSPP(int processId)
{
return VBB[allocationPS_BB[processId]].getProcessors()[0].getProcessorType() == "SPP";
}
// Return a subset of allocationPS by considering only processes mapped to BB with ID equal to bb_unit_id
vector<int> SystemManager::getAllocationPS_BB(int bb_id)
{
vector<int> pu_alloc;
for (unsigned int j = 2; j < allocationPS_BB.size(); j++) // 0 and 1 are the testbench
{
if (allocationPS_BB[j] == bb_id) pu_alloc.push_back(j);
}
return pu_alloc;
}
///// UPDATE XML Concurrency and Communication
void SystemManager::deleteConcXmlConCom()
{
pugi::xml_document myDoc;
pugi::xml_parse_result myResult = myDoc.load_file("./XML/application.xml");
cout << "XML Delete result: " << myResult.description() << endl;
//method 2: use object/node structure
pugi::xml_node instancesPS = myDoc.child("instancesPS");
xml_node processes = instancesPS.child("process");
for (int i = 0; i < NPS; i++){
xml_node concom = processes.child("concurrency");
for (pugi::xml_node processorId = concom.child("processId"); processorId; processorId = processorId.next_sibling()) {
concom.remove_child(processorId);
}
xml_node concom2 = processes.child("comunication");
for (pugi::xml_node processorId = concom2.child("rec"); processorId; processorId = processorId.next_sibling()) {
concom2.remove_child(processorId);
}
processes = processes.next_sibling();
}
xml_node instancesCH = myDoc.child("instancesLL");
xml_node processesCH = instancesCH.child("logical_link");
for (int i = 0; i < NCH; i++){
xml_node concom3 = processesCH.child("concurrency");
for (pugi::xml_node processorId = concom3.child("channelId"); processorId; processorId = processorId.next_sibling()) {
concom3.remove_child(processorId);
}
processesCH = processesCH.next_sibling();
}
myDoc.save_file("./XML/application.xml");
cout << endl;
}
void SystemManager::updateXmlConCom(float matrixCONC_PS_N[NPS][NPS], unsigned int matrixCOM[NPS][NPS], float matrixCONC_CH_N[NCH][NCH])
{
pugi::xml_document myDoc;
pugi::xml_parse_result myResult = myDoc.load_file("./XML/application.xml");
cout << "XML result: " << myResult.description() << endl;
//method 2: use object/node structure
pugi::xml_node instancesPS = myDoc.child("instancesPS");
for (xml_node_iterator seqProcess_it = instancesPS.begin(); seqProcess_it != instancesPS.end(); ++seqProcess_it){
int Id = atoi(seqProcess_it->child_value("id"));
if (seqProcess_it->child("concurrency")){
pugi::xml_node concurrency = seqProcess_it->child("concurrency");
for (int i = 0; i<NPS; i++){
if (i != Id){
pugi::xml_node conc_it = concurrency.append_child("processId");
conc_it.append_attribute("id").set_value(i);
conc_it.append_attribute("value").set_value(matrixCONC_PS_N[Id][i]);
}
}
}
else{
pugi::xml_node concurrency = seqProcess_it->append_child("concurrency");
for (int i = 0; i<NPS; i++){
if (i != Id){
pugi::xml_node conc_it = concurrency.append_child("processId");
conc_it.append_attribute("id").set_value(i);
conc_it.append_attribute("value").set_value(matrixCONC_PS_N[Id][i]);
}
}
}
}
//method 2: use object/node structure
pugi::xml_node instancesCOM = myDoc.child("instancesPS");
for (pugi::xml_node_iterator seqProcess_it = instancesCOM.begin(); seqProcess_it != instancesCOM.end(); ++seqProcess_it){
int Id = atoi(seqProcess_it->child_value("id"));
if (seqProcess_it->child("comunication")){
pugi::xml_node comunication = seqProcess_it->child("comunication");
for (int i = 0; i<NPS; i++){
if (i != Id){
pugi::xml_node com_it = comunication.append_child("rec");
com_it.append_attribute("idRec").set_value(i);
com_it.append_attribute("value").set_value(matrixCOM[Id][i]);
}
}
}
else{
pugi::xml_node comunication = seqProcess_it->append_child("comunication");
for (int i = 0; i<NPS; i++){
if (i != Id){
pugi::xml_node com_it = comunication.append_child("rec");
com_it.append_attribute("idRec").set_value(i);
com_it.append_attribute("value").set_value(matrixCOM[Id][i]);
}
}
}
}
pugi::xml_node instancesLL = myDoc.child("instancesLL");
for (xml_node_iterator seqLink_it = instancesLL.begin(); seqLink_it != instancesLL.end(); ++seqLink_it){
int Id = atoi(seqLink_it->child_value("id"));
if (seqLink_it->child("concurrency")){
pugi::xml_node concurrencyL = seqLink_it->child("concurrency");
for (int i = 0; i<NCH; i++){
if (i != Id){
pugi::xml_node concL_it = concurrencyL.append_child("channelId");
concL_it.append_attribute("id").set_value(i);
concL_it.append_attribute("value").set_value(matrixCONC_CH_N[Id][i]);
}
}
}
else{
pugi::xml_node concurrencyL = seqLink_it->append_child("concurrency");
for (int i = 0; i<NCH; i++){
if (i != Id){
pugi::xml_node concL_it = concurrencyL.append_child("channelId");
concL_it.append_attribute("id").set_value(i);
concL_it.append_attribute("value").set_value(matrixCONC_CH_N[Id][i]);
}
}
}
}
cout << "Saving result: " << myDoc.save_file("./XML/application.xml") << endl;
myDoc.reset();
cout << endl;
}
#if defined(_TIMING_ENERGY_)
// Fill VBB data structure from xml file (instancesTL.xml)
vector<BasicBlock> SystemManager::generateBBInstances(){
/*****************************
* LOAD BASIC BLOCKS
*****************************/
char* temp;
vector<BasicBlock> vbb;
// parsing xml file
xml_document myDoc;
xml_parse_result myResult = myDoc.load_file("./XML/instancesTL.xml");
xml_node instancesBB = myDoc.child("instancesBB");
for (xml_node_iterator seqBB_it=instancesBB.begin(); seqBB_it!=instancesBB.end(); ++seqBB_it){
xml_node_iterator BB_it = seqBB_it->begin();
BasicBlock bb;
//BB-ID
int id = atoi(BB_it->child_value());
bb.setId(id);
//BB-NAME
BB_it++;
string BBname = BB_it->child_value();
bb.setName(BBname);
//BB-TYPE
BB_it++;
string type = BB_it->child_value();
bb.setType(type);
// PROCESSING UNIT
BB_it++;
vector<ProcessingUnit> vpu;
for(xml_node child = seqBB_it->child("processingUnit");child;child= child.next_sibling("processingUnit")){
xml_node_iterator pu_it = child.begin();
ProcessingUnit pu;
//PU-NAME
string puName = pu_it->child_value();
pu.setName(puName);
//PU-ID
pu_it++;
int idPU = atoi(pu_it->child_value());
pu.setId(idPU);
//Processor Type
pu_it++;
string puType = pu_it->child_value();
pu.setProcessorType(puType);
// PU-cost
pu_it++;
float idCost = (float) atof(pu_it->child_value());
pu.setCost(idCost);
//PU-ISA
pu_it++;
string puISA = pu_it->child_value();
pu.setISA(puISA);
// PU-Frequency (MHz)
pu_it++;
float idFreq = (float) atof(pu_it->child_value());
pu.setFrequency(idFreq);
// PU-CC4CS
float** array = new float*[5];
//Int8
pu_it++;
float idCC4CSminint8 = (float) atof(pu_it->child_value());
pu_it++;
float idCC4CSmaxint8 = (float) atof(pu_it->child_value());
//Int16
pu_it++;
float idCC4CSminint16 = (float) atof(pu_it->child_value());
pu_it++;
float idCC4CSmaxint16 = (float) atof(pu_it->child_value());
//Int32
pu_it++;
float idCC4CSminint32 = (float) atof(pu_it->child_value());
pu_it++;
float idCC4CSmaxint32 = (float) atof(pu_it->child_value());
//Float
pu_it++;
float idCC4CSminfloat = (float) atof(pu_it->child_value());
pu_it++;
float idCC4CSmaxfloat = (float) atof(pu_it->child_value());
//Tot
pu_it++;
float idCC4CSmin = (float) atof(pu_it->child_value());
pu_it++;
float idCC4CSmax = (float) atof(pu_it->child_value());
array[0] = new float[2];
array[0][0] = idCC4CSminint8;
array[0][1] = idCC4CSmaxint8;
array[1] = new float[2];
array[1][0] = idCC4CSminint16;
array[1][1] = idCC4CSmaxint16;
array[2] = new float[2];
array[2][0] = idCC4CSminint32;
array[2][1] = idCC4CSmaxint32;
array[3] = new float[2];
array[3][0] = idCC4CSminfloat;
array[3][1] = idCC4CSmaxfloat;
array[4] = new float[2];
array[4][0] = idCC4CSmin;
array[4][1] = idCC4CSmax;
pu.setCC4S(array);
// PU-Power (W)
pu_it++;
float idPow = (float) atof(pu_it->child_value());
pu.setPower(idPow);
// PU-MIPS
pu_it++;
float idMIPS = (float) atof(pu_it->child_value());
pu.setMIPS(idMIPS);
// PU-I4CS
pu_it++;
float idI4CSmin = (float) atof(pu_it->child_value());
pu.setI4CSmin(idI4CSmin);
pu_it++;
float idI4CSmax = (float) atof(pu_it->child_value());
pu.setI4CSmax(idI4CSmax);
// PU-Vdd (V)
pu_it++;
float idVdd = (float)atof(pu_it->child_value());
pu.setVdd(idVdd);
// PU-Idd (A)
pu_it++;
float idIdd = (float)atof(pu_it->child_value());
pu.setIdd(idIdd);
// PU-overheadCS (us)
pu_it++;
float idOver = (float)atof(pu_it->child_value());
pu.setOverheadCS(sc_time((int)idOver, SC_US));
vpu.push_back(pu);
}
// LOACL MEMORY
bb.setProcessor(vpu);
BB_it++;
xml_node instancesLM = seqBB_it->child("localMemory");
xml_node_iterator lm_it = instancesLM.begin();
//CODE SIZE
int lmCodeSize = (int)atof(lm_it->child_value());
bb.setCodeSize(lmCodeSize);
//DATA SIZE
lm_it++;
int lmDataSize = (int)atof(lm_it->child_value());
bb.setDataSize(lmDataSize);
//eQG
lm_it++;
temp = (char*)lm_it->child_value();
int lmEqG = (int)atof(temp);
bb.setEqG(lmEqG);
// Comunication
BB_it++;
xml_node instancesCU = seqBB_it->child("communicationUnit");
xml_node_iterator cu_it = instancesCU.begin();
// TO DO
// Free Running time
BB_it++;
xml_node instancesFRT = seqBB_it->child("loadEstimation");
xml_node_iterator frt_it = instancesFRT.begin();
float lmFreeRunningTime = frt_it->attribute("value").as_float();
bb.setFRT(lmFreeRunningTime);
vbb.push_back(bb);
}
return vbb;
}
#else
/*
This method generates a dummy instance of a basic block.
Each BB contains more than one processing unit inside.
*/
vector<BasicBlock> SystemManager::generateBBInstances(){
vector<BasicBlock> vbb;
for (int i = 0; i < NBB; i++){
BasicBlock bb;
//BB-ID
bb.setId(i);
//BB-NAME
bb.setName("dummy");
//BB-TYPE
bb.setType("dummy");
// PROCESSING UNIT
vector<ProcessingUnit> vpu;
for (int j = 0; j < 4; j++){ // each block contains at most 4 pu
ProcessingUnit pu;
//PU-NAME
pu.setName("dummy");
//PU-ID
int idPU = j;
pu.setId(idPU);
//Processor Type
pu.setProcessorType("dummy");
//// PU-cost
//pu.setCost(0);
//PU-ISA
pu.setISA("dummy");
// PU-Frequency (MHz)
pu.setFrequency(0);
// PU-CC4CS
float** |
array = new float*[5]; //TODO: eliminare **?
//Int8
float idCC4CSminint8 = 0;
float idCC4CSmaxint8 = 0;
//Int16
float idCC4CSminint16 = 0;
float idCC4CSmaxint16 = 0;
//Int32
float idCC4CSminint32 = 0;
float idCC4CSmaxint32 = 0;
//Float
float idCC4CSminfloat = 0;
float idCC4CSmaxfloat = 0;
//Tot
float idCC4CSmin = 0;
float idCC4CSmax = 0;
//TODO: ciclo con tutti 0!
array[0] = new float[2];
array[0][0] = idCC4CSminint8;
array[0][1] = idCC4CSmaxint8;
array[1] = new float[2];
array[1][0] = idCC4CSminint16;
array[1][1] = idCC4CSmaxint16;
array[2] = new float[2];
array[2][0] = idCC4CSminint32;
array[2][1] = idCC4CSmaxint32;
array[3] = new float[2];
array[3][0] = idCC4CSminfloat;
array[3][1] = idCC4CSmaxfloat;
array[4] = new float[2];
array[4][0] = idCC4CSmin;
array[4][1] = idCC4CSmax;
pu.setCC4S(array);
// PU-Power (W)
pu.setPower(0);
// PU-MIPS
float idMIPS = 0;
pu.setMIPS(idMIPS);
// PU-I4CS
float idI4CSmin = 0;
pu.setI4CSmin(idI4CSmin);
float idI4CSmax = 0;
pu.setI4CSmax(idI4CSmax);
// PU-Vdd (V)
float idVdd = 0;
pu.setVdd(idVdd);
// PU-Idd (A)
float idIdd = 0;
pu.setIdd(idIdd);
// PU-overheadCS (us)
float idOver = 0;
pu.setOverheadCS(sc_time((int)idOver, SC_US));
vpu.push_back(pu);
}
bb.setProcessor(vpu);
// LOCAL MEMORY
//CODE SIZE
bb.setCodeSize(0);
//DATA SIZE
bb.setDataSize(0);
//eQG
bb.setEqG(0);
// Free Running time
float lmFreeRunningTime = 0;
bb.setFRT(lmFreeRunningTime);
vbb.push_back(bb);
}
return vbb;
}
#endif
#if defined(_TIMING_ENERGY_)
// Fill link data structure VPL from xml file (instancesTL.xml)
vector<PhysicalLink> SystemManager:: generatePhysicalLinkInstances()
{
vector<PhysicalLink> VPL;
PhysicalLink l;
// parsing xml file
xml_document myDoc;
xml_parse_result myResult = myDoc.load_file("./XML/instancesTL.xml");
xml_node instancesPL = myDoc.child("instancesPL");
//link parameters
xml_node_iterator seqLink_it;
for (seqLink_it=instancesPL.begin(); seqLink_it!=instancesPL.end(); ++seqLink_it){
xml_node_iterator link_node_it = seqLink_it->begin();
char* temp;
// Link NAME
string name = link_node_it->child_value();
l.setName(name);
// Link ID
link_node_it++;
temp = (char*) link_node_it->child_value();
unsigned int id = atoi(temp);
l.setId(id);
// Link PHYSICAL WIDTH
link_node_it++;
temp = (char*) link_node_it->child_value();
unsigned int physical_width = atoi(temp);
l.setPhysicalWidth(physical_width);
// Link TCOMM
link_node_it++;
temp = (char*) link_node_it->child_value();
float tc = (float) atof(temp);
sc_time tcomm(tc, SC_MS);
l.setTcomm(tcomm);
// Link TACOMM
link_node_it++;
temp = (char*) link_node_it->child_value();
float tac = (float) atof(temp);
sc_time tacomm(tac, SC_MS);
l.setTAcomm(tacomm);
// Link BANDWIDTH
link_node_it++;
temp = (char*) link_node_it->child_value();
unsigned int bandwidth = atoi(temp);
l.setBandwidth(bandwidth);
// Link a2 (coefficient needed to compute energy of the communication)
link_node_it++;
temp = (char*) link_node_it->child_value();
float a2 = (float) atof(temp);
l.seta2(a2);
// Link a1 (coefficient needed to compute energy of the communication)
link_node_it++;
temp = (char*) link_node_it->child_value();
float a1 = (float) atof(temp);
l.seta1(a1);
VPL.push_back(l);
}
return VPL;
}
#else
vector<PhysicalLink> SystemManager::generatePhysicalLinkInstances()
{
vector<PhysicalLink> VPL;
for (int i = 0; i < NPL; i++){
PhysicalLink pl;
pl.setId(i);
pl.setName("dummy");
pl.physical_width=1; // width of the physical link
pl.tcomm=sc_time(0, SC_MS); // LP: (bandwidth / phisycal_widht = 1/sec=hz (inverto)) ( per 1000) (non sforare i 5 ms)
pl.tacomm=sc_time(0, SC_MS); // LP: tcomm * K (es:K=1)
pl.bandwidth=0; // bandwidth in bit/s
pl.a2=0; // a2 coefficient of energy curve
pl.a1=0; // a1 coefficient of energy curve
VPL.push_back(pl);
}
return VPL;
}
#endif
#if defined(_TIMING_ENERGY_)
// Fill allocationPS data structure from xml file
void SystemManager:: mappingPS()
{
int exp_id = 0;
// parsing xml file
xml_document myDoc;
xml_parse_result myResult = myDoc.load_file(MAPPING_PS_BB);
xml_node mapping = myDoc.child("mapping");
//mapping parameters (process to processor)
xml_node_iterator mapping_it;
for (mapping_it=mapping.begin(); mapping_it!=mapping.end(); ++mapping_it){
xml_node_iterator child_mapping_it = mapping_it->begin();
int processId = child_mapping_it->attribute("PSid").as_int();
//string processorName = child_mapping_it->attribute("PRname").as_string();
string bbName = child_mapping_it->attribute("BBname").as_string();
int bbId = child_mapping_it->attribute("value").as_int();
int processingunitID = child_mapping_it->attribute("PUid").as_int(); //added **************
int partitionID = child_mapping_it->attribute("PTid").as_int(); //added **************
if(processId == exp_id){
allocationPS_BB.push_back(bbId);
exp_id++;
} else {
cout << "XML for allocation is corrupted\n";
exit(11);
}
}
}
#else
void SystemManager::mappingPS(){
for (int j = 0; j<NPS; j++){
int bbId = 0;
allocationPS_BB.push_back(bbId);
}
}
#endif
#if defined(_TIMING_ENERGY_)
// Fill allocationCH_PL data structure from xml file
void SystemManager::mappingCH()
{
int exp_id = 0;
// parsing xml file
xml_document myDoc;
xml_parse_result myResult = myDoc.load_file(MAPPING_LC_PL);
xml_node mapping = myDoc.child("mapping");
//mapping parameters (channel to link)
xml_node_iterator mapping_it;
for (mapping_it=mapping.begin(); mapping_it!=mapping.end(); ++mapping_it){
xml_node_iterator child_mapping_it = mapping_it->begin();
int channelId = child_mapping_it->attribute("CHid").as_int();
string linkName = child_mapping_it->attribute("Lname").as_string();
int linkId = child_mapping_it->attribute("value").as_int();
if(channelId == exp_id){
allocationCH_PL.push_back(linkId);
exp_id++;
} else {
cout << "XML for allocation is corrupted\n";
exit(11);
}
}
}
#else
void SystemManager::mappingCH(){
for (int j = 0; j < NCH; j++){
int linkId = 0;
allocationCH_PL.push_back(linkId);
}
}
#endif
///// OTHER METHODS ////////
// Evaluate the simulated time for the execution of a statement
/*
* for a given processID, returns the simulated time
* (the time needed by processor, for the allocated process, to
* to execute a statement)
*/
sc_time SystemManager:: updateSimulatedTime(int processId)
{
// Id representing process dominant datatype
int dataType = VPS[processId].getDataType();
//*********************VPU WAS CHANGED IN VBB**********************
float CC4Smin = VBB[allocationPS_BB[processId]].getProcessors()[0].getCC4S()[dataType][0]; // Average/min number of clock cycles needed by the PU to execute a C statement
float CC4Smax = VBB[allocationPS_BB[processId]].getProcessors()[0].getCC4S()[dataType][1]; // Average/max number of clock cycles needed by the PU to execute a C statement
// Affinity-based interpolation and round up of CC4CSaff
unsigned int CC4Saff = (unsigned int) ceil(CC4Smin + ((CC4Smax-CC4Smin)*(1-VPS[processId].getAffinityByName(VBB[allocationPS_BB[processId]].getProcessors()[0].getProcessorType()))));
float frequency = VBB[allocationPS_BB[processId]].getProcessors()[0].getFrequency(); // Frequency of the processor (MHz)
sc_time value((CC4Saff/(frequency*1000)), SC_MS); // Average time (ms) needed to execute a C statement
return value;
}
// The computation depends on the value setted for energyComputation (EPI or EPC)
float SystemManager:: updateEstimatedEnergy(int processId)
{
float J4CS;
float P;
if(energyComputation == "EPC") {
// EPC --> J4CS = CC4CSaff * EPC = CC4CSaff * (P/f)
// Id representing process dominant datatype
int dataType = VPS[processId].getDataType();
//I HAVE TO ADD A LOOP IN ORDER TO TAKE THE PARAMETERS OF EACH PROCESSOR (?) **********************
float CC4Smin = VBB[allocationPS_BB[processId]].getProcessors()[0].getCC4S()[dataType][0]; // Average/min number of clock cycles needed by the PU to execute a C statement
//float CC4Smin = VBB[allocationPS_BB[processId]].getCC4S()[dataType][0]; // Average/min number of clock cycles needed by the PU to execute a C statement
//float CC4Smax = VBB[allocationPS_BB[processId]].getCC4S()[dataType][1];
float CC4Smax = VBB[allocationPS_BB[processId]].getProcessors()[0].getCC4S()[dataType][1];// Average/max number of clock cycles needed by the PU to execute a C statement
// Affinity-based interpolation
float CC4Saff = CC4Smin + ((CC4Smax-CC4Smin)*(1-VPS[processId].getAffinityByName(VBB[allocationPS_BB[processId]].getProcessors()[0].getProcessorType())));
if(this->checkSPP(processId)) {
// if the process is on a SPP (HW) --> P = Vdd * Idd (V*A = W)
P = VBB[allocationPS_BB[processId]].getProcessors()[0].getVdd() * VBB[allocationPS_BB[processId]].getProcessors()[0].getIdd();
} else {
// if the process is on a GPP/DSP (SW) --> P (W)
P = VBB[allocationPS_BB[processId]].getProcessors()[0].getPower();
}
// EPC = P/f (W/MHz = uJ)
float EPC = P / VBB[allocationPS_BB[processId]].getProcessors()[0].getFrequency();
J4CS = CC4Saff * EPC; // uJ
} else {
// EPI
if(this->checkSPP(processId)) {
// if the process is on a SPP (HW) --> J4CS = CC4CSaff * P * (1/f)
// Id representing process dominant datatype
int dataType = VPS[processId].getDataType();
float CC4Smin = VBB[allocationPS_BB[processId]].getProcessors()[0].getCC4S()[dataType][0]; // Average/min number of clock cycles needed by the PU to execute a C statement
float CC4Smax = VBB[allocationPS_BB[processId]].getProcessors()[0].getCC4S()[dataType][1]; // Average/max number of clock cycles needed by the PU to execute a C statement
// Affinity-based interpolation
float CC4Saff = CC4Smin + ((CC4Smax-CC4Smin)*(1-VPS[processId].getAffinityByName(VBB[allocationPS_BB[processId]].getProcessors()[0].getProcessorType())));
// P = Vdd * Idd (V*A = W)
P = VBB[allocationPS_BB[processId]].getProcessors()[0].getVdd() * VBB[allocationPS_BB[processId]].getProcessors()[0].getIdd();
J4CS = CC4Saff * (P / VBB[allocationPS_BB[processId]].getProcessors()[0].getFrequency()); // uJ
} else {
// if the process is on a GPP/DSP (SW) --> J4CS = I4CSaff * EPI = I4CSaff * (P/MIPS)
float I4CSmin = VBB[allocationPS_BB[processId]].getProcessors()[0].getI4CSmin(); // Average/min number of assembly instructions to execute a C statement
float I4CSmax = VBB[allocationPS_BB[processId]].getProcessors()[0].getI4CSmax(); // Average/max number of assembly instructions to execute a C statement
// Affinity-based interpolation
float I4CSaff = I4CSmin + ((I4CSmax-I4CSmin)*(1-VPS[processId].getAffinityByName(VBB[allocationPS_BB[processId]].getProcessors()[0].getProcessorType())));
P = VBB[allocationPS_BB[processId]].getProcessors()[0].getPower(); // Watt
// EPI = P/MIPS (uJ/instr)
float EPI = P / VBB[allocationPS_BB[processId]].getProcessors()[0].getMIPS();
J4CS = I4CSaff * EPI; // uJ
}
}
return J4CS;
}
// Increase processTime for each statement
void SystemManager:: increaseSimulatedTime(int processId)
{
VPS[processId].processTime += updateSimulatedTime(processId); // Cumulated sum of the statement execution time
}
// Increase energy for each statement
void SystemManager:: increaseEstimatedEnergy(int processId)
{
VPS[processId].energy += updateEstimatedEnergy(processId); // Cumulated sum of the statement execution energy
}
// Increase processTime for the wait of the timers
void SystemManager::increaseTimer(int processId, sc_time delta)
{
VPS[processId].processTime += delta; // Cumulated sum of the statement execution time
}
// Energy XML Updates
void SystemManager::deleteConcXmlEnergy(){
char* temp;
int Id;
pugi::xml_document myDoc;
pugi::xml_parse_result myResult = myDoc.load_file("./XML/application.xml");
cout << "XML Delete result: " << myResult.description() << endl;
//method 2: use object/node structure
pugi::xml_node instancesPS = myDoc.child("instancesPS");
xml_node processes = instancesPS.child("process");
for(int i = 0; i < NPS; i++){
temp = (char*) processes.child_value("id");
Id = atoi(temp); //id process
xml_node energy = processes.child("energy");
for (pugi::xml_node processorId = energy.child("processorId"); processorId; processorId = processorId.next_sibling()) {
unsigned int processor_id_n = processorId.attribute("id").as_int();//
float process_load_value = processorId.attribute("value").as_float();//
if(allocationPS_BB[Id] == processor_id_n){
energy.remove_child(processorId);
}
}
processes = processes.next_sibling();
}
myDoc.save_file("./XML/application.xml");
cout<<endl;
/////////////////////////////////////
pugi::xml_document myDoc2;
pugi::xml_parse_result myResult2 = myDoc2.load_file("./XML/instancesTL.xml");
cout << "XML result: " << myResult2.description() << endl;
pugi::xml_node instancesBB = myDoc2.child("instancesBB");
xml_node basicBlock = instancesBB.child("basicBlock");
for(int i = 0; i < NBB; i++){
temp = (char*) basicBlock.child_value("id");
Id = atoi(temp); //id process
xml_node energyEst = basicBlock.child("energyEstimation");
for (pugi::xml_node energyTOT = energyEst.child("energyTOT"); energyTOT; energyTOT = energyTOT.next_sibling()) {
unsigned int processor_id_n = energyTOT.attribute("id").as_int();//
float energy_value = energyTOT.attribute("value").as_float();//
if(Id == allocationPS_BB[2]){
energyEst.remove_child(energyTOT);
}
}
basicBlock = basicBlock.next_sibling();
}
cout << "Saving result: " << myDoc2.save_file("./XML/instancesTL.xml") << endl;
cout<<endl;
}
void SystemManager:: updateXmlEnergy()
{
pugi::xml_document myDoc;
pugi::xml_parse_result myResult = myDoc.load_file("./XML/application.xml");
cout << "XML result: " << myResult.description() << endl;
//method 2: use object/node structure
pugi::xml_node instancesPS = myDoc.child("instancesPS");
/////////////////////// ENERGY //////////////////////////////
pugi::xml_node instancesPS2 = myDoc.child("instancesPS");
float sumEnergyTot=0;
for (xml_node_iterator seqProcess_it2=instancesPS2.begin(); seqProcess_it2!=instancesPS2.end(); ++seqProcess_it2){
int Id = atoi(seqProcess_it2->child_value("id"));
if(seqProcess_it2->child("energy")){
pugi::xml_node energy = seqProcess_it2->child("energy");
pugi::xml_node energy_it = energy.append_child("processorId");
energy_it.append_attribute("id").set_value(allocationPS_BB[Id]);
energy_it.append_attribute("value").set_value(VPS[Id].getEnergy());
}else{
pugi::xml_node energy = seqProcess_it2->append_child("energy");
pugi::xml_node energy_it = energy.append_child("processorId");
energy_it.append_attribute("id").set_value(allocationPS_BB[Id]);
energy_it.append_attribute("value").set_value(VPS[Id].getEnergy());
}
sumEnergyTot+=VPS[Id].getEnergy();
}
cout << "Saving result: " << myDoc.save_file("./XML/application.xml") << endl;
myDoc.reset();
cout<<endl;
pugi::xml_document myDoc2;
pugi::xml_parse_result myResult2 = myDoc2.load_file("./XML/instancesTL.xml");
cout << "XML result: " << myResult2.description() << endl;
xml_node instancesBB = myDoc2.child("instancesBB");
for (xml_node_iterator seqBB_it=instancesBB.begin(); seqBB_it!=instancesBB.end(); ++seqBB_it){
int Id = atoi(seqBB_it->child_value("id"));
///////////////////// ENERGY ////////////////////////
if(Id == allocationPS_BB[2]){
if(seqBB_it->child("energyEstimation")){
pugi::xml_node energyEstimation = seqBB_it->child("energyEstimation");
xml_node entot_node = energyEstimation.append_child("energyTOT");
entot_node.append_attribute("id").set_value(allocationPS_BB[2]);
entot_node.append_attribute("value").set_value(sumEnergyTot);
}else{
pugi::xml_node energyEstimation = seqBB_it->append_child("energyEstimation");
xml_node entot_node = energyEstimation.append_child("energyTOT");
entot_node.append_attribute("id").set_value(allocationPS_BB[2]);
entot_node.append_attribute("value").set_value(sumEnergyTot);
}
}
}
cout << "Saving result: " << myDoc2.save_file("./XML/instancesTL.xml") << endl;
myDoc2.reset();
cout<<endl;
}
// Load Metrics
sc_time SystemManager::getFRT(){
return this->FRT;
}
void SystemManager::setFRT(sc_time x){
FRT = x;
}
float* SystemManager:: loadEst(sc_time FRT_n){
for(unsigned i =2; i<VPS.size(); i++){
FRL[i] = (float) ((VPS[i].processTime/VPS[i].profiling)/(FRT_n/VPS[i].profiling)); //
}
return FRL;
}
float* SystemManager:: getFRL(){
return this->FRL;
}
// Load XML Updates
void SystemManager::deleteConcXmlLoad(){
char* temp;
int Id;
pugi::xml_document myDoc;
pugi::xml_parse_result myResult = myDoc.load_file("./XML/application.xml");
cout << "XML Delete result: " << myResult.description() << endl;
//method 2: use object/node structure
pugi::xml_node instancesPS = myDoc.child("instancesPS");
xml_node processes = instancesPS.child("process");
for(int i = 0; i < NPS; i++){
temp = (char*) processes.child_value("id");
Id = atoi(temp); //id process
xml_node load = processes.child("load");
for (pugi::xml_node processorId = load.child("processorId"); processorId; processorId = processorId.next_sibling()) {
unsigned int processor_id_n = processorId.attribute("id").as_int();//
float process_load_value = processorId.attribute("value").as_float();//
if(allocationPS_BB[Id] == processor_id_n){
load.remove_child(processorId);
}
}
/* xml_node WCET = processes.child("WCET");
for (pugi::xml_node processorId = WCET.child("processorId"); processorId; processorId = processorId.next_sibling()) {
WCET.remove_child(processorId);
}
xml_node Period = processes.child("Period");
for (pugi::xml_node processorId = Period.child("processorId"); processorId; processorId = processorId.next_sibling()) {
Period.remove_child(processorId);
}
xml_node Deadline = processes.child("Deadline");
for (pugi::xml_node processorId = Deadline.child("processorId"); processorId; processorId = processorId.next_sibling()) {
Deadline.remove_child(processorId);
} */
processes = processes.next_sibling();
}
myDoc.save_file("./XML/application.xml");
cout<<endl;
pugi::xml_document myDoc2;
pugi::xml_parse_result myResult2 = myDoc2.load_file("./XML/instancesTL.xml");
cout << "XML result: " << myResult2.description() << endl;
pugi::xml_node instancesBB = myDoc2.child("instancesBB");
xml_node basicBlock = instancesBB.child("basicBlock");
for(int i = 0; i < NBB; i++){
temp = (char*) basicBlock.child_value("id");
Id = atoi(temp); //id process
xml_node loadEst = basicBlock.child("loadEstimation");
for (pugi::xml_node loadTOT = loadEst.child("FreeRunningTime"); loadTOT; loadTOT = loadTOT.next_sibling()) {
unsigned int processor_id_n = loadTOT.attribute("id").as_int();//
float energy_value = loadTOT.attribute("value").as_float();//
if(Id == allocationPS_BB[2]){
loadEst.remove_child(loadTOT);
}
}
basicBlock = basicBlock.next_sibling();
}
cout << "Saving result: " << myDoc2.save_file("./XML/instancesTL.xml") << endl;
myDoc2.reset();
cout<<endl;
}
void SystemManager:: updateXmlLoad()
{
pugi::xml_document myDoc;
pugi::xml_parse_result myResult = myDoc.load_file("./XML/application |
.xml");
cout << "XML result: " << myResult.description() << endl;
//method 2: use object/node structure
pugi::xml_node instancesPS = myDoc.child("instancesPS");
for (xml_node_iterator seqProcess_it=instancesPS.begin(); seqProcess_it!=instancesPS.end(); ++seqProcess_it){
int Id = atoi(seqProcess_it->child_value("id"));
///////////////////// LOAD ////////////////////////////
if(seqProcess_it->child("load")){
pugi::xml_node load = seqProcess_it->child("load");
pugi::xml_node load_it = load.append_child("processorId");
load_it.append_attribute("id").set_value(allocationPS_BB[Id]);
load_it.append_attribute("value").set_value(FRL[Id]);
}else{
pugi::xml_node load = seqProcess_it->append_child("load");
pugi::xml_node load_it = load.append_child("processorId");
load_it.append_attribute("id").set_value(allocationPS_BB[Id]);
load_it.append_attribute("value").set_value(FRL[Id]);
}
}
/////////////////////// WCET //////////////////////////////
////method 2: use object/node structure
//pugi::xml_node instancesPS2 = myDoc.child("instancesPS");
//for (pugi::xml_node_iterator seqProcess_it=instancesPS2.begin(); seqProcess_it!=instancesPS2.end(); ++seqProcess_it){
// int Id = atoi(seqProcess_it->child_value("id"));
//
// if(seqProcess_it->child("WCET")){
// pugi::xml_node comunication = seqProcess_it->child("WCET");
// for (int i=0; i<NPS; i++){
// if(i!=Id){
// pugi::xml_node wcet_it = comunication.append_child("processorId");
// double wcet_task = (VPS[Id].processTime.to_seconds());
// wcet_it.append_attribute("id").set_value(i);
// wcet_it.append_attribute("value").set_value((wcet_task/VPS[Id].profiling)*1000000.0);
// }
// }
// }else{
// pugi::xml_node WCET = seqProcess_it->append_child("WCET");
// for (int i=0; i<VPU.size(); i++){
// if(i!=Id){
// pugi::xml_node wcet_it = WCET.append_child("processorId");
// double wcet_task = (VPS[Id].processTime.to_seconds());
// wcet_it.append_attribute("id").set_value(i);
// wcet_it.append_attribute("value").set_value((wcet_task/VPS[Id].profiling)*1000000.0);
// }
// }
// }
//}
/////////////////////// PERIOD //////////////////////////////
//pugi::xml_node instancesPS3 = myDoc.child("instancesPS");
//for (xml_node_iterator seqLink_it=instancesPS3.begin(); seqLink_it!=instancesPS3.end(); ++seqLink_it){
// int Id = atoi(seqLink_it->child_value("id"));
//
// if(seqLink_it->child("Period")){
// pugi::xml_node Period = seqLink_it->child("Period");
// for (int i=0; i<NPS; i++){
// if(i!=Id){
// pugi::xml_node period_it = Period.append_child("processorId");
// period_it.append_attribute("id").set_value(i);
// double period_value = (FRT.to_seconds());
// period_it.append_attribute("value").set_value((period_value/VPS[Id].profiling)*1000000.0);
// }
// }
// }else{
// pugi::xml_node Period = seqLink_it->append_child("Period");
// for (int i=0; i<NPS; i++){
// if(i!=Id){
// pugi::xml_node period_it = Period.append_child("processorId");
// period_it.append_attribute("id").set_value(i);
// double period_value = (FRT.to_seconds());
// period_it.append_attribute("value").set_value((period_value/VPS[Id].profiling)*1000000.0);
// }
// }
// }
//}
///////////////////////// DEADLINE //////////////////////////////
// pugi::xml_node instancesPS4 = myDoc.child("instancesPS");
//for (xml_node_iterator seqLink_it=instancesPS4.begin(); seqLink_it!=instancesPS4.end(); ++seqLink_it){
// int Id = atoi(seqLink_it->child_value("id"));
// if(seqLink_it->child("Deadline")){
// pugi::xml_node Deadline = seqLink_it->child("Deadline");
// for (int i=0; i<NPS; i++){
// if(i!=Id){
// pugi::xml_node dead_it = Deadline.append_child("processorId");
// dead_it.append_attribute("id").set_value(i);
// double deadline_value = (FRT.to_seconds());
// double dead_tot = (deadline_value/VPS[Id].profiling)*1000000.0;
// cout<<"VPS["<<Id<<"].profiling --> "<<VPS[Id].profiling<<endl;
// dead_it.append_attribute("value").set_value(dead_tot);
// }
// }
// }else{
// pugi::xml_node Deadline = seqLink_it->append_child("Deadline");
// for (int i=0; i<NPS; i++){
// if(i!=Id){
// pugi::xml_node dead_it = Deadline.append_child("processorId");
// dead_it.append_attribute("id").set_value(i);
// double deadline_value = (FRT.to_seconds());
// double dead_tot = (deadline_value/VPS[Id].profiling)*1000000.0;
// dead_it.append_attribute("value").set_value(dead_tot);
// }
// }
// }
//}
cout << "Saving result: " << myDoc.save_file("./XML/application.xml") << endl;
myDoc.reset();
cout<<endl;
/* pugi::xml_document myDoc2;
pugi::xml_parse_result myResult2 = myDoc2.load_file("./XML/instancesTL.xml");
cout << "XML result: " << myResult2.description() << endl;
xml_node instancesBB = myDoc2.child("instancesBB");
for (xml_node_iterator seqBB_it=instancesBB.begin(); seqBB_it!=instancesBB.end(); ++seqBB_it){
int Id = atoi(seqBB_it->child_value("id"));
///////////////////// LOAD ////////////////////////////
if(seqBB_it->child("loadEstimation")){
pugi::xml_node loadEstimation = seqBB_it->child("loadEstimation");
xml_node frl_node = loadEstimation.child("FreeRunningTime");
if(!(allocationPS_BB[Id] != Id))
{
sc_time local_frt = FRT;
//frl_node.attribute("value")=(local_frt.to_double()*1000); //another solution for the number conversion
frl_node.attribute("value")=(local_frt.to_seconds()*1000);
}
}else{
pugi::xml_node loadEstimation = seqBB_it->append_child("loadEstimation");
xml_node frl_node = loadEstimation.append_child("FreeRunningTime");
if(allocationPS_BB[Id] == Id)
{
sc_time local_frt = FRT;
//frl_node.attribute("value")=(local_frt.to_double()*1000); //another solution for the number conversion
frl_node.attribute("value")=(local_frt.to_seconds()*1000);
}
}
}
cout << "Saving result: " << myDoc2.save_file("./XML/instancesTL.xml") << endl;
myDoc2.reset();
cout<<endl; */
///////////////////////////////////////////////////
pugi::xml_document myDoc2;
pugi::xml_parse_result myResult2 = myDoc2.load_file("./XML/instancesTL.xml");
cout << "XML result: " << myResult2.description() << endl;
xml_node instancesBB = myDoc2.child("instancesBB");
for (xml_node_iterator seqBB_it=instancesBB.begin(); seqBB_it!=instancesBB.end(); ++seqBB_it){
int Id = atoi(seqBB_it->child_value("id"));
///////////////////// ENERGY ////////////////////////
if(Id == allocationPS_BB[2]){
if(seqBB_it->child("loadEstimation")){
pugi::xml_node energyEstimation = seqBB_it->child("loadEstimation");
xml_node entot_node = energyEstimation.append_child("FreeRunningTime");
entot_node.append_attribute("id").set_value(allocationPS_BB[2]);
sc_time local_frt = FRT;
entot_node.append_attribute("value").set_value(local_frt.to_seconds()*1000);
}else{
pugi::xml_node energyEstimation = seqBB_it->append_child("energyEstimation");
xml_node entot_node = energyEstimation.append_child("energyTOT");
entot_node.append_attribute("id").set_value(allocationPS_BB[2]);
sc_time local_frt = FRT;
entot_node.append_attribute("value").set_value(local_frt.to_seconds()*1000);
}
}
}
cout << "Saving result: " << myDoc2.save_file("./XML/instancesTL.xml") << endl;
myDoc2.reset();
cout<<endl;
}
/********************************************************************************
*** EOF ***
********************************************************************************/
|
/****************************************************************************
*
* Copyright (c) 2015, Cadence Design Systems. All Rights Reserved.
*
* This file contains confidential information that may not be
* distributed under any circumstances without the written permision
* of Cadence Design Systems.
*
***************************************************************************/
#ifndef _DUT_CYCSIM_INCLUDED_
#define _DUT_CYCSIM_INCLUDED_
#include "systemc.h"
#include "cynthhl.h"
SC_MODULE(dut_cycsim)
{
// Port declarations.
sc_in< bool > clk;
sc_in< bool > rst;
sc_out< bool > din_1_busy;
sc_in< bool > din_1_vld;
sc_in< sc_uint< 8 > > din_1_data;
sc_out< bool > din_2_busy;
sc_in< bool > din_2_vld;
sc_in< sc_uint< 8 > > din_2_data;
sc_in< bool > dout_busy;
sc_out< bool > dout_vld;
sc_out< sc_uint< 9 > > dout_data;
dut_cycsim( sc_module_name in_name=sc_module_name(sc_gen_unique_name(" dut") ) )
: sc_module(in_name)
,clk("clk")
,rst("rst")
,din_1_busy("din_1_busy")
,din_1_vld("din_1_vld")
,din_1_data("din_1_data")
,din_2_busy("din_2_busy")
,din_2_vld("din_2_vld")
,din_2_data("din_2_data")
,dout_busy("dout_busy")
,dout_vld("dout_vld")
,dout_data("dout_data")
{
};
};
#endif
|
#include <memory>
#include <systemc.h>
#include "Vtop.h"
#include "bfm.h"
SC_MODULE(sc_top) {
sc_clock clk;
sc_signal<bool> reset;
sc_signal<bool> cs;
sc_signal<bool> rw;
sc_signal<bool> ready;
#ifdef VERILATOR
sc_signal<uint32_t> addr;
sc_signal<uint32_t> data_in;
sc_signal<uint32_t> data_out;
#else
sc_signal<sc_uint<16>> addr;
sc_signal<sc_uint<32>> data_in;
sc_signal<sc_uint<32>> data_out;
#endif
Vtop *u_top;
bfm *u_bfm;
SC_CTOR(sc_top) :
clk("clk", 10, SC_NS, 0.5, 5, SC_NS, true),
reset("reset"), cs("cs"), rw("rw"), addr("addr"), ready("ready"), data_in("data_in"), data_out("data_out") {
#ifdef VERILATOR
u_top = new Vtop{"top"};
#else
u_top = new Vtop{"top", "Vtop", 0, NULL};
#endif
u_top->clk(clk);
u_top->reset(reset);
u_top->cs(cs);
u_top->rw(rw);
u_top->addr(addr);
u_top->data_in(data_in);
u_top->ready(ready);
u_top->data_out(data_out);
u_bfm = new bfm("bfm");
u_bfm->clk(clk);
u_bfm->reset(reset);
u_bfm->cs(cs);
u_bfm->rw(rw);
u_bfm->addr(addr);
u_bfm->data_in(data_out);
u_bfm->ready(ready);
u_bfm->data_out(data_in);
}
~sc_top() {
#ifdef VERILATOR
u_top->final();
#endif
delete u_top;
delete u_bfm;
}
};
|
/**********************************************************************
Filename: sc_fir_pe.h
Purpose : Verilated PE of Systolic FIR filter
Author : goodkook@gmail.com
History : Mar. 2024, First release
***********************************************************************/
#ifndef _V_FIR_PE_H_
#define _V_FIR_PE_H_
#include <systemc.h>
#include "./obj_dir/Vfir_pe.h"
SC_MODULE(V_fir_pe)
{
sc_in<bool> clk;
sc_in<bool> Rdy;
sc_out<bool> Vld;
sc_in<sc_uint<6> > Cin;
sc_in<sc_uint<4> > Xin;
sc_out<sc_uint<4> > Xout;
sc_in<sc_uint<4> > Yin;
sc_out<sc_uint<4> > Yout;
Vfir_pe* u_Vfir_pe;
sc_signal<uint32_t> _Cin;
sc_signal<uint32_t> _Xin;
sc_signal<uint32_t> _Xout;
sc_signal<uint32_t> _Yin;
sc_signal<uint32_t> _Yout;
sc_signal<bool> _Rdy;
sc_signal<bool> _Vld;
void pe_method(void)
{
_Cin = (uint32_t)Cin.read();
_Xin = (uint32_t)Xin.read();
_Yin = (uint32_t)Yin.read();
_Rdy = Rdy.read();
Xout.write(sc_uint<4>(_Xout));
Yout.write(sc_uint<4>(_Yout));
Vld.write(_Vld);
}
SC_CTOR(V_fir_pe):
clk("clk"),
Rdy("Rdy"), _Rdy("_Rdy"),
Vld("Vld"), _Vld("_Vld"),
Cin("Cin"), _Cin("_Cin"),
Xin("Xin"), _Xin("_Xin"),
Xout("Xout"), _Xout("_Xout"),
Yin("Yin"), _Yin("_Yin"),
Yout("Yout"), _Yout("_Yout")
{
SC_METHOD(pe_method);
sensitive << clk << Cin << Xin << Yin << Rdy;
// Instantiate Verilated PE
u_Vfir_pe = new Vfir_pe("u_Vfir_pe");
u_Vfir_pe->clk(clk);
u_Vfir_pe->Cin(_Cin);
u_Vfir_pe->Xin(_Xin);
u_Vfir_pe->Xout(_Xout);
u_Vfir_pe->Yin(_Yin);
u_Vfir_pe->Yout(_Yout);
u_Vfir_pe->Rdy(_Rdy);
u_Vfir_pe->Vld(_Vld);
}
~V_fir_pe(void)
{
}
};
#endif
|
// Generated by stratus_hls 17.20-p100 (88533.190925)
// Mon Nov 16 23:44:47 2020
// from dut.cc
#ifndef CYNTH_PART_dut_dut_rtl_h
#define CYNTH_PART_dut_dut_rtl_h
#include "systemc.h"
/* Include declarations of instantiated parts. */
/* Declaration of the synthesized module. */
struct dut : public sc_module {
sc_in<bool > clk;
sc_in<bool > rst;
sc_out<bool > din_busy;
sc_in<bool > din_vld;
sc_in<sc_uint<8> > din_data;
sc_in<bool > dout_busy;
sc_out<bool > dout_vld;
sc_out<sc_uint<11> > dout_data;
dut( sc_module_name name );
SC_HAS_PROCESS(dut);
sc_signal<bool > dout_m_req_m_prev_trig_req;
sc_signal<sc_uint<1> > dut_Xor_1Ux1U_1U_4_9_out1;
sc_signal<bool > dout_m_unacked_req;
sc_signal<sc_uint<1> > dut_Or_1Ux1U_1U_4_10_out1;
sc_signal<sc_uint<1> > dut_N_Muxb_1_2_0_4_1_out1;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_5_out1;
sc_signal<sc_uint<1> > dut_Not_1U_1U_4_4_out1;
sc_signal<sc_uint<1> > dut_Or_1Ux1U_1U_4_2_out1;
sc_signal<bool > din_m_unvalidated_req;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_3_out1;
sc_signal<sc_uint<2> > global_state_next;
sc_signal<sc_uint<1> > dut_Not_1U_1U_4_6_out1;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_11_out1;
sc_signal<sc_uint<1> > dut_Not_1U_1U_4_12_out1;
sc_signal<bool > dout_m_req_m_trig_req;
sc_signal<sc_uint<2> > global_state;
sc_signal<bool > din_m_busy_req_0;
sc_signal<sc_uint<11> > dut_Mul_8Ux3U_11U_4_13_out1;
sc_signal<sc_uint<1> > stall0;
void drive_dout_data();
void drive_din_m_busy_req_0();
void drive_dout_m_req_m_trig_req();
void drive_stall0();
void dut_Mul_8Ux3U_11U_4_13();
void drive_global_state();
void drive_global_state_next();
void drive_din_busy();
void dut_Or_1Ux1U_1U_4_2();
void dut_And_1Ux1U_1U_4_3();
void dut_Not_1U_1U_4_4();
void dut_And_1Ux1U_1U_4_5();
void dut_Not_1U_1U_4_6();
void drive_din_m_unvalidated_req();
void dut_N_Muxb_1_2_0_4_1();
void drive_dout_vld();
void dut_Or_1Ux1U_1U_4_10();
void drive_dout_m_unacked_req();
void dut_And_1Ux1U_1U_4_11();
void dut_Xor_1Ux1U_1U_4_9();
void drive_dout_m_req_m_prev_trig_req();
void dut_Not_1U_1U_4_12();
};
#endif
|
// Generated by stratus_hls 17.20-p100 (88533.190925)
// Tue Nov 17 14:53:19 2020
// from dut.cc
#ifndef CYNTH_PART_dut_dut_rtl_h
#define CYNTH_PART_dut_dut_rtl_h
#include "systemc.h"
/* Include declarations of instantiated parts. */
/* Declaration of the synthesized module. */
struct dut : public sc_module {
sc_in<bool > clk;
sc_in<bool > rst;
sc_out<bool > din_busy;
sc_in<bool > din_vld;
sc_in<sc_uint<8> > din_data;
sc_in<bool > dout_busy;
sc_out<bool > dout_vld;
sc_out<sc_uint<11> > dout_data;
sc_out<bool > mem_WE0;
sc_out<sc_uint<8> > mem_DIN0;
sc_in<sc_uint<8> > mem_DOUT0;
sc_out<sc_uint<6> > mem_A0;
sc_out<bool > mem_REQ0;
dut( sc_module_name name );
SC_HAS_PROCESS(dut);
sc_signal<bool > dout_m_req_m_prev_trig_req;
sc_signal<sc_uint<1> > dut_Xor_1Ux1U_1U_4_9_out1;
sc_signal<bool > dout_m_unacked_req;
sc_signal<sc_uint<1> > dut_Or_1Ux1U_1U_4_10_out1;
sc_signal<sc_uint<1> > dut_N_Muxb_1_2_0_4_1_out1;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_5_out1;
sc_signal<sc_uint<1> > dut_Not_1U_1U_4_4_out1;
sc_signal<sc_uint<1> > dut_Or_1Ux1U_1U_4_2_out1;
sc_signal<bool > din_m_unvalidated_req;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_3_out1;
sc_signal<sc_uint<3> > global_state_next;
sc_signal<sc_int<7> > dut_Add_7Sx2S_8S_4_13_in2;
sc_signal<sc_uint<1> > gs_ctrl0;
sc_signal<sc_uint<6> > dut_Add_6Ux1U_6U_4_15_out1;
sc_signal<sc_uint<1> > dut_Not_1U_1U_4_6_out1;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_11_out1;
sc_signal<sc_uint<1> > dut_Not_1U_1U_4_12_out1;
sc_signal<bool > dout_m_req_m_trig_req;
sc_signal<sc_uint<1> > dut_LessThan_8Sx8S_1U_4_14_out1;
sc_signal<bool > din_m_busy_req_0;
sc_signal<sc_uint<9> > dut_Add_8Ux8U_9U_4_16_out1;
sc_signal<sc_int<8> > dut_Add_7Sx2S_8S_4_13_out1;
sc_signal<sc_int<10> > dout_data_slice;
sc_signal<sc_uint<1> > stall0;
sc_signal<bool > mem_WE0_reg;
sc_signal<sc_uint<8> > s_reg_7;
sc_signal<sc_uint<3> > global_state;
sc_signal<bool > mem_REQ0_reg;
void drive_mem_REQ0();
void drive_mem_A0();
void drive_mem_DIN0();
void drive_mem_WE0();
void drive_dout_data();
void drive_din_m_busy_req_0();
void drive_dout_m_req_m_trig_req();
void drive_stall0();
void drive_mem_WE0_reg();
void drive_mem_REQ0_reg();
void drive_s_reg_7();
void drive_dut_Add_7Sx2S_8S_4_13_in2();
void dut_Add_7Sx2S_8S_4_13();
void dut_LessThan_8Sx8S_1U_4_14();
void dut_Add_6Ux1U_6U_4_15();
void dut_Add_8Ux8U_9U_4_16();
void drive_global_state();
void drive_global_state_next();
void drive_gs_ctrl0();
void drive_din_busy();
void dut_Or_1Ux1U_1U_4_2();
void dut_And_1Ux1U_1U_4_3();
void dut_Not_1U_1U_4_4();
void dut_And_1Ux1U_1U_4_5();
void dut_Not_1U_1U_4_6();
void drive_din_m_unvalidated_req();
void dut_N_Muxb_1_2_0_4_1();
void drive_dout_vld();
void dut_Or_1Ux1U_1U_4_10();
void drive_dout_m_unacked_req();
void dut_And_1Ux1U_1U_4_11();
void dut_Xor_1Ux1U_1U_4_9();
void drive_dout_m_req_m_prev_trig_req();
void dut_Not_1U_1U_4_12();
void thread_12();
};
#endif
|
#ifndef TESTBENCH_
#define TESTBENCH_
#include <systemc.h>
SC_MODULE (tbreg){
//l'horloge
sc_in <bool> clk;
sc_out < sc_uint<11> > din;
sc_in < sc_uint<15> > coded_dout;
sc_out < sc_uint<15> > coded_din;
sc_in < sc_uint<11> > dout;
//hand shake signals
sc_out < bool > din_vld;
sc_in < bool > din_rdy;
sc_in < bool > codedout_vld;
sc_out < bool > codedout_rdy;
sc_out < bool > codedin_vld;
sc_in < bool > codedin_rdy;
sc_in < bool > dout_vld;
sc_out < bool > dout_rdy;
void send();
void receive();
SC_CTOR(tbreg){
SC_CTHREAD(send,clk);
SC_CTHREAD(receive,clk);
sensitive << clk.pos();
}
};
#endif
|
#ifndef NEURON_H
#define NEURON_H
#include "systemc.h"
SC_MODULE(Neuron) {
sc_in<float> input1, input2;
sc_out<float> output;
float w1, w2, b, y;
float output_temp;
void neuron();
SC_CTOR(Neuron) {
SC_METHOD(neuron);
sensitive << input1 << input2;
}
};
#endif |
#include <systemc.h>
#ifndef ACC_H
#define ACC_H
//#define __SYNTHESIS__
//#define SYSC_ACC_DEBUG
//#define SYSC_ACC_DEBUG2
#ifndef __SYNTHESIS__
#define DWAIT(x) wait(x)
#else
#define DWAIT(x)
#endif
#define ACCNAME SA_INT8_V1_0
#define ACC_DTYPE sc_int
#define ACC_C_DTYPE int
#define MAX 2147483647
#define MIN -2147483648
#define POS 1073741824
#define NEG -1073741823
#define DIVMAX 2147483648
#define MAX8 127
#define MIN8 -128
typedef struct _DATA{
ACC_DTYPE<32> data;
bool tlast;
inline friend ostream& operator << (ostream& os, const _DATA &v){
cout << "data: " << v.data << " tlast: " << v.tlast;
return os;
}
} DATA;
typedef struct _HDATA{
bool rhs_take;
bool lhs_take;
sc_uint<8> rhs_count;
sc_uint<8> lhs_count;
sc_uint<16> dst_addr;
} HDATA;
typedef struct _ADATA{
ACC_DTYPE<32> d2;
ACC_DTYPE<32> d3;
ACC_DTYPE<32> d4;
ACC_DTYPE<32> d5;
ACC_DTYPE<32> d6;
ACC_DTYPE<32> d7;
ACC_DTYPE<32> d8;
ACC_DTYPE<32> d9;
ACC_DTYPE<32> d10;
ACC_DTYPE<32> d11;
ACC_DTYPE<32> d12;
ACC_DTYPE<32> d13;
ACC_DTYPE<32> d14;
ACC_DTYPE<32> d15;
ACC_DTYPE<32> d16;
ACC_DTYPE<32> d17;
inline friend ostream& operator << (ostream& os, const _ADATA &v){
return os;
}
} ADATA;
SC_MODULE(ACCNAME) {
//debug vars
bool print_po = false;
bool print_wo = false;
int simplecounter=0;
ACC_DTYPE<14> depth;
sc_in<bool> clock;
sc_in <bool> reset;
sc_fifo_in<DATA> din1;
sc_fifo_in<DATA> din2;
sc_fifo_in<DATA> din3;
sc_fifo_in<DATA> din4;
sc_fifo_out<DATA> dout1;
sc_fifo_out<DATA> dout2;
sc_fifo_out<DATA> dout3;
sc_fifo_out<DATA> dout4;
sc_signal<bool> read_inputs;
sc_signal<bool> rtake;
sc_signal<bool> ltake;
sc_signal<int> llen;
sc_signal<int> rlen;
sc_signal<int> lhs_block_max;
sc_signal<int> rhs_block_max;
#ifndef __SYNTHESIS__
sc_signal<bool,SC_MANY_WRITERS> d_in1;
sc_signal<bool,SC_MANY_WRITERS> d_in2;
sc_signal<bool,SC_MANY_WRITERS> d_in3;
sc_signal<bool,SC_MANY_WRITERS> d_in4;
sc_signal<bool,SC_MANY_WRITERS> schedule;
sc_signal<bool,SC_MANY_WRITERS> out_check;
sc_signal<bool,SC_MANY_WRITERS> gemm_unit_1_ready;
sc_signal<bool,SC_MANY_WRITERS> write1;
sc_signal<bool,SC_MANY_WRITERS> arrange1;
#else
sc_signal<bool> d_in1;
sc_signal<bool> d_in2;
sc_signal<bool> d_in3;
sc_signal<bool> d_in4;
sc_signal<bool> schedule;
sc_signal<bool> out_check;
sc_signal<bool> gemm_unit_1_ready;
sc_signal<bool> write1;
sc_signal<bool> arrange1;
#endif
sc_signal<int> gemm_unit_1_l_pointer;
sc_signal<bool> gemm_unit_1_iwuse;
ACC_DTYPE<32> g1 [256];
ACC_DTYPE<8> r1 [256];
//GEMM 1 Inputs
ACC_DTYPE<32> lhsdata1a[4096];
ACC_DTYPE<32> lhsdata2a[4096];
ACC_DTYPE<32> lhsdata3a[4096];
ACC_DTYPE<32> lhsdata4a[4096];
//Global Weights
ACC_DTYPE<32> rhsdata1[8192];
ACC_DTYPE<32> rhsdata2[8192];
ACC_DTYPE<32> rhsdata3[8192];
ACC_DTYPE<32> rhsdata4[8192];
// //new sums bram
// ACC_DTYPE<32> lhs_sum1[512];
// ACC_DTYPE<32> lhs_sum2[512];
// ACC_DTYPE<32> lhs_sum3[512];
// ACC_DTYPE<32> lhs_sum4[512];
//
// ACC_DTYPE<32> rhs_sum1[512];
// ACC_DTYPE<32> rhs_sum2[512];
// ACC_DTYPE<32> rhs_sum3[512];
// ACC_DTYPE<32> rhs_sum4[512];
//
// //crf & crx
// ACC_DTYPE<32> crf1[512];
// ACC_DTYPE<32> crf2[512];
// ACC_DTYPE<32> crf3[512];
// ACC_DTYPE<32> crf4[512];
// ACC_DTYPE<32> crx[512];
//new sums bram
ACC_DTYPE<32> lhs_sum1[1024];
ACC_DTYPE<32> lhs_sum2[1024];
ACC_DTYPE<32> lhs_sum3[1024];
ACC_DTYPE<32> lhs_sum4[1024];
ACC_DTYPE<32> rhs_sum1[1024];
ACC_DTYPE<32> rhs_sum2[1024];
ACC_DTYPE<32> rhs_sum3[1024];
ACC_DTYPE<32> rhs_sum4[1024];
//crf & crx
ACC_DTYPE<32> crf1[1024];
ACC_DTYPE<32> crf2[1024];
ACC_DTYPE<32> crf3[1024];
ACC_DTYPE<32> crf4[1024];
ACC_DTYPE<32> crx[1024];
int ra=0;
sc_fifo<int> WRQ1;
sc_fifo<int> WRQ2;
sc_fifo<int> WRQ3;
sc_fifo<char> sIs1;
sc_fifo<char> sIs2;
sc_fifo<char> sIs3;
sc_fifo<char> sIs4;
sc_fifo<char> sIs5;
sc_fifo<char> sIs6;
sc_fifo<char> sIs7;
sc_fifo<char> sIs8;
sc_fifo<char> sIs9;
sc_fifo<char> sIs10;
sc_fifo<char> sIs11;
sc_fifo<char> sIs12;
sc_fifo<char> sIs13;
sc_fifo<char> sIs14;
sc_fifo<char> sIs15;
sc_fifo<char> sIs16;
sc_fifo<char> sWs1;
sc_fifo<char> sWs2;
sc_fifo<char> sWs3;
sc_fifo<char> sWs4;
sc_fifo<char> sWs5;
sc_fifo<char> sWs6;
sc_fifo<char> sWs7;
sc_fifo<char> sWs8;
sc_fifo<char> sWs9;
sc_fifo<char> sWs10;
sc_fifo<char> sWs11;
sc_fifo<char> sWs12;
sc_fifo<char> sWs13;
sc_fifo<char> sWs14;
sc_fifo<char> sWs15;
sc_fifo<char> sWs16;
sc_signal<int> w1S;
sc_signal<int> w2S;
sc_signal<int> w3S;
sc_signal<int> w4S;
#ifndef __SYNTHESIS__
int weight_max_index=0;
int input_max_index=0;
int local_weight_max_index=0;
int g1_macs=0;
int g2_macs=0;
int g3_macs=0;
int g4_macs=0;
int g1_out_count=0;
int g2_out_count=0;
int g3_out_count=0;
int g4_out_count=0;
#endif
sc_out<int> inS;
sc_out<int> read_cycle_count;
sc_out<int> process_cycle_count;
sc_out<int> gemm_1_idle;
sc_out<int> gemm_2_idle;
sc_out<int> gemm_3_idle;
sc_out<int> gemm_4_idle;
sc_out<int> gemm_1_write;
sc_out<int> gemm_2_write;
sc_out<int> gemm_3_write;
sc_out<int> gemm_4_write;
sc_out<int> gemm_1;
sc_out<int> gemm_2;
sc_out<int> gemm_3;
sc_out<int> gemm_4;
sc_out<int> wstall_1;
sc_out<int> wstall_2;
sc_out<int> wstall_3;
sc_out<int> wstall_4;
sc_out<int> rmax;
sc_out<int> lmax;
sc_out<int> outS;
sc_out<int> w1SS;
sc_out<int> w2SS;
sc_out<int> w3SS;
sc_out<int> w4SS;
sc_out<int> schS;
sc_out<int> p1S;
void Input_Handler();
void Output_Handler();
void Worker1();
void Data_In1();
void Data_In2();
void Data_In3();
void Data_In4();
void Tracker();
void Scheduler();
void Post1();
void schedule_gemm_unit(int, int, int, int, int,int,int);
int SHR(int,int);
void Read_Cycle_Counter();
void Process_Cycle_Counter();
void Writer_Cycle_Counter();
SC_HAS_PROCESS(ACCNAME);
// Parameters for the DUT
ACCNAME(sc_module_name name_) :sc_module(name_),WRQ1(512),sIs1(2048),sIs2(2048),sIs3(2048),sIs4(2048),sIs5(2048),sIs6(2048),sIs7(2048),sIs8(2048),
sIs9(2048),sIs10(2048),sIs11(2048),sIs12(2048),sIs13(2048),sIs14(2048),sIs15(2048),sIs16(2048),
WRQ2(512),sWs1(2048),sWs2(2048),sWs3(2048),sWs4(2048),sWs5(2048),sWs6(2048),sWs7(2048),sWs8(2048),
sWs9(2048),sWs10(2048),sWs11(2048),sWs12(2048),sWs13(2048),sWs14(2048),sWs15(2048),sWs16(2048),WRQ3(512){
SC_CTHREAD(Input_Handler,clock.pos());
reset_signal_is(reset,true);
SC_CTHREAD(Worker1,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Output_Handler,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Data_In1,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Data_In2,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Data_In3,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Data_In4,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Scheduler,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Post1,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Read_Cycle_Counter,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Process_Cycle_Counter,clock);
reset_signal_is(reset,true);
SC_CTHREAD(Writer_Cycle_Counter,clock);
reset_signal_is(reset,true);
#pragma HLS RESOURCE variable=din1 core=AXI4Stream metadata="-bus_bundle S_AXIS_DATA1" port_map={{din1_0 TDATA} {din1_1 TLAST}}
#pragma HLS RESOURCE variable=din2 core=AXI4Stream metadata="-bus_bundle S_AXIS_DATA2" port_map={{din2_0 TDATA} {din2_1 TLAST}}
#pragma HLS RESOURCE variable=din3 core=AXI4Stream metadata="-bus_bundle S_AXIS_DATA3" port_map={{din3_0 TDATA} {din3_1 TLAST}}
#pragma HLS RESOURCE variable=din4 core=AXI4Stream metadata="-bus_bundle S_AXIS_DATA4" port_map={{din4_0 TDATA} {din4_1 TLAST}}
#pragma HLS RESOURCE variable=dout1 core=AXI4Stream metadata="-bus_bundle M_AXIS_DATA1" port_map={{dout1_0 TDATA} {dout1_1 TLAST}}
#pragma HLS RESOURCE variable=dout2 core=AXI4Stream metadata="-bus_bundle M_AXIS_DATA2" port_map={{dout2_0 TDATA} {dout2_1 TLAST}}
#pragma HLS RESOURCE variable=dout3 core=AXI4Stream metadata="-bus_bundle M_AXIS_DATA3" port_map={{dout3_0 TDATA} {dout3_1 TLAST}}
#pragma HLS RESOURCE variable=dout4 core=AXI4Stream metadata="-bus_bundle M_AXIS_DATA4" port_map={{dout4_0 TDATA} {dout4_1 TLAST}}
#pragma HLS array_partition variable=g1 complete dim=0
#pragma HLS RESET variable=reset
}
};
#endif /* ACC_H */
|
/**
#define meta ...
prInt32f("%s\n", meta);
**/
/*
All rights reserved to Alireza Poshtkohi (c) 1999-2023.
Email: arp@poshtkohi.info
Website: http://www.poshtkohi.info
*/
#ifndef __s6_h__
#define __s6_h__
#include <systemc.h>
SC_MODULE(s6)
{
sc_in<sc_uint<6> > stage1_input;
sc_out<sc_uint<4> > stage1_output;
void s6_box();
SC_CTOR(s6)
{
SC_METHOD(s6_box);
sensitive << stage1_input;
}
};
#endif
|
/**********************************************************************
Filename: sc_fir8_tb.h
Purpose : Testbench of 8-Tab Systolic FIR filter
Author : goodkook@gmail.com
History : Mar. 2024, First release
***********************************************************************/
#ifndef _SC_FIR8_TB_H_
#define _SC_FIR8_TB_H_
#include <systemc.h>
#include "sc_fir8.h"
SC_MODULE(sc_fir8_tb)
{
sc_clock clk;
sc_signal<sc_uint<8> > Xin;
sc_signal<sc_uint<8> > Xout;
sc_signal<sc_uint<16> > Yin;
sc_signal<sc_uint<16> > Yout;
#ifdef EMULATED
sc_signal<sc_uint<8> > E_Xout;
sc_signal<sc_uint<16> > E_Yout;
#endif
sc_fir8* u_sc_fir8;
// Test utilities
void Test_Gen();
void Test_Mon();
sc_uint<8> x[F_SAMPLE]; // Time seq. input
sc_uint<16> y[F_SAMPLE]; // Filter output
#ifdef VCD_TRACE_FIR8_TB
sc_trace_file* fp; // VCD file
#endif
SC_CTOR(sc_fir8_tb):
clk("clk", 100, SC_NS, 0.5, 0.0, SC_NS, false),
Xin("Xin"),
Xout("Xout"),
Yin("Yin"),
Yout("Yout")
{
SC_THREAD(Test_Gen);
sensitive << clk;
SC_THREAD(Test_Mon);
sensitive << clk;
// Instaltiate FIR8
u_sc_fir8 = new sc_fir8("u_sc_fir8");
u_sc_fir8->clk(clk);
u_sc_fir8->Xin(Xin);
u_sc_fir8->Xout(Xout);
u_sc_fir8->Yin(Yin);
u_sc_fir8->Yout(Yout);
#ifdef EMULATED
u_sc_fir8->E_Xout(E_Xout);
u_sc_fir8->E_Yout(E_Yout);
#endif
#ifdef VCD_TRACE_FIR8_TB
// WAVE
fp = sc_create_vcd_trace_file("sc_fir8_tb");
fp->set_time_unit(100, SC_PS); // resolution (trace) ps
sc_trace(fp, clk, "clk");
sc_trace(fp, Xin, "Xin");
sc_trace(fp, Xout, "Xout");
sc_trace(fp, Yin, "Yin");
sc_trace(fp, Yout, "Yout");
#endif
}
~sc_fir8_tb(void)
{
}
};
#endif |
/*******************************************************************************
* mux_in.cpp -- Copyright 2019 (c) Glenn Ramalho - RFIDo Design
*******************************************************************************
* Description:
* Model for the PCNT mux in the GPIO matrix.
*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************
*/
#include <systemc.h>
#include "info.h"
#include "mux_in.h"
void mux_in::mux(int gpiosel) {
if (gpiosel >= min_i.size()) {
PRINTF_WARN("MUXPCNT",
"Attempting to set GPIO Matrix to illegal pin %d.", gpiosel);
return;
}
function = gpiosel;
fchange_ev.notify();
}
void mux_in::transfer() {
bool nxval;
while(true) {
/* We simply copy the input onto the output. */
nxval = min_i[function]->read();
out_o.write(nxval);
if (debug) {
PRINTF_INFO("MUXIN", "mux_in %s is driving %c, function %d", name(),
(nxval)?'H':'L', function);
}
/* We wait for a function change or a signal change. */
wait(fchange_ev | min_i[function]->value_changed_event());
}
}
|
#include <systemc.h>
SC_MODULE(tb)
{
sc_in<bool> clk;
sc_out<bool> reset;
sc_out< sc_int<16> > input;
sc_out<bool> input_valid;
sc_in<bool> input_ready;
sc_in< sc_int<16> > output;
sc_in<bool> output_valid;
sc_out<bool> output_ready;
void source();
void sink();
SC_CTOR(tb){
SC_CTHREAD(source, clk.pos());
SC_CTHREAD(sink, clk.pos());
} |
#include "Neuron.h"
#include "systemc.h"
SC_MODULE(Neural_Network) {
sc_in<float> input1, input2;
sc_out<float> output;
sc_signal<float> c1, c2;
Neuron* N1;
Neuron* N2;
Neuron* N3;
SC_CTOR(Neural_Network) {
// vvvvv put your code here vvvvv
N1 = new Neuron("N1");
N2 = new Neuron("N2");
N3 = new Neuron("N3");
N1->input1(input1);
N1->input2(input2);
N1->output(c1);
N2->input1(input1);
N2->input2(input2);
N2->output(c2);
N3->input1(c1);
N3->input2(c2);
N3->output(output);
// ^^^^^ put your code here ^^^^^
N1->w1 = 10;
N1->w2 = -10;
N1->b = -5;
N2->w1 = -10;
N2->w2 = 10;
N2->b = -5;
N3->w1 = 10;
N3->w2 = 10;
N3->b = -5;
}
}; |
#include "systemc.h"
SC_MODULE(tb) {
sc_out < sc_uint<4> > OPa,OPb;
sc_out < sc_uint<4> > OP;
sc_in<bool> Clk;
void tbGen() {
OPa.write(0111);
OPb.write(0001);
OP.write(0);
wait(10,SC_NS);
OPa.write(0111);
OPb.write(0001);
OP.write(1);
wait(10,SC_NS);
OPa.write(0111);
OPb.write(0001);
OP.write(2);
wait(10,SC_NS);
OPa.write(0111);
OPb.write(0001);
OP.write(3);
wait(10,SC_NS);
OPa.write(0111);
OPb.write(0001);
OP.write(4);
wait(10,SC_NS);
OPa.write(0111);
OPb.write(0001);
OP.write(5);
wait(10,SC_NS);
sc_stop();
}
SC_CTOR(tb) {
SC_THREAD(tbGen);
}
};
|
// Generated by stratus_hls 17.20-p100 (88533.190925)
// Thu Nov 19 00:45:43 2020
// from dut.cc
#ifndef CYNTH_PART_dut_dut_rtl_h
#define CYNTH_PART_dut_dut_rtl_h
#include "systemc.h"
/* Include declarations of instantiated parts. */
#include "dut_Div_64Ux2U_32U_4.h"
/* Declaration of the synthesized module. */
struct dut : public sc_module {
sc_in<bool > clk;
sc_in<bool > rst;
sc_out<bool > din_busy;
sc_in<bool > din_vld;
sc_in<sc_uint<8> > din_data_a;
sc_in<sc_uint<8> > din_data_b;
sc_in<sc_uint<8> > din_data_c;
sc_in<sc_uint<8> > din_data_d;
sc_in<sc_uint<8> > din_data_e;
sc_in<sc_uint<8> > din_data_f;
sc_in<sc_uint<8> > din_data_g;
sc_in<sc_uint<8> > din_data_h;
sc_in<bool > dout_busy;
sc_out<bool > dout_vld;
sc_out<sc_uint<32> > dout_data;
dut( sc_module_name name );
SC_HAS_PROCESS(dut);
sc_signal<bool > dout_m_req_m_prev_trig_req;
sc_signal<sc_uint<1> > dut_Xor_1Ux1U_1U_4_14_out1;
sc_signal<bool > dout_m_unacked_req;
sc_signal<sc_uint<1> > dut_Or_1Ux1U_1U_4_15_out1;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_12_out1;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_10_out1;
sc_signal<sc_uint<1> > dut_Not_1U_1U_4_9_out1;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_11_out1;
sc_signal<sc_uint<1> > dut_N_Muxb_1_2_1_4_1_out1;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_5_out1;
sc_signal<sc_uint<1> > dut_Not_1U_1U_4_4_out1;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_3_out1;
sc_signal<sc_uint<1> > dut_Or_1Ux1U_1U_4_2_out1;
sc_signal<bool > din_m_unvalidated_req;
sc_signal<sc_uint<1> > dut_Or_1Ux1U_1U_4_7_out1;
sc_signal<sc_uint<2> > global_state_next;
sc_signal<sc_uint<1> > cycle2_state;
sc_signal<sc_uint<32> > dut_Mul_32Ux9U_32U_4_42_out1;
sc_signal<sc_uint<9> > dut_Add_8Ux8U_9U_4_40_out1;
sc_signal<sc_uint<17> > dut_Add_32Ux17U_33U_1_36_in1;
sc_signal<sc_uint<32> > dut_Add_32Ux17U_33U_1_36_in2;
sc_signal<sc_uint<32> > dut_Mul_32Ux9U_32U_4_35_out1;
sc_signal<sc_uint<8> > dut_Mul_32Ux9U_32U_4_35_in1_slice;
sc_signal<sc_uint<29> > dut_Mul_32Ux9U_32U_4_35_in2_slice;
sc_signal<sc_uint<16> > dut_Mul_8Ux8U_16U_4_34_out1;
sc_signal<sc_uint<8> > dut_Mul_8Ux8U_16U_4_34_in1;
sc_signal<sc_uint<8> > dut_Mul_8Ux8U_16U_4_34_in2;
sc_signal<sc_uint<32> > dut_Mul_33Ux32U_64U_4_33_in1;
sc_signal<sc_uint<32> > dut_Add_32Ux32U_32U_4_44_out1;
sc_signal<sc_uint<33> > dut_Mul_33Ux32U_64U_4_33_in2;
sc_signal<sc_uint<33> > dut_Add_32Ux16U_33U_4_45_out1;
sc_signal<sc_uint<32> > dut_Mul_32Ux10U_32U_4_32_out1;
sc_signal<sc_uint<10> > dut_Mul_32Ux10U_32U_4_32_in1;
sc_signal<sc_uint<9> > dut_Add_8Ux8U_9U_4_39_out1;
sc_signal<sc_uint<29> > dut_Mul_32Ux10U_32U_4_32_in2_slice;
sc_signal<sc_uint<1> > gs_ctrl0;
sc_signal<sc_uint<9> > dut_Add_8Ux8U_9U_4_31_out1;
sc_signal<sc_uint<10> > dut_Add_9Ux8U_10U_4_30_out1;
sc_signal<sc_uint<10> > dut_Add_9Ux8U_10U_4_29_out1;
sc_signal<sc_uint<8> > din_m_stall_reg_h;
sc_signal<sc_uint<8> > din_m_stall_reg_g;
sc_signal<sc_uint<9> > dut_Add_8Ux8U_9U_4_26_out1;
sc_signal<sc_uint<9> > dut_Add_8Ux8U_9U_4_25_out1;
sc_signal<sc_uint<8> > dut_N_Mux_8_2_0_4_24_out1;
sc_signal<sc_uint<8> > din_m_stall_reg_f;
sc_signal<sc_uint<8> > din_m_stall_reg_c;
sc_signal<sc_uint<8> > din_m_stall_reg_e;
sc_signal<sc_uint<8> > din_m_stall_reg_d;
sc_signal<sc_uint<8> > din_m_stall_reg_b;
sc_signal<bool > din_m_stall_reg_full;
sc_signal<sc_uint<8> > din_m_stall_reg_a;
sc_signal<sc_uint<33> > dut_Add_32Ux17U_33U_1_36_out1;
sc_signal<sc_uint<17> > s_reg_22;
sc_signal<sc_uint<64> > dut_Mul_33Ux32U_64U_4_33_out1;
sc_signal<sc_uint<29> > s_reg_21_slice11;
sc_signal<sc_uint<8> > dut_N_Mux_8_2_0_4_28_out1;
sc_signal<sc_uint<8> > s_reg_20;
sc_signal<sc_uint<8> > dut_N_Mux_8_2_0_4_27_out1;
sc_signal<sc_uint<8> > s_reg_19;
sc_signal<sc_uint<8> > dut_N_Mux_8_2_0_4_23_out1;
sc_signal<sc_uint<8> > s_reg_18;
sc_signal<sc_uint<8> > dut_N_Mux_8_2_0_4_22_out1;
sc_signal<sc_uint<8> > s_reg_17;
sc_signal<sc_uint<8> > dut_N_Mux_8_2_0_4_21_out1;
sc_signal<sc_uint<8> > s_reg_16;
sc_signal<sc_uint<8> > dut_N_Mux_8_2_0_4_20_out1;
sc_signal<sc_uint<8> > s_reg_15;
sc_signal<sc_uint<8> > dut_N_Mux_8_2_0_4_19_out1;
sc_signal<sc_uint<8> > s_reg_14;
sc_signal<sc_uint<1> > dut_Or_1Ux1U_1U_4_6_out1;
sc_signal<sc_uint<1> > s_reg_13_stage1;
sc_signal<sc_uint<1> > cycle6_state;
sc_signal<sc_uint<1> > dut_And_1Ux1U_1U_4_16_out1;
sc_signal<sc_uint<1> > dut_Not_1U_1U_4_17_out1;
sc_signal<sc_uint<1> > cycle4_state;
sc_signal<sc_uint<1> > s_reg_13;
sc_signal<bool > dout_m_req_m_trig_req;
sc_signal<sc_uint<2> > global_state;
sc_signal<bool > din_m_busy_req_0;
sc_signal<sc_uint<64> > s_reg_21_stage1;
sc_signal<sc_uint<2> > dut_Div_64Ux2U_32U_4_47_in1;
sc_signal<sc_uint<32> > dut_Div_64Ux2U_32U_4_47_out1;
sc_signal<sc_uint<1> > stall0;
dut_Div_64Ux2U_32U_4 *dut_Div_64Ux2U_32U_4_47;
void drive_dout_data();
void drive_din_m_busy_req_0();
void drive_dout_m_req_m_trig_req();
void drive_stall0();
void drive_s_reg_13();
void drive_s_reg_14();
void drive_s_reg_15();
void drive_s_reg_16();
void drive_s_reg_17();
void drive_s_reg_18();
void drive_s_reg_19();
void drive_s_reg_20();
void drive_s_reg_21();
void drive_s_reg_22();
void dut_N_Mux_8_2_0_4_19();
void dut_N_Mux_8_2_0_4_20();
void dut_N_Mux_8_2_0_4_21();
void dut_N_Mux_8_2_0_4_22();
void dut_N_Mux_8_2_0_4_23();
void dut_N_Mux_8_2_0_4_24();
void dut_Add_8Ux8U_9U_4_25();
void dut_Add_8Ux8U_9U_4_26();
void dut_N_Mux_8_2_0_4_27();
void dut_N_Mux_8_2_0_4_28();
void dut_Add_9Ux8U_10U_4_29();
void dut_Add_9Ux8U_10U_4_30();
void dut_Add_8Ux8U_9U_4_31();
void drive_dut_Mul_32Ux10U_32U_4_32_in2();
void drive_dut_Mul_32Ux10U_32U_4_32_in1();
void dut_Mul_32Ux10U_32U_4_32();
void drive_dut_Mul_33Ux32U_64U_4_33_in2();
void drive_dut_Mul_33Ux32U_64U_4_33_in1();
void dut_Mul_33Ux32U_64U_4_33();
void drive_dut_Mul_8Ux8U_16U_4_34_in2();
void drive_dut_Mul_8Ux8U_16U_4_34_in1();
void dut_Mul_8Ux8U_16U_4_34();
void drive_dut_Mul_32Ux9U_32U_4_35_in2();
void drive_dut_Mul_32Ux9U_32U_4_35_in1();
void dut_Mul_32Ux9U_32U_4_35();
void drive_dut_Add_32Ux17U_33U_1_36_in2();
void drive_dut_Add_32Ux17U_33U_1_36_in1();
void dut_Add_32Ux17U_33U_1_36();
void dut_Add_8Ux8U_9U_4_39();
void dut_Add_8Ux8U_9U_4_40();
void dut_Mul_32Ux9U_32U_4_42();
void dut_Add_32Ux32U_32U_4_44();
void dut_Add_32Ux16U_33U_4_45();
void drive_dut_Div_64Ux2U_32U_4_47_in1();
void drive_s_reg_13_stage1();
void drive_s_reg_21_stage1();
void drive_cycle2_state();
void drive_cycle4_state();
void drive_cycle6_state();
void drive_global_state();
void drive_global_state_next();
void drive_gs_ctrl0();
void drive_din_busy();
void dut_Or_1Ux1U_1U_4_2();
void dut_And_1Ux1U_1U_4_3();
void dut_Not_1U_1U_4_4();
void dut_And_1Ux1U_1U_4_5();
void dut_Or_1Ux1U_1U_4_6();
void dut_Or_1Ux1U_1U_4_7();
void drive_din_m_unvalidated_req();
void dut_N_Muxb_1_2_1_4_1();
void drive_din_m_stall_reg_h();
void drive_din_m_stall_reg_g();
void drive_din_m_stall_reg_f();
void drive_din_m_stall_reg_e();
void drive_din_m_stall_reg_d();
void drive_din_m_stall_reg_c();
void drive_din_m_stall_reg_b();
void drive_din_m_stall_reg_a();
void dut_Not_1U_1U_4_9();
void dut_And_1Ux1U_1U_4_10();
void dut_And_1Ux1U_1U_4_11();
void drive_din_m_stall_reg_full();
void dut_And_1Ux1U_1U_4_12();
void drive_dout_vld();
void dut_Or_1Ux1U_1U_4_15();
void drive_dout_m_unacked_req();
void dut_And_1Ux1U_1U_4_16();
void dut_Xor_1Ux1U_1U_4_14();
void drive_dout_m_req_m_prev_trig_req();
void dut_Not_1U_1U_4_17();
};
#endif
|
/****************************************************************************
*
* Copyright (c) 2015, Cadence Design Systems. All Rights Reserved.
*
* This file contains confidential information that may not be
* distributed under any circumstances without the written permision
* of Cadence Design Systems.
*
***************************************************************************/
#ifndef _DUT_CYCSIM_INCLUDED_
#define _DUT_CYCSIM_INCLUDED_
#include "systemc.h"
#include "cynthhl.h"
SC_MODULE(dut_cycsim)
{
// Port declarations.
sc_in< bool > clk;
sc_in< bool > rst;
sc_out< bool > din_busy;
sc_in< bool > din_vld;
sc_in< sc_uint< 8 > > din_data_a;
sc_in< sc_uint< 8 > > din_data_b;
sc_in< sc_uint< 8 > > din_data_c;
sc_in< sc_uint< 8 > > din_data_d;
sc_in< sc_uint< 8 > > din_data_e;
sc_in< sc_uint< 8 > > din_data_f;
sc_in< sc_uint< 8 > > din_data_g;
sc_in< sc_uint< 8 > > din_data_h;
sc_in< bool > dout_busy;
sc_out< bool > dout_vld;
sc_out< sc_uint< 32 > > dout_data;
dut_cycsim( sc_module_name in_name=sc_module_name(sc_gen_unique_name(" dut") ) )
: sc_module(in_name)
,clk("clk")
,rst("rst")
,din_busy("din_busy")
,din_vld("din_vld")
,din_data_a("din_data_a"),
din_data_b("din_data_b"),
din_data_c("din_data_c"),
din_data_d("din_data_d"),
din_data_e("din_data_e"),
din_data_f("din_data_f"),
din_data_g("din_data_g"),
din_data_h("din_data_h")
,dout_busy("dout_busy")
,dout_vld("dout_vld")
,dout_data("dout_data")
{
};
};
#endif
|
#include <memory>
#include <systemc.h>
#include "Vtop.h"
#include "bfm.h"
SC_MODULE(sc_top) {
sc_clock clk;
sc_signal<bool> reset;
sc_signal<bool> cs;
sc_signal<bool> rw;
sc_signal<bool> ready;
#ifdef VERILATOR
sc_signal<uint32_t> addr;
sc_signal<uint32_t> data_in;
sc_signal<uint32_t> data_out;
#else
sc_signal<sc_uint<16>> addr;
sc_signal<sc_uint<32>> data_in;
sc_signal<sc_uint<32>> data_out;
#endif
Vtop *u_top;
bfm *u_bfm;
SC_CTOR(sc_top) :
clk("clk", 10, SC_NS, 0.5, 5, SC_NS, true),
reset("reset"), cs("cs"), rw("rw"), addr("addr"), ready("ready"), data_in("data_in"), data_out("data_out") {
#ifdef VERILATOR
u_top = new Vtop{"top"};
#else
u_top = new Vtop{"top", "Vtop", 0, NULL};
#endif
u_top->clk(clk);
u_top->reset(reset);
u_top->cs(cs);
u_top->rw(rw);
u_top->addr(addr);
u_top->data_in(data_in);
u_top->ready(ready);
u_top->data_out(data_out);
u_bfm = new bfm("bfm");
u_bfm->clk(clk);
u_bfm->reset(reset);
u_bfm->cs(cs);
u_bfm->rw(rw);
u_bfm->addr(addr);
u_bfm->data_in(data_out);
u_bfm->ready(ready);
u_bfm->data_out(data_in);
}
~sc_top() {
#ifdef VERILATOR
u_top->final();
#endif
delete u_top;
delete u_bfm;
}
};
|
/**********************************************************************
Filename: sc_fir_pe.h
Purpose : Verilated PE of Systolic FIR filter
Author : goodkook@gmail.com
History : Mar. 2024, First release
***********************************************************************/
#ifndef _V_FIR_PE_H_
#define _V_FIR_PE_H_
#include <systemc.h>
#include "./obj_dir/Vfir_pe.h"
SC_MODULE(V_fir_pe)
{
sc_in<bool> clk;
sc_in<bool> Rdy;
sc_out<bool> Vld;
sc_in<sc_uint<6> > Cin;
sc_in<sc_uint<4> > Xin;
sc_out<sc_uint<4> > Xout;
sc_in<sc_uint<4> > Yin;
sc_out<sc_uint<4> > Yout;
Vfir_pe* u_Vfir_pe;
sc_signal<uint32_t> _Cin;
sc_signal<uint32_t> _Xin;
sc_signal<uint32_t> _Xout;
sc_signal<uint32_t> _Yin;
sc_signal<uint32_t> _Yout;
sc_signal<bool> _Rdy;
sc_signal<bool> _Vld;
void pe_method(void)
{
_Cin = (uint32_t)Cin.read();
_Xin = (uint32_t)Xin.read();
_Yin = (uint32_t)Yin.read();
_Rdy = Rdy.read();
Xout.write(sc_uint<4>(_Xout));
Yout.write(sc_uint<4>(_Yout));
Vld.write(_Vld);
}
SC_CTOR(V_fir_pe):
clk("clk"),
Rdy("Rdy"), _Rdy("_Rdy"),
Vld("Vld"), _Vld("_Vld"),
Cin("Cin"), _Cin("_Cin"),
Xin("Xin"), _Xin("_Xin"),
Xout("Xout"), _Xout("_Xout"),
Yin("Yin"), _Yin("_Yin"),
Yout("Yout"), _Yout("_Yout")
{
SC_METHOD(pe_method);
sensitive << clk << Cin << Xin << Yin << Rdy;
// Instantiate Verilated PE
u_Vfir_pe = new Vfir_pe("u_Vfir_pe");
u_Vfir_pe->clk(clk);
u_Vfir_pe->Cin(_Cin);
u_Vfir_pe->Xin(_Xin);
u_Vfir_pe->Xout(_Xout);
u_Vfir_pe->Yin(_Yin);
u_Vfir_pe->Yout(_Yout);
u_Vfir_pe->Rdy(_Rdy);
u_Vfir_pe->Vld(_Vld);
}
~V_fir_pe(void)
{
}
};
#endif
|
/******************************************************************************
* (C) Copyright 2014 AMIQ Consulting
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME: amiq_eth.h
* PROJECT: amiq_eth
* Description: This file includes all the C++ files which are part of
* amiq_eth package.
*******************************************************************************/
#ifndef __AMIQ_ETH
//protection against multiple includes
#define __AMIQ_ETH
#include <systemc.h>
#include "sysc/utils/sc_report.h"
#include "amiq_eth_defines.cpp"
#include "amiq_eth_ethernet_protocols.cpp"
#include "amiq_eth_packer.cpp"
#include "amiq_eth_types.cpp"
#include "amiq_eth_packet.cpp"
#include "amiq_eth_packet_ether_type.cpp"
#include "amiq_eth_packet_length.cpp"
#include "amiq_eth_packet_pause.cpp"
#include "amiq_eth_packet_pfc_pause.cpp"
#include "amiq_eth_packet_snap.cpp"
#include "amiq_eth_packet_jumbo.cpp"
#include "amiq_eth_packet_magic.cpp"
#include "amiq_eth_packet_ethernet_configuration_testing.cpp"
#include "amiq_eth_packet_ipv4.cpp"
#include "amiq_eth_packet_hsr_base.cpp"
#include "amiq_eth_packet_hsr_standard.cpp"
#include "amiq_eth_packet_fcoe.cpp"
#include "amiq_eth_packet_arp.cpp"
#include "amiq_eth_packet_ptp.cpp"
#endif
|
/*
* Created on: 21. jun. 2019
* Author: Jonathan Horsted Schougaard
*/
#pragma once
#define SC_INCLUDE_FX
#include "hwcore/cnn/data_buffer.h"
#include "hwcore/cnn/pe.h"
#include "hwcore/cnn/top_cnn.h"
#include "hwcore/cnn/weight_buffer.h"
#include "hwcore/hw/statusreg.h"
#include "hwcore/pipes/pipes.h"
#include <systemc.h>
#ifdef __RTL_SIMULATION__
#include "syn/systemc/cnn.h"
#endif
#ifndef P_data_P
#define P_data_P 2
#warning Using defualt parameter!
#endif
#ifndef P_data_W
#define P_data_W 16
#warning Using defualt parameter!
#endif
#ifndef P_input_width
#define P_input_width 128
#warning Using defualt parameter!
#endif
#ifndef P_output_width
#define P_output_width 128
#warning Using defualt parameter!
#endif
// calculatd parameter
#define P_input_BW_N (P_input_width / P_data_W)
#define P_output_BW_N (P_output_width / P_data_W)
// end
#ifndef P_pe_n
#define P_pe_n 8
#warning Using defualt parameter!
#endif
#ifndef P_pe_bw_n
#define P_pe_bw_n P_input_BW_N
#warning Using defualt parameter!
#endif
#ifndef P_wbuf_size
#define P_wbuf_size 3072
#warning Using defualt parameter!
#endif
#ifndef P_data_buf_clb_size
#define P_data_buf_clb_size 8192
#warning Using defualt parameter!
#endif
#ifndef P_data_buf_clb_n
#define P_data_buf_clb_n 3
#warning Using defualt parameter!
#endif
#ifndef P_data_buf_shift_size
#define P_data_buf_shift_size 384
#warning Using defualt parameter!
#endif
#ifndef P_data_out_n
#define P_data_out_n 1
#warning Using defualt parameter!
#endif
#ifndef P_pool_size
#define P_pool_size 1024
#warning Using defualt parameter!
#endif
#if P_pool_size < 512
#error bad pool size!!!
#endif
#ifndef P_PE_pipeline_II
#define P_PE_pipeline_II 1
#warning Using defualt parameter!
#endif
#ifndef P_pe_pre_fifo_deep
#define P_pe_pre_fifo_deep 1
#warning Using defualt parameter!
#endif
#ifndef P_X_fifo_deep
#define P_X_fifo_deep 1
#warning Using defualt parameter!
#endif
#ifndef P_W_fifo_deep
#define P_W_fifo_deep 1
#warning Using defualt parameter!
#endif
#ifndef P_Y_fifo_deep
#define P_Y_fifo_deep 1
#warning Using defualt parameter!
#endif
#ifndef P_BUF_fifo_deep
#define P_BUF_fifo_deep 1
#warning Using defualt parameter!
#endif
SC_MODULE(cnn) {
// typedef
typedef hwcore::cnn::top_cnn<P_data_W, P_data_P, P_input_BW_N, P_output_BW_N, P_pe_n, P_pe_bw_n, P_wbuf_size,
P_data_buf_clb_size, P_data_buf_clb_n, P_data_buf_shift_size, P_data_out_n,
P_pool_size, P_PE_pipeline_II, P_pe_pre_fifo_deep>
top_cnn_t;
// interface
SC_MODULE_CLK_RESET_SIGNAL;
sc_fifo_in<hwcore::pipes::SC_DATA_T(P_input_width)> data_sink;
sc_fifo_in<hwcore::pipes::SC_DATA_T(P_input_width)> data_buf_sink;
sc_fifo_in<hwcore::pipes::SC_DATA_T(P_input_width)> w_sink;
sc_fifo_in<hwcore::pipes::SC_DATA_T(64)> ctrl_sink;
sc_fifo_out<hwcore::pipes::SC_DATA_T(P_output_width)> data_source;
#if __RTL_SIMULATION__
sc_status_module_create_interface_only(reg1);
ap_rtl::cnn rtl_wrapper_cnn;
SC_FIFO_IN_TRANS<P_input_width> data_sink_trans;
SC_FIFO_IN_TRANS<P_input_width> data_buf_sink_trans;
SC_FIFO_IN_TRANS<P_input_width> w_sink_trans;
SC_FIFO_IN_TRANS<64> ctrl_sink_trans;
SC_FIFO_OUT_TRANS<P_output_width> data_source_trans;
sc_signal<sc_logic> reset_s;
sc_signal<sc_lv<32> > status_add_s;
sc_signal<sc_lv<32> > status_val_s;
void signal_connection() {
sc_dt::sc_logic reset_tmp = (sc_dt::sc_logic)reset.read();
reset_s.write(reset_tmp);
status_add_s.write(status_add.read());
status_val.write(status_val_s.read().to_int());
}
SC_CTOR(cnn)
: rtl_wrapper_cnn("rtl_wrapper_cnn"), data_sink_trans("data_sink_trans"),
data_buf_sink_trans("data_buf_sink_trans"), data_source_trans("data_source_trans"),
w_sink_trans("w_sink_trans"), ctrl_sink_trans("ctrl_sink_trans") {
// SC_MODULE_LINK(rtl_wrapper_cnn);
SC_FIFO_IN_TRANS_CONNECT(rtl_wrapper_cnn, data_sink_trans, data_sink);
SC_FIFO_IN_TRANS_CONNECT(rtl_wrapper_cnn, data_buf_sink_trans, data_buf_sink);
SC_FIFO_IN_TRANS_CONNECT(rtl_wrapper_cnn, w_sink_trans, w_sink);
SC_FIFO_IN_TRANS_CONNECT(rtl_wrapper_cnn, ctrl_sink_trans, ctrl_sink);
SC_FIFO_OUT_TRANS_CONNECT(rtl_wrapper_cnn, data_source_trans, data_source);
rtl_wrapper_cnn.clk(clk);
rtl_wrapper_cnn.reset(reset_s);
rtl_wrapper_cnn.status_add(status_add_s);
rtl_wrapper_cnn.status_val(status_val_s);
SC_METHOD(signal_connection);
sensitive << status_add << status_val_s << reset;
}
#else
sc_status_module_create(reg1);
sc_status_reg_create(r0_dma_ingress);
sc_status_reg_create(r1_dma_egress);
sc_status_reg_create(r2_data_W);
sc_status_reg_create(r3_data_P);
sc_status_reg_create(r4_input_BW_N);
sc_status_reg_create(r5_output_BW_N);
sc_status_reg_create(r6_pe_n);
sc_status_reg_create(r7_pe_bw_n);
sc_status_reg_create(r8_wbuf_size);
sc_status_reg_create(r9_data_buf_clb_size);
sc_status_reg_create(r10_data_buf_clb_n);
sc_status_reg_create(r11_data_buf_shift_size);
sc_status_reg_create(r12_data_out_n);
sc_status_end_create(regend);
void status_reg_param_link() {
r2_data_W_status.write(P_data_W);
r3_data_P_status.write(P_data_P);
r4_input_BW_N_status.write(P_input_BW_N);
r5_output_BW_N_status.write(P_pool_size);
r6_pe_n_status.write(P_pe_n);
r7_pe_bw_n_status.write(P_pe_bw_n);
r8_wbuf_size_status.write(P_wbuf_size);
r9_data_buf_clb_size_status.write(P_data_buf_clb_size);
r10_data_buf_clb_n_status.write(P_data_buf_clb_n);
r11_data_buf_shift_size_status.write(P_data_buf_shift_size);
r12_data_out_n_status.write(P_data_out_n);
}
sc_fifo<hwcore::pipes::SC_DATA_T(P_input_width)> data_sink_forward;
sc_fifo<hwcore::pipes::SC_DATA_T(P_input_width)> data_buf_sink_forward;
sc_fifo<hwcore::pipes::SC_DATA_T(P_input_width)> w_sink_forward;
sc_fifo<hwcore::pipes::SC_DATA_T(P_output_width)> data_source_forward;
sc_fifo<sc_uint<31> > weight_ctrls_fifo;
sc_fifo<sc_uint<32> > ctrl_image_size_fifo;
sc_fifo<sc_uint<16> > ctrl_row_size_pkg_fifo;
sc_fifo<sc_uint<16> > ctrl_window_size_fifo;
sc_fifo<sc_uint<16> > ctrl_depth_fifo;
sc_fifo<sc_uint<16> > ctrl_stride_fifo;
sc_fifo<sc_uint<16> > ctrl_replay_fifo;
sc_fifo<sc_uint<16> > ctrl_zeropad_fifo;
sc_fifo<sc_uint<1> > ctrl_output_channel_fifo;
sc_fifo<sc_uint<16> > ctrl_stitch_depth_fifo;
sc_fifo<sc_uint<16> > ctrl_stitch_buf_depth_fifo;
sc_fifo<sc_uint<1> > ctrl_db_output_fifo;
sc_fifo<sc_uint<1> > ctrl_image_data_fifo;
sc_fifo<sc_uint<16> > ctrl_pool_depth_fifo;
sc_fifo<sc_uint<16> > ctrl_pool_type_fifo;
sc_fifo<sc_uint<16> > ctrl_pool_N_fifo;
sc_fifo<sc_uint<16> > ctrl_pool_size_fifo;
sc_fifo<sc_uint<16> > ctrl_row_N_fifo;
sc_fifo<sc_uint<16> > ctrl_acf_fifo;
// modules
hwcore::cnn::top_cnn<P_data_W, P_data_P, P_input_BW_N, P_output_BW_N, P_pe_n, P_pe_bw_n, P_wbuf_size,
P_data_buf_clb_size, P_data_buf_clb_n, P_data_buf_shift_size, P_data_out_n>
top_cnn;
sc_status_reg_create_dummy(top_cnn_reg);
SC_CTOR(cnn)
: data_sink_forward(P_X_fifo_deep), data_buf_sink_forward(P_BUF_fifo_deep), w_sink_forward(P_W_fifo_deep),
data_source_forward(P_Y_fifo_deep), weight_ctrls_fifo(16), ctrl_row_size_pkg_fifo(16),
ctrl_window_size_fifo(16), ctrl_depth_fifo(16), ctrl_stride_fifo(16), ctrl_replay_fifo(16),
ctrl_row_N_fifo(16), ctrl_acf_fifo(16), ctrl_zeropad_fifo(16), SC_INST(top_cnn), SC_INST(reg1),
SC_INST(regend), SC_INST(r0_dma_ingress), SC_INST(r1_dma_egress), SC_INST(r2_data_W), SC_INST(r3_data_P),
SC_INST(r4_input_BW_N), SC_INST(r5_output_BW_N), SC_INST(r6_pe_n), SC_INST(r7_pe_bw_n), SC_INST(r8_wbuf_size),
SC_INST(r9_data_buf_clb_size), SC_INST(r10_data_buf_clb_n), SC_INST(r11_data_buf_shift_size),
SC_INST(r12_data_out_n), ctrl_output_channel_fifo(16), ctrl_db_output_fifo(16), ctrl_pool_depth_fifo(16),
ctrl_pool_type_fifo(16), ctrl_pool_N_fifo(16), ctrl_pool_size_fifo(16), ctrl_stitch_depth_fifo(16),
ctrl_stitch_buf_depth_fifo(1), ctrl_image_data_fifo(16)
{
top_cnn.clk(clk);
top_cnn.reset(reset);
/*SC_METHOD(reset_logic);
sensitive << reset << iclear;
SC_CTHREAD(clear_reg, clk.pos());*/
top_cnn.data_sink(data_sink_forward);
top_cnn.data_buf_sink(data_buf_sink_forward);
top_cnn.w_sink(w_sink_forward);
top_cnn.data_source(data_source_forward);
top_cnn.weight_ctrls_in(weight_ctrls_fifo);
// top_cnn.data_ctrls_in(data_ctrls_fifo);
top_cnn.ctrl_row_N(ctrl_row_N_fifo);
top_cnn.ctrl_row_size_pkg(ctrl_row_size_pkg_fifo);
top_cnn.ctrl_window_size(ctrl_window_size_fifo);
top_cnn.ctrl_depth(ctrl_depth_fifo);
top_cnn.ctrl_stride(ctrl_stride_fifo);
top_cnn.ctrl_replay(ctrl_replay_fifo);
top_cnn.ctrl_image_size(ctrl_image_size_fifo);
top_cnn.ctrl_acf(ctrl_acf_fifo);
top_cnn.ctrl_zeropad(ctrl_zeropad_fifo);
top_cnn.ctrl_output_channel(ctrl_output_channel_fifo);
top_cnn.ctrl_stitch_depth(ctrl_stitch_depth_fifo);
top_cnn.ctrl_stitch_buf_depth(ctrl_stitch_buf_depth_fifo);
top_cnn.ctrl_db_output(ctrl_db_output_fifo);
top_cnn.ctrl_image_data(ctrl_image_data_fifo);
top_cnn.ctrl_pool_depth(ctrl_pool_depth_fifo);
top_cnn.ctrl_pool_type(ctrl_pool_type_fifo);
top_cnn.ctrl_pool_N(ctrl_pool_N_fifo);
top_cnn.ctrl_pool_size(ctrl_pool_size_fifo);
// status reg
sc_status_module_connect(reg1);
sc_status_reg_connect(r0_dma_ingress, reg1);
sc_status_reg_connect(r1_dma_egress, r0_dma_ingress);
sc_status_reg_connect(r2_data_W, r1_dma_egress);
sc_status_reg_connect(r3_data_P, r2_data_W);
sc_status_reg_connect(r4_input_BW_N, r3_data_P);
sc_status_reg_connect(r5_output_BW_N, r4_input_BW_N);
sc_status_reg_connect(r6_pe_n, r5_output_BW_N);
sc_status_reg_connect(r7_pe_bw_n, r6_pe_n);
sc_status_reg_connect(r8_wbuf_size, r7_pe_bw_n);
sc_status_reg_connect(r9_data_buf_clb_size, r8_wbuf_size);
sc_status_reg_connect(r10_data_buf_clb_n, r9_data_buf_clb_size);
sc_status_reg_connect(r11_data_buf_shift_size, r10_data_buf_clb_n);
sc_status_reg_connect(r12_data_out_n, r11_data_buf_shift_size);
sc_status_end_connect(regend, r12_data_out_n);
SC_CTHREAD(thread_cnn_stream_source, clk.pos());
reset_signal_is(reset, true);
SC_CTHREAD(thread_cnn_stream_sink, clk.pos());
reset_signal_is(reset, true);
SC_CTHREAD(thread_cnn_stream_buf_sink, clk.pos());
reset_signal_is(reset, true);
SC_CTHREAD(thread_cnn_stream_w_sink, clk.pos());
reset_signal_is(reset, true);
SC_CTHREAD(thread_cnn_ctrl, clk.pos());
reset_signal_is(reset, true);
}
void thread_cnn_stream_source() {
SC_STREAM_INTERFACE_CREATE_SOURCE(data_source, "-bus_bundle M_AXIS_Y")
int count = 0;
while (true) {
hls_pipeline(1);
hwcore::pipes::SC_DATA_T(P_output_width) tmp_out = data_source_forward.read();
data_source.write(tmp_out);
count++;
r0_dma_ingress_status.write(count);
}
}
void thread_cnn_stream_sink() {
SC_STREAM_INTERFACE_CREATE_SINK(data_sink, "-bus_bundle S_AXIS_X")
int count = 0;
while (true) {
hls_pipeline(1);
hwcore::pipes::SC_DATA_T(P_input_width) tmp_in = data_sink.read();
data_sink_forward.write(tmp_in);
count++;
r1_dma_egress_status.write(count);
}
}
void thread_cnn_stream_buf_sink() {
SC_STREAM_INTERFACE_CREATE_SINK(data_buf_sink, "-bus_bundle S_AXIS_BUF")
while (true) {
hls_pipeline(1);
hwcore::pipes::SC_DATA_T(P_input_width) tmp_in = data_buf_sink.read();
data_buf_sink_forward.write(tmp_in);
}
}
void thread_cnn_stream_w_sink() {
SC_STREAM_INTERFACE_CREATE_SINK(w_sink, "-bus_bundle S_AXIS_W")
while (true) {
hls_pipeline(1);
hwcore::pipes::SC_DATA_T(P_input_width) tmp_in = w_sink.read();
w_sink_forward.write(tmp_in);
}
}
void thread_cnn_ctrl() {
SC_STREAM_INTERFACE_CREATE_SINK(ctrl_sink, "-bus_bundle S_AXIS_CTRL")
hwcore::pipes::SC_DATA_T(64) tmp_in;
status_reg_param_link();
while (true) {
do {
hls_pipeline(1);
tmp_in = ctrl_sink.read();
sc_uint<64> raw = tmp_in.data;
sc_uint<56> value = raw(56 - 1, 0);
sc_uint<8> address;
if (tmp_in.tkeep == 0) {
address = -1;
} else {
address = raw(64 - 1, 56);
}
#define add_new_reg_interface(name_, nr_) \
case nr_: \
name_##_fifo.write(value); \
break;
switch (address) {
add_new_reg_interface(weight_ctrls, 0);
add_new_reg_interface(ctrl_row_N, 1);
add_new_reg_interface(ctrl_row_size_pkg, 2);
add_new_reg_interface(ctrl_window_size, 3);
add_new_reg_interface(ctrl_depth, 4);
add_new_reg_interface(ctrl_stride, 5);
add_new_reg_interface(ctrl_replay, 6);
add_new_reg_interface(ctrl_image_size, 7);
add_new_reg_interface(ctrl_acf, 8);
add_new_reg_interface(ctrl_zeropad, 9);
add_new_reg_interface(ctrl_output_channel, 10);
add_new_reg_interface(ctrl_stitch_depth, 11);
add_new_reg_interface(ctrl_stitch_buf_depth, 12);
add_new_reg_interface(ctrl_db_output, 13);
add_new_reg_interface(ctrl_image_data, 14);
add_new_reg_interface(ctrl_pool_depth, 15);
add_new_reg_interface(ctrl_pool_type, 16);
add_new_reg_interface(ctrl_pool_N, 17);
add_new_reg_interface(ctrl_pool_size, 18);
default:
break;
};
} while (tmp_in.tlast == 0);
}
}
#endif
};
|
//
// Created by tobias on 29.11.17.
//
#ifndef PROJECT_STIMULI2_H
#define PROJECT_STIMULI2_H
#include "systemc.h"
#include "Interfaces.h"
#include "types.h"
struct Stimuli2 : public sc_module {
SC_HAS_PROCESS(Stimuli2);
Stimuli2(sc_module_name name) :
value("value")
{ SC_THREAD(fsm); }
//Blocking interface
blocking_out <int> value;
//Variables
int cnt;
//Behavior
void fsm() {
while (true) {
if(cnt < 887) ++cnt;
else cnt=0;
//value->write(cnt);
value->write(cnt);
}
};
};
#endif //PROJECT_STIMULI_H
|
End of preview. Expand
in Data Studio
No dataset card yet
- Downloads last month
- 8