LCOV - code coverage report
Current view: top level - inc - utils.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 40 64 62.5 %
Date: 2025-11-18 18:26:44 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #ifndef FVS_xcode_global_util_h
       2             : #define FVS_xcode_global_util_h
       3             : 
       4             : #include "global_param.h"
       5             : #include "header.h"
       6             : 
       7             : void displayTime(clock_t & begin_end, const std::string & message = "");
       8             : 
       9             : template<typename type>
      10     1441000 : void quick_sort_aux(std::vector<uint32_t> & id, std::vector<type> & distances, int nb_data, int min_data, int max_data, int verbose = 0)
      11             : {
      12     1441000 :     if (max_data == min_data + 1)
      13      957002 :         return;
      14      484000 :     if (min_data > max_data)
      15             :     {
      16           0 :         printf("Inconsistent data !");
      17           0 :         return;
      18             :     }
      19      968000 :     std::vector<uint32_t> ids_vec(max_data - min_data);
      20      968000 :     std::vector<type> distances_aux_vec(max_data - min_data);
      21      484000 :     int mid_data = (min_data + max_data) / 2;
      22      484000 :     if (verbose)
      23             :     {
      24           0 :         std::cout << " min_data : " << min_data << std::endl;
      25           0 :         std::cout << " mid_data : " << mid_data << std::endl;
      26           0 :         std::cout << " max_data : " << max_data << std::endl;
      27           0 :         for (int i = 0; i < id.size(); i++)
      28             :         {
      29           0 :             std::cout << " id[" << i << "] : " << id[i] << " distances[" << i << "] : " << distances[i] << std::endl;
      30             :         }
      31             :     }
      32             : 
      33      484000 :     quick_sort_aux<type>(id, distances, nb_data, min_data, mid_data, verbose);
      34      484000 :     quick_sort_aux<type>(id, distances, nb_data, mid_data, max_data, verbose);
      35             :     int id_first_half = min_data;
      36             :     int id_second_half = mid_data;
      37             :     // Fusion
      38             :     int id_aux = 0;
      39     1578620 :     while (id_first_half != mid_data || id_second_half != max_data)
      40             :     {
      41     1094620 :         if (id_first_half == mid_data)
      42             :         {
      43      403211 :             distances_aux_vec[id_aux] = distances[id_second_half];
      44      403211 :             ids_vec[id_aux] = id[id_second_half];
      45      403211 :             id_second_half++;
      46      403211 :             id_aux++;
      47             :         }
      48      691407 :         else if (id_second_half == max_data)
      49             :         {
      50       84497 :             distances_aux_vec[id_aux] = distances[id_first_half];
      51       84497 :             ids_vec[id_aux] = id[id_first_half];
      52       84497 :             id_first_half++;
      53       84497 :             id_aux++;
      54             :         }
      55      606910 :         else if (distances[id_first_half] < distances[id_second_half])
      56             :         {
      57      460108 :             distances_aux_vec[id_aux] = distances[id_first_half];
      58      460108 :             ids_vec[id_aux] = id[id_first_half];
      59      460108 :             id_first_half++;
      60      460108 :             id_aux++;
      61             :         }
      62             :         else
      63             :         {
      64      146802 :             distances_aux_vec[id_aux] = distances[id_second_half];
      65      146802 :             ids_vec[id_aux] = id[id_second_half];
      66      146802 :             id_second_half++;
      67      146802 :             id_aux++;
      68             :         }
      69             :     }
      70             :     // And now recopy
      71     1578620 :     for (int i = 0; i < max_data - min_data; i++)
      72             :     {
      73     1094620 :         distances[min_data + i] = distances_aux_vec[i];
      74     1094620 :         id[min_data + i] = ids_vec[i];
      75             :     }
      76      484000 :     if (verbose)
      77             :     {
      78           0 :         for (int i = 0; i < id.size(); i++)
      79             :         {
      80           0 :             std::cout << " id[" << i << "] : " << id[i] << " distances[" << i << "] : " << distances[i] << std::endl;
      81             :         }
      82             :     }
      83             : 
      84             : }
      85             : 
      86             : template<typename type>
      87      715002 : void quick_sort(std::vector<uint32_t> & id, std::vector<type> & distances, int nb_data, int verbose)
      88             : {
      89      715002 :     clock_t startClock = clock();
      90             : 
      91      715002 :     if (nb_data < 2)
      92             :         return;
      93      473002 :     if (verbose)
      94             :     {
      95           0 :         std::cout << " at most 100 first distances : " << std::endl;
      96           0 :         for (int i = 0; i < std::min<size_t>(100, id.size()); i++)
      97           0 :             std::cout << id[i]<< " : " << distances[i] << ", ";
      98             : 
      99           0 :         std::cout << " id size : " << id.size() << std::endl;
     100             : 
     101           0 :         std::cout << " calling quick_sort_aux " << std::endl;
     102             :     }
     103      473002 :     quick_sort_aux<type>(id, distances, nb_data, 0, nb_data, verbose);
     104      473002 :     if (verbose)
     105             :     {
     106           0 :         std::cout << " out of quick_sort_aux " << std::endl;
     107             : 
     108           0 :         std::cout << " id size : "<< id.size() << std::endl;
     109           0 :         std::cout << " nb_data : "<< nb_data << std::endl;
     110           0 :         std::cout << " max length  id, distance : "<< id[nb_data - 1] <<", " << distances[nb_data - 1] << std::endl;
     111           0 :         std::cout << " at most 100 first distances : " << std::endl;
     112           0 :         for (int i = 0; i < std::min<size_t>(100, id.size()); i++)
     113           0 :             std::cout << id[i]<< " : " << distances[i] << ", ";
     114             : 
     115           0 :         clock_t endClock = clock();
     116             : 
     117           0 :         std::cout << std::endl <<"Quitting quick sort " << std::endl;
     118           0 :         std::cout << " Quick sort in " << (long long unsigned int) (endClock - startClock) <<" micro seconds" << std::endl;
     119             :     }
     120             : }
     121             : 
     122             : /*
     123             :  * file.cu
     124             :  */
     125             : void loadBinary(std::vector<uint32_t> & ids_data, std::vector<uint32_t> & ids_index, std::vector<uint32_t> & type_data, std::vector<types_datas_t> & ReadCacheCPU,
     126             :   int nb_data_in_file, std::string rootDirectory_aux, int verbose);
     127             : void save(std::string rootDirectory_var, std::string completeFileName_aux, std::vector<to_insert_t> &to_insert, std::string velours_root, int max, int verbose, bool dontCheckDuplicateIdObject);
     128             : void cleanDataBinary(std::vector<uint32_t> & ids_data, std::vector<data> & data_to_load, int nb_data_in_file, std::string rootDirectory_aux, std::string completeFileName_aux, int dimension);
     129             : #ifndef ONLY_CPU
     130             : void testCUDA(cudaError_t error, const char *file, uint32_t line );
     131             : #define testCUDA(error){testCUDA(error, __FILE__, __LINE__);}
     132             : #endif
     133             : 
     134             : /*
     135             :  * init.cu
     136             :  */
     137             : int     set_with_conf_file(std::string conf_file_aux,GlobalParam & gp, LocalParam & lp);
     138             : void    setdefault(GlobalParam & gp, LocalParam & lp);
     139             : 
     140             : /*
     141             :  * server.cu
     142             :  */
     143             : int             create_server(int port);
     144             : int createConnectionAndOutputIp(int sock);
     145             : 
     146             : /*
     147             :  * gpu.cu
     148             :  */
     149             : 
     150             : #ifndef ONLY_CPU
     151             : void fromCPU(std::vector<uint32_t> &result, uint32_t id_query, std::vector<types_datas_t> &ReadCacheCPU, int descriptor_type, std::vector<uint32_t> &ids, uint32_t limit_return, std::vector<VDInt>& d, std::vector<data> &desc_to_query, int verbose, int index_type);
     152             : void fromCPUKmeanOneStep(std::vector<VDInt> &clusters, types_datas_t &ReadCacheCPUPointerOneDescriptorType, int verbose);
     153             : #endif
     154             : 
     155             : void query_pds(uint32_t idx_v, unsigned id_photo,std::vector<uint32_t>& res, std::vector<uint32_t>& dist, std::vector<types_datas_t>& ReadCacheCPU, LocalParam& lp, Query& cur_query, const std::vector<uint32_t>& candidats_grille);
     156             : // VR 7/11/23 : fonction non defini
     157             : void query_pds_gpu(unsigned m, unsigned nbc, unsigned n, unsigned d, uint32_t* vecteursDev,uint32_t* candidatsDev, uint32_t* argminDev, VDInt* distDev, uint32_t* pointeurGPU2, bool duplication);
     158             : void query_kernel_vide(uint32_t n, uint32_t NB, uint32_t NTPB);
     159             : void query_device(int count, int *NB, int *NTPB);
     160             : 
     161             : // La ce sont des données en photo_ids => il faut changer en ids et pour cela faire les find_index en dehors et passer vec et vvec (a changer en vecteur plutot que pointeur ! youpla boum)
     162             : void query_pds_from_cpu(std::vector<uint32_t> & result, std::vector<VDInt> & distances,
     163             :                  int & limit_return,
     164             :                  uint32_t* vec, // liste_ids_as_ids  a changer en vector
     165             :                  int m, // number query
     166             :                  uint32_t* vecc, // candidats_grille_as_ids  a changer en vector
     167             :                  int nbc, // number candidats
     168             :                  int n,   // number data total (m + nbc)
     169             :                  int d, // dimension (a renommer)
     170             :                  const datag *pointeurGPU,
     171             :                  int verbose
     172             :                  );
     173             : 
     174             : #endif
     175             : 
     176             : 
     177             : 

Generated by: LCOV version 1.14