Commit a2865b74 authored by Tobias Winchen's avatar Tobias Winchen
Browse files

Merged edd

parents 67e61eb3 a40b4387
[submodule "thirdparty/googletest"]
path = thirdparty/googletest
url = https://github.com/google/googletest.git
......@@ -11,4 +11,4 @@ if(BOOST_ASIO_DEBUG)
add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
else(BOOST_ASIO_DEBUG)
set(BOOST_ASIO_DEBUG false)
endif(BOOST_ASIO_DEBUG)
\ No newline at end of file
endif(BOOST_ASIO_DEBUG)
......@@ -31,9 +31,9 @@ endif ()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -Wno-unused-local-typedefs")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -Wall -Wextra -pedantic -Wno-unused-local-typedefs")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall -Wextra -pedantic -Wno-unused-local-typedefs")
set(CMAKE_CXX_FLAGS_DEBUG "-O3 -g -pg -Wall -Wextra -pedantic -Wno-unused-local-typedefs")
# Set include directories for dependencies
include_directories(
${Boost_INCLUDE_DIRS}
)
\ No newline at end of file
)
......@@ -12,14 +12,23 @@ if(ENABLE_CUDA)
set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
add_definitions(-DENABLE_CUDA)
# Pass options to NVCC ( -ccbin /path --compiler-options -lfftw3f --compiler-options -lm --verbose)
list(APPEND CUDA_NVCC_FLAGS -DENABLE_CUDA --std c++11)
list(APPEND CUDA_NVCC_FLAGS_DEBUG --debug; --device-debug; --generate-line-info -Xcompiler "-Werror")
# list(APPEND CUDA_NVCC_FLAGS -arch compute_35) # minumum compute level (Sps restriction)
list(APPEND CUDA_NVCC_FLAGS -DENABLE_CUDA --std c++11 -Wno-deprecated-gpu-targets --ptxas-options=-v)
list(APPEND CUDA_NVCC_FLAGS_DEBUG --debug; --device-debug; --generate-line-info -Xcompiler "-Wextra" -Xcompiler "-Werror")
list(APPEND CUDA_NVCC_FLAGS_PROFILE --generate-line-info)
#list(APPEND CUDA_NVCC_FLAGS -arch compute_35) # minumum compute level (Sps restriction)
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if(NOT uppercase_CMAKE_BUILD_TYPE MATCHES "DEBUG")
message("Enabling device specific compilation as not in DEBUG mode")
list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_61,code=sm_61) # GTX1080Ti
endif(NOT uppercase_CMAKE_BUILD_TYPE MATCHES "DEBUG")
#list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_52,code=sm_52) # TitanX
#list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_50,code=sm_50) # Maxwell
#list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_37,code=sm_37) # K80
list(APPEND CUDA_NVCC_FLAGS -O3 -use_fast_math -restrict)
set(CMAKE_CXX_FLAGS "-DENABLE_CUDA ${CMAKE_CXX_FLAGS}")
......
include(cuda)
include(compiler_settings)
include(cmake/googletest.cmake)
include(cmake/boost.cmake)
include(cmake/psrdada.cmake)
include_directories(SYSTEM ${Boost_INCLUDE_DIR} ${PSRDADA_INCLUDE_DIR})
include_directories(BEFORE ${GTEST_INCLUDE_DIR})
set(DEPENDENCY_LIBRARIES
${GTEST_LIBRARIES}
${Boost_LIBRARIES}
${PSRDADA_LIBRARIES}
${CUDA_CUDART_LIBRARY}
)
\ No newline at end of file
)
# == googletest build - must be build with the same compiler flags
if(NOT GTEST_INCLUDE_DIR)
if(APPLE)
add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1)
else(APPLE)
add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=0)
endif(APPLE)
add_subdirectory("thirdparty/googletest")
set(GTEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/googletest/include)
set(GTEST_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty/googletest)
message("BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}")
set(GTEST_LIBRARIES gtest_main gtest)
endif()
# -------------------------------------------
# Build and integrate a thirdparty dependency
#
# Copyright Oxford university 2018
# Released under GPL v3
# --------------------------------------------
macro(add_thirdparty_subdirectory dependency_name dependency_dir)
set(dependency_install_path "thirdparty/${dependency_name}")
mark_as_advanced(dependency_install_path)
# save current project state
list(APPEND LIBRARY_INSTALL_DIR_STACK ${LIBRARY_INSTALL_DIR})
list(APPEND INCLUDE_INSTALL_DIR_STACK ${INCLUDE_INSTALL_DIR})
list(APPEND MODULES_INSTALL_DIR_STACK ${MODULES_INSTALL_DIR})
list(APPEND BINARY_INSTALL_DIR_STACK ${LIBRARY_INSTALL_DIR})
list(APPEND DOC_INSTALL_DIR_STACK ${DOC_INSTALL_DIR})
# set dependency install targets to be relative to the parent project
set(LIBRARY_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/${dependency_install_path})
set(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/${dependency_install_path})
set(MODULES_INSTALL_DIR ${MODULES_INSTALL_DIR}/${dependency_install_path})
set(BINARY_INSTALL_DIR ${BINARY_INSTALL_DIR}/${dependency_install_path})
set(DOC_INSTALL_DIR ${DOC_INSTALL_DIR}/${dependency_install_path})
add_subdirectory(${dependency_dir})
# restore current project state
list(GET LIBRARY_INSTALL_DIR_STACK -1 LIBRARY_INSTALL_DIR)
list(REMOVE_AT LIBRARY_INSTALL_DIR_STACK -1)
list(GET INCLUDE_INSTALL_DIR_STACK -1 INCLUDE_INSTALL_DIR)
list(REMOVE_AT INCLUDE_INSTALL_DIR_STACK -1)
list(GET MODULES_INSTALL_DIR_STACK -1 MODULES_INSTALL_DIR)
list(REMOVE_AT MODULES_INSTALL_DIR_STACK -1)
list(GET BINARY_INSTALL_DIR_STACK -1 BINARY_INSTALL_DIR)
list(REMOVE_AT BINARY_INSTALL_DIR_STACK -1)
list(GET DOC_INSTALL_DIR_STACK -1 DOC_INSTALL_DIR)
list(REMOVE_AT DOC_INSTALL_DIR_STACK -1)
endmacro (add_thirdparty_directory)
......@@ -22,7 +22,7 @@ RUN echo 'deb http://us.archive.ubuntu.com/ubuntu trusty main multiverse' >> /et
apt-get -y update && \
apt-get install -y apt-utils apt-transport-https software-properties-common python-software-properties && \
apt-get -y update --fix-missing && \
apt-get -y upgrade
apt-get -y upgrade
# Install dependencies
RUN apt-get --no-install-recommends -y install \
......@@ -67,7 +67,7 @@ RUN mkdir build/ && \
./configure --prefix=$PSRDADA_HOME/build && \
make && \
make install && \
make clean
make clean
ENV PATH $PATH:$PSRDADA_HOME/build/bin
ENV PSRDADA_BUILD $PSRDADA_HOME/build/
ENV PACKAGES $PSRDADA_BUILD
......@@ -75,11 +75,13 @@ ENV PACKAGES $PSRDADA_BUILD
WORKDIR $PSRHOME
RUN git clone https://github.com/ewanbarr/psrdada_cpp.git && \
cd psrdada_cpp/ &&\
git checkout meerkat &&\
git checkout transpose &&\
git submodule init &&\
git submodule update &&\
mkdir build/ &&\
cd build/ &&\
cmake -DENABLE_CUDA=true ../ &&\
make -j 4 &&\
make -j 8 &&\
make install
RUN env | awk '{print "export ",$0}' > $HOME/.profile && \
......
......@@ -7,16 +7,39 @@ include_directories(${PROJECT_BINARY_DIR})
set(psrdada_cpp_src
src/cli_utils.cpp
src/dada_client_base.cpp
src/dada_db.cpp
src/dada_write_client.cpp
src/dada_null_sink.cpp
src/dada_disk_sink.cpp
src/dada_output_stream.cpp
src/dada_read_client.cpp
src/dada_write_client.cpp
src/multilog.cpp
src/raw_bytes.cpp
src/simple_file_writer.cpp
src/sigprocheader.cpp
src/psrdadaheader.cpp
)
set(psrdada_cpp_inc
cli_utils.hpp
dada_client_base.hpp
dada_input_stream.hpp
dada_output_stream.hpp
dada_read_client.hpp
dada_junk_source.hpp
dada_null_sink.hpp
multilog.hpp
common.hpp
dada_write_client.hpp
raw_bytes.hpp
cuda_utils.hpp
simple_file_writer.hpp
sigprocheader.hpp
psrdadaheader.hpp
psrdada_to_sigproc_header.hpp
)
# -- the main library target
add_library(${CMAKE_PROJECT_NAME} ${psrdada_cpp_src})
......@@ -24,11 +47,29 @@ add_library(${CMAKE_PROJECT_NAME} ${psrdada_cpp_src})
add_executable(junkdb examples/junkdb.cpp)
target_link_libraries (junkdb ${PSRDADA_CPP_LIBRARIES})
#syncdb
add_executable(syncdb examples/syncdb.cpp)
target_link_libraries (syncdb ${PSRDADA_CPP_LIBRARIES})
#fbfuse_output_db
add_executable(fbfuse_output_db examples/fbfuse_output_db.cpp)
target_link_libraries (fbfuse_output_db ${PSRDADA_CPP_LIBRARIES})
#dbnull
add_executable(dbnull examples/dbnull.cpp)
target_link_libraries (dbnull ${PSRDADA_CPP_LIBRARIES})
install (TARGETS junkdb dbnull DESTINATION bin)
#install (FILES MathFunctions.h DESTINATION include)
#dbisk
#add_executable(dbdisk examples/dbdisk.cpp)
#target_link_libraries (dbisk ${PSRDADA_CPP_LIBRARIES})
install (TARGETS junkdb dbnull syncdb fbfuse_output_db DESTINATION bin)
install (TARGETS ${CMAKE_PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(FILES ${psrdada_cpp_inc} DESTINATION include/psrdada_cpp)
install(DIRECTORY detail DESTINATION include/psrdada_cpp)
add_subdirectory(meerkat)
\ No newline at end of file
add_subdirectory(meerkat)
add_subdirectory(effelsberg)
......@@ -3,6 +3,7 @@
#include "dada_hdu.h"
#include "dada_def.h"
#include "dada_cuda.h"
#include "psrdada_cpp/multilog.hpp"
#include "psrdada_cpp/common.hpp"
......@@ -63,6 +64,11 @@ namespace psrdada_cpp {
*/
void reconnect();
/**
* @brief Pin memory with CUDA API
*/
void cuda_register_memory();
/**
* @brief Return a string identifier based on the buffer key and log name
*/
......@@ -71,4 +77,4 @@ namespace psrdada_cpp {
} //namespace psrdada_cpp
#endif //PSRDADA_CPP_DADA_CLIENT_BASE_HPP
\ No newline at end of file
#endif //PSRDADA_CPP_DADA_CLIENT_BASE_HPP
#ifndef PSRDADA_CPP_DADADB_HPP
#define PSRDADA_CPP_DADADB_HPP
#include "dada_def.h"
#include "ipcbuf.h"
#include <mutex>
namespace psrdada_cpp {
/**
* @brief A mock class for implementing the interface of a DADA DB (Header/Data Unit)
*
* @details A standard DADA HDU buffer is composed of a set of data buffers of equal size
* and a set of header buffers of equal size.
*
* The standard use case is that a client connects to the header buffer, reads some
* metadata and then uses that to determine how to handle the data in the data buffers.
*
*/
class DadaDB
{
public:
/**
* @brief Constructa new DadaDB instance
*
* @param[in] _key A hexidecimal shared memory key
* @param[in] _nbufs The number of data buffers
* @param[in] _bufsz The size in bytes of each data buffer
* @param[in] _nhdrs The number of header buffers
* @param[in] _hdrsz The size in bytes of each header buffer
*/
DadaDB(uint64_t nbufs = DADA_DEFAULT_BLOCK_NUM,
uint64_t bufsz = DADA_DEFAULT_BLOCK_SIZE,
uint64_t nhdrs = IPCBUF_XFERS,
uint64_t hdrsz = DADA_DEFAULT_HEADER_SIZE);
DadaDB(DadaDB const&) = delete;
~DadaDB();
/**
* @brief Create the data and header blocks in shared memory
*/
void create();
/**
* @brief Destroy the allocated shared memory blocks
*/
void destroy();
/**
* @brief Return the number of data buffers
*/
uint64_t num_data_buffers() const;
/**
* @brief Return the size of each data buffer
*/
uint64_t data_buffer_size() const;
/**
* @brief Return the number of header buffers
*/
uint64_t num_header_buffers() const;
/**
* @brief Return the size of each header buffer
*/
uint64_t header_buffer_size() const;
/**
* @brief Return the hexidecimal shared memory key
*
* @detail This key can be used by other processes to access
* the shared memory blocks.
*
* @note This key is the key to the data blocks. To access
* the header blocks use key+1. This is handled under
* the hood by PSRDADA applocations and is handled by
* DadaReadClient.
*/
key_t key() const;
protected:
void do_destroy();
private:
uint64_t _nbufs;
uint64_t _bufsz;
uint64_t _nhdrs;
uint64_t _hdrsz;
key_t _dada_key;
ipcbuf_t _data_block;
ipcbuf_t _header;
bool _data_blocks_created;
bool _header_blocks_created;
std::mutex _lock;
};
} // namespace psrdada_cpp
#endif // PSRDADA_CPP_DADADB_HPP
#ifndef PSRDADA_CPP_DADA_DISK_SINK_HPP
#define PSRDADA_CPP_DADA_DISK_SINK_HPP
#include "psrdada_cpp/raw_bytes.hpp"
#include "psrdada_cpp/common.hpp"
#include <fstream>
namespace psrdada_cpp
{
class DiskSink
{
public:
DiskSink(std::string prefix);
~DiskSink();
void init(RawBytes&);
bool operator()(RawBytes&);
public:
std::string _prefix;
std::size_t _counter;
std::ofstream _current_file;
};
} //namespace psrdada_cpp
#endif //PSRDADA_CPP_DADA_DISK_SINK_HPP
\ No newline at end of file
......@@ -28,4 +28,4 @@ namespace psrdada_cpp
#include "psrdada_cpp/detail/dada_input_stream.cpp"
#endif //PSRDADA_CPP_DADA_INPUT_STREAM_HPP
\ No newline at end of file
#endif //PSRDADA_CPP_DADA_INPUT_STREAM_HPP
......@@ -4,6 +4,8 @@
#include "psrdada_cpp/raw_bytes.hpp"
#include "psrdada_cpp/common.hpp"
#include <vector>
#include <cstdlib>
#include <fstream>
namespace psrdada_cpp
{
......@@ -11,13 +13,23 @@ namespace psrdada_cpp
void junk_source(Handler& handler,
std::size_t header_size,
std::size_t nbytes_per_write,
std::size_t total_bytes)
std::size_t total_bytes,
std::string header_file)
{
std::vector<char> junk_header(header_size);
std::vector<char> junk_block(nbytes_per_write);
std::ifstream input;
input.open(header_file,std::ios::in | std::ios::binary);
input.read(junk_header.data(),header_size);
RawBytes header(junk_header.data(),header_size,header_size,false);
handler.init(header);
std::size_t bytes_written = 0;
std::vector<char> junk_block(total_bytes,0);
srand(0);
for (std::uint32_t ii=0; ii < total_bytes; ++ii)
{
junk_block[ii] = rand()%255 + 1;
}
while (bytes_written < total_bytes)
{
RawBytes data(junk_block.data(),nbytes_per_write,nbytes_per_write,false);
......@@ -26,4 +38,4 @@ namespace psrdada_cpp
}
}
} //namespace psrdada_cpp
#endif //PSRDADA_CPP_DADA_JUNK_SOURCE_HPP
\ No newline at end of file
#endif //PSRDADA_CPP_DADA_JUNK_SOURCE_HPP
#ifndef PSRDADA_CPP_DADA_SYNC_SOURCE_HPP
#define PSRDADA_CPP_DADA_SYNC_SOURCE_HPP
#include "psrdada_cpp/raw_bytes.hpp"
#include "psrdada_cpp/common.hpp"
#include "ascii_header.h"
#include <vector>
#include <chrono>
#include <iomanip> // std::put_time
#include <thread> // std::this_thread::sleep_until
#include <chrono> // std::chrono::system_clock
#include <ctime>
#include <cmath>
namespace psrdada_cpp
{
template <class Handler>
void sync_source(Handler& handler,
std::size_t header_size,
std::size_t nbytes_per_write,
std::size_t total_bytes,
std::time_t sync_epoch,
double block_duration,
std::size_t ts_per_block)
{
std::vector<char> sync_header(header_size, 0);
std::vector<char> sync_block(nbytes_per_write, 1);
RawBytes header(sync_header.data(), header_size, header_size, false);
RawBytes data(sync_block.data(), nbytes_per_write, nbytes_per_write, false);
std::size_t sample_clock_start;
auto sync_epoch_tp = std::chrono::system_clock::from_time_t(sync_epoch);
auto curr_epoch_tp = std::chrono::system_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::microseconds>(curr_epoch_tp - sync_epoch_tp).count();
std::size_t next_block_idx;
if (sync_epoch_tp > curr_epoch_tp)
{
BOOST_LOG_TRIVIAL(info) << "The sync epoch is " << static_cast<float>(diff)/1e6
<< " seconds in the future";
next_block_idx = 0;
sample_clock_start = 0;
}
else
{
next_block_idx = static_cast<std::size_t>((std::ceil(static_cast<double>(diff)/1e6) / block_duration));
sample_clock_start = next_block_idx * ts_per_block;
}
BOOST_LOG_TRIVIAL(info) << "Setting SAMPLE_CLOCK_START to " << sample_clock_start;
ascii_header_set(sync_header.data(), "SAMPLE_CLOCK_START", "%ld", sample_clock_start);
handler.init(header);
std::size_t bytes_written = 0;
bool infinite = (total_bytes == 0);
while (true)
{
auto epoch_of_wait = sync_epoch_tp + std::chrono::duration<double>(next_block_idx * block_duration);
std::this_thread::sleep_until(epoch_of_wait);
handler(data);
bytes_written += data.used_bytes();
++next_block_idx;
if (!infinite && bytes_written >= total_bytes)
{
break;
}
}
}
} //namespace psrdada_cpp
#endif //PSRDADA_CPP_DADA_SYNC_SOURCE_HPP
......@@ -132,4 +132,4 @@ namespace psrdada_cpp {
} //namespace psrdada_cpp
#endif //PSRDADA_CPP_DADA_WRITE_CLIENT_HPP
\ No newline at end of file
#endif //PSRDADA_CPP_DADA_WRITE_CLIENT_HPP
......@@ -20,12 +20,13 @@ namespace psrdada_cpp {
template <class HandlerType>
void DadaInputStream<HandlerType>::start()
{
bool handler_stop_request = false;
if (_running)
{
throw std::runtime_error("Stream is already running");
}
_running = true;
while (!_stop)
while (!_stop && !handler_stop_request)
{
BOOST_LOG_TRIVIAL(info) << "Attaching new read client to buffer";
DadaReadClient client(_key,_log);
......@@ -34,14 +35,14 @@ namespace psrdada_cpp {
_handler.init(header_block);
header_stream.release();
auto& data_stream = client.data_stream();
while (!_stop)
while (!_stop && !handler_stop_request)
{
if (data_stream.at_end())
{
BOOST_LOG_TRIVIAL(info) << "Reached end of data";
break;
}
_stop = _handler(data_stream.next());
handler_stop_request = _handler(data_stream.next());
data_stream.release();
}
}
......@@ -54,4 +55,4 @@ namespace psrdada_cpp {
_stop = true;
}
} //psrdada_cpp
\ No newline at end of file
} //psrdada_cpp
#include "psrdada_cpp/double_buffer.hpp"
#include <utility>
namespace psrdada_cpp {
template <typename T>
DoubleBuffer<T>::DoubleBuffer()
{
_a_ptr = &_buf0;
_b_ptr = &_buf1;
}
template <typename T>
DoubleBuffer<T>::~DoubleBuffer()
{
}
template <typename T>
void DoubleBuffer<T>::resize(std::size_t size)
{
_buf0.resize(size);
_buf1.resize(size);
}
template <typename T>
void DoubleBuffer<T>::swap()
{
std::swap(_a_ptr, _b_ptr);
}
template <typename T>
T* DoubleBuffer<T>::a() const
{
return _a_ptr;
}
template <typename T>
T* DoubleBuffer<T>::b() const
{
return _b_ptr;
}
} //namespace psrdada_cpp
\ No newline at end of file
#include "psrdada_cpp/double_buffer.cuh"
#include <utility>
namespace psrdada_cpp {
template <typename VectorType>
DoubleBuffer<VectorType>::DoubleBuffer()
{
}
template <typename VectorType>
DoubleBuffer<VectorType>::~DoubleBuffer()
{
}
template <typename VectorType>
void DoubleBuffer<VectorType>::resize(std::size_t size)
{
_buf0.resize(size);
_buf1.resize(size);
}
template <typename VectorType>
void DoubleBuffer<VectorType>::resize(std::size_t size, typename VectorType::value_type fill_value)
{
_buf0.resize(size, fill_value);
_buf1.resize(size, fill_value);
}