DFT-EFE
 
Loading...
Searching...
No Matches
DeviceTypeConfigHalfPrec.hip.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2025 The Regents of the University of Michigan and DFT-FE
4// authors.
5//
6// This file is part of the DFT-FE code.
7//
8// The DFT-FE code is free software; you can use it, redistribute
9// it, and/or modify it under the terms of the GNU Lesser General
10// Public License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12// The full text of the license can be found in the file LICENSE at
13// the top level of the DFT-FE distribution.
14//
15// ---------------------------------------------------------------------
16//
17#ifndef dftefeDeviceTypeConfigHalfPrec_hiph
18#define dftefeDeviceTypeConfigHalfPrec_hiph
19#include <complex>
20#include <hip/hip_complex.h>
21#include <hip/hip_fp16.h>
22#include <hip/hip_bf16.h>
23namespace dftefe
24{
25 namespace utils
26 {
27 typedef __hip_bfloat16 __device_bfloat16;
28 typedef __hip_bfloat162 __device_bfloat162;
29
30 __forceinline__ __device__ void
31 copyValue(__device_bfloat16 *a, const float b)
32 {
33 *a = __float2bfloat16(b);
34 }
35
36 __forceinline__ __device__ void
37 copyValue(__device_bfloat16 *a, const double b)
38 {
39 *a = __float2bfloat16((float)b);
40 }
41
42 __forceinline__ __device__ void
43 copyValue(__device_bfloat162 *a, const hipFloatComplex b)
44 {
45 a->x = __float2bfloat16(b.x);
46 a->y = __float2bfloat16(b.y);
47 }
48
49 __forceinline__ __device__ void
50 copyValue(__device_bfloat162 *a, const hipDoubleComplex b)
51 {
52 a->x = __float2bfloat16((float)b.x);
53 a->y = __float2bfloat16((float)b.y);
54 }
55
56 __forceinline__ __device__ void
57 copyValue(float *a, const __device_bfloat16 b)
58 {
59 *a = __bfloat162float(b);
60 }
61
62 __forceinline__ __device__ void
63 copyValue(double *a, const __device_bfloat16 b)
64 {
65 *a = (double)__bfloat162float(b);
66 }
67
68 __forceinline__ __device__ void
69 copyValue(hipFloatComplex *a, const __device_bfloat162 b)
70
71 {
72 a->x = __bfloat162float(b.x);
73 a->y = __bfloat162float(b.y);
74 }
75
76 __forceinline__ __device__ void
77 copyValue(hipDoubleComplex *a, const __device_bfloat162 b)
78 {
79 a->x = (double)__bfloat162float(b.x);
80 a->y = (double)__bfloat162float(b.y);
81 }
82
83 __forceinline__ __device__ float
85 {
86 return a.x;
87 }
88
89 __forceinline__ __device__ float
91 {
92 return a.y;
93 }
94
95 // uint16_t saves bits only
96 // not for arithmetic operations
97
100 {
101 return __device_bfloat16{__hip_bfloat16_raw{a}};
102 }
103
104 inline __device_bfloat16 *
106 {
107 return reinterpret_cast<__device_bfloat16 *>(a);
108 }
109
110 inline const __device_bfloat16 *
111 makeDataTypeDeviceCompatible(const uint16_t *a)
112 {
113 return reinterpret_cast<const __device_bfloat16 *>(a);
114 }
115
116 inline __device_bfloat162
117 makeDataTypeDeviceCompatible(std::complex<uint16_t> a)
118 {
119 return __device_bfloat162{__device_bfloat16{__hip_bfloat16_raw{a.real()}},
121 __hip_bfloat16_raw{a.imag()}}};
122 }
123
124 inline __device_bfloat162 *
125 makeDataTypeDeviceCompatible(std::complex<uint16_t> *a)
126 {
127 return reinterpret_cast<__device_bfloat162 *>(a);
128 }
129
130 inline const __device_bfloat162 *
131 makeDataTypeDeviceCompatible(const std::complex<uint16_t> *a)
132 {
133 return reinterpret_cast<const __device_bfloat162 *>(a);
134 }
135
136 } // namespace utils
137} // namespace dftefe
138
139#endif // dftefeDeviceTypeConfigHalfPrec_hiph
__device_bfloat16 __float2bfloat16(float f)
Definition: DeviceTypeConfigHalfPrec.sycl.h:41
__nv_bfloat162 __device_bfloat162
Definition: DeviceTypeConfigHalfPrec.cu.h:27
__forceinline__ __device__ void copyValue(double *a, const double b)
Definition: DeviceDataTypeOverloads.cu.h:53
float __bfloat162float(__device_bfloat16 bf16)
Definition: DeviceTypeConfigHalfPrec.sycl.h:33
__forceinline__ __device__ double imagPartDevice(double a)
Definition: DeviceDataTypeOverloads.cu.h:156
__nv_bfloat16 __device_bfloat16
Definition: DeviceTypeConfigHalfPrec.cu.h:26
__forceinline__ __device__ double realPartDevice(double a)
Definition: DeviceDataTypeOverloads.cu.h:130
int * makeDataTypeDeviceCompatible(int *a)
Definition: DeviceDataTypeOverloads.cu.h:595
dealii includes
Definition: AtomFieldDataSpherical.cpp:31