Compute Library  18.05
reshape_layer.cl File Reference
#include "helpers.h"

Go to the source code of this file.

Functions

__kernel void reshape_layer (__global uchar *input_ptr, uint input_stride_x, uint input_step_x, uint input_stride_y, uint input_step_y, uint input_stride_z, uint input_step_z, uint input_offset_first_element_in_bytes, __global uchar *output_ptr, uint output_stride_x, uint output_step_x, uint output_stride_y, uint output_step_y, uint output_stride_z, uint output_step_z, uint output_offset_first_element_in_bytes, int2 input_shape, int2 output_shape)
 Perform tensor reshape. More...
 

Function Documentation

__kernel void reshape_layer ( __global uchar *  input_ptr,
uint  input_stride_x,
uint  input_step_x,
uint  input_stride_y,
uint  input_step_y,
uint  input_stride_z,
uint  input_step_z,
uint  input_offset_first_element_in_bytes,
__global uchar *  output_ptr,
uint  output_stride_x,
uint  output_step_x,
uint  output_stride_y,
uint  output_step_y,
uint  output_stride_z,
uint  output_step_z,
uint  output_offset_first_element_in_bytes,
int2  input_shape,
int2  output_shape 
)

Perform tensor reshape.

Note
Datatype should be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short
Parameters
[in]input_ptrPointer to the first source tensor. Supported data types: U8/S8/QS8/U16/S16/QS16/U32/S32/F16/F32
[in]input_stride_xStride of the first source tensor in X dimension (in bytes)
[in]input_step_xinput_stride_x * number of elements along X processed per workitem(in bytes)
[in]input_stride_yStride of the first source tensor in Y dimension (in bytes)
[in]input_step_yinput_stride_y * number of elements along Y processed per workitem(in bytes)
[in]input_stride_zStride of the first source tensor in Z dimension (in bytes)
[in]input_step_zinput_stride_z * number of elements along Z processed per workitem(in bytes)
[in]input_offset_first_element_in_bytesThe offset of the first element in the first source tensor
[out]output_ptrPointer to the destination tensor. Supported data types: same as input_ptr
[in]output_stride_xStride of the destination tensor in X dimension (in bytes)
[in]output_step_xoutput_stride_x * number of elements along X processed per workitem(in bytes)
[in]output_stride_yStride of the destination tensor in Y dimension (in bytes)
[in]output_step_youtput_stride_y * number of elements along Y processed per workitem(in bytes)
[in]output_stride_zStride of the destination tensor in Z dimension (in bytes)
[in]output_step_zoutput_stride_z * number of elements along Z processed per workitem(in bytes)
[in]output_offset_first_element_in_bytesThe offset of the first element in the destination tensor
[in]input_shapeInput spatial shape
[in]output_shapeOutput spatial shape

Definition at line 49 of file reshape_layer.cl.

References CONVERT_TO_TENSOR3D_STRUCT, CONVERT_TO_TENSOR3D_STRUCT_NO_STEP, DATA_TYPE, Tensor3D::ptr, and tensor3D_offset().

53 {
56 
57  int3 id = (int3)(get_global_id(0), get_global_id(1), get_global_id(2));
58 
59  // Linearize index
60  int linear_idx = id.x + id.y * input_shape.x + id.z * input_shape.x * input_shape.y;
61 
62  // Translate to output
63  int3 out_id;
64  out_id.x = linear_idx % output_shape.x;
65  out_id.y = (linear_idx / output_shape.x) % output_shape.y;
66  out_id.z = linear_idx / (output_shape.x * output_shape.y);
67 
68  // Store result
69  *((__global DATA_TYPE *)tensor3D_offset(&out, out_id.x, out_id.y, out_id.z)) = *((__global DATA_TYPE *)in.ptr);
70 }
#define CONVERT_TO_TENSOR3D_STRUCT(name)
Definition: helpers.h:119
#define DATA_TYPE
Structure to hold 3D tensor information.
Definition: helpers.h:151
__global const uchar * tensor3D_offset(const Tensor3D *tensor, int x, int y, int z)
Get the pointer position of a Tensor3D.
Definition: helpers.h:315
#define CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(name)
Definition: helpers.h:123
__global uchar * ptr
Pointer to the starting postion of the buffer.
Definition: helpers.h:153