Commit 8e2a43de authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add barycenter performance test

parent 374f01dd
......@@ -3,4 +3,5 @@ cmake_minimum_required(VERSION 2.8)
add_subdirectory(hadamard)
add_subdirectory(saxpy)
add_subdirectory(barycenter)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
set(CONFIG_BARYCENTER "1000, 2000, 3000, 4000, 5000, 10000, 50000, 100000, 200000, 500000, 1000000, 5000000, 10000000")
set(progSrc barycenter.cpp main.cpp)
phoenix_compileAndRunExample(perf_barycenter_par_O0 "-O0" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_par_O1 "-O1" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_par_O2 "-O2" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_par_O3 "-O3" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_par_Ofast "-Ofast" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_par_vectorize_O3 "-O3 -ftree-vectorize -march=native -mtune=native -mavx2" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_par_vectorize_Ofast "-Ofast -ftree-vectorize -march=native -mtune=native -mavx2" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_plotPerfLogX("barycenter_parBase" perf_barycenter_par_O0 perf_barycenter_par_O1 perf_barycenter_par_O2 perf_barycenter_par_O3 perf_barycenter_par_Ofast)
phoenix_plotPerfLogX("barycenter_parVectorize" perf_barycenter_par_O3 perf_barycenter_par_vectorize_O3 perf_barycenter_par_vectorize_Ofast)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
//some doc at : https://en.cppreference.com/w/cpp/header/algorithm
#include <algorithm>
//Some doc at : https://en.cppreference.com/w/cpp/header/execution
#include <execution>
#include "barycenter.h"
///Do a classical barycenter
/** @param[out] res : result
* @param tabX : talbe of x values
* @param nbElement : number of elements in the tables
*/
void barycenter(float & res, const float* tabX, size_t nbElement){
res = std::transform_reduce(std::execution::par_unseq,
tabX, tabX + nbElement,
0.0f, std::plus<float>(),
[](float xi){ return xi; });
res /= (float)nbElement;
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#ifndef __BARYCENTER_H__
#define __BARYCENTER_H__
#include <iostream>
void barycenter(float & res, const float* tabX, size_t nbElement);
#endif
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include <iostream>
#include "micro_benchmark.h"
#include "PTensor.h"
#include "barycenter.h"
///Get the number of nanoseconds per elements
/** @param nbElement : number of elements of the tables
*/
void evaluateBarycenter(size_t nbElement){
PTensor<float> tabX(AllocMode::ALIGNED, nbElement);
for(size_t i(0lu); i < nbElement; ++i){
tabX[i] = i*19lu%11;
}
float res(0.0f);
micro_benchmarkAutoNsPrint("evaluate barycenter", nbElement, barycenter, res, tabX.getData(), nbElement);
}
int main(int argc, char** argv){
return micro_benchmarkParseArg(argc, argv, evaluateBarycenter);
}
......@@ -3,4 +3,6 @@ cmake_minimum_required(VERSION 2.8)
add_subdirectory(hadamard)
add_subdirectory(saxpy)
add_subdirectory(barycenter)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
set(CONFIG_BARYCENTER "1000, 2000, 3000, 4000, 5000, 10000")
set(progSrc barycenter.cpp main.cpp)
phoenix_compileAndRunExample(perf_barycenter_seq_O0 "-O0" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_seq_O1 "-O1" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_seq_O2 "-O2" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_seq_O3 "-O3" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_seq_Ofast "-Ofast" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_seq_vectorize_O3 "-O3 -ftree-vectorize -march=native -mtune=native -mavx2" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter_seq_vectorize_Ofast "-Ofast -ftree-vectorize -march=native -mtune=native -mavx2" "${CONFIG_BARYCENTER}" ${progSrc})
phoenix_plotPerf("barycenter_seqBase" perf_barycenter_seq_O0 perf_barycenter_seq_O1 perf_barycenter_seq_O2 perf_barycenter_seq_O3 perf_barycenter_seq_Ofast)
phoenix_plotPerf("barycenter_seqVectorize" perf_barycenter_seq_O3 perf_barycenter_seq_vectorize_O3 perf_barycenter_seq_vectorize_Ofast)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
//some doc at : https://en.cppreference.com/w/cpp/header/algorithm
#include <algorithm>
//Some doc at : https://en.cppreference.com/w/cpp/header/execution
#include <execution>
#include "barycenter.h"
///Do a classical barycenter
/** @param[out] res : result
* @param tabX : talbe of x values
* @param nbElement : number of elements in the tables
*/
void barycenter(float & res, const float* tabX, size_t nbElement){
res = std::transform_reduce(std::execution::unseq,
tabX, tabX + nbElement,
0.0f, std::plus<float>(),
[](float xi){ return xi; });
res /= (float)nbElement;
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#ifndef __BARYCENTER_H__
#define __BARYCENTER_H__
#include <iostream>
void barycenter(float & res, const float* tabX, size_t nbElement);
#endif
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include <iostream>
#include "micro_benchmark.h"
#include "PTensor.h"
#include "barycenter.h"
///Get the number of nanoseconds per elements
/** @param nbElement : number of elements of the tables
*/
void evaluateBarycenter(size_t nbElement){
PTensor<float> tabX(AllocMode::ALIGNED, nbElement);
for(size_t i(0lu); i < nbElement; ++i){
tabX[i] = i*19lu%11;
}
float res(0.0f);
micro_benchmarkAutoNsPrint("evaluate barycenter", nbElement, barycenter, res, tabX.getData(), nbElement);
}
int main(int argc, char** argv){
return micro_benchmarkParseArg(argc, argv, evaluateBarycenter);
}
......@@ -21,7 +21,7 @@
* @param nbElement : number of elements in the tables
*/
void saxpy(float * tabRes, const float* tabX, const float* tabY, float scal, size_t nbElement){
std::transform(std::execution::seq, tabX, tabX + nbElement, tabY, tabRes,
std::transform(std::execution::unseq, tabX, tabX + nbElement, tabY, tabRes,
[=](float xi, float yi){ return scal * xi + yi; });
}
......
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