summaryrefslogtreecommitdiffstats
path: root/patches/astra-toolbox-approximate-projectors/rounding.h
diff options
context:
space:
mode:
Diffstat (limited to 'patches/astra-toolbox-approximate-projectors/rounding.h')
-rw-r--r--patches/astra-toolbox-approximate-projectors/rounding.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/patches/astra-toolbox-approximate-projectors/rounding.h b/patches/astra-toolbox-approximate-projectors/rounding.h
new file mode 100644
index 0000000..c1cbffb
--- /dev/null
+++ b/patches/astra-toolbox-approximate-projectors/rounding.h
@@ -0,0 +1,50 @@
+#include <cuda_fp16.h>
+
+#define precision 8
+#define approximate_interpolation
+
+#ifdef approximate_interpolation
+# ifdef precision
+# if precision == 16
+# define texto(v) __float2half(v)
+# define texfrom(v) __half2float(v)
+# define textype half
+# define interpolate(v0, v1, pos) (v0 + pos*(v1-v0))
+# define textocheck(var,msg,val) var=texto(val);
+# else
+# define precision_mult ((1<<precision)-1)
+# define texto(v) ((unsigned char)(precision_mult*v))
+# define texfrom(v) (1.f * v / precision_mult)
+# define textype unsigned
+# define interpolate(v0, v1, pos) (v0 + ((unsigned)(256 * pos)) * (v1 - v0) / 256)
+# define textocheck(var, msg, val) \
+ if ((val<0)||(val>1)) { printf("Received out-of-range value (%f) in %s texture fetch\n", val, msg); } \
+ var=texto(val);
+# endif
+# else
+# define texto(v) (v)
+# define texfrom(v) (v)
+# define textype float
+# define interpolate(v0, v1, pos) (v0 + pos*(v1-v0))
+# define textocheck(var,msg,val) var=texto(val);
+# endif
+#else
+# ifdef precision
+# if precision == 16
+# define texto(v) __half2float(__float2half(v))
+# define textocheck(var,msg,val) var=texto(val);
+# else
+# define precision_mult ((1<<precision)-1)
+# define texto(v) (floor(precision_mult*v)/precision_mult)
+# define textocheck(var, msg, val) \
+ if ((val<0)||(val>1)) { printf("Received out-of-range value (%f) in %s texture fetch\n", val, msg); } \
+ var=texto(val);
+# endif
+# else
+# define texto(v) (v)
+# define textocheck(var,msg,val) var=texto(val);
+# endif
+# define texfrom(v) (v)
+# define textype float
+# define interpolate(v0, v1, pos) (v0 + pos*(v1-v0))
+#endif