Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/max params #132

Merged
merged 6 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

cmake_minimum_required (VERSION 3.11)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

get_directory_property(hasParent PARENT_DIRECTORY)

#set module path at top level so wrapper projects can easily include fluid_version script
Expand Down Expand Up @@ -127,9 +131,6 @@ target_link_libraries(
target_include_directories(HISSTools_FFT PUBLIC "${hisstools_SOURCE_DIR}")

set_target_properties(HISSTools_FFT PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)

Expand All @@ -152,11 +153,6 @@ add_library(
"${hisstools_SOURCE_DIR}/AudioFile/OAudioFile.cpp"
)

set_target_properties(HISSTools_AudioFile PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)

#Fluid Decomposition header-only target
add_library(FLUID_DECOMPOSITION INTERFACE)
Expand Down
7 changes: 0 additions & 7 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,5 @@ foreach (EXAMPLE describe)
)

target_compile_options(${EXAMPLE} PRIVATE ${FLUID_ARCH})

set_target_properties(${EXAMPLE}
PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)

endforeach (EXAMPLE)
12 changes: 4 additions & 8 deletions include/clients/common/FluidBaseClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ enum ProcessState { kNoProcess, kProcessing, kDone, kDoneStillProcessing };

struct ControlChannel {
index count{0};
index size{-1};
index size{-1};
index max{-1};
};

class FluidBaseClient
Expand All @@ -47,7 +48,7 @@ class FluidBaseClient
ControlChannel controlChannelsOut() const noexcept { return mControlChannelsOut; }
index maxControlChannelsOut() const noexcept
{
return mMaxControlChannelsOut;
return mControlChannelsOut.max > -1 ? mControlChannelsOut.max : mControlChannelsOut.size;
}
bool controlTrigger() const noexcept { return mControlTrigger; }
index audioBuffersIn() const noexcept { return mBuffersIn; }
Expand All @@ -71,10 +72,6 @@ class FluidBaseClient
void audioChannelsOut(const index x) noexcept { mAudioChannelsOut = x; }
void controlChannelsIn(const index x) noexcept { mControlChannelsIn = x; }
void controlChannelsOut(const ControlChannel x) noexcept { mControlChannelsOut = x; }
void maxControlChannelsOut(const index x) noexcept
{
mMaxControlChannelsOut = x;
}
void controlTrigger(const bool x) noexcept { mControlTrigger = x; }
void audioBuffersIn(const index x) noexcept { mBuffersIn = x; }
void audioBuffersOut(const index x) noexcept { mBuffersOut = x; }
Expand All @@ -97,8 +94,7 @@ class FluidBaseClient
index mAudioChannelsIn = 0;
index mAudioChannelsOut = 0;
index mControlChannelsIn = 0;
ControlChannel mControlChannelsOut {0,0};
index mMaxControlChannelsOut = 0;
ControlChannel mControlChannelsOut {0,0,-1};
bool mControlTrigger{false};
index mBuffersIn = 0;
index mBuffersOut = 0;
Expand Down
8 changes: 4 additions & 4 deletions include/clients/common/FluidNRTClientWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ struct StreamingControl
{
// To account for process latency we need to copy the buffers with padding
std::vector<HostMatrix> inputData;
index nFeatures = client.controlChannelsOut().size;
index maxFeatures = client.maxControlChannelsOut();
// outputData.reserve(nFeatures);
inputData.reserve(inputBuffers.size());

Expand Down Expand Up @@ -557,7 +557,7 @@ struct StreamingControl
std::fill_n(std::back_inserter(inputData), inputBuffers.size(),
HostMatrix(nChans, nFrames + totalPadding));

HostMatrix outputData(nChans * nFeatures, nHops);
HostMatrix outputData(nChans * maxFeatures, nHops);
double sampleRate{0};
// Copy input data
for (index i = 0; i < nChans; ++i)
Expand Down Expand Up @@ -591,7 +591,7 @@ struct StreamingControl

// for (index k = 0; k < nFeatures; ++k)
// outputs.emplace_back(outputData.row(k + i * nFeatures)(Slice(j, 1)));
outputs.push_back(outputData.col(j)(Slice(i * nFeatures, nFeatures)));
outputs.push_back(outputData.col(j)(Slice(i * maxFeatures, maxFeatures)));

client.process(inputs, outputs, dummyContext);

Expand All @@ -603,7 +603,7 @@ struct StreamingControl
}

