Skip to content

Commit 1643be5

Browse files
committed
Protonect: Add argument to select GPU
1 parent 44f9e33 commit 1643be5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

examples/Protonect.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/** @file Protonect.cpp Main application file. */
2828

2929
#include <iostream>
30+
#include <cstdlib>
3031
#include <signal.h>
3132

3233
/// [headers]
@@ -112,7 +113,7 @@ int main(int argc, char *argv[])
112113
std::string program_path(argv[0]);
113114
std::cerr << "Version: " << LIBFREENECT2_VERSION << std::endl;
114115
std::cerr << "Environment variables: LOGFILE=<protonect.log>" << std::endl;
115-
std::cerr << "Usage: " << program_path << " [gl | cl | cuda | cpu] [<device serial>]" << std::endl;
116+
std::cerr << "Usage: " << program_path << " [-gpu=<id>] [gl | cl | cuda | cpu] [<device serial>]" << std::endl;
116117
std::cerr << " [-noviewer] [-norgb | -nodepth] [-help] [-version]" << std::endl;
117118
std::cerr << "To pause and unpause: pkill -USR1 Protonect" << std::endl;
118119
size_t executable_name_idx = program_path.rfind("Protonect");
@@ -152,6 +153,7 @@ int main(int argc, char *argv[])
152153
bool viewer_enabled = true;
153154
bool enable_rgb = true;
154155
bool enable_depth = true;
156+
int deviceId = -1;
155157

156158
for(int argI = 1; argI < argc; ++argI)
157159
{
@@ -162,6 +164,15 @@ int main(int argc, char *argv[])
162164
// Just let the initial lines display at the beginning of main
163165
return 0;
164166
}
167+
else if(arg.find("-gpu=") == 0)
168+
{
169+
if (pipeline)
170+
{
171+
std::cerr << "-gpu must be specified before pipeline argument" << std::endl;
172+
return -1;
173+
}
174+
deviceId = atoi(argv[argI] + 5);
175+
}
165176
else if(arg == "cpu")
166177
{
167178
if(!pipeline)
@@ -182,7 +193,7 @@ int main(int argc, char *argv[])
182193
{
183194
#ifdef LIBFREENECT2_WITH_OPENCL_SUPPORT
184195
if(!pipeline)
185-
pipeline = new libfreenect2::OpenCLPacketPipeline();
196+
pipeline = new libfreenect2::OpenCLPacketPipeline(deviceId);
186197
#else
187198
std::cout << "OpenCL pipeline is not supported!" << std::endl;
188199
#endif
@@ -191,7 +202,7 @@ int main(int argc, char *argv[])
191202
{
192203
#ifdef LIBFREENECT2_WITH_CUDA_SUPPORT
193204
if(!pipeline)
194-
pipeline = new libfreenect2::CudaPacketPipeline();
205+
pipeline = new libfreenect2::CudaPacketPipeline(deviceId);
195206
#else
196207
std::cout << "CUDA pipeline is not supported!" << std::endl;
197208
#endif

0 commit comments

Comments
 (0)