NEML2 2.0.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/core/TensorOptions.h>
29#include <c10/core/Scalar.h>
30
31namespace at
32{
33class Tensor;
34} // namespace at
35
36namespace neml2
37{
38using ATensor = at::Tensor;
39using CScalar = c10::Scalar;
40
42// torch also provide unsigned integer types after version 2.2.1, but for backward compatibility
43// reasons we don't include them here
44constexpr auto kInt8 = c10::kChar;
45constexpr auto kInt16 = c10::kShort;
46constexpr auto kInt32 = c10::kInt;
47constexpr auto kInt64 = c10::kLong;
48constexpr auto kFloat16 = c10::kHalf;
49constexpr auto kFloat32 = c10::kFloat;
50constexpr auto kFloat64 = c10::kDouble;
51
52// Device types (mirroring the definition in <c10/core/DeviceType.h>)
53constexpr auto kCPU = c10::DeviceType::CPU;
54constexpr auto kCUDA = c10::DeviceType::CUDA;
55
56template <typename T, unsigned N>
57using SmallVector = c10::SmallVector<T, N>;
58template <typename T>
59using ArrayRef = c10::ArrayRef<T>;
60using TensorOptions = c10::TensorOptions;
61using Dtype = c10::ScalarType;
62using DeviceIndex = c10::DeviceIndex;
63using Device = c10::Device;
64
65using Size = int64_t;
66using TensorShape = c10::SmallVector<Size, 8>;
67using TensorShapeRef = c10::ArrayRef<Size>;
68
69// Machine precision depending on the dtype
71
81enum class FType : int8_t
82{
83 NONE = 0,
84 INPUT = 1 << 0,
85 OUTPUT = 1 << 1,
86 PARAMETER = 1 << 2,
87 BUFFER = 1 << 3
88};
89std::ostream & operator<<(std::ostream & os, FType f);
90
92constexpr auto eps = std::numeric_limits<double>::epsilon();
93constexpr double sqrt2 = 1.4142135623730951;
94constexpr double invsqrt2 = 0.7071067811865475;
96} // namespace neml2
Definition types.h:32
Definition DiagnosticsInterface.cxx:30
c10::Device Device
Definition types.h:63
constexpr auto kInt8
Fixed width dtypes (mirroring the definition in <torch/csrc/api/include/torch/types....
Definition types.h:44
c10::SmallVector< Size, 8 > TensorShape
Definition types.h:66
constexpr auto kFloat64
Definition types.h:50
double machine_precision(Dtype dtype)
Definition types.cxx:34
constexpr auto kInt16
Definition types.h:45
c10::SmallVector< T, N > SmallVector
Definition types.h:57
constexpr auto eps
Constants.
Definition types.h:92
at::Tensor ATensor
Definition types.h:38
constexpr auto kInt32
Definition types.h:46
c10::ArrayRef< T > ArrayRef
Definition types.h:59
int64_t Size
Definition types.h:65
constexpr auto kInt64
Definition types.h:47
c10::Scalar CScalar
Definition types.h:39
constexpr double invsqrt2
Definition types.h:94
FType
Role in a function definition.
Definition types.h:82
c10::TensorOptions TensorOptions
Definition types.h:60
std::ostream & operator<<(std::ostream &os, const EnumSelection &es)
Definition EnumSelection.cxx:31
constexpr double sqrt2
Definition types.h:93
c10::ArrayRef< Size > TensorShapeRef
Definition types.h:67
constexpr auto kCPU
Definition types.h:53
c10::ScalarType Dtype
Definition types.h:61
c10::DeviceIndex DeviceIndex
Definition types.h:62
constexpr auto kFloat16
Definition types.h:48
constexpr auto kFloat32
Definition types.h:49
constexpr auto kCUDA
Definition types.h:54