Skip to content

Commit

Permalink
Modularisation to prepare gr4.0 integration (#138)
Browse files Browse the repository at this point in the history
* Restructure to gnuradio repo layout
* fix plugin macro names
* CI: update binary path
* Move algorithm and meta sublibraries outside of core
* rename namespaces
* rename include file header guards

---------
authored-by: Alexander Krimm <[email protected]>
Signed-off-by: Ralph J. Steinhagen <[email protected]>
Co-authored-by: Ralph J. Steinhagen <[email protected]>
Co-authored-by: Ralph J. Steinhagen <[email protected]>
  • Loading branch information
wirew0rm authored Oct 7, 2023
1 parent 36e9068 commit 9d6299e
Show file tree
Hide file tree
Showing 133 changed files with 1,602 additions and 4,409 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ jobs:
if: matrix.configurations.compiler != 'emscripten'
working-directory: ${{runner.workspace}}/build
shell: bash
run: ./src/main
run: ./core/src/main

- name: execute wasm main binary with nodejs
if: matrix.configurations.compiler == 'emscripten'
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
node --experimental-wasm-threads ./src/main.js
node --experimental-wasm-threads ./core/src/main.js
- name: Run sonar-scanner
if: matrix.configurations.compiler == 'gcc12' && matrix.cmake-build-type == 'Debug'
Expand Down
64 changes: 38 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.25)

