Skip to content

Commit

Permalink
add garbage collection for AsyncOps
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-ming authored and whchung committed Apr 18, 2016
1 parent e397525 commit def3939
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/hsa/mcwamp_hsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <thread>
#include <utility>
#include <vector>
#include <algorithm>

#include <hsa.h>
#include <hsa_ext_finalize.h>
Expand Down Expand Up @@ -66,6 +67,10 @@
// default set as 0 (NOT print out kernel dispatch time)
#define KALMAR_DISPATCH_TIME_PRINTOUT (0)

// threshold to clean up finished kernel in HSAQueue.asyncOps
// default set as 1024
#define ASYNCOPS_VECTOR_GC_SIZE (1024)



static const char* getHSAErrorString(hsa_status_t s) {
Expand Down Expand Up @@ -926,6 +931,12 @@ class HSAQueue final : public KalmarQueue
asyncOps[i] = nullptr;
}
}

// GC for finished kernels
if (asyncOps.size() > ASYNCOPS_VECTOR_GC_SIZE) {
asyncOps.erase(std::remove(asyncOps.begin(), asyncOps.end(), nullptr),
asyncOps.end());
}
}
};

Expand Down

0 comments on commit def3939

Please sign in to comment.