#include "cl_viv_vx_ext.h"

/*******************tensorstackconcat 16BITs********************/
__kernel void vxcTensorStackConcat(
    image2d_array_t input,
    image2d_t index,
    image2d_array_t output)
{
    int4 coord = (int4)(get_global_id(0), get_global_id(1), get_global_id(2), 0);
    vxc_short8 src0, src1;
    VXC_ReadImage2DArray(src0, input, coord, VXC_5BITOFFSET_XY(0, 0),\
        VXC_MODIFIER(0, 7, 0, VXC_RM_TowardZero, 0));
    VXC_ReadImage2DArray(src1, input, coord, VXC_5BITOFFSET_XY(8, 0),\
        VXC_MODIFIER(0, 7, 0, VXC_RM_TowardZero, 0));
    coord.w = 0;
    coord.y = read_imagei(index, coord.ww).x;
    VXC_WriteImage2DArray(output, coord, src0, VXC_MODIFIER(0, 7, 0, VXC_RM_TowardZero, 0));
    coord.x += 8;
    VXC_WriteImage2DArray(output, coord, src1, VXC_MODIFIER(0, 7, 0, VXC_RM_TowardZero, 0));
}

/**************tensorstackconcat 8BITs***************************/
__kernel void vxcTensorStackConcat8Bits(
    image2d_array_t input,
    image2d_t index,
    image2d_array_t output)
{
    int4 coord = (int4)(get_global_id(0), get_global_id(1), get_global_id(2), 0);
    int idx = coord.x;
    vxc_char16 src0, src1;
    VXC_ReadImage2DArray(src0, input, coord, VXC_5BITOFFSET_XY(0, 0),\
        VXC_MODIFIER(0, 15, 0, VXC_RM_TowardZero, 0));
    coord.x += 16;
    VXC_ReadImage2DArray(src1, input, coord, VXC_5BITOFFSET_XY(0, 0),\
        VXC_MODIFIER(0, 15, 0, VXC_RM_TowardZero, 0));
    coord.x = idx;
    coord.w = 0;
    coord.y = read_imagei(index, coord.ww).x;
    VXC_WriteImage2DArray(output, coord, src0, VXC_MODIFIER(0, 15, 0, VXC_RM_TowardZero, 0));
    coord.x += 16;
    VXC_WriteImage2DArray(output, coord, src1, VXC_MODIFIER(0, 15, 0, VXC_RM_TowardZero, 0));
}