LCOV - code coverage report
Current view: top level - inc - header.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 8 22 36.4 %
Date: 2025-09-25 06:26:27 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #ifndef HEADER_H
       2             : # define HEADER_H
       3             : /**
       4             :  *  \file header.h
       5             :  *  \author martigan
       6             :  *  \brief Fichier header avec prototype des fonctions et define
       7             :  *
       8             :  */
       9             : #include <stdint.h>
      10             : 
      11             : //#include "global_param.h"
      12             : 
      13             : 
      14             : #ifdef FLOAT_TYPE
      15             : typedef float VDInt;
      16             : typedef float data;
      17             : typedef float datag;
      18             : #else
      19             : typedef uint32_t VDInt;
      20             : typedef uint8_t data;
      21             : typedef uint8_t datag;
      22             : #endif
      23             : 
      24             : typedef uint32_t ind;
      25             : 
      26             : # include <stdlib.h>
      27             : # include <stdio.h>
      28             : # include <string.h>
      29             : # include <math.h>
      30             : # include <vector>
      31             : # include <string>
      32             : # include <boost/algorithm/string/split.hpp>
      33             : # include <boost/algorithm/string.hpp>
      34             : # include <boost/algorithm/cxx11/any_of.hpp>
      35             : # include <boost/lexical_cast.hpp>
      36             : # include <sys/stat.h>
      37             : # include <time.h>
      38             : # include <iostream>
      39             : # include <algorithm>
      40             : # include <numeric>
      41             : 
      42             : // OS-specific librairies
      43             : #ifdef _WIN64
      44             : # include <io.h>
      45             : # include <winsock2.h>
      46             : # include <ws2tcpip.h>
      47             : # include <windows.h>
      48             : # include <tchar.h>
      49             : #else
      50             : # include <dirent.h>
      51             : # include <netdb.h>
      52             : #endif
      53             : 
      54             : 
      55             : // librairies included before but not necessary actually
      56             : // # include <unistd.h>
      57             : // # include <signal.h>
      58             : // # include <sys/socket.h>
      59             : // # include <fcntl.h>
      60             : // # include <netinet/in.h>
      61             : // # include <arpa/inet.h>
      62             : // # include <sys/types.h>
      63             : 
      64             : # define INSERT 100000
      65             : # define INSERT_MAX 200000
      66             : # define SIZE_ALLOCATION_BUFFER 100000
      67             : # define PORT 22194
      68             : # define DIMENSION_TYPE_2 4096
      69             : # define LIMIT_RETURN 50
      70             : # define MAX_LIMIT_RETURN 1000000
      71             : # define NB_TYPE 5
      72             : //# include "./query_manager.h"
      73             : 
      74             : #ifndef ONLY_CPU
      75             : static texture<datag> texGPU;
      76             : #include <cuda_profiler_api.h>
      77             : #endif
      78             : 
      79             : struct LocalParam;
      80             : 
      81             : /**
      82             :  * \struct types_datas_t
      83             :  * \brief Objet buffer de lecture.
      84             :  *
      85             :  * contient un repertoire,  un type, une longueur, le nombre de photos, le nombre maximum de photo,
      86             :  *  le cpt, un tableau de photo_id, un tableau de liste de fichier(uint32_t), un array de descripteurs
      87             :  * et un array de descripteur sur GPU
      88             :  */
      89             : 
      90             : struct types_datas
      91             : {
      92             :     public :
      93             :     std::string dir;
      94             :     int         type;
      95             :     uint32_t    size;// dimension d for integer
      96             :     uint32_t    size_user_choice; // dimension d chosen by the user
      97             :     uint32_t    nb_data;// nombre n
      98             :     uint32_t    nb_max_data;
      99             :     uint32_t    cpt;
     100             :     std::vector<uint32_t> ids_vec;
     101             :     std::vector<uint32_t> index_vec;
     102             :     std::vector<data> datas_vec;
     103             :     datag       *dataGPU;
     104             :     datag    *dataGPUdyn;
     105             :     void resizeDatas(size_t newsize);
     106             :     types_datas();
     107             :     //  private :
     108             :     // http://stackoverflow.com/questions/9123022/preventing-a-destructor-from-running-in-c
     109             :     ~types_datas();
     110             : };
     111             : 
     112             : typedef types_datas types_datas_t;
     113             : 
     114             : 
     115             : /**
     116             :  * \struct to_insert_t
     117             :  * \brief Objet buffer d insertion.
     118             :  *
     119             :  * contient une photo_id, un repertoire, des descripteurs(datas), un type et une longueur
     120             :  *
     121             :  *
     122             :  */
     123             : 
     124     2600000 : typedef struct  toInsert
     125             : {
     126             :     int32_t     id;
     127             :     std::vector<data> datas_vec;
     128             :     int32_t     type_data;
     129             :     int32_t     length;
     130             :     std::string dire;
     131             : 
     132             :     int commit(int size);
     133             :     //    private :
     134             :     ~toInsert();
     135             : 
     136             : } to_insert_t;
     137             : 
     138             : 
     139             : class Query
     140             : {
     141             :     private :
     142             :     std::string input;
     143             :     size_t limit;
     144             :     size_t offset;
     145             :     int32_t type;
     146             :     size_t      size;
     147             :     char query_char;
     148             :     int index_type;
     149             :         
     150             :     int set_query(uint32_t server_type, LocalParam & lp, int verbose = 0);
     151             :     int set_query_delete(uint32_t server_type, LocalParam & lp);
     152             :     void set_type(const char *str, int32_t server_type, LocalParam& lp);
     153             :     void set_limit(char *str);
     154             :     void set_offset(char *str);
     155             :     
     156             :         std::string special_kmean;
     157             :     std::string kmean_param;
     158             :     std::string grid_filename = "";
     159             :     char divergence = 'E';
     160             :     int nb_iteration = 20;
     161             :     bool prediction=false;
     162             :     int iter_max;
     163             :     int nb_clusters;
     164             :     int k_min = 0;
     165             :     int k_max = 0;
     166             :     int crea_photo_desc;
     167             :     int return_centroid;
     168             :     int return_list_photo;
     169             :     int verbose_query;
     170             :     std::vector<data> query_desc;
     171             :     std::vector<uint32_t> list_ids;
     172             :     std::vector<std::vector<data> > data_to_insert;
     173             :     VDInt min_elem;
     174             : 
     175             :     size_t indice_coordinate;
     176             :     // ceci est pour le descriptor type
     177             : 
     178             :     std::vector<int32_t> type_list;
     179             :     std::vector<uint32_t> index_type_list;
     180             :     uint32_t    id;
     181             : 
     182             :     std::vector<size_t> list_size;
     183             : 
     184             :     // communication with client
     185             :     std::vector<std::vector<VDInt> > clusters;
     186             :     std::vector<std::pair<int, VDInt> > size_and_inertia;
     187             :     VDInt distortion = 0;
     188             :     std::vector<std::vector<uint32_t> > list_photo_ids_per_cluster;
     189             :     void get_cluster();
     190             :     void cluster_to_csv(LocalParam lp,int index_type, const std::vector<types_datas_t> & read_cache_cpu);
     191             :     void data_to_csv(LocalParam lp,int index_type, const std::vector<types_datas_t> & read_cache_cpu);
     192             : 
     193             :     // communication with GPU
     194             :     std::vector<VDInt> clusters_as_line;
     195             :     int set_query_desc(uint32_t server_type, LocalParam & lp);
     196             :     int set_query_advanced(uint32_t server_type, LocalParam & lp);
     197             :     int set_query_insert(LocalParam & lp);
     198             :     int set_query_multi_insert(LocalParam & lp);
     199             :     int set_query_commit(uint32_t server_type, LocalParam & lp);
     200             :     int set_query_generic(uint32_t server_type, LocalParam & lp);
     201             :     int set_query_unload(LocalParam & lp, int verbose);
     202             :     int set_query_multiarg(uint32_t server_type, LocalParam & lp);
     203             : 
     204             : 
     205             :     int set_query_list_ids(uint32_t server_type, LocalParam & lp);
     206             :     int set_query_load(uint32_t server_type, LocalParam & lp);
     207             :     int set_query_kmean(uint32_t server_type, LocalParam & lp, int verbose = 0);
     208             :     int set_query_prediction(uint32_t server_type, LocalParam & lp, int verbose);
     209             :     int set_query_coordinate(uint32_t server_type, LocalParam & lp, int verbose = 0);
     210             :     // remove pointer ?
     211             :     void set_types(std::string str, int32_t server_type, LocalParam & lp);
     212             :     void set_indice_coordinate(const char *str);
     213             : 
     214             :     public :
     215             :     
     216             :     const std::vector<int32_t> &get_query_types() const;
     217             :     const std::vector<uint32_t> &get_query_index_type_list() const;
     218             :     char get_query_char();
     219             :     std::vector<data> & get_query_desc();
     220             :     std::vector<uint32_t> &get_query_list_ids();
     221             :     size_t get_query_limit();
     222             :     size_t get_query_offset();
     223             :     int get_query_iter_max();
     224             :     int get_query_nb_clusters();
     225             :     int get_query_crea_photo_desc();
     226             :     int get_query_return_centroid();
     227             :     int get_query_return_list_photo();
     228             :     int get_query_index_type();
     229             :     int get_query_list_index_type(int i);
     230             :     const std::vector<std::vector<data> > & getDataInsert() const;
     231             :     const std::vector<uint32_t> & getListIds() const;
     232             :     const std::vector<int32_t> & getTypeList() const;
     233             :     const std::vector<uint32_t> & getIndexList() const;
     234             :     int32_t get_query_type();
     235             :     uint32_t get_query_id();
     236             :     const std::vector<VDInt> & getClustersForGPU() const;
     237             :     const std::vector<std::vector<VDInt> > & getClustersForOutput() const;
     238             :     const std::vector<std::pair<int, VDInt> > & getSizeAndInertieClustersForOutput() const;
     239             :     const std::vector<std::vector<uint32_t> > & getListPhotoIdsPerCluster() const;
     240             :     void set_cluster_init_dyn(const std::vector<data> & data_vec, const int dim);
     241             :     void set_cluster_init(const int nb_clusters, const std::vector<data> & data_vec, const int dim);
     242             :     void set_nb_clusters(int nb);
     243             :     int get_kmax();
     244             :     void grid_to_csv(LocalParam lp,int index_type);
     245             :     void load_grid_csv(LocalParam lp, int index_type);
     246             :     void prediction_to_csv(LocalParam lp, int index_type, const std::vector<types_datas_t> & read_cache_cpu);
     247             : 
     248             : 
     249             :     void reset_query();
     250             :         void reset_clusters(const int nb_clusters, const std::vector<data> & data_vec, const int dim);
     251             :     uint32_t get_query_size();
     252             :     void set_query_char(char c);
     253             :     void set_query_id(uint32_t newid);
     254             :     void set_limit(uint32_t lim);
     255             :     std::string get_query_input();
     256             : 
     257             :     int exit();
     258             :     // VR 2-12-16 : to integrate Lokmane code
     259             :     int executeQueryOneStepKmean(LocalParam & lp, int methodChoice = -1);
     260             :     int executeElbowKmean(LocalParam & lp, int methodChoice = -1);
     261             : 
     262             :     void get_data_kmean(int dimension);
     263             :     const std::string & get_special_kmean() const;
     264             :     size_t get_indice_coordinate() const;
     265             :     
     266             :     public :
     267             :     int load_query(int cs, uint32_t server_type, LocalParam & lp,int verbose = 0);
     268             :     Query();
     269             :     Query(std::string &, uint32_t server_type = 2);
     270             :     ~Query();
     271             : };
     272             : 
     273             : 
     274             : struct LocalParam
     275             : {
     276             :     int counter = 0;
     277             :     int limit_data = 0;
     278             :     bool empty_server = false;
     279             : 
     280             :     int cs;
     281             :     int retval_set_query;
     282             :     int32_t query_index = 0;
     283             :     int load_only_main = 0;
     284             :     // for coordinate retrieval
     285             :     int indice_data = 0;
     286             : 
     287             :     int cleaning_data = 0;
     288             :     int descriptor_type = -1;
     289             :     int desc_type_dyn = -1;
     290             :     int cleanCPU = 0;
     291             :     int insert_save_file = 1;
     292             :     int insert_sync_cache = 1;
     293             : 
     294             :         
     295             : 
     296             :     // MG 4-11-16 : a utiliser dans Query
     297             :     int index_type_query = 0;
     298             :     int type_query = 0;
     299             : 
     300             :     int dimension = 0;
     301             : 
     302             :     uint32_t nb_data_in_file;
     303             : 
     304             :     int verbose = 0;
     305             :     std::string conf_file;
     306             : 
     307             :     std::vector<uint32_t> idc_vec;
     308             :     int current_limit = 0;
     309             :     std::vector<VDInt> distances_vec;
     310             : 
     311             :     std::vector<uint32_t> result_vec;
     312             :     std::vector<data> result_data_vec;
     313             : 
     314             :     std::vector<types_datas_t> ReadCacheCPU;
     315             :     
     316             :     std::vector<types_datas_t> ReadCacheCpuDyn;
     317             :     
     318             :     std::vector<int> list_dyn_desc_type;
     319             :     std::vector<int> list_pere_desc_dyn;
     320             :     
     321             :     std::vector<int> indexCurrent;
     322             :     
     323             :     std::vector<std::vector<uint32_t>> list_photo_per_desc_dyn;
     324             :     
     325             : 
     326             :     Query query;
     327             : 
     328             :     int reload = 0;
     329             : 
     330           3 :     LocalParam() :
     331           3 :     nb_data_in_file(0), distances_vec(1)
     332             :     {
     333             : 
     334           3 :     }
     335             : };
     336             : 
     337             : struct SplitAndStickParam
     338             : {
     339             :     int period_step_split = 5;
     340             :     int fraction_split = 10;
     341             :     int mode_create = 1;
     342             :     int period_step_stick = 5;
     343             :     int fraction_stick = 10;
     344             :     int mode_remove = 0;
     345             : 
     346             :     // VR 15-1-17 : we could imagine a configuration that is self sustainable to keep the same number of cluster at each step !
     347           1 :     SplitAndStickParam(std::string kmean_param = "")
     348           1 :     {
     349           1 :         if (kmean_param != "")
     350             :         {
     351           0 :             std::vector<std::string> param_split_and_stick, one_set_param;
     352           0 :             split(param_split_and_stick, kmean_param, boost::is_any_of(";"));
     353           0 :             if (param_split_and_stick.size() > 0 and param_split_and_stick[0] != "")
     354             :             {
     355           0 :                 split(one_set_param, param_split_and_stick[0], boost::is_any_of(","));
     356           0 :                 if (one_set_param.size() >= 3)
     357             :                 {
     358           0 :                     period_step_split = (data) atoi(&(one_set_param[0].at(0)));
     359           0 :                     fraction_split = (data) atoi(&(one_set_param[1].at(0)));
     360           0 :                     mode_create = (data) atoi(&(one_set_param[2].at(0)));
     361             :                 }
     362             :             }
     363           0 :             if (param_split_and_stick.size() > 1 and param_split_and_stick[1] != "")
     364             :             {
     365           0 :                 split(one_set_param, param_split_and_stick[1], boost::is_any_of(","));
     366           0 :                 if (one_set_param.size() >= 3)
     367             :                 {
     368           0 :                     period_step_stick = (data) atoi(&(one_set_param[0].at(0)));
     369           0 :                     fraction_stick = (data) atoi(&(one_set_param[1].at(0)));
     370           0 :                     mode_remove = (data) atoi(&(one_set_param[2].at(0)));
     371             :                 }
     372             :             }
     373             :         }
     374           1 :     }
     375             : };
     376             : 
     377             : 
     378             : #endif
     379             : 
     380             : 
     381             : 
     382             : 
     383             : 

Generated by: LCOV version 1.14