Guest User

Untitled

a guest
Dec 16th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. // Variables and parameters
  2. float* ref; // Pointer to reference point array
  3. float* query; // Pointer to query point array
  4. float* dist; // Pointer to distance array
  5. int* ind; // Pointer to index array
  6. int ref_nb = 150; // Reference point number, max=65535
  7. int query_nb = 1; // Query point number, max=65535
  8. int dim = 4; // Dimension of points
  9. int k = 20; // Nearest neighbors to consider
  10. int iterations = 10;
  11. int i;
  12.  
  13. // Memory allocation
  14. ref = (float *) malloc(ref_nb * dim * sizeof(float));
  15. query = (float *) malloc(query_nb * dim * sizeof(float));
  16. dist = (float *) malloc(query_nb * k * sizeof(float));
  17. ind = (int *) malloc(query_nb * k * sizeof(float));
  18.  
  19. // Init
  20. /*
  21. srand(time(NULL));
  22. for (i=0 ; i<ref_nb * dim ; i++) ref[i] = (float)rand() / (float)RAND_MAX;
  23. for (i=0 ; i<query_nb * dim ; i++) query[i] = (float)rand() / (float)RAND_MAX;
  24. */
  25.  
  26. // query array boyutu 1
  27. // dim = 4
  28. // dosyayi oku 150 data point var
  29. // for i ; i < ref_nb * dim i ++ ref[i] = i * ref_nb + k
  30. // query i elle set et query nb = 1
  31. FILE* fp = fopen("data.csv","r");
  32. int index = 0;
  33. while(!feof(fp))
  34. {
  35. int k = 0;
  36. for(k; k< dim;k++)
  37. {
  38. fscanf(fp, "%f",&ref[index + k *ref_nb]);
  39. }
  40. index++;
  41. }
  42. query[0] = 5.1;
  43. query[1] = 3.5;
  44. query[2] = 1.4;
  45. query[3] = 0.2;
  46. // Variables for duration evaluation
  47. cudaEvent_t start, stop;
  48. cudaEventCreate(&start);
  49. cudaEventCreate(&stop);
  50. float elapsed_time;
  51.  
  52. // Display informations
  53. printf("Number of reference points : %6d\n", ref_nb );
  54. printf("Number of query points : %6d\n", query_nb);
  55. printf("Dimension of points : %4d\n", dim );
  56. printf("Number of neighbors to consider : %4d\n", k );
  57. printf("Processing kNN search :" );
  58.  
  59. // Call kNN search CUDA
  60. cudaEventRecord(start, 0);
  61. for (i=0; i<iterations; i++)
  62. knn(ref, ref_nb, query, query_nb, dim, k, dist, ind);
  63. cudaEventRecord(stop, 0);
  64. cudaEventSynchronize(stop);
  65. cudaEventElapsedTime(&elapsed_time, start, stop);
  66. printf(" done in %f s for %d iterations (%f s by iteration)\n", elapsed_time/1000, iterations, elapsed_time/(iterations*1000));
  67. for(i = 0; i<k; i++)
  68. printf("%d, %lf\n",ind[i], dist[i]);
  69. // ciktilari buradan al
  70. // Destroy cuda event object and free memory
  71. cudaEventDestroy(start);
  72. cudaEventDestroy(stop);
  73. free(ind);
  74. free(dist);
  75. free(query);
  76. free(ref);
Add Comment
Please, Sign In to add comment