imate
C++/CUDA Reference
Loading...
Searching...
No Matches
_cu_div.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_DIV_H_
12#define _CU_ARITHMETICS_CU_DIV_H_
13
14// =======
15// Headers
16// =======
17
18#include "../_cu_definitions/cu_types.h" // __nv_fp8_e5m2, __nv_fp8_e4m3,
19 // __half, __nv_bfloat16, __hdiv
20#include <cassert> // assert
21
22
23// =============
24// cu arithmetic
25// =============
26
39
40namespace cu_arithmetics
41{
42 // ===
43 // div
44 // ===
45
57
58 template <typename DataType>
60 const DataType x,
61 const DataType y);
62
63
64 // ===
65 // div (__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 // div (__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 // div (__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 __hdiv(x, y);
147 }
148 #endif
149
150
151 // ===
152 // div (__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 __hdiv(x, y);
174 }
175 #endif
176
177
178 // ===
179 // div (float)
180 // ===
181
193
194 #if defined(USE_CUDA_FP32) && (USE_CUDA_FP32 == 1)
195 template<>
197 const float x,
198 const float y)
199 {
200 return x / y;
201 }
202 #endif
203
204
205 // ===
206 // div (double)
207 // ===
208
220
221 #if defined(USE_CUDA_FP64) && (USE_CUDA_FP64 == 1)
222 template<>
224 const double x,
225 const double y)
226 {
227 return x / y;
228 }
229 #endif
230
231} // namespace cu_arithmetics
232
233#endif // _CU_ARITHMETICS_CU_DIV_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__ DataType div(const DataType x, const DataType y)
Divide two floating point numbers in round-to-nearest-even mode.
__host__ __device__ double div< double >(const double x, const double y)
Divide two double type numbers in round-to-nearest-even mode.
Definition _cu_div.h:223
__host__ __device__ float div< float >(const float x, const float y)
Divide two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.
Definition _cu_div.h:196