NEML2 2.1.0
Loading...
Searching...
No Matches
types.h
1// Copyright 2024, UChicago Argonne, LLC
2// All Rights Reserved
3// Software Name: NEML2 -- the New Engineering material Model Library, version 2
4// By: Argonne National Laboratory
5// OPEN SOURCE LICENSE (MIT)
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23// THE SOFTWARE.
24
25#pragma once
26
27#include <c10/util/ArrayRef.h>
28#include <c10/util/OptionalArrayRef.h>
29#include <c10/core/TensorOptions.h>
30#include <c10/core/Scalar.h>
31
32// preprocessor macros
33#include "neml2/config.h"
34
35namespace at
36{
37class Tensor;
38} // namespace at
39
40namespace neml2
41{
42using ATensor = at::Tensor;
43using CScalar = c10::Scalar;
44
46// torch also provide unsigned integer types after version 2.2.1, but for backward compatibility
47// reasons we don't include them here
48constexpr auto kInt8 = c10::kChar;
49constexpr auto kInt16 = c10::kShort;
50constexpr auto kInt32 = c10::kInt;
51constexpr auto kInt64 = c10::kLong;
52constexpr auto kFloat16 = c10::kHalf;
53constexpr auto kFloat32 = c10::kFloat;
54constexpr auto kFloat64 = c10::kDouble;
55
56// Device types (mirroring the definition in <c10/core/DeviceType.h>)
57constexpr auto kCPU = c10::DeviceType::CPU;
58constexpr auto kCUDA = c10::DeviceType::CUDA;
59
60template <typename T, unsigned N>
61using SmallVector = c10::SmallVector<T, N>;
62template <typename T>
63using ArrayRef = c10::ArrayRef<T>;
64template <typename T>
65using OptionalArrayRef = c10::OptionalArrayRef<T>;
66using TensorOptions = c10::TensorOptions;
67using Dtype = c10::ScalarType;
68using DeviceIndex = c10::DeviceIndex;
69using Device = c10::Device;
70
71using Size = int64_t;
72using TensorShape = c10::SmallVector<Size, 8>;
73using TensorShapeRef = c10::ArrayRef<Size>;
74
75// Machine precision depending on the dtype
77
87enum class FType : int8_t
88{
89 NONE = 0,
90 INPUT = 1 << 0,
91 OUTPUT = 1 << 1,
92 PARAMETER = 1 << 2,
93 BUFFER = 1 << 3
94};
95std::ostream & operator<<(std::ostream & os, FType f);
96
98constexpr auto eps = std::numeric_limits<double>::epsilon();
99constexpr double sqrt2 = 1.4142135623730951;
100constexpr double invsqrt2 = 0.7071067811865475;
101constexpr double pi = M_PI;
103} // namespace neml2
Definition types.h:36
Definition DiagnosticsInterface.h:31
double machine_precision(Dtype)
c10::Device Device
Definition types.h:69
constexpr auto kInt8
Fixed width dtypes (mirroring the definition in <torch/csrc/api/include/torch/types....
Definition types.h:48
c10::SmallVector< Size, 8 > TensorShape
Definition types.h:72
constexpr auto kFloat64
Definition types.h:54
std::ostream & operator<<(std::ostream &, const EnumSelection &)
constexpr auto kInt16
Definition types.h:49
c10::SmallVector< T, N > SmallVector
Definition types.h:61
constexpr auto eps
Constants.
Definition types.h:98
at::Tensor ATensor
Definition types.h:42
c10::OptionalArrayRef< T > OptionalArrayRef
Definition types.h:65
constexpr auto kInt32
Definition types.h:50
c10::ArrayRef< T > ArrayRef
Definition types.h:63
int64_t Size
Definition types.h:71
constexpr auto kInt64
Definition types.h:51
c10::Scalar CScalar
Definition types.h:43
constexpr double invsqrt2
Definition types.h:100
FType
Role in a function definition.
Definition types.h:88
@ BUFFER
Definition types.h:93
@ OUTPUT
Definition types.h:91
@ INPUT
Definition types.h:90
@ NONE
Definition types.h:89
@ PARAMETER
Definition types.h:92
c10::TensorOptions TensorOptions
Definition types.h:66
constexpr double pi
Definition types.h:101
constexpr double sqrt2
Definition types.h:99
c10::ArrayRef< Size > TensorShapeRef
Definition types.h:73
constexpr auto kCPU
Definition types.h:57
c10::ScalarType Dtype
Definition types.h:67
c10::DeviceIndex DeviceIndex
Definition types.h:68
constexpr auto kFloat16
Definition types.h:52
constexpr auto kFloat32
Definition types.h:53
constexpr auto kCUDA
Definition types.h:58