From f5d5731500828dd6512fd4cb48499595cfa3594f Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Tue, 15 Nov 2016 18:17:38 +0100 Subject: [PATCH] (committing very old stuff) Something with input/output --- CMakeLists.txt | 2 + cl.hpp | 6 +-- cl2.hpp | 105 ++++++++++++++++++++++++++----------------------- 3 files changed, 61 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87206d3..6c0a8c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,10 @@ add_library(${LIBNAME} ${headers} ${sources}) find_library(OPENCL_LIBRARY OpenCL) set(libs ${OPENCL_LIBRARY}) +set(${LIBNAME}_LIBRARIES ${LIBNAME} ${libs} CACHE INTERNAL "") target_link_libraries(${LIBNAME} ${libs}) +target_include_directories(${LIBNAME} PUBLIC ".") install(TARGETS ${LIBNAME} DESTINATION lib) install(FILES ${headers} DESTINATION include/J) diff --git a/cl.hpp b/cl.hpp index 3d02cf6..737bec9 100644 --- a/cl.hpp +++ b/cl.hpp @@ -4442,7 +4442,7 @@ typedef T param_type; \ struct KernelArgumentHandler { static ::size_t size(const T&) { return sizeof(T); } - static T* ptr(T& value) { return &value; } + static typename std::remove_reference_t* ptr(T& value) { return &value; } }; template <> @@ -4607,7 +4607,7 @@ typedef T param_type; \ } template - cl_int setArg(cl_uint index, T value) + cl_int setArg(cl_uint index, T&& value) { return detail::errHandler( ::clSetKernelArg( @@ -12449,4 +12449,4 @@ typedef T param_type; \ #pragma pop_macro("max") #endif // _WIN32 -#endif // CL_HPP_ \ No newline at end of file +#endif // CL_HPP_ diff --git a/cl2.hpp b/cl2.hpp index ad70640..5710060 100644 --- a/cl2.hpp +++ b/cl2.hpp @@ -13,64 +13,71 @@ #include #include -// debugging tool -static void check(cl_int err){ - assert(err == CL_SUCCESS); +namespace cl { + // debugging tool + inline void checky(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 - cl_int operator()(cl::CommandQueue & queue, size_t W, size_t H, Args&&... args){ - return apply(queue, W, H, 0, std::forward(args)...); - } - + KernelOp(const cl::Program& program, const char* name, cl_int* err = nullptr) + : kernel(program, name, err) + {} + + template + cl_int operator()(cl::CommandQueue & queue, size_t W, Args&&... args){ + return apply(queue, W, 0, std::forward(args)...); + } + private: - cl::Kernel kernel; - - template - 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)...); - } - - 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); - } + cl::Kernel kernel; + + template + cl_int apply(cl::CommandQueue & queue, size_t W, cl_uint n, T&& t, Args&&... args){ + cl::checky(kernel.setArg(n, t)); + return apply(queue, W, n+1, std::forward(args)...); + } + + cl_int apply(cl::CommandQueue & queue, size_t W, size_t){ + return queue.enqueueNDRangeKernel(kernel, cl::NullRange, cl::NDRange(W)); + } }; // 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() << ", " << platform.getInfo(); - } - - std::ostream& operator<<(std::ostream& out, Device const & device){ - out << device.getInfo() << ", " << device.getInfo() << ", " << device.getInfo(); - 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(); - 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(); - } + inline std::ostream& operator<<(std::ostream& out, Platform const & platform){ + return out << platform.getInfo() << ", " << platform.getInfo(); + } + + inline std::ostream& operator<<(std::ostream& out, Device const & device){ + out << device.getInfo() << ", " << device.getInfo() << ", " << device.getInfo(); + return out; + } + + inline 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(); + out << "Number of devices:\t" << devices.size() << '\n'; + int i = 0; + for(auto&& d : devices){ + out << ++i << "\t" << d << '\n'; + } + return out; + } + + inline std::ostream& operator<<(std::ostream& out, Program const & program){ + return out << "Kernels in program:\t" << program.getInfo(); + } + + inline std::ostream& operator<<(std::ostream& out, Image const & image){ + out << "Image: " << image.getImageInfo() << "x" << image.getImageInfo(); + return out << " elements: " << image.getImageInfo() << " pitch: " << image.getImageInfo(); + } } #endif