Added c++ header from khronos, and my own wrapper
This commit is contained in:
commit
ee27ef82cf
4 changed files with 12548 additions and 0 deletions
17
CMakeLists.txt
Normal file
17
CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(LIBNAME JCLWrapper)
|
||||
|
||||
file(GLOB sources "*.cpp")
|
||||
file(GLOB headers "*.hpp")
|
||||
|
||||
add_library(${LIBNAME} ${headers} ${sources})
|
||||
|
||||
find_library(OPENCL_LIBRARY OpenCL)
|
||||
|
||||
set(libs ${OPENCL_LIBRARY})
|
||||
|
||||
target_link_libraries(${LIBNAME} ${libs})
|
||||
|
||||
install(TARGETS ${LIBNAME} DESTINATION lib)
|
||||
install(FILES ${headers} DESTINATION include/J)
|
76
cl2.hpp
Normal file
76
cl2.hpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
//
|
||||
// cl2.hpp
|
||||
// XcodeOpenCL
|
||||
//
|
||||
// Created by Joshua Moerman on 28/03/14.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef XcodeOpenCL_cl2_hpp
|
||||
#define XcodeOpenCL_cl2_hpp
|
||||
|
||||
#include "cl.hpp"
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
// debugging tool
|
||||
static void check(cl_int err){
|
||||
assert(err == CL_SUCCESS);
|
||||
}
|
||||
|
||||
// simple variadic wrapper for kernels/arguments (1D)
|
||||
struct KernelOp{
|
||||
KernelOp(const cl::Program& program, const char* name, cl_int* err)
|
||||
: kernel(program, name, err)
|
||||
{}
|
||||
|
||||
template <typename... Args>
|
||||
cl_int operator()(cl::CommandQueue & queue, size_t W, size_t H, Args&&... args){
|
||||
return apply(queue, W, H, 0, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
cl::Kernel kernel;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
cl_int apply(cl::CommandQueue & queue, size_t W, size_t H, cl_uint n, T&& t, Args&&... args){
|
||||
check(kernel.setArg(n, t));
|
||||
return apply(queue, W, H, n+1, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
cl_int apply(cl::CommandQueue & queue, size_t W, size_t H, size_t){
|
||||
return queue.enqueueNDRangeKernel(kernel, cl::NullRange, cl::NDRange(W, H), cl::NullRange);
|
||||
}
|
||||
};
|
||||
|
||||
// We need to put the op<<'s in namespace cl (ADL)
|
||||
namespace cl {
|
||||
std::ostream& operator<<(std::ostream& out, Platform const & platform){
|
||||
return out << platform.getInfo<CL_PLATFORM_NAME>() << ", " << platform.getInfo<CL_PLATFORM_VERSION>();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Device const & device){
|
||||
out << device.getInfo<CL_DEVICE_NAME>() << ", " << device.getInfo<CL_DEVICE_VERSION>() << ", " << device.getInfo<CL_DRIVER_VERSION>();
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Context const & context){
|
||||
Platform p;
|
||||
context.getInfo(CL_CONTEXT_PLATFORM, &p);
|
||||
out << "Platform:\t" << p << '\n';
|
||||
|
||||
auto devices = context.getInfo<CL_CONTEXT_DEVICES>();
|
||||
out << "Number of devices:\t" << devices.size() << '\n';
|
||||
int i = 0;
|
||||
for(auto&& d : devices){
|
||||
out << ++i << "\t" << d << '\n';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Program const & program){
|
||||
return out << "Kernels in program:\t" << program.getInfo<CL_PROGRAM_KERNEL_NAMES>();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
3
dummy.cpp
Normal file
3
dummy.cpp
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
static int x = x;
|
||||
|
Reference in a new issue