| 255 | } |
| 256 | |
| 257 | void gen_kernel( |
| 258 | KernelGenRet& kernels, TContext* ctx, KernelGen::Arch arch, |
| 259 | const std::string& kernel_symbol, bool gen_deduce_func) { |
| 260 | int usable_kern_cnt = 0; |
| 261 | for (auto kernel : kernels.first) { |
| 262 | if (kernel->IsAvailable(ctx)) { |
| 263 | usable_kern_cnt++; |
| 264 | TargetModule& g_module = TargetModule::get_global_target_module(); |
| 265 | auto kern_sym = kernel->GetKernelSymbol(ctx); |
| 266 | auto if_match = std::regex_match(kern_sym, std::regex(kernel_symbol)); |
| 267 | if (!if_match) |
| 268 | continue; |
| 269 | if (!g_module.exist(kern_sym)) { |
| 270 | std::string deduce_sym = ""; |
| 271 | std::string deduce_body = ""; |
| 272 | if (gen_deduce_func) { |
| 273 | mgb_assert(kernels.second, "must have deduce func"); |
| 274 | deduce_sym = kernels.second->GetDeduceSymbol(ctx); |
| 275 | deduce_body = kernels.second->GetDeduceBody(ctx); |
| 276 | } |
| 277 | g_module.add( |
| 278 | kern_sym, kernel->GetKernelBody(ctx), |
| 279 | kernel->GetInitSymbol(ctx), kernel->GetInitBody(ctx), |
| 280 | kernel->GetWorkspaceSymbol(ctx), kernel->GetWorkspaceBody(ctx), |
| 281 | deduce_sym, deduce_body); |
| 282 | auto depends = kernel->GetDependInternalSymbol(ctx); |
| 283 | gen_depend_kernels(arch, depends); |
| 284 | } |
| 285 | size_t workspace_bytes = 0; |
| 286 | #if MEGCC_TEST_GEN |
| 287 | workspace_bytes = |
| 288 | megcc::KernelGen::JitExec::jit_exec_and_get_workspace(kernel, ctx); |
| 289 | #endif |
| 290 | auto workspace_size_symbol = |
| 291 | kernel->GetWorkspaceSymbol(ctx) + input_shape_to_string(ctx); |
| 292 | g_module.add_workspace_size(workspace_size_symbol, workspace_bytes); |
| 293 | return; |
| 294 | } |
| 295 | } |
| 296 | mgb_assert(0, "gen kernel failed, available %d", usable_kern_cnt); |
| 297 | } |
| 298 | |
| 299 | PerformanceResult call_kernel( |
| 300 | std::pair< |
no test coverage detected