| 35 | namespace arm_compute |
| 36 | { |
| 37 | cl::Image2D create_image2d_from_tensor(const ICLTensor *tensor, CLImage2DType image_type) |
| 38 | { |
| 39 | ARM_COMPUTE_ERROR_ON_NULLPTR(tensor); |
| 40 | |
| 41 | const cl::Context &ctx = CLKernelLibrary::get().context(); |
| 42 | const cl::Buffer &buffer = tensor->cl_buffer(); |
| 43 | const ITensorInfo *info = tensor->info(); |
| 44 | ARM_COMPUTE_ERROR_ON_MSG(info->lock_paddings(), "Tensor paddings must not be locked to allow extending paddings to " |
| 45 | "satisfy cl_image pitch alignment requirement"); |
| 46 | |
| 47 | const size_t image_w{info->dimension(0) / 4}; |
| 48 | const size_t image_h{info->tensor_shape().total_size() / info->dimension(0)}; |
| 49 | const size_t max_image_w{CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_IMAGE2D_MAX_WIDTH>()}; |
| 50 | const size_t max_image_h{CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_IMAGE2D_MAX_HEIGHT>()}; |
| 51 | |
| 52 | ARM_COMPUTE_UNUSED(max_image_w, max_image_h); |
| 53 | ARM_COMPUTE_ERROR_ON_MSG(image_w > max_image_w, "Image width exceeds maximum width for exporting to cl_image"); |
| 54 | ARM_COMPUTE_ERROR_ON_MSG(image_h > max_image_h, "Image height exceeds maximum height for exporting to cl_image"); |
| 55 | |
| 56 | const TensorShape shape2d(image_w, image_h); |
| 57 | const size_t image_row_pitch = info->strides_in_bytes()[1]; |
| 58 | |
| 59 | return create_image2d_from_buffer(ctx, buffer, shape2d, info->data_type(), image_row_pitch, image_type); |
| 60 | } |
| 61 | |
| 62 | cl::Image2D create_image2d_from_buffer(const cl::Context &ctx, |
| 63 | const cl::Buffer &buffer, |
no test coverage detected