summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Rusin <zack@kde.org>2009-08-21 14:35:59 -0400
committerZack Rusin <zack@kde.org>2009-08-21 14:35:59 -0400
commit17b6f64ae0523802d4f85492b8def361b911252c (patch)
tree303028ef5f27ee46a0ddcc0597dfffa28c7e1c47
parent4d8f029a62bedfe829cbc3c57327ecfd8161b129 (diff)
link in llvm/clang
-rw-r--r--CMakeLists.txt4
-rw-r--r--cmake/modules/FindLLVM.cmake63
-rw-r--r--examples/trivial/CMakeLists.txt6
-rw-r--r--src/CMakeLists.txt81
-rw-r--r--src/compiler/compiler.cpp42
-rw-r--r--src/compiler/compiler.h27
-rw-r--r--src/core/api_command.cpp42
-rw-r--r--src/core/api_context.cpp47
-rw-r--r--src/core/api_device.cpp132
-rw-r--r--src/core/api_enqueue.cpp221
-rw-r--r--src/core/api_event.cpp31
-rw-r--r--src/core/api_flush.cpp14
-rw-r--r--src/core/api_gl.cpp86
-rw-r--r--src/core/api_kernel.cpp61
-rw-r--r--src/core/api_memory.cpp84
-rw-r--r--src/core/api_platform.cpp34
-rw-r--r--src/core/api_profiling.cpp13
-rw-r--r--src/core/api_program.cpp74
-rw-r--r--src/core/api_sampler.cpp34
-rw-r--r--src/core/context.h16
-rw-r--r--src/core/device.cpp228
-rw-r--r--src/core/device.h47
-rw-r--r--src/core/deviceinfo.h67
23 files changed, 1405 insertions, 49 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f00d2b2..8fc1772 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.6)
project(Clover)
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
+
# project version
SET(${PROJECT_NAME}_MAJOR_VERSION 0)
SET(${PROJECT_NAME}_MINOR_VERSION 1)
@@ -13,5 +15,7 @@ SET(${PROJECT_NAME}_SOVERSION 1.0.0)
OPTION(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON)
+Find_Package(LLVM REQUIRED)
+
add_subdirectory(src)
add_subdirectory(examples)
diff --git a/cmake/modules/FindLLVM.cmake b/cmake/modules/FindLLVM.cmake
new file mode 100644
index 0000000..ef8f7f1
--- /dev/null
+++ b/cmake/modules/FindLLVM.cmake
@@ -0,0 +1,63 @@
+# Detect LLVM and set various variable to link against the different component of LLVM
+#
+# NOTE: This is a modified version of the module originally found in the OpenGTL project
+# at www.opengtl.org
+#
+# LLVM_BIN_DIR : directory with LLVM binaries
+# LLVM_LIB_DIR : directory with LLVM library
+# LLVM_INCLUDE_DIR : directory with LLVM include
+#
+# LLVM_COMPILE_FLAGS : compile flags needed to build a program using LLVM headers
+# LLVM_LDFLAGS : ldflags needed to link
+# LLVM_LIBS_CORE : ldflags needed to link against a LLVM core library
+# LLVM_LIBS_JIT : ldflags needed to link against a LLVM JIT
+# LLVM_LIBS_JIT_OBJECTS : objects you need to add to your source when using LLVM JIT
+
+if (LLVM_INCLUDE_DIR)
+ set(LLVM_FOUND TRUE)
+else (LLVM_INCLUDE_DIR)
+
+find_program(LLVM_CONFIG_EXECUTABLE
+ NAMES llvm-config
+ PATHS
+ /opt/local/bin
+)
+
+MACRO(FIND_LLVM_LIBS LLVM_CONFIG_EXECUTABLE _libname_ LIB_VAR OBJECT_VAR)
+ exec_program( ${LLVM_CONFIG_EXECUTABLE} ARGS --libs ${_libname_} OUTPUT_VARIABLE ${LIB_VAR} )
+ STRING(REGEX MATCHALL "[^ ]*[.]o[ $]" ${OBJECT_VAR} ${${LIB_VAR}})
+ SEPARATE_ARGUMENTS(${OBJECT_VAR})
+ STRING(REGEX REPLACE "[^ ]*[.]o[ $]" "" ${LIB_VAR} ${${LIB_VAR}})
+ENDMACRO(FIND_LLVM_LIBS)
+
+
+exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --bindir OUTPUT_VARIABLE LLVM_BIN_DIR )
+exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --libdir OUTPUT_VARIABLE LLVM_LIB_DIR )
+#MESSAGE(STATUS "LLVM lib dir: " ${LLVM_LIB_DIR})
+exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --includedir OUTPUT_VARIABLE LLVM_INCLUDE_DIR )
+
+
+exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --cxxflags OUTPUT_VARIABLE LLVM_COMPILE_FLAGS )
+MESSAGE(STATUS "LLVM CXX flags: " ${LLVM_COMPILE_FLAGS})
+exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --ldflags OUTPUT_VARIABLE LLVM_LDFLAGS )
+MESSAGE(STATUS "LLVM LD flags: " ${LLVM_LDFLAGS})
+exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --libs core bitreader bitwriter linker scalaropts ipo codegen selectiondag OUTPUT_VARIABLE LLVM_LIBS_CORE )
+MESSAGE(STATUS "LLVM core libs: " ${LLVM_LIBS_CORE})
+FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "jit native" LLVM_LIBS_JIT LLVM_LIBS_JIT_OBJECTS )
+#STRING(REPLACE " -lLLVMCore -lLLVMSupport -lLLVMSystem" "" LLVM_LIBS_JIT ${LLVM_LIBS_JIT_RAW})
+MESSAGE(STATUS "LLVM JIT libs: " ${LLVM_LIBS_JIT})
+MESSAGE(STATUS "LLVM JIT objs: " ${LLVM_LIBS_JIT_OBJECTS})
+
+if(LLVM_INCLUDE_DIR)
+ set(LLVM_FOUND TRUE)
+endif(LLVM_INCLUDE_DIR)
+
+if(LLVM_FOUND)
+ message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIR}")
+else(LLVM_FOUND)
+ if(LLVM_FIND_REQUIRED)
+ message(FATAL_ERROR "Could NOT find LLVM")
+ endif(LLVM_FIND_REQUIRED)
+endif(LLVM_FOUND)
+
+endif (LLVM_INCLUDE_DIR)
diff --git a/examples/trivial/CMakeLists.txt b/examples/trivial/CMakeLists.txt
index bfbe273..26de4b2 100644
--- a/examples/trivial/CMakeLists.txt
+++ b/examples/trivial/CMakeLists.txt
@@ -1,8 +1,8 @@
include_directories (${Clover_SOURCE_DIR}/include)
message(STATUS "source is ${Clover_SOURCE_DIR}")
-link_directories (${Clover_BINARY_DIR}/src)
+link_directories(${Clover_BINARY_DIR}/src)
-add_executable (basic basic.c)
+add_executable(basic basic.c)
-target_link_libraries (basic OpenCL)
+target_link_libraries(basic OpenCL)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5e67495..b2ded24 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,20 +1,26 @@
include_directories (${Clover_SOURCE_DIR}/include
${Clover_SOURCE_DIR}
+ ${LLVM_INCLUDE_DIR}
${GALLIUM}/include
${GALLIUM}/src/gallium/include
${GALLIUM}/src/gallium/auxiliary
${GALLIUM}/src/gallium/drivers
)
-add_library(OpenCL SHARED
- core/api_command.cpp core/api_device.cpp
- core/api_event.cpp core/api_kernel.cpp
- core/api_platform.cpp core/api_program.cpp
- core/device.cpp core/api_context.cpp
- core/api_enqueue.cpp core/api_flush.cpp
- core/api_memory.cpp core/api_profiling.cpp
- core/api_sampler.cpp core/api_gl.cpp
- ../cpuwinsys/cpuwinsys.c)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
+
+set(CLOVER_SRC_FILES
+ core/api_command.cpp core/api_device.cpp
+ core/api_event.cpp core/api_kernel.cpp
+ core/api_platform.cpp core/api_program.cpp
+ core/device.cpp core/api_context.cpp
+ core/api_enqueue.cpp core/api_flush.cpp
+ core/api_memory.cpp core/api_profiling.cpp
+ core/api_sampler.cpp core/api_gl.cpp
+ compiler/compiler.cpp
+ ../cpuwinsys/cpuwinsys.c)
+
+add_library(OpenCL SHARED ${CLOVER_SRC_FILES})
SET(LIBRARY_OUTPUT_PATH ${Clover_BINARY_DIR}/lib)
@@ -23,18 +29,10 @@ SET_TARGET_PROPERTIES(OpenCL PROPERTIES
SOVERSION ${${PROJECT_NAME}_SOVERSION} )
#message(STATUS "some project ${${PROJECT_NAME}_VERSION}")
-TARGET_LINK_LIBRARIES(OpenCL
- ${GALLIUM}/src/gallium/auxiliary/pipebuffer/libpipebuffer.a
- ${GALLIUM}/src/gallium/auxiliary/sct/libsct.a
- ${GALLIUM}/src/gallium/auxiliary/draw/libdraw.a
- ${GALLIUM}/src/gallium/auxiliary/rtasm/librtasm.a
- ${GALLIUM}/src/gallium/auxiliary/translate/libtranslate.a
- ${GALLIUM}/src/gallium/auxiliary/cso_cache/libcso_cache.a
- ${GALLIUM}/src/gallium/auxiliary/tgsi/libtgsi.a
- ${GALLIUM}/src/gallium/drivers/softpipe/libsoftpipe.a
- ${GALLIUM}/src/gallium/auxiliary/util/libutil.a
- )
-
+set_source_files_properties( ${CLOVER_SRC_FILES}
+ PROPERTIES COMPILE_FLAGS ${LLVM_COMPILE_FLAGS})
+set_target_properties(OpenCL
+ PROPERTIES LINK_FLAGS ${LLVM_LDFLAGS})
find_library(CLANG_CODEGEN_LIB clangCodeGen)
if (CLANG_CODEGEN_LIB)
@@ -81,30 +79,21 @@ if (CLANG_BASIC_LIB)
target_link_libraries(OpenCL ${CLANG_BASIC_LIB})
endif(CLANG_BASIC_LIB)
-
-find_library(LLVM_BITREADER_LIB LLVMBitReader)
-if (LLVM_BITREADER_LIB)
- target_link_libraries(OpenCL ${LLVM_BITREADER_LIB})
-endif(LLVM_BITREADER_LIB)
+find_library(CLANG_FRONTEND_LIB clangFrontend)
+if (CLANG_FRONTEND_LIB)
+ target_link_libraries(OpenCL ${CLANG_FRONTEND_LIB})
+endif(CLANG_FRONTEND_LIB)
-find_library(LLVM_BITWRITER_LIB LLVMBitWriter)
-if (LLVM_BITWRITER_LIB)
- target_link_libraries(OpenCL ${LLVM_BITWRITER_LIB})
-endif(LLVM_BITWRITER_LIB)
-
-
-find_library(LLVM_CODEGEN_LIB LLVMCodeGen)
-if (LLVM_CODEGEN_LIB)
- target_link_libraries(OpenCL ${LLVM_CODEGEN_LIB})
-endif(LLVM_CODEGEN_LIB)
-
-find_library(LLVM_IPO_LIB LLVMipo)
-if (LLVM_IPO_LIB)
- target_link_libraries(OpenCL ${LLVM_IPO_LIB})
-endif(LLVM_IPO_LIB)
-
-find_library(LLVM_SELECTIONDAG_LIB LLVMSelectionDAG)
-if (LLVM_SELECTIONDAG_LIB)
- target_link_libraries(OpenCL ${LLVM_SELECTIONDAG_LIB})
-endif(LLVM_SELECTIONDAG_LIB)
+TARGET_LINK_LIBRARIES(OpenCL
+ ${GALLIUM}/src/gallium/auxiliary/pipebuffer/libpipebuffer.a
+ ${GALLIUM}/src/gallium/auxiliary/sct/libsct.a
+ ${GALLIUM}/src/gallium/auxiliary/draw/libdraw.a
+ ${GALLIUM}/src/gallium/auxiliary/rtasm/librtasm.a
+ ${GALLIUM}/src/gallium/auxiliary/translate/libtranslate.a
+ ${GALLIUM}/src/gallium/auxiliary/cso_cache/libcso_cache.a
+ ${GALLIUM}/src/gallium/auxiliary/tgsi/libtgsi.a
+ ${GALLIUM}/src/gallium/drivers/softpipe/libsoftpipe.a
+ ${GALLIUM}/src/gallium/auxiliary/util/libutil.a
+ ${LLVM_LIBS_CORE}
+ )
diff --git a/src/compiler/compiler.cpp b/src/compiler/compiler.cpp
new file mode 100644
index 0000000..57b2579
--- /dev/null
+++ b/src/compiler/compiler.cpp
@@ -0,0 +1,42 @@
+#include "compiler.h"
+
+#include <clang/Frontend/ASTConsumers.h>
+#include <clang/Basic/Diagnostic.h>
+
+#include <llvm/Module.h>
+#include <llvm/Support/raw_ostream.h>
+#include <llvm/LLVMContext.h>
+
+Compiler::Compiler()
+{
+ init();
+}
+
+Compiler::~Compiler()
+{
+
+}
+
+void Compiler::init()
+{
+ m_langOptions.OpenCL = true;
+}
+
+llvm::Module * Compiler::compile(const std::string &text)
+{
+ clang::Diagnostic diags;
+ clang::ASTConsumer *consumer = 0;
+ std::string moduleId;
+ std::string llvmIr;
+ llvm::raw_string_ostream output(llvmIr);
+
+ consumer = clang::CreateBackendConsumer(
+ clang::Backend_EmitLL,
+ diags,
+ m_langOptions,
+ m_compileOptions,
+ moduleId,
+ &output,
+ llvm::getGlobalContext());
+
+}
diff --git a/src/compiler/compiler.h b/src/compiler/compiler.h
new file mode 100644
index 0000000..ea57314
--- /dev/null
+++ b/src/compiler/compiler.h
@@ -0,0 +1,27 @@
+#ifndef COMPILER_H
+#define COMPILER_H
+
+#include <clang/Basic/LangOptions.h>
+#include <clang/Frontend/CompileOptions.h>
+
+namespace llvm {
+ class Module;
+}
+
+class Compiler
+{
+public:
+ Compiler();
+ ~Compiler();
+
+ llvm::Module *compile(const std::string &text);
+
+private:
+ void init();
+
+private:
+ clang::LangOptions m_langOptions;
+ clang::CompileOptions m_compileOptions;
+};
+
+#endif
diff --git a/src/core/api_command.cpp b/src/core/api_command.cpp
new file mode 100644
index 0000000..4f1c417
--- /dev/null
+++ b/src/core/api_command.cpp
@@ -0,0 +1,42 @@
+#include <OpenCL/cl.h>
+
+// Command Queue APIs
+cl_command_queue
+clCreateCommandQueue(cl_context context,
+ cl_device_id device,
+ cl_command_queue_properties properties,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_int
+clRetainCommandQueue(cl_command_queue command_queue)
+{
+ return 0;
+}
+
+cl_int
+clReleaseCommandQueue(cl_command_queue command_queue)
+{
+ return 0;
+}
+
+cl_int
+clGetCommandQueueInfo(cl_command_queue command_queue,
+ cl_command_queue_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
+
+cl_int
+clSetCommandQueueProperty(cl_command_queue command_queue,
+ cl_command_queue_properties properties,
+ cl_bool enable,
+ cl_command_queue_properties * old_properties)
+{
+ return 0;
+}
diff --git a/src/core/api_context.cpp b/src/core/api_context.cpp
new file mode 100644
index 0000000..fbf3af9
--- /dev/null
+++ b/src/core/api_context.cpp
@@ -0,0 +1,47 @@
+#include <OpenCL/cl.h>
+
+
+// Context APIs
+
+cl_context
+clCreateContext(cl_context_properties properties,
+ cl_uint num_devices,
+ const cl_device_id * devices,
+ logging_fn pfn_notify,
+ void * user_data,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_context
+clCreateContextFromType(cl_context_properties properties,
+ cl_device_type device_type,
+ logging_fn pfn_notify,
+ void * user_data,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_int
+clRetainContext(cl_context context)
+{
+ return 0;
+}
+
+cl_int
+clReleaseContext(cl_context context)
+{
+ return 0;
+}
+
+cl_int
+clGetContextInfo(cl_context context,
+ cl_context_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
diff --git a/src/core/api_device.cpp b/src/core/api_device.cpp
new file mode 100644
index 0000000..cfb61ad
--- /dev/null
+++ b/src/core/api_device.cpp
@@ -0,0 +1,132 @@
+#include "OpenCL/cl.h"
+#include "OpenCL/cl_platform.h"
+
+#include "device.h"
+
+#include "pipe/p_screen.h"
+#include "pipe/p_format.h"
+#include "util/u_memory.h"
+
+#include <string>
+
+// Device APIs
+
+struct CLConstValue {
+ CLConstValue(int _id)
+ : id(_id)
+ {}
+
+ virtual void param(size_t param_value_size,
+ void * param_value,
+ size_t *param_value_size_ret)
+ {}
+
+ int id;
+};
+template <class T>
+struct CLConstValueTemplate : public CLConstValue {
+ CLConstValueTemplate(int _id, T _value)
+ : CLConstValue(id), value(_value)
+ {}
+ T value;
+};
+
+const CLConstValue values[] = {
+ CLConstValueTemplate<std::string>(CL_DEVICE_NAME, std::string("hello")),
+ CLConstValueTemplate<int>(CL_DEVICE_TYPE, (int)3)
+};
+
+static void
+create_gpu_device(cl_device_id * devices,
+ cl_uint * num_devices,
+ cl_uint num_entries)
+{
+}
+
+static void
+create_cpu_device(cl_device_id * devices,
+ cl_uint * num_devices,
+ cl_uint num_entries)
+{
+ Device *device = Device::create(CL_DEVICE_TYPE_CPU);
+
+ devices[0] = (cl_device_id)device;
+ *num_devices = 1;
+}
+
+static void
+create_accel_device(cl_device_id * devices,
+ cl_uint * num_devices,
+ cl_uint num_entries)
+{
+}
+
+
+cl_int
+clGetDeviceIDs(cl_device_type device_type,
+ cl_uint num_entries,
+ cl_device_id * devices,
+ cl_uint * num_devices)
+{
+ cl_bool gpu, cpu, accelerator;
+ cl_uint original_num_entries = num_entries;
+
+ gpu = (device_type & CL_DEVICE_TYPE_DEFAULT) ||
+ (device_type & CL_DEVICE_TYPE_GPU) ||
+ (device_type & CL_DEVICE_TYPE_ALL);
+
+ cpu = (device_type & CL_DEVICE_TYPE_CPU) ||
+ (device_type & CL_DEVICE_TYPE_ALL);
+
+ accelerator = (device_type & CL_DEVICE_TYPE_ACCELERATOR) ||
+ (device_type & CL_DEVICE_TYPE_ALL);
+
+ if (!gpu && !cpu && !accelerator)
+ return CL_INVALID_DEVICE_TYPE;
+
+ if ((!num_entries && devices) || (!num_devices && !devices))
+ return CL_INVALID_VALUE;
+
+ if (gpu && num_entries > 0) {
+ cl_uint num_gpus = 0;
+ create_gpu_device(devices, &num_gpus, num_entries);
+ num_entries -= num_gpus;
+ if (num_devices)
+ *num_devices += num_gpus;
+ }
+
+ if (cpu && num_entries > 0) {
+ cl_uint num_cpus = 0;
+ create_cpu_device(devices, &num_cpus, num_entries);
+ num_entries -= num_cpus;
+ if (num_devices)
+ *num_devices += num_cpus;
+ }
+
+ if (accelerator && num_entries) {
+ cl_uint num_accels = 0;
+ create_accel_device(devices, &num_accels, num_entries);
+ num_entries -= num_accels;
+ if (num_devices)
+ *num_devices += num_accels;
+ }
+
+ if (original_num_entries == num_entries)
+ return CL_DEVICE_NOT_FOUND;
+
+ return CL_SUCCESS;
+}
+
+cl_int
+clGetDeviceInfo(cl_device_id device,
+ cl_device_info opcode,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ if (!device)
+ return CL_INVALID_DEVICE;
+
+ return device->info(opcode, param_value_size, param_value,
+ param_value_size_ret);
+}
diff --git a/src/core/api_enqueue.cpp b/src/core/api_enqueue.cpp
new file mode 100644
index 0000000..15091b4
--- /dev/null
+++ b/src/core/api_enqueue.cpp
@@ -0,0 +1,221 @@
+#include <OpenCL/cl.h>
+
+// Enqueued Commands APIs
+cl_int
+clEnqueueReadBuffer(cl_command_queue command_queue,
+ cl_mem buffer,
+ cl_bool blocking_read,
+ size_t offset,
+ size_t cb,
+ void * ptr,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueWriteBuffer(cl_command_queue command_queue,
+ cl_mem buffer,
+ cl_bool blocking_write,
+ size_t offset,
+ size_t cb,
+ const void * ptr,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueCopyBuffer(cl_command_queue command_queue,
+ cl_mem src_buffer,
+ cl_mem dst_buffer,
+ size_t src_offset,
+ size_t dst_offset,
+ size_t cb,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueReadImage(cl_command_queue command_queue,
+ cl_mem image,
+ cl_bool blocking_read,
+ const size_t * origin,
+ const size_t * region,
+ size_t row_pitch,
+ size_t slice_pitch,
+ void * ptr,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueWriteImage(cl_command_queue command_queue,
+ cl_mem image,
+ cl_bool blocking_write,
+ const size_t * origin,
+ const size_t * region,
+ size_t row_pitch,
+ size_t slice_pitch,
+ const void * ptr,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueCopyImage(cl_command_queue command_queue,
+ cl_mem src_image,
+ cl_mem dst_image,
+ const size_t * src_origin,
+ const size_t * dst_origin,
+ const size_t * region,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueCopyImageToBuffer(cl_command_queue command_queue,
+ cl_mem src_image,
+ cl_mem dst_buffer,
+ const size_t * src_origin,
+ const size_t * region,
+ size_t dst_offset,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueCopyBufferToImage(cl_command_queue command_queue,
+ cl_mem src_buffer,
+ cl_mem dst_image,
+ size_t src_offset,
+ const size_t * dst_origin,
+ const size_t * region,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+void *
+clEnqueueMapBuffer(cl_command_queue command_queue,
+ cl_mem buffer,
+ cl_bool blocking_map,
+ cl_map_flags map_flags,
+ size_t offset,
+ size_t cb,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+void *
+clEnqueueMapImage(cl_command_queue command_queue,
+ cl_mem image,
+ cl_bool blocking_map,
+ cl_map_flags map_flags,
+ const size_t * origin,
+ const size_t * region,
+ size_t * image_row_pitch,
+ size_t * image_slice_pitch,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueUnmapMemObject(cl_command_queue command_queue,
+ cl_mem memobj,
+ void * mapped_ptr,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueNDRangeKernel(cl_command_queue command_queue,
+ cl_kernel kernel,
+ cl_uint work_dim,
+ const size_t * global_work_offset,
+ const size_t * global_work_size,
+ const size_t * local_work_size,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueTask(cl_command_queue command_queue,
+ cl_kernel kernel,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueNativeFnAsKernel(cl_command_queue command_queue,
+ void (*user_func)(void *),
+ void * args,
+ size_t cb_args,
+ cl_uint num_mem_objects,
+ const cl_mem * mem_list,
+ const void ** args_mem_loc,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueMarker(cl_command_queue command_queue,
+ cl_event * event)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueWaitForEvents(cl_command_queue command_queue,
+ cl_uint num_events,
+ const cl_event * event_list)
+{
+ return 0;
+}
+
+cl_int
+clEnqueueBarrier(cl_command_queue command_queue)
+{
+ return 0;
+}
diff --git a/src/core/api_event.cpp b/src/core/api_event.cpp
new file mode 100644
index 0000000..9c08011
--- /dev/null
+++ b/src/core/api_event.cpp
@@ -0,0 +1,31 @@
+#include <OpenCL/cl.h>
+
+// Event Object APIs
+cl_int
+clWaitForEvents(cl_uint num_events,
+ const cl_event * event_list)
+{
+ return 0;
+}
+
+cl_int
+clGetEventInfo(cl_event event,
+ cl_event_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
+
+cl_int
+clRetainEvent(cl_event event)
+{
+ return 0;
+}
+
+cl_int
+clReleaseEvent(cl_event event)
+{
+ return 0;
+}
diff --git a/src/core/api_flush.cpp b/src/core/api_flush.cpp
new file mode 100644
index 0000000..34afab0
--- /dev/null
+++ b/src/core/api_flush.cpp
@@ -0,0 +1,14 @@
+#include <OpenCL/cl.h>
+
+// Flush and Finish APIs
+cl_int
+clFlush(cl_command_queue command_queue)
+{
+ return 0;
+}
+
+cl_int
+clFinish(cl_command_queue command_queue)
+{
+ return 0;
+}
diff --git a/src/core/api_gl.cpp b/src/core/api_gl.cpp
new file mode 100644
index 0000000..757df6a
--- /dev/null
+++ b/src/core/api_gl.cpp
@@ -0,0 +1,86 @@
+#define GL_GLEXT_PROTOTYPES
+#include "GL/gl.h"
+#include "GL/glext.h"
+
+#include "OpenCL/cl.h"
+#include "OpenCL/cl_gl.h"
+
+cl_mem
+clCreateFromGLBuffer(cl_context context,
+ cl_mem_flags flags,
+ GLuint bufobj,
+ int * errcode_ret)
+{
+ return 0;
+}
+
+cl_mem
+clCreateFromGLTexture2D(cl_context context,
+ cl_mem_flags flags,
+ GLenum target,
+ GLint miplevel,
+ GLuint texture,
+ int * errcode_ret)
+{
+ return 0;
+}
+
+cl_mem
+clCreateFromGLTexture3D(cl_context context,
+ cl_mem_flags flags,
+ GLenum target,
+ GLint miplevel,
+ GLuint texture,
+ int * errcode_ret)
+{
+ return 0;
+}
+
+cl_mem
+clCreateFromGLRenderbuffer(cl_context context,
+ cl_mem_flags flags,
+ GLuint renderbuffer,
+ int * errcode_ret)
+{
+ return 0;
+}
+
+cl_int
+clGetGLObjectInfo(cl_mem memobj,
+ cl_gl_object_type * gl_object_type,
+ GLuint * gl_object_name)
+{
+ return 0;
+}
+
+cl_int
+clGetGLTextureInfo(cl_mem memobj,
+ cl_gl_texture_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
+
+cl_int
+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)
+{
+ return 0;
+}
+
+cl_int
+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)
+{
+ return 0;
+}
diff --git a/src/core/api_kernel.cpp b/src/core/api_kernel.cpp
new file mode 100644
index 0000000..27d7c81
--- /dev/null
+++ b/src/core/api_kernel.cpp
@@ -0,0 +1,61 @@
+#include <OpenCL/cl.h>
+
+// Kernel Object APIs
+cl_kernel
+clCreateKernel(cl_program program,
+ const char * kernel_name,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_int
+clCreateKernelsInProgram(cl_program program,
+ cl_uint num_kernels,
+ cl_kernel * kernels,
+ cl_uint * num_kernels_ret)
+{
+ return 0;
+}
+
+cl_int
+clRetainKernel(cl_kernel kernel)
+{
+ return 0;
+}
+
+cl_int
+clReleaseKernel(cl_kernel kernel)
+{
+ return 0;
+}
+
+cl_int
+clSetKernelArg(cl_kernel kernel,
+ cl_uint arg_indx,
+ size_t arg_size,
+ const void * arg_value)
+{
+ return 0;
+}
+
+cl_int
+clGetKernelInfo(cl_kernel kernel,
+ cl_kernel_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
+
+cl_int
+clGetKernelWorkGroupInfo(cl_kernel kernel,
+ cl_device_id device,
+ cl_kernel_work_group_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
diff --git a/src/core/api_memory.cpp b/src/core/api_memory.cpp
new file mode 100644
index 0000000..19d4095
--- /dev/null
+++ b/src/core/api_memory.cpp
@@ -0,0 +1,84 @@
+#include <OpenCL/cl.h>
+
+
+// Memory Object APIs
+cl_mem
+clCreateBuffer(cl_context context,
+ cl_mem_flags flags,
+ size_t size,
+ void * host_ptr,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_mem
+clCreateImage2D(cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format * image_format,
+ size_t image_width,
+ size_t image_height,
+ size_t image_row_pitch,
+ void * host_ptr,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_mem
+clCreateImage3D(cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format * image_format,
+ size_t image_width,
+ size_t image_height,
+ size_t image_depth,
+ size_t image_row_pitch,
+ size_t image_slice_pitch,
+ void * host_ptr,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_int
+clRetainMemObject(cl_mem memobj)
+{
+ return 0;
+}
+
+cl_int
+clReleaseMemObject(cl_mem memobj)
+{
+ return 0;
+}
+
+cl_int
+clGetSupportedImageFormats(cl_context context,
+ cl_mem_flags flags,
+ cl_mem_object_type image_type,
+ cl_uint num_entries,
+ cl_image_format * image_formats,
+ cl_uint * num_image_formats)
+{
+ return 0;
+}
+
+cl_int
+clGetMemObjectInfo(cl_mem memobj,
+ cl_mem_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
+
+cl_int
+clGetImageInfo(cl_mem image,
+ cl_image_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
diff --git a/src/core/api_platform.cpp b/src/core/api_platform.cpp
new file mode 100644
index 0000000..b6429e7
--- /dev/null
+++ b/src/core/api_platform.cpp
@@ -0,0 +1,34 @@
+#include <OpenCL/cl.h>
+
+#include <string.h>
+
+#define PROFILE_STR "FULL_PROFILE"
+#define PROFILE_STR_LEN 12
+
+#define VERSION_STR "OpenCL 1.0"
+#define VERSION_STR_LEN 10
+
+// Platform API
+cl_int
+clGetPlatformInfo(cl_platform_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ switch(param_name) {
+ case CL_PLATFORM_PROFILE:
+ strcpy((char*)param_value, PROFILE_STR);
+ *param_value_size_ret = PROFILE_STR_LEN;
+ break;
+
+ case CL_PLATFORM_VERSION:
+ strcpy((char*)param_value, VERSION_STR);
+ *param_value_size_ret = VERSION_STR_LEN;
+ break;
+
+ default:
+ return CL_INVALID_VALUE;
+ }
+
+ return CL_SUCCESS;
+}
diff --git a/src/core/api_profiling.cpp b/src/core/api_profiling.cpp
new file mode 100644
index 0000000..5980dee
--- /dev/null
+++ b/src/core/api_profiling.cpp
@@ -0,0 +1,13 @@
+#include <OpenCL/cl.h>
+
+// Profiling APIs
+cl_int
+clGetEventProfilingInfo(cl_event event,
+ cl_profiling_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
+
diff --git a/src/core/api_program.cpp b/src/core/api_program.cpp
new file mode 100644
index 0000000..98999fa
--- /dev/null
+++ b/src/core/api_program.cpp
@@ -0,0 +1,74 @@
+#include <OpenCL/cl.h>
+
+// Program Object APIs
+cl_program
+clCreateProgramWithSource(cl_context context,
+ cl_uint count,
+ const char ** strings,
+ const size_t * lengths,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_program
+clCreateProgramWithBinary(cl_context context,
+ cl_uint num_devices,
+ const cl_device_id * device_list,
+ const size_t * lengths,
+ const void ** binaries,
+ cl_int * binary_status,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_int
+clRetainProgram(cl_program program)
+{
+ return 0;
+}
+
+cl_int
+clReleaseProgram(cl_program program)
+{
+ return 0;
+}
+
+cl_int
+clBuildProgram(cl_program program,
+ cl_uint num_devices,
+ const cl_device_id * device_list,
+ const char * options,
+ void (*pfn_notify)(cl_program program, void * user_data),
+ void * user_data)
+{
+ return 0;
+}
+
+cl_int
+clUnloadCompiler(void)
+{
+ return 0;
+}
+
+cl_int
+clGetProgramInfo(cl_program program,
+ cl_program_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
+
+cl_int
+clGetProgramBuildInfo(cl_program program,
+ cl_device_id device,
+ cl_program_build_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
diff --git a/src/core/api_sampler.cpp b/src/core/api_sampler.cpp
new file mode 100644
index 0000000..8c4d74a
--- /dev/null
+++ b/src/core/api_sampler.cpp
@@ -0,0 +1,34 @@
+#include <OpenCL/cl.h>
+
+// Sampler APIs
+cl_sampler
+clCreateSampler(cl_context context,
+ cl_bool normalized_coords,
+ cl_addressing_mode addressing_mode,
+ cl_filter_mode filter_mode,
+ cl_int * errcode_ret)
+{
+ return 0;
+}
+
+cl_int
+clRetainSampler(cl_sampler sampler)
+{
+ return 0;
+}
+
+cl_int
+clReleaseSampler(cl_sampler sampler)
+{
+ return 0;
+}
+
+cl_int
+clGetSamplerInfo(cl_sampler sampler,
+ cl_sampler_info param_name,
+ size_t param_value_size,
+ void * param_value,
+ size_t * param_value_size_ret)
+{
+ return 0;
+}
diff --git a/src/core/context.h b/src/core/context.h
new file mode 100644
index 0000000..f74bcdb
--- /dev/null
+++ b/src/core/context.h
@@ -0,0 +1,16 @@
+#ifndef CONTEXT_H
+#define CONTEXT_H
+
+#include "OpenCL/cl.h"
+
+#include "pipe/p_context.h"
+
+struct _cl_context {
+ struct pipe_context *pipe;
+ cl_uint id;
+};
+
+void cl_set_current_context(struct _cl_context *ctx);
+struct _cl_context *cl_current_context(void);
+
+#endif
diff --git a/src/core/device.cpp b/src/core/device.cpp
new file mode 100644
index 0000000..e7306ba
--- /dev/null
+++ b/src/core/device.cpp
@@ -0,0 +1,228 @@
+#include "device.h"
+
+#include "OpenCL/cl.h"
+#include "OpenCL/cl_platform.h"
+
+#include "pipe/p_screen.h"
+#include "pipe/p_format.h"
+#include "util/u_memory.h"
+
+#include "cpuwinsys/cpuwinsys.h"
+#include "softpipe/sp_winsys.h"
+
+
+Device * Device::create(cl_uint type)
+{
+ switch(type) {
+ case CL_DEVICE_TYPE_CPU: {
+ struct pipe_winsys *ws = cpu_winsys();
+ struct pipe_screen *screen =
+ softpipe_create_screen(ws);
+ return new Device(CL_DEVICE_TYPE_CPU, screen);
+ }
+ break;
+ case CL_DEVICE_TYPE_GPU:
+ break;
+ case CL_DEVICE_TYPE_ACCELERATOR:
+#ifdef GALLIUM_CELL
+ if (!getenv("GALLIUM_NOCELL")) {
+ struct cell_winsys *cws = cell_get_winsys(pixelformat);
+ struct pipe_screen *screen = cell_create_screen(pws);
+
+ pipe = cell_create_context(screen, cws);
+ }
+#endif
+ break;
+ }
+ return 0;
+}
+
+static void stringToParam(const std::string &str,
+ void * paramValue,
+ size_t * paramValueSizeRet)
+{
+ strcpy((char*)paramValue, str.c_str());
+ if (paramValueSizeRet)
+ *paramValueSizeRet = str.size();
+}
+
+cl_int Device::info(cl_device_info opcode,
+ size_t paramValueSize,
+ void * paramValue,
+ size_t * paramValueSizeRet) const
+{
+ switch (opcode) {
+ case CL_DEVICE_TYPE:
+ ((cl_int*)paramValue)[0] = type();
+ break;
+ case CL_DEVICE_VENDOR_ID:
+ break;
+ case CL_DEVICE_MAX_COMPUTE_UNITS:
+ break;
+ case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:
+ break;
+ case CL_DEVICE_MAX_WORK_GROUP_SIZE:
+ break;
+ case CL_DEVICE_MAX_WORK_ITEM_SIZES:
+ break;
+ case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR:
+ break;
+ case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT:
+ break;
+ case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT:
+ break;
+ case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG:
+ break;
+ case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT:
+ break;
+ case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE:
+ break;
+ case CL_DEVICE_MAX_CLOCK_FREQUENCY:
+ break;
+ case CL_DEVICE_ADDRESS_BITS:
+ break;
+ case CL_DEVICE_MAX_READ_IMAGE_ARGS:
+ break;
+ case CL_DEVICE_MAX_WRITE_IMAGE_ARGS:
+ break;
+ case CL_DEVICE_MAX_MEM_ALLOC_SIZE:
+ break;
+ case CL_DEVICE_IMAGE2D_MAX_WIDTH:
+ break;
+ case CL_DEVICE_IMAGE2D_MAX_HEIGHT:
+ break;
+ case CL_DEVICE_IMAGE3D_MAX_WIDTH:
+ break;
+ case CL_DEVICE_IMAGE3D_MAX_HEIGHT:
+ break;
+ case CL_DEVICE_IMAGE3D_MAX_DEPTH:
+ break;
+ case CL_DEVICE_IMAGE_SUPPORT:
+ break;
+ case CL_DEVICE_MAX_PARAMETER_SIZE:
+ break;
+ case CL_DEVICE_MAX_SAMPLERS:
+ break;
+ case CL_DEVICE_MEM_BASE_ADDR_ALIGN:
+ break;
+ case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE:
+ break;
+ case CL_DEVICE_SINGLE_FP_CONFIG:
+ break;
+ case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE:
+ break;
+ case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE:
+ break;
+ case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE:
+ break;
+ case CL_DEVICE_GLOBAL_MEM_SIZE:
+ break;
+ case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE:
+ break;
+ case CL_DEVICE_MAX_CONSTANT_ARGS:
+ break;
+ case CL_DEVICE_LOCAL_MEM_TYPE:
+ break;
+ case CL_DEVICE_LOCAL_MEM_SIZE:
+ break;
+ case CL_DEVICE_ERROR_CORRECTION_SUPPORT:
+ break;
+ case CL_DEVICE_PROFILING_TIMER_RESOLUTION:
+ break;
+ case CL_DEVICE_ENDIAN_LITTLE:
+ break;
+ case CL_DEVICE_AVAILABLE:
+ break;
+ case CL_DEVICE_COMPILER_AVAILABLE:
+ break;
+ case CL_DEVICE_EXECUTION_CAPABILITIES:
+ break;
+ case CL_DEVICE_QUEUE_PROPERTIES:
+ break;
+ case CL_DEVICE_NAME:
+ stringToParam(m_info.name, paramValue, paramValueSizeRet);
+ break;
+ case CL_DEVICE_VENDOR:
+ stringToParam(m_info.name, paramValue, paramValueSizeRet);
+ break;
+ case CL_DRIVER_VERSION:
+ break;
+ case CL_DEVICE_PROFILE:
+ break;
+ case CL_DEVICE_VERSION:
+ break;
+ case CL_DEVICE_EXTENSIONS:
+ break;
+
+ default:
+ return CL_INVALID_VALUE;
+ break;
+ }
+
+ return CL_SUCCESS;
+}
+
+Device::Device(cl_uint type, struct pipe_screen *screen)
+ : m_screen(screen)
+{
+ fillInfo(type);
+}
+
+void Device::fillInfo(cl_uint type)
+{
+ m_info.type = type;
+ m_info.vendorId = 0;//should be a PCIe ID
+ m_info.maxComputeUnits = 1;//min
+ m_info.maxWorkItemDimensions = 3;//min
+#if 0
+ m_info.maxWorkGroupSize = ;
+ m_info.maxWorkItemSizes = ;
+ m_info.preferredVectorWidthChar = ;
+ m_info.preferredVectorWidthShort = ;
+ m_info.preferredVectorWidthInt = ;
+ m_info.preferredVectorWidthLong = ;
+ m_info.preferredVectorWidthFloat = ;
+ m_info.preferredVectorWidthDouble = ;
+
+ m_info.maxClockFrequency = ;
+ m_info.addressBits = ;
+ m_info.maxReadImageArgs = ;
+ m_info.maxWriteImageArgs = ;
+ m_info.maxMemAllocSize = ;
+
+ m_info.image2dMaxWidth = ;
+ m_info.image2dMaxHeight = ;
+ m_info.image3dMaxWidth = ;
+ m_info.image3dMaxHeight = ;
+ m_info.image3dMaxDepth = ;
+ m_info.imageSupport = ;
+
+ m_info.maxParameterSize = ;
+ m_info.maxSamplers = ;
+ m_info.memBaseAddrAlign = ;
+ m_info.minDataTypeAlignSize = ;
+ m_info.singleFpConfig = ;
+ m_info.globalMemCacheType = ;
+ m_info.globalMemCachelineSize = ;
+ m_info.globalMemCacheSize = ;
+ m_info.globalMemSize = ;
+ m_info.maxConstantBufferSize = ;
+ m_info.maxConstantArgs = ;
+ m_info.localMemType = ;
+ m_info.localMemSize = ;
+ m_info.errorCorrectionSupport = ;
+ m_info.profilingTimerResolution = ;
+ m_info.entianLittle = ;
+ m_info.available = ;
+ m_info.compilerAvailable = ;
+ m_info.executionCapabilities = ;
+ m_info.queueProperties = ;
+
+#endif
+ m_info.name = m_screen->get_name(m_screen);
+ m_info.vendor = m_screen->get_vendor(m_screen);
+ //m_info.driverVersion = ;
+ m_info.profile = "FULL_PROFILE";
+ //m_info.version = ;
+ //m_info.extensions = ;
+}
diff --git a/src/core/device.h b/src/core/device.h
new file mode 100644
index 0000000..5a3d43f
--- /dev/null
+++ b/src/core/device.h
@@ -0,0 +1,47 @@
+#ifndef DEVICE_H
+#define DEVICE_H
+
+#include "deviceinfo.h"
+
+#include "OpenCL/cl.h"
+
+struct pipe_screen;
+
+
+class Device
+{
+public:
+ static Device *create(cl_uint type);
+public:
+ inline cl_uint type() const;
+ inline struct pipe_screen *screen() const;
+
+ cl_int info(cl_device_info opcode,
+ size_t paramValueSize,
+ void * paramValue,
+ size_t * paramValueSizeRet) const;
+
+private:
+ Device(cl_uint type, struct pipe_screen *screen);
+ void fillInfo(cl_uint type);
+
+private:
+ DeviceInfo m_info;
+
+ struct pipe_screen *m_screen;
+};
+
+inline cl_uint Device::type() const
+{
+ return m_info.type;
+}
+
+inline struct pipe_screen *Device::screen() const
+{
+ return m_screen;
+}
+
+struct _cl_device_id : public Device
+{};
+
+#endif
diff --git a/src/core/deviceinfo.h b/src/core/deviceinfo.h
new file mode 100644
index 0000000..afbad19
--- /dev/null
+++ b/src/core/deviceinfo.h
@@ -0,0 +1,67 @@
+#ifndef DEVICEINFO_H
+#define DEVICEINFO_H
+
+#include "OpenCL/cl.h"
+
+#include <vector>
+#include <string>
+
+struct DeviceInfo
+{
+ cl_uint type; //CL_DEVICE_TYPE
+
+ cl_uint vendorId; //CL_DEVICE_VENDOR_ID
+ cl_uint maxComputeUnits; //CL_DEVICE_MAX_COMPUTE_UNITS
+ cl_uint maxWorkItemDimensions; //CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
+ std::vector<size_t> maxWorkItemSizes; //CL_DEVICE_MAX_WORK_ITEM_SIZES
+ size_t maxWorkGroupSize; //CL_DEVICE_MAX_WORK_GROUP_SIZE
+ cl_uint preferredVectorWidthChar; //CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
+ cl_uint preferredVectorWidthShort; //CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
+ cl_uint preferredVectorWidthInt; //CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
+ cl_uint preferredVectorWidthLong; //CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
+ cl_uint preferredVectorWidthFloat; //CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
+ cl_uint preferredVectorWidthDouble; //CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
+
+ cl_uint maxClockFrequency; //CL_DEVICE_MAX_CLOCK_FREQUENCY
+ cl_bitfield addressBits; //CL_DEVICE_ADDRESS_BITS
+ cl_uint maxReadImageArgs; //CL_DEVICE_MAX_READ_IMAGE_ARGS
+ cl_uint maxWriteImageArgs; //CL_DEVICE_MAX_WRITE_IMAGE_ARGS
+ cl_ulong maxMemAllocSize; //CL_DEVICE_MAX_MEM_ALLOC_SIZE
+
+ size_t image2dMaxWidth; //CL_DEVICE_IMAGE2D_MAX_WIDTH
+ size_t image2dMaxHeight; //CL_DEVICE_IMAGE2D_MAX_HEIGHT
+ size_t image3dMaxWidth; //CL_DEVICE_IMAGE3D_MAX_WIDTH
+ size_t image3dMaxHeight; //CL_DEVICE_IMAGE3D_MAX_HEIGHT
+ size_t image3dMaxDepth; //CL_DEVICE_IMAGE3D_MAX_DEPTH
+ cl_bool imageSupport; //CL_DEVICE_IMAGE_SUPPORT
+
+ size_t maxParameterSize; //CL_DEVICE_MAX_PARAMETER_SIZE
+ cl_uint maxSamplers; //CL_DEVICE_MAX_SAMPLERS
+ cl_uint memBaseAddrAlign; //CL_DEVICE_MEM_BASE_ADDR_ALIGN
+ cl_uint minDataTypeAlignSize; //CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
+ cl_device_fp_config singleFpConfig; //CL_DEVICE_SINGLE_FP_CONFIG
+ cl_device_mem_cache_type globalMemCacheType; //CL_DEVICE_GLOBAL_MEM_CACHE_TYPE
+ cl_uint globalMemCachelineSize; //CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
+ cl_ulong globalMemCacheSize; //CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
+ cl_ulong globalMemSize; //CL_DEVICE_GLOBAL_MEM_SIZE
+ cl_ulong maxConstantBufferSize; //CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
+ cl_uint maxConstantArgs; //CL_DEVICE_MAX_CONSTANT_ARGS
+ cl_device_local_mem_type localMemType; //CL_DEVICE_LOCAL_MEM_TYPE
+ cl_ulong localMemSize; //CL_DEVICE_LOCAL_MEM_SIZE
+ cl_bool errorCorrectionSupport; //CL_DEVICE_ERROR_CORRECTION_SUPPORT
+ size_t profilingTimerResolution; //CL_DEVICE_PROFILING_TIMER_RESOLUTION
+ cl_bool entianLittle; //CL_DEVICE_ENDIAN_LITTLE
+ cl_bool available; //CL_DEVICE_AVAILABLE
+ cl_bool compilerAvailable; //CL_DEVICE_COMPILER_AVAILABLE
+ cl_device_exec_capabilities executionCapabilities; //CL_DEVICE_EXECUTION_CAPABILITIES
+ cl_command_queue_properties queueProperties; //CL_DEVICE_QUEUE_PROPERTIES
+
+ std::string name; //CL_DEVICE_NAME
+ std::string vendor; //CL_DEVICE_VENDOR
+ std::string driverVersion; //CL_DRIVER_VERSION
+ std::string profile; //CL_DEVICE_PROFILE
+ std::string version; //CL_DEVICE_VERSION
+ std::string extensions; //CL_DEVICE_EXTENSIONS
+};
+
+#endif