summaryrefslogtreecommitdiff
path: root/src
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
parent2b3a495f31d3f9de57e6bbe2605843e6f1efbe3a (diff)
Avoid temporary file for listing GPUs.
Diffstat (limited to 'src')
-rw-r--r--src/lib/grok/util.cc34
-rw-r--r--src/lib/grok/util.h2
-rw-r--r--src/wx/grok/gpu_config_panel.h3
3 files changed, 19 insertions, 20 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;
}
diff --git a/src/lib/grok/util.h b/src/lib/grok/util.h
index 069a6cc08..9996fa0e9 100644
--- a/src/lib/grok/util.h
+++ b/src/lib/grok/util.h
@@ -24,4 +24,4 @@
#include <vector>
-extern std::vector<std::string> get_gpu_names(boost::filesystem::path binary, boost::filesystem::path filename);
+extern std::vector<std::string> get_gpu_names(boost::filesystem::path binary);
diff --git a/src/wx/grok/gpu_config_panel.h b/src/wx/grok/gpu_config_panel.h
index 6b8a4f150..b61bccbde 100644
--- a/src/wx/grok/gpu_config_panel.h
+++ b/src/wx/grok/gpu_config_panel.h
@@ -45,9 +45,8 @@ public:
{
auto grok = Config::instance()->grok();
auto lister_binary = grok.binary_location / "gpu_lister";
- auto lister_file = grok.binary_location / "gpus.txt";
if (boost::filesystem::exists(lister_binary)) {
- auto gpu_names = get_gpu_names(lister_binary, lister_file);
+ auto gpu_names = get_gpu_names(lister_binary);
_combo_box->Clear();
for (auto const& name: gpu_names) {