Hello:
调用cl_arm_import_memory报错,错误号CL_INVALID_PROPERTY。
我尝试的调用方法如下:
方式一:
cl_int clRet = 0;
image->pImageData = malloc(image->iImageSize);
image->handler = clImportMemoryARM(oclContext(), CL_MEM_READ_WRITE, NULL, image->pImageData, image->iImageSize, &clRet);
方式二:
cl_import_properties_arm importProps[] = {CL_IMPORT_TYPE_ARM, CL_IMPORT_TYPE_HOST_ARM, 0};
image->handler = clImportMemoryARM(oclContext(), CL_MEM_READ_WRITE, importProps, image->pImageData, image->iImageSize, &clRet);
两种方式均报出前述错误。
注意到该API的文档中提到:
If the extension string cl_arm_import_memory_dma_buf is exposed then
importing from DMA_BUF file handles is supported.
If the extension string cl_arm_import_memory_host is exposed then importing
from normal process allocations (such as malloc) is supported.
但是我们的设备并没有上述扩展字符串,只有cl_arm_import_memory一个。
我们设备的详细信息见下,请帮忙确认一下我们的设备是否支持clImportMemoryARM,谢谢。
OpenCL-Z-Android Report========================Version: 1.0.1Release date: April 2015Author: Robert WangEmail: robertwgh@gmail.comWebsite: http://web.guohuiwang.com
Phone/Tablet Information--------------------------------Device model: NICIGOAndroid OS version: 6.0Kernel version: 3.18.22, 周六 10月 29 15:55:55 2016Build number: MRA58K release-keysCPU ABI: arm64-v8aCPU ABI 2: armeabi-v7a
OpenCL Information-------------------------Found 1 OpenCL platforms.[Platform] INDEX: 1[Platform] NAME: ARM Platform[Platform] VENDOR: ARM[Platform] PROFILE: FULL_PROFILE[Platform] VERSION: OpenCL 1.1 v1.r7p0-02rel0.a6c0939b3050616905647b55b149c24b[Platform] EXTENSIONS: cl_khr_global_int32_base_atomics;cl_khr_global_int32_extended_atomics;cl_khr_local_int32_base_atomics;cl_khr_local_int32_extended_atomics;cl_khr_byte_addressable_store;cl_khr_3d_image_writes;cl_khr_fp64;cl_khr_int64_base_atomics;cl_khr_int64_extended_atomics;cl_khr_fp16;cl_khr_gl_sharing;cl_khr_icd;cl_khr_egl_event;cl_khr_egl_image;cl_arm_core_id;cl_arm_printf;cl_arm_thread_limit_hint;cl_arm_non_uniform_work_group_size;cl_arm_import_memory
Found 1 devices: [Device] INDEX: 1 [Device] TYPE: GPU [Device] NAME: Mali-T860 [Device] VENDOR: ARM [Device] VENDOR_ID: 0x8600020>>> [Device] DRIVER_VERSION: 1.1 [Device] PROFILE: FULL_PROFILE [Device] VERSION: OpenCL 1.1 v1.r7p0-02rel0.a6c0939b3050616905647b55b149c24b [Device] MAX_CLOCK_FREQUENCY: 5 MHz [Device] MAX_COMPUTE_UNITS: 2 [Device] AVAILABLE: true [Device] COMPILER_AVAILABLE: true [Device] EXTENSIONS: cl_khr_global_int32_base_atomics;cl_khr_global_int32_extended_atomics;cl_khr_local_int32_base_atomics;cl_khr_local_int32_extended_atomics;cl_khr_byte_addressable_store;cl_khr_3d_image_writes;cl_khr_fp64;cl_khr_int64_base_atomics;cl_khr_int64_extended_atomics;cl_khr_fp16;cl_khr_gl_sharing;cl_khr_icd;cl_khr_egl_event;cl_khr_egl_image;cl_arm_core_id;cl_arm_printf;cl_arm_thread_limit_hint;cl_arm_non_uniform_work_group_size;cl_arm_import_memory [Device] MAX_WORK_ITEM_DIMENSIONS: 3 [Device] MAX_WORK_ITEM_SIZES: (256, 256, 256) [Device] MAX_WORK_GROUP_SIZE: 256 [Device] ADDRESS_BITS: 64 [Device] MAX_READ_IMAGE_ARGS: 128 [Device] MAX_WRITE_IMAGE_ARGS: 8 [Device] MAX_MEM_ALLOC_SIZE: 536870912 [Device] IMAGE2D_MAX_WIDTH: 65536 [Device] IMAGE2D_MAX_HEIGHT: 65536 [Device] IMAGE3D_MAX_WIDTH: 65536 [Device] IMAGE3D_MAX_HEIGHT: 65536 [Device] IMAGE3D_MAX_DEPTH: 65536 [Device] IMAGE_SUPPORT: true [Device] MAX_PARAMETER_SIZE: 1024 [Device] MAX_SAMPLERS: 16 [Device] MEM_BASE_ADDR_ALIGN: 1024 [Device] MIN_DATA_TYPE_ALIGN_SIZE: 128 [Device] SINGLE_FP_CONFIG: CL_FP_DENORM;CL_FP_INF_NAN;CL_FP_ROUND_TO_NEAREST;CL_FP_ROUND_TO_ZERO;CL_FP_ROUND_TO_INF;CL_FP_FMA; [Device] HOST_UNIFIED_MEMORY: Unified [Device] GLOBAL_MEM_CACHE_TYPE: read/write cache [Device] GLOBAL_MEM_CACHELINE_SIZE: 64 [Device] GLOBAL_MEM_CACHE_SIZE: 262144 [Device] GLOBAL_MEM_SIZE: 2147483648 [Device] MAX_CONSTANT_BUFFER_SIZE: 65536 [Device] MAX_CONSTANT_ARGS: 8 [Device] LOCAL_MEM_TYPE: global [Device] LOCAL_MEM_SIZE: 32768 [Device] ERROR_CORRECTION_SUPPORT: false [Device] PROFILING_TIMER_RESOLUTION: 1000 nanoseconds [Device] ENDIAN_LITTLE: true [Device] EXECUTION_CAPABILITIES: CL_EXEC_KERNEL; [Device] QUEUE_PROPERTIES: CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;CL_QUEUE_PROFILING_ENABLE; [Device] PREFERRED_VECTOR_WIDTH_CHAR: 16 [Device] PREFERRED_VECTOR_WIDTH_SHORT: 8 [Device] PREFERRED_VECTOR_WIDTH_INT: 4 [Device] PREFERRED_VECTOR_WIDTH_LONG: 2 [Device] PREFERRED_VECTOR_WIDTH_FLOAT: 4 [Device] PREFERRED_VECTOR_WIDTH_DOUBLE: 2 [Device] PREFERRED_VECTOR_WIDTH_HALF: 8 [Device] NATIVE_VECTOR_WIDTH_CHAR: 16 [Device] NATIVE_VECTOR_WIDTH_SHORT: 8 [Device] NATIVE_VECTOR_WIDTH_INT: 4 [Device] NATIVE_VECTOR_WIDTH_LONG: 2 [Device] NATIVE_VECTOR_WIDTH_FLOAT: 4 [Device] NATIVE_VECTOR_WIDTH_DOUBLE: 2 [Device] NATIVE_VECTOR_WIDTH_HALF: 8
malloc出来的system memory在r7p0里面还没有支持,需要更新到r18. 最新的spec请参考www.khronos.org/.../cl_arm_import_memory.txt
有点不太理解,如果设备不支持的话,不应该能查询出cl_arm_import_memory这个扩展字符串吧?
根据spec,cl_arm_import_memory_host/dma_buf扩展字符串有的时候,相应的import功能才存在,而cl_arm_import_memory扩展字符串只要前面两者之一存在就会存在。r7p0是我们刚刚支持import memory这个extension,而且只支持dam_buf.
Name Strings cl_arm_import_memory cl_arm_import_memory_host cl_arm_import_memory_dma_buf cl_arm_import_memory will be reported if at least one of the other extension strings is also reported.
感谢确认,但仍有问题:
1. 对于我的设备来说,这两个”cl_arm_import_memory_host/dma_buf“一个也没有啊,因此按照spec的要求,"cl_arm_import_memory"这个字符串应该也不存在才对吧?
2. 如果r7p0支持dam_buf,”cl_arm_import_memory_dma_buf“这个扩展字符串应该能查询到的吧?
3. 所以,我有点乱了,麻烦再次确认下我们的设备是否支持dam_buf的import。如果支持,具体如何操作呢?
dma_buf应该是支持的,可能export的时候有些小问题,但是malloc肯定是不支持的。具体操作,请参考spec,如果还有问题再问。
Sample Code CL_IMPORT_TYPE_DMA_BUF_ARM #define WIDTH 1024 #define HEIGHT 512 // Create buffer to be used as a hardware texture with graphics APIs (can also // include video/camera use flags here) int dma_buf_handle = get_dma_buf_handle_from_exporter_kernel_module( ..., WIDTH * HEIGHT * 2 ); cl_int error = CL_SUCCESS; cl_mem buffer = clImportMemoryARM( ctx, CL_MEM_READ_WRITE, { CL_IMPORT_TYPE_ARM, CL_IMPORT_TYPE_DMA_BUF_ARM, 0 }, &dma_buf_handle WIDTH * HEIGHT * 2, &error ); if( error == CL_SUCCESS ) { // Use <buffer> as you would any other cl_mem buffer } CL_IMPORT_TYPE_HOST_ARM #define WIDTH 1024 #define HEIGHT 512 // tightly packed buffer we will treat as RGB565 char *buffer = malloc( WIDTH * HEIGHT * 2 ); // The type CL_IMPORT_TYPE_HOST_ARM can be omitted as it is the default cl_int error = CL_SUCCESS; cl_mem buffer = clImportMemoryARM( ctx, CL_MEM_READ_WRITE, NULL, buffer, WIDTH * HEIGHT * 2, &error ); if( error == CL_SUCCESS ) { // Use <buffer> as you would any other cl_mem buffer }
不清楚get_dma_buf_handle_from_exporter_kernel_module的含义。
其对应的android平台下的API是什么?
申请出的DMA Buffer可否同时供CPU访问呢?
Android平台下你用什么buffer作为需要import的buffer呢?我这里给你举个GraphicBuffer的例子,你可以参考一下。
GraphicBuffer* buffer = new GraphicBuffer( WIDTH, HEIGHT,
PIXEL_FORMAT_RGB_565, GraphicBuffer::USAGE_SW_WRITE_OFTEN |
GraphicBuffer::USAGE_HW_TEXTURE );
android_native_buffer_t *anb = buffer->getNativeBuffer(); const private_handle_t *gralloc_handle = (const private_handle_t*)anb->handle;
private_handle_t是跟平台相关的,但你可以从"gralloc_priv.h"找到相关的dma_buf file descriptor.
把handle传到clImportMemoryARM里面用就可以了。
明白,真是麻烦你了,非常感谢~
1, clImportMemoryARM 可以导入HAL_PIXEL_FORMAT_YCrCb_420_SP (NV21格式的图)的GraphicBuffer吗?2, 支持cl_arm_import_memory_host的话, 任何host 端malloc出来的memory都可以 clImportMemoryARM吗, 有无约束?3, GraphicBuffer lock&lockYCbCr 出来的内存地址(CPU可用)可否用cl_arm_import_memory_host 来clImportMemoryARM ?4, 其他OPENCL context 关联的cl_mem map出来的host ptr 是否可以通过可否用cl_arm_import_memory_host 来clImportMemoryARM?
get_dma_buf_handle_from_exporter_kernel_module 函数在哪个头文件啊