connectionManager.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef myCONNMANAGE_H
  2. #define myCONNMANAGE_H
  3. #include <iostream>
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include <thread>
  7. #include <future>
  8. #include <mutex>
  9. #include <condition_variable>
  10. #include "commFPGA.hpp"
  11. #include "worker.hpp"
  12. /*
  13. worker thread:
  14. takes jobs
  15. assigns free fpga
  16. queue response
  17. cb on overwrite + delete old resp
  18. fills send buffer
  19. retransmit job
  20. send thread:
  21. send 1 packet per fpga if available
  22. recv thread:
  23. recv data into response
  24. cb on success
  25. */
  26. class ConnectionManager {
  27. public:
  28. ConnectionManager();
  29. ~ConnectionManager();
  30. void startFromTensorflow();
  31. void addFPGA(const char* ip, const uint port, bool bindSelf=false);
  32. void start();
  33. Worker* createWorker(Module mod, size_t numberOfJobs = 1);
  34. Worker* getWorker(size_t i) const {return &(*workers.at(i));}
  35. size_t getWorkerCount() const {return workers.size();}
  36. void setSendDelay(microseconds us) {sendDelay = us;}
  37. bool isRunning() const {return running;}
  38. private:
  39. std::vector<std::unique_ptr<commFPGA>> fpgas;
  40. std::vector<std::unique_ptr<Worker>> workers;
  41. void sendThread();
  42. std::future<void> sendResult;
  43. bool running = false;
  44. microseconds sendDelay = microseconds(50);
  45. };
  46. #endif