MCPcopy Create free account
hub / github.com/alibaba/MNN / buildKernelFromSource

Method buildKernelFromSource

source/backend/opencl/core/runtime/OpenCLRuntime.cpp:687–721  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

685}
686
687std::shared_ptr<KernelWrap> OpenCLRuntime::buildKernelFromSource(const std::string& source, const std::string &kernelName,
688 const std::set<std::string> &buildOptions, int precisionLevel) {
689 std::string buildOptionsStr;
690 if (precisionLevel != 1) {
691 buildOptionsStr = "-DFLOAT=half -DFLOAT4=half4 -DFLOAT8=half8 -DFLOAT16=half16 -DRI_F=read_imageh -DWI_F=write_imageh -DCONVERT_FLOAT4=convert_half4 -DMNN_SUPPORT_FP16";
692 } else {
693 buildOptionsStr = "-DFLOAT=float -DFLOAT4=float4 -DFLOAT8=float8 -DRI_F=read_imagef -DFLOAT16=float16 -DWI_F=write_imagef -DCONVERT_FLOAT4=convert_float4";
694 }
695
696 if(isSetWorkGroupAttribute) {
697 buildOptionsStr += " -DSET_ATTRIBUTE=true";
698 } else {
699 buildOptionsStr += " -DSET_ATTRIBUTE=false";
700 }
701 for (auto &option : buildOptions) {
702 buildOptionsStr += " " + option;
703 }
704 buildOptionsStr += mDefaultBuildParams;
705
706 cl::Program::Sources sources;
707 sources.push_back(source);
708 cl::Program program = cl::Program(context(), sources);
709 auto status = this->buildProgram(buildOptionsStr, &program);
710 if (!status) {
711 FUNC_PRINT_ALL(kernelName.c_str(), s);
712 }
713 // mBuildProgramMap.emplace(key, program);
714
715 cl_int res;
716 std::shared_ptr<cl::Kernel> kernel;
717 kernel.reset(new cl::Kernel(program, kernelName.c_str(), &res));
718 MNN_CHECK_CL_SUCCESS(res, "getKernel");
719 std::shared_ptr<KernelWrap> kw(new KernelWrap(kernel, nullptr));
720 return kw;
721}
722
723
724uint64_t OpenCLRuntime::getMaxWorkGroupSize(std::shared_ptr<KernelWrap> kernel) {

Callers 1

FuseExecutionMethod · 0.80

Calls 5

buildProgramMethod · 0.95
ProgramClass · 0.50
push_backMethod · 0.45
c_strMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected