Commit 9000296a authored by Berenger Bramas's avatar Berenger Bramas

Update Examples -- add the first function to test the perf model

parent 81884818
###########################################################################
# Inastemp - Berenger Bramas MPCDF - 2016
# Under MIT Licence, please you must read the LICENCE file.
###########################################################################
project(EXAMPLES_PERFMODEL_INASTEMP C CXX)
ADD_DEFINITIONS(${INASTEMP_CXX_FLAGS})
OPTION( INASTEMP_BUILD_PATTERNS "Set to ON to build pattern examples" ON )
if($ENV{VERBOSE})
MESSAGE(STATUS "Examples -- PERFMODEL")
endif()
# Find all code files
file(
GLOB_RECURSE
source_tests_files
./*.cpp
)
# Adding the project sources dir as an include dir
INCLUDE_DIRECTORIES(
${INASTEMP_BINARY_DIR}/Src
${INASTEMP_SOURCE_DIR}/Src
./
)
# Add execs - 1 cpp = 1 exec
foreach(exec ${source_tests_files})
get_filename_component(
execname ${exec}
NAME_WE
)
set(execname "perfmodel-${execname}")
if($ENV{VERBOSE})
MESSAGE(STATUS "Examples -- PERFMODEL ${execname}")
endif()
add_executable(
${execname}
${exec}
)
target_link_libraries(
${execname}
${INASTEMP_LIBRARIES}
)
endforeach(exec)
///////////////////////////////////////////////////////////////////////////
// Inastemp - Berenger Bramas MPCDF - 2016
// Under MIT Licence, please you must read the LICENCE file.
///////////////////////////////////////////////////////////////////////////
#include "InastempConfig.h"
#include "SCALAR/InaVecSCALARDouble.hpp"
#include "SCALAR/InaVecSCALARFloat.hpp"
#include <cassert>
#include <iostream>
#include <memory>
template < class VecType >
VecType DummyPower(VecType inVal, const int inPow){
VecType res = 1;
for( int idx = 0 ; idx < inPow ; ++idx) {
res *= inVal;
}
return res;
}
template < class VecType, class MaskType, class RealType >
void KernelAll(RealType inVal, MaskType msk, int pow1, int pow2, int pow3, size_t nbLoops){
VecType vec = inVal;
for(size_t idxLoop = 0 ; idxLoop < nbLoops ; ++idxLoop){
vec += DummyPower(inVal, pow1);
vec += VecType::IfElse(msk, DummyPower(inVal, pow2), DummyPower(inVal, pow3));
}
}
template < class VecType, class MaskType, class RealType >
void KernelIfTrue(RealType inVal, MaskType msk, int pow1, int pow2, int pow3, size_t nbLoops){
VecType vec = inVal;
for(size_t idxLoop = 0 ; idxLoop < nbLoops ; ++idxLoop){
vec += DummyPower(inVal, pow1);
if( msk.isAllTrue() ){
vec += DummyPower(inVal, pow2);
}
else{
vec += VecType::IfElse(msk, DummyPower(inVal, pow2), DummyPower(inVal, pow3));
}
}
}
template < class VecType, class RealType >
void test(const size_t nbLoops){
std::cout << "The best vectorizer computes " << VecType::GetName() << " double values together." << std::endl;
KernelAll<VecType, typename VecType::MaskType, RealType>(1, typename VecType::MaskType(), 1, 2, 3, nbLoops);
}
int main() {
const size_t nbLoops = 10000;
test<InaVecBestType<double>, double>(nbLoops);
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