pytorch/caffe2/onnx/device.cc
Shashank Chaudhry 06d1be2447 [NOOP][clangformat][codemod] Enable CLANGFORMAT for caffe2/caffe2/* (#67624)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/67624

Test Plan: Visual inspection. Sandcastle.

Reviewed By: malfet

Differential Revision: D31986628

fbshipit-source-id: c872bded7325997a2945dbf5d4d052628dcb3659
2021-11-02 22:14:04 -07:00

19 lines
473 B
C++

#include "caffe2/onnx/device.h"
#include <cstdlib>
#include <unordered_map>
namespace caffe2 {
namespace onnx {
static const std::unordered_map<std::string, DeviceType> kDeviceMap = {
{"CPU", DeviceType::CPU},
{"CUDA", DeviceType::CUDA}};
Device::Device(const std::string& spec) {
auto pos = spec.find_first_of(':');
type = kDeviceMap.at(spec.substr(0, pos - 1));
device_id = atoi(spec.substr(pos + 1).c_str());
}
} // namespace onnx
} // namespace caffe2