Team 142857: Difference between revisions

From Cpre584
Jump to navigation Jump to search
Jmpark00 (talk | contribs)
Jmpark00 (talk | contribs)
Line 195: Line 195:
   return 0;
   return 0;
  }
  }
=== Profile C++ code ===

Revision as of 02:20, 11 February 2012

Team members

  • Michael Patterson
  • Chetan N-Govindaiah
  • Jungmin Park

Assignment 1

Developing a Custom Personality

1 Analyze Application

  • How does the current application perform on existing hardware?
  • What bottleneacks are limiting the performance?
  • What data structures are involved?
  • How parallelizable is the application?

2 Evaluate Hardware Options

3 Define Custom Instructions

  • The functions implemented by the hardware design can then be mapped to custom instructions.

4 Develop Software Model of Custom Personality

  • Convey provides an architecture simulation environment to allow rapid prototyping of both the hardware and software components of a custom personality.
  • This environment is written in C++ to emulate the rest of the system. It includes hardware models of instruction dispatch, register state and the memory subsystem.

5 Modify Application to Use Coprocessor

6 Compile Application with Convey Compiler

7 Simulate Application with Convey Architecture Simulator

  • This step allows the application and the custom instruction set to be debugged before the hardware is designed.

8 Develop FPGA Hardware

9 Simulate Hardware in Convey Simulation Environment

  • Convey provides a hardware simulation environment with bus-functional models for all hardware interfaces to the Application Engine (AE) FPGA.
  • Using a standard VPI interface (Verilog Procedural Inteface) the architecture simulator can be used to provide stimulus to the HDL simulation.

10 Integrate with Convey Hardware

Running the Sample Application

1. Copy Sample AE and Sample Application The Vadd sample personality and application is installed with the PDK RPM in /opt/convey/pdk/2010_08_09/.

