Commit ce4c1154 authored by Bednárek David RNDr. Ph.D.'s avatar Bednárek David RNDr. Ph.D.
Browse files

improved cmakefiles

levenstein (empty) added
parent c450061b
cmake_minimum_required (VERSION 3.8)
cmake_policy(SET CMP0076 NEW)
add_executable (${TARGET_MACRO})
set(THREADS_PREFER_PTHREAD_FLAG True)
find_package(Threads REQUIRED)
add_test(run-${TARGET_MACRO} ${TARGET_MACRO})
if(UNIX)
function(CPUFLAG VNAME FLAG)
if(NOT DEFINED ${VNAME})
message("Searching /proc/cpuinfo for ${FLAG}")
execute_process(COMMAND grep "-c" "^flags.*${FLAG}" "/proc/cpuinfo" OUTPUT_VARIABLE CNT)
if (${CNT} GREATER 0)
set(HAS True)
else()
set(HAS False)
endif()
set(${VNAME} ${HAS} CACHE BOOL "CPU has ${FLAG}")
endif()
endfunction()
set_property(TARGET ${TARGET_MACRO} PROPERTY CXX_STANDARD 17)
CPUFLAG(USE_AVX "avx2")
CPUFLAG(USE_AVX512 "avx512f")
else()
# use only definitions from the command-line
if(NOT DEFINED USE_AVX)
set(USE_AVX True CACHE BOOL "Use AVX2 instruction set")
message("USE_AVX was not defined, defaulting to ${USE_AVX}")
endif()
if(NOT DEFINED USE_AVX512)
set(USE_AVX512 False CACHE BOOL "Use AVX512F instruction set")
message("USE_AVX512 was not defined, defaulting to ${USE_AVX512}")
endif()
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${TARGET_MACRO} Threads::Threads)
message("USE_AVX = ${USE_AVX}")
message("USE_AVX512 = ${USE_AVX512}")
function(SET_TARGET_OPTIONS TARGET OPT_GCC OPT_MSVC)
if(MSVC)
target_compile_options(${TARGET} PUBLIC ${OPT_MSVC})
else()
target_compile_options(${TARGET} PUBLIC ${OPT_GCC})
endif()
endfunction()
function(MAKE_TARGET TARGET_MACRO_SUFFIX TARGET)
set("TARGET_${TARGET_MACRO_SUFFIX}" ${TARGET} PARENT_SCOPE)
add_executable (${TARGET})
add_test(run-${TARGET} ${TARGET})
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD 17)
SET_TARGET_OPTIONS(${TARGET} "-msse4.2" "")
if(USE_AVX)
SET_TARGET_OPTIONS(${TARGET} "-mavx2" "/arch:AVX2")
target_compile_definitions(${TARGET} PUBLIC "USE_AVX")
endif()
if(USE_AVX512)
SET_TARGET_OPTIONS(${TARGET} "-mavx512f" "/arch:AVX512")
target_compile_definitions(${TARGET} PUBLIC "USE_AVX512")
endif()
target_link_libraries(${TARGET} Threads::Threads)
endfunction()
......@@ -4,11 +4,12 @@ cmake_minimum_required (VERSION 3.8)
cmake_policy(SET CMP0076 NEW)
enable_testing()
project ("asgn")
project ("fmwkng")
set(TARGET_MACRO "macro")
include("CMakeConf.cmake")
add_subdirectory ("asgn" "asgn")
add_subdirectory ("sol" "sol")
MAKE_TARGET("MACRO" "macro")
MAKE_TARGET("LEVEN" "leven")
add_subdirectory ("asgn")
add_subdirectory ("sol")
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
}
]
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
},
{
"name": "x64-Clang-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64" ],
"variables": []
},
{
"name": "WSL-Release",
"generator": "Unix Makefiles",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeExecutable": "/usr/bin/cmake",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_x64" ],
"wslPath": "${defaultWSLPath}",
"addressSanitizerRuntimeFlags": "detect_leaks=0",
"variables": []
}
]
}
\ No newline at end of file
target_include_directories(${TARGET_MACRO} PUBLIC ".")
target_include_directories(${TARGET_LEVEN} PUBLIC ".")
target_sources(${TARGET_MACRO} PUBLIC "fmwkng.hpp" "macroasgn.hpp" "macroasgn.cpp" "macromain.cpp")
target_sources(${TARGET_LEVEN} PUBLIC "fmwkng.hpp" "levenasgn.hpp" "levenmain.cpp")
......@@ -1074,6 +1074,7 @@ namespace fmwkng {
void exit(const dt_t& dt)
{
impl::thread_pointer(dt)->template push_element< platform_tag, element_sense::CLOSE>();
impl::thread_pointer(dt)->flush();
/*
auto g = impl::root_pointer(dt)->guard();
std::cout << "exit_platform<" << platform_tag::name() << ">" << std::endl;
......@@ -2082,11 +2083,11 @@ namespace fmwkng {
private:
value_type v_count_;
};
template< typename X>
using platform_t = typename std::remove_cv_t< std::remove_reference_t< X>>::platform_t;
#pragma endregion
#pragma region public_wrappers
template< typename X>
using platform_t = typename std::remove_cv_t< std::remove_reference_t< X>>::platform_t;
template< typename F, typename ... tags>
auto for_platforms(const tagged_context< tags ...>& ctx, F && f)
{
......
#ifndef _levenasgn_hpp
#define _levenasgn_hpp
#include <cstddef>
#include <memory>
#include <vector>
#include <cassert>
#include <random>
#include "fmwkng.hpp"
///////////////////////////////
typedef int data_element;
using time_complexity = std::size_t;
template< typename IT>
inline std::uint64_t chksum(IT b, IT e)
{
std::uint64_t s = 0;
for (; b != e; ++b)
{
auto x = *b;
s = s * 3 + (std::uint64_t)x;
}
return s;
}
struct generator_4 {
time_complexity complexity() const
{
return s1_ * s2_;
}
auto begin1() const
{
return v1_.cbegin();
}
auto end1() const
{
return v1_.cend();
}
auto begin2() const
{
return v2_.cbegin();
}
auto end2() const
{
return v2_.cend();
}
template< typename GP>
generator_4( GP && p, std::size_t s1, std::size_t s2)
: s2_( s2),
s1_( s1),
v1_( s1),
v2_( s2)
{
auto gen = [&p]() -> data_element {
return p.get();
};
std::generate(v1_.begin(), v1_.end(), gen);
std::generate(v2_.begin(), v2_.end(), gen);
}
private:
std::size_t s1_, s2_;
std::vector< data_element> v1_, v2_;
};
struct policy_random {
static std::string name() { return "random"; }
explicit policy_random(std::size_t seed)
: engine_(seed), ui_(0, 255)
{
}
void reset()
{
}
data_element get()
{
return ui_(engine_);
}
private:
typedef std::mt19937_64 M;
M engine_;
typedef std::uniform_int_distribution< data_element> D;
D ui_;
};
#endif
#include "levensol.hpp"
#include "levenasgn.hpp"
#include "fmwkng.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
namespace levenmain {
/*
struct platform_scalar {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "scalar"; }
using policy = levensol::policy_scalar;
};
*/
struct platform_sse {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "sse"; }
using policy = levensol::policy_sse;
};
#ifdef USE_AVX
struct platform_avx {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "avx"; }
using policy = levensol::policy_avx;
};
#endif
#ifdef USE_AVX512
struct platform_avx512 {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "avx512"; }
using policy = levensol::policy_avx512;
};
#endif
struct repeats {
using tag_category = fmwkng::range_tag_category;
static auto name() { return "repeats"; }
static auto enumerator() {
return fmwkng::auto_repeat(
#ifdef NDEBUG
50000
#else
1000
#endif
);
}
};
struct root_config {
using platforms = fmwkng::platforms<
//platform_scalar
//,
platform_sse
#ifdef USE_AVX
, platform_avx
#endif
#ifdef USE_AVX512
, platform_avx512
#endif
>;
using ranges = fmwkng::ranges<repeats>;
};
struct run_thread_ftor {
template< typename CTX>
void operator()(CTX&& ctx2) const
{
using namespace fmwkng;
using policy = typename platform_t<decltype(ctx2)>::policy;
{
generator_4 mg(
policy_random(
std::mt19937_64::default_seed + ctx2.thread_index()
), 100, 100);
levensol::levenstein<policy> data(mg.begin1(), mg.end1(), mg.begin2(), mg.end2());
std::size_t h = 0;
for (auto&& ctx5 : auto_measurement<repeats>(ctx2, 1024))
{
for (auto i : for_index<repeats>(ctx5))
{
auto rv = data.compute();
h += rv;
}
}
}
}
};
struct run_platform_ftor {
template< typename CTX>
void operator()(CTX&& ctx1) const
{
using namespace fmwkng;
#ifdef NDEBUG
for_parallel(ctx1, run_thread_ftor());
#else
run_thread_ftor()(ctx1);
#endif
}
};
}
int main(int argc, char** argv)
{
using namespace fmwkng;
root<levenmain::root_config> ctx1(argc, argv);
//std::cout << "Running..." << std::endl;
for_platforms(ctx1, levenmain::run_platform_ftor());
//std::cout << "Done." << std::endl;
return 0;
}
///////////////////////////////
///////////////////////////////
///////////////////////////////
void o_main()
{
#ifdef _DEBUG
std::size_t min_inner = 64UL;
std::size_t step_inner = 4;
std::size_t max_inner = 2UL * 1024UL;
std::size_t min_outer = 64UL;
std::size_t step_outer = 4;
std::size_t max_outer = 2UL * 1024UL;
time_complexity target_complexity = 250000UL;
#else
std::size_t min_inner = 64UL;
std::size_t step_inner = 8;
std::size_t max_inner = 32UL * 1024UL;
std::size_t min_outer = 64UL;
std::size_t step_outer = 8;
std::size_t max_outer = 32UL * 1024UL;
time_complexity target_complexity = 10000000000UL;
#endif
}
///////////////////////////////
......@@ -6,7 +6,6 @@
#include "fmwkng.hpp"
#include <fstream>
#include <string_view>
#include <vector>
namespace macromain {
......@@ -27,7 +26,7 @@ namespace macromain {
struct platform_avx {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "avx"; }
using policy = policy_avx;
using policy = macrosol::policy_avx;
};
#endif
......@@ -35,7 +34,7 @@ namespace macromain {
struct platform_avx512 {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "avx512"; }
using policy = policy_avx512;
using policy = macrosol::policy_avx512;
};
#endif
......@@ -54,16 +53,16 @@ namespace macromain {
};
struct root_config {
using platforms = fmwkng::platforms< platform_scalar
/*
, platform_sse
using platforms = fmwkng::platforms<
platform_scalar
,
platform_sse
#ifdef USE_AVX
, platform_avx
#endif
#ifdef USE_AVX512
, platform_avx512
#endif
*/
>;
using ranges = fmwkng::ranges<lines>;
};
......@@ -120,24 +119,26 @@ namespace macromain {
}
};
template< typename CTX>
void run_platforms(CTX&& ctx1)
{
using namespace fmwkng;
struct run_platform_ftor {
template< typename CTX>
void operator()(CTX&& ctx1) const
{
using namespace fmwkng;
#ifdef NDEBUG
for_parallel(ctx1, run_thread_ftor());
for_parallel(ctx1, run_thread_ftor());
#else
run_thread_ftor()(ctx1);
run_thread_ftor()(ctx1);
#endif
}
}
};
}
int main(int argc, char** argv)
{
using namespace fmwkng;
root<macromain::root_config> ctx1(argc, argv);
std::cout << "Running..." << std::endl;
macromain::run_platforms(ctx1);
std::cout << "Done." << std::endl;
//std::cout << "Running..." << std::endl;
for_platforms(ctx1, macromain::run_platform_ftor());
//std::cout << "Done." << std::endl;
return 0;
}
# CMakeList.txt
#
target_include_directories(${TARGET_MACRO} PUBLIC ".")
target_include_directories(${TARGET_LEVEN} PUBLIC ".")
target_sources(${TARGET_MACRO} PUBLIC "macrosol.hpp" "macrosol.cpp")
target_sources(${TARGET_LEVEN} PUBLIC "levensol.hpp" "levensol.cpp")
#include "levensol.hpp"
namespace levensol {
}
#ifndef levensol_hpp_
#define levensol_hpp_
namespace levensol {
template< typename policy>
class levenstein {
public:
typedef int data_element;
template< typename I1, typename I2>
levenstein(I1 i1b, I1 i1e, I2 i2b, I2 i2e)
{}
data_element compute() { return 0; }
};
struct policy_scalar {
};
struct policy_sse {
};
struct policy_avx {
};
struct policy_avx512 {
};
}
#endif
Supports Markdown
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