BufferAdaptor::Access thisOutput(outputBuffers[0]);

index nFeatures = client.controlChannelsOut().size;
index latencyHops = client.latency() / controlRate;
index keepHops = nHops - latencyHops;

Expand Down
25 changes: 20 additions & 5 deletions include/clients/common/ParameterConstraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,22 @@ struct MinImpl
constexpr void clamp(U& x, Tuple& /*params*/, Descriptor& d, Result* r) const
{
U oldX = x;
x = std::max<U>(x, value);
x = std::max<U>(x, static_cast<U>(value));
if (r && oldX != x)
{
r->set(Result::Status::kWarning);
r->addMessage(d.template get<N>().name, " value, ", oldX,
", below absolute minimum ", x);
}
}

template <size_t Offset, size_t N, typename Tuple,
typename Descriptor>
constexpr void clamp(LongRuntimeMaxParam& x, Tuple& /*params*/, Descriptor& d, Result* r) const
{
index oldX = x();
index newx = std::max<index>(x(), value);
x.set(newx);
if (r && oldX != x)
{
r->set(Result::Status::kWarning);
Expand Down Expand Up @@ -75,17 +90,17 @@ struct LowerLimitImpl : public Relational
{
T oldV = v;

v = std::max<T>({v, std::get<Is + Offset>(params)...});
v = std::max<T>({v, std::get<Is + Offset>(params).get()...});

if (r && oldV != v)
{
r->set(Result::Status::kWarning);
std::array<T, sizeof...(Is)> constraintValues{
{std::get<Is + Offset>(params)...}};
{std::get<Is + Offset>(params).get()...}};
index minPos = std::distance(
constraintValues.begin(),
std::min_element(constraintValues.begin(), constraintValues.end()));
std::array<const char*, sizeof...(Is)> constraintNames{
std::array<std::string_view, sizeof...(Is)> constraintNames{
{d.template get<Is + Offset>().name...}};
r->addMessage(d.template get<N>().name, " value (", oldV,
") below parameter ", constraintNames[asUnsigned(minPos)],
Expand Down Expand Up @@ -113,7 +128,7 @@ struct UpperLimitImpl : public Relational
index maxPos = std::distance(
constraintValues.begin(),
std::max_element(constraintValues.begin(), constraintValues.end()));
std::array<const char*, sizeof...(Is)> constraintNames{
std::array<std::string_view, sizeof...(Is)> constraintNames{
{d.template get<Is + Offset>().name...}};
r->addMessage(d.template get<N>().name, " value, ", oldV,
", above parameter ", constraintNames[asUnsigned(maxPos)],
Expand Down
69 changes: 64 additions & 5 deletions include/clients/common/ParameterSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ under the European Union’s Horizon 2020 research and innovation programme
#include "../../data/FluidIndex.hpp"
#include <functional>
#include <tuple>
#include <type_traits>



namespace fluid {
namespace client {
Expand All @@ -29,16 +32,41 @@ class ParameterDescriptorSet;
template <size_t... Os, typename... Ts>
class ParameterDescriptorSet<std::index_sequence<Os...>, std::tuple<Ts...>>
{


template<size_t N, typename Tuple>
using tuple_element_t = typename std::tuple_element<N,Tuple>::type;

struct IsPrimary
{
template <typename T>
using apply = std::is_same<Primary,tuple_element_t<2,T>>;
};

template <bool B>
struct FixedParam
{
template <typename T>
using apply =
std::is_same<Fixed<B>, typename std::tuple_element<2, T>::type>;
using apply = std::is_same<Fixed<B>, tuple_element_t<2,T>>;
};

using IsFixed = FixedParam<true>;
using IsMutable = FixedParam<false>;

struct IsFixed
{
template <typename T>
using apply = std::is_same<Fixed<true>, tuple_element_t<2,T>>;
};

struct IsMutable
{
template <typename T>
using apply = std::disjunction<
std::is_same<Fixed<false>, tuple_element_t<2,T>>,
std::is_same<Primary, tuple_element_t<2,T>>>;
};


// using IsFixed = FixedParam<true>;
// using IsMutable = FixedParam<false>;

struct IsRelational
{
Expand Down Expand Up @@ -79,6 +107,9 @@ class ParameterDescriptorSet<std::index_sequence<Os...>, std::tuple<Ts...>>

// clang < 3.7: index_sequence_for doesn't work here
using IndexList = std::make_index_sequence<sizeof...(Ts)>;

using PrimaryIndexList = typename impl::FilterTupleIndices<IsPrimary, DescriptorType,IndexList>::type;

using FixedIndexList =
typename impl::FilterTupleIndices<IsFixed, DescriptorType,
IndexList>::type;
Expand All @@ -105,6 +136,7 @@ class ParameterDescriptorSet<std::index_sequence<Os...>, std::tuple<Ts...>>
typename impl::FilterTupleIndices<T, DescriptorType, IndexList>::type::size();
}

static constexpr index NumPrimaryParams = PrimaryIndexList::size();
static constexpr index NumFixedParams = FixedIndexList::size();
static constexpr index NumMutableParams = MutableIndexList::size();

Expand All @@ -124,6 +156,14 @@ class ParameterDescriptorSet<std::index_sequence<Os...>, std::tuple<Ts...>>
iterateImpl<Func>(IndexList(), std::forward<Args>(args)...);
}

template<class Func>
void iteratePrimary(Func&& func) const
{
ForThese(mDescriptors,
[](auto& d, auto idx, auto&& f){ f(std::get<0>(d),idx); },
PrimaryIndexList(), std::forward<Func>(func));
}

template <template <size_t N, typename T> class Func>
void iterateFixed() const
{
Expand Down Expand Up @@ -208,6 +248,7 @@ class ParameterSetView<

using ValueRefTuple = typename DescriptorSetType::ValueRefTuple;
using IndexList = typename DescriptorSetType::IndexList;
using PrimaryIndexList = typename DescriptorSetType::PrimaryIndexList;
using FixedIndexList = typename DescriptorSetType::FixedIndexList;
using MutableIndexList = typename DescriptorSetType::MutableIndexList;

Expand Down Expand Up @@ -281,6 +322,24 @@ class ParameterSetView<
std::forward<Args>(args)...);
}


template<typename Func,typename... Args>
std::array<Result, PrimaryIndexList::size()>
setPrimaryParameterValues(bool reportage, Func&& func, Args&&... args)
{
static std::array<Result, PrimaryIndexList::size()> results;
results.fill(Result(Result::Status::kOk));

ForThese(mParams,[this,reportage,n=0u](auto&, auto idx, auto& res, Func&& f, auto&&... As) mutable
{
this->template set<idx()>(f(idx,std::forward<Args>(As)...),reportage ? &res[n++] : nullptr);
}, PrimaryIndexList(), results, std::forward<Func>(func), std::forward<Args>(args)...);


return constrainParameterValuesImpl(std::make_index_sequence<PrimaryIndexList::size()>(),
PrimaryIndexList());
}

template <template <size_t N, typename T> class Func, typename... Args>
std::array<Result, FixedIndexList::size()>
setFixedParameterValues(bool reportage, Args&&... args)
Expand Down
Loading