Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis12/src/include/Diderot/diderot.h
ViewVC logotype

Annotation of /branches/vis12/src/include/Diderot/diderot.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1979 - (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 1831 #ifdef DIDEROT_TARGET_PARALLEL
31 :     # include <pthread.h>
32 :     #endif
33 :    
34 : jhr 1978 #if defined (DIDEROT_SINGLE_PRECISION)
35 :     # define SIZEOF_DIDEROT_REAL 4
36 : jhr 1979 #elif defined (DIDEROT_DOUBLE_PRECISION)
37 : jhr 1978 # define SIZEOF_DIDEROT_REAL 8
38 :     #else
39 :     # error must define either DIDEROT_SINGLE_PRECISION or DIDEROT_SINGLE_PRECISION
40 :     #endif
41 :     #if defined (DIDEROT_INT)
42 :     # define SIZEOF_DIDEROT_INT 4
43 :     #elif defined (DIDEROT_LONGINT)
44 :     # define SIZEOF_DIDEROT_INT 8
45 :     #else
46 : jhr 1979 # error must define either DIDEROT_INT or DIDEROT_LONGINT
47 : jhr 1978 #endif
48 :    
49 : jhr 1115 /* gcc has a bug that breaks code that uses 8-byte vectors (e.g., vec2f_t), but clang
50 :     * handles the code correctly.
51 :     */
52 : jhr 1941 #if defined(__clang__) || defined(DIDEROT_DOUBLE_PRECISION)
53 : jhr 1115 # define VEC2_OK
54 :     #endif
55 :    
56 :     #ifdef NDEBUG
57 : jhr 1295 #define STATIC_INLINE static inline
58 : jhr 1115 #else
59 : jhr 1295 #define STATIC_INLINE static
60 : jhr 1115 #endif
61 :    
62 : jhr 1640 #include <assert.h>
63 : jhr 1115 #include <stdint.h>
64 :     #include <stdbool.h>
65 :     #include <stdlib.h>
66 :     #include <math.h>
67 :     #include <stdio.h> // for printing output
68 : jhr 1640 #include <string.h>
69 :     #include "teem/air.h"
70 : jhr 1716 #include "teem/nrrd.h"
71 : jhr 1824 #include "teem/biff.h"
72 : jhr 1115
73 :     #include "types.h"
74 : jhr 1640 #include "world.h"
75 : jhr 1115 #include "strands.h"
76 : jhr 1301 #include "options.h"
77 : jhr 1115
78 :     /* load image data from Nrrd files */
79 : jhr 1807 extern Status_t Diderot_SetImage1D (WorldPrefix_t *wrld, Nrrd *nin, Diderot_image1D_t **imgOut);
80 :     extern Status_t Diderot_LoadImage1D (WorldPrefix_t *wrld, Diderot_string_t name, Diderot_image1D_t **img);
81 : nseltzer 1870 extern Status_t Diderot_FreeImage1D (WorldPrefix_t *wrld, Diderot_image1D_t **img);
82 : jhr 1807 extern Status_t Diderot_SetImage2D (WorldPrefix_t *wrld, Nrrd *nin, Diderot_image2D_t **imgOut);
83 :     extern Status_t Diderot_LoadImage2D (WorldPrefix_t *wrld, Diderot_string_t name, Diderot_image2D_t **img);
84 : nseltzer 1870 extern Status_t Diderot_FreeImage2D (WorldPrefix_t *wrld, Diderot_image2D_t **img);
85 : jhr 1807 extern Status_t Diderot_LoadImage3D (WorldPrefix_t *wrld, Diderot_string_t name, Diderot_image3D_t **img);
86 : nseltzer 1870 extern Status_t Diderot_FreeImage3D (WorldPrefix_t *wrld, Diderot_image3D_t **img);
87 : jhr 1115
88 : jhr 1380 #ifdef DIDEROT_TARGET_CL
89 :     #include "shadow-types.h"
90 :     #endif
91 : jhr 1232
92 : jhr 1831 #ifdef DIDEROT_TARGET_PARALLEL
93 : jhr 1295 //! Summary information about the CPU configuration.
94 : jhr 1232 typedef struct {
95 : jhr 1295 int numHWNodes; //!< \brief number of (possibly multicore) processors
96 :     int numHWCores; //!< \brief total number of (possibly
97 :     //! mulithreaded) cores
98 :     int numHWThreads; //!< \brief total number of hardware threads
99 :     int numCoresPerNode; //!< \brief number of cores per thread
100 :     int numThdsPerCore; //!< \brief number of threads per core
101 : jhr 1232 } CPUInfo_t;
102 :    
103 : jhr 1295 //! \brief function to get information about the CPU configuration
104 : jhr 1831 //! \return true if there is an error
105 :     bool Diderot_GetNumCPUs (CPUInfo_t *info);
106 :     #endif
107 : jhr 1232
108 : jhr 1640 //! Checked memory allocation
109 :     STATIC_INLINE void *CheckedAlloc (size_t szb)
110 :     {
111 :     void *p = malloc(szb);
112 :     if (p == 0) {
113 :     fprintf (stderr, "fatal error: unable to allocate %d bytes of memory\n", (int)szb);
114 :     exit (1);
115 :     }
116 :     return p;
117 :     }
118 : jhr 1232
119 : jhr 1640 #define NEW(ty) (ty *)CheckedAlloc(sizeof(ty))
120 :     #define NEWVEC(ty,n) (ty *)CheckedAlloc(sizeof(ty) * (n))
121 :     #define NEWSTR(s) strcpy((char *)CheckedAlloc(strlen(s)+1), s)
122 : jhr 1718 #define FREE(p) do { if (p != 0) free(p); } while(0)
123 : jhr 1301
124 : jhr 1115 /********** scalar math functions **********/
125 :    
126 : jhr 1640 STATIC_INLINE Diderot_real_t min (Diderot_real_t a, Diderot_real_t b)
127 : jhr 1115 {
128 : jhr 1295 return (a < b) ? a : b;
129 : jhr 1115 }
130 :    
131 : jhr 1640 STATIC_INLINE Diderot_real_t max (Diderot_real_t a, Diderot_real_t b)
132 : jhr 1115 {
133 : jhr 1295 return (a < b) ? b : a;
134 : jhr 1115 }
135 :    
136 : jhr 1640 STATIC_INLINE Diderot_real_t clamp (Diderot_real_t lo, Diderot_real_t hi, Diderot_real_t x)
137 : jhr 1295 {
138 : jhr 1640 return min(max(lo, x), hi);
139 : jhr 1295 }
140 :    
141 : jhr 1640 STATIC_INLINE Diderot_real_t lerp (Diderot_real_t a, Diderot_real_t b, Diderot_real_t t)
142 : jhr 1115 {
143 :     return a + t*(b - a);
144 :     }
145 :    
146 : jhr 1640 #if defined(DIDEROT_SINGLE_PRECISION)
147 :     # define EPSILON 1.0E-12
148 :     # define ABS(x) fabsf(x)
149 :     # define ATAN2(x,y) atan2f(x,y)
150 :     # define CBRT(x) cbrtf(x)
151 :     # define COS(x) cosf(x)
152 :     # define FLOOR(x) floorf(x)
153 :     # define SIN(x) sinf(x)
154 :     # define SQRT(x) sqrtf(x)
155 :     # define TRUNC(x) truncf(x)
156 :     #elif defined(DIDEROT_DOUBLE_PRECISION)
157 :     # define EPSILON 1.0E-12
158 :     # define ABS(x) fabs(x)
159 :     # define ATAN2(x,y) atan2(x,y)
160 :     # define CBRT(x) cbrt(x)
161 :     # define COS(x) cos(x)
162 :     # define FLOOR(x) floor(x)
163 :     # define SIN(x) sin(x)
164 :     # define SQRT(x) sqrt(x)
165 :     # define TRUNC(x) trunc(x)
166 :     #else
167 :     # error floating-point precision unknown
168 :     #endif
169 :    
170 : jhr 1115 /********** vector math functions **********/
171 :    
172 :     #include "inline-vec2.h"
173 :     #include "inline-vec3.h"
174 :     #include "inline-vec4.h"
175 : jhr 1943 #include "inline-vec6.h"
176 : jhr 1115 #include "inline-matrix.h"
177 : jhr 1796 #include "inline-tensor3.h"
178 : jhr 1115
179 :     /********** other Diderot support functions **********/
180 :    
181 :     #include "inline-image.h"
182 : jhr 1978 #include "dyn-seq.h"
183 : jhr 1115
184 : jhr 1640 /********** other math functions **********/
185 :     int Diderot_evals2x2 (
186 :     Diderot_real_t eval[2],
187 :     const Diderot_real_t _M00, const Diderot_real_t _M01,
188 :     const Diderot_real_t _M11);
189 :     int Diderot_evecs2x2 (
190 :     Diderot_real_t eval[2], Diderot_vec2_t evec[2],
191 :     const Diderot_real_t _M00, const Diderot_real_t _M01,
192 :     const Diderot_real_t _M11);
193 :     int Diderot_evals3x3 (
194 :     Diderot_real_t eval[3],
195 :     const Diderot_real_t _M00, const Diderot_real_t _M01, const Diderot_real_t _M02,
196 :     const Diderot_real_t _M11, const Diderot_real_t _M12,
197 :     const Diderot_real_t _M22);
198 :     int Diderot_evecs3x3 (
199 :     Diderot_real_t eval[3], Diderot_vec3_t evecs[3],
200 :     const Diderot_real_t _M00, const Diderot_real_t _M01, const Diderot_real_t _M02,
201 :     const Diderot_real_t _M11, const Diderot_real_t _M12,
202 :     const Diderot_real_t _M22);
203 :    
204 : jhr 1115 #endif /* !_DIDEROT_H_ */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0