Commit 560db636 by Maxime Grégoire

Added OpenCL project, heavily based on GSOC Clover project

Change-Id: I77e5d5fe63c436292a207b0630f01a3a898b5b1d Reviewed-on: https://swiftshader-review.googlesource.com/3470Reviewed-by: 's avatarMaxime Grégoire <mgregoire@google.com> Tested-by: 's avatarMaxime Grégoire <mgregoire@google.com>
parent f0338bbc
# Ignored folders by git #
/lib/
/x64/
/Debug/
# Ignored files #
*.opensdf
*.filters
*.user
*.cache
*.exp
*.ipch
*.obj
*.log
*.tlog
*.exe
*.ilk
*.pdb
*.sbr
*.bsc
*.res
*.idb
*.sdf
*.suo
*.o
*.depend
*.layout
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{50F99088-AF0E-4A66-9619-E3FF87F3B246}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>HelloTriangle</RootNamespace>
<ProjectName>HelloWorld</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<PrecompiledHeaderFile />
<AdditionalIncludeDirectories>..\OpenCL1;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\OpenCL1;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\OpenCL1;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\OpenCL1;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="HelloWorld.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenCL1\OpenCL1.vcxproj">
<Project>{eabbe82d-cdd3-4be2-8a29-b5bf4569b723}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
// HelloTriangle.cpp : Defines the entry point for the console application.
//
#include "opencl.h"
#include <stdio.h>
#include <tchar.h>
#include <stddef.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <assert.h>
#define NUM_OF_EVENTS 100
#define BUFFER_SIZE 16777216
void getAttributes(cl_platform_id * platformIDs)
{
size_t infoSize;
char * info;
const cl_platform_info attributeTypes[5] = {
CL_PLATFORM_NAME,
CL_PLATFORM_VENDOR,
CL_PLATFORM_VERSION,
CL_PLATFORM_PROFILE,
CL_PLATFORM_EXTENSIONS };
for(int j = 0; j < 5; j++)
{
// get platform attribute value size
cl_int res5 = clGetPlatformInfo(platformIDs[0], attributeTypes[j], 0, NULL, &infoSize);
info = (char*)malloc(infoSize);
assert(res5 == CL_SUCCESS);
// get platform attribute value
cl_int res6 = clGetPlatformInfo(platformIDs[0], attributeTypes[j], infoSize, info, NULL);
assert(res6 == CL_SUCCESS);
}
}
int main(int argc, char **argv){
cl_uint num_platforms1;
cl_uint num_platforms2;
cl_platform_id * platformIDs;
cl_int res1 = clGetPlatformIDs(0, NULL, &num_platforms1);
assert(res1 == CL_SUCCESS);
cl_int res2 = clGetPlatformIDs(0, NULL, &num_platforms2);
assert(res2 == CL_SUCCESS);
platformIDs = (cl_platform_id *)alloca(
sizeof(cl_platform_id) * num_platforms2);
platformIDs[0] = 0;
cl_int res3 = clGetPlatformIDs(num_platforms2, platformIDs, &num_platforms2);
assert(res3 == CL_SUCCESS);
getAttributes(platformIDs);
size_t siz;
const cl_platform_info attributeTypes[5] = {
CL_PLATFORM_NAME,
CL_PLATFORM_VENDOR,
CL_PLATFORM_VERSION,
CL_PLATFORM_PROFILE,
CL_PLATFORM_EXTENSIONS };
char * info;
for(int j = 0; j < 5; j++)
{
// get platform attribute value size
clGetPlatformInfo(platformIDs[0], attributeTypes[j], 0, NULL, &siz);
info = (char*)malloc(siz);
// get platform attribute value
clGetPlatformInfo(platformIDs[0], attributeTypes[j], siz, info, NULL);
}
cl_uint num_devices;
cl_int res4 = clGetDeviceIDs(platformIDs[0], 4, 0, NULL, &num_devices);
assert(res4 == CL_SUCCESS);
cl_device_id * devices;
devices = (cl_device_id *)alloca(
sizeof(cl_device_id) * num_devices);
devices[0] = 0;
cl_int res5 = clGetDeviceIDs(platformIDs[0], 4, 1, devices, NULL);
assert(res5 == CL_SUCCESS);
cl_int errcode_ret;
cl_context_properties contextProperties[] =
{
CL_CONTEXT_PLATFORM,
(cl_context_properties)platformIDs[0],
CL_WGL_HDC_KHR,
0,
CL_GL_CONTEXT_KHR,
0,
0
};
cl_context context = clCreateContext(
contextProperties,
num_devices,
devices,
NULL,
NULL,
&errcode_ret);
assert(errcode_ret == CL_SUCCESS);
cl_int errcodeQueue;
cl_command_queue queue = clCreateCommandQueue(context, devices[0], CL_QUEUE_PROFILING_ENABLE, &errcodeQueue);
char * tocopy = "foobar";
cl_int errcodeBufferRead;
cl_int errcodeBuffeWrite;
cl_mem readBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY, BUFFER_SIZE, NULL, &errcodeBufferRead);
assert(errcodeBufferRead == CL_SUCCESS);
cl_mem writeBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, BUFFER_SIZE, NULL, &errcodeBuffeWrite);
assert(errcodeBuffeWrite == CL_SUCCESS);
int res6 = clFinish(queue);
assert(res6 == CL_SUCCESS);
cl_event evnt[NUM_OF_EVENTS];
int res7 = clEnqueueCopyBuffer(queue, readBuffer, writeBuffer, 0, 0, BUFFER_SIZE, 0, NULL, &evnt[0]);
assert(res7 == CL_SUCCESS);
for(int i = 1; i < NUM_OF_EVENTS; i++)
{
int res7 = clEnqueueCopyBuffer(queue, readBuffer, writeBuffer, 0, 0, BUFFER_SIZE, 0, NULL, &evnt[i]);
assert(res7 == CL_SUCCESS);
}
int res8 = clFinish(queue);
assert(res8 == CL_SUCCESS);
cl_ulong time_start, time_end;
double total_time[NUM_OF_EVENTS];
for(int j = 0; j < NUM_OF_EVENTS; j++)
{
int res9 = clGetEventProfilingInfo(evnt[j], CL_PROFILING_COMMAND_END, 8, &time_end, NULL);
assert(res9 == CL_SUCCESS);
int res10 = clGetEventProfilingInfo(evnt[j], CL_PROFILING_COMMAND_START, 8, &time_start, NULL);
assert(res10 == CL_SUCCESS);
total_time[j] = time_end - time_start;
}
int res99 = clReleaseContext(context);
return 0;
}
\ No newline at end of file
========================================================================
CONSOLE APPLICATION : HelloTriangle Project Overview
========================================================================
AppWizard has created this HelloTriangle application for you.
This file contains a summary of what you will find in each of the files that
make up your HelloTriangle application.
HelloTriangle.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
HelloTriangle.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
HelloTriangle.cpp
This is the main application source file.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named HelloTriangle.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////
========================================================================
DYNAMIC LINK LIBRARY : OpenCL1 Project Overview
========================================================================
AppWizard has created this OpenCL1 DLL for you.
This file contains a summary of what you will find in each of the files that
make up your OpenCL1 application.
OpenCL1.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
OpenCL1.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
OpenCL1.cpp
This is the main DLL source file.
When created, this DLL does not export any symbols. As a result, it
will not produce a .lib file when it is built. If you wish this project
to be a project dependency of some other project, you will either need to
add code to export some symbols from the DLL so that an export library
will be produced, or you can set the Ignore Input Library property to Yes
on the General propert page of the Linker folder in the project's Property
Pages dialog box.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named OpenCL1.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////
//TODO: copyrights
#include "buffer.h"
#include "device.h"
#include "memobject.h"
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace Devices;
CPUBuffer::CPUBuffer(CPUDevice *device, MemObject *buffer, cl_int *rs)
: DeviceBuffer(), p_device(device), p_buffer(buffer), p_data(0),
p_data_malloced(false)
{
if(buffer->type() == MemObject::SubBuffer)
{
// We need to create this CPUBuffer based on the CPUBuffer of the
// parent buffer
SubBuffer *subbuf = (SubBuffer *)buffer;
MemObject *parent = subbuf->parent();
CPUBuffer *parentcpubuf = (CPUBuffer *)parent->deviceBuffer(device);
char *tmp_data = (char *)parentcpubuf->data();
tmp_data += subbuf->offset();
p_data = (void *)tmp_data;
}
else if(buffer->flags() & CL_MEM_USE_HOST_PTR)
{
// We use the host ptr, we are already allocated
p_data = buffer->host_ptr();
}
// NOTE: This function can also reject Image buffers by setting a value
// != CL_SUCCESS in rs.
}
CPUBuffer::~CPUBuffer()
{
if(p_data_malloced)
{
std::free((void *)p_data);
}
}
void *CPUBuffer::data() const
{
return p_data;
}
void *CPUBuffer::nativeGlobalPointer() const
{
return data();
}
bool CPUBuffer::allocate()
{
size_t buf_size = p_buffer->size();
if(buf_size == 0)
// Something went wrong...
return false;
if(!p_data)
{
// We don't use a host ptr, we need to allocate a buffer
p_data = std::malloc(buf_size);
if(!p_data)
return false;
p_data_malloced = true;
}
if(p_buffer->type() != MemObject::SubBuffer &&
p_buffer->flags() & CL_MEM_COPY_HOST_PTR)
{
std::memcpy(p_data, p_buffer->host_ptr(), buf_size);
}
// Say to the memobject that we are allocated
p_buffer->deviceAllocated(this);
return true;
}
DeviceInterface *CPUBuffer::device() const
{
return p_device;
}
bool CPUBuffer::allocated() const
{
return p_data != 0;
}
//TODO: copyrights
#ifndef __CPU_BUFFER_H__
#define __CPU_BUFFER_H__
#include "device_interface.h"
namespace Devices
{
class CPUDevice;
class MemObject;
/**
* \brief CPU implementation of \c Coal::MemObject
*
* This class is responsible of the actual allocation of buffer objects, using
* \c malloc() or by reusing a given \c host_ptr.
*/
class CPUBuffer : public DeviceBuffer
{
public:
/**
* \brief Constructor
* \param device Device for which the buffer is allocated
* \param buffer \c Coal::MemObject holding information about the buffer
* \param rs return code (\c CL_SUCCESS if all is good)
*/
CPUBuffer(CPUDevice *device, MemObject *buffer, cl_int *rs);
~CPUBuffer();
bool allocate();
DeviceInterface *device() const;
void *data() const; /*!< \brief Pointer to the buffer's data */
void *nativeGlobalPointer() const;
bool allocated() const;
private:
CPUDevice *p_device;
MemObject *p_buffer;
void *p_data;
bool p_data_malloced;
};
}
#endif
//TODO: copyrights
#ifndef __BUILTINS_H__
#define __BUILTINS_H__
#include <string>
namespace Devices {
class CPUKernelWorkGroup;
}
/**
* \brief Set the current kernel work-group of this thread
* \param current \c Coal::CPUKernelWorkGroup to be set in \c g_work_group.
*/
void setThreadLocalWorkGroup(Devices::CPUKernelWorkGroup *current);
/**
* \brief Return the address of a built-in function given its name
* \param name name of the built-in whose address is requested
*/
void *getBuiltin(const std::string &name);
/**
* \brief Work-item stacks
* \see \ref barrier
* \param size size of the allocated space for stacks
* \return address of the allocated space for stacks
*/
void *getWorkItemsData(size_t &size);
/**
* \brief Set work-item stacks
* \see \ref barrier
* \param ptr address of allocated space for stacks
* \param size size of the allocated space for stacks
*/
void setWorkItemsData(void *ptr, size_t size);
/**
* \brief Increment a n-component vector given a maximum value
*
* This function is used to increment a vector for which a set of maximum values
* each of its element can reach before the next is incremented.
*
* For example, if \p dims is \c 3, \p vec starts at <tt>{0, 0, 0}</tt> and
* \p maxs if <tt>{2, 3, 1}</tt>, repeatedly calling this function with the
* same vector will produce the following results :
*
* \code
* {0, 0, 1}
* {0, 1, 0}
* {0, 1, 1}
* {0, 2, 0}
* {0, 2, 1}
* {0, 3, 0}
* {0, 3, 1}
* {1, 0, 0}
* ...
* \endcode
*
* Until \p vec reaches <tt>{2, 3, 1}</tt>.
*
* \param dims number of elements in the vectors
* \param vec vector whose elements will be incremented
* \param maxs vector containing a maximum value above which each corresponding
* element of \p vec cannot go.
* \return false if the increment was ok, true if \p vec was already at it's
* maximum value and couldn't be further incremented.
*/
template<typename T>
bool incVec(unsigned long dims, T *vec, T *maxs)
{
bool overflow = false;
for(unsigned int i = 0; i<dims; ++i)
{
vec[i] += 1;
if(vec[i] > maxs[i])
{
vec[i] = 0;
overflow = true;
}
else
{
overflow = false;
break;
}
}
return overflow;
}
/**
* \brief Address of a pixel in an image
*
* This function is heavily used when Clover needs to address a pixel or a byte
* in a rectangular or three-dimensional image or buffer.
*
* \param base address of the first pixel in the image (address of the image itself)
* \param x X coordinate, cannot be bigger or equal to \c width
* \param y Y coordinate, cannot be bigger or equal to \c height
* \param z Z coordinate, cannot be bigger or equal to \c depth (1 for 2D arrays)
* \param row_pitch size in bytes of a row of pixels in the image
* \param slice_pitch size in bytes of a slice in a 3D array
* \param bytes_per_pixel bytes per pixel (1 for simple buffers), used when
* coordinates are in pixels and not in bytes.
*/
unsigned char *imageData(unsigned char *base, size_t x, size_t y, size_t z,
size_t row_pitch, size_t slice_pitch,
unsigned int bytes_per_pixel);
#endif
\ No newline at end of file
/**********************************************************************************
* Copyright (c) 2008-2010 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
**********************************************************************************/
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */
/*
* cl_gl.h contains Khronos-approved (KHR) OpenCL extensions which have
* OpenGL dependencies. The application is responsible for #including
* OpenGL or OpenGL ES headers before #including cl_gl.h.
*/
#ifndef __OPENCL_CL_GL_H
#define __OPENCL_CL_GL_H
#ifdef __APPLE__
#include <OpenCL/cl.h>
#include <OpenGL/CGLDevice.h>
#else
#include "cl.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef cl_uint cl_gl_object_type;
typedef cl_uint cl_gl_texture_info;
typedef cl_uint cl_gl_platform_info;
typedef struct __GLsync *cl_GLsync;
/* cl_gl_object_type */
#define CL_GL_OBJECT_BUFFER 0x2000
#define CL_GL_OBJECT_TEXTURE2D 0x2001
#define CL_GL_OBJECT_TEXTURE3D 0x2002
#define CL_GL_OBJECT_RENDERBUFFER 0x2003
/* cl_gl_texture_info */
#define CL_GL_TEXTURE_TARGET 0x2004
#define CL_GL_MIPMAP_LEVEL 0x2005
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLBuffer(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLuint /* bufobj */,
int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLTexture2D(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLenum /* target */,
cl_GLint /* miplevel */,
cl_GLuint /* texture */,
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLTexture3D(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLenum /* target */,
cl_GLint /* miplevel */,
cl_GLuint /* texture */,
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLRenderbuffer(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLuint /* renderbuffer */,
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clGetGLObjectInfo(cl_mem /* memobj */,
cl_gl_object_type * /* gl_object_type */,
cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clGetGLTextureInfo(cl_mem /* memobj */,
cl_gl_texture_info /* param_name */,
size_t /* param_value_size */,
void * /* param_value */,
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */,
cl_uint /* num_objects */,
const cl_mem * /* mem_objects */,
cl_uint /* num_events_in_wait_list */,
const cl_event * /* event_wait_list */,
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */,
cl_uint /* num_objects */,
const cl_mem * /* mem_objects */,
cl_uint /* num_events_in_wait_list */,
const cl_event * /* event_wait_list */,
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0;
/* cl_khr_gl_sharing extension */
#define cl_khr_gl_sharing 1
typedef cl_uint cl_gl_context_info;
/* Additional Error Codes */
#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000
/* cl_gl_context_info */
#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006
#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007
/* Additional cl_context_properties */
#define CL_GL_CONTEXT_KHR 0x2008
#define CL_EGL_DISPLAY_KHR 0x2009
#define CL_GLX_DISPLAY_KHR 0x200A
#define CL_WGL_HDC_KHR 0x200B
#define CL_CGL_SHAREGROUP_KHR 0x200C
extern CL_API_ENTRY cl_int CL_API_CALL
clGetGLContextInfoKHR(const cl_context_properties * /* properties */,
cl_gl_context_info /* param_name */,
size_t /* param_value_size */,
void * /* param_value */,
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetGLContextInfoKHR_fn)(
const cl_context_properties * properties,
cl_gl_context_info param_name,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret);
#ifdef __cplusplus
}
#endif
#endif /* __OPENCL_CL_GL_H */
\ No newline at end of file
/**********************************************************************************
* Copyright (c) 2008-2010 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
**********************************************************************************/
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */
/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */
/* OpenGL dependencies. */
#ifndef __OPENCL_CL_GL_EXT_H
#define __OPENCL_CL_GL_EXT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __APPLE__
#include <OpenCL/cl_gl.h>
#else
#include "cl_gl.h"
#endif
/*
* For each extension, follow this template
* /* cl_VEN_extname extension */
/* #define cl_VEN_extname 1
* ... define new types, if any
* ... define new tokens, if any
* ... define new APIs, if any
*
* If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header
* This allows us to avoid having to decide whether to include GL headers or GLES here.
*/
/*
* cl_khr_gl_event extension
* See section 9.9 in the OpenCL 1.1 spec for more information
*/
#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D
extern CL_API_ENTRY cl_event CL_API_CALL
clCreateEventFromGLsyncKHR(cl_context /* context */,
cl_GLsync /* cl_GLsync */,
cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1;
#ifdef __cplusplus
}
#endif
#endif /* __OPENCL_CL_GL_EXT_H */
\ No newline at end of file
//TODO: copyrights
#include "context.h"
#include "device_interface.h"
#include "propertylist.h"
#include "platform.h"
#include <cstring>
#include <cstdlib>
//#include <llvm/Support/TargetSelect.h>
using namespace Devices;
static void __stdcall default_pfn_notify(const char *, const void *, size_t, void *)
{
return;
}
Context::Context(const cl_context_properties *properties,
cl_uint num_devices,
const cl_device_id *devices,
void (CL_CALLBACK *pfn_notify)(const char *, const void *,
size_t, void *),
void *user_data,
cl_int *errcode_ret)
: Object(Object::T_Context, 0), p_properties(0), p_pfn_notify(pfn_notify),
p_user_data(user_data), p_devices(0), p_num_devices(0), p_props_len(0),
p_platform(0), wgl_handle(0), opengl_context_handle(0)
{
if(!p_pfn_notify)
p_pfn_notify = &default_pfn_notify;
// Intialize LLVM, this can be done more than one time per program
/*llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();*/
// Explore the properties
if(properties)
{
const unsigned char *props = (const unsigned char *)properties;
cl_context_properties prop;
size_t props_len = 0;
#define GET_PROP(type, var) \
var = *(const type *)props; \
props += sizeof(type); \
props_len += sizeof(type);
while(true)
{
GET_PROP(cl_context_properties, prop)
if(!prop)
break;
switch(prop)
{
case CL_CONTEXT_PLATFORM:
GET_PROP(cl_platform_id, p_platform);
break;
case CL_WGL_HDC_KHR:
GET_PROP(cl_context_properties, wgl_handle);
break;
case CL_GL_CONTEXT_KHR:
GET_PROP(cl_context_properties, opengl_context_handle);
break;
default:
*errcode_ret = CL_INVALID_PROPERTY;
return;
}
}
// properties may be allocated on the stack of the client application
// copy it into a real buffer
p_properties = (cl_context_properties *)std::malloc(props_len);
p_props_len = props_len;
if(!p_properties)
{
*errcode_ret = CL_OUT_OF_HOST_MEMORY;
return;
}
std::memcpy((void *)p_properties, (const void *)properties, props_len);
}
// Verify that the platform is good
if(p_platform != DEFAULT_PLATFORM)
{
*errcode_ret = CL_INVALID_PLATFORM;
return;
}
// Explore the devices
p_devices = (DeviceInterface **)std::malloc(num_devices * sizeof(DeviceInterface *));
p_num_devices = num_devices;
if(!p_devices)
{
*errcode_ret = CL_OUT_OF_HOST_MEMORY;
return;
}
for(cl_uint i = 0; i<num_devices; ++i)
{
cl_device_id device = devices[i];
if(device == 0)
{
*errcode_ret = CL_INVALID_DEVICE;
return;
}
// Verify that the device is available
cl_bool device_available;
*errcode_ret = device->info(CL_DEVICE_AVAILABLE,
sizeof(device_available),
&device_available,
0);
if(*errcode_ret != CL_SUCCESS)
return;
if(!device_available)
{
*errcode_ret = CL_DEVICE_NOT_AVAILABLE;
return;
}
// Add the device to the list
p_devices[i] = (DeviceInterface *)device;
}
}
Context::~Context()
{
if(p_properties)
std::free((void *)p_properties);
if(p_devices)
std::free((void *)p_devices);
}
cl_int Context::info(cl_context_info param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret) const
{
void *value = 0;
size_t value_length = 0;
union {
cl_uint cl_uint_var;
};
switch(param_name)
{
case CL_CONTEXT_REFERENCE_COUNT:
SIMPLE_ASSIGN(cl_uint, references());
break;
case CL_CONTEXT_NUM_DEVICES:
SIMPLE_ASSIGN(cl_uint, p_num_devices);
break;
case CL_CONTEXT_DEVICES:
MEM_ASSIGN(p_num_devices * sizeof(DeviceInterface *), p_devices);
break;
case CL_CONTEXT_PROPERTIES:
MEM_ASSIGN(p_props_len, p_properties);
break;
default:
return CL_INVALID_VALUE;
}
if(param_value && param_value_size < value_length)
return CL_INVALID_VALUE;
if(param_value_size_ret)
*param_value_size_ret = value_length;
if(param_value && value_length /* CONTEXT_PROPERTIES can be of length 0 */)
std::memcpy(param_value, value, value_length);
return CL_SUCCESS;
}
bool Context::hasDevice(DeviceInterface *device) const
{
for(unsigned int i = 0; i<p_num_devices; ++i)
if(p_devices[i] == device)
return true;
return false;
}
//TODO: copyrights
#ifndef __CONTEXT_H__
#define __CONTEXT_H__
#include "object.h"
#include "opencl.h"
namespace Devices
{
class DeviceInterface;
/**
* \brief OpenCL context
*
* This class is the root of all OpenCL objects, except \c Coal::DeviceInterface.
*/
class Context : public Object
{
public:
/**
* \brief Constructor
* \param properties properties of the context
* \param num_devices number of devices that will be used
* \param devices \c Coal::DeviceInterface to be used
* \param pfn_notify function to call when an error arises, to give
* more detail
* \param user_data user data to pass to \p pfn_notify
* \param errcode_ret return code
*/
Context(const cl_context_properties *properties,
cl_uint num_devices,
const cl_device_id *devices,
void (CL_CALLBACK *pfn_notify)(const char *, const void *,
size_t, void *),
void *user_data,
cl_int *errcode_ret);
~Context();
/**
* \brief Info about the context
* \copydetails Coal::DeviceInterface::info
*/
cl_int info(cl_context_info param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret) const;
/**
* \brief Check that this context contains a given \p device
* \param device device to check
* \return whether this context contains \p device
*/
bool hasDevice(DeviceInterface *device) const;
private:
cl_context_properties *p_properties;
void (CL_CALLBACK *p_pfn_notify)(const char *, const void *,
size_t, void *);
void *p_user_data;
DeviceInterface **p_devices;
unsigned int p_num_devices, p_props_len;
cl_platform_id p_platform;
cl_context_properties wgl_handle;
cl_context_properties opengl_context_handle;
};
}
struct _cl_context : public Devices::Context
{};
#endif
#include "debug.h"
static void output(const char *format, va_list vararg)
{
if(true)
{
static FILE* file = nullptr;
file = fopen(TRACE_OUTPUT_FILE, "a+");
vfprintf(file, format, vararg);
fclose(file);
/*if(!file)
{
}
if(file)
{
vfprintf(file, format, vararg);
}*/
}
}
void trace(const char *format, ...)
{
va_list vararg;
va_start(vararg, format);
output(format, vararg);
va_end(vararg);
}
\ No newline at end of file
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
#define TRACE_OUTPUT_FILE "C:/Users/mgregoire/opencl.txt"
void trace(const char *format, ...);
#define UNIMPLEMENTED() trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
#define TRACE(message, ...) trace("trace: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
\ No newline at end of file
//TODO: copyrights
#ifndef __CPU_DEVICE_H__
#define __CPU_DEVICE_H__
#include <list>
#include "opencl.h"
#include "device_interface.h"
#include "pthread.h"
namespace Devices
{
class CPUDevice : public DeviceInterface
{
public:
CPUDevice();
~CPUDevice();
/**
* \brief Initialize the CPU device
*
* This function creates the worker threads and get information about
* the host system for the \c numCPUs() and \c cpuMhz functions.
*/
void init();
cl_int info(cl_device_info param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret) const;
DeviceBuffer *createDeviceBuffer(MemObject *buffer, cl_int *rs);
DeviceProgram *createDeviceProgram(Program *program);
DeviceKernel *createDeviceKernel(Kernel *kernel,
llvm::Function *function);
cl_int initEventDeviceData(Event *event);
void freeEventDeviceData(Event *event);
void pushEvent(Event *event);
Event *getEvent(bool &stop);
unsigned int numCPUs() const; /*!< \brief Number of logical CPU cores on the system */
float cpuMhz() const; /*!< \brief Speed of the CPU in Mhz */
private:
unsigned int p_cores, p_num_events;
float p_cpu_mhz;
pthread_t *p_workers;
std::list<Event *> p_events;
pthread_cond_t p_events_cond;
pthread_mutex_t p_events_mutex;
bool p_stop, p_initialized;
};
//class GPUDevice : public DeviceInterface
//{
//public:
// GPUDevice();
// ~GPUDevice();
//
// /**
// * \brief Initialize the CPU device
// *
// * This function creates the worker threads and get information about
// * the host system for the \c numCPUs() and \c cpuMhz functions.
// */
// void init();
//
// cl_int info(cl_device_info param_name,
// size_t param_value_size,
// void *param_value,
// size_t *param_value_size_ret) const;
//
// DeviceBuffer *createDeviceBuffer(MemObject *buffer, cl_int *rs);
// DeviceProgram *createDeviceProgram(Program *program);
// DeviceKernel *createDeviceKernel(Kernel *kernel,
// llvm::Function *function);
//
// cl_int initEventDeviceData(Event *event);
// void freeEventDeviceData(Event *event);
//
// void pushEvent(Event *event);
// Event *getEvent(bool &stop);
//
// unsigned int numCPUs() const; /*!< \brief Number of logical CPU cores on the system */
// float cpuMhz() const; /*!< \brief Speed of the CPU in Mhz */
//
//private:
// unsigned int p_cores, p_num_events;
// float p_cpu_mhz;
// pthread_t *p_workers;
//
// std::list<Event *> p_events;
// pthread_cond_t p_events_cond;
// pthread_mutex_t p_events_mutex;
// bool p_stop, p_initialized;
//};
}
#endif
\ No newline at end of file
//TODO: copyrights
#ifndef __DEVICEINTERFACE_H__
#define __DEVICEINTERFACE_H__
#include "opencl.h"
#include "object.h"
namespace llvm
{
class PassManager;
class Module;
class Function;
}
namespace Devices
{
class DeviceBuffer;
class DeviceProgram;
class DeviceKernel;
class MemObject;
class Event;
class Program;
class Kernel;
/**
* \brief Abstraction layer between core Clover objects and the devices
*
* This interface is used by the core Clover classes to communicate with the
* devices, that must reimplement all the functions described here.
*/
class DeviceInterface : public Object
{
public:
DeviceInterface() : Object(Object::T_Device, 0) {}
virtual ~DeviceInterface() {}
/**
* \brief Retrieve information about the device
*
* This function is used to retrieve information about an object.
* Sometimes, the size of the data retrieved is unknown (for example, a
* string). The application can call this function twice, the first time
* to get the size, then it allocates a buffer, and finally get the data.
*
* \code
* const char *string = 0;
* size_t len;
*
* object->info(FOO_PROPERTY_STRING, 0, 0, &len);
* string = std::malloc(len);
* object->info(FOO_PROPERTY_STRING, len, string, 0);
* \endcode
*
* \param param_name Name of the property to retrieve
* \param param_value_size Size of the application-allocated buffer
* in which to put the value.
* \param param_value Pointer to an application-allocated buffer
* where the property data will be stored. Ignored
* if NULL.
* \param param_value_size_ret Size of the value retrieved, ignored if
* NULL.
* \return CL_SUCCESS in case of success, otherwise a CL error code.
*/
virtual cl_int info(cl_device_info param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret) const = 0;
/**
* \brief Create a \c Coal::DeviceBuffer object for this device
* \param buffer Memory object for which the buffer has to be created
* \param rs Error code (\c CL_SUCCESS if no error)
* \return a \c Coal::DeviceBuffer object, undefined if there is an error
*/
virtual DeviceBuffer *createDeviceBuffer(MemObject *buffer, cl_int *rs) = 0;
/**
* \brief Create a \c Coal::DeviceProgram object for this device
* \param program \c Coal::Program containing the device-independent
* program data
* \return a \c Coal::DeviceProgram object
*/
virtual DeviceProgram *createDeviceProgram(Program *program) = 0;
/**
* \brief Create a \c Coal::DeviceKernel object for this device
* \param kernel \c Coal::Kernel containing the device-independent kernel
* data
* \param function device-specific \c llvm::Function to be used
* \return a \c Coal::DeviceKernel object
*/
virtual DeviceKernel *createDeviceKernel(Kernel *kernel,
llvm::Function *function) = 0;
/**
* \brief Push an event on the device
* \sa the end of \ref events
* \param event the event to be pushed
*/
virtual void pushEvent(Event *event) = 0;
/**
* \brief Initialize device-specific event data
*
* This call allows a device to initialize device-specific event data,
* by using \c Coal::Event::setDeviceData(). For instance, an
* hardware-accelerated device can associate a device command to an
* event, and use it to manage the event when it gets pushed.
*
* @note This function has one obligation: it must call
* \c Coal::MapBufferEvent::setPtr() and
* \c Coal::MapImageEvent::setPtr() (and other function described
* in its documentation)
*
* \param event the event for which data can be set
* \return CL_SUCCESS in case of success
*/
virtual cl_int initEventDeviceData(Event *event) = 0;
/**
* \brief Free device-specific event data
*
* This function is called just before \p event gets deleted. It allows
* a device to free device-specific data of this event, if any.
*
* \param event the event that will be destroyed
*/
virtual void freeEventDeviceData(Event *event) = 0;
};
/**
* \brief Device-specific memory buffer
*
* This class is the backing-store used on a device for a \c Coal::MemObject. It
* is created by \c Coal::DeviceInterface::createDeviceBuffer().
*/
class DeviceBuffer
{
public:
DeviceBuffer() {}
virtual ~DeviceBuffer() {}
/**
* \brief Allocate the buffer on the device
* \return true when success, false otherwise
*/
virtual bool allocate() = 0;
/**
* \brief \c Coal::DeviceInterface of this buffer
* \return parent \c Coal::DeviceInterface
*/
virtual DeviceInterface *device() const = 0;
/**
* \brief Allocation status
* \return true if already allocated, false otherwise
*/
virtual bool allocated() const = 0;
/**
* \brief Host-accessible memory pointer
*
* This function returns what is passed as arguments to native kernels
* (\c clEnqueueNativeKernel(), \c Coal::NativeKernelEvent) in place of
* \c Coal::MemObject pointers.
*
* For \c Coal::CPUDevice, it's simply a pointer in RAM, but
* hardware-accelerated devices may need to do some copying or mapping.
*
* \warning Beware that this data may get written to by the native kernel.
*
* \return A memory pointer usable by a host native kernel
*/
virtual void *nativeGlobalPointer() const = 0;
};
/**
* \brief Device-specific program data
*/
class DeviceProgram
{
public:
DeviceProgram() {}
virtual ~DeviceProgram() {}
/**
* \brief Linking or not \b stdlib with this program
*
* \b stdlib is a LLVM bitcode file containing some implementations of
* OpenCL C built-ins. This function allows a device to tell
* \c Coal::Program::build() if it wants \b stdlib to be linked or not.
*
* Linking the library may allow inlining of functions like \c ceil(),
* \c floor(), \c clamp(), etc. So, if these functions are not better
* handled by the device itself than by \b stdlib, it's a good thing
* to link it.
*
* But if the device provides instructions for these functions, then
* it could be better not to link \b stdlib and to replace the LLVM
* calls to these functions with device-specific instructions.
*
* \warning \b Stdlib currently only works for \c Coal::CPUDevice, as
* it contains host-specific code (LLVM IR is not meant to be
* portable, pointer size changes for example).
*
* \return true if \b stdlib must be linked with the program
*/
virtual bool linkStdLib() const = 0;
/**
* \brief Create device-specific optimization passes
*
* This hook allows a device to add LLVM optimization passes to a
* \c llvm::PassManager . This way, devices needing function flattening
* or special analysis passes can have them run on the mode.
*
* \param manager \c llvm::PassManager to which add the passes
* \param optimize false if \c -cl-opt-disable was given at compilation
* time.
*/
virtual void createOptimizationPasses(llvm::PassManager *manager,
bool optimize) = 0;
/**
* \brief Build a device-specific representation of the program
*
* This function is called by \c Coal::Program::build() when the module
* is compiled and linked. It can be used by the device to build a
* device-specific representation of the program.
*
* \param module \c llvm::Module containing the program's LLVM IR
* \return true in case of success, false otherwise
*/
virtual bool build(llvm::Module *module) = 0;
};
/**
* \brief Device-specific kernel data
*/
class DeviceKernel
{
public:
DeviceKernel() {}
virtual ~DeviceKernel() {}
/**
* \brief Maximum work-group size of a kernel
* \return Maximum work-group size of the kernel based on device-specific
* data such as memory usage, register pressure, etc)
*/
virtual size_t workGroupSize() const = 0;
/**
* \brief Local memory used by the kernel
* \return Local memory used by the kernel, in bytes
*/
virtual cl_ulong localMemSize() const = 0;
/**
* \brief Private memory used by the kernel
* \return Private memory used by the kernel, in bytes
*/
virtual cl_ulong privateMemSize() const = 0;
/**
* \brief Preferred work-group size multiple
* \return The size multiple a work-group can have to work the best and
* the fastest on the device
*/
virtual size_t preferredWorkGroupSizeMultiple() const = 0;
/**
* \brief Optimal work-group size
*
* This function allows a device to calculate the optimal work-group size
* for this kernel, using it's memory usage, SIMD dimension, etc.
*
* \c Coal::CPUDevice tries to split the kernel into a number of
* work-groups the closest possible to the number of CPU cores.
*
* \param num_dims Number of working dimensions
* \param dim Dimension for which the multiple is being calculated
* \param global_work_size Total number of work-items to split into
* work-groups
* \return optimal size of a work-group, for the \p dim dimension.
*/
virtual size_t guessWorkGroupSize(cl_uint num_dims, cl_uint dim,
size_t global_work_size) const = 0;
};
}
struct _cl_device_id : public Devices::DeviceInterface
{};
#endif
// dllmain.cpp : Defines the entry point for the DLL application.
#include "windows.h"
#include "opencl.h"
#include "debug.h"
#include <windows.h>
#include <intrin.h>
#include <WinUser.h>
#include "dllmain.h"
#if defined(_WIN32)
typedef DWORD LocalStorageKey;
#else
typedef pthread_key_t LocalStorageKey;
#endif
static LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
#if defined(_WIN32)
#define IDD_DIALOG1 101
static void clAttachThread()
{
TRACE("()");
cl::Current *current = new cl::Current();
{
TlsSetValue(currentTLS, current);
current->context = 0;
}
}
static void clDetachThread()
{
TRACE("()");
cl::Current *current = (cl::Current*)TlsGetValue(currentTLS);
if(current)
{
delete current;
}
}
static bool clAttachProcess()
{
TRACE("()");
currentTLS = TlsAlloc();
if(currentTLS == TLS_OUT_OF_INDEXES)
{
return false;
}
clAttachThread();
return true;
}
static void clDetachProcess()
{
TRACE("()");
clDetachThread();
TlsFree(currentTLS);
}
static INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT rect;
switch(uMsg)
{
case WM_INITDIALOG:
GetWindowRect(GetDesktopWindow(), &rect);
SetWindowPos(hwnd, HWND_TOP, rect.right / 2, rect.bottom / 2, 0, 0, SWP_NOSIZE);
SetTimer(hwnd, 1, 100, NULL);
return TRUE;
case WM_COMMAND:
if(LOWORD(wParam) == IDCANCEL)
{
EndDialog(hwnd, 0);
}
break;
case WM_TIMER:
if(IsDebuggerPresent())
{
EndDialog(hwnd, 0);
}
}
return FALSE;
}
static void WaitForDebugger(HINSTANCE instance)
{
if(!IsDebuggerPresent())
{
HRSRC dialog = FindResource(instance, MAKEINTRESOURCE(IDD_DIALOG1), RT_DIALOG);
DLGTEMPLATE *dialogTemplate = (DLGTEMPLATE*)LoadResource(instance, dialog);
DialogBoxIndirect(instance, dialogTemplate, NULL, DebuggerWaitDialogProc);
}
}
extern "C" BOOL APIENTRY DllMain(HINSTANCE instance, DWORD ul_reason_for_call, LPVOID lpReserved)
{
//UNIMPLEMENTED();
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
/*#ifdef NDEBUG
WaitForDebugger(instance);
#endif*/
return clAttachProcess();
break;
case DLL_THREAD_ATTACH:
clAttachThread();
break;
case DLL_THREAD_DETACH:
clDetachThread();
break;
case DLL_PROCESS_DETACH:
clDetachProcess();
break;
default:
break;
}
return TRUE;
}
#endif
namespace cl
{
static Current *getCurrent(void)
{
Current *current = (Current*)TlsGetValue(currentTLS);
if(!current)
{
clAttachThread();
}
return (Current*)TlsGetValue(currentTLS);
}
void makeCurrent(cl_platform_id platformId, Devices::Context *context)
{
Current *current = getCurrent();
current->context = context;
current->platform = platformId;
/*if(context)
{
context->makeCurrent(surface);
}*/
}
Devices::Context *getContext()
{
Current *current = getCurrent();
return current->context;
}
}
\ No newline at end of file
#include "context.h"
namespace cl
{
struct Current
{
Devices::Context* context;
cl_platform_id platform;
};
static Current *getCurrent(void);
void makeCurrent(cl_platform_id platformId, Devices::Context *context);
Devices::Context *getContext();
}
\ No newline at end of file
#ifndef __CPU_KERNEL_H__
#define __CPU_KERNEL_H__
#include "device_interface.h"
//#include <llvm/ExecutionEngine/GenericValue.h>
#include <vector>
#include <string>
#include "pthread.h"
#include <stdint.h>
#ifndef MAX_WORK_DIMS
#define MAX_WORK_DIMS 3
#endif
namespace llvm
{
class Function;
}
namespace Devices
{
class CPUDevice;
class Kernel;
class KernelEvent;
class Image2D;
class Image3D;
/**
* \brief CPU kernel
*
* This class holds passive information about a kernel (\c Coal::Kernel object
* and device on which it is run) and provides the \c callFunction() function.
*
* This function is described at the end of \ref llvm .
*
* \see Coal::CPUKernelWorkGroup
*/
class CPUKernel : public DeviceKernel
{
public:
/**
* \brief Constructor
* \param device device on which the kernel will be run
* \param kernel \c Coal::Kernel object holding information about this
* kernel
* \param function \c llvm::Function to run
*/
CPUKernel(CPUDevice *device, Kernel *kernel, llvm::Function *function);
~CPUKernel();
size_t workGroupSize() const;
cl_ulong localMemSize() const;
cl_ulong privateMemSize() const;
size_t preferredWorkGroupSizeMultiple() const;
size_t guessWorkGroupSize(cl_uint num_dims, cl_uint dim,
size_t global_work_size) const;
Kernel *kernel() const; /*!< \brief \c Coal::Kernel object this kernel will run */
CPUDevice *device() const; /*!< \brief device on which the kernel will be run */
llvm::Function *function() const; /*!< \brief \c llvm::Function representing the kernel but <strong>not to be run</strong> */
llvm::Function *callFunction(); /*!< \brief stub function used to run the kernel, see \ref llvm */
/**
* \brief Calculate where to place a value in an array
*
* This function is used to calculate where to place a value in an
* array given its size, properly aligning it.
*
* This function is called repeatedly to obtain the aligned position of
* each value that must be place in the array
*
* \code
* size_t array_len = 0, array_offset = 0;
* void *array;
*
* // First, get the array size given alignment constraints
* typeOffset(array_len, sizeof(int));
* typeOffset(array_len, sizeof(float));
* typeOffset(array_len, sizeof(void *));
*
* // Then, allocate memory
* array = malloc(array_len)
*
* // Finally, place the arguments
* *(int *)((char *)array + typeOffset(array_offset, sizeof(int))) = 1337;
* *(float *)((char *)array + typeOffset(array_offset, sizeof(int))) = 3.1415f;
* *(void **)((char *)array + typeOffset(array_offset, sizeof(int))) = array;
* \endcode
*
* \param offset offset at which the value will be placed. This variable
* gets incremented by <tt>type_len + padding</tt>.
* \param type_len size in bytes of the value that will be stored
* \return offset at which the value will be stored (equal to \p offset
* before incrementation.
*/
static size_t typeOffset(size_t &offset, size_t type_len);
private:
CPUDevice *p_device;
Kernel *p_kernel;
llvm::Function *p_function, *p_call_function;
pthread_mutex_t p_call_function_mutex;
};
class CPUKernelEvent;
/**
* \brief CPU kernel work-group
*
* This class represent a bulk of work-items that will be run. It is the one
* to actually run the kernel of its elements.
*
* \see \ref llvm
* \nosubgrouping
*/
class CPUKernelWorkGroup
{
public:
/**
* \brief Constructor
* \param kernel kernel to run
* \param event event containing information about the kernel run
* \param cpu_event CPU-specific information and cache about \p event
* \param work_group_index index of this work-group in the kernel
*/
CPUKernelWorkGroup(CPUKernel *kernel, KernelEvent *event,
CPUKernelEvent *cpu_event,
const size_t *work_group_index);
~CPUKernelWorkGroup();
/**
* \brief Build a structure of arguments
*
* As C doesn't support calling functions with variable arguments
* unknown at the compilation, this function builds the list of
* arguments in memory. This array will then be passed to a LLVM stub
* function reading it and passing its values to the actuel kernel.
*
* \see \ref llvm
* \param locals_to_free if this kernel takes \c __local arguments, they
* must be \c malloc()'ed for every work-group.
* They are placed in this vector to be
* \c free()'ed at the end of \c run().
* \return address of a memory location containing the arguments
*/
void *callArgs(std::vector<void *> &locals_to_free);
/**
* \brief Run the work-group
*
* This function is the core of CPU-acceleration. It runs the work-items
* of this work-group given the correct arguments.
*
* \see \ref llvm
* \see \ref barrier
* \see callArgs()
* \return true if success, false in case of an error
*/
bool run();
/**
* \name Native implementation of built-in OpenCL C functions
* @{
*/
size_t getGlobalId(cl_uint dimindx) const;
cl_uint getWorkDim() const;
size_t getGlobalSize(cl_uint dimindx) const;
size_t getLocalSize(cl_uint dimindx) const;
size_t getLocalID(cl_uint dimindx) const;
size_t getNumGroups(cl_uint dimindx) const;
size_t getGroupID(cl_uint dimindx) const;
size_t getGlobalOffset(cl_uint dimindx) const;
void barrier(unsigned int flags);
void *getImageData(Image2D *image, int x, int y, int z) const;
void writeImage(Image2D *image, int x, int y, int z, float *color) const;
void writeImage(Image2D *image, int x, int y, int z, int32_t *color) const;
void writeImage(Image2D *image, int x, int y, int z, uint32_t *color) const;
void readImage(float *result, Image2D *image, int x, int y, int z,
uint32_t sampler) const;
void readImage(int32_t *result, Image2D *image, int x, int y, int z,
uint32_t sampler) const;
void readImage(uint32_t *result, Image2D *image, int x, int y, int z,
uint32_t sampler) const;
void readImage(float *result, Image2D *image, float x, float y, float z,
uint32_t sampler) const;
void readImage(int32_t *result, Image2D *image, float x, float y, float z,
uint32_t sampler) const;
void readImage(uint32_t *result, Image2D *image, float x, float y, float z,
uint32_t sampler) const;
/**
* @}
*/
/**
* \brief Function called when a built-in name cannot be found
*/
void builtinNotFound(const std::string &name) const;
private:
template<typename T>
void writeImageImpl(Image2D *image, int x, int y, int z, T *color) const;
template<typename T>
void readImageImplI(T *result, Image2D *image, int x, int y, int z,
uint32_t sampler) const;
template<typename T>
void readImageImplF(T *result, Image2D *image, float x, float y, float z,
uint32_t sampler) const;
template<typename T>
void linear3D(T *result, float a, float b, float c,
int i0, int j0, int k0, int i1, int j1, int k1,
Image3D *image) const;
template<typename T>
void linear2D(T *result, float a, float b, float c, int i0, int j0,
int i1, int j1, Image2D *image) const;
private:
CPUKernel *p_kernel;
CPUKernelEvent *p_cpu_event;
KernelEvent *p_event;
cl_uint p_work_dim;
size_t p_index[MAX_WORK_DIMS],
p_max_local_id[MAX_WORK_DIMS],
p_global_id_start_offset[MAX_WORK_DIMS];
void(*p_kernel_func_addr)(void *);
void *p_args;
// Machinery to have barrier() working
struct Context
{
size_t local_id[MAX_WORK_DIMS];
//ucontext_t context;
unsigned int initialized;
};
Context *getContextAddr(unsigned int index);
Context *p_current_context;
Context p_dummy_context;
void *p_contexts;
size_t p_stack_size;
unsigned int p_num_work_items, p_current_work_item;
bool p_had_barrier;
};
/**
* \brief CPU-specific information about a kernel event
*
* This class put in a \c Coal::KernelEvent device-data field
* (see \c Coal::Event::setDeviceData()) is responsible for dispatching the
* \c Coal::CPUKernelWorkGroup objects between the CPU worker threads.
*/
class CPUKernelEvent
{
public:
/**
* \brief Constructor
* \param device device running the kernel
* \param event \c Coal::KernelEvent holding device-agnostic data
* about the event
*/
CPUKernelEvent(CPUDevice *device, KernelEvent *event);
~CPUKernelEvent();
bool reserve(); /*!< \brief The next Work Group that will execute will be the last. Locks the event */
bool finished(); /*!< \brief All the work groups have finished */
CPUKernelWorkGroup *takeInstance(); /*!< \brief Must be called exactly one time after reserve(). Unlocks the event */
void *kernelArgs() const; /*!< \brief Return the cached kernel arguments */
void cacheKernelArgs(void *args); /*!< \brief Cache pre-built kernel arguments */
void workGroupFinished(); /*!< \brief A work-group has just finished */
private:
CPUDevice *p_device;
KernelEvent *p_event;
size_t p_current_work_group[MAX_WORK_DIMS],
p_max_work_groups[MAX_WORK_DIMS];
size_t p_current_wg, p_finished_wg, p_num_wg;
pthread_mutex_t p_mutex;
void *p_kernel_args;
};
}
#endif
#ifndef LIBGL_MAIN_H_
#define LIBGL_MAIN_H_
#define _GDI32_
#include <windows.h>
#include <WinUser.h>
#endif
\ No newline at end of file
//TODO: copyrights
#ifndef __MEMOBJECT_H__
#define __MEMOBJECT_H__
#include "object.h"
#include "opencl.h"
namespace Devices
{
class DeviceBuffer;
class Context;
class DeviceInterface;
/**
* \brief Base class for all the memory objects
*/
class MemObject : public Object
{
public:
/**
* \brief Type of memory object
*/
enum Type
{
Buffer,
SubBuffer,
Image2D,
Image3D
};
/**
* \brief Constructor
* \param ctx parent \c Coal::Context
* \param flags memory object flags
* \param host_ptr host pointer used by some flags (see the OpenCL spec)
* \param errcode_ret return value
* \note Don't do any initialization here, but in \c init(). We only fill
* the private variables and check the values passed in argument.
* \sa init
*/
MemObject(Context *ctx, cl_mem_flags flags, void *host_ptr,
cl_int *errcode_ret);
~MemObject();
/**
* \brief Initialize the memory object
*
* Memory objects are device-independent classes. This function creates
* one \c Coal::DeviceBuffer per device present in the context by
* calling \c Coal::DeviceInterface::createDeviceBuffer().
*
* If there is only one device, its \c Coal::DeviceBuffer is directly
* allocated. If there are more than one device, the allocation is
* deferred until a \c Coal::Event is pushed for this device.
*
* \return \c CL_SUCCESS if success, an error code otherwise
*/
virtual cl_int init();
virtual bool allocate(DeviceInterface *device); /*!< \brief Allocate this memory object on the given \p device */
virtual size_t size() const = 0; /*!< \brief Device-independent size of the memory object */
virtual Type type() const = 0; /*!< \brief Type of the memory object */
cl_mem_flags flags() const; /*!< \brief Flags */
void *host_ptr() const; /*!< \brief Host pointer */
DeviceBuffer *deviceBuffer(DeviceInterface *device) const; /*!< \brief \c Coal::DeviceBuffer for the given \p device */
void deviceAllocated(DeviceBuffer *buffer); /*!< \brief Is the \c Coal::DeviceBuffer for \p buffer allocated ? */
/**
* \brief Set a destructor callback for this memory object
*
* This callback is called when this memory object is deleted. It is
* currently called from the destructor, so the memory object is already
* invalid, but as OpenCL objects are immutable, the callback cannot
* use its \c memobj parameter except in a pointer comparison, and there
* is no problem.
*
* \param pfn_notify function to call when the memory object is deleted
* \param user_data user data to pass to this function
*/
void setDestructorCallback(void (CL_CALLBACK *pfn_notify)(cl_mem memobj,
void *user_data),
void *user_data);
/**
* \brief Get information about this memory object
* \copydetails Coal::DeviceInterface::info
*/
cl_int info(cl_mem_info param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret) const;
private:
unsigned int p_num_devices, p_devices_to_allocate;
cl_mem_flags p_flags;
void *p_host_ptr;
DeviceBuffer **p_devicebuffers;
void (CL_CALLBACK *p_dtor_callback)(cl_mem memobj, void *user_data);
void *p_dtor_userdata;
};
/**
* \brief Simple buffer object
*/
class Buffer : public MemObject
{
public:
/**
* \brief Constructor
* \param ctx parent \c Coal::Context
* \param size size of the buffer, in bytes
* \param host_ptr host pointer
* \param flags memory flags
* \param errcode_ret return code
*/
Buffer(Context *ctx, size_t size, void *host_ptr, cl_mem_flags flags,
cl_int *errcode_ret);
size_t size() const; /*!< \brief Size of the buffer, in bytes */
Type type() const; /*!< \brief Return that we are a \c Coal::MemObject::Buffer */
private:
size_t p_size;
};
/**
* \brief Sub-buffer
*/
class SubBuffer : public MemObject
{
public:
/**
* \brief Constructor
* \param parent parent \c Coal::Buffer
* \param offset offset in \p parent of the start of this sub-buffer
* \param size size of the sub-buffer
* \param flags memory flags (must be compatible with the \p parent's ones)
* \param errcode_ret return code
*/
SubBuffer(class Buffer *parent, size_t offset, size_t size,
cl_mem_flags flags, cl_int *errcode_ret);
size_t size() const; /*!< \brief Size */
Type type() const; /*!< \brief Return that we are a \c Coal::MemObject::SubBuffer */
bool allocate(DeviceInterface *device); /*!< \brief Allocate the \b parent \c Coal::Buffer */
size_t offset() const; /*!< \brief Offset in bytes */
class Buffer *parent() const; /*!< \brief Parent \c Coal::Buffer */
private:
size_t p_offset, p_size;
class Buffer *p_parent;
};
/**
* \brief 2D image
*/
class Image2D : public MemObject
{
public:
/**
* \brief Constructor
* \param ctx parent \c Coal::Context
* \param width width of the image
* \param height height of the image
* \param row_pitch number of bytes in a row of pixels. If 0, defaults to <tt>width * pixel_size()</tt>
* \param format image format
* \param host_ptr host pointer
* \param flags memory flags
* \param errcode_ret return code
*/
Image2D(Context *ctx, size_t width, size_t height, size_t row_pitch,
const cl_image_format *format, void *host_ptr,
cl_mem_flags flags, cl_int *errcode_ret);
virtual size_t size() const; /*!< \brief Size in bytes */
virtual Type type() const; /*!< \brief Return that we are a \c Coal::MemObject::Image2D */
size_t width() const; /*!< \brief Width */
size_t height() const; /*!< \brief Height */
size_t row_pitch() const; /*!< \brief Size in bytes of a row of pixels */
virtual size_t slice_pitch() const; /*!< \brief Size in bytes of the image */
const cl_image_format &format() const; /*!< \brief Image format descriptor */
/**
* \brief Information about this image object
*
* This function is also usable for \c Coal::Image3D objects as it does
* casting when necessary in order to give information when needed.
*
* \copydetails Coal::DeviceInterface::info
*/
cl_int imageInfo(cl_image_info param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret) const;
static size_t element_size(const cl_image_format &format); /*!< \brief Size in bytes of each channel of \p format */
static unsigned int channels(const cl_image_format &format);/*!< \brief Number of channels of \p format */
static size_t pixel_size(const cl_image_format &format); /*!< \brief Size in bytes of a pixel in \p format */
size_t pixel_size() const; /*!< \brief Pixel size of this image */
size_t element_size() const; /*!< \brief Channel size of this image */
unsigned int channels() const; /*!< \brief Number of channels of this image */
private:
size_t p_width, p_height, p_row_pitch;
cl_image_format p_format;
};
/**
* \brief 3D image
*/
class Image3D : public Image2D
{
public:
/**
* \brief Constructor
* \param ctx parent \c Coal::Context
* \param width width of the image
* \param height height of the image
* \param depth depth of the image
* \param row_pitch number of bytes in a row of pixels. If 0, defaults to <tt>width * pixel_size()</tt>
* \param slice_pitch number of bytes in a 2D slice. If 0, defaults to <tt>height * row_pitch()</tt>
* \param format image format
* \param host_ptr host pointer
* \param flags memory flags
* \param errcode_ret return code
*/
Image3D(Context *ctx, size_t width, size_t height, size_t depth,
size_t row_pitch, size_t slice_pitch,
const cl_image_format *format, void *host_ptr,
cl_mem_flags flags, cl_int *errcode_ret);
size_t size() const; /*!< \brief Size in bytes of this image */
Type type() const; /*!< \brief Return that we are a \c Coal::MemObject::Image3D */
size_t depth() const; /*!< \brief Depth of the image */
size_t slice_pitch() const; /*!< \brief Size in bytes of a 2D slice */
private:
size_t p_depth, p_slice_pitch;
};
}
struct _cl_mem : public Devices::MemObject
{};
#endif
//TODO: copyrights
#include "object.h"
using namespace Devices;
static std::list<Object *>& getKnownObjects()
{
static std::list<Object *> known_objects;
return known_objects;
}
Object::Object(Type type, Object *parent)
: p_references(1), p_parent(parent), p_type(type), p_release_parent(true)
{
if(parent)
parent->reference();
// Add object in the list of known objects
getKnownObjects().push_front(this);
p_it = getKnownObjects().begin();
}
Object::~Object()
{
if(p_parent && p_parent->dereference() && p_release_parent)
delete p_parent;
// Remove object from the list of known objects
getKnownObjects().erase(p_it);
}
void Object::reference()
{
p_references++;
}
bool Object::dereference()
{
p_references--;
return (p_references == 0);
}
void Object::setReleaseParent(bool release)
{
p_release_parent = release;
}
unsigned int Object::references() const
{
return p_references;
}
Object *Object::parent() const
{
return p_parent;
}
Object::Type Object::type() const
{
return p_type;
}
bool Object::isA(Object::Type type) const
{
// Check for null values
if(this == 0)
return false;
// Check that the value isn't garbage or freed pointer
std::list<Object *>::const_iterator it = getKnownObjects().begin(),
e = getKnownObjects().end();
while(it != e)
{
if(*it == this)
return this->type() == type;
++it;
}
return false;
}
//TODO: copyrights
#ifndef __REFCOUNTED_H__
#define __REFCOUNTED_H__
#include <list>
namespace Devices
{
/**
* \brief Base class of all the Clover objects
*
* This class implements functions needed by all the Clover objects, like
* reference counting, the object tree (parents/children), etc.
*
* It also uses a special list of known objects, used to check that a pointer
* passed by the user to an OpenCL function actually is an object of the correct
* type. See \c isA().
*/
class Object
{
public:
/**
* \brief Type of object the inherited class actually is
*/
enum Type
{
T_Device, /*!< \brief \c Coal::DeviceInterface */
T_CommandQueue, /*!< \brief \c Coal::CommandQueue */
T_Event, /*!< \brief \c Coal::Event */
T_Context, /*!< \brief \c Coal::Context */
T_Kernel, /*!< \brief \c Coal::Kernel */
T_MemObject, /*!< \brief \c Coal::MemObject */
T_Program, /*!< \brief \c Coal::Program */
T_Sampler /*!< \brief \c Coal::Sampler */
};
/**
* \brief Constructor
* \param type type of the child class calling this constructor
* \param parent parent object
*/
Object(Type type, Object *parent = 0);
virtual ~Object();
/**
* \brief Increments the reference counter
*/
void reference();
/**
* \brief Decrements the reference counter
* \return true if the reference counter has reached 0
*/
bool dereference();
/**
* \brief Reference counter
* \return the number of references of this class currently in use
*/
unsigned int references() const;
/**
* \brief Set if the parent object has to be deleted if its reference count reaches 0
*
* The destructor of \c Coal::Object dereferences its parent object.
* This is done in order to correctly free objects when no object has
* a reference to it anymore.
*
* Some objects such as \c Coal::CommandQueue need to do some operations
* before being deleted. This function tells \c Coal::Object to
* dereference its parent object, but not to call \b delete on it.
*
* \param release true to have \b delete called on the parent object
* when its reference count reaches 0, false to keep it
*/
void setReleaseParent(bool release);
Object *parent() const; /*!< \brief Parent object */
Type type() const; /*!< \brief Type */
/**
* \brief Returns whether this object is an instance of \p type
* \note This function begins with a NULL-check on the \c this pointer,
* so it's safe to use even when \c this is not guaranteed not to
* be NULL.
* \param type type this object must have for the check to pass
* \return true if this object exists and has the correct type
*/
bool isA(Type type) const;
private:
unsigned int p_references;
Object *p_parent;
Type p_type;
std::list<Object *>::iterator p_it;
bool p_release_parent;
};
}
#endif
\ No newline at end of file
LIBRARY opencl
EXPORTS
clBuildProgram @1
clCreateBuffer @2
clCreateCommandQueue @3
clCreateContext @4
clCreateContextFromType @5
clCreateFromGLBuffer @6
clCreateFromGLRenderbuffer @7
clCreateFromGLTexture2D @8
clCreateFromGLTexture3D @9
clCreateImage2D @10
clCreateImage3D @11
clCreateKernel @12
clCreateKernelsInProgram @13
clCreateProgramWithBinary @14
clCreateProgramWithSource @15
clCreateSampler @16
clCreateSubBuffer @17
clCreateUserEvent @18
clEnqueueAcquireGLObjects @19
clEnqueueBarrier @20
clEnqueueCopyBuffer @21
clEnqueueCopyBufferRect @22
clEnqueueCopyBufferToImage @23
clEnqueueCopyImage @24
clEnqueueCopyImageToBuffer @25
clEnqueueMapBuffer @26
clEnqueueMapImage @27
clEnqueueMarker @28
clEnqueueNDRangeKernel @29
clEnqueueNativeKernel @30
clEnqueueReadBuffer @31
clEnqueueReadBufferRect @32
clEnqueueReadImage @33
clEnqueueReleaseGLObjects @34
clEnqueueTask @35
clEnqueueUnmapMemObject @36
clEnqueueWaitForEvents @37
clEnqueueWriteBuffer @38
clEnqueueWriteBufferRect @39
clEnqueueWriteImage @40
clFinish @41
clFlush @42
clGetCommandQueueInfo @43
clGetContextInfo @44
clGetDeviceIDs @45
clGetDeviceInfo @46
clGetEventInfo @47
clGetEventProfilingInfo @48
clGetExtensionFunctionAddress @49
clGetGLObjectInfo @50
clGetGLTextureInfo @51
clGetImageInfo @52
clGetKernelInfo @53
clGetKernelWorkGroupInfo @54
clGetMemObjectInfo @55
clGetPlatformIDs @56
clGetPlatformInfo @57
clGetProgramBuildInfo @58
clGetProgramInfo @59
clGetSamplerInfo @60
clGetSupportedImageFormats @61
clReleaseCommandQueue @62
clReleaseContext @63
clReleaseEvent @64
clReleaseKernel @65
clReleaseMemObject @66
clReleaseProgram @67
clReleaseSampler @68
clRetainCommandQueue @69
clRetainContext @70
clRetainEvent @71
clRetainKernel @72
clRetainMemObject @73
clRetainProgram @74
clRetainSampler @75
clSetCommandQueueProperty @76
clSetEventCallback @77
clSetKernelArg @78
clSetMemObjectDestructorCallback @79
clSetUserEventStatus @80
clUnloadCompiler @81
clWaitForEvents @82
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2008-2010 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
******************************************************************************/
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */
#ifndef __OPENCL_H
#define __OPENCL_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __APPLE__
#include <OpenCL/cl.h>
#include <OpenCL/cl_gl.h>
#include <OpenCL/cl_gl_ext.h>
#include <OpenCL/cl_ext.h>
#else
#include "cl.h"
#include "cl_gl.h"
#include "cl_gl_ext.h"
#include "cl_ext.h"
#endif
#ifdef __cplusplus
}
#endif
#endif /* __OPENCL_H */
// For now, only one platform is defined
#include "opencl.h"
#define MAX_PLATFORMS 1
const cl_platform_id DEFAULT_PLATFORM = (cl_platform_id)1;
\ No newline at end of file
//TODO: copyrights
#include "program.h"
#include "device.h"
#include "kernel.h"
#include "builtins.h"
#include "program.h"
//#include <llvm/PassManager.h>
//#include <llvm/Analysis/Passes.h>
//#include <llvm/Analysis/Verifier.h>
//#include <llvm/Transforms/Scalar.h>
//#include <llvm/Transforms/IPO.h>
//#include <llvm/ExecutionEngine/ExecutionEngine.h>
//#include <llvm/ExecutionEngine/JIT.h>
//#include <llvm/ExecutionEngine/Interpreter.h>
#include <string>
#include <iostream>
using namespace Devices;
CPUProgram::CPUProgram(CPUDevice *device, Program *program)
: DeviceProgram(), p_device(device), p_program(program), p_jit(0)
{
}
CPUProgram::~CPUProgram()
{
if(p_jit)
{
// Dont delete the module
//p_jit->removeModule(p_module);
//delete p_jit;
}
}
bool CPUProgram::linkStdLib() const
{
return true;
}
void CPUProgram::createOptimizationPasses(llvm::PassManager *manager, bool optimize)
{
if(optimize)
{
/*
* Inspired by code from "The LLVM Compiler Infrastructure"
*/
//manager->add(llvm::createDeadArgEliminationPass());
//manager->add(llvm::createInstructionCombiningPass());
//manager->add(llvm::createFunctionInliningPass());
//manager->add(llvm::createPruneEHPass()); // Remove dead EH info.
//manager->add(llvm::createGlobalOptimizerPass());
//manager->add(llvm::createGlobalDCEPass()); // Remove dead functions.
//manager->add(llvm::createArgumentPromotionPass());
//manager->add(llvm::createInstructionCombiningPass());
//manager->add(llvm::createJumpThreadingPass());
//manager->add(llvm::createScalarReplAggregatesPass());
//manager->add(llvm::createFunctionAttrsPass()); // Add nocapture.
//manager->add(llvm::createGlobalsModRefPass()); // IP alias analysis.
//manager->add(llvm::createLICMPass()); // Hoist loop invariants.
//manager->add(llvm::createGVNPass()); // Remove redundancies.
//manager->add(llvm::createMemCpyOptPass()); // Remove dead memcpys.
//manager->add(llvm::createDeadStoreEliminationPass());
//manager->add(llvm::createInstructionCombiningPass());
//manager->add(llvm::createJumpThreadingPass());
//manager->add(llvm::createCFGSimplificationPass());
}
}
bool CPUProgram::build(llvm::Module *module)
{
// Nothing to build
p_module = module;
return true;
}
bool CPUProgram::initJIT()
{
if(p_jit)
return true;
if(!p_module)
return false;
// Create the JIT
std::string err;
//llvm::EngineBuilder builder(p_module);
//builder.setErrorStr(&err);
//builder.setAllocateGVsWithCode(false);
//p_jit = builder.create();
//if(!p_jit)
//{
// std::cout << "Unable to create a JIT: " << err << std::endl;
// return false;
//}
//p_jit->DisableSymbolSearching(true); // Avoid an enormous security hole (a kernel calling system())
//p_jit->InstallLazyFunctionCreator(&getBuiltin);
return true;
}
llvm::ExecutionEngine *CPUProgram::jit() const
{
return p_jit;
}
//TODO: copyrights
#ifndef __CPU_PROGRAM_H__
#define __CPU_PROGRAM_H__
#include "device_interface.h"
namespace llvm
{
class ExecutionEngine;
class Module;
}
namespace Devices
{
class CPUDevice;
class Program;
/**
* \brief CPU program
*
* This class implements the \c Coal::DeviceProgram interface for CPU
* acceleration.
*
* It's main purpose is to initialize a \c llvm::JIT object to run LLVM bitcode,
* in \c initJIT().
*/
class CPUProgram : public DeviceProgram
{
public:
/**
* \brief Constructor
* \param device CPU device to which this program is attached
* \param program \c Coal::Program that will be run
*/
CPUProgram(CPUDevice *device, Program *program);
~CPUProgram();
bool linkStdLib() const;
void createOptimizationPasses(llvm::PassManager *manager, bool optimize);
bool build(llvm::Module *module);
/**
* \brief Initialize an LLVM JIT
*
* This function creates a \c llvm::JIT object to run this program on
* the CPU. A few implementation details :
*
* - The JIT is set not to resolve unknown symbols using \c dlsym().
* This way, a malicious kernel cannot execute arbitrary code on
* the host by declaring \c libc functions and calling them.
* - All the unknown function names are passed to \c getBuiltin() to
* get native built-in implementations.
*
* \return true if success, false otherwise
*/
bool initJIT();
llvm::ExecutionEngine *jit() const; /*!< \brief Current LLVM execution engine */
private:
CPUDevice *p_device;
Program *p_program;
llvm::ExecutionEngine *p_jit;
llvm::Module *p_module;
};
}
#endif
//TODO: copyrights
#ifndef __PROPERTYLIST_H__
#define __PROPERTYLIST_H__
/**
* \brief Assign a value of a given type to the return value
* \param type type of the argument
* \param _value value to assign
*/
#define SIMPLE_ASSIGN(type, _value) do { \
value_length = sizeof(type); \
type##_var = (type)_value; \
value = & type##_var; \
} while (0);
/**
* \brief Assign a string to the return value
* \param string the string to assign, as a constant
*/
#define STRING_ASSIGN(string) do { \
static const char str[] = string; \
value_length = sizeof(str); \
value = (void *)str; \
} while (0);
/**
* \brief Assign a memory buffer to the return value
* \note the buffer must remain valid after the end of the \c info() call
* \param size size of the buffer
* \param buf buffer (of type <tt>void *</tt> for instance)
*/
#define MEM_ASSIGN(size, buf) do { \
value_length = size; \
value = (void *)buf; \
} while (0);
#endif
//TODO: copyrights
#include "worker.h"
#include "device.h"
#include "buffer.h"
#include "kernel.h"
#include "builtins.h"
#include "commandqueue.h"
#include "events.h"
#include "memobject.h"
#include "kernel.h"
#include <cstring>
#include <iostream>
using namespace Devices;
void *worker(void *data)
{
CPUDevice *device = (CPUDevice *)data;
bool stop = false;
cl_int errcode;
Event *event;
// Initialize TLS
setWorkItemsData(0, 0);
while(true)
{
event = device->getEvent(stop);
// Ensure we have a good event and we don't have to stop
if(stop) break;
if(!event) continue;
// Get info about the event and its command queue
Event::Type t = event->type();
CommandQueue *queue = 0;
cl_command_queue_properties queue_props = 0;
errcode = CL_SUCCESS;
event->info(CL_EVENT_COMMAND_QUEUE, sizeof(CommandQueue *), &queue, 0);
if(queue)
queue->info(CL_QUEUE_PROPERTIES, sizeof(cl_command_queue_properties),
&queue_props, 0);
if(queue_props & CL_QUEUE_PROFILING_ENABLE)
event->updateTiming(Event::Start);
// Execute the action
switch(t)
{
case Event::ReadBuffer:
case Event::WriteBuffer:
{
ReadWriteBufferEvent *e = (ReadWriteBufferEvent *)event;
CPUBuffer *buf = (CPUBuffer *)e->buffer()->deviceBuffer(device);
char *data = (char *)buf->data();
data += e->offset();
if(t == Event::ReadBuffer)
std::memcpy(e->ptr(), data, e->cb());
else
std::memcpy(data, e->ptr(), e->cb());
break;
}
case Event::CopyBuffer:
{
CopyBufferEvent *e = (CopyBufferEvent *)event;
CPUBuffer *src = (CPUBuffer *)e->source()->deviceBuffer(device);
CPUBuffer *dst = (CPUBuffer *)e->destination()->deviceBuffer(device);
std::memcpy(dst->data(), src->data(), e->cb());
break;
}
case Event::ReadBufferRect:
case Event::WriteBufferRect:
case Event::CopyBufferRect:
case Event::ReadImage:
case Event::WriteImage:
case Event::CopyImage:
case Event::CopyBufferToImage:
case Event::CopyImageToBuffer:
{
// src = buffer and dst = mem if note copy
ReadWriteCopyBufferRectEvent *e = (ReadWriteCopyBufferRectEvent *)event;
CPUBuffer *src_buf = (CPUBuffer *)e->source()->deviceBuffer(device);
unsigned char *src = (unsigned char *)src_buf->data();
unsigned char *dst;
switch(t)
{
case Event::CopyBufferRect:
case Event::CopyImage:
case Event::CopyImageToBuffer:
case Event::CopyBufferToImage:
{
CopyBufferRectEvent *cbre = (CopyBufferRectEvent *)e;
CPUBuffer *dst_buf =
(CPUBuffer *)cbre->destination()->deviceBuffer(device);
dst = (unsigned char *)dst_buf->data();
break;
}
default:
{
// dst = host memory location
ReadWriteBufferRectEvent *rwbre = (ReadWriteBufferRectEvent *)e;
dst = (unsigned char *)rwbre->ptr();
}
}
// Iterate over the lines to copy and use memcpy
for(size_t z = 0; z<e->region(2); ++z)
{
for(size_t y = 0; y<e->region(1); ++y)
{
unsigned char *s;
unsigned char *d;
d = imageData(dst,
e->dst_origin(0),
y + e->dst_origin(1),
z + e->dst_origin(2),
e->dst_row_pitch(),
e->dst_slice_pitch(),
1);
s = imageData(src,
e->src_origin(0),
y + e->src_origin(1),
z + e->src_origin(2),
e->src_row_pitch(),
e->src_slice_pitch(),
1);
// Copying and image to a buffer may need to add an offset
// to the buffer address (its rectangular origin is
// always (0, 0, 0)).
if(t == Event::CopyBufferToImage)
{
CopyBufferToImageEvent *cptie = (CopyBufferToImageEvent *)e;
s += cptie->offset();
}
else if(t == Event::CopyImageToBuffer)
{
CopyImageToBufferEvent *citbe = (CopyImageToBufferEvent *)e;
d += citbe->offset();
}
if(t == Event::WriteBufferRect || t == Event::WriteImage)
std::memcpy(s, d, e->region(0)); // Write dest (memory) in src
else
std::memcpy(d, s, e->region(0)); // Write src (buffer) in dest (memory), or copy the buffers
}
}
break;
}
case Event::MapBuffer:
case Event::MapImage:
// All was already done in CPUBuffer::initEventDeviceData()
break;
case Event::NativeKernel:
{
NativeKernelEvent *e = (NativeKernelEvent *)event;
void(*func)(void *) = (void(*)(void *))e->function();
void *args = e->args();
func(args);
break;
}
case Event::NDRangeKernel:
case Event::TaskKernel:
{
KernelEvent *e = (KernelEvent *)event;
CPUKernelEvent *ke = (CPUKernelEvent *)e->deviceData();
// Take an instance
CPUKernelWorkGroup *instance = ke->takeInstance();
ke = 0; // Unlocked, don't use anymore
if(!instance->run())
errcode = CL_INVALID_PROGRAM_EXECUTABLE;
delete instance;
break;
}
default:
break;
}
// Cleanups
if(errcode == CL_SUCCESS)
{
bool finished = true;
if(event->type() == Event::NDRangeKernel ||
event->type() == Event::TaskKernel)
{
CPUKernelEvent *ke = (CPUKernelEvent *)event->deviceData();
finished = ke->finished();
}
if(finished)
{
event->setStatus(Event::Complete);
if(queue_props & CL_QUEUE_PROFILING_ENABLE)
event->updateTiming(Event::End);
// Clean the queue
if(queue)
queue->cleanEvents();
}
}
else
{
// The event failed
event->setStatus((Event::Status)errcode);
if(queue_props & CL_QUEUE_PROFILING_ENABLE)
event->updateTiming(Event::End);
}
}
// Free mmapped() data if needed
size_t mapped_size;
void *mapped_data = getWorkItemsData(mapped_size);
/*if(mapped_data)
munmap(mapped_data, mapped_size);*/
return 0;
}
//TODO: copyrights
#ifndef __CPU_WORKER_H__
#define __CPU_WORKER_H__
/**
* \brief Main loop of the CPU worker threads
*
* This function is run by as many thread as they are CPU cores on the host
* system. As explained by \ref events , this function waits until there
* are \c Coal::Event objects to process and handle them.
*/
void *worker(void *data);
#endif

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenCL1", "OpenCL1\OpenCL1.vcxproj", "{EABBE82D-CDD3-4BE2-8A29-B5BF4569B723}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloTriangle", "HelloTriangle\HelloTriangle.vcxproj", "{50F99088-AF0E-4A66-9619-E3FF87F3B246}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EABBE82D-CDD3-4BE2-8A29-B5BF4569B723}.Debug|Win32.ActiveCfg = Debug|Win32
{EABBE82D-CDD3-4BE2-8A29-B5BF4569B723}.Debug|Win32.Build.0 = Debug|Win32
{EABBE82D-CDD3-4BE2-8A29-B5BF4569B723}.Debug|x64.ActiveCfg = Debug|x64
{EABBE82D-CDD3-4BE2-8A29-B5BF4569B723}.Debug|x64.Build.0 = Debug|x64
{EABBE82D-CDD3-4BE2-8A29-B5BF4569B723}.Release|Win32.ActiveCfg = Release|Win32
{EABBE82D-CDD3-4BE2-8A29-B5BF4569B723}.Release|Win32.Build.0 = Release|Win32
{EABBE82D-CDD3-4BE2-8A29-B5BF4569B723}.Release|x64.ActiveCfg = Release|x64
{EABBE82D-CDD3-4BE2-8A29-B5BF4569B723}.Release|x64.Build.0 = Release|x64
{50F99088-AF0E-4A66-9619-E3FF87F3B246}.Debug|Win32.ActiveCfg = Debug|Win32
{50F99088-AF0E-4A66-9619-E3FF87F3B246}.Debug|Win32.Build.0 = Debug|Win32
{50F99088-AF0E-4A66-9619-E3FF87F3B246}.Debug|x64.ActiveCfg = Debug|x64
{50F99088-AF0E-4A66-9619-E3FF87F3B246}.Debug|x64.Build.0 = Debug|x64
{50F99088-AF0E-4A66-9619-E3FF87F3B246}.Release|Win32.ActiveCfg = Release|Win32
{50F99088-AF0E-4A66-9619-E3FF87F3B246}.Release|Win32.Build.0 = Release|Win32
{50F99088-AF0E-4A66-9619-E3FF87F3B246}.Release|x64.ActiveCfg = Release|x64
{50F99088-AF0E-4A66-9619-E3FF87F3B246}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
========================================================================
DYNAMIC LINK LIBRARY : SwiftCL Project Overview
========================================================================
AppWizard has created this SwiftCL DLL for you.
This file contains a summary of what you will find in each of the files that
make up your SwiftCL application.
SwiftCL.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
SwiftCL.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
SwiftCL.cpp
This is the main DLL source file.
SwiftCL.h
This file contains a class declaration.
AssemblyInfo.cpp
Contains custom attributes for modifying assembly metadata.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////
// stdafx.cpp : source file that includes just the standard includes
// SwiftCL.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{26973B5F-B02B-446F-8D7A-3001406AB55F}</ProjectGuid>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Keyword>ManagedCProj</Keyword>
<RootNamespace>SwiftCL</RootNamespace>
<ProjectName>OpenCL</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CLRSupport>false</CLRSupport>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
<EnableManagedIncrementalBuild>false</EnableManagedIncrementalBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<OmitFramePointers />
<MinimalRebuild>false</MinimalRebuild>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeaderFile />
<BrowseInformation>true</BrowseInformation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>
</AdditionalDependencies>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
<ModuleDefinitionFile>opencl.def</ModuleDefinitionFile>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies />
<ModuleDefinitionFile>opencl.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="cl.h" />
<ClInclude Include="cl_ext.h" />
<ClInclude Include="cl_gl.h" />
<ClInclude Include="cl_gl_ext.h" />
<ClInclude Include="cl_platform.h" />
<ClInclude Include="debug.h" />
<ClInclude Include="opencl.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="cl.cpp" />
<ClCompile Include="cl_ext.cpp" />
<ClCompile Include="cl_gl.cpp" />
<ClCompile Include="cl_gl_ext.cpp" />
<ClCompile Include="dllmain.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="app.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="app.ico" />
</ItemGroup>
<ItemGroup>
<None Include="opencl.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
#include "cl_ext.h"
#include "debug.h"
cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE(cl_mem /* memobj */,
void(* /*pfn_notify*/)(cl_mem /* memobj */, void* /*user_data*/),
void * /*user_data */) CL_EXT_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE(const char * /* errstr */,
const void * /* private_info */,
size_t /* cb */,
void * /* user_data */) CL_EXT_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
}
extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE(const char * /* errstr */,
const void * /* private_info */,
size_t /* cb */,
void * /* user_data */) CL_EXT_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
}
extern void CL_API_ENTRY clLogMessagesToStderrAPPLE(const char * /* errstr */,
const void * /* private_info */,
size_t /* cb */,
void * /* user_data */) CL_EXT_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
}
extern CL_API_ENTRY cl_int CL_API_CALL
clIcdGetPlatformIDsKHR(cl_uint /* num_entries */,
cl_platform_id * /* platforms */,
cl_uint * /* num_platforms */)
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_int CL_API_CALL
clReleaseDeviceEXT(cl_device_id /*device*/) CL_EXT_SUFFIX__VERSION_1_1
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_int CL_API_CALL
clRetainDeviceEXT(cl_device_id /*device*/) CL_EXT_SUFFIX__VERSION_1_1
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_int CL_API_CALL
clCreateSubDevicesEXT(cl_device_id /*in_device*/,
const cl_device_partition_property_ext * /* properties */,
cl_uint /*num_entries*/,
cl_device_id * /*out_devices*/,
cl_uint * /*num_devices*/) CL_EXT_SUFFIX__VERSION_1_1
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_int CL_API_CALL
clGetDeviceImageInfoQCOM(cl_device_id device,
size_t image_width,
size_t image_height,
const cl_image_format *image_format,
cl_image_pitch_info_qcom param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret)
{
UNIMPLEMENTED();
return 0;
}
\ No newline at end of file
#include "cl_gl.h"
#include "debug.h"
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLBuffer(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLuint /* bufobj */,
int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLTexture2D(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLenum /* target */,
cl_GLint /* miplevel */,
cl_GLuint /* texture */,
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLTexture3D(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLenum /* target */,
cl_GLint /* miplevel */,
cl_GLuint /* texture */,
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLRenderbuffer(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLuint /* renderbuffer */,
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_int CL_API_CALL
clGetGLObjectInfo(cl_mem /* memobj */,
cl_gl_object_type * /* gl_object_type */,
cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_int CL_API_CALL
clGetGLTextureInfo(cl_mem /* memobj */,
cl_gl_texture_info /* param_name */,
size_t /* param_value_size */,
void * /* param_value */,
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */,
cl_uint /* num_objects */,
const cl_mem * /* mem_objects */,
cl_uint /* num_events_in_wait_list */,
const cl_event * /* event_wait_list */,
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */,
cl_uint /* num_objects */,
const cl_mem * /* mem_objects */,
cl_uint /* num_events_in_wait_list */,
const cl_event * /* event_wait_list */,
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
extern CL_API_ENTRY cl_int CL_API_CALL
clGetGLContextInfoKHR(const cl_context_properties * /* properties */,
cl_gl_context_info /* param_name */,
size_t /* param_value_size */,
void * /* param_value */,
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0
{
UNIMPLEMENTED();
return 0;
}
\ No newline at end of file
/**********************************************************************************
* Copyright (c) 2008-2010 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
**********************************************************************************/
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */
/*
* cl_gl.h contains Khronos-approved (KHR) OpenCL extensions which have
* OpenGL dependencies. The application is responsible for #including
* OpenGL or OpenGL ES headers before #including cl_gl.h.
*/
#ifndef __OPENCL_CL_GL_H
#define __OPENCL_CL_GL_H
#ifdef __APPLE__
#include <OpenCL/cl.h>
#include <OpenGL/CGLDevice.h>
#else
#include "cl.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef cl_uint cl_gl_object_type;
typedef cl_uint cl_gl_texture_info;
typedef cl_uint cl_gl_platform_info;
typedef struct __GLsync *cl_GLsync;
/* cl_gl_object_type */
#define CL_GL_OBJECT_BUFFER 0x2000
#define CL_GL_OBJECT_TEXTURE2D 0x2001
#define CL_GL_OBJECT_TEXTURE3D 0x2002
#define CL_GL_OBJECT_RENDERBUFFER 0x2003
/* cl_gl_texture_info */
#define CL_GL_TEXTURE_TARGET 0x2004
#define CL_GL_MIPMAP_LEVEL 0x2005
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLBuffer(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLuint /* bufobj */,
int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLTexture2D(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLenum /* target */,
cl_GLint /* miplevel */,
cl_GLuint /* texture */,
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLTexture3D(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLenum /* target */,
cl_GLint /* miplevel */,
cl_GLuint /* texture */,
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLRenderbuffer(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLuint /* renderbuffer */,
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clGetGLObjectInfo(cl_mem /* memobj */,
cl_gl_object_type * /* gl_object_type */,
cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clGetGLTextureInfo(cl_mem /* memobj */,
cl_gl_texture_info /* param_name */,
size_t /* param_value_size */,
void * /* param_value */,
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */,
cl_uint /* num_objects */,
const cl_mem * /* mem_objects */,
cl_uint /* num_events_in_wait_list */,
const cl_event * /* event_wait_list */,
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */,
cl_uint /* num_objects */,
const cl_mem * /* mem_objects */,
cl_uint /* num_events_in_wait_list */,
const cl_event * /* event_wait_list */,
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0;
/* cl_khr_gl_sharing extension */
#define cl_khr_gl_sharing 1
typedef cl_uint cl_gl_context_info;
/* Additional Error Codes */
#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000
/* cl_gl_context_info */
#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006
#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007
/* Additional cl_context_properties */
#define CL_GL_CONTEXT_KHR 0x2008
#define CL_EGL_DISPLAY_KHR 0x2009
#define CL_GLX_DISPLAY_KHR 0x200A
#define CL_WGL_HDC_KHR 0x200B
#define CL_CGL_SHAREGROUP_KHR 0x200C
extern CL_API_ENTRY cl_int CL_API_CALL
clGetGLContextInfoKHR(const cl_context_properties * /* properties */,
cl_gl_context_info /* param_name */,
size_t /* param_value_size */,
void * /* param_value */,
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
typedef CL_API_ENTRY cl_int(CL_API_CALL *clGetGLContextInfoKHR_fn)(
const cl_context_properties * properties,
cl_gl_context_info param_name,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret);
#ifdef __cplusplus
}
#endif
#endif /* __OPENCL_CL_GL_H */
\ No newline at end of file
#include "cl_gl_ext.h"
#include "debug.h"
extern CL_API_ENTRY cl_event CL_API_CALL
clCreateEventFromGLsyncKHR(cl_context /* context */,
cl_GLsync /* cl_GLsync */,
cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1
{
UNIMPLEMENTED();
return 0;
}
\ No newline at end of file
/**********************************************************************************
* Copyright (c) 2008-2010 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
**********************************************************************************/
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */
/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */
/* OpenGL dependencies. */
#ifndef __OPENCL_CL_GL_EXT_H
#define __OPENCL_CL_GL_EXT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __APPLE__
#include <OpenCL/cl_gl.h>
#else
#include "cl_gl.h"
#endif
/*
* For each extension, follow this template
* /* cl_VEN_extname extension */
/* #define cl_VEN_extname 1
* ... define new types, if any
* ... define new tokens, if any
* ... define new APIs, if any
*
* If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header
* This allows us to avoid having to decide whether to include GL headers or GLES here.
*/
/*
* cl_khr_gl_event extension
* See section 9.9 in the OpenCL 1.1 spec for more information
*/
#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D
extern CL_API_ENTRY cl_event CL_API_CALL
clCreateEventFromGLsyncKHR(cl_context /* context */,
cl_GLsync /* cl_GLsync */,
cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1;
#ifdef __cplusplus
}
#endif
#endif /* __OPENCL_CL_GL_EXT_H */
\ No newline at end of file
#include <assert.h>
#include <stdio.h>
#define UNIMPLEMENTED() do { \
static FILE* file = nullptr; \
file = fopen("C:/Users/mgregoire/opencl.txt", "w"); \
fprintf(file, "hi\n"); \
fclose(file); \
assert(false); \
} while(0)
\ No newline at end of file
// dllmain.cpp : Defines the entry point for the DLL application.
#include "windows.h"
#include "opencl.h"
#include "debug.h"
#include <WinUser.h>
#if defined(_WIN32)
#define IDD_DIALOG1 101
static INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT rect;
switch(uMsg)
{
case WM_INITDIALOG:
GetWindowRect(GetDesktopWindow(), &rect);
SetWindowPos(hwnd, HWND_TOP, rect.right / 2, rect.bottom / 2, 0, 0, SWP_NOSIZE);
SetTimer(hwnd, 1, 100, NULL);
return TRUE;
case WM_COMMAND:
if(LOWORD(wParam) == IDCANCEL)
{
EndDialog(hwnd, 0);
}
break;
case WM_TIMER:
if(IsDebuggerPresent())
{
EndDialog(hwnd, 0);
}
}
return FALSE;
}
static void WaitForDebugger(HINSTANCE instance)
{
if(!IsDebuggerPresent())
{
HRSRC dialog = FindResource(instance, MAKEINTRESOURCE(IDD_DIALOG1), RT_DIALOG);
DLGTEMPLATE *dialogTemplate = (DLGTEMPLATE*)LoadResource(instance, dialog);
DialogBoxIndirect(instance, dialogTemplate, NULL, DebuggerWaitDialogProc);
}
}
BOOL APIENTRY DllMain(HINSTANCE instance, DWORD ul_reason_for_call, LPVOID lpReserved)
{
UNIMPLEMENTED();
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
WaitForDebugger(instance);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif
LIBRARY opencl
EXPORTS
clBuildProgram @1
clCreateBuffer @2
clCreateCommandQueue @3
clCreateContext @4
clCreateContextFromType @5
clCreateFromGLBuffer @6
clCreateFromGLRenderbuffer @7
clCreateFromGLTexture2D @8
clCreateFromGLTexture3D @9
clCreateImage2D @10
clCreateImage3D @11
clCreateKernel @12
clCreateKernelsInProgram @13
clCreateProgramWithBinary @14
clCreateProgramWithSource @15
clCreateSampler @16
clCreateSubBuffer @17
clCreateUserEvent @18
clEnqueueAcquireGLObjects @19
clEnqueueBarrier @20
clEnqueueCopyBuffer @21
clEnqueueCopyBufferRect @22
clEnqueueCopyBufferToImage @23
clEnqueueCopyImage @24
clEnqueueCopyImageToBuffer @25
clEnqueueMapBuffer @26
clEnqueueMapImage @27
clEnqueueMarker @28
clEnqueueNDRangeKernel @29
clEnqueueNativeKernel @30
clEnqueueReadBuffer @31
clEnqueueReadBufferRect @32
clEnqueueReadImage @33
clEnqueueReleaseGLObjects @34
clEnqueueTask @35
clEnqueueUnmapMemObject @36
clEnqueueWaitForEvents @37
clEnqueueWriteBuffer @38
clEnqueueWriteBufferRect @39
clEnqueueWriteImage @40
clFinish @41
clFlush @42
clGetCommandQueueInfo @43
clGetContextInfo @44
clGetDeviceIDs @45
clGetDeviceInfo @46
clGetEventInfo @47
clGetEventProfilingInfo @48
clGetExtensionFunctionAddress @49
clGetGLObjectInfo @50
clGetGLTextureInfo @51
clGetImageInfo @52
clGetKernelInfo @53
clGetKernelWorkGroupInfo @54
clGetMemObjectInfo @55
clGetPlatformIDs @56
clGetPlatformInfo @57
clGetProgramBuildInfo @58
clGetProgramInfo @59
clGetSamplerInfo @60
clGetSupportedImageFormats @61
clReleaseCommandQueue @62
clReleaseContext @63
clReleaseEvent @64
clReleaseKernel @65
clReleaseMemObject @66
clReleaseProgram @67
clReleaseSampler @68
clRetainCommandQueue @69
clRetainContext @70
clRetainEvent @71
clRetainKernel @72
clRetainMemObject @73
clRetainProgram @74
clRetainSampler @75
clSetCommandQueueProperty @76
clSetEventCallback @77
clSetKernelArg @78
clSetMemObjectDestructorCallback @79
clSetUserEventStatus @80
clUnloadCompiler @81
clWaitForEvents @82
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2008-2010 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
******************************************************************************/
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */
#ifndef __OPENCL_H
#define __OPENCL_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __APPLE__
#include <OpenCL/cl.h>
#include <OpenCL/cl_gl.h>
#include <OpenCL/cl_gl_ext.h>
#include <OpenCL/cl_ext.h>
#else
#include "cl.h"
#include "cl_gl.h"
#include "cl_gl_ext.h"
#include "cl_ext.h"
#endif
#ifdef __cplusplus
}
#endif
#endif /* __OPENCL_H */
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by app.rc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment