Skip to content

Commit 264f8c4

Browse files
committed
GPU: Unify usage of half precision float into half_t typedef in GPUCommonMath.h
1 parent b141791 commit 264f8c4

15 files changed

Lines changed: 53 additions & 942 deletions

‎Common/ML/include/ML/3rdparty/GPUORTFloat16.h‎

Lines changed: 0 additions & 887 deletions
This file was deleted.

‎Common/ML/src/OrtInterface.cxx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
/// \brief A header library for loading ONNX models and inferencing them on CPU and GPU
1515

1616
#include "ML/OrtInterface.h"
17-
#include "ML/3rdparty/GPUORTFloat16.h"
17+
#include "GPUCommonMath.h"
18+
19+
namespace o2::OrtDataType
20+
{
21+
using Float16_t = o2::gpu::GPUCommonMath::half_t;
22+
}
1823

1924
// ONNX includes
2025
#include <onnxruntime_cxx_api.h>

‎GPU/Common/GPUCommonMath.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
#if defined(__CUDACC__) && !defined(__clang__) && !defined(GPUCA_GPUCODE_COMPILEKERNELS) && !defined(GPUCA_GPUCODE_HOSTONLY)
2121
#include <sm_20_atomic_functions.h>
22+
#include <cuda_fp16.h>
23+
#endif
24+
25+
#if defined(__HIPCC__) && !defined(GPUCA_GPUCODE_COMPILEKERNELS) && !defined(GPUCA_GPUCODE_HOSTONLY)
26+
#include <hip/hip_fp16.h>
2227
#endif
2328

2429
#if !defined(GPUCA_GPUCODE_DEVICE)
@@ -27,6 +32,9 @@
2732
#include <atomic>
2833
#include <limits>
2934
#include <cstring>
35+
#if __cplusplus >= 202302L && __has_include(<stdfloat>)
36+
#include <stdfloat>
37+
#endif
3038
#endif
3139

3240
#if !defined(GPUCA_GPUCODE_COMPILEKERNELS) && (!defined(GPUCA_GPUCODE_DEVICE) || defined(__CUDACC__) || defined(__HIPCC__))
@@ -48,6 +56,14 @@ namespace o2::gpu
4856
class GPUCommonMath
4957
{
5058
public:
59+
#if (defined(GPUCA_GPUCODE_DEVICE) && !defined(__CPUDEVICE__)) || defined(__CUDACC__)
60+
using half_t = half;
61+
#elif __cplusplus >= 202302L && defined(__STDCPP_FLOAT16_T__)
62+
using half_t = std::float16_t;
63+
#else
64+
using half_t = _Float16;
65+
#endif
66+
5167
GPUd() static float2 MakeFloat2(float x, float y); // TODO: Find better appraoch that is constexpr
5268

5369
template <class T>

‎GPU/GPUTracking/Base/hip/GPUReconstructionHIPIncludesSystem.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
#include <thrust/sort.h>
2626
#include <thrust/execution_policy.h>
2727
#include <thrust/device_ptr.h>
28+
#include <hip/hip_fp16.h>
2829

2930
#endif // O2_GPU_RECONSTRUCTIONHIPINCLUDESSYSTEM_H

‎GPU/GPUTracking/Base/metal/GPUReconstructionMetalIncludesHost.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
#ifndef __METAL_VERSION__
2323
// __METAL_VERSION__ is only defined in device code.
2424
#define __METAL_HOST__
25-
// The parameter table picks MSL's `half` for the device layouts this translation
26-
// unit has to agree with; _Float16 is the same IEEE binary16 type.
27-
using half = _Float16;
2825
#endif
2926

3027
#import <Foundation/Foundation.h>

‎GPU/GPUTracking/Base/opencl/GPUReconstructionOCLIncludesHost.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include <string>
2626
#include <memory>
2727

28-
typedef int16_t half; // TODO: Fixme once we have C++23 and proper host side half support
29-
3028
#include "GPULogging.h"
3129

3230
#include "GPUReconstructionOCL.h"

‎GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ TRACKLET_SELECTOR_HITS_REG_SIZE,12,0,9,27,,,,,,20,20,20,20,,20,,2,20,
109109
ALTERNATE_BORDER_SORT,1,0,1,1,,,,,,1,1,1,1,,1,,1,1,
110110
SORT_BEFORE_FIT,1,0,1,1,,,,,,1,1,1,1,,1,,1,1,
111111
NO_ATOMIC_PRECHECK,0,0,1,1,,,,,,1,1,1,1,,1,,1,1,
112-
DEDX_STORAGE_TYPE,"""half""","""float""",,,,,,,,,,,,,,,,,
113-
MERGER_INTERPOLATION_ERROR_TYPE,"""half""","""float""",,,,,,,,,,,,,,,,,
112+
DEDX_STORAGE_TYPE,"""CAMath::half_t""","""float""",,,,,,,,,,,,,,,,,
113+
MERGER_INTERPOLATION_ERROR_TYPE,"""CAMath::half_t""","""float""",,,,,,,,,,,,,,,,,
114114
COMP_GATHER_KERNEL,4,0,4,4,,,,,,4,4,4,4,,4,,4,4,
115115
COMP_GATHER_MODE,3,0,3,3,,,,,,3,3,3,3,,3,,3,3,
116116
CF_SCAN_WORKGROUP_SIZE,512,0,,,,,,,,224,,992,448,,1024,,,448,

‎GPU/GPUTracking/Definitions/Parameters/GPUParameters.json.example‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,10 @@
588588
"MERGER_INTERPOLATION_ERROR_TYPE": {
589589
"default": "float",
590590
"default_cpu": "float",
591-
"MI100": "half",
592-
"VEGA": "half",
593-
"AMPERE": "half",
594-
"TURING": "half"
591+
"MI100": "CAMath::half_t",
592+
"VEGA": "CAMath::half_t",
593+
"AMPERE": "CAMath::half_t",
594+
"TURING": "CAMath::half_t"
595595
},
596596
"COMP_GATHER_KERNEL": {
597597
"default": 0,

‎GPU/GPUTracking/Merger/GPUTPCGMMergerTypes.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define GPUTPCGMMERGERTYPES_H
1717

1818
#include "GPUTPCDef.h"
19+
#include "GPUCommonMath.h"
1920
#include "GPUGeneralKernels.h"
2021

2122
namespace o2::gpu::gputpcgmmergertypes

‎GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizer.cxx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
/// \author Christian Sonnabend
1414

1515
#include "GPUReconstruction.h"
16-
#include "ML/3rdparty/GPUORTFloat16.h"
1716
#include "GPUTPCNNClusterizer.h"
1817
#include "GPUSettings.h"
1918
#include "GPUCommonLogger.h"

0 commit comments

Comments
 (0)