3 #include "structures.h"
4 #include "lib_snake_2_gpu.h"
8 void snake2gpu( snake_node_gpu * d_snake, snake_node* h_snake, int n ){
10 snake_node * snake = h_snake;
11 snake_node_gpu snake_nodes[n];
13 for (int i=0; i<n; i++){
15 snake_nodes[i].sum_1 = snake->contrib.sum_1 ;
16 snake_nodes[i].sum_x = snake->contrib.sum_x ;
17 snake_nodes[i].sum_x2 = snake->contrib.sum_x2 ;
19 snake_nodes[i].code_segment = snake->code_segment ;
20 snake_nodes[i].freeman_in = snake->freeman_in ;
21 snake_nodes[i].freeman_out = snake->freeman_out ;
22 snake_nodes[i].nb_pixels = snake->nb_pixels ;
24 snake_nodes[i].posi = snake->posi ;
25 snake_nodes[i].posj = snake->posj ;
26 snake_nodes[i].centre_i = snake->centre_i ;
27 snake_nodes[i].centre_j = snake->centre_j ;
29 snake_nodes[i].last_move = snake->last_move ;
31 snake = snake->noeud_suiv ;
34 cudaMemcpy( d_snake, snake_nodes, n*sizeof(snake_node_gpu), cudaMemcpyHostToDevice );
36 /*verif integrite data*/
38 snake_node_gpu new_snake_nodes[n];
39 cudaMemcpy( new_snake_nodes , d_snake, n*sizeof(snake_node_gpu), cudaMemcpyDeviceToHost );
41 for (int i=0; i<n; i++){
42 printf("NODE %d : ", i);
43 printf("\tsum_1 : %u - sum_x : %lu - sum_x2 : %lu\n", new_snake_nodes[i].sum_1, new_snake_nodes[i].sum_x , new_snake_nodes[i].sum_x2) ;
45 printf("\tcode_segment : %d\n", new_snake_nodes[i].code_segment ) ;
46 printf("\tfreeman_in : %d\n", new_snake_nodes[i].freeman_in );
47 printf("\tfreeman_out : %d\n", new_snake_nodes[i].freeman_out ) ;
48 printf("\tnb_pixels : %d\n", new_snake_nodes[i].nb_pixels ) ;
50 printf("\ti = %d\n", new_snake_nodes[i].posi ) ;
51 printf("\tj = %d\n", new_snake_nodes[i].posj ) ;
52 printf("\tcentre i = %d\n", new_snake_nodes[i].centre_i ) ;
53 printf("\tcentre j = %d\n", new_snake_nodes[i].centre_j ) ;
55 printf("\tlast_move : %d\n", new_snake_nodes[i].last_move ) ;
62 void gpu2snake( snake_node_gpu * d_snake, snake_node **h_snake, int n ){
64 snake_node *snake_prec, *snake ;
65 snake_node_gpu * snake_nodes = new snake_node_gpu[n];
66 cudaMemcpy( snake_nodes, d_snake, n*sizeof(snake_node_gpu), cudaMemcpyDeviceToHost );
68 *h_snake = new snake_node;
70 for (int i=0; i<n; i++){
71 if (i == 0 ) snake = *h_snake;
74 snake = new snake_node;
75 snake_prec->noeud_suiv = snake;
76 snake->noeud_prec = snake_prec;
79 snake->noeud_suiv = *h_snake;
80 (*h_snake)->noeud_prec = snake;
83 snake->contrib.sum_1 = snake_nodes[i].sum_1 ;
84 snake->contrib.sum_x = snake_nodes[i].sum_x ;
85 snake->contrib.sum_x2 = snake_nodes[i].sum_x2 ;
87 snake->code_segment = snake_nodes[i].code_segment ;
88 snake->freeman_in = snake_nodes[i].freeman_in ;
89 snake->freeman_out = snake_nodes[i].freeman_out ;
91 snake->nb_pixels = snake_nodes[i].nb_pixels ;
92 snake->posi = snake_nodes[i].posi ;
93 snake->posj = snake_nodes[i].posj ;
95 snake->centre_i = snake_nodes[i].centre_i ;
96 snake->centre_j = snake_nodes[i].centre_j ;
97 snake->last_move = snake_nodes[i].last_move ;
101 /*verif integrite donnees*/
104 for (int i=0; i<n; i++){
105 printf("NODE %d : ", i);
107 printf("\tcode_segment : %d\n", snake->code_segment ) ;
108 printf("\tfreeman_in : %d\n", snake->freeman_in );
109 printf("\tfreeman_out : %d\n", snake->freeman_out ) ;
111 printf("\tnb_pixels : %d", snake->nb_pixels ) ;
113 printf("\ti = %d ", snake->posi ) ;
114 printf("\tj = %d \n", snake->posj ) ;
116 printf("\tcentre i = %d\n", snake->centre_i ) ;
117 printf("\tcentre j = %d\n", snake->centre_j ) ;
119 printf("\tcontribs = %lu - %lu - %lu\n", snake->contrib.sum_1, snake->contrib.sum_x, snake->contrib.sum_x2 ) ;
121 printf("\tlast_move : %d\n", snake->last_move ) ;
123 snake = snake->noeud_suiv;