CYNQ  0.3.0
Framework to develop FPGA applications in C++ with the easiness of PYNQ
structures/execution-stream.cpp

This is a sample use case of the execution stream. It should not be used directly by the factory. Instead, it is recommended to use it from the IHardware instance given some possible restrictions. This example is purely a test of the proof-of-concept.

/*
* See LICENSE for more information about licensing
*
* Copyright 2024
* Author: Luis G. Leon-Vega <luis.leon@ieee.org>
*/
#include <atomic> // NOLINT
#include <cynq/cynq.hpp>
#include <iostream>
#include <thread> // NOLINT
volatile std::atomic_int num{0};
cynq::Status dummy_function() {
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "num: " << num.load() << std::endl;
num++;
return cynq::Status{};
}
int main(int, char **) {
auto type = cynq::IExecutionGraph::Type::STREAM;
auto stream = cynq::IExecutionGraph::Create(type, nullptr);
cynq::IExecutionGraph::Function func = dummy_function;
for (uint i = 0; i < 5; ++i) {
stream->Add(func);
}
stream->Sync(2);
std::cout << "Synchronised w.r.t. the third" << std::endl;
stream->Sync();
std::cout << "Synchronised w.r.t. the last" << std::endl;
stream->Add(func);
stream->Sync();
std::cout << "Synchronised w.r.t. the last" << std::endl;
return 0;
}
std::function< Status()> Function
Underlying type for the auxiliar functions.
Definition: execution-graph.hpp:67
static std::shared_ptr< IExecutionGraph > Create(const IExecutionGraph::Type type, const std::shared_ptr< ExecutionGraphParameters > params)
Factory method to create a new implementation.
Definition: execution-graph.cpp:13
Structure to define the return characteristics of each function.
Definition: status.hpp:19