#include "opencl_source_map.hpp" namespace MNN { #ifndef MNN_OPENCL_BUFFER_CLOSED const char* topkv2_buf = "#ifdef MNN_SUPPORT_FP16\n" "#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n" "#endif\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" "#define THREAD_NUMBER 128\n" "#define LOCAL_K 8\n" "#define CANDIDATE_NUMBER (THREAD_NUMBER*LOCAL_K)\n" "#ifdef IS_INT\n" "typedef int DTYPE;\n" "#else\n" "typedef FLOAT DTYPE;\n" "#endif\n" "inline bool afterAsc(DTYPE aValue,int aIndex,DTYPE bValue,int bIndex) {\n" " if (aValue>bValue) {\n" " return true;\n" " }\n" " if (aValuebIndex;\n" "}\n" "inline bool better(DTYPE aValue,int aIndex,DTYPE bValue,int bIndex) {\n" " if (bIndex<0) {\n" " return true;\n" " }\n" " if (aIndex<0) {\n" " return false;\n" " }\n" "#ifdef SORT_DESC\n" " if (aValue>bValue) {\n" " return true;\n" " }\n" " if (aValuebValue) {\n" " return false;\n" " }\n" "#endif\n" " return aIndex= THREAD_NUMBER || row >= numRows) {\n" " return;\n" " }\n" "#ifdef IS_INT\n" " const DTYPE initWorst=(DTYPE)(2147483647);\n" " const DTYPE initBestWorst=(DTYPE)(-2147483648);\n" "#else\n" " const DTYPE initWorst=(DTYPE)(FLT_MAX);\n" " const DTYPE initBestWorst=(DTYPE)(-FLT_MAX);\n" "#endif\n" " DTYPE localValue[LOCAL_K];\n" " int localIndex[LOCAL_K];\n" "#ifdef SORT_DESC\n" " for (uint i=0; i= LOCAL_K) {\n" " continue;\n" " }\n" " for (uint j=LOCAL_K-1; j>insertPos; --j) {\n" " localValue[j]=localValue[j-1];\n" " localIndex[j]=localIndex[j-1];\n" " }\n" " localValue[insertPos]=value;\n" " localIndex[insertPos]=i;\n" " }\n" " __local DTYPE sharedValue[CANDIDATE_NUMBER];\n" " __local int sharedIndex[CANDIDATE_NUMBER];\n" " const uint base=tid*LOCAL_K;\n" " for (uint i=0; i> 1; stride>0; stride >>= 1) {\n" " for (uint idx=tid; idx