Commit 0ad70d40 authored by Jö Fahlke's avatar Jö Fahlke

Merge branch 'feature/implement-vectorclass-interface' into 'master'

implement SIMD-functionality

Closes #3

See merge request lukas.renelt/dune-vectorclass!3
parents c5e529aa e4af1b31
Pipeline #9530 failed with stage
in 0 seconds
---
before_script:
- duneci-install-module https://gitlab.dune-project.org/core/dune-common.git
debian:10 gcc:c++17:
image: duneci/base:10
script: duneci-standard-test
variables: {DUNECI_OPTS: /duneci/opts.gcc.c++17}
tags: [duneci]
debian:9--gcc:
image: duneci/base:9
script: duneci-standard-test
tags: [duneci]
debian:9--clang:
image: duneci/base:9
script: duneci-standard-test
variables: {DUNECI_OPTS: /duneci/opts.clang}
tags: [duneci]
ubuntu:16.04--gcc:
image: duneci/base:16.04
script: duneci-standard-test
tags: [duneci]
ubuntu:16.04--clang:
image: duneci/base:16.04
script: duneci-standard-test
variables: {DUNECI_OPTS: /duneci/opts.clang}
tags: [duneci]
......@@ -22,7 +22,6 @@ dune_project()
dune_enable_all_packages()
add_subdirectory(src)
add_subdirectory(dune)
add_subdirectory(doc)
add_subdirectory(cmake/modules)
......
......@@ -8,3 +8,4 @@ Version: Module
Maintainer: l_rene02@uni-muenster.de
#depending on
Depends: dune-common
Suggests: dune-istl
#install headers
install(FILES vectorclass.hh DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vectorclass)
dune_add_test(NAME vctest SOURCES vectorclasstest.cc LINK_LIBRARIES dunecommon)
add_subdirectory(test)
include(DuneCMakeCompat)
include(DuneInstance)
set(MAX_VECTOR_SIZE 512)
dune_instance_begin(FILES vectorclasstest.hh vectorclasstest.cc)
foreach(VECTOR_SIZE IN ITEMS 128 256 512)
# float and associated types
math(EXPR LANES "${VECTOR_SIZE} / 32")
set(TYPE f)
dune_instance_add(TEMPLATE VECTOR ID "${LANES}${TYPE}"
FILES vectorclasstest_vector.cc vectorclasstest_mask.cc)
set(TYPE i)
dune_instance_add(TEMPLATE INDEX ID "${LANES}${TYPE}"
FILES vectorclasstest_index.cc vectorclasstest_mask.cc)
# double and associated types
math(EXPR LANES "${VECTOR_SIZE} / 64")
set(TYPE d)
dune_instance_add(TEMPLATE VECTOR ID "${LANES}${TYPE}"
FILES vectorclasstest_vector.cc vectorclasstest_mask.cc)
set(TYPE q)
dune_instance_add(TEMPLATE INDEX ID "${LANES}${TYPE}"
FILES vectorclasstest_index.cc vectorclasstest_mask.cc)
endforeach(VECTOR_SIZE)
dune_instance_end()
dune_list_filter(DUNE_INSTANCE_GENERATED INCLUDE REGEX [[\.cc$]])
dune_add_test(NAME vectorclasstest-sse
SOURCES ${DUNE_INSTANCE_GENERATED}
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_FLAGS -msse2
LINK_LIBRARIES dunecommon
)
dune_add_test(NAME vectorclasstest-avx
SOURCES ${DUNE_INSTANCE_GENERATED}
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_FLAGS -mavx
LINK_LIBRARIES dunecommon
)
dune_add_test(NAME vectorclasstest-avx2
SOURCES ${DUNE_INSTANCE_GENERATED}
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_FLAGS -mavx2 -mfma
LINK_LIBRARIES dunecommon
)
dune_add_test(NAME vectorclasstest-avx512
SOURCES ${DUNE_INSTANCE_GENERATED}
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_FLAGS -mavx512f -mfma
LINK_LIBRARIES dunecommon
)
dune_add_test(NAME multirhstest-sse
SOURCES multirhstest.cc
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_FLAGS -msse2
LINK_LIBRARIES dunecommon
CMAKE_GUARD dune-istl_FOUND
)
dune_add_test(NAME multirhstest-avx
SOURCES multirhstest.cc
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_FLAGS -mavx
LINK_LIBRARIES dunecommon
CMAKE_GUARD dune-istl_FOUND
)
dune_add_test(NAME multirhstest-avx2
SOURCES multirhstest.cc
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_FLAGS -mavx2 -mfma
LINK_LIBRARIES dunecommon
CMAKE_GUARD dune-istl_FOUND
)
dune_add_test(NAME multirhstest-avx512
SOURCES multirhstest.cc
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_FLAGS -mavx512f -mfma
LINK_LIBRARIES dunecommon
CMAKE_GUARD dune-istl_FOUND
)
#include "config.h"
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <dune/common/classname.hh>
#include <dune/common/simd/loop.hh>
#include <dune/common/simd/simd.hh>
#include <dune/common/timer.hh>
#include <dune/istl/test/multirhstest.hh>
#include <dune/vectorclass/vectorclass.hh>
struct runInformation {
double vectorTime;
double scalarTime;
double loopTime;
std::string vectorName;
std::string scalarName;
std::string loopName;
int lanes;
};
template<class T>
runInformation performTest(){
runInformation result;
const int size = Dune::Simd::lanes<T>();
typedef Dune::Simd::Scalar<T> scalarType;
typedef Dune::LoopSIMD<scalarType,size> loopType;
result.vectorName = Dune::className<T>();
result.scalarName = Dune::className<scalarType>();
result.loopName = Dune::className<loopType>();
result.lanes = size;
Dune::Timer t;
test_all<T>();
result.vectorTime = t.stop();
t.reset();
t.start();
test_all<scalarType>();
result.scalarTime = t.stop();
t.reset();
t.start();
test_all<loopType>();
result.loopTime = t.stop();
return result;
}
int main(int argc, char ** argv)
{
std::vector<runInformation> times;
#if MAX_VECTOR_SIZE >= 128
times.push_back(performTest<Vec4f>());
times.push_back(performTest<Vec2d>());
#endif
#if MAX_VECTOR_SIZE >= 256
times.push_back(performTest<Vec8f>());
times.push_back(performTest<Vec4d>());
#endif
#if MAX_VECTOR_SIZE >= 512
times.push_back(performTest<Vec16f>());
times.push_back(performTest<Vec8d>());
#endif
for(auto el : times) {
double totalScalarTime = el.lanes * el.scalarTime;
double vectorTimePerLane = el.vectorTime/el.lanes;
std::cout << "========================================" << std::endl;
std::cout << "Time(" << el.vectorName << "): " << el.vectorTime << std::endl;
std::cout << "Time(" << el.scalarName << "): " << totalScalarTime << std::endl;
std::cout << "Difference (total): " << totalScalarTime-el.vectorTime << std::endl;
std::cout << "Difference (per lane): " << (totalScalarTime-el.vectorTime) / el.lanes << std::endl;
std::cout << "Difference (relative): " << (totalScalarTime-el.vectorTime)/el.vectorTime * 100 << "%" << std::endl;
std::cout << (el.scalarTime-vectorTimePerLane)/vectorTimePerLane / (el.lanes-1) << "% of expected difference reached" << std::endl;
std::cout << std::endl;
std::cout << "Time(" << el.vectorName << "): " << el.vectorTime << std::endl;
std::cout << "Time(" << el.loopName << "): " << el.loopTime << std::endl;
std::cout << "Difference (total): " << el.loopTime-el.vectorTime << std::endl;
std::cout << "Difference (per lane): " << (el.loopTime-el.vectorTime) / el.lanes << std::endl;
std::cout << "Difference (relative): " << (el.loopTime-el.vectorTime)/el.vectorTime * 100 << "%" << std::endl;
}
std::cout << "========================================" << std::endl;
return 0;
}
// @GENERATED_SOURCE@
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <cstddef>
#include <cstdlib>
#include <dune/common/simd/test.hh>
#include <dune/vectorclass/test/vectorclasstest.hh>
#include <dune/vectorclass/vectorclass.hh>
int main() {
Dune::Simd::UnitTest test;
#cmake @template VECTOR@
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
test.checkVector<Vec@LANES@@TYPE@>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
#cmake @endtemplate@
return test.good() ? EXIT_SUCCESS : EXIT_FAILURE;
}
// @GENERATED_SOURCE@
#ifndef DUNE_VECTORCLASS_TEST_VECTORCLASSTEST_HH
#define DUNE_VECTORCLASS_TEST_VECTORCLASSTEST_HH
#include <cstddef>
#include <dune/common/simd/test.hh>
#include <dune/vectorclass/vectorclass.hh>
namespace Dune {
namespace Simd {
#cmake @template VECTOR@
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
extern template void UnitTest::checkVector<Vec@LANES@@TYPE@>();
extern template void UnitTest::checkMask<Vec@LANES@@TYPE@b>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
#cmake @endtemplate@
#cmake @template INDEX@
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
extern template void UnitTest::checkIndex<Vec@LANES@@TYPE@>();
extern template void UnitTest::checkMask<Vec@LANES@@TYPE@b>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
#cmake @endtemplate@
}
}
#endif
// @GENERATED_SOURCE@
#include <config.h>
#include <dune/common/simd/test.hh>
#include <dune/vectorclass/test/vectorclasstest.hh>
namespace Dune {
namespace Simd {
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
template void UnitTest::checkIndex<Vec@LANES@@TYPE@>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
}
}
// @GENERATED_SOURCE@
#include <config.h>
#include <dune/vectorclass/test/vectorclasstest.hh>
namespace Dune {
namespace Simd {
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
template void UnitTest::checkMask<Vec@LANES@@TYPE@b>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
}
}
// @GENERATED_SOURCE@
#include <config.h>
#include <dune/vectorclass/test/vectorclasstest.hh>
namespace Dune {
namespace Simd {
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
template void UnitTest::checkVector<Vec@LANES@@TYPE@>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
}
}
This diff is collapsed.
#include <iostream>
#include <dune/vectorclass/vectorclass.hh>
int main() {
Vec4i Vec(1,2,3,4);
assert(Dune::Simd::lane(2,Vec)==3);
assert(Vec[2]==3);
assert(Vec.extract(2)==3);
Dune::Simd::lane(2,Vec) += 3;
assert(Dune::Simd::lane(2,Vec)==6);
assert(Vec[2]==6);
assert(Vec.extract(2)==6);
Vec4i Vec2 = Vec+2;
assert(Dune::Simd::lane(0,Vec2)==3);
assert(Vec2[0]==3);
assert(Vec2.extract(0)==3);
Dune::Simd::lane(3,Vec2) = 10;
assert(Dune::Simd::lane(3,Vec2)==10);
assert(Vec2[3]==10);
assert(Vec2.extract(3)==10);
}
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