UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor elizash
Visitor
7,769 Views
Registered: ‎05-11-2011

Work with matrix

Jump to solution

Hi all,

I need to generate the random sparse matrix but elements of have to be at specific place for example random numbers on diagonal other is 0.How can I store it ? And how I can get the special element of this matrix each time?

Thanks in advance !

0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
8,478 Views
Registered: ‎05-23-2008

Re: Work with matrix

Jump to solution

All,

in Coregen there is a Linear Algebra toolkit IP. Please see http://www.xilinx.com/products/intellectual-property/EF-DI-LAT.htm

 

regards

Mike

8 Replies
Advisor eilert
Advisor
7,766 Views
Registered: ‎08-14-2007

Re: Work with matrix

Jump to solution

hi,

matlab has the "eye" function, giving you amatrix filled with ones on the diagonal:

e.g.:

>> eye(7)

ans =

     1     0     0     0     0     0     0
     0     1     0     0     0     0     0
     0     0     1     0     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     1     0     0
     0     0     0     0     0     1     0
     0     0     0     0     0     0     1

now you can multiply this with a rqandom matrix of the same size using the ".*" operator for element wise multiplication

e.g.:

rand(7,7).*eye(7)

ans =

    0.0648         0         0         0         0         0         0
         0    0.5798         0         0         0         0         0
         0         0    0.4611         0         0         0         0
         0         0         0    0.8744         0         0         0
         0         0         0         0    0.2140         0         0
         0         0         0         0         0    0.4399         0
         0         0         0         0         0         0    0.6072

 

So much for generating such a matrix.

But for the other questions, please be more specific.

Is this also just matlab related, or is anything with FPGAs involved?

 

Have a nice simulation

  Eilert

 

0 Kudos
Visitor elizash
Visitor
7,752 Views
Registered: ‎05-11-2011

Re: Work with matrix

Jump to solution

Hi,

If be more specific, I need store this matrix in some element in system generator .I know two store elements which probably can be appropriate for it: ROM and single port RAM.But my problem is how to get specific element of this matrix ?For example I need only element (5,5)?And another question which appears :How can I do matrix multiplication?not just multiplication element by element?

Non-technical example

if A=\begin{bmatrix}a&b\\c&d\end{bmatrix} and B=\begin{bmatrix}e&f\\g&h\end{bmatrix} then [1]AB=\begin{bmatrix}a&b\\c&d\end{bmatrix}\begin{bmatrix}e&f\\g&h\end{bmatrix}=\begin{bmatrix}ae+bg&af+bh\\ce+dg&cf+dh\end{bmatrix}

and size of matrix can be different.

 

 

0 Kudos
Advisor eilert
Advisor
7,750 Views
Registered: ‎08-14-2007

Re: Work with matrix

Jump to solution

Hi,

ok, so you want to do matrix math inside an FPGA.

It's not impssible, but kind of inconvenient, if you are used to the high level matlab functions.

Actually you have to redesign the algorithms according to your system specifications all by yourself.

In some cases you may find predifined libraries written in some HDL, but they may not always fit to your requirements one way or the other.

 

So, how to proceed:

Lets just assume that you somehow managed to store some 2D Matrix into a RAM.

The RAM now holds a 1D representation of your matrix.

 

e.g.

RAM address    Matrix element

0                           a

1                           b

2                           c

3                           d

4                           e

5                           f

6                           g

7                           h

 

Now you need some controlling device (e.g. some FSM) that performs read operations on this ram and controlls a data path, that is able to do two multiplications and one addition (e.g.:  a*e + b*g), the result then can be stored to some other ram position or forwarded to some output, depending on your requirements.

 

As you can see the adress for some specific element of the marix can be calculated using some simple operations:

       adress=row_pos+col_pos*row_length

If your matrix dimension is a 2^n value, the multiplication herein is a simple shift operation.

 

There are many things that can be done to optimize the performance of your design in any direction (area vs. speed), but they are very specific to your requirements.

 

If the size of your matrix shall be different, you need to make your controller flexible, e.g. by using loadable counters for address calculations. basically just the same as you would do in software, just that you have to care fore some more limitations because the arithmetic structure (your datapath) has to be fixed, and can not change at runtime.

Also your memory is kind of limited, if you intend to use just internal RAM ressources.

 

Hope you got an idea now what lies in front of you.

This is hardware design and the higher grade of freedom has to be paid with work time.

 

Have a nice synthesis

  Eilert

 

 

 

Visitor elizash
Visitor
7,745 Views
Registered: ‎05-11-2011

Re: Work with matrix

Jump to solution

Thanks for reply and I am trying to it.But now I faced other problem I need to find a reminder.I am tring to use Divider Generator but it gives result only after 50 time clk. But I need that it gives each time.I try to use black box but it gives me 0 output.

Simple verilog code:

module remaider(counter,matrixsize,remainder,clk);
input [15:0] counter;
input [15:0] matrixsize;
input clk;
output signed [14:10] remainder;
always @ (posedge clk )
begin
assign remainder = counter%matrixsize;
end
endmodule

 


I know why it gives 0 because output of model changes to [5:0] but i didn't get why??

0 Kudos
Advisor eilert
Advisor
7,721 Views
Registered: ‎08-14-2007

Re: Work with matrix

Jump to solution

Hi,

sorry for answering so late, I had some weeks of vacancy.

 

The solution is simple, you hopefully already found it by yourself.

In your black box the HDL simulator isn't activated:

  sim_method          "Inactive"

 

So, without a HDL simulator runnig you won't get any outputs from the black box.

You can choose between ISIM or Modelsim. In the later case you also have to add the ModelSim block to your simulink model.

 

Have a nice simulation

  Eilert

0 Kudos
Xilinx Employee
Xilinx Employee
8,479 Views
Registered: ‎05-23-2008

Re: Work with matrix

Jump to solution

All,

in Coregen there is a Linear Algebra toolkit IP. Please see http://www.xilinx.com/products/intellectual-property/EF-DI-LAT.htm

 

regards

Mike

Highlighted
Visitor elizash
Visitor
7,698 Views
Registered: ‎05-11-2011

Re: Work with matrix

Jump to solution
Yes thanks)I already understood problem)
0 Kudos
Visitor boudy
Visitor
6,363 Views
Registered: ‎03-20-2014

Re: Work with matrix

Jump to solution
bro how can i multiply a matrix, using xilinx block in simulink?
0 Kudos