89 lines
3.0 KiB
C++
89 lines
3.0 KiB
C++
#include "opencl_source_map.hpp"
|
|
namespace MNN {
|
|
const char* binary =
|
|
"#ifdef MNN_SUPPORT_FP16\n"
|
|
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
|
|
"#endif\n"
|
|
"#define PI 3.141592653589f\n"
|
|
"__constant sampler_t SAMPLER=CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;\n"
|
|
"__kernel void binary(__private int global_dim0,__private int global_dim1,\n"
|
|
" __read_only image2d_t input0,__read_only image2d_t input1,\n"
|
|
" __write_only image2d_t output,\n"
|
|
" __private const int4 shape,//[N,H,W,C4]\n"
|
|
" __private const int2 isFull,\n"
|
|
" __private const int activationType) {\n"
|
|
" int2 pos=(int2)(get_global_id(0),get_global_id(1));//WC4,NH\n"
|
|
" \n"
|
|
" #ifdef INT_COMPUTE_MOD\n"
|
|
" int4 in0,in1;\n"
|
|
" if (pos.x<global_dim0 && pos.y<global_dim1) {\n"
|
|
" if(isFull.x == 0) {\n"
|
|
" in0=convert_int4(RI_DATA(input0,SAMPLER,(int2)(0,0)));\n"
|
|
" in0=(int4)(in0.x,in0.x,in0.x,in0.x);\n"
|
|
" } else {\n"
|
|
" in0=convert_int4(RI_DATA(input0,SAMPLER,pos));\n"
|
|
" }\n"
|
|
" if(isFull.y == 0) {\n"
|
|
" in1=convert_int4(RI_DATA(input1,SAMPLER,(int2)(0,0)));\n"
|
|
" in1=(int4)(in1.x,in1.x,in1.x,in1.x);\n"
|
|
" } else {\n"
|
|
" in1=convert_int4(RI_DATA(input1,SAMPLER,pos));\n"
|
|
" }\n"
|
|
" \n"
|
|
" int4 out=in0 % in1;\n"
|
|
" out=((out<(int4)0 && in1>(int4)0) || (out>(int4)0 && in1<(int4)0)) ? out+in1 : out;\n"
|
|
" \n"
|
|
" if(activationType == 1) {\n"
|
|
" out=out>0 ? out : 0;\n"
|
|
" }\n"
|
|
" WI_DATA(output,pos,CONVERT_OUTPUT_I4(out));\n"
|
|
" }\n"
|
|
" #else\n"
|
|
" float4 in0,in1;\n"
|
|
" if (pos.x<global_dim0 && pos.y<global_dim1) {\n"
|
|
" if(isFull.x == 0) {\n"
|
|
" in0=convert_float4(RI_DATA(input0,SAMPLER,(int2)(0,0)));\n"
|
|
" in0=(float4)(in0.x,in0.x,in0.x,in0.x);\n"
|
|
" } else {\n"
|
|
" in0=convert_float4(RI_DATA(input0,SAMPLER,pos));\n"
|
|
" }\n"
|
|
" if(isFull.y == 0) {\n"
|
|
" in1=convert_float4(RI_DATA(input1,SAMPLER,(int2)(0,0)));\n"
|
|
" in1=(float4)(in1.x,in1.x,in1.x,in1.x);\n"
|
|
" } else {\n"
|
|
" in1=convert_float4(RI_DATA(input1,SAMPLER,pos));\n"
|
|
" }\n"
|
|
" \n"
|
|
" float4 out=OPERATOR;\n"
|
|
" \n"
|
|
" if(activationType == 1) {\n"
|
|
" out=fmax(out,(float4)0);\n"
|
|
" }\n"
|
|
" WI_DATA(output,pos,CONVERT_OUTPUT_I4(out));\n"
|
|
" }\n"
|
|
" #endif\n"
|
|
"}\n"
|
|
"__kernel void binary_prelu(__read_only image2d_t input0,__read_only image2d_t input1,__write_only image2d_t output,\n"
|
|
" int4 shape,int2 whInput1,int4 input1NHWCStep) {\n"
|
|
" int2 pos=(int2)(get_global_id(0),get_global_id(1));\n"
|
|
" int4 nhwc=(int4)(pos.y/shape.y,pos.y%shape.y,pos.x%shape.z,pos.x/shape.z);\n"
|
|
" if (nhwc.x<shape.x && nhwc.w<shape.w) {\n"
|
|
" int4 nhwc1=nhwc*input1NHWCStep;\n"
|
|
" int2 pos1=(int2)(nhwc1.w*whInput1.x+nhwc1.z,nhwc1.x*whInput1.y+nhwc1.y);\n"
|
|
" float4 in0=convert_float4(RI_DATA(input0,SAMPLER,pos));\n"
|
|
" float4 in1=convert_float4(RI_DATA(input1,SAMPLER,pos1));\n"
|
|
" OUTPUT_TYPE_I4 out=CONVERT_OUTPUT_I4(OPERATOR);\n"
|
|
" WI_DATA(output,pos,out);\n"
|
|
" }\n"
|
|
"}\n"
|
|
"__kernel void imageCopy(__read_only image2d_t input,__write_only image2d_t output) {\n"
|
|
" const int2 pos=(int2)(get_global_id(0),get_global_id(1));\n"
|
|
" const int2 dim=get_image_dim(input);\n"
|
|
" if (pos.x >= dim.x && pos.y >= dim.y) {\n"
|
|
" return;\n"
|
|
" }\n"
|
|
" WI_DATA(output,pos,CONVERT_OUTPUT_I4(RI_DATA(input,SAMPLER,pos)));\n"
|
|
"}\n"
|
|
;
|
|
}
|