| 343 | } |
| 344 | |
| 345 | Status XlaCompilationCache::CompileImpl( |
| 346 | const XlaCompiler::Options& options, const NameAttrList& function, |
| 347 | std::vector<XlaCompiler::Argument>& args, |
| 348 | const std::function<Status(XlaCompiler* compiler, |
| 349 | const std::vector<XlaCompiler::Argument>& args, |
| 350 | XlaCompiler::CompilationResult*)>& compile_fn, |
| 351 | CompileMode compile_mode, |
| 352 | const XlaCompiler::CompilationResult** out_compilation_result, |
| 353 | xla::LocalExecutable** out_executable) { |
| 354 | DCHECK_NE(out_executable, nullptr); |
| 355 | VLOG(2) << "XlaCompilationCache::Compile " << DebugString(); |
| 356 | |
| 357 | VLOG(2) << "num_inputs=" << args.size(); |
| 358 | if (VLOG_IS_ON(3)) { |
| 359 | for (int i = 0; i < args.size(); i++) { |
| 360 | VLOG(3) << i << ": " << args[i].HumanString(); |
| 361 | } |
| 362 | } |
| 363 | absl::optional<int64> compile_threshold; |
| 364 | if (compile_mode == CompileMode::kLazy) { |
| 365 | compile_threshold = kDefaultCompilationThreshold; |
| 366 | } else if (compile_mode == CompileMode::kAsync) { |
| 367 | compile_threshold = 0; // for now, always compile right away |
| 368 | } |
| 369 | |
| 370 | TF_ASSIGN_OR_RETURN(Signature signature, BuildSignature(function, args)); |
| 371 | string function_name = function.name(); |
| 372 | string human_signature = VLOG_IS_ON(3) ? signature.HumanString() : function_name; |
| 373 | VLOG(2) << "Signature: " << human_signature; |
| 374 | |
| 375 | // The outer lock protects the existence of the cache entry. It does not |
| 376 | // protect the contents of the cache entry. |
| 377 | Entry* entry; |
| 378 | { |
| 379 | mutex_lock lock(compile_cache_mu_); |
| 380 | // Find or create a cache entry. |
| 381 | std::unique_ptr<Entry>& e = cache_[signature]; |
| 382 | if (!e) { |
| 383 | e.reset(new Entry); |
| 384 | } |
| 385 | entry = e.get(); |
| 386 | } |
| 387 | |
| 388 | // We avoid compiling clusters that have "gone megamorphic" i.e. have an |
| 389 | // excessive amount of shape dynamism. |
| 390 | bool is_megamorphic; |
| 391 | |
| 392 | { |
| 393 | mutex_lock lock(cluster_compile_stats_mu_); |
| 394 | auto it = |
| 395 | cluster_compile_stats_.emplace(function_name, ClusterCompileStats{}) |
| 396 | .first; |
| 397 | |
| 398 | it->second.execution_count++; |
| 399 | // The is_megamorphic bit is "sticky". We assume clusters that have been |
| 400 | // observed to be megamorphic once stay megamorphic forever. |
| 401 | it->second.is_megamorphic |= |
| 402 | IsMegamorphic(/*compile_count=*/it->second.compile_count, |
nothing calls this directly
no test coverage detected