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

SCM Repository

[diderot] Annotation of /branches/vis12-cl/src/include/Diderot/shadow-types.h
ViewVC logotype

Annotation of /branches/vis12-cl/src/include/Diderot/shadow-types.h

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : jhr 1640 /*! \file shadow-types.h
2 :     *
3 :     * \author John Reppy
4 :     *
5 :     * Type definitions for the shadow globals.
6 :     */
7 :    
8 :     /*
9 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
10 :     * All rights reserved.
11 :     */
12 :    
13 :     #ifndef _SHADOW_TYPES_H_
14 :     #define _SHADOW_TYPES_H_
15 :    
16 :     #if defined(CL_VERSION_1_1)
17 :     # define HAS_VEC3_TYPE
18 :     #endif
19 :    
20 :     #if defined(DIDEROT_SINGLE_PRECISION)
21 :     typedef cl_float Shadow_real_t;
22 :     typedef cl_float2 Shadow_vec2_t;
23 :     #ifdef HAS_VEC3_TYPE
24 :     typedef cl_float3 Shadow_vec3_t;
25 :     #else
26 :     typedef cl_float4 Shadow_vec3_t;
27 :     #endif
28 :     typedef cl_float4 Shadow_vec4_t;
29 :     #else
30 :     typedef cl_double Shadow_real_t;
31 :     typedef cl_double2 Shadow_vec2_t;
32 :     #ifdef HAS_VEC3_TYPE
33 :     typedef cl_double3 Shadow_vec3_t;
34 :     #else
35 :     typedef cl_double4 Shadow_vec3_t;
36 :     #endif
37 :     typedef cl_double4 Shadow_vec4_t;
38 :     #endif
39 :     typedef Shadow_vec2_t Shadow_Mat2x2_t[2];
40 :     typedef Shadow_vec3_t Shadow_Mat3x3_t[3];
41 :     typedef Shadow_vec4_t Shadow_Mat4x4_t[4];
42 :    
43 :     // OpenCL 1.0 does not specify the C representation of the host types
44 :     // for OpenCL vector types (e.g., cl_float4), so we have to handle this
45 :     // mechanism with a macro.
46 :     #if defined(CL_HOST_VECTORS_ARE_STRUCTS)
47 :     # define VSUB(v,i) (v).s[i]
48 :     #elif defined(CL_HOST_VECTORS_ARE_ARRAYS)
49 :     # define VSUB(v,i) (v)[i]
50 :     #else
51 :     # error unable to access elements of host vectors
52 :     #endif
53 :    
54 : jhr 3118 // Shadow of GPU-side image types. Note that these structs should have the same layout
55 :     // as the non-data prefix of the Diderot_image[123]D_t types defined in cl-types.h
56 : jhr 1640
57 :     //! shadow wrapper for 1D image meta-info
58 :     typedef struct {
59 :     cl_int size[1];
60 :     Shadow_real_t s; //!< scaling from world-space to image-space
61 :     Shadow_real_t t; //!< translation from world-space to image-space
62 :     } Shadow_image1D_t;
63 :    
64 :     //! shadow wrapper for 2D image meta-info
65 :     typedef struct {
66 :     cl_int size[2]; //!< sizes (fast to slow)
67 :     Shadow_Mat2x2_t w2i; //!< affine tranform from world space to index space. This is the
68 :     //! inverse of the index to world-space transform that is loaded from
69 :     //! the Nrrd file.
70 :     Shadow_vec2_t tVec; //!< translation part of world to index transform
71 :     Shadow_Mat2x2_t w2iT; //!< transpose w3i
72 :     } Shadow_image2D_t;
73 :    
74 :     //! shadow wrapper for 3D image meta-info
75 :     typedef struct {
76 :     cl_int size[3]; //!< sizes (fast to slow)
77 :     Shadow_Mat3x3_t w2i; //!< affine tranform from world space to index space. This is the
78 :     //! inverse of the index to world-space transform that is loaded from
79 :     //! the Nrrd file.
80 :     Shadow_vec3_t tVec; //!< translation part of world to index transform
81 :     Shadow_Mat3x3_t w2iT; //!< transpose w3i
82 :     } Shadow_image3D_t;
83 :    
84 :     /*! \brief initialize a shadow 2D vector from a host vector.
85 :     * \param dst the shadow value to initialize (an array)
86 :     * \param src the host vector to shadow.
87 :     */
88 :     STATIC_INLINE void ShadowVec2 (Shadow_vec2_t *dst, Diderot_vec2_t src)
89 :     {
90 :     VSUB(*dst,0) = ((Diderot_union2_t)(src)).r[0];
91 :     VSUB(*dst,1) = ((Diderot_union2_t)(src)).r[1];
92 :     }
93 :    
94 :     /*! \brief initialize a shadow 3D vector from a host vector.
95 :     * \param dst the shadow value to initialize (an array)
96 :     * \param src the host vector to shadow.
97 :     */
98 :     STATIC_INLINE void ShadowVec3 (Shadow_vec3_t *dst, Diderot_vec3_t src)
99 :     {
100 :    
101 :     VSUB(*dst,0) = ((Diderot_union3_t)(src)).r[0];
102 :     VSUB(*dst,1) = ((Diderot_union3_t)(src)).r[1];
103 :     VSUB(*dst,2) = ((Diderot_union3_t)(src)).r[2];
104 :     }
105 :    
106 :     /*! \brief initialize a shadow 4D vector from a host vector.
107 :     * \param dst the shadow value to initialize (an array)
108 :     * \param src the host vector to shadow.
109 :     */
110 :     STATIC_INLINE void ShadowVec4 (Shadow_vec4_t *dst, Diderot_vec4_t src)
111 :     {
112 :     VSUB(*dst,0) = ((Diderot_union4_t)(src)).r[0];
113 :     VSUB(*dst,1) = ((Diderot_union4_t)(src)).r[1];
114 :     VSUB(*dst,2) = ((Diderot_union4_t)(src)).r[2];
115 :     VSUB(*dst,3) = ((Diderot_union4_t)(src)).r[3];
116 :     }
117 :    
118 :     /*! \brief initialize a shadow 2x2 matrix from a host matrix.
119 :     * \param dst the shadow value to initialize (an array of arrays)
120 :     * \param src the host matrix to shadow.
121 :     */
122 :     STATIC_INLINE void ShadowMat2x2 (Shadow_Mat2x2_t dst, Diderot_Mat2x2_t src)
123 :     {
124 :     ShadowVec2 (&dst[0], src[0].v);
125 :     ShadowVec2 (&dst[1], src[1].v);
126 :     }
127 :    
128 :     /*! \brief initialize a shadow 3x3 matrix from a host matrix.
129 :     * \param dst the shadow value to initialize (an array of arrays)
130 :     * \param src the host matrix to shadow.
131 :     */
132 :     STATIC_INLINE void ShadowMat3x3 (Shadow_Mat3x3_t dst, Diderot_Mat3x3_t src)
133 :     {
134 :     ShadowVec3 (&dst[0], src[0].v);
135 :     ShadowVec3 (&dst[1], src[1].v);
136 :     ShadowVec3 (&dst[2], src[2].v);
137 :     }
138 :    
139 :     /*! \brief initialize a shadow 4x4 matrix from a host matrix.
140 :     * \param dst the shadow value to initialize (an array of arrays)
141 :     * \param src the host matrix to shadow.
142 :     */
143 :     STATIC_INLINE void ShadowMat4x4 (Shadow_Mat4x4_t dst, Diderot_Mat4x4_t src)
144 :     {
145 :     ShadowVec4 (&dst[0], src[0].v);
146 :     ShadowVec4 (&dst[1], src[1].v);
147 :     ShadowVec4 (&dst[2], src[2].v);
148 :     ShadowVec4 (&dst[3], src[3].v);
149 :     }
150 :    
151 :     /*! \brief initialize a shadow for a 1D image
152 :     * \param cxt the OpenCL context used to allocate the shadow buffer
153 :     * \param dst the pointer to the shadow image
154 :     * \param src the source image to shadow
155 :     */
156 :     void ShadowImage1D (cl_context cxt, Shadow_image1D_t *dst, Diderot_image1D_t *img);
157 :    
158 :     /*! \brief initialize a shadow for a 2D image
159 :     * \param cxt the OpenCL context used to allocate the shadow buffer
160 :     * \param dst the pointer to the shadow image
161 :     * \param src the source image to shadow
162 :     */
163 :     void ShadowImage2D (cl_context cxt, Shadow_image2D_t *dst, Diderot_image2D_t *img);
164 :    
165 :     /*! \brief initialize a shadow for a 3D image
166 :     * \param cxt the OpenCL context used to allocate the shadow buffer
167 :     * \param dst the pointer to the shadow image
168 :     * \param src the source image to shadow
169 :     */
170 :     void ShadowImage3D (cl_context cxt, Shadow_image3D_t *dst, Diderot_image3D_t *img);
171 :    
172 :     // the following functions are currently not used by the compiler or runtime;
173 :     // are they necessary?
174 :     #ifdef NEED_UNSHADOW_FUNCTIONS
175 :     /*! \brief initialize a host 2D vector from a shadow vector.
176 :     * \param dst the host value to initialize (an array)
177 :     * \param src the shadow vector (an array)
178 :     */
179 :     STATIC_INLINE void UnshadowVec2 (Diderot_vec2_t dst, Shadow_vec2_t src)
180 :     {
181 :     ((Diderot_union2_t)(dst)).r[0] = VSUB(src,0);
182 :     ((Diderot_union2_t)(dst)).r[1] = VSUB(src,1);
183 :     }
184 :    
185 :     /*! \brief initialize a host 3D vector from a shadow vector.
186 :     * \param dst the host value to initialize (an array)
187 :     * \param src the shadow vector (an array)
188 :     */
189 :     STATIC_INLINE void UnshadowVec3 (Diderot_vec3_t dst, Shadow_vec3_t src)
190 :     {
191 :     ((Diderot_union3_t)(dst)).r[0] = VSUB(src,0);
192 :     ((Diderot_union3_t)(dst)).r[1] = VSUB(src,1);
193 :     ((Diderot_union3_t)(dst)).r[2] = VSUB(src,2);
194 :     }
195 :    
196 :     /*! \brief initialize a host 4D vector from a shadow vector.
197 :     * \param dst the host value to initialize (an array)
198 :     * \param src the shadow vector (an array)
199 :     */
200 :     STATIC_INLINE void UnshadowVec4 (Diderot_vec4_t dst, Shadow_vec4_t src)
201 :     {
202 :     ((Diderot_union4_t)(dst)).r[0] = VSUB(src,0);
203 :     ((Diderot_union4_t)(dst)).r[1] = VSUB(src,1);
204 :     ((Diderot_union4_t)(dst)).r[2] = VSUB(src,2);
205 :     ((Diderot_union4_t)(dst)).r[3] = VSUB(src,3);
206 :     }
207 :     #endif /* NEED_UNSHADOW_FUNCTIONS */
208 :    
209 :     #endif /* !_SHADOW_TYPES_H_ */

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