CUTLASS
CUDA Templates for Linear Algebra Subroutines and Solvers
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 <>
58  static int const value = 1;
59 };
60 
62 
63 } // namespace cutlass
64 
66 
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 
uint16_t Type
Definition: numeric_types.h:115
integer_subbyte< 4, false > uint4b_t
4-bit Unsigned integer type
Definition: integer_subbyte.h:158
Definition: aligned_buffer.h:35
Defines integers based on size and whether they are signed.
Definition: numeric_types.h:76
static int const value
Definition: numeric_types.h:43
int64_t Type
Definition: numeric_types.h:130
uint32_t Type
Definition: numeric_types.h:125
double Type
Definition: numeric_types.h:148
Defines a class for using IEEE half-precision floating-point types in host or device code...
4-bit signed integer type
Definition: integer_subbyte.h:42
IEEE half-precision floating-point type.
Definition: half.h:126
Defines a floating-point type based on the number of exponent and mantissa bits.
Definition: numeric_types.h:144
Defines a class for using integer types smaller than one byte in host or device code.
bool bin1_t
1-bit binary type
Definition: numeric_types.h:53
Defines the size of an element in bits.
Definition: numeric_types.h:42
bin1_t Type
Definition: numeric_types.h:85
int32_t Type
Definition: numeric_types.h:120
int16_t Type
Definition: numeric_types.h:110
uint64_t Type
Definition: numeric_types.h:135
float Type
Definition: numeric_types.h:153
bin1_t Type
Definition: numeric_types.h:80
integer_subbyte< 4, true > int4b_t
4-bit Integer type
Definition: integer_subbyte.h:155
Basic include for CUTLASS.
uint8_t Type
Definition: numeric_types.h:105
int8_t Type
Definition: numeric_types.h:100