mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-23 21:39:10 -04:00
enabling automatic device cleanup for bad applications not releasing the device on exit
This commit is contained in:
parent
c2b3aaa7d1
commit
4976a8c4f2
3 changed files with 98 additions and 1 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
|
||||
#if defined(USE_FPGA) || defined(USE_ASE)
|
||||
#include <opae/fpga.h>
|
||||
|
@ -78,6 +79,34 @@ inline bool is_aligned(size_t addr, size_t alignment) {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class AutoDeviceCleanup {
|
||||
private:
|
||||
std::list<vx_device_h> devices_;
|
||||
|
||||
public:
|
||||
AutoDeviceCleanup() {}
|
||||
|
||||
~AutoDeviceCleanup() {
|
||||
for (auto it = devices_.begin(), it_end = devices_.end(); it != it_end;) {
|
||||
auto device = *it;
|
||||
it = devices_.erase(it);
|
||||
vx_dev_close(device);
|
||||
}
|
||||
}
|
||||
|
||||
void add_device(vx_device_h device) {
|
||||
devices_.push_back(device);
|
||||
}
|
||||
|
||||
void remove_device(vx_device_h device) {
|
||||
devices_.remove(device);
|
||||
}
|
||||
};
|
||||
|
||||
AutoDeviceCleanup gAutoDeviceCleanup;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern int vx_dev_caps(vx_device_h hdevice, unsigned caps_id, unsigned *value) {
|
||||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
@ -223,6 +252,8 @@ extern int vx_dev_open(vx_device_h* hdevice) {
|
|||
|
||||
*hdevice = device;
|
||||
|
||||
gAutoDeviceCleanup.add_device(device);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -230,6 +261,8 @@ extern int vx_dev_close(vx_device_h hdevice) {
|
|||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
||||
gAutoDeviceCleanup.remove_device(hdevice);
|
||||
|
||||
vx_device_t *device = ((vx_device_t*)hdevice);
|
||||
|
||||
#ifdef SCOPE
|
||||
|
|
|
@ -154,6 +154,34 @@ private:
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class AutoDeviceCleanup {
|
||||
private:
|
||||
std::list<vx_device_h> devices_;
|
||||
|
||||
public:
|
||||
AutoDeviceCleanup() {}
|
||||
|
||||
~AutoDeviceCleanup() {
|
||||
for (auto it = devices_.begin(), it_end = devices_.end(); it != it_end;) {
|
||||
auto device = *it;
|
||||
it = devices_.erase(it);
|
||||
vx_dev_close(device);
|
||||
}
|
||||
}
|
||||
|
||||
void add_device(vx_device_h device) {
|
||||
devices_.push_back(device);
|
||||
}
|
||||
|
||||
void remove_device(vx_device_h device) {
|
||||
devices_.remove(device);
|
||||
}
|
||||
};
|
||||
|
||||
AutoDeviceCleanup gAutoDeviceCleanup;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern int vx_dev_caps(vx_device_h hdevice, unsigned caps_id, unsigned *value) {
|
||||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
@ -198,6 +226,8 @@ extern int vx_dev_open(vx_device_h* hdevice) {
|
|||
|
||||
*hdevice = new vx_device();
|
||||
|
||||
gAutoDeviceCleanup.add_device(*hdevice);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -205,6 +235,8 @@ extern int vx_dev_close(vx_device_h hdevice) {
|
|||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
||||
gAutoDeviceCleanup.remove_device(hdevice);
|
||||
|
||||
vx_device *device = ((vx_device*)hdevice);
|
||||
|
||||
#ifdef DUMP_PERF_STATS
|
||||
|
|
|
@ -223,11 +223,41 @@ private:
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class AutoDeviceCleanup {
|
||||
private:
|
||||
std::list<vx_device_h> devices_;
|
||||
|
||||
public:
|
||||
AutoDeviceCleanup() {}
|
||||
|
||||
~AutoDeviceCleanup() {
|
||||
for (auto it = devices_.begin(), it_end = devices_.end(); it != it_end;) {
|
||||
auto device = *it;
|
||||
it = devices_.erase(it);
|
||||
vx_dev_close(device);
|
||||
}
|
||||
}
|
||||
|
||||
void add_device(vx_device_h device) {
|
||||
devices_.push_back(device);
|
||||
}
|
||||
|
||||
void remove_device(vx_device_h device) {
|
||||
devices_.remove(device);
|
||||
}
|
||||
};
|
||||
|
||||
AutoDeviceCleanup gAutoDeviceCleanup;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern int vx_dev_open(vx_device_h* hdevice) {
|
||||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
||||
*hdevice = new vx_device();
|
||||
*hdevice = new vx_device();
|
||||
|
||||
gAutoDeviceCleanup.add_device(*hdevice);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -236,6 +266,8 @@ extern int vx_dev_close(vx_device_h hdevice) {
|
|||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
||||
gAutoDeviceCleanup.remove_device(hdevice);
|
||||
|
||||
vx_device *device = ((vx_device*)hdevice);
|
||||
|
||||
#ifdef DUMP_PERF_STATS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue