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

Core: rework Tag handling #340

Merged
merged 2 commits into from
Jun 14, 2024
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
2 changes: 0 additions & 2 deletions blocks/basic/include/gnuradio-4.0/basic/FunctionGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ clockSrc.tags = { Tag(0, createConstPropertyMap(5.f)),

void
settingsChanged(const property_map & /*old_settings*/, const property_map &new_settings) {
fmt::println("settingsChanged:\n");
if (new_settings.contains(gr::tag::TRIGGER_META_INFO.shortKey())) {
fmt::println("settingsChanged:\nnew: {}\n", new_settings);
const auto funcSettings = bestMatch(trigger_meta_info);
if (funcSettings.has_value()) {
applyFunctionSettings(funcSettings.value());
Expand Down
4 changes: 2 additions & 2 deletions blocks/basic/test/qa_DataSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct fmt::formatter<gr::Tag> {

template<typename FormatContext>
constexpr auto format(const gr::Tag& tag, FormatContext& ctx) const {
return fmt::format_to(ctx.out(), "{}", tag.index);
return fmt::format_to(ctx.out(), "{} -> {}", tag.index, tag.map);
}
};

Expand Down Expand Up @@ -344,7 +344,7 @@ const boost::ut::suite DataSinkTests = [] {
expect(eq(samplesSeen2, static_cast<std::size_t>(kSamples)));
const auto& [metadataTags, nonMetadataTags] = extractMetadataTags(receivedTags);
expect(eq(nonMetadataTags.size(), srcTags.size()));
expect(eq(indexesMatch(nonMetadataTags, srcTags), true)) << fmt::format("{} != {}", formatList(receivedTags), formatList(srcTags));
expect(indexesMatch(nonMetadataTags, srcTags)) << fmt::format("{} != {}", formatList(receivedTags), formatList(srcTags));
const auto metadata = latestMetadata(metadataTags);
expect(eq(metadata.signal_name.value_or("<unset>"), "test source"s));
expect(eq(metadata.signal_unit.value_or("<unset>"), "test unit"s));
Expand Down
18 changes: 16 additions & 2 deletions blocks/basic/test/qa_sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const boost::ut::suite TagTests = [] {
expect(eq(static_cast<gr::Size_t>(sink2.n_samples_produced), n_samples)) << fmt::format("sink2 did not consume enough input samples ({} vs. {})", sink2.n_samples_produced, n_samples);

// TODO: last decimator/interpolator + stride addition seems to break the limiting the input samples to the min of available vs. n_samples-until next tags
// expect(equal_tag_lists(src.tags, sink1.tags)) << "sink1 (USE_PROCESS_ONE) did not receive the required tags";
// expect(equal_tag_lists(src.tags, sink2.tags)) << "sink2 (USE_PROCESS_BULK) did not receive the required tags";
// expect(equal_tag_lists(src.tags, sink1._tags)) << "sink1 (USE_PROCESS_ONE) did not receive the required tags";
// expect(equal_tag_lists(src.tags, sink2._tags)) << "sink2 (USE_PROCESS_BULK) did not receive the required tags";
if (verbose) {
fmt::println("finished ClockSource test w/ {}", useIoThreadPool ? "Graph/Block<T>-provided thread" : "user-provided thread");
}
Expand Down Expand Up @@ -185,6 +185,13 @@ const boost::ut::suite TagTests = [] {
scheduler::Simple sched{std::move(testGraph)};
expect(sched.runAndWait().has_value());
expect(eq(N, static_cast<std::uint32_t>(sink.samples.size()))) << "Number of samples does not match";
expect(eq(sink._tags.size(), clockSrc.tags.size())) << [&]() {
std::string ret = fmt::format("DataSet nTags: {}\n", sink._tags.size());
for (const auto &tag : sink._tags) {
ret += fmt::format("tag.index: {} .map: {}\n", tag.index, tag.map);
}
return ret;
}();

std::vector<double> xValues(N);
std::vector<double> yValues(sink.samples.begin(), sink.samples.end());
Expand Down Expand Up @@ -260,6 +267,13 @@ const boost::ut::suite TagTests = [] {
scheduler::Simple sched{std::move(testGraph)};
expect(sched.runAndWait().has_value());
expect(eq(N, static_cast<std::uint32_t>(sink.samples.size()))) << "Number of samples does not match";
expect(eq(sink._tags.size(), 9UZ)) << [&]() {
std::string ret = fmt::format("DataSet nTags: {}\n", sink._tags.size());
for (const auto &tag : sink._tags) {
ret += fmt::format("tag.index: {} .map: {}\n", tag.index, tag.map);
}
return ret;
}();

std::vector<double> xValues(N);
std::vector<double> yValues(sink.samples.begin(), sink.samples.end());
Expand Down
137 changes: 91 additions & 46 deletions core/include/gnuradio-4.0/Block.hpp

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions core/include/gnuradio-4.0/BlockTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ struct DummyConsumableSpan {
};
static_assert(ConsumableSpan<DummyConsumableSpan<int>>);

template<typename T>
struct DummyConsumablePortSpan: public DummyConsumableSpan<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tags etc should be absorbed in the concept ConsumableSpan etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand.
There are 2 concepts ConsumableSpan(no tag handling) and ConsumablePortSpan(the former + added tag handling). DummyConsumableSpan and DummyConsumablePortSpan are mock implementations of the respective concepts needed by the machinery of Block::prepareStreams.

DummyConsumableSpan<gr::Tag> tags{};
};
static_assert(ConsumablePortSpan<DummyConsumablePortSpan<int>>);

template<typename T>
struct DummyPublishableSpan {
using value_type = typename std::remove_cv_t<T>;
Expand Down Expand Up @@ -379,7 +385,7 @@ port_to_processBulk_argument_helper() {
if constexpr (isVectorOfSpansReturned) {
return static_cast<std::span<std::span<const typename Port::value_type::value_type>> *>(nullptr);
} else {
return static_cast<std::span<DummyConsumableSpan<typename Port::value_type::value_type>> *>(nullptr);
return static_cast<std::span<DummyConsumablePortSpan<typename Port::value_type::value_type>> *>(nullptr);
}
} else if constexpr (Port::value_type::kIsOutput) {
if constexpr (isVectorOfSpansReturned) {
Expand All @@ -391,7 +397,7 @@ port_to_processBulk_argument_helper() {

} else { // single port
if constexpr (Port::kIsInput) {
return static_cast<DummyConsumableSpan<typename Port::value_type> *>(nullptr);
return static_cast<DummyConsumablePortSpan<typename Port::value_type> *>(nullptr);
} else if constexpr (Port::kIsOutput) {
return static_cast<DummyPublishableSpan<typename Port::value_type> *>(nullptr);
}
Expand Down Expand Up @@ -440,7 +446,7 @@ concept can_processBulk = can_processBulk_helper<TBlock, detail::port_to_process
template<typename TDerived, std::size_t I>
concept processBulk_requires_ith_output_as_span
= can_processBulk<TDerived> && (I < traits::block::stream_output_port_types<TDerived>::size) && (I >= 0)
&& requires(TDerived &d, typename meta::transform_types<detail::DummyConsumableSpan, traits::block::stream_input_port_types<TDerived>>::template apply<std::tuple> inputs,
&& requires(TDerived &d, typename meta::transform_types<detail::DummyConsumablePortSpan, traits::block::stream_input_port_types<TDerived>>::template apply<std::tuple> inputs,
typename meta::transform_conditional<decltype([](auto j) { return j == I; }), detail::dynamic_span, detail::DummyPublishableSpan,
traits::block::stream_output_port_types<TDerived>>::template apply<std::tuple>
outputs,
Expand Down
Loading
Loading