summaryrefslogtreecommitdiff
path: root/src/lib/grok/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-03-03 23:16:09 +0100
committerCarl Hetherington <cth@carlh.net>2025-03-08 00:12:07 +0100
commiteef48c36012180d20001def874864607e15968b8 (patch)
tree59c45a1579dc5dbf2ddd03f7a363df2f5e30647f /src/lib/grok/util.cc
parent2b3a495f31d3f9de57e6bbe2605843e6f1efbe3a (diff)
Avoid temporary file for listing GPUs.
Diffstat (limited to 'src/lib/grok/util.cc')
-rw-r--r--src/lib/grok/util.cc34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/lib/grok/util.cc b/src/lib/grok/util.cc
index e9b535df8..8a6d2c4f9 100644
--- a/src/lib/grok/util.cc
+++ b/src/lib/grok/util.cc
@@ -20,6 +20,8 @@
#include "util.h"
+#include <boost/process.hpp>
+#include <future>
using std::string;
@@ -27,24 +29,22 @@ using std::vector;
vector<string>
-get_gpu_names(boost::filesystem::path binary, boost::filesystem::path filename)
+get_gpu_names(boost::filesystem::path binary)
{
- // Execute the GPU listing program and redirect its output to a file
- if (std::system((binary.string() + " > " + filename.string()).c_str()) < 0) {
- return {};
- }
-
- std::vector<std::string> gpu_names;
- std::ifstream file(filename.c_str());
- if (file.is_open())
- {
- std::string line;
- while (std::getline(file, line))
- gpu_names.push_back(line);
- file.close();
- }
-
- return gpu_names;
+ namespace bp = boost::process;
+
+ bp::ipstream stream;
+ bp::child child(binary, bp::std_out > stream);
+
+ string line;
+ vector<string> gpu_names;
+ while (child.running() && std::getline(stream, line) && !line.empty()) {
+ gpu_names.push_back(line);
+ }
+
+ child.wait();
+
+ return gpu_names;
}