#include "opencl_source_map.hpp" namespace MNN { const char* softmax = "#ifdef MNN_SUPPORT_FP16\n" "#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n" "#endif\n" "#define EXP exp\n" "#define GLOBAL_SIZE_3_DIMS "" __private const int global_size_dim0,__private const int global_size_dim1,__private const int global_size_dim2,\n" "#define DEAL_NON_UNIFORM_DIM3(input1, input2, input3) "" if (input1 >= global_size_dim0 || input2 >= global_size_dim1 || input3 >= global_size_dim2) { "" return; "" }\n" "__constant sampler_t SAMPLER=CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;\n" "__kernel void softmax_channel(GLOBAL_SIZE_3_DIMS __read_only image2d_t input,__write_only image2d_t output,\n" " __private const int remain_channels,__private const int4 shape // NCHW\n" " ) {\n" " const int x=get_global_id(0);\n" " const int w=get_global_id(1);\n" " const int bh=get_global_id(2);\n" " DEAL_NON_UNIFORM_DIM3(x,w,bh);\n" "#if SOFTMAX_LOCAL_SIZE >= 4\n" " int lid=get_local_id(0);\n" " FLOAT4 local sum_mnn[SOFTMAX_LOCAL_SIZE];\n" " FLOAT4 local max_mnn[SOFTMAX_LOCAL_SIZE];\n" " FLOAT4 maxValue=(FLOAT4)-FLT_MAX;\n" " for (int i=lid; i0; i /= 2){\n" " if (lid0; i /= 2){\n" " if (lid= 4\n" " int lid=get_local_id(0);\n" " FLOAT4 local sum_mnn[SOFTMAX_LOCAL_SIZE];\n" " FLOAT4 local max_mnn[SOFTMAX_LOCAL_SIZE];\n" " /*Compute Max */\n" " FLOAT4 maxValue=(FLOAT4)(-FLT_MAX);\n" " for (int i=lid; i0; i /= 2){\n" " if (lid0; i /= 2){\n" " if (lid= 4\n" " int lid=get_local_id(0);\n" " FLOAT4 local sum_mnn[SOFTMAX_LOCAL_SIZE];\n" " FLOAT4 local max_mnn[SOFTMAX_LOCAL_SIZE];\n" " \n" " /*Compute Max */\n" " FLOAT4 maxValue=(FLOAT4)(-FLT_MAX);\n" " for (int i=lid; i0; i /= 2){\n" " if (lid0; i /= 2){\n" " if (lid