From c2805a9208f68b43eda36900f8f5d85131adc2a8 Mon Sep 17 00:00:00 2001 From: Matteo Cicuttin <datafl4sh@toxicnet.eu> Date: Thu, 26 Mar 2020 15:00:41 +0100 Subject: [PATCH] Added skeleton for OpenAcc. --- kokkos-testing/fd_catalog/fd_kokkos.cpp | 21 +++++++++++++++ kokkos-testing/fd_catalog/fd_main.cpp | 23 +++++++++------- kokkos-testing/fd_catalog/fd_openacc.cpp | 32 +++++++++++++++++++++++ kokkos-testing/fd_catalog/fd_wave_cpu.hpp | 8 ++++-- kokkos-testing/test_daz_ftz.cpp | 10 +++++++ 5 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 kokkos-testing/fd_catalog/fd_openacc.cpp create mode 100644 kokkos-testing/test_daz_ftz.cpp diff --git a/kokkos-testing/fd_catalog/fd_kokkos.cpp b/kokkos-testing/fd_catalog/fd_kokkos.cpp index 823fb1f..98ddd90 100644 --- a/kokkos-testing/fd_catalog/fd_kokkos.cpp +++ b/kokkos-testing/fd_catalog/fd_kokkos.cpp @@ -9,6 +9,9 @@ #include <silo.h> #include <Kokkos_Core.hpp> +#include <pmmintrin.h> +#include <xmmintrin.h> + #define WAVE_8_HALO_SIZE 4 using namespace Kokkos; @@ -179,6 +182,11 @@ double solve_kokkos(wave_equation_context_kokkos<T>& wec) static const T w3 = 8.0/315.0; static const T w4 = -1.0/560.0; static const T w[9] = { w4, w3, w2, w1, w0, w1, w2, w3, w4 }; + +#ifdef DISALLOW_DENORMALS + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); + _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); +#endif i += WAVE_8_HALO_SIZE; j += WAVE_8_HALO_SIZE; @@ -226,7 +234,20 @@ double solve_kokkos(wave_equation_context_kokkos<T>& wec) int main(int argc, char *argv[]) { +#ifdef SINGLE_PRECISION + using T = float; + std::cout << "Precision: single" << std::endl; +#else using T = double; + std::cout << "Precision: single" << std::endl; +#endif + +#ifdef DISALLOW_DENORMALS + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); + _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); + std::cout << "Denormals: FTZ and DAZ" << std::endl; +#endif + _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID); Kokkos::initialize( argc, argv ); diff --git a/kokkos-testing/fd_catalog/fd_main.cpp b/kokkos-testing/fd_catalog/fd_main.cpp index 61abba8..e0d50d5 100644 --- a/kokkos-testing/fd_catalog/fd_main.cpp +++ b/kokkos-testing/fd_catalog/fd_main.cpp @@ -2,31 +2,36 @@ #include <fstream> #include <cstdio> #include <unistd.h> + +#include <pmmintrin.h> +#include <xmmintrin.h> + #include "fd_wave_cpu.hpp" #ifdef HAVE_CUDA #include "fd_wave_cuda.hpp" #endif -#include <pmmintrin.h> -#include <xmmintrin.h> - int main(int argc, char **argv) { -#ifdef DISALLOW_DENORMALS - _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); - _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); -#endif - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID); - #ifdef SINGLE_PRECISION using T = float; + std::cout << "Precision: single" << std::endl; std::ofstream ofs("timings-float.txt"); #else using T = double; + std::cout << "Precision: double" << std::endl; std::ofstream ofs("timings-double.txt"); #endif +#ifdef DISALLOW_DENORMALS + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); + _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); + std::cout << "Denormals: FTZ and DAZ" << std::endl; +#endif + _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID); + + /* Make header */ ofs << "\"SIZE\" \"Seq\" \"SeqBlk\" "; diff --git a/kokkos-testing/fd_catalog/fd_openacc.cpp b/kokkos-testing/fd_catalog/fd_openacc.cpp new file mode 100644 index 0000000..9a857a1 --- /dev/null +++ b/kokkos-testing/fd_catalog/fd_openacc.cpp @@ -0,0 +1,32 @@ +#include <iostream> +#include <fstream> +#include <cstdio> +#include <unistd.h> + +#include "fd_wave_cpu.hpp" + +template<typename T> +double solve_openacc(wave_equation_context<T>& wec, size_t nths) +{ +} + +int main(void) +{ +#ifdef SINGLE_PRECISION + using T = float; + std::cout << "Precision: single" << std::endl; +#else + using T = double; + std::cout << "Precision: double" << std::endl; +#endif + + for (size_t sz = 128; sz <= 1024; sz *= 2) + { + wave_equation_context<T> wec(sz, sz, 1, 0.1, 0.0001, 5000); + + wec.init(); + time = solve_openacc(wec); + } + + return 0; +} \ No newline at end of file diff --git a/kokkos-testing/fd_catalog/fd_wave_cpu.hpp b/kokkos-testing/fd_catalog/fd_wave_cpu.hpp index 96e11c1..152c2b1 100644 --- a/kokkos-testing/fd_catalog/fd_wave_cpu.hpp +++ b/kokkos-testing/fd_catalog/fd_wave_cpu.hpp @@ -359,7 +359,7 @@ solve_sequential_aux(wave_equation_context<T>& wec) std::cout << "[Wave][SeqBlk] Wall Time: " << time << "ms" << std::endl; double itertime = time/wec.maxiter; - double gflops_s = 60*(params.maxrow*params.maxcol)/(1e6*itertime); + double gflops_s = 58*(params.maxrow*params.maxcol)/(1e6*itertime); std::cout << "[Wave][SeqBlk] GFlops/s: " << gflops_s << std::endl; } else @@ -368,7 +368,7 @@ solve_sequential_aux(wave_equation_context<T>& wec) std::cout << "[Wave][Sequential] Wall Time: " << time << "ms" << std::endl; double itertime = time/wec.maxiter; - double gflops_s = 60*(params.maxrow*params.maxcol)/(1e6*itertime); + double gflops_s = 58*(params.maxrow*params.maxcol)/(1e6*itertime); std::cout << "[Wave][Sequential] GFlops/s: " << gflops_s << std::endl; size_t kernel_bytes = 3*sizeof(T)*(params.maxrow*params.maxcol); @@ -418,6 +418,10 @@ double solve_multithread(wave_equation_context<T>& wec, size_t nths) bool iteration_finished = false; auto thread_lambda = [&](size_t thread_id, size_t num_threads) { +#ifdef DISALLOW_DENORMALS + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); + _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); +#endif while (1) { /* Wait for the producer to notify that there's something to do */ diff --git a/kokkos-testing/test_daz_ftz.cpp b/kokkos-testing/test_daz_ftz.cpp new file mode 100644 index 0000000..b127429 --- /dev/null +++ b/kokkos-testing/test_daz_ftz.cpp @@ -0,0 +1,10 @@ +#include <iostream> +#include <pmmintrin.h> +#include <xmmintrin.h> + +int main(void) +{ + std::cout << "DAZ: " << _MM_GET_DENORMALS_ZERO_MODE() << std::endl; + std::cout << "FTZ: " << _MM_GET_FLUSH_ZERO_MODE() << std::endl; + return 0; +} -- GitLab