Commit 5425851e authored by Tobias WEBER's avatar Tobias WEBER
parent 60ac96ed
*.o
*.moc
*.pyc
*.exe
*.dll
*.so
*.a
.~lock*
*~
*.cmake
!FindMinuit2.cmake
.directory
*.kate-swp
Debug/*
Release/*
ui/*.h
script/hermelin
perf.data
perf.data.old
gmon.out
script/tokens.h
script/script.tab.cc
script/script.cc
script/.clang/*
script/.codelite/*
script/Debug/*
script/Release/*
script/CMakeFiles/*
script/CMakeCache.txt
script/Makefile
.clang/*
.codelite/*
.settings/*
CMakeFiles/*
CMakeCache.txt
cmake_install.cmake
Makefile
build/*
script/build/*
externals/**
doc/*
!doc/.dir
obj/*
!obj/.dir
Faddeeva.*
#
# tlibs
# @author Tobias Weber <tobias.weber@tum.de>
# @date 2012-2017
# @license GPLv2 or GPLv3
#
project(tlibs)
cmake_minimum_required(VERSION 3.0)
#set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(CMAKE_BUILD_TYPE Release)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}" ".")
set(CMAKE_BINARY_DIR "${CMAKE_SOURCE_DIR}")
#set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
find_package(Boost REQUIRED COMPONENTS iostreams system filesystem regex REQUIRED)
find_package(Threads REQUIRED)
find_package(Freetype REQUIRED)
find_package(Minuit2 REQUIRED)
find_package(OpenGL REQUIRED)
set(CMAKE_AUTOMOC OFF)
set(CMAKE_AUTOUIC OFF)
#message("Project source dir: ${PROJECT_SOURCE_DIR}")
#message("CMake source dir: ${CMAKE_SOURCE_DIR}")
#message("Binary dir: ${CMAKE_BINARY_DIR}")
message("Install path prefix: ${CMAKE_INSTALL_PREFIX}")
add_definitions(-DNDEBUG)
add_definitions(-DUSE_IOSTR -DUSE_BOOST_REX)
add_definitions(-DNO_LAPACK)
#add_definitions(-DUSE_FFTW)
add_definitions(-DINSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")
add_definitions(${Boost_CXX_FLAGS})
include_directories("${PROJECT_SOURCE_DIR}" ".")
include_directories("${Boost_INCLUDE_DIRS}/..")
include_directories("${FREETYPE_INCLUDE_DIRS}")
include_directories("${Minuit2_INCLUDE_DIRS}")
include_directories("${OPENGL_INCLUDE_DIR}" "${OPENGL_INCLUDE_DIR}/GL" "${OPENGL_INCLUDE_DIR}/OpenGL")
add_definitions(-std=c++11)
#add_definitions(-march=native -s)
# -----------------------------------------------------------------------------
# build
# -----------------------------------------------------------------------------
add_library(tlibs SHARED
file/tmp.cpp file/loadinstr.cpp file/x3d.cpp
log/log.cpp log/debug.cpp
helper/flags.cpp
math/fourier.cpp math/linalg2.cpp math/rand.cpp
net/tcp.cpp
string/spec_char.cpp string/eval.cpp
gfx/gl.cpp gfx/gnuplot.cpp
version.cpp
)
target_link_libraries(tlibs ${Boost_LIBRARIES} Threads::Threads
${OPENGL_LIBRARIES} ${FREETYPE_LIBRARY} ${Minuit2_LIBRARIES}
)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_custom_command(TARGET tlibs POST_BUILD
COMMAND strip -v $<TARGET_FILE:tlibs>
MAIN_DEPENDENCY tlibs
)
endif()
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# install
# -----------------------------------------------------------------------------
install(TARGETS tlibs DESTINATION lib)
file(GLOB tlibs_rt ${PROJECT_SOURCE_DIR}/*.h)
file(GLOB tlibs_file ${PROJECT_SOURCE_DIR}/file/*.h)
file(GLOB tlibs_helper ${PROJECT_SOURCE_DIR}/helper/*.h)
file(GLOB tlibs_math ${PROJECT_SOURCE_DIR}/math/*.h)
file(GLOB tlibs_phys ${PROJECT_SOURCE_DIR}/phys/*.h)
file(GLOB tlibs_net ${PROJECT_SOURCE_DIR}/net/*.h)
file(GLOB tlibs_string ${PROJECT_SOURCE_DIR}/string/*.h)
file(GLOB tlibs_gfx ${PROJECT_SOURCE_DIR}/gfx/*.h)
file(GLOB tlibs_time ${PROJECT_SOURCE_DIR}/time/*.h)
file(GLOB tlibs_cl ${PROJECT_SOURCE_DIR}/cl/*.h)
file(GLOB tlibs_log ${PROJECT_SOURCE_DIR}/log/*.h)
file(GLOB tlibs_fit ${PROJECT_SOURCE_DIR}/fit/*.h)
file(GLOB tlibs_ext ${PROJECT_SOURCE_DIR}/ext/*.h)
install(FILES ${tlibs_rt} DESTINATION include/tlibs)
install(FILES ${tlibs_file} DESTINATION include/tlibs/file)
install(FILES ${tlibs_helper} DESTINATION include/tlibs/helper)
install(FILES ${tlibs_math} DESTINATION include/tlibs/math)
install(FILES ${tlibs_phys} DESTINATION include/tlibs/phys)
install(FILES ${tlibs_net} DESTINATION include/tlibs/net)
install(FILES ${tlibs_string} DESTINATION include/tlibs/string)
install(FILES ${tlibs_gfx} DESTINATION include/tlibs/gfx)
install(FILES ${tlibs_time} DESTINATION include/tlibs/time)
install(FILES ${tlibs_cl} DESTINATION include/tlibs/cl)
install(FILES ${tlibs_log} DESTINATION include/tlibs/log)
install(FILES ${tlibs_fit} DESTINATION include/tlibs/fit)
install(FILES ${tlibs_ext} DESTINATION include/tlibs/ext)
install(FILES ${PROJECT_SOURCE_DIR}/FindMinuit2.cmake DESTINATION share/tlibs)
install(FILES ${PROJECT_SOURCE_DIR}/COPYING.GPLv2 ${PROJECT_SOURCE_DIR}/COPYING.GPLv3
${PROJECT_SOURCE_DIR}/AUTHORS ${PROJECT_SOURCE_DIR}/LICENSES
DESTINATION share/tlibs
)
# -----------------------------------------------------------------------------
#
# finds the minuit libs
# @author Tobias Weber <tobias.weber@tum.de>
# @license GPLv2 or GPLv3
#
find_path(Minuit2_INCLUDE_DIRS
NAMES MnMigrad.h
PATH_SUFFIXES root Minuit2 Minuit root/Minuit2 root/Minuit
HINTS /usr/include/root/Minuit2 /usr/local/include/root/Minuit2 /opt/local/include/root/Minuit2
DOC "Root/Minuit2 include directories"
)
# also include root base dir
list(APPEND Minuit2_INCLUDE_DIRS "${Minuit2_INCLUDE_DIRS}/..")
find_library(Minuit2_LIBRARIES
NAMES Minuit2
HINTS /usr/lib64/root /usr/lib/root /usr/lib32/root
DOC "Minuit2 library"
)
if(Minuit2_INCLUDE_DIRS AND Minuit2_LIBRARIES)
set(Minuit2_FOUND 1)
message("Minuit include directories: ${Minuit2_INCLUDE_DIRS}")
message("Minuit library: ${Minuit2_LIBRARIES}")
else()
set(Minuit2_FOUND 0)
message("Error: Minuit2 could not be found!")
endif()
This diff is collapsed.
COPYING.GPLv2
\ No newline at end of file
This diff is collapsed.
References for formulas and algorithms, which are employed in this software.
============================================================================
-------------------------------------------------------------------------------
Neutrons
-------------------------------------------------------------------------------
* (Shirane 2002), G. Shirane et al., "Neutron Scattering with a Triple-Axis Spectrometer", 2002, ISBN: 978-0521411264.
* (Squires 2012), G. L. Squires, "Thermal Neutron Scattering", 2012, ISBN: 9781139107808.
-------------------------------------------------------------------------------
General Mathematics
-------------------------------------------------------------------------------
* (Stoecker 1999), H. Stoecker et al., "Taschenbuch mathematischer Formeln", 1999, ISBN: 3-8171-1573-3.
* (Kuipers 2002), J. B. Kuipers, "Quaternions and Rotation Sequences", 2002, ISBN: 0-691-10298-8.
* (Merziger 2006), G. Merziger and T. Wirth, "Repetitorium der hoeheren Mathematik", 2006, ISBN: 3923923333.
* (Bronstein 2008), I. N. Bronstein et al., "Taschenbuch der Mathematik", 2008, ISBN: 978-3-8171-2017-8.
* (Scherer 2010), P. O. J. Scherer, "Computational Physics", 2010, ISBN: 978-3-642-13989-5.
* (Scarpino 2011), M. Scarpino, "OpenCL in Action", 2011, ISBN: 9781617290176.
* (Arfken 2013), G. B. Arfken, "Mathematical Methods for Physicists", 2013, ISBN: 978-0-12-384654-9.
* (Arens 2015), T. Arens et al., "Mathematik", 2015, ISBN: 978-3-642-44919-2
-------------------------------------------------------------------------------
General Physics
-------------------------------------------------------------------------------
* (Schroeder 2000), D. V. Schroeder, "Thermal Physics", 2000, ISBN: 0-321-27779-1.
* (Khomskii 2014), D. I. Khomskii, "Transition Metal Compounds", 2014, ISBN: 978-1-107-02017-7
/**
* CL helpers
* @author Tobias Weber <tobias.weber@tum.de>
* @date 20-jan-2015
* @license GPLv2 or GPLv3
*/
#ifndef __CL_WRAP_H__
#define __CL_WRAP_H__
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <type_traits>
#include <CL/cl.hpp>
namespace tl {
template<typename t_real=double>
bool get_best_cl_dev(cl::Platform& platRet, cl::Device& devRet,
cl::Context* pctxRet=nullptr)
{
std::vector<cl::Platform> vecPlat;
cl::Platform::get(&vecPlat);
if(vecPlat.size() == 0)
return false;
struct _Dev
{
cl::Platform* pPlat = nullptr;
cl::Device dev;
cl_device_type devtype;
};
std::vector<_Dev> vecAllDevs;
for(cl::Platform& plat : vecPlat)
{
std::vector<cl::Device> vecDevs;
plat.getDevices(CL_DEVICE_TYPE_ALL, &vecDevs);
for(cl::Device& dev : vecDevs)
{
_Dev _dev;
_dev.pPlat = &plat;
_dev.dev = dev;
_dev.devtype = dev.getInfo<CL_DEVICE_TYPE>();
std::string strExtensions = dev.getInfo<CL_DEVICE_EXTENSIONS>();
// needs double type support?
if(std::is_same<t_real, double>::value)
{
bool bHasDouble = (strExtensions.find("cl_khr_fp64") != std::string::npos);
if(!bHasDouble) continue;
}
vecAllDevs.push_back(_dev);
}
}
if(vecAllDevs.size() == 0)
return false;
std::sort(vecAllDevs.begin(), vecAllDevs.end(),
[](const _Dev& dev1, const _Dev& dev2) -> bool
{
int (*get_device_score)(cl_device_type ty) = [](cl_device_type ty) -> int
{
int iScore = 0;
if(ty & CL_DEVICE_TYPE_GPU)
iScore += 1000;
if(ty & CL_DEVICE_TYPE_ACCELERATOR)
iScore += 100;
if(ty & CL_DEVICE_TYPE_CPU)
iScore += 10;
return iScore;
};
int iScore1 = get_device_score(dev1.devtype);
int iScore2 = get_device_score(dev2.devtype);
return iScore1 > iScore2;
});
platRet = *vecAllDevs[0].pPlat;
devRet = vecAllDevs[0].dev;
if(pctxRet) *pctxRet = cl::Context({devRet});
return true;
}
template<typename t_real=double>
bool build_cl_src(cl::Context& ctx, const std::string& strSrc,
cl::Program& prog, std::unordered_map<std::string, cl::Kernel>& mapKerns)
{
using t_map = std::remove_reference<decltype(mapKerns)>::type;
cl::Program::Sources vecSrc;
vecSrc.emplace_back(cl::Program::Sources::value_type(strSrc.c_str(), strSrc.length()+1));
prog = cl::Program(ctx, vecSrc);
std::string strBuildOpts;
if(std::is_same<t_real, double>::value)
strBuildOpts = "-DUSE_DOUBLE";
if(prog.build(/*{dev}, */strBuildOpts.c_str()) != CL_SUCCESS)
{
std::vector<cl::Device> vecDev;
ctx.getInfo(CL_CONTEXT_DEVICES, &vecDev);
for(cl::Device& dev : vecDev)
{
//int iStatus = prog.getBuildInfo<CL_PROGRAM_BUILD_STATUS>(dev);
std::cerr << prog.getBuildInfo<CL_PROGRAM_BUILD_LOG>(dev) << std::endl;
}
return 0;
}
std::vector<cl::Kernel> vecKerns;
if(prog.createKernels(&vecKerns) != CL_SUCCESS)
return false;
for(cl::Kernel& kern : vecKerns)
{
std::string strName = kern.getInfo<CL_KERNEL_FUNCTION_NAME>();
mapKerns.insert(t_map::value_type(strName, std::move(kern)));
}
return 1;
}
template<typename t_real=double>
const std::string& get_cl_typedefs()
{
if(std::is_same<t_real, double>::value)
{
static const std::string strTypedefs =
R"RAWSTR(
#pragma OPENCL EXTENSION cl_khr_fp64: enable
typedef double t_real;
typedef double2 t_real2;
typedef double4 t_real4;
)RAWSTR";
return strTypedefs;
}
else
{
static const std::string strTypedefs =
R"RAWSTR(
typedef float t_real;
typedef float2 t_real2;
typedef float4 t_real4;
)RAWSTR";
return strTypedefs;
}
}
// ----------------------------------------------------------------------------
// buffers
template<class T, template<class...> class t_cont = std::vector>
inline bool create_cl_readbuf(cl::Context& ctx, const t_cont<T>& cont, cl::Buffer& buf)
{
cl_int iErr;
buf = cl::Buffer(ctx, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
cont.size() * sizeof(typename t_cont<T>::value_type),
(void*)cont.data(), &iErr);
return iErr == CL_SUCCESS;
}
template<class T>
inline bool create_cl_writebuf(cl::Context& ctx, std::size_t iNum, cl::Buffer& buf)
{
cl_int iErr;
buf = cl::Buffer(ctx, CL_MEM_WRITE_ONLY,
iNum * sizeof(T),
nullptr, &iErr);
return iErr == CL_SUCCESS;
}
template<class T, template<class...> class t_cont = std::vector>
inline bool create_cl_readimg(cl::Context& ctx, const t_cont<T>& cont, cl::Image2D& img,
std::size_t iW, std::size_t iH,
cl::ImageFormat fmt = cl::ImageFormat(CL_RGBA/*CL_RGBx*/, CL_UNSIGNED_INT8))
{
cl_int iErr;
img = cl::Image2D(ctx, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
fmt, iW, iH, 0, (void*)cont.data(), &iErr);
return iErr == CL_SUCCESS;
}
static inline bool create_cl_writeimg(cl::Context& ctx, cl::Image2D& img,
std::size_t iW, std::size_t iH,
cl::ImageFormat fmt = cl::ImageFormat(CL_RGBA, CL_UNSIGNED_INT8))
{
cl_int iErr;
img = cl::Image2D(ctx, CL_MEM_WRITE_ONLY,
fmt, iW, iH, 0, nullptr, &iErr);
return iErr == CL_SUCCESS;
}
}
#endif
/**
* Helper functions using Boost.Compute
* @author Tobias Weber <tobias.weber@tum.de>
* @date jun-2017
* @license GPLv2 or GPLv3
*/
#ifndef __CL_COMP_WRAP_H__
#define __CL_COMP_WRAP_H__
#include "cl.h"
#include <vector>
#include <boost/optional.hpp>
#include <boost/compute/system.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/type_traits/make_vector_type.hpp>
namespace tl {
namespace comp = boost::compute;
template<class t_scalar>
using t_comp_vec2 = typename comp::make_vector_type<t_scalar, 2>::type;
template<class t_scalar>
using t_comp_vec4 = typename comp::make_vector_type<t_scalar, 4>::type;
template<typename t_real=double>
boost::optional<comp::device> get_best_comp_dev()
{
struct _Dev
{
comp::device dev;
cl_device_type devtype;
};
std::vector<_Dev> vecAllDevs;
// enumerate all platforms & devices
for(comp::device& dev : comp::system::devices())
{
_Dev _dev;
_dev.dev = dev;
_dev.devtype = dev.type();