MCPcopy Create free account
hub / github.com/MegEngine/MegCC / call_kernel

Function call_kernel

compiler/test/kernel/common/src/cc_proxy.cpp:299–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297}
298
299PerformanceResult call_kernel(
300 std::pair<
301 std::vector<const KernelGen::KernelFunc*>,
302 const KernelGen::DeduceFunc*>& kernels,
303 TContext* ctx, const TensorNDArray& tensors,
304 const BenchmarkOption& benchmark_option, const std::string& kernel_symbol,
305 const OutputScope output_idx, bool dynamic_shape) {
306 std::string kern_name;
307 std::string kern_init_name;
308 std::string kern_deduce_name;
309 std::string kern_workspace_name;
310 for (auto kernel : kernels.first) {
311 if (kernel->IsAvailable(ctx)) {
312 auto kern_sym = kernel->GetKernelSymbol(ctx);
313 auto if_match = std::regex_match(kern_sym, std::regex(kernel_symbol));
314 if (!if_match)
315 continue;
316 kern_name = kern_sym;
317 kern_init_name = kernel->GetInitSymbol(ctx);
318 kern_workspace_name = kernel->GetWorkspaceSymbol(ctx);
319 if (dynamic_shape) {
320 mgb_assert(kernels.second, "deduce func can not be null");
321 kern_deduce_name = kernels.second->GetDeduceSymbol(ctx);
322 }
323 break;
324 }
325 }
326 mgb_assert(
327 kern_name.size() > 0 && kern_init_name.size() > 0,
328 "gen kernel name failed");
329 TargetModule& g_module = TargetModule::get_global_target_module();
330 auto func = g_module.get_kernel(kern_name);
331 mgb_assert(func, "can not get kernel[%s] from target module", kern_name.c_str());
332 auto init_func = g_module.get_kernel_init(kern_init_name);
333 mgb_assert(
334 init_func, "can not get init kernel[%s] from target module",
335 kern_init_name.c_str());
336 auto workspace_func = g_module.get_kernel_workspace(kern_workspace_name);
337 mgb_assert(
338 workspace_func, "can not get workspace kernel[%s] from target module",
339 kern_workspace_name.c_str());
340 auto workspace_size_symbol = kern_workspace_name + input_shape_to_string(ctx);
341 size_t workspace_bytes = g_module.get_kernel_workspace_size(workspace_size_symbol);
342 StdKernelDeduceCall deduce_func = nullptr;
343 if (dynamic_shape) {
344 deduce_func = g_module.get_kernel_deduce(kern_deduce_name);
345 mgb_assert(
346 deduce_func, "can not get deduce func[%s] from target module",
347 kern_deduce_name.c_str());
348 }
349 return proxy_kernel(
350 tensors, func, init_func, workspace_func, deduce_func, benchmark_option,
351 workspace_bytes, output_idx);
352}
353
354} // namespace
355

Callers 2

fused_elemwise_execMethod · 0.85
execMethod · 0.85

Calls 12

input_shape_to_stringFunction · 0.85
proxy_kernelFunction · 0.85
get_kernelMethod · 0.80
get_kernel_initMethod · 0.80
get_kernel_workspaceMethod · 0.80
get_kernel_deduceMethod · 0.80
IsAvailableMethod · 0.45
GetKernelSymbolMethod · 0.45
GetInitSymbolMethod · 0.45
GetWorkspaceSymbolMethod · 0.45
GetDeduceSymbolMethod · 0.45

Tested by

no test coverage detected