Directory: | ./ |
---|---|
File: | build/TESTS/TEST_PROXY_LIB/HadamardProduct/Hadamard_productProxyLoader.cpp |
Date: | 2025-03-14 12:14:21 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 44 | 63 | 69.8% |
Branches: | 21 | 85 | 24.7% |
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 | 1 | Hadamard_productProxyLoader::Hadamard_productProxyLoader(){ | |
27 | 1 | initialisationHadamard_productProxyLoader(); | |
28 | 1 | std::cout << "Hadamard_productProxyLoader::Hadamard_productProxyLoader() : check current architecture" << std::endl; | |
29 | //First get the /proc/cpuinfo file | ||
30 |
3/4✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
|
1 | if(!parseArchFile("/proc/cpuinfo")){ |
31 | //No library found, let's load the default library | ||
32 | ✗ | load("libhadamard_product_anyarch.so"); | |
33 | } | ||
34 | 1 | updateFunction(); | |
35 | 1 | } | |
36 | |||
37 | ///Destructor of Hadamard_productProxyLoader | ||
38 | 2 | Hadamard_productProxyLoader::~Hadamard_productProxyLoader(){ | |
39 | 2 | 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 | 1 | bool Hadamard_productProxyLoader::load(const std::string & libName){ | |
47 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if(libName == ""){return false;} |
48 | 1 | p_handle = dlopen(libName.c_str(), RTLD_LAZY); | |
49 | 1 | std::cout << "Hadamard_productProxyLoader::load : loading library '"<<libName<<"'" << std::endl; | |
50 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if(p_handle == NULL){ |
51 | ✗ | fprintf(stderr, "Hadamard_productProxyLoader::load : %s\n", dlerror()); | |
52 | ✗ | return false; | |
53 | } | ||
54 | 1 | dlerror(); //Erase an exsiting error | |
55 | 1 | 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 | 1 | bool Hadamard_productProxyLoader::parseArchFile(const std::string & archfileName){ | |
63 |
1/1✓ Branch 2 taken 1 times.
|
1 | FILE * fp = fopen(archfileName.c_str(), "r"); |
64 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if(fp == NULL){ |
65 | ✗ | std::cerr << "Cannot open file '" << archfileName << "'" << std::endl; | |
66 | ✗ | return false; | |
67 | } | ||
68 |
1/1✓ Branch 2 taken 1 times.
|
1 | std::string bufferAllFile(""); |
69 | int buffer; | ||
70 |
1/2✓ Branch 1 taken 98555 times.
✗ Branch 2 not taken.
|
98555 | while(!feof(fp)){ |
71 |
1/1✓ Branch 1 taken 98555 times.
|
98555 | buffer = fgetc(fp); |
72 |
3/3✓ Branch 0 taken 98554 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 98554 times.
|
98555 | if(buffer != EOF) bufferAllFile += (char)buffer; |
73 | 1 | else break; | |
74 | } | ||
75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if(bufferAllFile == ""){ |
76 | ✗ | std::cerr << "Empty file '" << archfileName << "'" << std::endl; | |
77 | ✗ | return false; | |
78 | } | ||
79 | 1 | const char * procCpuInfo = bufferAllFile.c_str(); | |
80 | //Let's check the avalaible architectures | ||
81 | 1 | bool isLibFound(true); | |
82 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if(strstr(procCpuInfo, "avx512f") != NULL){ |
83 | ✗ | load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/TEST_PROXY_LIB/HadamardProduct/libhadamard_product_avx512f.so"); | |
84 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | }else if(strstr(procCpuInfo, "avx2") != NULL){ |
85 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/TEST_PROXY_LIB/HadamardProduct/libhadamard_product_avx2.so"); |
86 | ✗ | }else if(strstr(procCpuInfo, "avx") != NULL){ | |
87 | ✗ | load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/TEST_PROXY_LIB/HadamardProduct/libhadamard_product_avx.so"); | |
88 | ✗ | }else if(strstr(procCpuInfo, "sse4.2") != NULL){ | |
89 | ✗ | load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/TEST_PROXY_LIB/HadamardProduct/libhadamard_product_sse4.so"); | |
90 | ✗ | }else if(strstr(procCpuInfo, "ssse3") != NULL){ | |
91 | ✗ | load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/TEST_PROXY_LIB/HadamardProduct/libhadamard_product_ssse3.so"); | |
92 | ✗ | }else if(strstr(procCpuInfo, "sse2") != NULL){ | |
93 | ✗ | load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/TEST_PROXY_LIB/HadamardProduct/libhadamard_product_sse2.so"); | |
94 | ✗ | }else if(strstr(procCpuInfo, "anyarch") != NULL){ | |
95 | ✗ | load("/builds/CTA-LAPP/PHOENIX_LIBS2/PhoenixHPCProxy/build/TESTS/TEST_PROXY_LIB/HadamardProduct/libhadamard_product_anyarch.so"); | |
96 | }else{ | ||
97 | ✗ | isLibFound = false; | |
98 | } | ||
99 | |||
100 |
1/1✓ Branch 1 taken 1 times.
|
1 | fclose(fp); |
101 | 1 | return isLibFound; | |
102 | 1 | } | |
103 | |||
104 | ///Say if the current library is opened or not | ||
105 | /** @return true if the current library is opened, false otherwise | ||
106 | */ | ||
107 | 2 | bool Hadamard_productProxyLoader::isOpen() const{ | |
108 | 2 | return p_handle != NULL; | |
109 | } | ||
110 | |||
111 | ///Close the current library | ||
112 | 1 | void Hadamard_productProxyLoader::close(){ | |
113 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if(isOpen()){ |
114 | 1 | dlclose(p_handle); | |
115 | } | ||
116 | 1 | } | |
117 | |||
118 | ///Update the functions to be used | ||
119 | 1 | void Hadamard_productProxyLoader::updateFunction(){ | |
120 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if(!isOpen()){exit(-1);return;} |
121 | //Then set all the function pointers | ||
122 | 1 | update_hadamard_product(p_handle); | |
123 | } | ||
124 | |||
125 | ///Initialisation function of the class Hadamard_productProxyLoader | ||
126 | 1 | void Hadamard_productProxyLoader::initialisationHadamard_productProxyLoader(){ | |
127 | 1 | p_handle = NULL; | |
128 | 1 | } | |
129 | |||
130 |