Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/neuropod/backends/torchscript/torch_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "neuropod/backends/torchscript/type_utils.hh"
#include "neuropod/internal/tensor_types.hh"

#ifndef __APPLE__
#include <c10/cuda/CUDAGuard.h>
#endif

#include <caffe2/core/macros.h>

#include <iostream>
Expand Down Expand Up @@ -291,6 +295,16 @@ std::unique_ptr<NeuropodValueMap> TorchNeuropodBackend::infer_internal(const Neu
{
torch::NoGradGuard guard;

#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?

}
#endif

// Get inference schema
const auto &method = model_->get_method("forward");
const auto &schema = SCHEMA(method);
Expand Down