SCM Repository
Annotation of /trunk/src/include/Diderot/diderot.h
Parent Directory
|
Revision Log
Revision 1694 - (view) (download) (as text)
1 : | jhr | 1115 | /*! \file diderot.h |
2 : | * | ||
3 : | * \author John Reppy | ||
4 : | * | ||
5 : | * This is the interface to the Diderot runtime for the C target. For now, | ||
6 : | * we are targetting single-precision computations. | ||
7 : | */ | ||
8 : | |||
9 : | /* | ||
10 : | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu) | ||
11 : | * All rights reserved. | ||
12 : | */ | ||
13 : | |||
14 : | #ifndef _DIDEROT_H_ | ||
15 : | #define _DIDEROT_H_ | ||
16 : | |||
17 : | jhr | 1232 | #include "Diderot/config.h" |
18 : | |||
19 : | jhr | 1301 | // include OpenCL headers when the target is OpenCL |
20 : | #if defined(DIDEROT_TARGET_CL) | ||
21 : | # ifdef HAVE_CL_CL_H | ||
22 : | # include <CL/cl.h> | ||
23 : | # elif defined(HAVE_OPENCL_CL_H) | ||
24 : | # include <OpenCL/cl.h> | ||
25 : | # else | ||
26 : | # error no cl.h | ||
27 : | # endif | ||
28 : | #endif | ||
29 : | |||
30 : | jhr | 1115 | /* gcc has a bug that breaks code that uses 8-byte vectors (e.g., vec2f_t), but clang |
31 : | * handles the code correctly. | ||
32 : | jhr | 1694 | * NOTE: we may be able to fix this issue with proper alignment directives. |
33 : | jhr | 1115 | */ |
34 : | jhr | 1694 | #if defined(__clang__) || defined(DIDEROT_DOUBLE_PRECISION) |
35 : | jhr | 1115 | # define VEC2_OK |
36 : | #endif | ||
37 : | |||
38 : | #ifdef NDEBUG | ||
39 : | jhr | 1295 | #define STATIC_INLINE static inline |
40 : | jhr | 1115 | #else |
41 : | jhr | 1295 | #define STATIC_INLINE static |
42 : | jhr | 1115 | #endif |
43 : | |||
44 : | jhr | 1640 | #include <assert.h> |
45 : | jhr | 1115 | #include <stdint.h> |
46 : | #include <stdbool.h> | ||
47 : | #include <stdlib.h> | ||
48 : | #include <math.h> | ||
49 : | #include <stdio.h> // for printing output | ||
50 : | jhr | 1640 | #include <string.h> |
51 : | #include "teem/air.h" | ||
52 : | jhr | 1115 | |
53 : | #include "types.h" | ||
54 : | jhr | 1640 | #include "world.h" |
55 : | jhr | 1115 | #include "strands.h" |
56 : | jhr | 1301 | #include "options.h" |
57 : | jhr | 1640 | #include "output.h" |
58 : | jhr | 1115 | |
59 : | /* load image data from Nrrd files */ | ||
60 : | extern Status_t Diderot_LoadImage1D (Diderot_string_t name, Diderot_image1D_t **img); | ||
61 : | extern Status_t Diderot_LoadImage2D (Diderot_string_t name, Diderot_image2D_t **img); | ||
62 : | extern Status_t Diderot_LoadImage3D (Diderot_string_t name, Diderot_image3D_t **img); | ||
63 : | |||
64 : | jhr | 1380 | #ifdef DIDEROT_TARGET_CL |
65 : | #include "shadow-types.h" | ||
66 : | #endif | ||
67 : | jhr | 1232 | |
68 : | jhr | 1295 | //! Summary information about the CPU configuration. |
69 : | jhr | 1232 | typedef struct { |
70 : | jhr | 1295 | int numHWNodes; //!< \brief number of (possibly multicore) processors |
71 : | int numHWCores; //!< \brief total number of (possibly | ||
72 : | //! mulithreaded) cores | ||
73 : | int numHWThreads; //!< \brief total number of hardware threads | ||
74 : | int numCoresPerNode; //!< \brief number of cores per thread | ||
75 : | int numThdsPerCore; //!< \brief number of threads per core | ||
76 : | jhr | 1232 | } CPUInfo_t; |
77 : | |||
78 : | jhr | 1295 | //! \brief function to get information about the CPU configuration |
79 : | jhr | 1232 | bool GetNumCPUs (CPUInfo_t *info); |
80 : | |||
81 : | jhr | 1640 | //! Checked memory allocation |
82 : | STATIC_INLINE void *CheckedAlloc (size_t szb) | ||
83 : | { | ||
84 : | void *p = malloc(szb); | ||
85 : | if (p == 0) { | ||
86 : | fprintf (stderr, "fatal error: unable to allocate %d bytes of memory\n", (int)szb); | ||
87 : | exit (1); | ||
88 : | } | ||
89 : | return p; | ||
90 : | } | ||
91 : | jhr | 1232 | |
92 : | jhr | 1640 | #define NEW(ty) (ty *)CheckedAlloc(sizeof(ty)) |
93 : | #define NEWVEC(ty,n) (ty *)CheckedAlloc(sizeof(ty) * (n)) | ||
94 : | #define NEWSTR(s) strcpy((char *)CheckedAlloc(strlen(s)+1), s) | ||
95 : | jhr | 1301 | |
96 : | jhr | 1640 | |
97 : | jhr | 1115 | /********** scalar math functions **********/ |
98 : | |||
99 : | jhr | 1640 | STATIC_INLINE Diderot_real_t min (Diderot_real_t a, Diderot_real_t b) |
100 : | jhr | 1115 | { |
101 : | jhr | 1295 | return (a < b) ? a : b; |
102 : | jhr | 1115 | } |
103 : | |||
104 : | jhr | 1640 | STATIC_INLINE Diderot_real_t max (Diderot_real_t a, Diderot_real_t b) |
105 : | jhr | 1115 | { |
106 : | jhr | 1295 | return (a < b) ? b : a; |
107 : | jhr | 1115 | } |
108 : | |||
109 : | jhr | 1640 | STATIC_INLINE Diderot_real_t clamp (Diderot_real_t lo, Diderot_real_t hi, Diderot_real_t x) |
110 : | jhr | 1295 | { |
111 : | jhr | 1640 | return min(max(lo, x), hi); |
112 : | jhr | 1295 | } |
113 : | |||
114 : | jhr | 1640 | STATIC_INLINE Diderot_real_t lerp (Diderot_real_t a, Diderot_real_t b, Diderot_real_t t) |
115 : | jhr | 1115 | { |
116 : | return a + t*(b - a); | ||
117 : | } | ||
118 : | |||
119 : | jhr | 1640 | #if defined(DIDEROT_SINGLE_PRECISION) |
120 : | # define EPSILON 1.0E-12 | ||
121 : | # define ABS(x) fabsf(x) | ||
122 : | # define ATAN2(x,y) atan2f(x,y) | ||
123 : | # define CBRT(x) cbrtf(x) | ||
124 : | # define COS(x) cosf(x) | ||
125 : | # define FLOOR(x) floorf(x) | ||
126 : | # define SIN(x) sinf(x) | ||
127 : | # define SQRT(x) sqrtf(x) | ||
128 : | # define TRUNC(x) truncf(x) | ||
129 : | #elif defined(DIDEROT_DOUBLE_PRECISION) | ||
130 : | # define EPSILON 1.0E-12 | ||
131 : | # define ABS(x) fabs(x) | ||
132 : | # define ATAN2(x,y) atan2(x,y) | ||
133 : | # define CBRT(x) cbrt(x) | ||
134 : | # define COS(x) cos(x) | ||
135 : | # define FLOOR(x) floor(x) | ||
136 : | # define SIN(x) sin(x) | ||
137 : | # define SQRT(x) sqrt(x) | ||
138 : | # define TRUNC(x) trunc(x) | ||
139 : | #else | ||
140 : | # error floating-point precision unknown | ||
141 : | #endif | ||
142 : | |||
143 : | jhr | 1115 | /********** vector math functions **********/ |
144 : | |||
145 : | #include "inline-vec2.h" | ||
146 : | #include "inline-vec3.h" | ||
147 : | #include "inline-vec4.h" | ||
148 : | #include "inline-matrix.h" | ||
149 : | |||
150 : | /********** other Diderot support functions **********/ | ||
151 : | |||
152 : | #include "inline-image.h" | ||
153 : | |||
154 : | jhr | 1640 | /********** other math functions **********/ |
155 : | int Diderot_evals2x2 ( | ||
156 : | Diderot_real_t eval[2], | ||
157 : | const Diderot_real_t _M00, const Diderot_real_t _M01, | ||
158 : | const Diderot_real_t _M11); | ||
159 : | int Diderot_evecs2x2 ( | ||
160 : | Diderot_real_t eval[2], Diderot_vec2_t evec[2], | ||
161 : | const Diderot_real_t _M00, const Diderot_real_t _M01, | ||
162 : | const Diderot_real_t _M11); | ||
163 : | int Diderot_evals3x3 ( | ||
164 : | Diderot_real_t eval[3], | ||
165 : | const Diderot_real_t _M00, const Diderot_real_t _M01, const Diderot_real_t _M02, | ||
166 : | const Diderot_real_t _M11, const Diderot_real_t _M12, | ||
167 : | const Diderot_real_t _M22); | ||
168 : | int Diderot_evecs3x3 ( | ||
169 : | Diderot_real_t eval[3], Diderot_vec3_t evecs[3], | ||
170 : | const Diderot_real_t _M00, const Diderot_real_t _M01, const Diderot_real_t _M02, | ||
171 : | const Diderot_real_t _M11, const Diderot_real_t _M12, | ||
172 : | const Diderot_real_t _M22); | ||
173 : | |||
174 : | jhr | 1115 | #endif /* !_DIDEROT_H_ */ |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |