Commit 059e050a authored by Francisco Barranco's avatar Francisco Barranco

Uploading attention core v0.1

parent e86681b9
This diff is collapsed.
//********************************************************************
//
// Programmed by Javier Díaz, DRIVSCO project
// Granada, March 2008, version 2.1
//
//********************************************************************
#ifndef __GABORPRIMITIVES__
#define __GABORPRIMITIVES__
#include <stdlib.hch>
#include "generic.hch"
#include "parameters.hch"
// Data bit-widths
//*****************************************
#define KERN_BITS 12 //14
#define CONV_BITS 10
#define CONV_FRACT_BITS 0
#define F_BITS (CONV_BITS) // USE CONV_BITS+1 FOR OPTICAL FLOW AND STEREO OR 17 FOR LOCAL FEATURES
#define TRIG_BITS 9
#define ORIENTED_ENERGY_BITS 20
#define ACORI_BITS (24)
#define PHASE_ORI_BITS 10 // 16 for hardware, 64 for debugging
#define ENER_BITS 10 // 16 for hardware, 32 for debugging
#define ACPHI_BITS 10//(COSLUTCOREWIDTH+F_BITS+3) // in fact this is larger than the software simulator
//#define PI 25736 // it uses 16 bits in format 2QN (1 bit sign, 2 bit integer part, 13 bits fractional part)
#define PI 201 // it uses 10 bits ( 6 bits of frac part)
// SQRT CORE (SCALED RADIANS 2Q24 FORMAT (1 for sign, 2 as integer part and the others as fractional part)
#define SQRTCOREWIDTHIN 20
#define SQRTCOREWIDTHOUT 10
#define SQRTCORELATENCY (SQRTCOREWIDTHOUT+2)
#define SQRTCORENAME sqrtcordic
// ARC TAN CORE
#define ATAN2COREWIDTHIN 24
#define ATAN2COREWIDTHOUT 24
#define ATAN2CORELATENCY (ATAN2COREWIDTHOUT+4)
#define ATAN2CORENAME atan2cordic24
// ARC TAN CORE PHASE
#define ATAN2COREWIDTHIN_P 10 //32
#define ATAN2COREWIDTHOUT_P 10 //32
#define ATAN2CORELATENCY_P (ATAN2COREWIDTHOUT_P+4)
#define ATAN2CORENAME_P atan2cordic10//atan2cordic24
// cosLUT CORE
#define COSLUTCOREWIDTH 10
#define COSLUTCORENAME cosLUT
/* BIT CONFIGUATION EXAMPLES
*****************************************
1) #define KERN_BITS 11
#define CONV_BITS 9
#define ATAN2COREWIDTH 20
#define ATAN2CORENAME atan2cordic20
2) #define KERN_BITS 13
#define CONV_BITS 11
#define ATAN2COREWIDTH 24
#define ATAN2CORENAME atan2cordic24
3) #define KERN_BITS 15 / 17 / 17 / 19 / 21
#define CONV_BITS 14 / 16 / 18 / 20 / 22
#define ATAN2COREWIDTH 30 / 34 / 38 / 42 / 46
#define ATAN2CORENAME atan2cordic30 / atan2cordic34 / atan2cordic38 / atan2cordic42 / atan2cordic46
*/
// Extra parameters
#define NORIENTATIONS 8
//#define PI 201 // 3.14 (3 bit integer, 6 bit fractional)
//#define NAN 0b100000000000
//#define NSCALES 1
#define MAX_PROC_DISPARITY 2
#define MAX_PROC_FLOW 3
#define FLOW_INDEX_BITS 2
#define DISPARITY_INDEX_BITS 1
#define DIVIDER_INPUT 18
#define DIVIDER_LATENCY DIVIDER_INPUT+4 // is +4 if divider has clks/div==1
// Generic Macros
macro expr SumMacro(Array, begin, Index,Extend);
// Computing Macros
/*********************************************************************/
macro proc GenericConvolution(Input, Output, X_FIR, Y_FIR, NTaps, NTapsMinus1, ColumnLength,normx, normy,Sx,Sy);
macro proc GaborY(Input, FNY, NTaps, NTapsMinus1, ColumnLength);
macro proc GaborBase(DataIn, FNYNX,Columns);
macro proc BuildGabor(FNYNX,fe,fo);
macro proc SortNaN(bufferIn,bufferOut, bufferLength, offset);
macro proc PhasePrimitive (fe, fo, phase, latency);
macro proc Primitives(fe,fo,Energy, Orientation, TH ,Latencies);
macro proc Primitives_short(fe,fo,Energy, Orientation, TH ,Latencies);
// Added macros (F Barranco)
/*********************************************************************/
macro proc SpatialConvolutions_last(Input,Output,KernelX,KernelY, ColumnLength);
macro proc Delaying(Input, Output, ColumnLength);
macro proc Prefilter5Taps(buffer,Out);
macro proc division_core(Num, Den, result);
#endif
\ No newline at end of file
/* channels.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#include "channels.hch"
// ***************************************************************
// Channels implemented using signals
// ***************************************************************
/*
% Channel - Send data through this channel
% Input - Data to be sent through the channel
%
% DESCRIPTION
% This function sends Input through Channel.
% Channels are structs declared
% in channels.hcc file
%
% RETURN
%
*/
macro proc Send(Channel, Input)
{
//register indicating that the procedure has completed
unsigned 1 done;
//do this at least once
do
{
par
{
//set the transfer wires to the input value
Channel.DataTransfer = Input;
//indicate that the send process is ready
Channel.SendReady = 1;
//set the done register if the read process is ready
done = Channel.ReadReady;
}
}while(!done); //until the transfer is complete
}
/*
% Channel - Send signed data through this channel
% Input - Data to be sent through the channel
%
% DESCRIPTION
% This function safely sends Input through Channel: to work, there must be
% a channel reading in the other side. It waits until the ready signal is activated
% and then sends the correct data. Otherwise, it is sending 0.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
*/
macro proc SignedSecureSend(Channel, Input)
{
signed auxInput;
if (Read_Ready(Channel))
Send(Channel, Input);
else
{
auxInput=Input;
Send(Channel, auxInput);
}
}
/*
% Channel - Send unsigned data through this channel
% Input - Data to be sent through the channel
%
% DESCRIPTION
% This function safely sends Input through Channel: to work, there must be
% a channel reading in the other side. It waits until the ready signal is activated
% and then sends the correct data. Otherwise, it is sending 0.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
*/
macro proc UnsignedSecureSend(Channel, Input)
{
unsigned auxInput;
if (Read_Ready(Channel))
Send(Channel, Input);
else
{
auxInput=Input;
Send(Channel, auxInput);
}
}
/*
% Channel - Receive data coming through this channel
% Output - Data to be received through the channel
%
% DESCRIPTION
% This function safely receives Output through Channel.
% It waits until the ready signal is activated (meaning that
% the sending part is ready) and then receives the data.
% This function is blocked until the reception of the first
% transference.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
*/
macro proc Receive(Channel, Output)
{
//register indicating that the procedure has completed
unsigned 1 done;
//do this at least once
do
{
par
{
//is the send process is ready
if (Channel.SendReady)
{
//ready the value on the data transfer wires
Output = Channel.DataTransfer;
}
else
delay;
//indicate that the receive process is ready
Channel.ReadReady = 1;
//set the done register if the send process is ready
done = Channel.SendReady;
}
}while(!done); //until the transfer is complete
}
/*
% Channel - Channel
%
% DESCRIPTION
% This function checks whether the sender is ready or not.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
% SendReady - Signal that is active if the sender is ready to transmit data
%
*/
macro expr Send_Ready(Channel) = Channel.SendReady;
/*
% Channel - Channel
%
% DESCRIPTION
% This function checks whether the receiver is ready or not.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
% ReadReady - Signal that is active if the receiver is ready to receive data
%
*/
macro expr Read_Ready(Channel) = Channel.ReadReady;
\ No newline at end of file
/* channels.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __CHANNELS__
#define __CHANNELS__
#include "stdlib.hch"
// Channels implemented using signals
// ***************************************************************
struct unsignedchannel
{
signal unsigned 1 ReadReady;
signal unsigned 1 SendReady;
signal unsigned DataTransfer;
};
struct signedchannel
{
signal unsigned 1 ReadReady;
signal unsigned 1 SendReady;
signal signed DataTransfer;
};
// Definition of a channel with default values of 0
#define UNSIGNED_CHANNEL static struct unsignedchannel
#define SIGNED_CHANNEL static struct signedchannel
// Example channel declaration: declare a variable MyChannel
// as channel structure with default value of zero
// UNSIGNED_CHANNEL MyChannel;
macro proc Send(Channel, Input);
macro proc SignedSecureSend(Channel, Input);
macro proc UnsignedSecureSend(Channel, Input);
macro proc Receive(Channel, Output);
// These expressions allow the user to implement non-blocking channels:
// This channel structure has the readiness of the send and
// receive process exposed as signals, allowing the user to check
// the status of a channel. This can be simply expressed as
// expressions in Handel-C thus:
//Check whether the sender is ready
macro expr Send_Ready(Channel);
//Check whether the receiver is ready
macro expr Read_Ready(Channel);
#endif
/* cores.hcc
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#include "cores.hch"
// Interfaces for the top and core projects
// ***************************************************************
/*
% Input - Input channel for the 3 pixels of 8 bits (from the 3 RGB channels)
% Output - Local descriptor feature maps (27 bits)
% Control - Control word with the different parameters:
% * Control[60:45] - Latencies for the feature estimation (gabor modules)
% * Control[44:36] - Thresholds for the feature estimation
% * Control[35:26] - Number of columns of the input images
% * Control[24:21] - Not used
% * Control[20:13] - Not used
% * Control[12:0] - Latency cycles of the pipeline
% ImSize - Size of the input images
%
% DESCRIPTION
% Interface for a top architecture to interface with the attention estimation core
% RETURN
%
*/
macro proc InterfazTopFlowCore_lf_attention(Input, Output, Control, ImSize)
{
macro expr InWidth=24; //192;//24;
//macro expr OutWidth=51;//24;
macro expr OutWidth=27;//18; 9 bits are useless
interface CoreOpticFlow( signal OutWidth CoreOut, signal unsigned 1 OutSendReady, signal unsigned 1 InReadReady)
MyCore( unsigned 1 clk=__clock, unsigned imSize=ImSize, signal InWidth CoreIn=Input.DataTransfer,
signal unsigned 1 InSendReady=Input.SendReady,
signal unsigned 1 OutReadReady=Output.ReadReady, unsigned cmd=Control)with{retime=0};
while(1)
{
par
{
Output.DataTransfer=MyCore.CoreOut;
Output.SendReady=MyCore.OutSendReady;
Input.ReadReady=MyCore.InReadReady;
}
}
}
/*
% Input - Input channel for the 3 pixels of 8 bits (from the 3 RGB channels)
% Output - Local descriptor feature maps (27 bits)
% Control - Control word with the different parameters:
% * Control[60:45] - Latencies for the feature estimation (gabor modules)
% * Control[44:36] - Thresholds for the feature estimation
% * Control[35:26] - Number of columns of the input images
% * Control[24:21] - Not used
% * Control[20:13] - Not used
% * Control[12:0] - Latency cycles of the pipeline
% ImSize - Size of the input images
%
% DESCRIPTION
% Interface for the attention estimation core (used in the main.hcc)
%
% RETURN
%
*/
macro proc InterfazCore_lf_attention(Input, Output, Control,ImSize)
{
#if CORE==1
// Outcoming data
interface port_out() OutData(signal CoreOut = Output.DataTransfer)with{retime=0};
interface port_out() OutSendStatus(signal unsigned 1 OutSendReady = Output.SendReady)with{retime=0};
interface port_in(signal unsigned 1 OutReadReady) OutReadStatus()with{retime=0} ;
// Incoming data
// interface port_in(unsigned 1 clk with {clockport = 1}) ClockPort() ;
interface port_in(unsigned imSize) CimSize()with{retime=0};
interface port_in(signal CoreIn) InData()with{retime=0};
interface port_in(signal unsigned 1 InSendReady) InSendStatus()with{retime=0};
interface port_out() InReadStatus(signal unsigned 1 InReadReady = Input.ReadReady)with{retime=0};
// Control & Commands
interface port_in(unsigned cmd) Control_Commands()with{retime=0};
#else
// Outcoming data
interface bus_out() OutData(signal CoreOut = Output.DataTransfer)with{retime=0};
interface bus_out() OutSendStatus(signal unsigned 1 OutSendReady = Output.SendReady)with{retime=0};
interface bus_in(signal unsigned 1 OutReadReady) OutReadStatus() with{retime=0};
// Incoming data
// interface port_in(unsigned 1 clk with {clockport = 1}) ClockPort() ;
interface bus_in(unsigned imSize) CimSize()with{retime=0};
interface bus_in(signal CoreIn) InData()with{retime=0};
interface bus_in(signal unsigned 1 InSendReady) InSendStatus()with{retime=0};
interface bus_out() InReadStatus(signal unsigned 1 InReadReady = Input.ReadReady)with{retime=0};
// Control & Commands
interface bus_in(unsigned cmd) Control_Commands()with{retime=0};
#endif
while(1)
{
par
{
Output.ReadReady=OutReadStatus.OutReadReady;
Input.DataTransfer=InData.CoreIn;
Input.SendReady=InSendStatus.InSendReady;
Control=Control_Commands.cmd;
ImSize=CimSize.imSize;
}
}
}
/* cores.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __CORES__
#define __CORES__
#include "stdlib.hch"
#include "channels.hch"
//#include "xircav4_lib.hch" //Platform-dependent
#define CORE 1 // 0 for sub-circuit test, 1 for core calls
//Attention cores
macro proc InterfazCore_lf_attention(Input, Output, Control,ImSize);
macro proc InterfazTopFlowCore_lf_attention(Input, Output, Control, ImSize);
#endif
\ No newline at end of file
/* generic.hcc
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#include "generic.hch"
// Pipeline synchronization delays
/*
% DelayCycles - Number of cycles of the delay
%
% DESCRIPTION
% This function sequentially generates the number of cycles that
% is passed in DelayCycles. It can be used for synchronization.
%
% RETURN
%
*/
macro proc PipelineDelay(DelayCycles)
{
seq(t=0;t<(DelayCycles);t++)
{
delay;
}
}
/*
% input - Input data
%
% DESCRIPTION
% This function creates a NaN valid. The value will depend on
% the width of the input. It will be 1 followed by as many zeros
% as the size of input minus 1.
%
% RETURN
% The NaN value for the width of input.
%
*/
macro expr SetNAN(input) = 1<<(width(input)-1);
/* generic.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __GENERIC_HCH__
#define __GENERIC_HCH__
#include "stdlib.hch"
#include "parameters.hch"
#include "cores.hch"
#include "channels.hch"
#include "bilinear_warping_v2.hch"
static struct SECURE_FIFO_CHANNEL_INTERFACE_12
{
signal unsigned 1 wren;
signal unsigned 1 rden;
signal unsigned 12 data_w;
signal unsigned 12 data_r;
signal unsigned 1 full;
signal unsigned 1 empty;
};
#define SECURE_FIFO_CHANNEL_12 static struct SECURE_FIFO_CHANNEL_INTERFACE_12
macro proc SecureFifoChannel_12(PtrInterface);
macro proc MyFIFORead_12(PtrInterface, data);
macro proc MyFIFOWrite_12(PtrInterface, data);
macro expr SetNAN(input);
#endif
\ No newline at end of file
This diff is collapsed.
/* lklib.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __LKLIB__
#define __LKLIB__
#include "stdlib.hch"
#include "generic.hch"
#define XYTDERIVATIVESIZE 9
#define PIXELSIZE 8
#define DIVIDER_INPUT 25 //Input size of the divider core
#define DIVIDER_LATENCY DIVIDER_INPUT+4+1 //Latency of the divider core
macro proc Prefilter5Taps(buffer,Out);
macro proc Prefilter3Taps(buffer,Out);
macro proc Diff5Taps(buffer,Out);
macro proc Diff3Taps(buffer,Out);
macro proc Weighting(buffer,Out);
macro proc SpatialConvolutions_optf(Input,Output,KernelX,KernelY, ColumnLength);
macro proc WeightingMatrix_optf(Input0, Input1,Output, ColumnLength);
macro proc TemporalDerivative_optf(DataIn, dt, st);
macro proc FIXPOINTftu_optf(FractionalShift, detTH, Axx, Axy, Ayy, Axt, Ayt, VxOut, VyOut);
macro proc division_core(Num, Den, quot);
#endif
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#ifndef __OPTICFLOW__
#define __OPTICFLOW__
#include "GaborPrimitives.hch"
#define NFRAMES 3
#define NORIENTATIONS 8
#define ATAN2WIDTH 10 //19 //24
#define ATAN2OUTWIDTH 10 //9 //19 //24
#define ATAN2LATENCY (ATAN2OUTWIDTH+4)
#define ATAN2NAME atan2_10bit //atan2_19bit
#define DIVIDER_NAME divider_21
#define DIVIDER_NAME_2 divider_27
#define DIVIDER_INPUT 18
#define DIVIDER_LATENCY DIVIDER_INPUT+4 // is +4 if divider has clks/div==1
#define FLOW_BITS 12
#define THRESHOLD 16
#define NC_MIN 4
#define EPS 0
#define NAN 0b100000000000
// CORES
macro proc CoreATAN2CORDIC_fl(y, x, enable, angle);
macro proc CoreDIVIDER(my_dividend, my_divisor, result, enable);
macro proc CoreDIVIDER_2(my_dividend, my_divisor, result, enable);
//***************************************************
//Macro component_velocity
//***************************************************
macro proc component_velocity(P, FVreal, FVimag, LE);
macro proc component_velocity_mia(P, FVreal, FVimag, LE);
macro proc new_component_velocity(P, FV, LE);
//***************************************************
//Macro compute_phase
//***************************************************
macro proc compute_phase(Greal, Gimag, P);
macro proc compute_single_phase(Greal, Gimag, P);
//***************************************************
//Macro unwrap
//***************************************************
macro proc unwrap(Pin, Pout);
macro proc unwrap_3(Pin, Pout);
//***************************************************
//Macro full_velocity
//***************************************************
macro proc full_velocity(FVx,FVy,LE,thres,nc_min, enable, Ox, Oy);
macro proc full_velocity_small(FVx,FVy,LE,thres, Div_thr, nc_min, Ox, Oy);
macro proc new_full_velocity(FV, LE,thres, nc_min, Ox, Oy);
macro proc divide12(Num, Den, quot);
macro proc invert(Num, Den, quot);
//***************************************************
//Resource sharing functions
//***************************************************
macro proc compute_phase_top(Greal,Gimag, P, index);
void function_compute_phase(signed int F_BITS (*Greal),signed int F_BITS (*Gimag), signed int 9 *P);
macro proc compute_phase_index(Greal, Gimag, P);
#endif
\ No newline at end of file
/* parameters.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __PARAMETERS__
#define __PARAMETERS__
// Number of cameras (1 for single camera, 2 for stereo system)
//#define NCAMERAS 2
// Max image resolution
#define MAX_RES_X 1024
#define MAX_RES_Y 1024
#define MAX_IMSIZE (MAX_RES_X*MAX_RES_Y)
//Number of frames we are using
#define NFRAMES 3
#endif
\ No newline at end of file
......@@ -20,7 +20,7 @@
% ImSize - Size of the input images
%
% DESCRIPTION
% Interface for a top architecture to interface with the disparity estimation core
% Interface for a top architecture to interface with the optic flow estimation core
% RETURN
%
*/
......
......@@ -8,7 +8,7 @@
#include "stdlib.hch"
#include "channels.hch"
//#include "xircav4_lib.hch" Platform-dependent
//#include "xircav4_lib.hch" //Platform-dependent
#define CORE 1 // 0 for sub-circuit test, 1 for core calls
......
/* lklib.hcc
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#include "lklib.hch"
#include "cores.hch"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment