31 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
33 utils::getenv(
"IGANET_DEVICE_COUNT", (torch::cuda::is_available()
34 ? torch::cuda::device_count()
35 : (torch::xpu::is_available() ? torch::xpu::device_count() ? 1)));
45template <
typename real_t>
46 requires DType<real_t>
57 (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"CPU")
59 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"CUDA")
61 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"HIP")
63 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"MPS")
65 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"XLA")
67 : (utils::getenv(
"IGANET_DEVICE",
std::string{}) ==
"XPU")
69 : (
torch::cuda::is_available()
77 explicit Options(torch::TensorOptions &&options)
86 operator torch::TensorOptions()
const {
return options_; }
100 static inline torch::Dtype
dtype() noexcept {
101 return ::iganet::dtype_v<real_t>;
197template <
typename real_t>
205template <
typename real_t>
The Options class handles the automated determination of dtype from the template argument and the sel...
Definition options.hpp:47
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:174
Options()
Default constructor.
Definition options.hpp:50
static torch::Dtype dtype() noexcept
Returns the dtype property.
Definition options.hpp:100
Options(torch::TensorOptions &&options)
Constructor from torch::TensorOptions.
Definition options.hpp:77
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:157
torch::Device device() const noexcept
Returns the device property.
Definition options.hpp:90
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the Options object.
Definition options.hpp:183
bool requires_grad() const noexcept
Returns the requires_grad property.
Definition options.hpp:110
bool is_sparse() const noexcept
Returns whether the layout is sparse.
Definition options.hpp:122
operator torch::TensorOptions() const
Implicit conversion operator.
Definition options.hpp:86
Options< real_t > device(torch::Device device) const noexcept
Returns a new Options object with the device property as given.
Definition options.hpp:127
int32_t device_index() const noexcept
Returns the device_index property.
Definition options.hpp:94
real_t value_type
Data type.
Definition options.hpp:179
torch::Layout layout() const noexcept
Returns the layout property.
Definition options.hpp:106
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:135
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:165
const torch::TensorOptions options_
Tensor options.
Definition options.hpp:189
Options< other_t > dtype() const noexcept
Returns a new Options object with the dtype property as given.
Definition options.hpp:142
Options< real_t > layout(torch::Layout layout) const noexcept
Returns a new Options object with the layout property as given.
Definition options.hpp:149
bool pinned_memory() const noexcept
Returns the pinned_memory property.
Definition options.hpp:116
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
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:28
int guess_device_index()
Guesses the accelerator device index for the current process.
Definition options.hpp:28
std::ostream & operator<<(std::ostream &os, const MemoryDebugger< id > &obj)
Prints a memory debugger object.
Definition memory.hpp:145
constexpr torch::Dtype dtype_v
Determines the LibTorch dtype from a template parameter.
Definition dtype.hpp:75
Definition optimizer.hpp:61