|
|
#pragma once |
|
|
|
|
|
#include <ATen/core/IListRef.h> |
|
|
#include <ATen/core/Tensor.h> |
|
|
#include <c10/core/DeviceGuard.h> |
|
|
#include <c10/core/ScalarType.h> |
|
|
|
|
|
namespace at { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline c10::optional<Device> device_of(const Tensor& t) { |
|
|
if (t.defined()) { |
|
|
return c10::make_optional(t.device()); |
|
|
} else { |
|
|
return c10::nullopt; |
|
|
} |
|
|
} |
|
|
|
|
|
inline c10::optional<Device> device_of(const c10::optional<Tensor>& t) { |
|
|
return t.has_value() ? device_of(t.value()) : nullopt; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline c10::optional<Device> device_of(ITensorListRef t) { |
|
|
if (!t.empty()) { |
|
|
return device_of(t.front()); |
|
|
} else { |
|
|
return c10::nullopt; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|