SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
smv_accel_pool.cpp
1 #include <string>
2 
4 #include "smaug/operators/smv/smv_accel_pool.h"
5 #include "smaug/utility/debug_stream.h"
6 
7 namespace smaug {
8 
9 SmvAcceleratorPool::SmvAcceleratorPool(int _size)
10  : size(_size), finishFlags(_size) {}
11 
12 void SmvAcceleratorPool::addFinishFlag(
13  int accelIdx, std::unique_ptr<volatile int> finishFlag) {
14  if (runningInSimulation) {
15  finishFlags[accelIdx].push_back(std::move(finishFlag));
16  }
17 }
18 
19 void SmvAcceleratorPool::join(int accelIdx) {
20  if (finishFlags[accelIdx].empty())
21  return;
22 
23  while (!finishFlags[accelIdx].empty()) {
24  std::unique_ptr<volatile int> finishFlag =
25  std::move(finishFlags[accelIdx].front());
26  waitForAccelerator(finishFlag.get());
27  finishFlags[accelIdx].pop_front();
28  }
29  dout(1) << "Accelerator " << accelIdx << " finished.\n";
30 }
31 
32 void SmvAcceleratorPool::joinAll() {
33  dout(1) << "Waiting for all accelerators to finish.\n";
34  for (int i = 0; i < size; i++)
35  join(i);
36  dout(1) << "All accelerators finished.\n";
37 }
38 
39 int SmvAcceleratorPool::getNextAvailableAccelerator(int currAccelIdx) {
40  // Round-robin policy.
41  int pickedAccel = currAccelIdx + 1;
42  if (pickedAccel == size)
43  pickedAccel = 0;
44  // If the picked accelerator has not finished, wait until it returns.
45  join(pickedAccel);
46  if (size > 1)
47  dout(1) << "Switched to accelerator " << pickedAccel << ".\n";
48  return pickedAccel;
49 }
50 
51 } // namespace smaug
smaug::dout
const DebugStream & dout(int debugLevel)
Returns a DebugStream instance for the given debug level.
Definition: debug_stream.cpp:16
smaug::runningInSimulation
bool runningInSimulation
This is true if the user chooses to run the network in gem5 simulation.
Definition: globals.cpp:4
smaug
The smaug namespace is the parent namespace of all C++ code in SMAUG.
Definition: backend.cpp:38
common.h
Utilities for writing and invoking Aladdin kernels from Operators.