Optimized Belief Propagation (CPU and GPU)
AVXTemplateSpFuncts.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2024 Scott Grauer-Gray
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
27 #ifndef AVXTEMPLATESPFUNCTS_H_
28 #define AVXTEMPLATESPFUNCTS_H_
29 
30 //this is only processed when on x86
31 #ifdef _WIN32
32 #include <intrin.h>
33 #else
34 #include <x86intrin.h>
35 #endif
36 
37 #include "RunImp/UtilityFuncts.h"
39 #include <immintrin.h>
40 
41 //used code from https://github.com/microsoft/DirectXMath/blob/master/Extensions/DirectXMathF16C.h
42 //for the values conversion on Windows since _cvtsh_ss and _cvtss_sh not supported in Visual Studio
43 template<> inline
44 short util_functs::ZeroVal<short>()
45 {
46 #ifdef _WIN32
47  __m128 dataInAvxReg = _mm_set_ss(0.0);
48  __m128i convertedData = _mm_cvtps_ph(dataInAvxReg, 0);
49  return ((short*)& convertedData)[0];
50 #else
51  return _cvtss_sh(0.0f, 0);
52 #endif
53 }
54 
55 template<> inline
56 float util_functs::ConvertValToDifferentDataTypeIfNeeded<short, float>(short data)
57 {
58 #ifdef _WIN32
59  __m128i dataInAvxReg = _mm_cvtsi32_si128(static_cast<int>(data));
60  __m128 convertedData = _mm_cvtph_ps(dataInAvxReg);
61  return ((float*)& convertedData)[0];
62 #else
63  return _cvtsh_ss(data);
64 #endif
65 }
66 
67 template<> inline
68 short util_functs::ConvertValToDifferentDataTypeIfNeeded<float, short>(float data)
69 {
70 #ifdef _WIN32
71  __m128 dataInAvxReg = _mm_set_ss(data);
72  __m128i convertedData = _mm_cvtps_ph(dataInAvxReg, 0);
73  return ((short*)&convertedData)[0];
74 #else
75  return _cvtss_sh(data, 0);
76 #endif
77 }
78 
79 #endif //AVXTEMPLATESPFUNCTS_H_
Contains namespace with constants and enums related to run environment and settings for run.
Contains namespace with utility functions for implementation.