imate
C++/CUDA Reference
Loading...
Searching...
No Matches
_cu_sub.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3 * SPDX-License-Identifier: BSD-3-Clause
4 * SPDX-FileType: SOURCE
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the license found in the LICENSE.txt file in the root
8 * directory of this source tree.
9 */
10
11#ifndef _CU_ARITHMETICS_CU_SUB_H_
12#define _CU_ARITHMETICS_CU_SUB_H_
13
14// =======
15// Headers
16// =======
17
18#include "../_cu_definitions/cu_types.h" // __nv_fp8_e5m2, __nv_fp8_e4m3,
19 // __half, __nv_bfloat16, __hsub
20#include <cassert> // assert
21
22
23// =============
24// cu arithmetic
25// =============
26
39
40namespace cu_arithmetics
41{
42 // ===
43 // sub
44 // ===
45
57
58 template <typename DataType>
60 const DataType x,
61 const DataType y);
62
63
64 // ===
65 // sub (__nv_fp8_e5m2)
66 // ===
67
79
80 #if defined(USE_CUDA_FP8_E5M2) && (USE_CUDA_FP8_E5M2 == 1)
81 template<>
83 const __nv_fp8_e5m2 x,
84 const __nv_fp8_e5m2 y)
85 {
86 // Not implemented
87 assert(false);
88
89 return __nv_fp8_e5m2(NAN);
90 }
91 #endif
92
93
94 // ===
95 // sub (__nv_fp8_e4m3)
96 // ===
97
109
110 #if defined(USE_CUDA_FP8_E4M3) && (USE_CUDA_FP8_E4M3 == 1)
111 template<>
113 const __nv_fp8_e4m3 x,
114 const __nv_fp8_e4m3 y)
115 {
116 // Not implemented
117 assert(false);
118
119 return __nv_fp8_e4m3(NAN);
120 }
121 #endif
122
123
124 // ===
125 // sub (__half)
126 // ===
127
139
140 #if defined(USE_CUDA_FP16) && (USE_CUDA_FP16 == 1)
141 template<>
143 const __half x,
144 const __half y)
145 {
146 return __hsub(x, y);
147 }
148 #endif
149
150
151 // ===
152 // sub (__nv_bfloat16)
153 // ===
154
166
167 #if defined(USE_CUDA_BF16) && (USE_CUDA_BF16 == 1)
168 template<>
170 const __nv_bfloat16 x,
171 const __nv_bfloat16 y)
172 {
173 return __hsub(x, y);
174 }
175 #endif
176
177
178 // ===
179 // sub (float)
180 // ===
181
192
193 #if defined(USE_CUDA_FP32) && (USE_CUDA_FP32 == 1)
194 template<>
196 const float x,
197 const float y)
198 {
199 return x - y;
200 }
201 #endif
202
203
204 // ===
205 // sub (double)
206 // ===
207
218
219 #if defined(USE_CUDA_FP64) && (USE_CUDA_FP64 == 1)
220 template<>
222 const double x,
223 const double y)
224 {
225 return x - y;
226 }
227 #endif
228
229} // namespace cu_arithmetics
230
231#endif // _CU_ARITHMETICS_CU_SUB_H_
Cast from float to __half and __nv_bfloat16 types and vice-versa, and float to double and vice-versa.
Definition _cu_abs.h:43
__host__ __device__ DataType abs(const DataType x)
Absolute value of a floating point number.
__host__ __device__ float sub< float >(const float x, const float y)
Subtract two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.
Definition _cu_sub.h:195
__host__ __device__ DataType sub(const DataType x, const DataType y)
Subtract two floating point numbers in round-to-nearest-even mode.
__host__ __device__ double sub< double >(const double x, const double y)
Subtract two double type float numbers.
Definition _cu_sub.h:221