Limit the number of HSA signals that are active (#140)

* Limit the number of HSA signals that are active

There is a hard limit currently to the number of
signals that HSA allows to be created (before weird stuff
happens such as hangs or straight up crashes in HSA). While
there is some work going on to fix this in HSA/AQL. Lets limit the
number we create.

Increased the counter colleciton example to 200K launches, which
with this change no longer hangs/crashes randomly in HSA.

* source formatting (clang-format v11) (#142)

Co-authored-by: bwelton <bwelton@users.noreply.github.com>

* Up timout

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: bwelton <bwelton@users.noreply.github.com>

[ROCm/rocprofiler-sdk commit: de685246a7]
This commit is contained in:
Benjamin Welton
2023-10-19 11:18:42 -07:00
zatwierdzone przez GitHub
rodzic 162c77d349
commit d05031db89
4 zmienionych plików z 75 dodań i 2 usunięć
@@ -25,7 +25,9 @@
#include <sys/syscall.h>
#include <unistd.h>
#include <chrono>
#include <condition_variable>
#include <cstdint>
#include <mutex>
#include <string>
#include <vector>
@@ -97,5 +99,57 @@ private:
L _destroy_func;
};
/**
* Limits the number of active items to those set in capacity.
* If capacity is reached, will block until another caller
* removes active capacity.
*/
class active_capacity_gate
{
public:
active_capacity_gate(size_t capacity)
: _capacity(capacity)
{}
void add_active(size_t size)
{
if(size >= _capacity)
{
throw std::runtime_error("Size exceeds gate capacity");
}
std::unique_lock lock(_m);
if(_count + size < _capacity)
{
_count += size;
return;
}
_waiters++;
_cv.wait(lock, [&]() { return _count + size < _capacity; });
_waiters--;
_count += size;
}
void remove_active(size_t size)
{
std::unique_lock lock(_m);
if(_count > size)
_count -= size;
else
_count = 0;
if(_waiters > 0)
{
_cv.notify_all();
}
}
private:
size_t _count{0};
size_t _capacity{0};
size_t _waiters{0};
std::mutex _m;
std::condition_variable _cv;
};
} // namespace common
} // namespace rocprofiler