Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. A: number of elements: 560
  2. B: number of elements: 560
  3. B: number of elements: 0
  4. B: number of elements: 0
  5. B: number of elements: 0
  6. C: number of elements: 0
  7.  
  8. cout << "A: number of elements: " << combinations.size() << endl;
  9. float sum_vect[120][2];
  10. for (int i = 0; i < combinations.size(); ++i) {
  11. for (int j = 0; j < 2; ++j) {
  12. sum_vect[i][j] = 0;
  13. }
  14. }
  15. cout << "B: number of elements: " << combinations.size() << endl;
  16. cout << "B: number of elements: " << combinations.size() << endl;
  17. cout << "B: number of elements: " << combinations.size() << endl;
  18. cout << "B: number of elements: " << combinations.size() << endl;
  19.  
  20. for (int i = 0; i < combinations.size(); ++i) {
  21. combination = combinations.at(i);
  22. for (int j = 0; j < order; ++j) {
  23. sum_vect[i][0] += (float)virtual_pos[combination[j]][0];
  24. sum_vect[i][1] += (float)virtual_pos[combination[j]][1];
  25. }
  26. }
  27.  
  28. vector<int> optimal_ind;
  29. cout << "C: number of elements: " << combinations.size() << endl;
  30.  
  31. void nchoosek_helper(int offset, int n, int k, vector<vector<int>> &combinations, vector<int> combination) {
  32. if (k == 0) {
  33. combinations.push_back(combination);
  34. return;
  35. }
  36. for (int i = offset; i <= n - k; ++i) {
  37. combination.push_back(i);
  38. nchoosek_helper(i+1, n, k-1, combinations, combination);
  39. combination.pop_back();
  40. }
  41. }
  42.  
  43.  
  44. double euclidean_norm(double dist1, double dist2){
  45. return sqrt(pow(dist1,2) + pow(dist2,2));
  46. }
  47.  
  48. //weirdest: look at A B C
  49. vector<vector<char> > step37::CUDADriver::get_access_pattern(int order){
  50. vector<vector<char> > result;
  51. vector<vector<int> > combinations;
  52. vector<int> combination;
  53.  
  54. nchoosek_helper(0, 16 ,order, combinations, combination);
  55. cout << "number of combinations: " << combination.size() << endl;
  56.  
  57.  
  58. // //mapping lexical index 1-16 to 2D array
  59. int virtual_pos [16][2];
  60. for (int i = 0; i < 16; ++i) {
  61. virtual_pos[i][0] = i%4 * order; //write x
  62. virtual_pos[i][1] = (int)ceil(i/4) * order; //write y
  63. cout << "mapping " << i << "to (" << i%4 * order << "'" << (int)ceil(i/4) * order<< ")" << endl;
  64. }
  65.  
  66. cout << "A: number of elements: " << combinations.size() << endl;
  67. float sum_vect[120][2];
  68. for (int i = 0; i < combinations.size(); ++i) {
  69. for (int j = 0; j < 2; ++j) {
  70. sum_vect[i][j] = 0;
  71. }
  72. }
  73. cout << "B: number of elements: " << combinations.size() << endl;
  74. cout << "B: number of elements: " << combinations.size() << endl;
  75. cout << "B: number of elements: " << combinations.size() << endl;
  76. cout << "B: number of elements: " << combinations.size() << endl;
  77.  
  78. for (int i = 0; i < combinations.size(); ++i) {
  79. combination = combinations.at(i);
  80. for (int j = 0; j < order; ++j) {
  81. sum_vect[i][0] += (float)virtual_pos[combination[j]][0];
  82. sum_vect[i][1] += (float)virtual_pos[combination[j]][1];
  83. }
  84. }
  85.  
  86. vector<int> optimal_ind;
  87. cout << "C: number of elements: " << combinations.size() << endl;
  88.  
  89. cout << "main loop"<< endl;
  90. for (int i = order; i < order*2; ++i) {
  91. for (int j = order; j < order*2; ++j) {
  92. int pos [2];
  93. // pos[0] = i;
  94. // pos[1] = j;
  95. pos[0] = j;
  96. pos[1] = i;
  97.  
  98. cout << "current position: (" << j << "," << i << ")" << endl;
  99.  
  100. float min_len = std::numeric_limits<float>::infinity(); //minimum length of combined vector
  101. float min_sum_ind = std::numeric_limits<float>::infinity(); //minimum sum of individual vectors
  102. int min_idx = -1;
  103.  
  104. for (int k = 0; k < combinations.size(); ++k) {
  105. int curr_vect [2];
  106. curr_vect[0] = sum_vect[k][0] - pos[0] * order;
  107. curr_vect[1] = sum_vect[k][1] - pos[1] * order;
  108.  
  109. float curr_len = euclidean_norm(curr_vect[0], curr_vect[1]);
  110.  
  111. float min_sum_tmp = 0;
  112. combination = combinations[k];
  113.  
  114. for (int l = 0; l < order; ++l) {
  115. min_sum_tmp += euclidean_norm(virtual_pos[combination.at(l)][0] - pos[0],
  116. virtual_pos[combination.at(l)][1]- pos[1]);
  117. }
  118.  
  119. if (i==4&&j==4){
  120. cout << " ind sum: " << min_sum_tmp << " len: " << curr_len << " sv: (" << sum_vect[k][0] << "," << sum_vect[k][1] <<
  121. ") cv: (" << curr_vect[0] << "," << curr_vect[1] << ")" <<endl;
  122.  
  123. }
  124.  
  125. if (min_len > curr_len ||
  126. min_len == curr_len && min_sum_tmp < min_sum_ind){
  127. min_len = curr_len;
  128. min_idx = k;
  129. min_sum_ind = min_sum_tmp;
  130. }
  131. }
  132.  
  133. // cout <<
  134.  
  135. cout << "pushing minimal idx " << min_idx << endl;
  136. optimal_ind.push_back(min_idx);
  137. }
  138. }
  139.  
  140. cout << "main loop done"<< endl;
  141.  
  142. //unpack optimal combinations into relative movements
  143. vector<char> optimal_x((int)pow(order,3));
  144. vector<char> optimal_y((int)pow(order,3));
  145.  
  146. cout << "number of elements: " << combinations.size() << endl;
  147. for (int i = 0; i <(int)pow(order,2); ++i) {
  148. cout << "optimal idx: " << optimal_ind.at(i) << endl;
  149. combination = combinations.at(optimal_ind.at(i));
  150. for (int j = 0; j < order; ++j) {
  151. int lex_idx = combination.at(j); //some index between 0 and 15 from 4x4 grid
  152.  
  153. //mvt range in grid relative to thread position: -1 to +
  154. int relative_x = -1 + lex_idx % 4;
  155. int relative_y = -1 + (int) floor(lex_idx / 4);
  156.  
  157. optimal_x[i * order + j] = relative_x;
  158. optimal_y[i * order + j] = relative_y;
  159. }
  160. }
  161.  
  162. //DEBUG print
  163. for (int i = 0; i < (int)pow(order,2); ++i) {
  164. combination = combinations.at(optimal_ind.at(i));
  165. cout << "combination: " << i << " ";
  166. for (int j = 0; j < order; ++j) {
  167. cout << combination.at(j) << " ";
  168. }
  169. cout << endl;
  170. }
  171.  
  172. result.push_back(optimal_x);
  173. result.push_back(optimal_y);
  174.  
  175. for (int i = 0; i < optimal_x.size(); ++i) {
  176. cout << (int)optimal_x.at(i) << " " << endl;
  177. }
  178.  
  179. cout << "optimal sizes: " << optimal_x.size() << endl;
  180. cout << "optimal sizes: " << optimal_y.size() << endl;
  181.  
  182.  
  183. cout << "result size: " << result.size() << endl;
  184.  
  185. return result;
  186. }
  187.  
  188. A: number of elements: 560
  189.  
  190. cout << "A: number of elements: " << combinations.size() << endl;
  191. float sum_vect[120][2];
  192. for (int i = 0; i < combinations.size(); ++i) {
  193. for (int j = 0; j < 2; ++j) {
  194. sum_vect[i][j] = 0;
  195. }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement