forked from Firmware/Firmwares
		
	restructure for parallel execution
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							| @@ -16,17 +16,40 @@ bool double_equals(double a, double b, double epsilon = 0.001) | |||||||
|     return std::abs(a - b) < epsilon; |     return std::abs(a - b) < epsilon; | ||||||
| } | } | ||||||
|  |  | ||||||
| void run_xspn() { | void run_xspn(int in_addr, int out_addr) { | ||||||
| 	spn::mode_reg() = 0; | 	spn::mode_reg() = 0; | ||||||
| 	spn::input_length_reg() = 100; 		// each sample consists of 5 uint8 values | 	spn::input_length_reg() = 500; 		// each sample consists of 5 uint8 values | ||||||
| 	spn::input_addr_reg() = 0x800C0000; | 	spn::input_addr_reg() = in_addr; | ||||||
| 	spn::output_addr_reg() = 0x800A0000; | 	spn::output_addr_reg() = out_addr; | ||||||
| 	spn::num_of_in_beats_reg() = 8;		// Number of AXI4 burst beats needed to load all input data | 	spn::num_of_in_beats_reg() = 40;		// Number of AXI4 burst beats needed to load all input data | ||||||
| 	spn::num_of_out_beats_reg() = 13;	// Number of AXI4 burst beats needed to store all result data | 	spn::num_of_out_beats_reg() = 64;	// Number of AXI4 burst beats needed to store all result data | ||||||
| 	spn::start_reg() = 1; | 	spn::start_reg() = 1; | ||||||
|  | } | ||||||
|  |  | ||||||
| 	wait_for_interrupt(); | void load_input_data(int addr, const int k=0) { | ||||||
| 	spn::interrupt_reg() = 1; |     int * mem_base = (int *) addr; | ||||||
|  | 	int offset = k * 5; | ||||||
|  |  | ||||||
|  | 	for (size_t i = 0, j = 0; j < 625; i += 4, j++) { // load 5000 samples | ||||||
|  | 		*(mem_base + j) = input_data.at(offset + i); | ||||||
|  | 		*(mem_base + j) |= (input_data.at(offset + i + 1) << 8) & 0x0000FF00; | ||||||
|  | 		*(mem_base + j) |= (input_data.at(offset + i + 2) << 16) & 0x00FF0000; | ||||||
|  | 		*(mem_base + j) |= (input_data.at(offset + i + 3) << 24) & 0xFF000000; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool check_results(int addr, int k) { | ||||||
|  | 	bool result = 0; | ||||||
|  | 	int  step = 500; | ||||||
|  | 	double *res_base = (double*) (addr); | ||||||
|  | 	for (int i = 0; i < step; i++) { | ||||||
|  | 		if (!double_equals(res_base[i] * ln2, ref_data.at(k + i))) { | ||||||
|  | 			printf("XSPN ref %d comparison FAILED\n", k + i); | ||||||
|  | 			result = 1; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |     printf("Compared samples %d - %d with the reference\n", k, k+step); | ||||||
|  | 	return result; | ||||||
| } | } | ||||||
|  |  | ||||||
| /*! \brief main function | /*! \brief main function | ||||||
| @@ -34,37 +57,33 @@ void run_xspn() { | |||||||
|  */ |  */ | ||||||
| int main() { | int main() { | ||||||
|     platform_init(); |     platform_init(); | ||||||
|  |     int ret_val = 0; | ||||||
|  |  | ||||||
|     spn::mode_reg() = 1; |     spn::mode_reg() = 1; | ||||||
|     spn::start_reg() = 1; |     spn::start_reg() = 1; | ||||||
| 	wait_for_interrupt(); | 	wait_for_interrupt(); | ||||||
|     spn::interrupt_reg() = 1; |     spn::interrupt_reg() = 1; | ||||||
|     printf("READOUT HW:0x%x\n", spn::readout_reg()); |     printf("READOUT HW:0x%x\n", spn::readout_reg()); | ||||||
|  |  | ||||||
| 	for (int k = 0; k < 10000; k+=100) { | 	int in_addr  = 0x800C0000; | ||||||
|         // write input samples into the memory | 	int out_addr = 0x800A0000; | ||||||
|         int * mem_base = (int *) 0x800C0000; |     load_input_data(in_addr); | ||||||
|         int offset = k * 5; |  | ||||||
|  |  | ||||||
|         for(size_t i = 0, j = 0; j < 125; i += 4, j++) { |     int step = 500; // number of samples to be process at once | ||||||
|         	*(mem_base+j) = input_data.at(offset+i); |     for (int k = 0; k < 10000; k+=step) { | ||||||
|         	*(mem_base+j) |= (input_data.at(offset+i+1) << 8)  & 0x0000FF00; |  | ||||||
|         	*(mem_base+j) |= (input_data.at(offset+i+2) << 16) & 0x00FF0000; |  | ||||||
|         	*(mem_base+j) |= (input_data.at(offset+i+3) << 24) & 0xFF000000; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         printf("XSPN process samples %d - %d\n", k, k+100); |         run_xspn(in_addr, out_addr); | ||||||
|     	run_xspn(); |         printf("XSPN processes samples %d - %d\n", k, k+step); | ||||||
|  |  | ||||||
|     	// read calculation results from the memory |         // pre-load data for the next run while HW accelerator is running | ||||||
|         double * res_base = (double*) 0x800A0000; |         if(k<(10000-step)) | ||||||
|  |             load_input_data(in_addr, k+step); | ||||||
|  |  | ||||||
|         for (int i = 0; i < 100; i++) { |         wait_for_interrupt(); | ||||||
|             if (!double_equals(res_base[i] * ln2, ref_data.at(k+i))) { |     	spn::interrupt_reg() = 1; | ||||||
|                 printf("XSPN ref %d comparison FAILED\n", k+i); |  | ||||||
|             } |  | ||||||
|     	} |  | ||||||
|  |  | ||||||
|  | 		ret_val = check_results(out_addr, k); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return 0; | 	return ret_val; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user