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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1716 - (download) (as text) (annotate)
Sat Mar 10 17:08:11 2012 UTC (7 years, 6 months ago) by jhr
File size: 5209 byte(s)
  Working on library support
/*! \file diderot.h
 *
 * \author John Reppy
 *
 * This is the interface to the Diderot runtime for the C target.  For now,
 * we are targetting single-precision computations.
 */

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

#ifndef _DIDEROT_H_
#define _DIDEROT_H_

#include "Diderot/config.h"

// include OpenCL headers when the target is OpenCL
#if defined(DIDEROT_TARGET_CL)
# ifdef HAVE_CL_CL_H
#   include <CL/cl.h>
# elif defined(HAVE_OPENCL_CL_H)
#   include <OpenCL/cl.h>
# else
#   error no cl.h
# endif
#endif

/* gcc has a bug that breaks code that uses 8-byte vectors (e.g., vec2f_t), but clang
 * handles the code correctly.
 */
#if defined(__clang__)
#  define VEC2_OK
#endif

#ifdef NDEBUG
#define STATIC_INLINE   static inline
#else
#define STATIC_INLINE   static
#endif

#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>  // for printing output
#include <string.h>
#include "teem/air.h"
#include "teem/nrrd.h"

#include "types.h"
#include "world.h"
#include "strands.h"
#include "options.h"
//#include "output.h"

/* load image data from Nrrd files */
extern Status_t Diderot_LoadImage1D (Diderot_string_t name, Diderot_image1D_t **img);
extern Status_t Diderot_LoadImage2D (Diderot_string_t name, Diderot_image2D_t **img);
extern Status_t Diderot_LoadImage3D (Diderot_string_t name, Diderot_image3D_t **img);

#ifdef DIDEROT_TARGET_CL
#include "shadow-types.h"
#endif

//! Summary information about the CPU configuration.
typedef struct {
    int         numHWNodes;             //!< \brief number of (possibly multicore) processors
    int         numHWCores;             //!< \brief total number of (possibly
                                        //!  mulithreaded) cores
    int         numHWThreads;           //!< \brief total number of hardware threads
    int         numCoresPerNode;        //!< \brief number of cores per thread
    int         numThdsPerCore;         //!< \brief number of threads per core
} CPUInfo_t;

//! \brief function to get information about the CPU configuration
bool GetNumCPUs (CPUInfo_t *info);

//! Checked memory allocation
STATIC_INLINE void *CheckedAlloc (size_t szb)
{
    void *p = malloc(szb);
    if (p == 0) {
        fprintf (stderr, "fatal error: unable to allocate %d bytes of memory\n", (int)szb);
        exit (1);
    }
    return p;
}

#define NEW(ty)         (ty *)CheckedAlloc(sizeof(ty))
#define NEWVEC(ty,n)    (ty *)CheckedAlloc(sizeof(ty) * (n))
#define NEWSTR(s)       strcpy((char *)CheckedAlloc(strlen(s)+1), s)

/* dynamic sequences */
#include "dyn-seq.h"


/********** scalar math functions **********/

STATIC_INLINE Diderot_real_t min (Diderot_real_t a, Diderot_real_t b)
{
    return (a < b) ? a : b;
}

STATIC_INLINE Diderot_real_t max (Diderot_real_t a, Diderot_real_t b)
{
    return (a < b) ? b : a;
}

STATIC_INLINE Diderot_real_t clamp (Diderot_real_t lo, Diderot_real_t hi, Diderot_real_t x)
{
    return min(max(lo, x), hi);
}

STATIC_INLINE Diderot_real_t lerp (Diderot_real_t a, Diderot_real_t b, Diderot_real_t t)
{
    return a + t*(b - a);
}

#if defined(DIDEROT_SINGLE_PRECISION)
#  define EPSILON       1.0E-12
#  define ABS(x)        fabsf(x)
#  define ATAN2(x,y)	atan2f(x,y)
#  define CBRT(x)	cbrtf(x)
#  define COS(x)        cosf(x)
#  define FLOOR(x)      floorf(x)
#  define SIN(x)        sinf(x)
#  define SQRT(x)       sqrtf(x)
#  define TRUNC(x)      truncf(x)
#elif defined(DIDEROT_DOUBLE_PRECISION)
#  define EPSILON       1.0E-12
#  define ABS(x)        fabs(x)
#  define ATAN2(x,y)    atan2(x,y)
#  define CBRT(x)       cbrt(x)
#  define COS(x)        cos(x)
#  define FLOOR(x)      floor(x)
#  define SIN(x)        sin(x)
#  define SQRT(x)       sqrt(x)
#  define TRUNC(x)      trunc(x)
#else
#  error floating-point precision unknown
#endif

/********** vector math functions **********/

#include "inline-vec2.h"
#include "inline-vec3.h"
#include "inline-vec4.h"
#include "inline-matrix.h"

/********** other Diderot support functions **********/

#include "inline-image.h"

/********** other math functions **********/
int Diderot_evals2x2 (
    Diderot_real_t eval[2],
    const Diderot_real_t _M00, const Diderot_real_t _M01,
                               const Diderot_real_t _M11);
int Diderot_evecs2x2 (
    Diderot_real_t eval[2], Diderot_vec2_t evec[2],
    const Diderot_real_t _M00, const Diderot_real_t _M01,
                               const Diderot_real_t _M11);
int Diderot_evals3x3 (
    Diderot_real_t eval[3],
    const Diderot_real_t _M00, const Diderot_real_t _M01, const Diderot_real_t _M02, 
                               const Diderot_real_t _M11, const Diderot_real_t _M12, 
                                                          const Diderot_real_t _M22);
int Diderot_evecs3x3 (
    Diderot_real_t eval[3], Diderot_vec3_t evecs[3],
    const Diderot_real_t _M00, const Diderot_real_t _M01, const Diderot_real_t _M02, 
                               const Diderot_real_t _M11, const Diderot_real_t _M12, 
                                                          const Diderot_real_t _M22);

#endif /* !_DIDEROT_H_ */

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