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: 
Highlighted
Voyager
Voyager
8,209 Views
Registered: ‎04-10-2012

How best to do inner product of two vectors

I am using Vivado and am attempting to compute the dot product of two vectors, but seem to be getting stuck in the weeds.

 

I have sync_pattern_size elements (lets say that is 8 for simplicity sake) in one vector, and a much larger number of elements in a circular vector that I want to multiply agasint.  Where I keep getting wrapped around the axle is how to handle the sum of the products in parallel.

 

My plan was:

   reg [15:0] index2 = 8'd0;
reg signed [31:0] corr_sum;
reg signed [31:0] corr_sum_reg;
reg [31:0] abs_corr_sum = 32'd0;
reg [31:0] abs_corr_sum_reg = 32'd0;

always @*//(posedge clock) begin // for each incoming sample abs_corr_sum = 32'd0; sample_data_buffer_I[sample_index] = i_tdata[15:0]; sample_data_buffer_I[circ_buf_size + sample_index] = i_tdata[15:0]; sample_data_buffer_Q[sample_index] = i_tdata[31:16]; sample_data_buffer_Q[circ_buf_size + sample_index] = i_tdata[31:16]; for (index2 = 0; index2 < sync_pattern_size; index2 = index2 + 1'b1) begin corr_sum = sample_data_buffer_I[index2+sample_index+circ_buf_size-sync_pattern_size] * sync_pattern_I[index2] + sample_data_buffer_Q[index2+sample_index+circ_buf_size-sync_pattern_size] * sync_pattern_Q[index2]; if(corr_sum[31] == 1'b1) begin abs_corr_sum = abs_corr_sum + corr_sum; end else begin abs_corr_sum = abs_corr_sum + corr_sum; end end
end

And then in a second block:

    always @(posedge clock)
    begin  
        corr_sum_reg <= corr_sum;
        abs_corr_sum_reg <= abs_corr_sum;
    end

But this doesn't seem to work right when the corr_sum is a negative value.  I know that my cheapo absolute value convertion should be fine, so I think I am scewing up somewhere else trying to parallelize this dot product operation.  Is there any easier way to go about this?

Tags (2)
0 Kudos
3 Replies
Voyager
Voyager
8,193 Views
Registered: ‎04-21-2014

Re: How best to do inner product of two vectors

wooshh, answer deleted because it was ignored.

***Many of us who help you are just FPGA enthusiasts, and not Xilinx employees. If you receive help, and give kudos (star), you're likely to continue receiving help in the future. If you get a solution, please mark it as a solution.***
0 Kudos
Voyager
Voyager
8,179 Views
Registered: ‎04-10-2012

Re: How best to do inner product of two vectors

A lot of other issues I'd comment on after asking questions, but you didn't ask for that kind of feedback.

I'm sorry, I'm not sure what you mean by this?

 

 if(corr_sum[31] == 1'b1)
                begin
                    abs_corr_sum = abs_corr_sum + corr_sum;
                end
                else
                begin
                    abs_corr_sum = abs_corr_sum - corr_sum;
                end

I had an error when I was was cleaning up my copy and paste, you are right, I didn't have my original if-statement right, here is what I have that isn't working:

                //this is my quick and dirty abs(corr_sum) summer
                if(corr_sum[31] == 1'b1)
                begin
                    $display("NEG:",abs_corr_sum,"+", ~corr_sum+1,"=", abs_corr_sum + ~corr_sum+1);
                    abs_corr_sum = abs_corr_sum + ~corr_sum+1;
                    $display("NEG:",abs_corr_sum);
                end
                else
                begin
                    $display("POS:",abs_corr_sum,"+", corr_sum,"=", abs_corr_sum + corr_sum);
                    abs_corr_sum = abs_corr_sum + corr_sum;
                    $display("POS:",abs_corr_sum);
                end
0 Kudos
Voyager
Voyager
8,171 Views
Registered: ‎04-21-2014

Re: How best to do inner product of two vectors

wooshh, answer deleted because it was ignored.

***Many of us who help you are just FPGA enthusiasts, and not Xilinx employees. If you receive help, and give kudos (star), you're likely to continue receiving help in the future. If you get a solution, please mark it as a solution.***
0 Kudos