File: OSPCommon.ih

package info (click to toggle)
ospray 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 10,040 kB
  • sloc: cpp: 80,569; ansic: 951; sh: 805; makefile: 171; python: 69
file content (269 lines) | stat: -rw-r--r-- 7,196 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "rkcommon/math/vec.ih"

#define STRING(x) #x
#define TOSTRING(x) STRING(x)
#define CODE_LOCATION __FILE__ " (" TOSTRING(__LINE__) ")"

#ifdef OSPRAY_TARGET_SYCL
#include <sycl/sycl.hpp>

#define __noinline __attribute__((noinline))

#define in ,
#define foreach_unique(var_in_set) FOREACH_UNIQUE(var_in_set)
#define FOREACH_UNIQUE(var, set) for (const auto &var : {set})

namespace ispc {
using uint64 = uint64_t;
using uint32 = uint32_t;
using uint16 = uint16_t;
using uint8 = uint8_t;
using int64 = int64_t;
using int32 = int32_t;
using int16 = int16_t;
using int8 = int8_t;
} // namespace ispc

#define PING                                                                   \
  sycl::ext::oneapi::experimental::printf(CODE_LOCATION ": " __FUNCTION__ "\n")

#undef PRINT
#undef PRINTV

// Skip printing in host code.
#define PRINT(x)
#define PRINTV(x)

// Note: SYCL printf needs the type specifier, unlike ISPC. So, we need
// overloaded functions to print based on the type of the parameter. We use a
// wrapper macro to extract argument's name as a char string to print both name
// and value of the variable.

#ifdef __SYCL_DEVICE_ONLY__
// rkcommon has its own macros for the host that we conflict with
#undef PRINT
#undef PRINTV

#define CONSTANT __attribute__((opencl_constant))

void print_(const CONSTANT char *name, const int &x)
{
  sycl::ext::oneapi::experimental::printf("%s = %d\n", name, x);
}

void print_(const CONSTANT char *name, const float &x)
{
  sycl::ext::oneapi::experimental::printf("%s = %f\n", name, x);
}

void print_(const CONSTANT char *name, const uint32_t &x)
{
  sycl::ext::oneapi::experimental::printf("%s = %u\n", name, x);
}

void print_(const CONSTANT char *name, const ispc::vec2i &v)
{
  sycl::ext::oneapi::experimental::printf("%s = (%d, %d)\n", name, v.x, v.y);
}

void print_(const CONSTANT char *name, const ispc::vec2f &v)
{
  sycl::ext::oneapi::experimental::printf("%s = (%f, %f)\n", name, v.x, v.y);
}

void print_(const CONSTANT char *name, const ispc::vec3i &v)
{
  sycl::ext::oneapi::experimental::printf(
      "%s = (%d, %d, %d)\n", name, v.x, v.y, v.z);
}

void print_(const CONSTANT char *name, const ispc::vec3f &v)
{
  sycl::ext::oneapi::experimental::printf(
      "%s = (%f, %f, %f)\n", name, v.x, v.y, v.z);
}

void print_(const CONSTANT char *name, const ispc::vec4i &v)
{
  sycl::ext::oneapi::experimental::printf(
      "%s = (%d, %d, %d, %d)\n", name, v.x, v.y, v.z, v.w);
}

void print_(const CONSTANT char *name, const ispc::vec4f &v)
{
  sycl::ext::oneapi::experimental::printf(
      "%s = (%f, %f, %f, %f)\n", name, v.x, v.y, v.z, v.w);
}

void print_(const CONSTANT char *name, const CONSTANT char *s)
{
  sycl::ext::oneapi::experimental::printf("%s = %s\n", name, s);
}

#define PRINT(x)                                                               \
  {                                                                            \
    static const CONSTANT char var_name[] = #x;                                \
    print_(var_name, x);                                                       \
  }

// SYCL is scalar, PRINTV = PRINT
#define PRINTV(x) PRINT(x);

#endif

#else // ISPC

#define PING print(CODE_LOCATION "\n")

#define __noinline noinline

inline void printv_(const int &x)
{
  print("%\n", x);
}

