topic Re: How best to do inner product of two vectors in General Technical Discussion
https://forums.xilinx.com/t5/General-Technical-Discussion/How-best-to-do-inner-product-of-two-vectors/m-p/657560#M35787
<P>wooshh, answer deleted because it was ignored.</P>Sat, 31 Oct 2015 03:42:22 GMTmorgan1985102015-10-31T03:42:22ZHow best to do inner product of two vectors
https://forums.xilinx.com/t5/General-Technical-Discussion/How-best-to-do-inner-product-of-two-vectors/m-p/657356#M35769
<P>I am using Vivado and am attempting to compute the dot product of two vectors, but seem to be getting stuck in the weeds.</P>
<P> </P>
<P>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.</P>
<P> </P>
<P>My plan was:</P>
<PRE> reg [15:0] index2 = 8'd0;<BR /> reg signed [31:0] corr_sum;<BR /> reg signed [31:0] corr_sum_reg;<BR /> reg [31:0] abs_corr_sum = 32'd0;<BR /> reg [31:0] abs_corr_sum_reg = 32'd0;<BR /> <BR /> 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<BR /> end</PRE>
<P>And then in a second block:</P>
<PRE> always @(posedge clock)
begin
corr_sum_reg <= corr_sum;
abs_corr_sum_reg <= abs_corr_sum;
end</PRE>
<P>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?</P>Mon, 28 Sep 2015 18:27:54 GMThttps://forums.xilinx.com/t5/General-Technical-Discussion/How-best-to-do-inner-product-of-two-vectors/m-p/657356#M35769garengllc2015-09-28T18:27:54ZRe: How best to do inner product of two vectors
https://forums.xilinx.com/t5/General-Technical-Discussion/How-best-to-do-inner-product-of-two-vectors/m-p/657404#M35783
<P>wooshh, answer deleted because it was ignored.</P>Sat, 31 Oct 2015 03:42:08 GMThttps://forums.xilinx.com/t5/General-Technical-Discussion/How-best-to-do-inner-product-of-two-vectors/m-p/657404#M35783morgan1985102015-10-31T03:42:08ZRe: How best to do inner product of two vectors
https://forums.xilinx.com/t5/General-Technical-Discussion/How-best-to-do-inner-product-of-two-vectors/m-p/657518#M35786
<PRE>A lot of other issues I'd comment on after asking questions, but you didn't ask for that kind of feedback.</PRE>
<P>I'm sorry, I'm not sure what you mean by this?</P>
<P> </P>
<PRE> 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</PRE>
<P>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:</P>
<PRE> //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</PRE>Tue, 29 Sep 2015 12:47:03 GMThttps://forums.xilinx.com/t5/General-Technical-Discussion/How-best-to-do-inner-product-of-two-vectors/m-p/657518#M35786garengllc2015-09-29T12:47:03ZRe: How best to do inner product of two vectors
https://forums.xilinx.com/t5/General-Technical-Discussion/How-best-to-do-inner-product-of-two-vectors/m-p/657560#M35787
<P>wooshh, answer deleted because it was ignored.</P>Sat, 31 Oct 2015 03:42:22 GMThttps://forums.xilinx.com/t5/General-Technical-Discussion/How-best-to-do-inner-product-of-two-vectors/m-p/657560#M35787morgan1985102015-10-31T03:42:22Z