The sample is made up of two components:

  • cae_pers_vadd - contains the sample custom personality, including the software model which emulates the Application Engine FPGA
    • CaeSimPers - contains the AE simulation model of the sample personality
      • CaelsaVadd.cpp - models the behavior of the custom personality, implements the following functions :
        • void CCaelsa::InitPers()
        • void CCaelas::CaepInst(int masked, int ae, int opcode, int immed, unit64 scalar
    • phys - Xilinx physical implementation, contains constraints files
    • testbench
    • verilog-RTL to be synthesized into FPGA
  • SampleAppVadd - contains the application that uses the instruction defined in the CasSample tree.
cd $HOME
mkdir pdk_sample
cp -r /opt/convey/pdk/2010_08_09/cae_pers_vadd pdk_sample
cp -r /opt/convey/pdk/2010_08_09/pdk_apps/SampleAppVadd pdk_sample

2. Build the Sample AE and Sample Application

cd $HOME/pdk_sample/cae_pers_vadd/CaeSim 
make
cd ../../SampleAppVadd
make

3. Custom AE Software Simulation

  • Set up Environment Variables
export CNY_PDK_PROJ=~/pdk_sample/cae_pers_vadd/

By this commend, CNY_CAE_EMULATOR will be changed into ~/pdk_sample/cae_pers_vadd/CaeSimPers/CaeSimPers

  • Run the application against the architecture simulator

4. Custom AE Hardware Simulation

5. AE Physical Build

cd ~/pdk_sample/cae_pers_vadd/phys
make

PDK build flow automatically runs synthesis, place and route, timing analysis and bitgen

Sample Application Software Model

~/pdk_sample/cae_pers_vadd/CaeSimPers/CaeIsaVadd.cpp

ConveyPDKReferenceManual.pdf Section 7.2

Assignment 2 (Sobel Edge Detection)

Sobel Algorithm [1]

Simplified description

  • In simple terms, the operator calculates the gradient of the image intensity at each point, giving the direction of the largest possible increase from light to dark and the rate of change in that direction. The result therefore shows how "abruptly" or "smoothly" the image changes at that point, and therefore how likely it is that that part of the image represents an edge, as well as how that edge is likely to be oriented. In practice, the magnitude (likelihood of an edge) calculation is more reliable and easier to interpret than the direction calculation.
  • Mathematically, the gradient of a two-variable function (here the image intensity function) is at each image point a 2D vector with the components given by the derivatives in the horizontal and vertical directions. At each image point, the gradient vector points in the direction of largest possible intensity increase, and the length of the gradient vector corresponds to the rate of change in that direction. This implies that the result of the Sobel operator at an image point which is in a region of constant image intensity is a zero vector and at a point on an edge is a vector which points across the edge, from darker to brighter values.

Source Code

  • We use the Clmg Library which is an image processing library, designed for C++ programmers. It provides useful classes and functions to load/save, display and process various types of images.
  • files
    • CImg.h - header file
    • sobel_edge_detection.cpp - sobel algorithm
    • Img - folder including image files
    • Makefile
// sobel_edge_detection.cpp
#include <iostream>
#include <cmath>
#include "CImg.h"
using namespace cimg_library;
using namespace std;
 int main(){
 int width;
 int height;
 int SUM;
 int sumX, sumY;
 int y;
 int x;
 int GX[3][3];
 int GY[3][3];
 //Sobel Matrices Horizontal
 GX[0][0] = -1; GX[0][1] = 0; GX[0][2] = 1;
 GX[1][0] = -2; GX[1][1] = 0; GX[1][2] = 2;
 GX[2][0] = -1; GX[2][1] = 0; GX[2][2] = 1;
 //Sobel Matrices Vertical
 GY[0][0] = -1; GY[0][1] = -2; GY[0][2] = -1;
 GY[1][0] = 0; GY[1][1] = 0; GY[1][2] = 0;
 GY[2][0] = 1; GY[2][1] = 2; GY[2][2] = 1;
 CImg<unsigned char> image("./img/lena.pgm");
 width = image.width();
 height = image.height();
 cout << "Width is " << width << " and height is  " << height << endl;
 int **px;
 px = new int *[width];
 for (y=0; y<height; y++)
 {
    px[y] = new int [height];
    for (x=0; x<width; x++)
    {
         px[y][x] = image(x, y);
    }
 }
 // Soble Algorithm 
 for (y=0; y< height; y++)
 {
    for (x=0; x < width; x++)
    {
       sumX    = 0;
       sumY    = 0;
           
           /*Convolution for X*/
               for(int i = 0; i < 3; i++)
               {
                   for(int j = 0; j < 3; j++)
                   {
                      if (x+j >= width || y-2+i <0 ) 
                       sumX = sumX ;
                      else
                       sumX = sumX + GX[i][j] * (int)image(x+j,y-2+i);
                   }
               }
           /*Convolution for Y*/
               for(int i = 0; i < 3; i++)
               {
                   for(int j = 0; j < 3; j++)
                   {
                      if (x+j >= width || y-2+i <0 ) 
                       sumY = sumY ;
                      else
                       sumY = sumY + GY[i][j] * (int)image(x+j,y-2+i);
                   }
               }
           /*Edge strength*/
           SUM = sqrt(pow((double)sumX,2) + pow((double)sumY,2));
           if(SUM > 255) SUM = 255;
           if(SUM < 0) SUM = 0;
           px[x][y] = SUM;
    }
 }
   CImg<unsigned char> oimage(width,height);
   for(y = 0; y < height; y++)
   {
       for(x = 0; x< width; x++)
       {
           oimage(x,y) = px[x][y];
       }
   }
   oimage.save_bmp("edge.pgm");
 CImgDisplay disp1(image, "Original image"), disp2(oimage, "Edge detected image");
 while (!disp1.is_closed() && !disp2.is_closed()) {
 disp1.wait();
 }
 return 0;
}

Profile C++ code