project(graph-prototype CXX)
project(gnuradio CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
Expand All @@ -18,14 +18,21 @@ endif()
# Replace ; with space
string(REPLACE ";" " " ALL_COMPILER_FLAGS "${ALL_COMPILER_FLAGS}")

# Determine if fmt is built as a subproject (using add_subdirectory) or if it is the master project.
if (NOT DEFINED GR_TOPLEVEL_PROJECT)
set(GR_TOPLEVEL_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(GR_TOPLEVEL_PROJECT ON)
message(STATUS "CMake version: ${CMAKE_VERSION}")
endif ()
endif ()

# Mainly for FMT
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

add_library(graph-prototype-options INTERFACE)
add_library(gnuradio-options INTERFACE)
include(cmake/CompilerWarnings.cmake)
set_project_warnings(graph-prototype-options)

set_project_warnings(gnuradio-options)

if(CMAKE_CXX_COMPILER MATCHES "/em\\+\\+(-[a-zA-Z0-9.])?$") # if this hasn't been set before via e.g. emcmake
message(" Transpiling to WASM: using: Emscripten (${CMAKE_CXX_COMPILER})")
Expand All @@ -34,19 +41,18 @@ endif()

if (EMSCRIPTEN)
set(CMAKE_EXECUTABLE_SUFFIX ".js")
target_compile_options(graph-prototype-options INTERFACE
target_compile_options(gnuradio-options INTERFACE
-fwasm-exceptions
-pthread
)
target_link_options(graph-prototype-options INTERFACE
target_link_options(gnuradio-options INTERFACE
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
-fwasm-exceptions
-pthread
"SHELL:-s PTHREAD_POOL_SIZE=30"
)
endif ()


include(FetchContent)
FetchContent_Declare(
fmt
Expand Down Expand Up @@ -78,11 +84,20 @@ FetchContent_Declare(
GIT_TAG yaml-cpp-0.7.0
)

FetchContent_MakeAvailable(fmt refl-cpp pmt ut yaml-cpp)
FetchContent_Declare(
vir-simd
GIT_REPOSITORY https://github.com/mattkretz/vir-simd.git
GIT_TAG v0.2.0
)

FetchContent_MakeAvailable(fmt refl-cpp pmt ut yaml-cpp vir-simd)

add_library(pmtv INTERFACE)
target_include_directories(pmtv INTERFACE ${pmt_SOURCE_DIR}/include/)

add_library(vir INTERFACE)
target_include_directories(vir INTERFACE ${vir-simd_SOURCE_DIR}/)

# FFTW3 is build 2 times for float and double precisions
SET(FFTW_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/fftw)
if (EMSCRIPTEN)
Expand Down Expand Up @@ -116,44 +131,41 @@ ExternalProject_Add(fftw_ext
LOG_DOWNLOAD ON
)

include_directories(${FFTW_PREFIX}/install/include)

add_library(fftw INTERFACE)
target_link_libraries(fftw INTERFACE fftw3 INTERFACE fftw3f INTERFACE m)
target_include_directories(fftw INTERFACE ${FFTW_PREFIX}/install/include)
target_include_directories(fftw INTERFACE ${FFTW_PREFIX}/install/include ${PROJECT_BINARY_DIR})
target_link_directories(fftw INTERFACE ${FFTW_PREFIX}/install/lib ${FFTW_PREFIX}/install/lib64)
add_dependencies(fftw fftw_ext)

# configure a header file to pass the CMake settings to the source code
configure_file("${PROJECT_SOURCE_DIR}/cmake/config.h.in" "${PROJECT_BINARY_DIR}/config.h" @ONLY)
include_directories("${PROJECT_BINARY_DIR}")
option(ENABLE_EXAMPLES "Enable Example Builds" ${GR_TOPLEVEL_PROJECT})

add_subdirectory(include)
add_subdirectory(src)

option(ENABLE_TESTING "Enable Test Builds" ON)
option(ENABLE_TESTING "Enable Test Builds" ${GR_TOPLEVEL_PROJECT})
if (ENABLE_TESTING AND UNIX AND NOT APPLE)
list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
enable_testing()
if (ENABLE_COVERAGE)
message("Coverage reporting enabled")
include(cmake/CodeCoverage.cmake) # https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake # (License: BSL-1.0)
target_compile_options(graph-prototype-options INTERFACE --coverage -O0 -g -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0) # fortify_source is not possible without optimization
target_link_libraries(graph-prototype-options INTERFACE --coverage)
target_compile_options(gnuradio-options INTERFACE --coverage -O0 -g -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0) # fortify_source is not possible without optimization
target_link_libraries(gnuradio-options INTERFACE --coverage)
append_coverage_compiler_flags()
setup_target_for_coverage_gcovr_xml(
NAME coverage
EXECUTABLE ctest
DEPENDENCIES qa_buffer qa_data_sink qa_dynamic_port qa_dynamic_node qa_hier_node qa_filter qa_fft qa_settings qa_tags qa_scheduler qa_thread_pool qa_thread_affinity
DEPENDENCIES qa_buffer qa_data_sink qa_dynamic_port qa_dynamic_node qa_hier_node qa_filter qa_settings qa_tags qa_scheduler qa_thread_pool qa_thread_affinity
EXCLUDE "$CMAKE_BUILD_DIR/*" "concepts/.*" ".*/test/.*")
setup_target_for_coverage_gcovr_html(
NAME coverage_html
EXECUTABLE ctest
DEPENDENCIES qa_buffer qa_data_sink qa_dynamic_port qa_dynamic_node qa_hier_node qa_filter qa_fft qa_settings qa_tags qa_scheduler qa_thread_pool qa_thread_affinity
DEPENDENCIES qa_buffer qa_data_sink qa_dynamic_port qa_dynamic_node qa_hier_node qa_filter qa_settings qa_tags qa_scheduler qa_thread_pool qa_thread_affinity
EXCLUDE "$CMAKE_BUILD_DIR/*" "concepts/.*" ".*/test/.*")
endif ()
message("Building Tests.")
add_subdirectory(test)
message("Building Benchmarks.")
add_subdirectory(bench)
message("Building Tests and benchmarks.")
endif ()

add_subdirectory(bench) # custom ut addon for microbenchmarking

add_subdirectory(core)
add_subdirectory(meta)
add_subdirectory(algorithm)
add_subdirectory(blocks)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![License](https://img.shields.io/badge/License-LGPL%203.0-blue.svg)](https://opensource.org/licenses/LGPL-3.0)
![CMake](https://github.com/fair-acc/graph-prototype/workflows/CMake/badge.svg)
# Graph Prototype
# GNURadio 4.0 prototype
A small proof-of-concept for evaluating efficient [directed graph](https://en.wikipedia.org/wiki/Directed_graph)-based
algorithms, notably required node structures, scheduling interfaces, and partial compile-time merging of
[directed acyclic](https://en.wikipedia.org/wiki/Directed_acyclic_graph) as well as
Expand Down
7 changes: 7 additions & 0 deletions algorithm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_library(gnuradio-algorithm INTERFACE)
target_include_directories(gnuradio-algorithm INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/> $<INSTALL_INTERFACE:include/>)
target_link_libraries(gnuradio-algorithm INTERFACE gnuradio-options gnuradio-meta vir fftw)

if (ENABLE_TESTING)
add_subdirectory(test)
endif ()
6 changes: 6 additions & 0 deletions algorithm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# gnuradio-algorithm

A math support library with math primitives to be used by different block types.

Included algorithms:
- Fast Fourier Transform
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef GRAPH_PROTOTYPE_ALGORITHM_FFT_HPP
#define GRAPH_PROTOTYPE_ALGORITHM_FFT_HPP
#ifndef GNURADIO_ALGORITHM_FFT_HPP
#define GNURADIO_ALGORITHM_FFT_HPP

#include <ranges>

#include "fft_types.hpp"
#include "node.hpp"
#include "window.hpp"
#include <ranges>

namespace gr::algorithm {

Expand Down Expand Up @@ -109,4 +109,4 @@ struct FFT {

} // namespace gr::algorithm

#endif // GRAPH_PROTOTYPE_ALGORITHM_FFT_HPP
#endif // GNURADIO_ALGORITHM_FFT_HPP
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#ifndef GRAPH_PROTOTYPE_ALGORITHM_FFT_COMMON_HPP
#define GRAPH_PROTOTYPE_ALGORITHM_FFT_COMMON_HPP
#ifndef GNURADIO_ALGORITHM_FFT_COMMON_HPP
#define GNURADIO_ALGORITHM_FFT_COMMON_HPP

#include "fft_types.hpp"
#include <algorithm>
#include <cmath>
#include <vector>

#include <fmt/format.h>

#include "fft_types.hpp"

namespace gr::algorithm {

template<ComplexType T, typename U>
Expand All @@ -32,4 +35,4 @@ computePhaseSpectrum(const std::vector<T> &fftOut, std::vector<U> &phaseSpectrum
}

} // namespace gr::algorithm
#endif // GRAPH_PROTOTYPE_ALGORITHM_FFT_COMMON_HPP
#endif // GNURADIO_ALGORITHM_FFT_COMMON_HPP
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef GRAPH_PROTOTYPE_ALGORITHM_FFT_TYPES_HPP
#define GRAPH_PROTOTYPE_ALGORITHM_FFT_TYPES_HPP
#ifndef GNURADIO_ALGORITHM_FFT_TYPES_HPP
#define GNURADIO_ALGORITHM_FFT_TYPES_HPP

#include "node.hpp"
#include <type_traits>
#include <complex>

namespace gr::algorithm {
template<typename T>
Expand All @@ -24,4 +25,4 @@ struct FFTAlgoPrecision<T> {
};

} // namespace gr::algorithm
#endif // GRAPH_PROTOTYPE_ALGORITHM_FFT_TYPES_HPP
#endif // GNURADIO_ALGORITHM_FFT_TYPES_HPP
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#ifndef GRAPH_PROTOTYPE_ALGORITHM_FFTW_HPP
#define GRAPH_PROTOTYPE_ALGORITHM_FFTW_HPP
#ifndef GNURADIO_ALGORITHM_FFTW_HPP
#define GNURADIO_ALGORITHM_FFTW_HPP

#include <fftw3.h>

#include "dataset.hpp"
#include "fft_types.hpp"
#include "fftw3.h"
#include "history_buffer.hpp"
#include "node.hpp"
#include "window.hpp"

namespace gr::algorithm {

using namespace fair::graph;

template<typename T>
concept FFTwDoubleType = std::is_same_v<T, std::complex<double>> || std::is_same_v<T, double>;

Expand Down Expand Up @@ -215,4 +211,4 @@ struct FFTw {

} // namespace gr::algorithm

#endif // GRAPH_PROTOTYPE_ALGORITHM_FFTW_HPP
#endif // GNURADIO_ALGORITHM_FFTW_HPP
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

#ifndef GRAPH_PROTOTYPE_ALGORITHM_WINDOW_HPP
#define GRAPH_PROTOTYPE_ALGORITHM_WINDOW_HPP
#ifndef GNURADIO_ALGORITHM_WINDOW_HPP
#define GNURADIO_ALGORITHM_WINDOW_HPP

#include <algorithm>
#include <array>
#include <cmath>
#include <numbers>
#include <ranges>
#include <string_view>
#include <utils.hpp>
#include <vector>

#include <fmt/format.h>

#include <gnuradio-4.0/meta/utils.hpp>

namespace gr::algorithm::window {

/**
Expand All @@ -22,7 +23,7 @@ namespace gr::algorithm::window {
enum class Type : int { None, Rectangular, Hamming, Hann, HannExp, Blackman, Nuttall, BlackmanHarris, BlackmanNuttall, FlatTop, Exponential, Kaiser };
using enum Type;
inline static constexpr std::array<Type, 12> TypeList{ None, Rectangular, Hamming, Hann, HannExp, Blackman, Nuttall, BlackmanHarris, BlackmanNuttall, FlatTop, Exponential, Kaiser };
inline static constexpr fair::meta::fixed_string TypeNames = "[None, Rectangular, Hamming, Hann, HannExp, Blackman, Nuttall, BlackmanHarris, BlackmanNuttall, FlatTop, Exponential, Kaiser]";
inline static constexpr gr::meta::fixed_string TypeNames = "[None, Rectangular, Hamming, Hann, HannExp, Blackman, Nuttall, BlackmanHarris, BlackmanNuttall, FlatTop, Exponential, Kaiser]";

constexpr std::string_view
to_string(Type window) noexcept {
Expand Down Expand Up @@ -91,7 +92,7 @@ bessel_i0(const T x) noexcept {
* @param windowFunction The type of window function to create.
* @param Container std::vector containing the values of the window function.
*/
template<fair::meta::array_or_vector_type ContainerType, typename T = ContainerType::value_type>
template<gr::meta::array_or_vector_type ContainerType, typename T = ContainerType::value_type>
requires std::is_floating_point_v<T>
void
create(ContainerType &container, Type windowFunction, const T beta = static_cast<T>(1.6)) {
Expand Down Expand Up @@ -233,4 +234,4 @@ create<std::vector<double>>(std::vector<double> &container, Type windowFunction,

} // namespace gr::algorithm::window

#endif // GRAPH_PROTOTYPE_ALGORITHM_WINDOW_HPP
#endif // GNURADIO_ALGORITHM_WINDOW_HPP
2 changes: 2 additions & 0 deletions algorithm/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_ut_test(qa_algorithm_fourier)
target_link_libraries(qa_algorithm_fourier PRIVATE gnuradio-algorithm)
Loading

0 comments on commit 9d6299e

Please sign in to comment.