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/ocl-support.h
ViewVC logotype

View of /branches/vis12-cl/src/include/Diderot/ocl-support.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 ago) by jhr
File size: 6032 byte(s)
  working on OpenCL issues
/*! \file ocl-support.h
 * \author John Reppy

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

#ifndef _OCL_SUPPORT_
#define _OCL_SUPPORT_

#include "Diderot/config.h"
# 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
#include <stdio.h>
#include <stdbool.h>

#  include "world.h"

typedef struct {
    unsigned short  index[2];		//!< the platform/device index of the device
    char            *name;              //!< name of device
    char            *vendor;            //!< device vendor
    int             majorVersion;       //!< major OpenCL version number supported by the device
    int             minorVersion;       //!< minor OpenCL version number supported by the device
    cl_device_id    id;                 //!< the device ID
    cl_device_type  ty;                 //!< the type of the device
    cl_bool         isAvail;            //!< true, if the device is available
    cl_uint         addrBits;           //!< number of address bits on device (32 or 64)
    cl_bool         littleEndian;       //!< true if device is little endian
    cl_uint         numCUs;             //!< number of compute units
    cl_uint         cuWidth;            //!< width of a compute unit; this value is determined
                                        //!  by looking at the device type and vendor string.
    cl_uint         maxConstArgs;       //!< maximum number of __constant arguments
    cl_uint         maxWIDims;          //!< maximum number of work item dimensions
    size_t          maxWGSize;          //!< maximum workgroup size
    size_t          *maxWISize;         //!< maximum number of work items in each dimension
    cl_ulong        globalMemSzb;       //!< the size of the device's global memory
    cl_ulong        localMemSzb;        //!< the size of the device's local memory
    size_t          maxParamSzb;        //!< the maximum size in bytes of the kernel arguments
    cl_ulong        maxConstBufSzb;     //!< maximum size of a constant buffer
    cl_ulong        maxAllocSzb;        //!< maximum allocation size in bytes
    size_t          maxImg2D[2];        //!< maximum width and height of 2D images
    size_t          maxImg3D[3];        //!< maximim width, height, and depthe of 3D images
                                        // prefered vector widths by type:
    cl_uint         charWid;            //!< prefered width of char vectors
    cl_uint         shortWid;           //!< prefered width of short vectors
    cl_uint         intWid;             //!< prefered width of int vectors
    cl_uint         longWid;            //!< prefered width of long vectors
    cl_uint         floatWid;           //!< prefered width of float vectors
    cl_uint         doubleWid;          //!< prefered width of double vectors
                                        //!  (0 if doubles are not supported)
} Diderot_DeviceInfo_t;

typedef struct {
    char            *name;              //!< name of platform
    cl_platform_id  id;                 //! the platform ID
    int             numDevices;         //!< number of devices supported by platform
    Diderot_DeviceInfo_t *devices;	//!< array of devices
} Diderot_PlatformInfo_t;

typedef struct {
    int             numPlatforms;       //!< number of platforms supported by system
    Diderot_PlatformInfo_t *platforms;	//!< array of supported platforms.
} Diderot_OCLInfo_t;

// sizes of the various GPU-side data structures
// Note: this structure must match the definition in cl-target/fragments/cl-sizes.in
typedef struct {
    cl_uint	schedSzB;	// size of SchedState_t
    cl_uint	strandBlkSzB;	// size of StrandBlock_t
    cl_uint	globSzB;	// size of globals buffer
    cl_uint	stateSzB;	// size of strand type
} Diderot_Sizes_t;

// extension of the WorldPrefix_t struct with common OpenCL components
typedef struct {
    Diderot_OCLInfo_t	*oclInfo;
    cl_int		gpuDevId;
    Diderot_DeviceInfo_t *device;
    uint32_t		nWorkers;
    Diderot_Sizes_t	oclSizes;
    cl_program		prog;
    cl_command_queue	cmdQ;
    cl_context		context;
} OCLWorldPrefix_t;

/*! \brief return information about the OpenCL support of the system.
 *  \return pointer to a CLInfo_t structure or 0 if there is an error.
Diderot_OCLInfo_t *Diderot_GetCLInfo (WorldPrefix_t *wrld);

/*! \brief return the device with the given index.
Diderot_DeviceInfo_t *Diderot_GetDeviceByIndex (Diderot_OCLInfo_t *oclinfo, unsigned int platIdx, unsigned int devIdx);

/*! \brief return the default device for the system.
Diderot_DeviceInfo_t *Diderot_DefaultCLDevice (Diderot_OCLInfo_t *oclinfo);

/*! \brief print the CL profile information to an output stream.
void Diderot_PrintCLInfo (FILE *outS, Diderot_OCLInfo_t *oclinfo);

/*! \brief check to see if a device is a GPU */
STATIC_INLINE bool Diderot_isGPUDevice (Diderot_DeviceInfo_t *dev)
    return ((dev->ty & CL_DEVICE_TYPE_GPU) != 0);

/*! \brief check to see if a device is a CPU */
STATIC_INLINE bool Diderot_isCPUDevice (Diderot_DeviceInfo_t *dev)
    return ((dev->ty & CL_DEVICE_TYPE_CPU) != 0);

/*! \brief load an OpenCL program from a source file.
cl_program Diderot_LoadProgramFromSource (WorldPrefix_t *wrld, cl_context cxt, const char *filename, cl_int *status);

/*! \brief return a string representation of an OpenCL error.
const char *Diderot_OCLErrorString (cl_int sts);

/***** CPU-side image initialization routines *****/

bool Diderot_LoadGPUImage1D (OCLWorldPrefix_t *wrld, cl_mem globals, const char *imgName, cl_kernel initKern, cl_mem *objOut);
bool Diderot_LoadGPUImage2D (OCLWorldPrefix_t *wrld, cl_mem globals, const char *imgName, cl_kernel initKern, cl_mem *objOut);
bool Diderot_LoadGPUImage3D (OCLWorldPrefix_t *wrld, cl_mem globals, const char *imgName, cl_kernel initKern, cl_mem *objOut);

#endif /* !_OCL_SUPPORT_ */

ViewVC Help
Powered by ViewVC 1.0.0