Skip to content
Snippets Groups Projects
Commit 132edf32 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

WIP to use second GPU

parent b96edc2e
No related branches found
No related tags found
Loading
Pipeline #27208 passed
...@@ -197,7 +197,21 @@ static void run(ftl::Configurable *root) { ...@@ -197,7 +197,21 @@ static void run(ftl::Configurable *root) {
delete net; delete net;
} }
static void threadSetCUDADevice() {
// Ensure all threads have correct cuda device
std::atomic<int> ijobs = 0;
for (int i=0; i<ftl::pool.size(); ++i) {
ftl::pool.push([&ijobs](int id) {
ftl::cuda::setDevice();
++ijobs;
while (ijobs < ftl::pool.size()) std::this_thread::sleep_for(std::chrono::milliseconds(10));
});
}
while (ijobs < ftl::pool.size()) std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
#ifdef HAVE_PYLON #ifdef HAVE_PYLON
Pylon::PylonAutoInitTerm autoInitTerm; Pylon::PylonAutoInitTerm autoInitTerm;
#endif #endif
...@@ -208,6 +222,9 @@ int main(int argc, char **argv) { ...@@ -208,6 +222,9 @@ int main(int argc, char **argv) {
std::cout << "FTL Vision Node " << FTL_VERSION_LONG << std::endl; std::cout << "FTL Vision Node " << FTL_VERSION_LONG << std::endl;
auto root = ftl::configure(argc, argv, "vision_default"); auto root = ftl::configure(argc, argv, "vision_default");
// Use other GPU if available.
//ftl::cuda::setDevice(ftl::cuda::deviceCount()-1);
std::cout << "Loading..." << std::endl; std::cout << "Loading..." << std::endl;
run(root); run(root);
......
...@@ -10,6 +10,8 @@ static int dev_count = 0; ...@@ -10,6 +10,8 @@ static int dev_count = 0;
static std::vector<cudaDeviceProp> properties; static std::vector<cudaDeviceProp> properties;
bool ftl::cuda::initialise() { bool ftl::cuda::initialise() {
if (dev_count > 0) return true;
// Do an initial CUDA check // Do an initial CUDA check
cudaSafeCall(cudaGetDeviceCount(&dev_count)); cudaSafeCall(cudaGetDeviceCount(&dev_count));
CHECK_GE(dev_count, 1) << "No CUDA devices found"; CHECK_GE(dev_count, 1) << "No CUDA devices found";
...@@ -50,6 +52,7 @@ void ftl::cuda::setDevice(int id) { ...@@ -50,6 +52,7 @@ void ftl::cuda::setDevice(int id) {
} }
void ftl::cuda::setDevice() { void ftl::cuda::setDevice() {
LOG(INFO) << "Using CUDA Device " << dev_to_use;
cudaSafeCall(cudaSetDevice(dev_to_use)); cudaSafeCall(cudaSetDevice(dev_to_use));
} }
......
...@@ -120,7 +120,7 @@ void Group::onFrameSet(const ftl::rgbd::VideoCallback &cb) { ...@@ -120,7 +120,7 @@ void Group::onFrameSet(const ftl::rgbd::VideoCallback &cb) {
//ftl::pool.push([this,s,ts](int id) { //ftl::pool.push([this,s,ts](int id) {
_retrieveJob(s); _retrieveJob(s);
LOG(INFO) << "Retrieve latency: " << ftl::timer::get_time()-ts; //LOG(INFO) << "Retrieve latency: " << ftl::timer::get_time()-ts;
--jobs_; --jobs_;
_dispatchJob(s, ts); _dispatchJob(s, ts);
//}); //});
......
...@@ -195,7 +195,10 @@ bool Source::retrieve() { ...@@ -195,7 +195,10 @@ bool Source::retrieve() {
bool Source::dispatch(int64_t ts) { bool Source::dispatch(int64_t ts) {
if (!callback_) return false; if (!callback_) return false;
if (is_dispatching || is_retrieving) return false; if (is_dispatching || is_retrieving) {
LOG(WARNING) << "Previous distance not completed";
return false;
}
is_dispatching = true; is_dispatching = true;
_swap(); _swap();
ftl::pool.push([this,ts](int id) { ftl::pool.push([this,ts](int id) {
......
...@@ -124,6 +124,10 @@ void PylonDevice::_configureCamera(CBaslerUniversalInstantCamera *cam) { ...@@ -124,6 +124,10 @@ void PylonDevice::_configureCamera(CBaslerUniversalInstantCamera *cam) {
bool PylonDevice::grab() { bool PylonDevice::grab() {
if (!isReady()) return false; if (!isReady()) return false;
//int dev;
//cudaGetDevice(&dev);
//LOG(INFO) << "Current cuda device = " << dev;
try { try {
FTL_Profile("Frame Capture", 0.001); FTL_Profile("Frame Capture", 0.001);
if (rcam_) rcam_->WaitForFrameTriggerReady( 30, Pylon::TimeoutHandling_ThrowException); if (rcam_) rcam_->WaitForFrameTriggerReady( 30, Pylon::TimeoutHandling_ThrowException);
...@@ -152,6 +156,12 @@ bool PylonDevice::get(cv::cuda::GpuMat &l_out, cv::cuda::GpuMat &r_out, cv::cuda ...@@ -152,6 +156,12 @@ bool PylonDevice::get(cv::cuda::GpuMat &l_out, cv::cuda::GpuMat &r_out, cv::cuda
Mat &lfull = (!hasHigherRes()) ? l : hres; Mat &lfull = (!hasHigherRes()) ? l : hres;
Mat &rfull = (!hasHigherRes()) ? r : rtmp_; Mat &rfull = (!hasHigherRes()) ? r : rtmp_;
//ftl::cuda::setDevice();
//int dev;
//cudaGetDevice(&dev);
//LOG(INFO) << "Current cuda device = " << dev;
try { try {
FTL_Profile("Frame Retrieve", 0.005); FTL_Profile("Frame Retrieve", 0.005);
std::future<bool> future_b; std::future<bool> future_b;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment