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

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