blob: 80a0019bf542820c690e714cc9ce8eba9c933a55 [file] [log] [blame]
Gian Marco Iodice781cba72020-06-19 16:56:57 +01001/*
2 * Copyright (c) 2020 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/Error.h"
25#include "arm_compute/core/Types.h"
26
27#include "src/core/CL/CLUtils.h"
28
29cl::Image2D arm_compute::create_image2d_from_buffer(const cl::Context &ctx, const cl::Buffer &buffer, const TensorShape &shape2d, cl_channel_type data_type, size_t image_row_pitch)
30{
31 cl_mem cl_image;
32 cl_int err = CL_SUCCESS;
33
34 const cl_image_format format = { CL_RGBA, data_type };
35
36 cl_image_desc desc;
37 memset(&desc, 0, sizeof(desc));
38 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
39 desc.mem_object = buffer();
40 desc.image_row_pitch = image_row_pitch;
41 desc.image_width = shape2d[0];
42 desc.image_height = shape2d[1];
43
44 cl_image = clCreateImage(ctx(), CL_MEM_READ_ONLY, &format, &desc, nullptr, &err);
45
46 ARM_COMPUTE_UNUSED(err);
47 ARM_COMPUTE_ERROR_ON_MSG(err != CL_SUCCESS, "Error during the creation of CL image from buffer");
48
49 return cl::Image2D(cl_image);
50}