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

SCM Repository

[diderot] Annotation of /branches/pure-cfg/src/include/Diderot/diderot.h
ViewVC logotype

Annotation of /branches/pure-cfg/src/include/Diderot/diderot.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1557 - (view) (download) (as text)

1 : jhr 438 /*! \file diderot.h
2 :     *
3 :     * \author John Reppy
4 : jhr 441 *
5 :     * This is the interface to the Diderot runtime for the C target. For now,
6 :     * we are targetting single-precision computations.
7 : jhr 438 */
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 1196 #include "Diderot/config.h"
18 :    
19 : jhr 1273 // 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 601 /* gcc has a bug that breaks code that uses 8-byte vectors (e.g., vec2f_t), but clang
31 :     * handles the code correctly.
32 :     */
33 :     #if defined(__clang__)
34 :     # define VEC2_OK
35 :     #endif
36 :    
37 : jhr 579 #ifdef NDEBUG
38 : jhr 1268 #define STATIC_INLINE static inline
39 : jhr 579 #else
40 : jhr 1268 #define STATIC_INLINE static
41 : jhr 579 #endif
42 : jhr 440
43 : jhr 1519 #include <assert.h>
44 : jhr 438 #include <stdint.h>
45 :     #include <stdbool.h>
46 : jhr 558 #include <stdlib.h>
47 :     #include <math.h>
48 : jhr 654 #include <stdio.h> // for printing output
49 : nseltzer 1449 #include <string.h>
50 : jhr 438
51 : jhr 710 #include "types.h"
52 : jhr 1519 #include "world.h"
53 : jhr 710 #include "strands.h"
54 : jhr 1237 #include "options.h"
55 : nseltzer 1479 #include "output.h"
56 : jhr 438
57 :     /* load image data from Nrrd files */
58 : jhr 561 extern Status_t Diderot_LoadImage1D (Diderot_string_t name, Diderot_image1D_t **img);
59 :     extern Status_t Diderot_LoadImage2D (Diderot_string_t name, Diderot_image2D_t **img);
60 :     extern Status_t Diderot_LoadImage3D (Diderot_string_t name, Diderot_image3D_t **img);
61 : jhr 438
62 : jhr 1282 #ifdef DIDEROT_TARGET_CL
63 : jhr 1354 #include "shadow-types.h"
64 : jhr 1282 #endif
65 : jhr 438
66 : jhr 1268 //! Summary information about the CPU configuration.
67 : jhr 1196 typedef struct {
68 : jhr 1268 int numHWNodes; //!< \brief number of (possibly multicore) processors
69 :     int numHWCores; //!< \brief total number of (possibly
70 :     //! mulithreaded) cores
71 :     int numHWThreads; //!< \brief total number of hardware threads
72 :     int numCoresPerNode; //!< \brief number of cores per thread
73 :     int numThdsPerCore; //!< \brief number of threads per core
74 : jhr 1196 } CPUInfo_t;
75 :    
76 : jhr 1268 //! \brief function to get information about the CPU configuration
77 : jhr 1196 bool GetNumCPUs (CPUInfo_t *info);
78 :    
79 : jhr 1276 //! get the current time in seconds
80 :     double GetTime ();
81 : jhr 1196
82 : jhr 1472 //! Checked memory allocation
83 :     STATIC_INLINE void *CheckedAlloc (size_t szb)
84 :     {
85 :     void *p = malloc(szb);
86 :     if (p == 0) {
87 :     fprintf (stderr, "fatal error: unable to allocate %d bytes of memory\n", (int)szb);
88 :     exit (1);
89 :     }
90 :     return p;
91 :     }
92 : jhr 1276
93 : jhr 1472 #define NEW(ty) (ty *)CheckedAlloc(sizeof(ty))
94 :     #define NEWVEC(ty,n) (ty *)CheckedAlloc(sizeof(ty) * (n))
95 :     #define NEWSTR(s) strcpy((char *)CheckedAlloc(strlen(s)+1), s)
96 :    
97 :    
98 : jhr 561 /********** scalar math functions **********/
99 :    
100 : glk 758 STATIC_INLINE float minf (float a, float b)
101 :     {
102 : jhr 1297 return (a < b) ? a : b;
103 : glk 758 }
104 :    
105 : jhr 561 STATIC_INLINE float maxf (float a, float b)
106 :     {
107 : jhr 1297 return (a < b) ? b : a;
108 : jhr 561 }
109 :    
110 : jhr 1297 STATIC_INLINE float clampf (float lo, float hi, float x)
111 :     {
112 :     return minf(maxf(lo, x), hi);
113 :     }
114 :    
115 : jhr 756 STATIC_INLINE float lerpf (float a, float b, float t)
116 :     {
117 :     return a + t*(b - a);
118 :     }
119 :    
120 : jhr 710 /********** vector math functions **********/
121 : jhr 588
122 : jhr 710 #include "inline-vec2.h"
123 :     #include "inline-vec3.h"
124 :     #include "inline-vec4.h"
125 : jhr 727 #include "inline-matrix.h"
126 : jhr 588
127 : jhr 560 /********** other Diderot support functions **********/
128 :    
129 : jhr 710 #include "inline-image.h"
130 : jhr 449
131 : jhr 1557 /********** other math functions **********/
132 :     int Diderot_evals2x2 (
133 :     Diderot_real_t eval[2],
134 :     const Diderot_real_t _M00, const Diderot_real_t _M01,
135 :     const Diderot_real_t _M11);
136 :     int Diderot_evecs2x2 (
137 :     Diderot_real_t eval[2], Diderot_vec2_t evec[2],
138 :     const Diderot_real_t _M00, const Diderot_real_t _M01,
139 :     const Diderot_real_t _M11);
140 :     int Diderot_evals3x3 (
141 :     Diderot_real_t eval[3],
142 :     const Diderot_real_t _M00, const Diderot_real_t _M01, const Diderot_real_t _M02,
143 :     const Diderot_real_t _M11, const Diderot_real_t _M12,
144 :     const Diderot_real_t _M22);
145 :     int Diderot_evecs3x3 (
146 :     Diderot_real_t eval[3], Diderot_vec3_t evecs[3],
147 :     const Diderot_real_t _M00, const Diderot_real_t _M01, const Diderot_real_t _M02,
148 :     const Diderot_real_t _M11, const Diderot_real_t _M12,
149 :     const Diderot_real_t _M22);
150 :    
151 : jhr 438 #endif /* !_DIDEROT_H_ */

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