diff options
author | Michael Bien <[email protected]> | 2010-02-19 01:27:23 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-02-19 01:27:23 +0100 |
commit | a49b22397ae525e9b659a112aa11e4647c18c214 (patch) | |
tree | cc13baf0bae35131f7f13d1a9c71d3eab8ffe0fe /resources | |
parent | 9542b173b10d2bb0eb492230025bdede638631b0 (diff) |
enabled putMapImage methods in CLCommandQueue.
added slightly modified mapImage implementation via custom code for mapped image buffer size calculation in the glue layer.
Diffstat (limited to 'resources')
-rw-r--r-- | resources/cl-impl.cfg | 3 | ||||
-rw-r--r-- | resources/clImplCustomCode.c | 63 | ||||
-rw-r--r-- | resources/clImplCustomCode.java | 54 |
3 files changed, 119 insertions, 1 deletions
diff --git a/resources/cl-impl.cfg b/resources/cl-impl.cfg index e1a942b9..0b2a4b74 100644 --- a/resources/cl-impl.cfg +++ b/resources/cl-impl.cfg @@ -40,7 +40,8 @@ Ignore clEnqueueNativeKernel #take buffer capacity from input param 5 ReturnValueCapacity clEnqueueMapBuffer {5} -#TODO ReturnValueCapacity clEnqueueMapImage ? +#this one is more complicated, we have to calculate the capacity with custom code +ManuallyImplement clEnqueueMapImage #include custom code IncludeAs CustomJavaCode CLImpl clImplCustomCode.java diff --git a/resources/clImplCustomCode.c b/resources/clImplCustomCode.c index 6829e8b6..05a29552 100644 --- a/resources/clImplCustomCode.c +++ b/resources/clImplCustomCode.c @@ -122,3 +122,66 @@ Java_com_mbien_opencl_impl_CLImpl_clBuildProgram0(JNIEnv *env, jobject _unused, return (jint)_res; } + +/* Java->C glue code: + * Java package: com.mbien.opencl.impl.CLImpl + * Java method: java.nio.ByteBuffer clEnqueueMapImage(long command_queue, long image, int blocking_map, long map_flags, com.sun.gluegen.runtime.PointerBuffer origin, com.sun.gluegen.runtime.PointerBuffer range, com.sun.gluegen.runtime.PointerBuffer image_row_pitch, com.sun.gluegen.runtime.PointerBuffer image_slice_pitch, int num_events_in_wait_list, com.sun.gluegen.runtime.PointerBuffer event_wait_list, com.sun.gluegen.runtime.PointerBuffer event, java.nio.IntBuffer errcode_ret) + * C function: void * clEnqueueMapImage(cl_command_queue command_queue, cl_mem image, uint32_t blocking_map, uint64_t map_flags, const size_t * , const size_t * , size_t * image_row_pitch, size_t * image_slice_pitch, uint32_t num_events_in_wait_list, cl_event * event_wait_list, cl_event * event, int32_t * errcode_ret); + */ +JNIEXPORT jobject JNICALL +Java_com_mbien_opencl_impl_CLImpl_clEnqueueMapImage0__JJIJLjava_lang_Object_2ILjava_lang_Object_2ILjava_lang_Object_2ILjava_lang_Object_2IILjava_lang_Object_2ILjava_lang_Object_2ILjava_lang_Object_2I(JNIEnv *env, jobject _unused, jlong command_queue, jlong image, jint blocking_map, jlong map_flags, jobject origin, jint origin_byte_offset, jobject range, jint range_byte_offset, jobject image_row_pitch, jint image_row_pitch_byte_offset, jobject image_slice_pitch, jint image_slice_pitch_byte_offset, jint num_events_in_wait_list, jobject event_wait_list, jint event_wait_list_byte_offset, jobject event, jint event_byte_offset, jobject errcode_ret, jint errcode_ret_byte_offset) { + + size_t * _origin_ptr = NULL; + size_t * _range_ptr = NULL; + size_t * _image_row_pitch_ptr = NULL; + size_t * _image_slice_pitch_ptr = NULL; + cl_event * _event_wait_list_ptr = NULL; + cl_event * _event_ptr = NULL; + int32_t * _errcode_ret_ptr = NULL; + size_t * elements = NULL; + size_t * depth = NULL; + size_t pixels; + cl_int status; + + void * _res; + + if (origin != NULL) { + _origin_ptr = (size_t *) (((char*) (*env)->GetDirectBufferAddress(env, origin)) + origin_byte_offset); + } + if (range != NULL) { + _range_ptr = (size_t *) (((char*) (*env)->GetDirectBufferAddress(env, range)) + range_byte_offset); + } + if (image_row_pitch != NULL) { + _image_row_pitch_ptr = (size_t *) (((char*) (*env)->GetDirectBufferAddress(env, image_row_pitch)) + image_row_pitch_byte_offset); + } + if (image_slice_pitch != NULL) { + _image_slice_pitch_ptr = (size_t *) (((char*) (*env)->GetDirectBufferAddress(env, image_slice_pitch)) + image_slice_pitch_byte_offset); + } + if (event_wait_list != NULL) { + _event_wait_list_ptr = (cl_event *) (((char*) (*env)->GetDirectBufferAddress(env, event_wait_list)) + event_wait_list_byte_offset); + } + if (event != NULL) { + _event_ptr = (cl_event *) (((char*) (*env)->GetDirectBufferAddress(env, event)) + event_byte_offset); + } + if (errcode_ret != NULL) { + _errcode_ret_ptr = (int32_t *) (((char*) (*env)->GetDirectBufferAddress(env, errcode_ret)) + errcode_ret_byte_offset); + } + + _res = clEnqueueMapImage((cl_command_queue) (intptr_t) command_queue, (cl_mem) (intptr_t) image, (uint32_t) blocking_map, (uint64_t) map_flags, (size_t *) _origin_ptr, (size_t *) _range_ptr, (size_t *) _image_row_pitch_ptr, (size_t *) _image_slice_pitch_ptr, (uint32_t) num_events_in_wait_list, (cl_event *) _event_wait_list_ptr, (cl_event *) _event_ptr, (int32_t *) _errcode_ret_ptr); + if (_res == NULL) return NULL; + + // calculate buffer size + status = clGetImageInfo((cl_mem) (intptr_t) image, CL_IMAGE_ELEMENT_SIZE, sizeof(size_t), (void *) elements, NULL); + status |= clGetImageInfo((cl_mem) (intptr_t) image, CL_IMAGE_DEPTH, sizeof(size_t), (void *) depth, NULL); + + if(status != CL_SUCCESS) return NULL; + + if(*depth == 0) { // 2D + pixels = (*_image_row_pitch_ptr) * _range_ptr[1] + _range_ptr[0]; + }else{ // 3D + pixels = (*_image_slice_pitch_ptr) * _range_ptr[2] + + (*_image_row_pitch_ptr) * _range_ptr[1] + _range_ptr[0]; + } + + return (*env)->NewDirectByteBuffer(env, _res, pixels * (*elements)); +} diff --git a/resources/clImplCustomCode.java b/resources/clImplCustomCode.java index e981fbcc..86366a10 100644 --- a/resources/clImplCustomCode.java +++ b/resources/clImplCustomCode.java @@ -64,6 +64,60 @@ private native int clBuildProgram0(long program, int deviceCount, Object deviceList, int deviceListOffset, String options, BuildProgramCallback cb, Object userData); + /** Interface to C language function: <br> <code> void * {@native clEnqueueMapImage}(cl_command_queue command_queue, cl_mem image, uint32_t blocking_map, uint64_t map_flags, const size_t * , const size_t * , size_t * image_row_pitch, size_t * image_slice_pitch, uint32_t num_events_in_wait_list, cl_event * event_wait_list, cl_event * event, int32_t * errcode_ret); </code> + @param origin a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param range a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param image_row_pitch a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param image_slice_pitch a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param event_wait_list a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param event a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param errcode_ret a direct {@link java.nio.IntBuffer} */ + public java.nio.ByteBuffer clEnqueueMapImage(long command_queue, long image, int blocking_map, long map_flags, + com.sun.gluegen.runtime.PointerBuffer origin, com.sun.gluegen.runtime.PointerBuffer range, + com.sun.gluegen.runtime.PointerBuffer image_row_pitch, com.sun.gluegen.runtime.PointerBuffer image_slice_pitch, + int num_events_in_wait_list, + com.sun.gluegen.runtime.PointerBuffer event_wait_list, com.sun.gluegen.runtime.PointerBuffer event, java.nio.IntBuffer errcode_ret) { + + if (!BufferFactory.isDirect(origin)) + throw new CLException("Argument \"origin\" was not a direct buffer"); + if (!BufferFactory.isDirect(range)) + throw new CLException("Argument \"range\" was not a direct buffer"); + if (!BufferFactory.isDirect(image_row_pitch)) + throw new CLException("Argument \"image_row_pitch\" was not a direct buffer"); + if (!BufferFactory.isDirect(image_slice_pitch)) + throw new CLException("Argument \"image_slice_pitch\" was not a direct buffer"); + if (!BufferFactory.isDirect(event_wait_list)) + throw new CLException("Argument \"event_wait_list\" was not a direct buffer"); + if (!BufferFactory.isDirect(event)) + throw new CLException("Argument \"event\" was not a direct buffer"); + if (!BufferFactory.isDirect(errcode_ret)) + throw new CLException("Argument \"errcode_ret\" was not a direct buffer"); + + java.nio.ByteBuffer _res; + _res = clEnqueueMapImage0(command_queue, image, blocking_map, map_flags, origin!=null?origin.getBuffer():null, + BufferFactory.getDirectBufferByteOffset(origin), range!=null?range.getBuffer():null, + BufferFactory.getDirectBufferByteOffset(range), image_row_pitch!=null?image_row_pitch.getBuffer():null, + BufferFactory.getDirectBufferByteOffset(image_row_pitch), image_slice_pitch!=null?image_slice_pitch.getBuffer():null, + BufferFactory.getDirectBufferByteOffset(image_slice_pitch), num_events_in_wait_list, + event_wait_list!=null?event_wait_list.getBuffer():null, BufferFactory.getDirectBufferByteOffset(event_wait_list), + event!=null?event.getBuffer():null, BufferFactory.getDirectBufferByteOffset(event), errcode_ret, + BufferFactory.getDirectBufferByteOffset(errcode_ret)); + if (_res == null) return null; + BufferFactory.nativeOrder(_res); + return _res; + } + + /** Entry point to C language function: <code> void * {@native clEnqueueMapImage}(cl_command_queue command_queue, cl_mem image, uint32_t blocking_map, uint64_t map_flags, const size_t * , const size_t * , size_t * image_row_pitch, size_t * image_slice_pitch, uint32_t num_events_in_wait_list, cl_event * event_wait_list, cl_event * event, int32_t * errcode_ret); </code> + @param origin a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param range a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param image_row_pitch a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param image_slice_pitch a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param event_wait_list a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param event a direct {@link com.sun.gluegen.runtime.PointerBuffer} + @param errcode_ret a direct {@link java.nio.IntBuffer} */ + private native java.nio.ByteBuffer clEnqueueMapImage0(long command_queue, long image, int blocking_map, long map_flags, Object origin, int origin_byte_offset, Object range, int range_byte_offset, Object image_row_pitch, int image_row_pitch_byte_offset, Object image_slice_pitch, int image_slice_pitch_byte_offset, int num_events_in_wait_list, Object event_wait_list, int event_wait_list_byte_offset, Object event, int event_byte_offset, Object errcode_ret, int errcode_ret_byte_offset); + + private final static void convert32To64(long[] values) { if(values.length%2 == 1) { values[values.length-1] = values[values.length/2]>>>32; |