28 std::is_same_v<T, bool> || std::is_same_v<T, char> ||
29 std::is_same_v<T, short> || std::is_same_v<T, int> ||
30 std::is_same_v<T, long> || std::is_same_v<T, long long> ||
31 std::is_same_v<T, half> || std::is_same_v<T, float> ||
32 std::is_same_v<T, double> || std::is_same_v<T, std::complex<half>> ||
33 std::is_same_v<T, std::complex<float>> ||
34 std::is_same_v<T, std::complex<double>>;
44inline constexpr torch::Dtype
dtype();
46template <>
inline constexpr torch::Dtype
dtype<bool>() {
return torch::kBool; }
48template <>
inline constexpr torch::Dtype
dtype<char>() {
return torch::kChar; }
54template <>
inline constexpr torch::Dtype
dtype<int>() {
return torch::kInt; }
56template <>
inline constexpr torch::Dtype
dtype<long>() {
return torch::kLong; }
62template <>
inline constexpr torch::Dtype
dtype<half>() {
return torch::kHalf; }
69 return torch::kDouble;
72template <>
inline constexpr torch::Dtype dtype<std::complex<half>>() {
73 return at::kComplexHalf;
76template <>
inline constexpr torch::Dtype dtype<std::complex<float>>() {
77 return at::kComplexFloat;
80template <>
inline constexpr torch::Dtype dtype<std::complex<double>>() {
81 return at::kComplexDouble;
88 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
90 utils::getenv(
"IGANET_DEVICE_COUNT", (torch::cuda::is_available()
91 ? torch::cuda::device_count()
92 : (torch::xpu::is_available() ? torch::xpu::device_count() ? 1)));
102template <
typename real_t>
103 requires DType<real_t>
114 (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"CPU")
116 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"CUDA")
118 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"HIP")
120 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"MPS")
122 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"XLA")
124 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"XPU")
126 : (
torch::cuda::is_available()
133 explicit Options(torch::TensorOptions &&options)
141 operator torch::TensorOptions()
const {
return options_; }
152 static inline torch::Dtype
dtype() noexcept {
153 return ::iganet::dtype<real_t>();
226template <
typename real_t>
233template <
typename real_t>
The Options class handles the automated determination of dtype from the template argument and the sel...
Definition options.hpp:104
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:208
Options()
Default constructor.
Definition options.hpp:107
static torch::Dtype dtype() noexcept
Returns the dtype property.
Definition options.hpp:152
Options(torch::TensorOptions &&options)
Constructor from torch::TensorOptions.
Definition options.hpp:133
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:195
torch::Device device() const noexcept
Returns the device property.
Definition options.hpp:144
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the Options object.
Definition options.hpp:216
bool requires_grad() const noexcept
Returns the requires_grad property.
Definition options.hpp:160
bool is_sparse() const noexcept
Returns if the layout is sparse.
Definition options.hpp:170
operator torch::TensorOptions() const
Implicit conversion operator.
Definition options.hpp:141
Options< real_t > device(torch::Device device) const noexcept
Returns a new Options object with the device property as given.
Definition options.hpp:173
int32_t device_index() const noexcept
Returns the device_index property.
Definition options.hpp:147
real_t value_type
Data type.
Definition options.hpp:213
torch::Layout layout() const noexcept
Returns the layout property.
Definition options.hpp:157
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:179
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:201
const torch::TensorOptions options_
Tensor options.
Definition options.hpp:222
Options< other_t > dtype() const noexcept
Returns a new Options object with the dtype property as given.
Definition options.hpp:184
Options< real_t > layout(torch::Layout layout) const noexcept
Returns a new Options object with the layout property as given.
Definition options.hpp:189
bool pinned_memory() const noexcept
Returns the pinned_memory property.
Definition options.hpp:165
Full qualified name descriptor.
Definition fqn.hpp:22
virtual const std::string & name() const noexcept
Returns the full qualified name of the object.
Definition fqn.hpp:28
Concept to identify template parameters that are acceptable as DTypes.
Definition options.hpp:27
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
constexpr torch::Dtype dtype< char >()
Definition options.hpp:48
constexpr torch::Dtype dtype< float >()
Definition options.hpp:64
constexpr torch::Dtype dtype< bool >()
Definition options.hpp:46
constexpr torch::Dtype dtype< double >()
Definition options.hpp:68
int guess_device_index()
Definition options.hpp:85
constexpr torch::Dtype dtype< long long >()
Definition options.hpp:58
std::ostream & operator<<(std::ostream &os, const MemoryDebugger< id > &obj)
Print (as string) a memory debugger object.
Definition memory.hpp:125
constexpr torch::Dtype dtype< half >()
Definition options.hpp:62
constexpr torch::Dtype dtype< int >()
Definition options.hpp:54
constexpr torch::Dtype dtype()
constexpr torch::Dtype dtype< short >()
Definition options.hpp:50
constexpr torch::Dtype dtype< long >()
Definition options.hpp:56
Definition options.hpp:23
Definition optimizer.hpp:61