void MAT_Multiply(int *A, int *B, long *C, unsigned int mA, unsigned int nA, unsigned int mB, unsigned int nB, unsigned int mC, unsigned int nC) { #pragma HLS INTERFACE ap_fifo depth=100 port=A #pragma HLS INTERFACE ap_fifo depth=100 port =B #pragma HLS INTERFACE ap_fifo depth=100 port =C int arrayA[1000][1000]; #pragma HLS ARRAY_RESHAPE variable=arrayA complete dim=2 #24 "partB/matrixmath.c" int arrayB[1000][1000]; #pragma HLS ARRAY_RESHAPE variable=arrayB complete dim=1 #25 "partB/matrixmath.c" long arrayC[1000][1000]; long temp; unsigned int i, j, k; if ((nA == mB)&(mA == mC)&(nB==nC))//Multiplication only when the dimensions are suitable { load_mat(A,arrayA,mA,nA); load_mat(B,arrayB,mB,nB); Row: for (i=0; i<1000; i++) Col: for (j=0; j<1000; j++) { arrayC[i][j] = 0; Product: for (k=0; k<1000; k++) { #pragma HLS PIPELINE #41 "partB/matrixmath.c" if ((i<mC)&(j<nC)) { if (k<nA) arrayC[i][j] += arrayA[i][k] * arrayB[k][j]; } } } //Assignment Row_Assign: for (i=0; i<1000; i++) Col_Assign: for (j=0; j<1000; j++) { #pragma HLS PIPELINE #54 "partB/matrixmath.c" if ((i<mC)&(j<nC)) { C[i*1000 +j] = arrayC[i][j]; } } } }
void MAT_Multiply(int *A, int *B, long *C, unsigned int mA, unsigned int nA, unsigned int mB, unsigned int nB, unsigned int mC, unsigned int nC) { #pragma HLS INTERFACE ap_fifo depth=3 port=A #pragma HLS INTERFACE ap_fifo depth=3 port =B #pragma HLS INTERFACE ap_fifo depth=3 port =C #pragma empty_line int arrayA[50][50]; int arrayB[50][50]; long arrayC[50][50]; long temp; #pragma empty_line unsigned int i, j, k; if ((nA == mB)&(mA == mC)&(nB==nC)) { load_mat(A,arrayA,mA,nA); load_mat(B,arrayB,mB,nB); #pragma empty_line #pragma empty_line Row: for (i=0; i<50; i++) Col: for (j=0; j<50; j++) { arrayC[i][j] = 0; Product: for (k=0; k<50; k++) { if ((i<mC)&(j<nC)) { if (k<nA) arrayC[i][j] += arrayA[i][k] * arrayB[k][j]; } } } #pragma empty_line #pragma empty_line #pragma empty_line Row_Assign: for (i=0; i<50; i++) Col_Assign: for (j=0; j<50; j++) { if ((i<mC)&(j<nC)) { C[i*50 +j] = arrayC[i][j]; } } #pragma empty_line } }
void MAT_Multiply(int *A, int *B, long *C, unsigned int mA, unsigned int nA, unsigned int mB, unsigned int nB, unsigned int mC, unsigned int nC) { #pragma HLS INTERFACE ap_fifo port =A #pragma HLS INTERFACE ap_fifo port =B #pragma HLS INTERFACE ap_fifo port =C int arrayA[100][100]; int arrayB[100][100]; long arrayC[100][100]; long temp; unsigned int i, j, k; if ((nA == mB)&(mA == mC)&(nB==nC)) { load_mat(A,arrayA,mA,nA); load_mat(B,arrayB,mB,nB); Row: for (i=0; i<100; i++) Col: for (j=0; j<100; j++) { arrayC[i][j] = 0; Product: for (k=0; k<100; k++) { if ((i<mC)&(j<nC)) { if (k<nA) arrayC[i][j] += arrayA[i][k] * arrayB[k][j]; } } } Row_Assign: for (i=0; i<100; i++) Col_Assign: for (j=0; j<100; j++) { if ((i<mC)&(j<nC)) { C[i*100 +j] = arrayC[i][j]; } } } }
int load_scene_open(t_prog *prog, char *str) { char **file; t_coord dir; if (((file = str_to_wordtab(str, "\n")) == NULL) || (load_scene_open_beg(prog, file))) return (-1); prog->cam_fov.y = prog->cam_fov.x * ((prog->win_size.x / prog->win_size.y) / 1.5); if (get_cam_pos(file, prog) == 1 || get_cam_look_at(file, prog) == 1 || load_mat(prog, file) == -1 || load_light(prog, file) == -1 || load_obj(prog, file) == -1) return (-1); if (prog->look_at.x == prog->cam_pos.x && prog->look_at.y == prog->cam_pos.y && prog->look_at.z == prog->cam_pos.z) return (my_printf(2, "Wrong camera placement\n") - 1); dir = normalize(minus_point(prog->look_at, prog->cam_pos)); prog->cam_rot.x = RTD(acos(-(dir.z / sqrt(pow(dir.x, 2) + pow(dir.z, 2))))) - 90; prog->cam_rot.y = RTD((M_PI / 2 - acos(dir.y))); prog->cam_dir = normalize(minus_point(prog->look_at, prog->cam_pos)); free_tab(file); return (0); }
/* * Loads the first dataset into a matrix structure */ static int load_real_ball_data(int dataset, int numSet) { int numCols; static char fileName[100]; static char dirName[100]; if (dataset == 1) { sprintf(dirName, "../../Desktop/okanKinestheticTeachin_20141210"); numCols = 25; dist_to_table = -0.80; } else if (dataset == 2) { sprintf(dirName, "../../Desktop/okanKinestheticTeachin_20151124"); numCols = 25 + 6; // cartesian robot pos and vel also saved for this dataset dist_to_table = -1.15; } else { printf("Dataset not found!\n"); return FALSE; } static char savefile[] = "unifyData"; sprintf(fileName,"%s//%s%d.txt",dirName, savefile, numSet); int numRows = read_row_size(fileName); realBallData = my_matrix(1,numRows,1,numCols); if (load_mat(realBallData,numRows,numCols,fileName)) //print_mat_size("ballData", realBallData, numRows, 5); return TRUE; return FALSE; }
// load params void load_params(FILE* ifile, int max_examples) { if ((max_examples < 0) || (max_examples > (int) n_examples)) max_examples = n_examples; for(auto w : param_matrices) { // we only load the whole matrics here LOG(trace) << "load params " << "max_examples=" << max_examples << " cols(w)=" << w->n_cols; assert(max_examples == (int) w->n_cols); LOG(trace) << "load one param matrix"; load_mat(ifile, *w); } }
int main(int argc, char ** argv) { int t, j, k, n, sum; int * mat; int * best; int run_number, runs_max; srand(time(NULL)); if(argc < 3) n = 15; else n = atoi(argv[2]); if(argc < 2) mat = load_mat("euler345_matrix.txt", n); else mat = load_mat(argv[1], n); best = (int *) malloc(n * sizeof(best[0])); for(j = 0; j < n; j++) best[j] = j; runs_max = INT_MIN; for(run_number = 0; run_number < n * n; run_number++) { for(t = 0; t < n; t++) { int temp; j = rand() % (n - 1); k = j + 1 + rand() % (n - j - 1); temp = best[j]; best[j] = best[k]; best[k] = temp; } for(t = 0; t < n; t++) { for(j = 0; j < n; j++) { for(k = j + 1; k < n; k++) { if(mat[k * n + best[j]] + mat[j * n + best[k]] > mat[j * n + best[j]] + mat[k * n + best[k]]) { int temp = best[j]; best[j] = best[k]; best[k] = temp; } } } } sum = 0; for(j = 0; j < n; j++) { //printf("%d\n", mat[j * n + best[j]]); sum += mat[j * n + best[j]]; } if(sum > runs_max) runs_max = sum; } printf("Matrix sum: %d\n", runs_max); return 0; }
void SpinAdapted::Load(Matrix& a, std::ifstream &ifs) { boost::archive::binary_iarchive load_mat(ifs); load_mat >> a; }