summaryrefslogtreecommitdiffstats
path: root/patches/astra-toolbox-approximate-projectors/rounding.h
blob: c1cbffba617fad81c2cfc2a7a9961005231c2faf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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