connectionManager.hpp 1.3 KB

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