inline void printv_(const float &x)
{
  print("%\n", x);
}

inline void printv_(const uint32 &x)
{
  print("%\n", x);
}

inline void printv_(const vec2i &v)
{
  print("(%, %)\n", v.x, v.y);
}

inline void printv_(const vec2f &v)
{
  print("(%, %)\n", v.x, v.y);
}

inline void printv_(const vec3i &v)
{
  print("(% % %)\n", v.x, v.y, v.z);
}

inline void printv_(const vec3f &v)
{
  print("(% % %)\n", v.x, v.y, v.z);
}

inline void printv_(const vec4i &v)
{
  print("(% % % %)\n", v.x, v.y, v.z, v.w);
}

inline void printv_(const vec4f &v)
{
  print("(% % % %)\n", v.x, v.y, v.z, v.w);
}

#define PRINTV(x)                                                              \
  {                                                                            \
    print(#x " = ");                                                           \
    printv_(x);                                                                \
  }

inline void print_(const int &x)
{
  print("[%] = %\n",
      count_trailing_zeros(lanemask()),
      extract(x, count_trailing_zeros(lanemask())));
}

inline void print_(const float &x)
{
  print("[%] = %\n",
      count_trailing_zeros(lanemask()),
      extract(x, count_trailing_zeros(lanemask())));
}

inline void print_(const uint32 &x)
{
  print("[%] = %\n",
      count_trailing_zeros(lanemask()),
      extract(x, count_trailing_zeros(lanemask())));
}

inline void print_(const vec2i &v)
{
  print("[%] = (%, %)\n",
      count_trailing_zeros(lanemask()),
      extract(v.x, count_trailing_zeros(lanemask())),
      extract(v.y, count_trailing_zeros(lanemask())));
}

inline void print_(const vec2f &v)
{
  print("[%] = (%, %)\n",
      count_trailing_zeros(lanemask()),
      extract(v.x, count_trailing_zeros(lanemask())),
      extract(v.y, count_trailing_zeros(lanemask())));
}

inline void print_(const vec3i &v)
{
  print("[%] = (%, %, %)\n",
      count_trailing_zeros(lanemask()),
      extract(v.x, count_trailing_zeros(lanemask())),
      extract(v.y, count_trailing_zeros(lanemask())),
      extract(v.z, count_trailing_zeros(lanemask())));
}

inline void print_(const vec3f &v)
{
  print("[%] = (%, %, %)\n",
      count_trailing_zeros(lanemask()),
      extract(v.x, count_trailing_zeros(lanemask())),
      extract(v.y, count_trailing_zeros(lanemask())),
      extract(v.z, count_trailing_zeros(lanemask())));
}

inline void print_(const vec4i &v)
{
  print("[%] = (%, %, %, %)\n",
      count_trailing_zeros(lanemask()),
      extract(v.x, count_trailing_zeros(lanemask())),
      extract(v.y, count_trailing_zeros(lanemask())),
      extract(v.z, count_trailing_zeros(lanemask())),
      extract(v.w, count_trailing_zeros(lanemask())));
}

inline void print_(const vec4f &v)
{
  print("[%] = (%, %, %, %)\n",
      count_trailing_zeros(lanemask()),
      extract(v.x, count_trailing_zeros(lanemask())),
      extract(v.y, count_trailing_zeros(lanemask())),
      extract(v.z, count_trailing_zeros(lanemask())),
      extract(v.w, count_trailing_zeros(lanemask())));
}

#define PRINT(x)                                                               \
  {                                                                            \
    print(#x);                                                                 \
    print_(x);                                                                 \
  }

#define PRINT_STR(s) print(#s " = %\n", s);
#endif

#ifndef OSPRAY_TARGET_SYCL
/*! 64-bit malloc. allows for alloc'ing memory larger than 64 bits */
extern "C" void *uniform malloc64(uniform uint64 size);
extern "C" void free64(void *uniform ptr);

/*! Thread Local Storage functions */
extern "C" void *uniform pushTLS(uniform uint64 size);
extern "C" void *uniform reallocTLS(void *uniform ptr, uniform uint64 size);
extern "C" void popTLS(void *uniform ptr);
#endif