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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3118 - (download) (as text) (annotate)
Mon Mar 23 18:05:45 2015 UTC (4 years, 1 month ago) by jhr
File size: 7420 byte(s)
  working on OpenCL issues
/*! \file shadow-types.h
 *
 * \author John Reppy
 *
 * Type definitions for the shadow globals.
 */

/*
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 */

#ifndef _SHADOW_TYPES_H_
#define _SHADOW_TYPES_H_

#if defined(CL_VERSION_1_1)
#  define HAS_VEC3_TYPE
#endif

#if defined(DIDEROT_SINGLE_PRECISION)
typedef cl_float Shadow_real_t;
typedef cl_float2 Shadow_vec2_t;
#ifdef HAS_VEC3_TYPE
typedef cl_float3 Shadow_vec3_t;
#else
typedef cl_float4 Shadow_vec3_t;
#endif
typedef cl_float4 Shadow_vec4_t;
#else
typedef cl_double Shadow_real_t;
typedef cl_double2 Shadow_vec2_t;
#ifdef HAS_VEC3_TYPE
typedef cl_double3 Shadow_vec3_t;
#else
typedef cl_double4 Shadow_vec3_t;
#endif
typedef cl_double4 Shadow_vec4_t;
#endif
typedef Shadow_vec2_t Shadow_Mat2x2_t[2];
typedef Shadow_vec3_t Shadow_Mat3x3_t[3];
typedef Shadow_vec4_t Shadow_Mat4x4_t[4];

// OpenCL 1.0 does not specify the C representation of the host types
// for OpenCL vector types (e.g., cl_float4), so we have to handle this
// mechanism with a macro.
#if defined(CL_HOST_VECTORS_ARE_STRUCTS)
#  define VSUB(v,i)        (v).s[i]
#elif defined(CL_HOST_VECTORS_ARE_ARRAYS)
#  define VSUB(v,i)        (v)[i]
#else
# error unable to access elements of host vectors
#endif

// Shadow of GPU-side image types.  Note that these structs should have the same layout
// as the non-data prefix of the Diderot_image[123]D_t types defined in cl-types.h

//! shadow wrapper for 1D image meta-info
typedef struct {
    cl_int              size[1];
    Shadow_real_t       s;              //!< scaling from world-space to image-space
    Shadow_real_t       t;              //!< translation from world-space to image-space
} Shadow_image1D_t;

//! shadow wrapper for 2D image meta-info
typedef struct {
    cl_int              size[2];        //!< sizes (fast to slow)
    Shadow_Mat2x2_t     w2i;            //!< affine tranform from world space to index space.  This is the
                                        //!  inverse of the index to world-space transform that is loaded from
                                        //!  the Nrrd file.
    Shadow_vec2_t       tVec;           //!< translation part of world to index transform
    Shadow_Mat2x2_t     w2iT;           //!< transpose w3i
} Shadow_image2D_t;

//! shadow wrapper for 3D image meta-info
typedef struct {
    cl_int              size[3];        //!< sizes (fast to slow)
    Shadow_Mat3x3_t     w2i;            //!< affine tranform from world space to index space.  This is the
                                        //!  inverse of the index to world-space transform that is loaded from
                                        //!  the Nrrd file.
    Shadow_vec3_t       tVec;           //!< translation part of world to index transform
    Shadow_Mat3x3_t     w2iT;           //!< transpose w3i
} Shadow_image3D_t;

/*! \brief initialize a shadow 2D vector from a host vector.
 *  \param dst the shadow value to initialize (an array)
 *  \param src the host vector to shadow.
 */
STATIC_INLINE void ShadowVec2 (Shadow_vec2_t *dst, Diderot_vec2_t src)
{
    VSUB(*dst,0) = ((Diderot_union2_t)(src)).r[0];
    VSUB(*dst,1) = ((Diderot_union2_t)(src)).r[1];
}

/*! \brief initialize a shadow 3D vector from a host vector.
 *  \param dst the shadow value to initialize (an array)
 *  \param src the host vector to shadow.
 */
STATIC_INLINE void ShadowVec3 (Shadow_vec3_t *dst, Diderot_vec3_t src)
{

   VSUB(*dst,0) = ((Diderot_union3_t)(src)).r[0];
   VSUB(*dst,1) = ((Diderot_union3_t)(src)).r[1];
   VSUB(*dst,2) = ((Diderot_union3_t)(src)).r[2];
}

/*! \brief initialize a shadow 4D vector from a host vector.
 *  \param dst the shadow value to initialize (an array)
 *  \param src the host vector to shadow.
 */
