cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor
Contributor
988 Views
Registered: ‎11-10-2017

Execution time greatly differs between the first and second times

Hi all, I made standalone design with Zynq.

I high-level-synthesized code to calculate matrix product.

The code is following.

 

#include <string.h>
#define P 32
int matrixmul(int pa[P][P],int b[P][P],int pc[P][P]){
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE m_axi port=pa offset=slave bundle=bundle_a
#pragma HLS INTERFACE s_axilite port=b bundle=bundle_b
#pragma HLS INTERFACE m_axi port=pc offset=slave bundle=bundle_a
	int a[P][P];
	int c[P][P];
	memcpy(a, pa, sizeof(int) * 1024);
  int i,j,k;
  for (i = 0; i < P; i++){
    for (j = 0; j < P; j++){
      c[i][j] = 0;
      for (k = 0; k < P; k++){
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
	memcpy(pc, c, sizeof(int) * 1024);
  return 0;
}

And I connect HW module to Zynq.

 

design

 

I measured three execution time.

1. time to calculate matrix product on HW and detect completion using interrupt

2. time to calculate matrix product on HW and detect completion using polling

3. time to calculate matrix product on SW.

 

I executed some times. The result greatly differs between the first time and second times.

(the result shows not time but clock cycle)

 

Hello! matrixmul
hard interr time: 1811700
hard poling time: 1788774
soft time       : 1150352
end matrixmul

Hello! matrixmul
hard interr time: 30510
hard poling time: 3570196
soft time       : 1150432
end matrixmul

Hello! matrixmul
hard interr time: 30640
hard poling time: 3570270
soft time       : 1150516

 

Q1: Why interrupt time becomes very shorter in second time?

Q2: Why polling time becomes longer in second time ?

 

The SW code to measure execution time is attached.

 

Thanks.

 

0 Kudos
4 Replies
Highlighted
Scholar
Scholar
980 Views
Registered: ‎03-22-2016

Re: Execution time greatly differs between the first and second times

@nittax What happens if: 

1. You comment out Xil_DCacheDisable() in line 46

2. You switch the order of matrixmul_interrupt and matrixmul? Perhaps make it like matrixmul, matrixmul_interrupt, matrixmul, matrixmul_interrupt

3. You store matrices a, b, c in BRAM or OCM (you can get their addressed in the editor)?

 

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
0 Kudos
Highlighted
Contributor
Contributor
971 Views
Registered: ‎11-10-2017

Re: Execution time greatly differs between the first and second times

@hbucher Sorry I don't understand much. It means I could not measure execution time correctly in my way?

0 Kudos
Highlighted
Scholar
Scholar
965 Views
Registered: ‎03-22-2016

Re: Execution time greatly differs between the first and second times

@nittax  I am just proposing that you make some modifications (3) in your code and rerun to see if the new results can give you some insight. 

Despite the fact that you disabled cache, I believe it is still an issue.

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
0 Kudos
Highlighted
Scholar
Scholar
862 Views
Registered: ‎03-22-2016

Re: Execution time greatly differs between the first and second times

@nittax  I came back to this thread because it really caught my attention. 

I believe there is a bug in your interrupt code. 

You set matrixmul_done=0 in the initialization but never elsewhere. 

I believe as you run matrixmul() before the interrupt version, the ISR gets called and sets the matrixmul_done=1. When you run the interrupt version, matrixmul_done is already set so it goes through without blocking.

You should set matrixmul_done to zero every time matrixmul_interrupt() executes. 

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
0 Kudos