Commit efe3bd26 authored by Roel Aaij's avatar Roel Aaij
Browse files

Use config.h for USE_AVX2 to prevent vague allocation issues when building against the library.

parent 9d6127d5
......@@ -103,18 +103,19 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g -DDEBUG")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${INCLUDES} -W -O3 -DNDEBUG")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} " )
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" )
include(VcMacros)
vc_set_preferred_compiler_flags()
if (USE_AVX2)
include_directories(${Vc_INCLUDE_DIR})
add_definitions("-DUSE_AVX2")
string(REPLACE ";" " " VC_FLAGS "${Vc_COMPILE_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VC_FLAGS} -mavx2 -mfma -mbmi2")
endif()
configure_file(lib/generate/config.h.in lib/generate/config.h)
set(generate_SOURCES
src/generate/generate.cpp
src/generate/generate_scalar.cpp)
......@@ -127,6 +128,7 @@ endif()
include_directories(${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR}/lib/generate)
include_directories(${CMAKE_BINARY_DIR}/lib/generate)
add_library(generate SHARED ${generate_SOURCES})
......
#pragma once
#cmakedefine01 USE_AVX2 @USE_AVX2@
......@@ -22,37 +22,37 @@
namespace GenAVX2 {
const std::array<Vc::SimdArray<float, 3>, 31> PMTs
{{{ 0 , -0.832, 0.55},
{-0.955, 0 , 0.29},
{-0.478, -0.827, 0.29},
{ 0.478, -0.827, 0.29},
{ 0.72 , -0.416, 0.55},
{-0.72 , -0.416, 0.55},
{ 0.955, 0 , 0.29},
{-0.72 , 0.416, 0.55},
{ 0.72 , 0.416, 0.55},
{ 0 , 0.832, 0.55},
{ 0.478, 0.827, 0.29},
{-0.478, 0.827, 0.29},
{ 0 , 0.955, 0.29},
{ 0.416, 0.72 , 0.55},
{ 0 , 0.527, 0.85},
{ 0.827, 0.478, 0.29},
{-0.827, 0.478, 0.29},
{-0.416, 0.72 , 0.55},
{-0.456, 0.263, 0.85},
{ 0.456, 0.263, 0.85},
{-0.832, 0 , 0.55},
{ 0.832, 0 , 0.55},
{ 0 , 0 , 1 },
{ 0.827, -0.478, 0.29},
{ 0 , -0.527, 0.85},
{ 0.456, -0.263, 0.85},
{-0.456, -0.263, 0.85},
{-0.827, -0.478, 0.29},
{-0.416, -0.72 , 0.55},
{ 0.416, -0.72 , 0.55},
{ 0 , -0.955, 0.29}}};
{{{ 0.000f, -0.832f, 0.555f},
{-0.955f, 0.000f, 0.295f},
{-0.478f, -0.827f, 0.295f},
{ 0.478f, -0.827f, 0.295f},
{ 0.720f, -0.416f, 0.555f},
{-0.720f, -0.416f, 0.555f},
{ 0.955f, 0.000f, 0.295f},
{-0.720f, 0.416f, 0.555f},
{ 0.720f, 0.416f, 0.555f},
{ 0.000f, 0.832f, 0.555f},
{ 0.478f, 0.827f, 0.295f},
{-0.478f, 0.827f, 0.295f},
{ 0.000f, 0.955f, -0.295f},
{ 0.416f, 0.720f, -0.555f},
{ 0.000f, 0.527f, -0.850f},
{ 0.827f, 0.478f, -0.295f},
{-0.827f, 0.478f, -0.295f},
{-0.416f, 0.720f, -0.555f},
{-0.456f, 0.263f, -0.850f},
{ 0.456f, 0.263f, -0.850f},
{-0.832f, 0.000f, -0.555f},
{ 0.832f, 0.000f, -0.555f},
{ 0.000f, 0.000f, -1.000f},
{ 0.827f, -0.478f, -0.295f},
{ 0.000f, -0.527f, -0.850f},
{ 0.456f, -0.263f, -0.850f},
{-0.456f, -0.263f, -0.850f},
{-0.827f, -0.478f, -0.295f},
{-0.416f, -0.720f, -0.555f},
{ 0.416f, -0.720f, -0.555f},
{ 0.000f, -0.955f, -0.295f}}};
float dot_product(const Vc::SimdArray<float, 3>& left, const Vc::SimdArray<float, 3>& right);
......
......@@ -48,7 +48,7 @@ float cross_prob(const float ct);
struct Generators {
private:
const std::array<int, 2> m_seeds;
const std::array<float, 4> m_rates{7000., 700, 70., 7.};
const std::array<float, 4> m_rates;
std::seed_seq m_seed_seq;
public:
......
......@@ -21,37 +21,37 @@
namespace GenScalar {
const std::array<std::array<float, 3>, 31> PMTs
{{{ 0 , -0.832, 0.55},
{-0.955, 0 , 0.29},
{-0.478, -0.827, 0.29},
{ 0.478, -0.827, 0.29},
{ 0.72 , -0.416, 0.55},
{-0.72 , -0.416, 0.55},
{ 0.955, 0 , 0.29},
{-0.72 , 0.416, 0.55},
{ 0.72 , 0.416, 0.55},
{ 0 , 0.832, 0.55},
{ 0.478, 0.827, 0.29},
{-0.478, 0.827, 0.29},
{ 0 , 0.955, 0.29},
{ 0.416, 0.72 , 0.55},
{ 0 , 0.527, 0.85},
{ 0.827, 0.478, 0.29},
{-0.827, 0.478, 0.29},
{-0.416, 0.72 , 0.55},
{-0.456, 0.263, 0.85},
{ 0.456, 0.263, 0.85},
{-0.832, 0 , 0.55},
{ 0.832, 0 , 0.55},
{ 0 , 0 , 1 },
{ 0.827, -0.478, 0.29},
{ 0 , -0.527, 0.85},
{ 0.456, -0.263, 0.85},
{-0.456, -0.263, 0.85},
{-0.827, -0.478, 0.29},
{-0.416, -0.72 , 0.55},
{ 0.416, -0.72 , 0.55},
{ 0 , -0.955, 0.29}}};
{{{ 0.000f, -0.832f, 0.555f},
{-0.955f, 0.000f, 0.295f},
{-0.478f, -0.827f, 0.295f},
{ 0.478f, -0.827f, 0.295f},
{ 0.720f, -0.416f, 0.555f},
{-0.720f, -0.416f, 0.555f},
{ 0.955f, 0.000f, 0.295f},
{-0.720f, 0.416f, 0.555f},
{ 0.720f, 0.416f, 0.555f},
{ 0.000f, 0.832f, 0.555f},
{ 0.478f, 0.827f, 0.295f},
{-0.478f, 0.827f, 0.295f},
{ 0.000f, 0.955f, -0.295f},
{ 0.416f, 0.720f, -0.555f},
{ 0.000f, 0.527f, -0.850f},
{ 0.827f, 0.478f, -0.295f},
{-0.827f, 0.478f, -0.295f},
{-0.416f, 0.720f, -0.555f},
{-0.456f, 0.263f, -0.850f},
{ 0.456f, 0.263f, -0.850f},
{-0.832f, 0.000f, -0.555f},
{ 0.832f, 0.000f, -0.555f},
{ 0.000f, 0.000f, -1.000f},
{ 0.827f, -0.478f, -0.295f},
{ 0.000f, -0.527f, -0.850f},
{ 0.456f, -0.263f, -0.850f},
{-0.456f, -0.263f, -0.850f},
{-0.827f, -0.478f, -0.295f},
{-0.416f, -0.720f, -0.555f},
{ 0.416f, -0.720f, -0.555f},
{ 0.000f, -0.955f, -0.295f}}};
float dot_product(const std::array<float, 3>& left, const std::array<float, 3>& right);
......
......@@ -15,6 +15,8 @@
*/
#pragma once
#include "config.h"
#include <vector>
#ifdef USE_AVX2
......
......@@ -172,6 +172,9 @@ std::tuple<storage_t, storage_t> generate_avx2(const long time_start, const long
}
}
if (idx >= times.size() - 2 * long_v::size()) {
std::cerr << "Warning: allocated space exceeded, event is truncated." << std::endl;
}
times.resize(idx);
values.resize(idx);
return {std::move(times), std::move(values)};
......
......@@ -80,8 +80,8 @@ std::tuple<storage_t, storage_t> generate_scalar(const long time_start, const lo
const size_t n_expect = gens.n_expect(time_end - time_start, true);
const float tau_l0 = gens.tau_l0();
storage_t times; times.resize(n_expect);
storage_t values; values.resize(n_expect + 1);
storage_t times(n_expect);
storage_t values(n_expect + 1);
const size_t n_expect_pmts = gens.n_expect(time_end - time_start, false);
pmts_t pmts(n_expect_pmts, 0);
size_t idx = 0;
......@@ -112,6 +112,9 @@ std::tuple<storage_t, storage_t> generate_scalar(const long time_start, const lo
idx += n_times;
}
}
if (idx >= times.size() - 2) {
std::cerr << "Warning: allocated space exceeded, event is truncated." << std::endl;
}
times.resize(idx);
values.resize(idx);
return {std::move(times), std::move(values)};
......
......@@ -26,10 +26,6 @@ endif()
include_directories(include)
if (USE_AVX2)
add_definitions("-DUSE_AVX2=1")
endif()
add_library(test_functions STATIC
lib/coincidences.cpp
lib/generate.cpp)
......
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