Commit c705a208 authored by Bramas, Berenger (bbramas)'s avatar Bramas, Berenger (bbramas)

Merge branch 'flop-counter' into 'master'

Add Flops class and Flops example to compute flop easily

See merge request !8
parents f4f6f85a a8fef81c
......@@ -36,6 +36,20 @@ inline VecType FastPow(VecType base, std::size_t power){
return res;
}
inline std::size_t FastPowNbMul(std::size_t power){
std::size_t nbMul = 0;
while(power){
if(1 & power){
nbMul += 1;
}
nbMul += 1;
power >>= 1;
}
return nbMul;
}
}
#endif // UTILS_HPP
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// Inastemp - Berenger Bramas MPCDF - 2016
// Under MIT Licence, please you must read the LICENCE file.
///////////////////////////////////////////////////////////////////////////
#ifndef FLOPSTESTALL_HPP
#define FLOPSTESTALL_HPP
#include "InastempConfig.h"
#include "UTester.hpp"
#include <cmath>
#include <cstring>
template < class VecType >
class FlopsTestAll : public UTester< FlopsTestAll< VecType > > {
using Parent = UTester< FlopsTestAll< VecType > >;
using RealType = typename VecType::RealType;
using MaskType = typename VecType::MaskType;
void TestBasic() {
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
VecType a = 1;
{
VecType res = a + a;
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(1));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
res += a;
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
}
VecType::ResetFlopsStats();
{
VecType res = a * a;
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(1));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
res *= a;
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
}
VecType::ResetFlopsStats();
{
VecType res = a / a;
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(1));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
res /= a;
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
}
VecType::ResetFlopsStats();
{
VecType res = a - a;
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(1));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
res -= a;
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
}
VecType::ResetFlopsStats();
{
VecType res = (a*a) + (a/a) - (a+a) * (a-a) / a;
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
res = VecType(0.);
UASSERTEEQUAL(VecType::GetFlopsStats().getMulOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getDivOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getAddOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getSubOp() , VecType::VecLength * size_t(2));
UASSERTEEQUAL(VecType::GetFlopsStats().getRsqrt() , VecType::VecLength * size_t(0));
UASSERTEEQUAL(VecType::GetFlopsStats().getSqrt() , VecType::VecLength * size_t(0));
}
}
void SetTests() {
Parent::AddTest(&FlopsTestAll::TestBasic, "Basic test for vec type");
}
};
#endif
......@@ -8,11 +8,16 @@
#include "@TYPE@/InaVec@TYPE@Float.hpp"
#include "core-test-all.hpp"
#include "FLOPS/InaVecFLOPS.hpp"
int main() {
// clang-format off
TestAll<InaVec@TYPE@<double>> testerDouble;
TestAll<InaVec@TYPE@<float>> testerSingle;
TestAll<InaVecFLOPS<InaVec@TYPE@<double>>> testerDoubleFlops;
TestAll<InaVecFLOPS<InaVec@TYPE@<float>>> testerSingleFlops;
// clang-format on
return testerDouble.Run() + testerSingle.Run();
return testerDouble.Run() + testerSingle.Run()
+ testerDoubleFlops.Run() + testerSingleFlops.Run();
}
///////////////////////////////////////////////////////////////////////////
// Inastemp - Berenger Bramas MPCDF - 2016
// Under MIT Licence, please you must read the LICENCE file.
///////////////////////////////////////////////////////////////////////////
#include "InastempConfig.h"
#include "@TYPE@/InaVec@TYPE@Double.hpp"
#include "@TYPE@/InaVec@TYPE@Float.hpp"
#include "flops-test-all.hpp"
#include "FLOPS/InaVecFLOPS.hpp"
int main() {
// clang-format off
FlopsTestAll<InaVecFLOPS<InaVec@TYPE@<double>>> testerDoubleFlops;
FlopsTestAll<InaVecFLOPS<InaVec@TYPE@<float>>> testerSingleFlops;
// clang-format on
return testerDoubleFlops.Run() + testerSingleFlops.Run();
}
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