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_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_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; }
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; }
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; }
void work_func(const random_generator_ptr& rng) { boost::random::uniform_int_distribution<> wait_flag(0, 1); for (std::size_t i = 0; i != work_cycle_count; ++i) { const foo_ptr f = foo::get_instance(); BOOST_ASSERT_MSG(f, "Instance has to exist"); if (wait_flag(*rng)) { boost::this_thread::sleep(boost::posix_time::milliseconds(1)); } (void) f; } }
//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; }
void *reader(void *dummy) { int i; wait_flag(&wflag, NTHR); for (i = 0; i < NITER; i++) { tbb_start_read(&rwlock); /*rcnt++;*/ assert(shared[1] == shared[0]); assert(shared[1] == shared[2]); /*rcnt--;*/ tbb_end_read(&rwlock); } }
void *writer(void *dummy) { int i; wait_flag(&wflag, NTHR); for (i = 0; i < NITER; i++) { tbb_start_write(&rwlock); /*wcnt++;*/ shared[0]++; shared[1]++; shared[2]++; /*wcnt--;*/ tbb_end_write(&rwlock); } }
int __cdecl main(int argc, char *argv[]) { int rc=0; int sent = 0; int received = 0; int total_loop=0; char *ptr2; FILE *pfile; xillybus_init(); wait_flag(ADDR01, RDY); //FilesizeA = read_flag(ADDR03); FilesizeA = 67108864; //printf("\nHostPC RX will receive %d Bytes.", FilesizeA); ptr2 = (char *)malloc(FilesizeA); while (received < FilesizeA) { rc = _read(fdr, ptr2 + received, FilesizeA - received); 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(1); break; } received += rc; } //printf("\nHostPC RX has completed."); if((pfile=fopen("outputfile.cpcie","wb"))==NULL){ printf("\nUnable to open file output"); exit(1); } //printf("\noutputfile.cpcie has been written."); fwrite(ptr2,received,1,pfile); fclose(pfile); free(ptr2); //xillybus_close(); return 0; xillybus_init(); //printf("\nHostPC RX will receive %d Bytes.", FilesizeA); //FilesizeA = 4194304; ptr2 = (char *)malloc(FilesizeA); while (received < FilesizeA) { rc = _read(fdr, ptr2 + received, FilesizeA - received); 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(1); break; } received += rc; } //printf("\nHostPC RX has completed."); if((pfile=fopen("outputfile.cpcie","wb"))==NULL){ printf("\nUnable to open file output"); exit(1); } //printf("\noutputfile.cpcie has been written."); fwrite(ptr2,received,1,pfile); fclose(pfile); free(ptr2); return 0; }
static int do_test (int argc, char *argv[]) { char name[] = "/tmp/aio4.XXXXXX"; int fd; struct aiocb *arr[1]; struct aiocb cb; static const char buf[] = "Hello World\n"; struct aioinit init = {10, 20, 0}; struct sigaction sa; struct sigevent ev; if (SIGRTMIN == -1) { printf ("RT signals not supported.\n"); return 0; } /* Select a signal from the middle of the available choices... */ my_signo = (SIGRTMAX + SIGRTMIN) / 2; fd = mkstemp (name); if (fd == -1) { printf ("cannot open temp name: %m\n"); return 1; } unlink (name); /* Test also aio_init. */ aio_init (&init); arr[0] = &cb; cb.aio_fildes = fd; cb.aio_lio_opcode = LIO_WRITE; cb.aio_reqprio = 0; cb.aio_buf = (void *) buf; cb.aio_nbytes = sizeof (buf) - 1; cb.aio_offset = 0; cb.aio_sigevent.sigev_notify = SIGEV_SIGNAL; cb.aio_sigevent.sigev_notify_function = NULL; cb.aio_sigevent.sigev_notify_attributes = NULL; cb.aio_sigevent.sigev_signo = my_signo; cb.aio_sigevent.sigev_value.sival_ptr = NULL; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_notify_function = NULL; ev.sigev_notify_attributes = NULL; ev.sigev_signo = my_signo; sa.sa_handler = sighandler; sigemptyset (&sa.sa_mask); sa.sa_flags = SA_RESTART; if (sigaction (my_signo, &sa, NULL) < 0) { printf ("sigaction failed: %m\n"); return 1; } flag = 0; /* First use aio_write. */ if (aio_write (arr[0]) < 0) { if (errno == ENOSYS) { puts ("no aio support in this configuration"); return 0; } printf ("aio_write failed: %m\n"); return 1; } if (wait_flag ()) return 1; puts ("aio_write OK"); flag = 0; /* Again with lio_listio. */ if (lio_listio (LIO_NOWAIT, arr, 1, &ev) < 0) { printf ("lio_listio failed: %m\n"); return 1; } if (wait_flag ()) return 1; puts ("all OK"); return 0; }
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; }