diff --git a/pyopencl/c_wrapper/wrap_cl_core.h b/pyopencl/c_wrapper/wrap_cl_core.h index 08dc767881578d3214a413a3994c90d78ed0c20c..051f6b048e154f86b6622a2feaf9237676d3369d 100644 --- a/pyopencl/c_wrapper/wrap_cl_core.h +++ b/pyopencl/c_wrapper/wrap_cl_core.h @@ -1,6 +1,12 @@ // Interface between C and Python // Types +typedef enum { + TYPE_FLOAT, + TYPE_INT, + TYPE_UINT, +} type_t; + typedef enum { KND_UNKNOWN, KND_SOURCE, @@ -107,8 +113,9 @@ error *create_image_3d(clobj_t *image, clobj_t context, cl_mem_flags flags, cl_image_format *fmt, size_t width, size_t height, size_t depth, size_t pitch_x, size_t pitch_y, void *buffer); -error *image__get_image_info(clobj_t image, cl_image_info param, +error *image__get_image_info(clobj_t img, cl_image_info param, generic_info *out); +type_t image__get_fill_type(clobj_t img); // Event error *event__get_profiling_info(clobj_t event, cl_profiling_info param, generic_info *out); diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index 9eb05acdae3063d227a30526b73444af9172d351..bbd064b335ce1376d42cb1cd4550bf8508afb0a1 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -1209,7 +1209,7 @@ class Image(MemoryObject): return (self.width, self.height, self.depth) else: raise LogicError("Image", status_code.INVALID_VALUE, - "only images have shapes") + "only images have shapes") # TODO # create_image_from_desc diff --git a/src/c_wrapper/wrap_cl.cpp b/src/c_wrapper/wrap_cl.cpp index db3f1e73f01f35062b84ff8fdc358988cbe691a0..d95adfdc7ecb4aab09072d8c9d4bbb1abc39a8f0 100644 --- a/src/c_wrapper/wrap_cl.cpp +++ b/src/c_wrapper/wrap_cl.cpp @@ -1015,11 +1015,21 @@ public: // {{{ image class image : public memory_object { +private: + cl_image_format m_format; public: PYOPENCL_DEF_GET_CLASS_T(IMAGE); - image(cl_mem mem, bool retain, void *hostbuf=0) + image(cl_mem mem, bool retain, void *hostbuf=0, + const cl_image_format *fmt=0) : memory_object(mem, retain, hostbuf) - {} + { + if (fmt) { + memcpy(&m_format, fmt, sizeof(m_format)); + } else { + pyopencl_call_guarded(clGetImageInfo, data(), CL_IMAGE_FORMAT, + sizeof(m_format), &m_format, NULL); + } + } generic_info get_image_info(cl_image_info param_name) const { @@ -1062,11 +1072,27 @@ public: throw clerror("Image.get_image_info", CL_INVALID_VALUE); } } + inline type_t + get_fill_type() + { + switch (m_format.image_channel_data_type) { + case CL_SIGNED_INT8: + case CL_SIGNED_INT16: + case CL_SIGNED_INT32: + return TYPE_INT; + case CL_UNSIGNED_INT8: + case CL_UNSIGNED_INT16: + case CL_UNSIGNED_INT32: + return TYPE_UINT; + default: + return TYPE_FLOAT; + } + } }; static inline image* -new_image(cl_mem mem, void *buff=0) +new_image(cl_mem mem, void *buff, const cl_image_format *fmt) { - return pyopencl_convert_obj(image, clReleaseMemObject, mem, buff); + return pyopencl_convert_obj(image, clReleaseMemObject, mem, buff, fmt); } // {{{ image creation @@ -1185,40 +1211,6 @@ new_image(cl_mem mem, void *buff=0) // // }}} - // #if PYOPENCL_CL_VERSION >= 0x1020 - // inline - // event *enqueue_fill_image( - // command_queue &cq, - // memory_object_holder &mem, - // py::object color, - // py::object py_origin, py::object py_region, - // py::object py_wait_for - // ) - // { - // PYOPENCL_PARSE_WAIT_FOR; - - // COPY_PY_COORD_TRIPLE(origin); - // COPY_PY_REGION_TRIPLE(region); - - // const void *color_buf; - // PYOPENCL_BUFFER_SIZE_T color_len; - - // if (PyObject_AsReadBuffer(color.ptr(), &color_buf, &color_len)) - // throw py::error_already_set(); - - // cl_event evt; - // PYOPENCL_RETRY_IF_MEM_ERROR( - // PYOPENCL_CALL_GUARDED(clEnqueueFillImage, ( - // cq.data(), - // mem.data(), - // color_buf, origin, region, - // PYOPENCL_WAITLIST_ARGS, &evt - // )); - // ); - // PYOPENCL_RETURN_NEW_EVENT(evt); - // } - // #endif - // }}} // {{{ gl interop @@ -2187,7 +2179,7 @@ create_image_2d(clobj_t *img, clobj_t _ctx, cl_mem_flags flags, fmt, width, height, pitch, buffer); }); *img = new_image(mem, (flags & CL_MEM_USE_HOST_PTR ? - buffer : NULL)); + buffer : NULL), fmt); }); } @@ -2204,7 +2196,7 @@ create_image_3d(clobj_t *img, clobj_t _ctx, cl_mem_flags flags, height, depth, pitch_x, pitch_y, buffer); }); *img = new_image(mem, (flags & CL_MEM_USE_HOST_PTR ? - buffer : NULL)); + buffer : NULL), fmt); }); } @@ -2216,6 +2208,12 @@ image__get_image_info(clobj_t img, cl_image_info param, generic_info *out) }); } +type_t +image__get_fill_type(clobj_t img) +{ + return static_cast<image*>(img)->get_fill_type(); +} + // Event error* @@ -2613,6 +2611,40 @@ enqueue_map_image(clobj_t *_evt, clobj_t *map, clobj_t _queue, clobj_t _mem, }); } +#if PYOPENCL_CL_VERSION >= 0x1020 + // inline + // event *enqueue_fill_image( + // command_queue &cq, + // memory_object_holder &mem, + // py::object color, + // py::object py_origin, py::object py_region, + // py::object py_wait_for + // ) + // { + // PYOPENCL_PARSE_WAIT_FOR; + + // COPY_PY_COORD_TRIPLE(origin); + // COPY_PY_REGION_TRIPLE(region); + + // const void *color_buf; + // PYOPENCL_BUFFER_SIZE_T color_len; + + // if (PyObject_AsReadBuffer(color.ptr(), &color_buf, &color_len)) + // throw py::error_already_set(); + + // cl_event evt; + // PYOPENCL_RETRY_IF_MEM_ERROR( + // PYOPENCL_CALL_GUARDED(clEnqueueFillImage, ( + // cq.data(), + // mem.data(), + // color_buf, origin, region, + // PYOPENCL_WAITLIST_ARGS, &evt + // )); + // ); + // PYOPENCL_RETURN_NEW_EVENT(evt); + // } +#endif + // }}} intptr_t