Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Variables and parameters
- float* ref; // Pointer to reference point array
- float* query; // Pointer to query point array
- float* dist; // Pointer to distance array
- int* ind; // Pointer to index array
- int ref_nb = 150; // Reference point number, max=65535
- int query_nb = 1; // Query point number, max=65535
- int dim = 4; // Dimension of points
- int k = 20; // Nearest neighbors to consider
- int iterations = 10;
- int i;
- // Memory allocation
- ref = (float *) malloc(ref_nb * dim * sizeof(float));
- query = (float *) malloc(query_nb * dim * sizeof(float));
- dist = (float *) malloc(query_nb * k * sizeof(float));
- ind = (int *) malloc(query_nb * k * sizeof(float));
- // Init
- /*
- srand(time(NULL));
- for (i=0 ; i<ref_nb * dim ; i++) ref[i] = (float)rand() / (float)RAND_MAX;
- for (i=0 ; i<query_nb * dim ; i++) query[i] = (float)rand() / (float)RAND_MAX;
- */
- // query array boyutu 1
- // dim = 4
- // dosyayi oku 150 data point var
- // for i ; i < ref_nb * dim i ++ ref[i] = i * ref_nb + k
- // query i elle set et query nb = 1
- FILE* fp = fopen("data.csv","r");
- int index = 0;
- while(!feof(fp))
- {
- int k = 0;
- for(k; k< dim;k++)
- {
- fscanf(fp, "%f",&ref[index + k *ref_nb]);
- }
- index++;
- }
- query[0] = 5.1;
- query[1] = 3.5;
- query[2] = 1.4;
- query[3] = 0.2;
- // Variables for duration evaluation
- cudaEvent_t start, stop;
- cudaEventCreate(&start);
- cudaEventCreate(&stop);
- float elapsed_time;
- // Display informations
- printf("Number of reference points : %6d\n", ref_nb );
- printf("Number of query points : %6d\n", query_nb);
- printf("Dimension of points : %4d\n", dim );
- printf("Number of neighbors to consider : %4d\n", k );
- printf("Processing kNN search :" );
- // Call kNN search CUDA
- cudaEventRecord(start, 0);
- for (i=0; i<iterations; i++)
- knn(ref, ref_nb, query, query_nb, dim, k, dist, ind);
- cudaEventRecord(stop, 0);
- cudaEventSynchronize(stop);
- cudaEventElapsedTime(&elapsed_time, start, stop);
- printf(" done in %f s for %d iterations (%f s by iteration)\n", elapsed_time/1000, iterations, elapsed_time/(iterations*1000));
- for(i = 0; i<k; i++)
- printf("%d, %lf\n",ind[i], dist[i]);
- // ciktilari buradan al
- // Destroy cuda event object and free memory
- cudaEventDestroy(start);
- cudaEventDestroy(stop);
- free(ind);
- free(dist);
- free(query);
- free(ref);
Add Comment
Please, Sign In to add comment