Skip to content

Conversation

@VivekPanyam
Copy link
Collaborator

This PR ensures that we're running on the correct device even if something else calls cudaSetDevice before running inference.

This fixes a class of issues where another piece of code changes the current device for the current thread. For example, this can happen if TF and Torch run together on the same threadpool. TF will call cudaSetDevice and cause torch to break if it runs on the same thread in the future.

This can cause some obscure cuDNN errors and generally hard-to-debug issues.

@VivekPanyam VivekPanyam requested a review from selitvin April 23, 2020 02:00

#ifndef __APPLE__
// Make sure we're running on the correct device
std::unique_ptr<at::cuda::CUDAGuard> device_guard;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <memory>

const auto model_device = get_torch_device(DeviceType::GPU);
if (model_device.is_cuda())
{
device_guard = stdx::make_unique<at::cuda::CUDAGuard>(model_device);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can use std:: here not stdx:: because Neuropod became C++14 recently, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants