GCC Code Coverage Report


Directory: ./
File: build/TESTS/PERFORMANCE_TESTS/PERF_HADAMARD_PROXY/HadamardProductProxy/Hadamard_productProxyLoader.cpp
Date: 2025-03-14 12:14:21
Exec Total Coverage
Lines: 0 59 0.0%
Branches: 0 94 0.0%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7
8 //Warning : this file has been generated automatically by the phoenix_hpc_proxy program
9 //You can find it at https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/PhoenixHPCProxy
10 //Do NOT modify it
11
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <dlfcn.h>
16 #include <string.h>
17
18 #include "hadamard_product.h"
19
20 #include "Hadamard_productProxyLoader.h"
21
22 ///Variable which will load automatically the right library by respect to the given architecture
23 Hadamard_productProxyLoader PROXY_LOADER;
24
25 ///Default constructor of Hadamard_productProxyLoader
26 Hadamard_productProxyLoader::Hadamard_productProxyLoader(){
27 initialisationHadamard_productProxyLoader();
28 std::cout << "Hadamard_productProxyLoader::Hadamard_productProxyLoader() : check current architecture" << std::endl;
29 //First get the /proc/cpuinfo file
30 if(!parseArchFile("/proc/cpuinfo")){
31 //No library found, let's load the default library
32 load("libhadamard_product_perf_anyarch.so");
33 }
34 updateFunction();
35 }
36
37 ///Destructor of Hadamard_productProxyLoader
38 Hadamard_productProxyLoader::~Hadamard_productProxyLoader(){
39 close();
40 }
41
42 ///Load the given library
43 /** @param libName : name of the library to be loaded
44 * @return true on success, false otherwise
45 */
46 bool Hadamard_productProxyLoader::load(const std::string & libName){
47 if(libName == ""){return false;}
48 p_handle = dlopen(libName.c_str(), RTLD_LAZY);
49 std::cout << "Hadamard_productProxyLoader::load : loading library '"<<libName<<"'" << std::endl;
50 if(p_handle == NULL){
51 fprintf(stderr, "Hadamard_productProxyLoader::load : %s\n", dlerror());
52 return false;
53 }
54 dlerror(); //Erase an exsiting error
55 return true;
56 }
57
58 ///Parse the given architecture file
59 /** @param archfileName : name of the architecture file to be loaded
60 * @return true on success, false otherwise
61 */
62 bool Hadamard_productProxyLoader::parseArchFile(const std::string & archfileName){
63 FILE * fp = fopen(archfileName.c_str(), "r");
64 if(fp == NULL){
65 std::cerr << "Cannot open file '" << archfileName << "'" << std::endl;
66 return false;
67 }
68 std::string bufferAllFile("");
69 int buffer;
70 while(!feof(fp)){
71 buffer = fgetc(fp);
72 if(buffer != EOF) bufferAllFile += (char)buffer;
73 else break;
74 }
75 if(bufferAllFile == ""){
76 std::cerr << "Empty file '" << archfileName << "'" << std::endl;
77 return false;
78 }
79 const char * procCpuInfo = bufferAllFile.c_str();
80 //Let's check the avalaible architectures
81 bool isLibFound(true);
82 if(strstr(procCpuInfo, "avx512f") != NULL){
83 load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/PERFORMANCE_TESTS/PERF_HADAMARD_PROXY/HadamardProductProxy/libhadamard_product_perf_avx512f.so");
84 }else if(strstr(procCpuInfo, "avx2") != NULL){
85 load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/PERFORMANCE_TESTS/PERF_HADAMARD_PROXY/HadamardProductProxy/libhadamard_product_perf_avx2.so");
86 }else if(strstr(procCpuInfo, "avx") != NULL){
87 load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/PERFORMANCE_TESTS/PERF_HADAMARD_PROXY/HadamardProductProxy/libhadamard_product_perf_avx.so");
88 }else if(strstr(procCpuInfo, "sse4.2") != NULL){
89 load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/PERFORMANCE_TESTS/PERF_HADAMARD_PROXY/HadamardProductProxy/libhadamard_product_perf_sse4.so");
90 }else if(strstr(procCpuInfo, "ssse3") != NULL){
91 load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/PERFORMANCE_TESTS/PERF_HADAMARD_PROXY/HadamardProductProxy/libhadamard_product_perf_ssse3.so");
92 }else if(strstr(procCpuInfo, "sse2") != NULL){
93 load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/PERFORMANCE_TESTS/PERF_HADAMARD_PROXY/HadamardProductProxy/libhadamard_product_perf_sse2.so");
94 }else if(strstr(procCpuInfo, "anyarch") != NULL){
95 load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/PERFORMANCE_TESTS/PERF_HADAMARD_PROXY/HadamardProductProxy/libhadamard_product_perf_anyarch.so");
96 }else{
97 isLibFound = false;
98 }
99
100 fclose(fp);
101 return isLibFound;
102 }
103
104 ///Say if the current library is opened or not
105 /** @return true if the current library is opened, false otherwise
106 */
107 bool Hadamard_productProxyLoader::isOpen() const{
108 return p_handle != NULL;
109 }
110
111 ///Close the current library
112 void Hadamard_productProxyLoader::close(){
113 if(isOpen()){
114 dlclose(p_handle);
115 }
116 }
117
118 ///Update the functions to be used
119 void Hadamard_productProxyLoader::updateFunction(){
120 if(!isOpen()){exit(-1);return;}
121 //Then set all the function pointers
122 update_hadamard_product(p_handle);
123 }
124
125 ///Initialisation function of the class Hadamard_productProxyLoader
126 void Hadamard_productProxyLoader::initialisationHadamard_productProxyLoader(){
127 p_handle = NULL;
128 }
129
130