Forums - Copies image data(64M) from the ION buffer to the host very slowly

1 post / 0 new
Copies image data(64M) from the ION buffer to the host very slowly
andrew.wu
Join Date: 21 Dec 20
Posts: 2
Posted: Mon, 2021-01-11 18:02
    /*
     * Step 1: Create suitable ion buffer-backed CL images.
     */
 
    cl_image_format src_format;
    src_format.image_channel_order     = CL_R;
    src_format.image_channel_data_type = CL_UNORM_INT8;
    cl_image_desc src_desc;
    std::memset(&src_desc, 0, sizeof(src_desc));
    src_desc.image_type      = CL_MEM_OBJECT_IMAGE2D;
    src_desc.image_width     = src_bayer_image_info.width;
    src_desc.image_height    = src_bayer_image_info.height;
    src_desc.image_row_pitch = wrapper.get_ion_image_row_pitch(src_format, src_desc);
    cl_mem_ion_host_ptr src_ion_mem = wrapper.make_ion_buffer_for_nonplanar_image(src_format, src_desc);
 
    cl_int              err         = 0;
    cl_mem              src_image   = clCreateImage(
            context,
            CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_EXT_HOST_PTR_QCOM,
            &src_format,
            &src_desc,
            &src_ion_mem,
            &err
    );
 
    const size_t   origin[]     = {0, 0, 0};
    size_t         row_pitch    = 0 ;
    const size_t   src_region[] = {src_desc.image_width, src_desc.image_height, 1};
    unsigned char *image_ptr    = static_cast<unsigned char *>(clEnqueueMapImage(
            command_queue,
            src_image,
            CL_BLOCKING,
            CL_MAP_WRITE,
            origin,
            src_region,
            &row_pitch,
            NULL,
            0,
            NULL,
            NULL,
            &err
    ));
 
    // Copies image data from the host to the ION buffer cost 20ms
memcpy(image_ptr, src_ptr, src_desc.image_height * src_desc.image_width);
 
 
    err = clEnqueueUnmapMemObject(command_queue, src_image, image_ptr, 0, NULL, NULL);
    if (err != CL_SUCCESS)
    {
        std::cerr << "Error " << err << " unmapping source image." << "\n";
        std::exit(err);
    }
 
    cl_image_format out_format;
    out_format.image_channel_order     = CL_R;
    out_format.image_channel_data_type = CL_UNORM_INT8;
 
    cl_image_desc dst_desc;
    std::memset(&dst_desc, 0, sizeof(dst_desc));
    dst_desc.image_type      = CL_MEM_OBJECT_IMAGE2D;
    dst_desc.image_width     = src_bayer_image_info.width;
    dst_desc.image_height    = src_bayer_image_info.height;
    dst_desc.image_row_pitch = wrapper.get_ion_image_row_pitch(out_format, dst_desc);
int width = dst_desc.image_width;
int height = dst_desc.image_height;
    cl_mem_ion_host_ptr out_ion_mem = wrapper.make_ion_buffer_for_nonplanar_image(out_format, dst_desc);
    cl_mem dst_image = clCreateImage(
            context,
            CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_EXT_HOST_PTR_QCOM,
            &out_format,
            &dst_desc,
            &out_ion_mem,
            &err
);
 
/*
     * Step 2: do ...init and meanfilter kernel running
     */
 
    /*
     * Step 3: Copy the data out of the ion buffer.
     */
    rgba_image_t dst_image_info;
    dst_image_info.width  = dst_desc.image_width;
    dst_image_info.height = dst_desc.image_height;
 
    const size_t out_region[] = {dst_desc.image_width, dst_desc.image_height, 1};
    row_pitch                 = 0;
    image_ptr                 = static_cast<unsigned char *>(clEnqueueMapImage(
            command_queue,
            dst_image,
            CL_TRUE,
            CL_MAP_READ,
            origin,
            out_region,
            &row_pitch,
            NULL,
            0,
            NULL,
            NULL,
            &err
    ));
 
clFinish(command_queue);
 
    // Copies image data(64M) from the ION buffer to the host cost 350ms
memcpy(dst_ptr, image_ptr, dst_image_info.width * dst_image_info.height);
 
  • Up0
  • Down0

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.