Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 1d5e7718 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

First full proxy test works, OK

parent 29999275
Pipeline #95386 passed with stages
in 3 minutes and 54 seconds
......@@ -5,9 +5,10 @@ add_subdirectory(HadamardProduct)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/HadamardProduct)
add_executable(test_proxy_hadamard_product main.cpp)
target_link_libraries(test_proxy_hadamard_product hadamard_product)
# set_property(TARGET test_proxy_hadamard_product PROPERTY BUILD_RPATH_USE_ORIGIN "${CMAKE_CURRENT_BINARY_DIR}/HadamardProduct")
# set_property(TARGET test_proxy_hadamard_product PROPERTY BUILD_RPATH "${CMAKE_CURRENT_BINARY_DIR}/HadamardProduct")
target_link_libraries(test_proxy_hadamard_product hadamard_product dl)
......
......@@ -24,7 +24,7 @@ add_library(hadamard_product_avx2 SHARED ${HADAMARD_PRODUCT_BASE_SOURCE})
set_property(TARGET hadamard_product_avx2 PROPERTY COMPILE_FLAGS "-O3 -ftree-vectorize -march=native -mtune=native -mavx2 -DFLOAT_VECTOR_ALIGNEMENT=32")
add_library(hadamard_product_avx512f SHARED ${HADAMARD_PRODUCT_BASE_SOURCE})
set_property(TARGET hadamard_product_avx512f PROPERTY COMPILE_FLAGS "-O3 -ftree-vectorize -march=native -mtune=native -mavx512f -DFLOAT_VECTOR_ALIGNEMENT=32")
set_property(TARGET hadamard_product_avx512f PROPERTY COMPILE_FLAGS "-O3 -ftree-vectorize -march=native -mtune=native -mavx512f -DFLOAT_VECTOR_ALIGNEMENT=64")
set(HADAMARD_PRODUCT_LIBS hadamard_product_anyarch hadamard_product_sse2 hadamard_product_ssse3 hadamard_product_sse4 hadamard_product_avx hadamard_product_avx2 hadamard_product_avx512f)
......@@ -41,7 +41,7 @@ set(OUTPUT_PROXY_FILES ${CMAKE_CURRENT_BINARY_DIR}/hadamard_product.h
add_custom_command(OUTPUT ${OUTPUT_PROXY_FILES}
COMMAND ${CMAKE_BINARY_DIR}/src/phoenix_hpc_proxy -i ${CMAKE_CURRENT_SOURCE_DIR}/hadamard_product.h -l hadamard_product --anyarch=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_anyarch.so --sse2=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_sse2.so --ssse3=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_ssse3.so --sse4.2=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_sse4.so --avx=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_avx.so --avx2=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_avx2.so --avx512f=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_avx512f.so
COMMAND ${CMAKE_BINARY_DIR}/src/phoenix_hpc_proxy -i ${CMAKE_CURRENT_SOURCE_DIR}/hadamard_product.h -l hadamard_product --anyarch=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_anyarch.so --sse2=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_sse2.so --ssse3=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_ssse3.so --sse4.2=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_sse4.so --avx=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_avx.so --avx2=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_avx2.so --avx512f=${CMAKE_CURRENT_BINARY_DIR}/libhadamard_product_avx512f.so --libdir=${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS phoenix_hpc_proxy ${HADAMARD_PRODUCT_LIBS}
COMMENT "Create the proxy hadamard product"
......
......@@ -4,12 +4,62 @@
Licence : CeCILL-C
****************************************/
#ifndef __APPLE__
# include <malloc.h>
#else
# include <stdlib.h>
#endif
#include <iostream>
#include "hadamard_product.h"
#define VECTOR_ALIGNEMENT 64lu
#ifdef __APPLE__
///Alloc an aligned vector
/** @param sizeOfVectorInBytes : size of the vector xe want to allocate
* @param alignementInBytes : alignement of the vector we want to allocate
* @return aligned pointor of the vector
*/
void * memalign(long unsigned int alignementInBytes, long unsigned int sizeOfVectorInBytes){
void * ptr = NULL;
posix_memalign(&ptr, alignementInBytes, sizeOfVectorInBytes);
return ptr;
}
#endif
///Do the aligned allocation of a pointer
/** @param sizeOfVectorInBytes : number of bytes to be allocated
* @return allocated pointer
*/
void * custom_aligned_malloc(long unsigned int sizeOfVectorInBytes){
return memalign(VECTOR_ALIGNEMENT, sizeOfVectorInBytes);
}
///Free an aligned pointer
/** @param ptr : ptr to be freed
*/
void custom_aligned_free(void* ptr){
free(ptr);
}
///Test the proxy library
void testProxyLib(){
size_t nbElement(1000lu);
float * tabX = (float*)custom_aligned_malloc(sizeof(float)*nbElement);
float * tabY = (float*)custom_aligned_malloc(sizeof(float)*nbElement);
float * tabRes = (float*)custom_aligned_malloc(sizeof(float)*nbElement);
for(size_t i(0lu); i < nbElement; ++i){
tabX[i] = i*19lu%11;
tabY[i] = i*27lu%19;
}
hadamard_product(tabRes, tabX, tabY, nbElement);
std::cout << "testProxyLib = tabRes[0] = " << tabRes[0] << std::endl;
custom_aligned_free(tabRes);
custom_aligned_free(tabY);
custom_aligned_free(tabX);
}
int main(int argc, char** argv){
......
......@@ -107,7 +107,7 @@ std::string cpp_backendTableHeaderHandleType(PFunction & function){
*/
std::string cpp_backendHeader(PSource & source){
std::string body(cpp_licenceSaveStr());
std::string baseMacro("__" + strToUpper(eraseExtension(source.getName())) + "_H__");
std::string baseMacro("__" + strToUpper(eraseExtension(source.getName())) + "_PROXY_H__");
body += "#ifndef " + baseMacro + "\n";
body += "#define " + baseMacro + "\n\n";
body += "#include <iostream>\n\n\n";
......
......@@ -49,8 +49,9 @@ std::string cpp_backendProxyLoaderHeader(const std::string & libraryName, const
std::string cpp_backendProxyLoaderConstructorSource(const std::string & className, const std::string & defaultLib){
std::string body("");
body += "///Default constructor of "+className+"\n";
body += ""+className+"::"+className+"(){\n";
body += className+"::"+className+"(){\n";
body += "\tinitialisation"+className+"();\n";
body += "\tstd::cout << \""+className+"::"+className+"() : check current architecture\" << std::endl;\n";
body += "\t//First get the /proc/cpuinfo file\n";
body += "\tif(!parseArchFile(\"/proc/cpuinfo\")){\n";
body += "\t\t//No library found, let's load the default library\n";
......@@ -102,9 +103,10 @@ std::string cpp_backendProxyLoaderLoadSource(const std::string & className){
///Create the Source of the ProxyLoader load
/** @param vecArchLib : vector of library to be loaded on the fly by respect to the host architecture
* @param className : name of the ProxyLoader class
* @param libDir : directory where the sub libraries are installed
* @return corresponding code
*/
std::string cpp_backendProxyLoaderParseArchFileSource(const PVecArchLib & vecArchLib, const std::string & className){
std::string cpp_backendProxyLoaderParseArchFileSource(const PVecArchLib & vecArchLib, const std::string & className, const std::string & libDir){
std::string body("");
body += "///Parse the given architecture file\n";
body += "/**\t@param archfileName : name of the architecture file to be loaded\n";
......@@ -116,23 +118,43 @@ std::string cpp_backendProxyLoaderParseArchFileSource(const PVecArchLib & vecArc
body += "\t\tstd::cerr << \"Cannot open file '\" << archfileName << \"'\" << std::endl;\n";
body += "\t\treturn false;\n";
body += "\t}\n";
body += "\t//Let's get the file size\n";
body += "\tfseek(fp, 0, SEEK_END);\n";
body += "\tsize_t fileSize(ftell(fp));\n";
body += "\tfseek(fp, 0, SEEK_SET);\n";
body += "\tif(fileSize == 0lu){\n";
body += "\t\treturn false;\n";
body += "\tstd::string bufferAllFile(\"\");\n";
body += "\tint buffer;\n";
body += "\twhile(!feof(fp)){\n";
body += "\t\tbuffer = fgetc(fp);\n";
body += "\t\tif(buffer != EOF) bufferAllFile += (char)buffer;\n";
body += "\t\telse break;\n";
body += "\t}\n";
body += "\t//Now we can alloate the table to get the file content\n";
body += "\tchar * procCpuInfo = new char[fileSize];\n";
body += "\t//And load the file\n";
body += "\tif(fread(procCpuInfo, sizeof(char), fileSize, fp) != fileSize){return false;}\n";
body += "\tif(bufferAllFile == \"\"){\n";
body += "\t\tstd::cerr << \"Empty file '\" << archfileName << \"'\" << std::endl;\n";
body += "\t\treturn false;\n\t}\n";
body += "\tconst char * procCpuInfo = bufferAllFile.c_str();\n";
//The following method does not work with text file for some reason
// body += "\t//Let's get the file size\n";
// body += "\tfseek(fp, 0, SEEK_END);\n";
// body += "\tsize_t fileSize(ftell(fp));\n";
// body += "\tfseek(fp, 0, SEEK_SET);\n";
// body += "\tif(fileSize == 0lu){\n";
// body += "\t\tstd::cerr << \"Empty file '\" << archfileName << \"'\" << std::endl;\n";
// body += "\t\treturn false;\n";
// body += "\t}\n";
// body += "\t//Now we can alloate the table to get the file content\n";
// body += "\tchar * procCpuInfo = new char[fileSize];\n";
// body += "\t//And load the file\n";
// body += "\tif(fread(procCpuInfo, sizeof(char), fileSize, fp) != fileSize){\n";
// body += "\t\tstd::cerr << \"Cannot read file '\" << archfileName << \"'\" << std::endl;\n";
// body += "\t\treturn false;\n\t}\n";
body += "\t//Let's check the avalaible architectures\n";
body += "\tbool isLibFound(true);\n";
std::string strElse("\t");
std::string strElse("\t"), libraryFullDirectory("");
if(libDir != ""){
libraryFullDirectory = libDir + "/";
}
for(PVecArchLib::const_reverse_iterator it(vecArchLib.rbegin()); it != vecArchLib.rend(); ++it){
body += strElse + "if(strstr(procCpuInfo, \""+it->getArchitecture()+"\") != NULL){\n";
std::string libName(getFileName(it->getName()));
std::string libName(libraryFullDirectory + getFileName(it->getName()));
body += "\t\tload(\""+libName+"\");\n";
body += "\t}";
strElse = "else ";
......@@ -140,7 +162,7 @@ std::string cpp_backendProxyLoaderParseArchFileSource(const PVecArchLib & vecArc
body += "else{\n\t\tisLibFound = false;\n\t}\n";
body += "\n";
body += "\tfclose(fp);\n";
body += "\tdelete [] procCpuInfo;\n";
// body += "\tdelete [] procCpuInfo;\n";
body += "\treturn isLibFound;\n";
body += "}\n\n";
return body;
......@@ -185,7 +207,7 @@ std::string cpp_backendProxyLoaderUpdateSource(const std::string & className, co
std::string body("");
body += "///Update the functions to be used\n";
body += "void "+className+"::updateFunction(){\n";
body += "\tif(!isOpen()){return;}\n";
body += "\tif(!isOpen()){exit(-1);return;}\n";
body += "\t//Then set all the function pointers\n";
for(PVecSource::const_iterator it(vecSource.begin()); it != vecSource.end(); ++it){
body += "\t"+getUpdateFunction(it->getName())+"(p_handle);\n";
......@@ -211,10 +233,11 @@ std::string cpp_backendProxyLoaderInitialisationSource(const std::string & class
/** @param vecSource : vector of source
* @param vecArchLib : vector of library to be loaded on the fly by respect to the host architecture
* @param className : name of the ProxyLoader class
* @param libDir : directory where the sub libraries are installed
* @return corresponding code
*/
std::string cpp_backendProxyLoaderSource(const PVecSource & vecSource, const PVecArchLib & vecArchLib,
const std::string & className)
const std::string & className, const std::string & libDir)
{
std::string body(cpp_licenceSaveStr());
body += "#include <stdio.h>\n";
......@@ -232,7 +255,7 @@ std::string cpp_backendProxyLoaderSource(const PVecSource & vecSource, const PVe
body += cpp_backendProxyLoaderConstructorSource(className, defaultLib);
body += cpp_backendProxyLoaderDesonstructorSource(className);
body += cpp_backendProxyLoaderLoadSource(className);
body += cpp_backendProxyLoaderParseArchFileSource(vecArchLib, className);
body += cpp_backendProxyLoaderParseArchFileSource(vecArchLib, className, libDir);
body += cpp_backendProxyLoaderIsOpenSource(className);
body += cpp_backendProxyLoaderCloseSource(className);
body += cpp_backendProxyLoaderUpdateSource(className, vecSource);
......@@ -244,13 +267,14 @@ std::string cpp_backendProxyLoaderSource(const PVecSource & vecSource, const PVe
/** @param vecSource : vector of source
* @param libraryName : name of the library to be created
* @param vecArchLib : vector of library to be loaded on the fly by respect to the host architecture
* @param libDir : directory where the sub libraries are installed
* @param outputDir : output directory where to save ProxyLoader
* @return true on success, false otherwise
*/
bool cpp_backend_proxy(const PVecSource & vecSource, const std::string & libraryName, const PVecArchLib & vecArchLib, const std::string & outputDir){
bool cpp_backend_proxy(const PVecSource & vecSource, const std::string & libraryName, const PVecArchLib & vecArchLib, const std::string & libDir, const std::string & outputDir){
std::string className(firstToUpper(libraryName + "ProxyLoader"));
std::string headerSrc(cpp_backendProxyLoaderHeader(libraryName, className));
std::string sourceSrc(cpp_backendProxyLoaderSource(vecSource, vecArchLib, className));
std::string sourceSrc(cpp_backendProxyLoaderSource(vecSource, vecArchLib, className, libDir));
std::string outputHeaderFile(outputDir + "/" + className + ".h");
std::string outputSourceFile(outputDir + "/" + className + ".cpp");
if(!saveFileContent(outputHeaderFile, headerSrc)){
......
......@@ -9,6 +9,6 @@
#include "Representation/representation.h"
bool cpp_backend_proxy(const PVecSource & vecSource, const std::string & libraryName, const PVecArchLib & vecArchLib, const std::string & outputDir);
bool cpp_backend_proxy(const PVecSource & vecSource, const std::string & libraryName, const PVecArchLib & vecArchLib, const std::string & libDir, const std::string & outputDir);
#endif
......@@ -27,16 +27,18 @@ OptionParser createOptionParser(){
std::string libName("lib_shadok");
parser.addOption("library", "l", libName, "name of the library to be created");
parser.addOption("anyarch", "a", OptionType::FILENAME, false, "file name of the library to be used for any architectures (kind of security if the other architectures are not found)");
parser.addOption("sse", "b", OptionType::FILENAME, false, "file name of the library to be used for sse architecture");
parser.addOption("sse2", "c", OptionType::FILENAME, false, "file name of the library to be used for sse2 architecture");
parser.addOption("ssse3", "d", OptionType::FILENAME, false, "file name of the library to be used for ssse3 architecture");
parser.addOption("sse4.1", "e", OptionType::FILENAME, false, "file name of the library to be used for sse4.1 architecture");
parser.addOption("sse4.2", "f", OptionType::FILENAME, false, "file name of the library to be used for sse4.2 architecture");
parser.addOption("avx", "g", OptionType::FILENAME, false, "file name of the library to be used for avx architecture");
parser.addOption("avx2", "j", OptionType::FILENAME, false, "file name of the library to be used for avx2 architecture");
parser.addOption("avx512f", "k", OptionType::FILENAME, false, "file name of the library to be used for avx512f architecture");
parser.addOption("avx512wb", "m", OptionType::FILENAME, false, "file name of the library to be used for avx512wb architecture");
parser.addOption("libdir", "d", OptionType::DIRECTORY, false, "directory where the sub libraries are installed");
parser.addOption("anyarch", "", OptionType::FILENAME, false, "file name of the library to be used for any architectures (kind of security if the other architectures are not found)");
parser.addOption("sse", "", OptionType::FILENAME, false, "file name of the library to be used for sse architecture");
parser.addOption("sse2", "", OptionType::FILENAME, false, "file name of the library to be used for sse2 architecture");
parser.addOption("ssse3", "", OptionType::FILENAME, false, "file name of the library to be used for ssse3 architecture");
parser.addOption("sse4.1", "", OptionType::FILENAME, false, "file name of the library to be used for sse4.1 architecture");
parser.addOption("sse4.2", "", OptionType::FILENAME, false, "file name of the library to be used for sse4.2 architecture");
parser.addOption("avx", "", OptionType::FILENAME, false, "file name of the library to be used for avx architecture");
parser.addOption("avx2", "", OptionType::FILENAME, false, "file name of the library to be used for avx2 architecture");
parser.addOption("avx512f", "", OptionType::FILENAME, false, "file name of the library to be used for avx512f architecture");
parser.addOption("avx512wb", "", OptionType::FILENAME, false, "file name of the library to be used for avx512wb architecture");
std::string defaultOutputDir(".");
......@@ -78,10 +80,13 @@ void parseVecArchLib(PVecArchLib & vecArchLib, const OptionMode & defaultMode){
/** @param inputFile : name of the input file to be used
* @param libraryName : name of the library to be created
* @param vecArchLib : vector of library architecture to be used
* @param libDir : directory where the sub libraries are installed
* @param outputDir : output directory to be used
* @return true on success, false otherwise
*/
bool createSourceFromConfig(const std::string & inputFile, const std::string & libraryName, const PVecArchLib & vecArchLib, const std::string & outputDir){
bool createSourceFromConfig(const std::string & inputFile, const std::string & libraryName, const PVecArchLib & vecArchLib,
const std::string & libDir, const std::string & outputDir)
{
HeaderParser parser;
if(!parser.load(inputFile)){
std::cerr << "createSourceFromConfig : cannot parse the input file '"<<inputFile<<"'" << std::endl;
......@@ -98,7 +103,7 @@ bool createSourceFromConfig(const std::string & inputFile, const std::string & l
std::cerr << "createSourceFromConfig : cannot save source/header from input file '"<<inputFile<<"'" << std::endl;
return b;
}
b &= cpp_backend_proxy(vecSource, libraryName, vecArchLib, outputDir);
b &= cpp_backend_proxy(vecSource, libraryName, vecArchLib, libDir, outputDir);
if(!b){
std::cerr << "createSourceFromConfig : cannot save source/header ProxyLoader class" << std::endl;
return b;
......@@ -110,13 +115,16 @@ bool createSourceFromConfig(const std::string & inputFile, const std::string & l
/** @param listInputFile : list of the input files
* @param libraryName : name of the library to be created
* @param vecArchLib : vector of library architecture to be used
* @param libDir : directory where the sub libraries are installed
* @param outputDir : output directory to be used
* @return 0 on success, -1 otherwise
*/
int processFiles(const std::list<std::string> & listInputFile, const std::string & libName, const PVecArchLib & vecArchLib, const std::string & outputDir){
int processFiles(const std::list<std::string> & listInputFile, const std::string & libName, const PVecArchLib & vecArchLib,
const std::string & libDir, const std::string & outputDir)
{
bool b(true);
for(std::list<std::string>::const_iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
b &= createSourceFromConfig(*it, libName, vecArchLib, outputDir);
b &= createSourceFromConfig(*it, libName, vecArchLib, libDir, outputDir);
}
return b - 1;
}
......@@ -129,14 +137,15 @@ int main(int argc, char** argv){
std::list<std::string> listInputFile;
defaultMode.getValue(listInputFile, "header");
std::string outputDir("."), libName("");
std::string outputDir("."), libName(""), libDir("");
defaultMode.getValue(outputDir, "output");
defaultMode.getValue(libName, "library");
defaultMode.getValue(libDir, "libdir");
PVecArchLib vecArchLib;
parseVecArchLib(vecArchLib, defaultMode);
return processFiles(listInputFile, libName, vecArchLib, outputDir);
return processFiles(listInputFile, libName, vecArchLib, libDir, outputDir);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment