21#include <torch/torch.h>
33template <
typename T>
inline constexpr torch::Dtype
dtype();
35template <>
inline constexpr torch::Dtype
dtype<bool>() {
return torch::kBool; }
37template <>
inline constexpr torch::Dtype
dtype<char>() {
return torch::kChar; }
43template <>
inline constexpr torch::Dtype
dtype<int>() {
return torch::kInt; }
45 template <>
inline constexpr torch::Dtype
dtype<long>() {
return torch::kLong; }
49template <>
inline constexpr torch::Dtype
dtype<half>() {
return torch::kHalf; }
56 return torch::kDouble;
60 return at::kComplexHalf;
64 return at::kComplexFloat;
68 return at::kComplexDouble;
77 utils::getenv(
"IGANET_DEVICE_COUNT", (torch::cuda::is_available()
78 ? torch::cuda::device_count()
79 : (torch::xpu::is_available() ? torch::xpu::device_count() ? 1)));
89template <
typename real_t>
100 (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"CPU")
102 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"CUDA")
104 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"HIP")
106 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"MPS")
108 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"XLA")
110 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"XPU")
116 explicit Options(torch::TensorOptions &&options)
120 operator torch::TensorOptions()
const {
return options_; }
198template <
typename real_t>
200 obj.pretty_print(
os);
205template <
typename real_t>
The Options class handles the automated determination of dtype from the template argument and the sel...
Definition options.hpp:90
Options< real_t > memory_format(torch::MemoryFormat memory_format) const noexcept
Returns a new Options object with the memory_format property as given.
Definition options.hpp:179
Options()
Default constructor.
Definition options.hpp:93
Options(torch::TensorOptions &&options)
Constructor from torch::TensorOptions.
Definition options.hpp:116
Options< real_t > requires_grad(bool requires_grad) const noexcept
Returns a new Options object with the requires_grad property as given.
Definition options.hpp:166
torch::Device device() const noexcept
Returns the device property.
Definition options.hpp:123
bool requires_grad() const noexcept
Returns the requires_grad property.
Definition options.hpp:135
bool is_sparse() const noexcept
Returns if the layout is sparse.
Definition options.hpp:141
operator torch::TensorOptions() const
Implicit conversion operator.
Definition options.hpp:120
Options< real_t > device(torch::Device device) const noexcept
Returns a new Options object with the device property as given.
Definition options.hpp:144
int32_t device_index() const noexcept
Returns the device_index property.
Definition options.hpp:126
real_t value_type
Data type.
Definition options.hpp:184
torch::Layout layout() const noexcept
Returns the layout property.
Definition options.hpp:132
Options< real_t > device_index(int16_t device_index) const noexcept
Returns a new Options object with the device_index property as given.
Definition options.hpp:150
Options< real_t > pinned_memory(bool pinned_memory) const noexcept
Returns a new Options object with the pinned_memory property as given.
Definition options.hpp:172
virtual void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the Options object.
Definition options.hpp:188
const torch::TensorOptions options_
Tensor options.
Definition options.hpp:194
torch::Dtype dtype() const noexcept
Returns the dtype property.
Definition options.hpp:129
Options< other_t > dtype() const noexcept
Returns a new Options object with the dtype property as given.
Definition options.hpp:155
Options< real_t > layout(torch::Layout layout) const noexcept
Returns a new Options object with the layout property as given.
Definition options.hpp:160
bool pinned_memory() const noexcept
Returns the pinned_memory property.
Definition options.hpp:138
Full qualified name descriptor.
Definition fqn.hpp:26
virtual const std::string & name() const noexcept
Returns the full qualified name of the object.
Definition fqn.hpp:31
Full qualified name utility functions.
Environment utility function.
T getenv(std::string variable, const T &default_value)
Returns the value from an environment variable.
Definition getenv.hpp:24
Definition boundary.hpp:22
constexpr torch::Dtype dtype< char >()
Definition options.hpp:37
constexpr torch::Dtype dtype()
constexpr torch::Dtype dtype< float >()
Definition options.hpp:51
constexpr torch::Dtype dtype< bool >()
Definition options.hpp:35
constexpr torch::Dtype dtype< double >()
Definition options.hpp:55
int guess_device_index()
Definition options.hpp:72
constexpr torch::Dtype dtype< long long >()
Definition options.hpp:47
constexpr bool is_SplineType_v
Alias to the value of is_SplineType.
Definition bspline.hpp:3243
constexpr torch::Dtype dtype< half >()
Definition options.hpp:49
std::ostream & operator<<(std::ostream &os, const Boundary< Spline > &obj)
Print (as string) a Boundary object.
Definition boundary.hpp:1978
struct iganet::@0 Log
Logger.
constexpr torch::Dtype dtype< int >()
Definition options.hpp:43
constexpr torch::Dtype dtype< short >()
Definition options.hpp:39
constexpr torch::Dtype dtype< long >()
Definition options.hpp:45
Definition options.hpp:25