int HostPC_to_HwAcc_to_SDRAM_1_file() { int FilesizeH; clear_flag(); wait_flag(ADDR01, REQ); printf("\nA"); send_flag(ADDR00, RDY); FilesizeH = hostpc_tx_size(matrix_UA); printf("\nFilesizeH: %d", FilesizeH); hostpc_tx_file(FilesizeH); printf("\nB"); /* FilesizeH = hostpc_tx_size(matrix_UA); hostpc_tx_file(FilesizeH); */ wait_flag(ADDR01, FIN); send_flag(ADDR00, ACK); wait_flag(ADDR01, NCN); printf("\nC"); clear_flag(); xillybus_close(); return 0; }
int Test_SDRAM_to_HwAcc_to_HostPC() { struct packet fiforead; HANDLE Handle_Of_Thread_1 = 0; // variable to hold handle of Thread 1 wait_flag(ADDR01, REQ); FilesizeUse = hostpc_rx_size(); printf("\nHostPC will receive %d Bytes from FPGA.", FilesizeUse); send_flag(ADDR00, RDY); // Create thread 1: Read Handle_Of_Thread_1 = CreateThread(NULL, 0, hostpc_rx_file, &fiforead, 0, NULL); if (Handle_Of_Thread_1 == NULL) { errorprint("Failed to create thread 1\n", GetLastError()); exit(1); } printf("\nThread 1 creation completed."); WaitForSingleObject(Handle_Of_Thread_1, INFINITE); CloseHandle(Handle_Of_Thread_1); wait_flag(ADDR01, FIN); send_flag(ADDR00, ACK); wait_flag(ADDR01, NCN); clear_flag(); // All flag from HostPC must be cleared before exit xillybus_close(); return 0; }
int Test_HostPC_to_SDRAM() { int FilesizeH; clear_flag(); FilesizeH = hostpc_tx_size(matrix_UA); send_flag(ADDR02, FilesizeH); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); /* FilesizeH = hostpc_tx_size(matrix_UB); send_flag(ADDR02, FilesizeH); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); */ xillybus_close(); return 0; }
int Test_throughput_power() { int FilesizeH; //DWORD dwStartTime; //DWORD dwElapsed; clear_flag(); FilesizeH = hostpc_tx_size(matrix_UA); send_flag(ADDR02, FilesizeH); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); //dwStartTime = GetTickCount(); hostpc_tx_file(FilesizeH); //dwElapsed = GetTickCount() - dwStartTime; //printf("It took %d.%3d seconds to complete\n", dwElapsed/1000, dwElapsed - dwElapsed/1000); send_flag(ADDR00, FIN); wait_flag(ADDR01, NCN); clear_flag(); printf("\nFinish!"); clear_flag(); xillybus_close(); return 0; }
int Test_HostPC_to_HwAcc_to_HostPC_1_file() { struct packet fiforead; struct packet fifowriteA; HANDLE Handle_Of_Thread_1 = 0; // variable to hold handle of Thread 1 HANDLE Handle_Of_Thread_2 = 0; // variable to hold handle of Thread 2 HANDLE Array_Of_Thread_Handles[2]; // Aray to store thread handles clear_flag(); wait_flag(ADDR01, REQ); FilesizeUse = hostpc_rx_size(); FilesizeA = hostpc_tx_sizeA(matrix_UA); //printf("\nFilesizeA: %d", FilesizeA); send_flag(ADDR00, REQ); // Create thread 1: Read Handle_Of_Thread_1 = CreateThread(NULL, 0, hostpc_rx_file, &fiforead, 0, NULL); if (Handle_Of_Thread_1 == NULL) { errorprint("Failed to create thread 1\n", GetLastError()); exit(1); } //printf("\nThread 1 creation completed."); // Create thread 2: Write Matrix A and B Handle_Of_Thread_2 = CreateThread(NULL, 0, hostpc_tx_fileA, &fifowriteA, 0, NULL); if (Handle_Of_Thread_2 == NULL) { errorprint("Failed to create thread 2\n", GetLastError()); exit(1); } //printf("\nThread 2 creation completed."); // Store Thread handles in Array of Thread Handles as per the requirement of WaitForMultipleObjects() Array_Of_Thread_Handles[0] = Handle_Of_Thread_1; Array_Of_Thread_Handles[1] = Handle_Of_Thread_2; // Wait until all threads have terminated. WaitForMultipleObjects(2, Array_Of_Thread_Handles, TRUE, INFINITE); // Close all thread handles upon completion. CloseHandle(Handle_Of_Thread_1); CloseHandle(Handle_Of_Thread_2); //printf("\nAll threads are closed now."); wait_flag(ADDR01, ACK); send_flag(ADDR00, ACK); //printf("\nFinish!"); return 0; }
//int Test_HostPC_decompress_to_SDRAM_1_file() int decompress(char matrix_UA, char output_UA) { clear_flag(); send_flag(ADDR00, REQD); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); xillybus_close(); //return 0; return output_UA; }
//int Test_HostPC_to_SDRAM_1_file() int compress(char matrix_UA, int FilesizeH, int threshold, char output_UA) { int FilesizeH; clear_flag(); FilesizeH = hostpc_tx_size(matrix_UA); send_flag(ADDR02, FilesizeH); send_flag(ADDR02, threshold); send_flag(ADDR00, REQC); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); xillybus_close(); //return 0; return output_UA; }
DWORD WINAPI hostpc_tx_file_mat_mult(LPVOID arg) { FilesizeUse = hostpc_tx_size(matrix_UA); send_flag(ADDR02, FilesizeUse); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeUse); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); printf("\nMatrix A has been transferred."); FilesizeUse = hostpc_tx_size(matrix_UB); send_flag(ADDR02, FilesizeUse); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeUse); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); printf("\nMatrix B has been transferred."); return 0; }
void sig_handler(){ pthread_mutex_unlock(&tmutex); send_flag(gsock, "You've won Charlie!\n"); close(gsock); pthread_exit(NULL); }
int __cdecl main(int argc, char *argv[]) { int rc=0; int sent = 0; int received = 0; int ijk; int total_loop=0; unsigned char *buf; int donebytes; //clock_t t; /* time_t start,end; double dif; */ DWORD dwStartTime; DWORD dwElapsed; xillybus_init(); clear_flag(); send_flag(ADDR00, FIN); matrix_UA = (argv[1]); total_loop = atoi(argv[2]); FilesizeA = hostpc_tx_sizeA(matrix_UA); buf = (char *) malloc(FilesizeA); //send_flag(ADDR03, FilesizeA); send_flag(ADDR03, 4096); send_flag(ADDR00, REQ); //t = clock(); while (1) { rc = _read(fhA, buf, FilesizeA); rc += 4; // tupple of 4 if ((rc < 0) && (errno == EINTR)) continue; if (rc < 0) { perror("allread() failed to read"); exit(1); } if (rc == 0) { fprintf(stderr, "Reached read EOF.\n"); exit(0); } allwritex(fdw, buf, rc); break; } //t = clock() - t; //printf ("%d ticks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC); send_flag(ADDR00, FIN); _close(fhA); free(buf); //xillybus_close(); return 0; //char *to_pcie_file; // unreferenced local variables /* char *loopback_File; int FilesizeH; int FilesizeC; int FilesizeL; */ xillybus_init(); // unreferenced local variable /* FilesizeH = 0; FilesizeC = 0; */ //printf("\nADDR00: %08X\n", read_flag(ADDR00)); //printf("\nADDR01: %08X\n", read_flag(ADDR01)); //printf("\nADDR02: %08X\n", read_flag(ADDR02)); //printf("\nADDR03: %08X\n", read_flag(ADDR03)); clear_flag(); matrix_UA = (argv[1]); total_loop = atoi(argv[2]); //printf("\nSTART> total_loop: %d\n", total_loop); FilesizeA = hostpc_tx_sizeA(matrix_UA); buf = (char *) malloc(FilesizeA); donebytes = 0; send_flag(ADDR02, FilesizeA); send_flag(ADDR00, REQ); //wait_flag(ADDR01, RDY); //printf("\n1\n"); while (1) { rc = _read(fhA, buf, FilesizeA); rc += 4; // tupple of 4 if ((rc < 0) && (errno == EINTR)) continue; if (rc < 0) { perror("allread() failed to read"); exit(1); } if (rc == 0) { fprintf(stderr, "Reached read EOF.\n"); exit(0); } allwritex(fdw, buf, rc); break; //printf("\n2\n"); } //printf("\n>>> (hostpc_tx_fileA) File %d Bytes transferred\n", FilesizeA); send_flag(ADDR00, FIN); //wait_flag(ADDR01, NCN); _close(fhA); free(buf); return 0; /* _close(fhA); xillybus_close(); return 0; */ // Function of sending from SDRAM(FPGA) to HostPC /* wait_flag(ADDR01, REQ); FilesizeC = hostpc_rx_size(); send_flag(ADDR00, RDY); wait_flag(ADDR01, FIN); hostpc_rx_file(FilesizeC); send_flag(ADDR00, ACK); wait_flag(ADDR01, NCN); clear_flag(); // All flag from HostPC must be cleared before exit xillybus_close(); return 0; */ /* hostpc_tx_file_mat_mult(NULL); printf("\nC2"); xillybus_close(); clear_flag(); return 0; */ /* wait_flag(ADDR01, REQ); printf("\nHWACC is ready to accept data."); send_flag(ADDR00, RDY); */ //Test_throughput_power(); //Test_HostPC_to_SDRAM(); // OK //Test_HostPC_Loopback(); // OK //Test_SDRAM_to_HostPC(); // OK //Test_SDRAM_to_HwAcc_to_HostPC(); // OK //Test_HostPC_to_SDRAM_1_file(); // OK //HostPC_to_HwAcc_to_SDRAM_1_file(); // OK //Test_HostPC_to_SDRAM_to_HwAcc_to_HostPC(); // OK //HostPC_to_HwAcc_to_SDRAM(); //Test_HostPC_decompress_to_SDRAM_1_file(); return 0; //printf("\nA\n"); send_flag(ADDR04, NCN); //printf("\nB\n"); wait_flag(ADDR01, RDY); //printf("\nC\n"); send_flag(ADDR00, RDY); //printf("\nD\n"); //time (&start); dwStartTime = GetTickCount(); for (ijk=total_loop-1; ijk>=0; --ijk) { send_flag(ADDR04, ijk); Test_HostPC_to_HwAcc_to_HostPC_1_file(); } //time (&end); dwElapsed = GetTickCount() - dwStartTime; //printf("\nE\n"); //dif = difftime (end,start); //printf ("\nTime taken is: %.2lf\n", dif); printf("It took %d.%3d seconds to complete\n", dwElapsed/1000, dwElapsed - dwElapsed/1000); printf("\nFINISH\n"); send_flag(ADDR04, NCN); wait_flag(ADDR01, NCN); clear_flag(); xillybus_close(); /* clear_flag(); xillybus_close(); */ return 0; }