STATIC_INLINE void ShadowVec4 (Shadow_vec4_t *dst, Diderot_vec4_t src)
{
    VSUB(*dst,0) = ((Diderot_union4_t)(src)).r[0];
    VSUB(*dst,1) = ((Diderot_union4_t)(src)).r[1];
    VSUB(*dst,2) = ((Diderot_union4_t)(src)).r[2];
    VSUB(*dst,3) = ((Diderot_union4_t)(src)).r[3];
}

/*! \brief initialize a shadow 2x2 matrix from a host matrix.
 *  \param dst the shadow value to initialize (an array of arrays)
 *  \param src the host matrix to shadow.
 */
STATIC_INLINE void ShadowMat2x2 (Shadow_Mat2x2_t dst, Diderot_Mat2x2_t src)
{
    ShadowVec2 (&dst[0], src[0].v);
    ShadowVec2 (&dst[1], src[1].v);
}

/*! \brief initialize a shadow 3x3 matrix from a host matrix.
 *  \param dst the shadow value to initialize (an array of arrays)
 *  \param src the host matrix to shadow.
 */
STATIC_INLINE void ShadowMat3x3 (Shadow_Mat3x3_t dst, Diderot_Mat3x3_t src)
{
    ShadowVec3 (&dst[0], src[0].v);
    ShadowVec3 (&dst[1], src[1].v);
    ShadowVec3 (&dst[2], src[2].v);
}

/*! \brief initialize a shadow 4x4 matrix from a host matrix.
 *  \param dst the shadow value to initialize (an array of arrays)
 *  \param src the host matrix to shadow.
 */
STATIC_INLINE void ShadowMat4x4 (Shadow_Mat4x4_t dst, Diderot_Mat4x4_t src)
{
    ShadowVec4 (&dst[0], src[0].v);
    ShadowVec4 (&dst[1], src[1].v);
    ShadowVec4 (&dst[2], src[2].v);
    ShadowVec4 (&dst[3], src[3].v);
}

/*! \brief initialize a shadow for a 1D image
 *  \param cxt the OpenCL context used to allocate the shadow buffer
 *  \param dst the pointer to the shadow image
 *  \param src the source image to shadow
 */
void ShadowImage1D (cl_context cxt, Shadow_image1D_t *dst, Diderot_image1D_t *img);

/*! \brief initialize a shadow for a 2D image
 *  \param cxt the OpenCL context used to allocate the shadow buffer
 *  \param dst the pointer to the shadow image
 *  \param src the source image to shadow
 */
void ShadowImage2D (cl_context cxt, Shadow_image2D_t *dst, Diderot_image2D_t *img);

/*! \brief initialize a shadow for a 3D image
 *  \param cxt the OpenCL context used to allocate the shadow buffer
 *  \param dst the pointer to the shadow image
 *  \param src the source image to shadow
 */
void ShadowImage3D (cl_context cxt, Shadow_image3D_t *dst, Diderot_image3D_t *img);

// the following functions are currently not used by the compiler or runtime;
// are they necessary?
#ifdef NEED_UNSHADOW_FUNCTIONS
/*! \brief initialize a host 2D vector from a shadow vector.
 *  \param dst the host value to initialize (an array)
 *  \param src the shadow vector (an array)
 */
STATIC_INLINE void UnshadowVec2 (Diderot_vec2_t dst, Shadow_vec2_t src)
{
    ((Diderot_union2_t)(dst)).r[0] = VSUB(src,0);
    ((Diderot_union2_t)(dst)).r[1] = VSUB(src,1);
}

/*! \brief initialize a host 3D vector from a shadow vector.
 *  \param dst the host value to initialize (an array)
 *  \param src the shadow vector (an array)
 */
STATIC_INLINE void UnshadowVec3 (Diderot_vec3_t dst, Shadow_vec3_t src)
{
    ((Diderot_union3_t)(dst)).r[0] = VSUB(src,0);
    ((Diderot_union3_t)(dst)).r[1] = VSUB(src,1);
    ((Diderot_union3_t)(dst)).r[2] = VSUB(src,2);
}

/*! \brief initialize a host 4D vector from a shadow vector.
 *  \param dst the host value to initialize (an array)
 *  \param src the shadow vector (an array)
 */
STATIC_INLINE void UnshadowVec4 (Diderot_vec4_t dst, Shadow_vec4_t src)
{
    ((Diderot_union4_t)(dst)).r[0] = VSUB(src,0);
    ((Diderot_union4_t)(dst)).r[1] = VSUB(src,1);
    ((Diderot_union4_t)(dst)).r[2] = VSUB(src,2);
    ((Diderot_union4_t)(dst)).r[3] = VSUB(src,3);
}
#endif /* NEED_UNSHADOW_FUNCTIONS */

#endif /* !_SHADOW_TYPES_H_ */

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