Skip to content

Commit 0c652eb

Browse files
committed
GPU RTC: Fix float precision for constexpr optimization
1 parent 8b7ae7d commit 0c652eb

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

GPU/GPUTracking/utils/qconfig.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,12 @@ enum qConfigRetVal { qcrOK = 0,
250250
#define AddVariable(name, type, default) out << qon_mxstr(type) << " " << qon_mxstr(name) << ";\n";
251251
#define AddOptionArray(name, type, count, default, optname, optnameshort, help, ...) out << qon_mxstr(type) << " " << qon_mxstr(name) << "[" << qon_mxstr(count) << "];\n";
252252
#define AddOptionVec(name, type, optname, optnameshort, help, ...) out << "std::vector<" << qon_mxstr(type) << "> " << qon_mxstr(name) << ";\n";
253-
#define AddVariableRTC(name, type, default) \
254-
if (useConstexpr) { \
255-
out << "static constexpr " << qon_mxstr(type) << " " << qon_mxstr(name) << " = " << qConfig::print_type(std::get<const qConfigCurrentType*>(tSrc)->name) << ";\n"; \
256-
out << qon_mxstr(type) << " " << qon_mxstr(qon_mxcat(_dummy_, name)) << ";\n"; \
257-
} else { \
258-
AddOption(name, type, default, optname, optnameshort, help); \
253+
#define AddVariableRTC(name, type, default) \
254+
if (useConstexpr) { \
255+
out << "static constexpr " << qon_mxstr(type) << " " << qon_mxstr(name) << " = " << qConfig::print_type(std::get<const qConfigCurrentType*>(tSrc)->name, true) << ";\n"; \
256+
out << qon_mxstr(type) << " " << qon_mxstr(qon_mxcat(_dummy_, name)) << ";\n"; \
257+
} else { \
258+
AddOption(name, type, default, optname, optnameshort, help); \
259259
}
260260
#define AddOptionRTC(name, type, default, optname, optnameshort, help, ...) AddVariableRTC(name, type, default)
261261
#define AddOptionArrayRTC(name, type, count, default, optname, optnameshort, help, ...) \

GPU/GPUTracking/utils/qconfig_helpers.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <string>
1919
#include <sstream>
20+
#include <type_traits>
2021

2122
#define qon_mcat(a, b) a##b
2223
#define qon_mxcat(a, b) qon_mcat(a, b)
@@ -30,29 +31,34 @@
3031
namespace qConfig
3132
{
3233
template <class T>
33-
inline std::string print_type(T val)
34+
inline std::string print_type(T val, bool precise = false)
3435
{
3536
std::ostringstream s;
37+
if constexpr (std::is_same_v<T, float> || std::is_same_v<T, double>) {
38+
if (precise) {
39+
s << std::hexfloat;
40+
}
41+
}
3642
s << val;
3743
return s.str();
3844
};
3945
template <>
40-
inline std::string print_type<char>(char val)
46+
inline std::string print_type<char>(char val, bool precise)
4147
{
4248
return std::to_string(val);
4349
};
4450
template <>
45-
inline std::string print_type<int8_t>(int8_t val)
51+
inline std::string print_type<int8_t>(int8_t val, bool precise)
4652
{
4753
return std::to_string(val);
4854
};
4955
template <>
50-
inline std::string print_type<uint8_t>(uint8_t val)
56+
inline std::string print_type<uint8_t>(uint8_t val, bool precise)
5157
{
5258
return std::to_string(val);
5359
};
5460
template <>
55-
inline std::string print_type<bool>(bool val)
61+
inline std::string print_type<bool>(bool val, bool precise)
5662
{
5763
return val ? "true" : "false";
5864
};

GPU/GPUTracking/utils/qconfigrtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ template <class T>
3131
static std::string qConfigPrintRtc(const T& tSrc, bool useConstexpr)
3232
{
3333
std::stringstream out;
34+
out << std::hexfloat;
3435
#define QCONFIG_PRINT_RTC
3536
#include "qconfig.h"
3637
#undef QCONFIG_PRINT_RTC

0 commit comments

Comments
 (0)