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

Function codegen

codegen/OpFuse.cpp:307–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307bool codegen(std::vector<Schedule::OpCacheInfo>& infos, std::vector<std::vector<Node*>>& fuseSets, MNNForwardType type, BackendConfig::PrecisionMode precision) {
308 // generate Kernel
309 std::unique_ptr<Target> target;
310 switch (type) {
311#ifdef MNN_CODEGEN_OPENCL
312 case MNN_FORWARD_OPENCL:
313 target.reset(new OpenCLTarget(precision));
314 break;
315#endif
316#ifdef MNN_CODEGEN_METAL
317 case MNN_FORWARD_METAL:
318 target.reset(new MetalTarget(precision));
319 break;
320#endif
321#ifdef MNN_CODEGEN_CUDA
322 case MNN_FORWARD_CUDA:
323 target.reset(new CUDATarget(precision));
324 break;
325#endif
326 default:
327 return false;
328 }
329#if 0
330 if (fuseSets.size() > 0) {
331 MNN_PRINT(">>>>>>>>>>>>> fuseSets.size = %lu\n", fuseSets.size());
332 }
333#endif
334 std::map<std::string, int> mapKernelSources;
335 for (int i = 0; i < fuseSets.size(); i++) {
336 auto& compSet = fuseSets[i];
337 /*
338 for (auto comp : compSet) {
339 dumpCmd(comp->cmd);
340 }
341 */
342 bool fuseKernelVectorize = true;
343 for (auto& node : compSet) {
344 auto cmd = node->cmd;
345 if(!cmd->canVectorize) {
346 fuseKernelVectorize = false;
347 break;
348 }
349 }
350 target->setFuseKernelVectorize(fuseKernelVectorize);
351 SourceModule fuseModule(target.get());
352 InOutTensors tensors = fuseModule.buildKernel(compSet, i);
353 auto inputs = tensors.first;
354 auto outputs = tensors.second;
355 // build Plugin Op
356 std::shared_ptr<Command> cmdPlugin;
357 {
358 auto sourceCode = fuseModule.codegen();
359 if(mapKernelSources.find(sourceCode) == mapKernelSources.end()) {
360 int kernelCount = mapKernelSources.size();
361 mapKernelSources.insert(std::pair<std::string, int>(sourceCode, kernelCount));
362 }
363 std::string kernelName = "kernel_" + std::to_string(mapKernelSources[sourceCode]);
364 sourceCode.insert(fuseModule.strIndexForKernelNum(), kernelName);

Callers 1

opFuseFunction · 0.85

Calls 15

strIndexForKernelNumMethod · 0.80
opNameMethod · 0.80
to_stringFunction · 0.50
resetMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
buildKernelMethod · 0.45
codegenMethod · 0.45
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected