MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / CompileImpl

Method CompileImpl

tensorflow/compiler/jit/xla_compilation_cache.cc:345–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343}
344
345Status 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,

Callers

nothing calls this directly

Calls 10

IsMegamorphicFunction · 0.85
nameMethod · 0.65
DebugStringFunction · 0.50
sizeMethod · 0.45
HumanStringMethod · 0.45
resetMethod · 0.45
getMethod · 0.45
emplaceMethod · 0.45
IgnoreErrorMethod · 0.45

Tested by

no test coverage detected