Commit 8cc89dfa authored by Berenger Bramas's avatar Berenger Bramas

Update example - exponential - to have time per exp and being able to move to float

parent 525c741e
......@@ -8,6 +8,7 @@
#include "InastempConfig.h"
#include "SCALAR/InaVecSCALARDouble.hpp"
#include "SCALAR/InaVecSCALARFloat.hpp"
#include "Common/InaTimer.hpp"
#include <memory>
......@@ -26,40 +27,67 @@ int main(int /*argc*/, char* /*argv*/ []) {
{
InaTimer timer;
InaVecSCALAR<double> vectorizer;
InaVecSCALAR<RealType> vectorizer;
for (size_t idxLoop = 0; idxLoop < NbOverLoop; ++idxLoop) {
for (size_t idx = 0; idx < NbExp; ++idx) {
resScalar[idx] = static_cast<double>(InaVecSCALAR<double>(double(idx % 200)).exp());
resScalar[idx] = static_cast<RealType>(InaVecSCALAR<RealType>(RealType(idx % 200)).exp());
}
}
timer.stop();
std::cout << "Scalar for " << NbExp * NbOverLoop << " exp took " << timer.getElapsed() << "s\n";
std::cout << "Scalar for " << NbExp * NbOverLoop
<< " exp took " << timer.getElapsed() << "s (" << timer.getElapsed()/double(NbExp * NbOverLoop) << "s per exp)\n";
}
/////////////////////////////////////////////////////////////
// Note : we increase the length of the vector to avoid checking the loop size
std::unique_ptr< RealType[] > resIna(new RealType[NbExp + InaVecBestType<double>::VecLength]);
std::unique_ptr< RealType[] > resIna(new RealType[NbExp + InaVecBestType<RealType>::VecLength]);
{
InaTimer timer;
alignas(64) double bufferX[InaVecBestType<double>::VecLength];
alignas(64) RealType bufferX[InaVecBestType<RealType>::VecLength];
for (size_t idxLoop = 0; idxLoop < NbOverLoop; ++idxLoop) {
for (size_t idx = 0; idx < NbExp; idx += InaVecBestType<double>::VecLength) {
for (size_t idx = 0; idx < NbExp; idx += InaVecBestType<RealType>::VecLength) {
// Copy value into a buffer since we do it on the fly
for (size_t idxX = 0; idxX < InaVecBestType<double>::VecLength; ++idxX) {
bufferX[idxX] = static_cast<double>((idx + idxX) % 200);
for (size_t idxX = 0; idxX < InaVecBestType<RealType>::VecLength; ++idxX) {
bufferX[idxX] = static_cast<RealType>((idx + idxX) % 200);
}
InaVecBestType<double>(bufferX).exp().storeInArray(&resIna[idx]);
InaVecBestType<RealType>(bufferX).exp().storeInArray(&resIna[idx]);
}
}
timer.stop();
std::cout << "Vector " << InaVecBestType<double>::GetName() << " for " << NbExp * NbOverLoop << " exp took " << timer.getElapsed() << "s\n";
std::cout << "Vector " << InaVecBestType<RealType>::GetName() << " for " << NbExp * NbOverLoop
<< " exp took " << timer.getElapsed() << "s (" << timer.getElapsed()/double(NbExp * NbOverLoop) << "s per exp)\n";
}
/////////////////////////////////////////////////////////////
// Note : we increase the length of the vector to avoid checking the loop size
std::unique_ptr< RealType[] > resInaLowAcc(new RealType[NbExp + InaVecBestType<RealType>::VecLength]);
{
InaTimer timer;
alignas(64) RealType bufferX[InaVecBestType<RealType>::VecLength];
for (size_t idxLoop = 0; idxLoop < NbOverLoop; ++idxLoop) {
for (size_t idx = 0; idx < NbExp; idx += InaVecBestType<RealType>::VecLength) {
// Copy value into a buffer since we do it on the fly
for (size_t idxX = 0; idxX < InaVecBestType<RealType>::VecLength; ++idxX) {
bufferX[idxX] = static_cast<RealType>((idx + idxX) % 200);
}
InaVecBestType<RealType>(bufferX).expLowAcc().storeInArray(&resInaLowAcc[idx]);
}
}
timer.stop();
std::cout << "Vector low acc " << InaVecBestType<RealType>::GetName() << " for " << NbExp * NbOverLoop
<< " exp took " << timer.getElapsed() << "s (" << timer.getElapsed()/double(NbExp * NbOverLoop) << "s per exp)\n";
}
return 0;
......
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