diff --git a/lib/adaptive_dfe_impl.cc b/lib/adaptive_dfe_impl.cc index 73daeb0..e176132 100644 --- a/lib/adaptive_dfe_impl.cc +++ b/lib/adaptive_dfe_impl.cc @@ -232,9 +232,9 @@ bool adaptive_dfe_impl::start() GR_LOG_DEBUG(d_logger,str(boost::format("adaptive_dfe_impl::start() nB=%d nF=%d mu=%f alpha=%f") % _nB % _nF % _mu % _alpha)); _filter_update = lms::make(_mu); - //_filter_update = nlms::make(0.5f, 1.0f); - //_filter_update = rls::make(0.001f, 0.9f); // not stable - //_filter_update = kalman_exp::make(1.0f, 0.9f); // too slow + // _filter_update = nlms::make(0.5f, 1.0f); + // _filter_update = rls::make(0.001f, 0.9f); // not stable + // _filter_update = kalman_exp::make(1.0f, 0.9f); // too slow // _filter_update = kalman_hsu::make(0.02f, 0.1f); // not stable return true; } diff --git a/lib/adaptive_dfe_impl.h b/lib/adaptive_dfe_impl.h index c4fcba0..635c9e0 100644 --- a/lib/adaptive_dfe_impl.h +++ b/lib/adaptive_dfe_impl.h @@ -27,7 +27,7 @@ #include #include "filter_update.hpp" -#include "volk_allocator.hpp" +#include "volk_alloc.h" namespace gr { namespace digitalhf { @@ -59,7 +59,7 @@ private: class adaptive_dfe_impl : public adaptive_dfe { private: - typedef std::vector > gr_complex_vec_type; + typedef volk::vector gr_complex_vec_type; int _sps; int _nB, _nF, _nW; diff --git a/lib/kalman_exp.hpp b/lib/kalman_exp.hpp index 4628540..09d9030 100644 --- a/lib/kalman_exp.hpp +++ b/lib/kalman_exp.hpp @@ -6,7 +6,7 @@ #include #include "filter_update.hpp" -#include "volk_allocator.hpp" +#include "volk_alloc.h" // see // [1] https://open.library.ubc.ca/collections/ubctheses/831/items/1.0096286 @@ -30,7 +30,7 @@ protected: private: kalman_exp(float r, float lambda); - typedef std::vector > vec_type; + typedef volk::vector vec_type; float _lambda; float _r; vec_type _gain; diff --git a/lib/kalman_hsu.hpp b/lib/kalman_hsu.hpp index e739c57..7cd2e4a 100644 --- a/lib/kalman_hsu.hpp +++ b/lib/kalman_hsu.hpp @@ -6,7 +6,7 @@ #include #include "filter_update.hpp" -#include "volk_allocator.hpp" +#include "volk_alloc.h" namespace gr { @@ -40,8 +40,8 @@ protected: private: kalman_hsu(float q, float e); - typedef std::vector > complex_vec_type; - typedef std::vector > real_vec_type; + typedef volk::vector complex_vec_type; + typedef volk::vector real_vec_type; float _q; float _e; complex_vec_type _g; // n -- kaman gain diff --git a/lib/lms.hpp b/lib/lms.hpp index 57ff132..d087d07 100644 --- a/lib/lms.hpp +++ b/lib/lms.hpp @@ -6,7 +6,7 @@ #include #include "filter_update.hpp" -#include "volk_allocator.hpp" +#include "volk/volk_alloc.h" namespace gr { @@ -28,7 +28,7 @@ protected: private: lms(float mu); - typedef std::vector > vec_type; + typedef volk::vector vec_type; float _mu; vec_type _gain; vec_type _tmp; diff --git a/lib/nlms.cc b/lib/nlms.cc index bf3eee3..1e13a93 100644 --- a/lib/nlms.cc +++ b/lib/nlms.cc @@ -44,7 +44,7 @@ gr_complex const* nlms::update(gr_complex const* beg, volk_32fc_magnitude_squared_32f(&_t1[0], beg, n); float norm = _delta; volk_32f_accumulator_s32f(&norm, &_t1[0], n); - volk_32f_s32f_multiply_32f((float*)&_gain[0], (float const*)&_tmp[0], std::max(0.006f, _mu/norm), 2*n); + volk_32f_s32f_multiply_32f((float*)&_gain[0], (float const*)&_tmp[0], std::max(0.005f, _mu/norm), 2*n); return &_gain.front(); } diff --git a/lib/nlms.hpp b/lib/nlms.hpp index 5b5e293..f20ca7f 100644 --- a/lib/nlms.hpp +++ b/lib/nlms.hpp @@ -6,7 +6,7 @@ #include #include "filter_update.hpp" -#include "volk_allocator.hpp" +#include "volk_alloc.h" namespace gr { @@ -28,8 +28,8 @@ protected: private: nlms(float mu, float delta); - typedef std::vector > complex_vec_type; - typedef std::vector > real_vec_type; + typedef volk::vector complex_vec_type; + typedef volk::vector real_vec_type; float _mu; float _delta; complex_vec_type _gain; diff --git a/lib/rls.hpp b/lib/rls.hpp index 68c4762..fce8151 100644 --- a/lib/rls.hpp +++ b/lib/rls.hpp @@ -6,7 +6,7 @@ #include #include "filter_update.hpp" -#include "volk_allocator.hpp" +#include "volk_alloc.h" namespace gr { @@ -28,7 +28,7 @@ protected: private: rls(float delta, float lambda); - typedef std::vector > vec_type; + typedef volk::vector vec_type; float _delta; float _lambda; vec_type _gain; diff --git a/lib/volk_alloc.h b/lib/volk_alloc.h new file mode 100644 index 0000000..a2975da --- /dev/null +++ b/lib/volk_alloc.h @@ -0,0 +1,80 @@ +/* -*- C++ -*- */ +/* + * Copyright 2019 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_VOLK_ALLOC_H +#define INCLUDED_VOLK_ALLOC_H + +#include +#include +#include +#include + +#include + +namespace volk { + +/*! + * \brief C++11 allocator using volk_malloc and volk_free + * + * \details + * adapted from https://en.cppreference.com/w/cpp/named_req/Alloc + */ +template +struct alloc { + typedef T value_type; + + alloc() = default; + + template constexpr alloc(alloc const&) noexcept {} + + T* allocate(std::size_t n) { + if (n > std::numeric_limits::max() / sizeof(T)) throw std::bad_alloc(); + + if (auto p = static_cast(volk_malloc(n*sizeof(T), volk_get_alignment()))) + return p; + + throw std::bad_alloc(); + } + + void deallocate(T* p, std::size_t) noexcept { volk_free(p); } + +} ; + +template +bool operator==(alloc const&, alloc const&) { return true; } + +template +bool operator!=(alloc const&, alloc const&) { return false; } + + +/*! + * \brief type alias for std::vector using volk::alloc + * + * \details + * example code: + * volk::vector v(100); // vector using volk_malloc, volk_free + */ +template +using vector = std::vector >; + +} // namespace volk +#endif // INCLUDED_VOLK_ALLOC_H diff --git a/lib/volk_allocator.hpp b/lib/volk_allocator.hpp deleted file mode 100644 index d4c926e..0000000 --- a/lib/volk_allocator.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// -*- c++ -*- - -#ifndef _LIB_VOLK_ALLOCATOR_HPP_ -#define _LIB_VOLK_ALLOCATOR_HPP_ - -#include -#include -#include - -namespace gr { -namespace digitalhf { - -// see https://en.cppreference.com/w/cpp/named_req/Allocator -template -struct volk_allocator { - typedef T value_type; - - volk_allocator() = default; - - template constexpr volk_allocator(const volk_allocator&) noexcept {} - - T* allocate(std::size_t n) { - if (n > std::numeric_limits::max() / sizeof(T)) throw std::bad_alloc(); - - if (auto p = static_cast(volk_malloc(n*sizeof(T), volk_get_alignment()))) - return p; - - throw std::bad_alloc(); - } - - void deallocate(T* p, std::size_t) noexcept { volk_free(p); } - -} ; - -template -bool operator==(const volk_allocator&, const volk_allocator&) { return true; } - -template -bool operator!=(const volk_allocator&, const volk_allocator&) { return false; } - -} // namespace digitalhf -} // namespace gr -#endif // _LIB_VOLK_ALLOCATOR_HPP_