CUTLASS: numeric_types.h Source File

| CUTLASS CUDA Templates for Linear Algebra Subroutines and Solvers

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

numeric_types.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright notice, this list of
7 * conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright notice, this list of
9 * conditions and the following disclaimer in the documentation and/or other materials
10 * provided with the distribution.
11 * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12 * to endorse or promote products derived from this software without specific prior written
13 * permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 **************************************************************************************************/
29 #pragma once
30
31 #include <assert.h>
32
33 #include "cutlass/cutlass.h"
34
35 namespace cutlass {
36
37
39
41 template <typename T>
42 struct sizeof_bits {
43 static int const value = sizeof(T) * 8;
44 };
45
47
48 //
49 // Definitions for 1-bit binary and 4-bit integer types
50 //
51
53 using bin1_t = bool;
54
56 template <>
57 struct sizeof_bits<bin1_t> {
58 static int const value = 1;
59 };
60
62
63 } // namespace cutlass
64
66
67 #include "cutlass/integer_subbyte.h"
68 #include "cutlass/half.h"
69
71
72 namespace cutlass {
73
75 template <int Bits, bool Signed = true>
76 struct IntegerType;
77
78 template <>
79 struct IntegerType<1, true> {
80 using Type = bin1_t;
81 };
82
83 template <>
84 struct IntegerType<1, false> {
85 using Type = bin1_t;
86 };
87
88 template <>
89 struct IntegerType<4, true> {
90 using Type = int4b_t;
91 };
92
93 template <>
94 struct IntegerType<4, false> {
95 using Type = uint4b_t;
96 };
97
98 template <>
99 struct IntegerType<8, true> {
100 using Type = int8_t;
101 };
102
103 template <>
104 struct IntegerType<8, false> {
105 using Type = uint8_t;
106 };
107
108 template <>
109 struct IntegerType<16, true> {
110 using Type = int16_t;
111 };
112
113 template <>
114 struct IntegerType<16, false> {
115 using Type = uint16_t;
116 };
117
118 template <>
119 struct IntegerType<32, true> {
120 using Type = int32_t;
121 };
122
123 template <>
124 struct IntegerType<32, false> {
125 using Type = uint32_t;
126 };
127
128 template <>
129 struct IntegerType<64, true> {
130 using Type = int64_t;
131 };
132
133 template <>
134 struct IntegerType<64, false> {
135 using Type = uint64_t;
136 };
137
138 //
139 // Floating point types
140 //
141
143 template <int Exp, int Mantissa>
144 struct FloatType;
145
146 template <>
147 struct FloatType<11, 52> {
148 using Type = double;
149 };
150
151 template <>
152 struct FloatType<8, 23> {
153 using Type = float;
154 };
155
156
157 template <>
158 struct FloatType<5, 10> {
159 using Type = half_t;
160 };
161
163
164 } // namespace cutlass
165
cutlass::IntegerType< 16, false >::Type
uint16_t Type
Definition: numeric_types.h:115
cutlass::uint4b_t
integer_subbyte< 4, false > uint4b_t
4-bit Unsigned integer type
Definition: integer_subbyte.h:158
cutlass
Definition: aligned_buffer.h:35
cutlass::IntegerType
Defines integers based on size and whether they are signed.
Definition: numeric_types.h:76
cutlass::sizeof_bits::value
static int const value
Definition: numeric_types.h:43
cutlass::IntegerType< 64, true >::Type
int64_t Type
Definition: numeric_types.h:130
cutlass::IntegerType< 32, false >::Type
uint32_t Type
Definition: numeric_types.h:125
cutlass::FloatType< 11, 52 >::Type
double Type
Definition: numeric_types.h:148
half.h
Defines a class for using IEEE half-precision floating-point types in host or device code...
cutlass::integer_subbyte
4-bit signed integer type
Definition: integer_subbyte.h:42
cutlass::half_t
IEEE half-precision floating-point type.
Definition: half.h:126
cutlass::FloatType
Defines a floating-point type based on the number of exponent and mantissa bits.
Definition: numeric_types.h:144
integer_subbyte.h
Defines a class for using integer types smaller than one byte in host or device code.
cutlass::bin1_t
bool bin1_t
1-bit binary type
Definition: numeric_types.h:53
cutlass::sizeof_bits
Defines the size of an element in bits.
Definition: numeric_types.h:42
cutlass::IntegerType< 1, false >::Type
bin1_t Type
Definition: numeric_types.h:85
cutlass::IntegerType< 32, true >::Type
int32_t Type
Definition: numeric_types.h:120
cutlass::IntegerType< 16, true >::Type
int16_t Type
Definition: numeric_types.h:110
cutlass::IntegerType< 64, false >::Type
uint64_t Type
Definition: numeric_types.h:135
cutlass::FloatType< 8, 23 >::Type
float Type
Definition: numeric_types.h:153
cutlass::IntegerType< 1, true >::Type
bin1_t Type
Definition: numeric_types.h:80
cutlass::int4b_t
integer_subbyte< 4, true > int4b_t
4-bit Integer type
Definition: integer_subbyte.h:155
cutlass.h
Basic include for CUTLASS.
cutlass::IntegerType< 8, false >::Type
uint8_t Type
Definition: numeric_types.h:105
cutlass::IntegerType< 8, true >::Type
int8_t Type
Definition: numeric_types.h:100