tensorflow/compiler/mlir/tfrt/jit/tf_jitrt_kernels.cc
// Gets a JitExecutable async value from the cache, and then dispatches it
// inline or using and-then continuation depending on the async value state.
Gets a JitExecutable async value from the cache, and then dispatches it
inline or using and-then continuation depending on the async value state.
Gets a JitExecutable async value from the cache and then dispatches it inline or using and - then continuation depending on the async value state .
static void ExecuteImpl(RepeatedArguments<FallbackTensor> operands,
                        RemainingResults results, const StringAttribute& device,
                        const CompilationUnitAttribute& kernel,
                        const ExecutionContext& exec_ctx, bool debug = false,
                        const Optional<TfJitRtPipelineOpts>& opts = None) {
  Expected<AsyncValuePtr<JitExecutable>> jit_executable =
      CompileImpl(kernel, exec_ctx, opts);
  if (LLVM_UNLIKELY(!jit_executable))
    return ReturnErrors(results, jit_executable.takeError(), exec_ctx);
  if (LLVM_LIKELY(jit_executable->IsConcrete()))
    return ExecuteImpl(**jit_executable, operands, results, exec_ctx, debug);
  if (LLVM_UNLIKELY(jit_executable->IsError()))
    return ReturnErrors(results, jit_executable->GetError(), exec_ctx);
  for (unsigned i = 0; i < results.size(); ++i)
    results.AllocateIndirectResultAt(i);
  jit_executable->AndThen([exec_ctx, jit_executable = *jit_executable,
                           r = RCArray<AsyncValue>(results.values()),
                           o = RCArray<AsyncValue>(operands.values()), debug] {
    llvm::SmallVector<RCReference<AsyncValue>> results_storage;
    results_storage.resize(r.size());
    RepeatedArguments<FallbackTensor> operands(o.values());
    RemainingResults results(results_storage);
    if (jit_executable.IsError()) {
      ReturnErrors(results, jit_executable.GetError(), exec_ctx);
    } else {
      ExecuteImpl(*jit_executable, operands, results, exec_ctx, debug);
    }
    for (unsigned i = 0; i < r.size(); ++i)
      llvm::cast<IndirectAsyncValue>(*r[i]).ForwardTo(
          std::move(results_storage[i]));
  });
}
static void ExecuteImpl ( RepeatedArguments < FallbackTensor > operands , RemainingResults results , const StringAttribute & device , const CompilationUnitAttribute & kernel , const ExecutionContext & exec_ctx , bool debug = false , const Optional < TfJitRtPipelineOpts > & opts = None ) { Expected < AsyncValuePtr < JitExecutable > > jit_executable = CompileImpl ( kernel , exec_ctx , opts ) ; if ( LLVM_UNLIKELY ( ! jit_executable ) ) return ReturnErrors ( results , jit_executable . takeError ( ) , exec_ctx ) ; if ( LLVM_LIKELY ( jit_executable -> IsConcrete ( ) ) ) return ExecuteImpl ( * * jit_executable , operands , results , exec_ctx , debug ) ; if ( LLVM_UNLIKELY ( jit_executable -> IsError ( ) ) ) return ReturnErrors ( results , jit_executable -> GetError ( ) , exec_ctx ) ; for ( unsigned i = 0 ; i < results . size ( ) ; ++ i ) results . AllocateIndirectResultAt ( i ) ; jit_executable -> AndThen ( [ exec_ctx , jit_executable = * jit_executable , r = RCArray < AsyncValue > ( results . values ( ) ) , o = RCArray < AsyncValue > ( operands . values ( ) ) , debug ] { llvm :: SmallVector < RCReference < AsyncValue > > results_storage ; results_storage . resize ( r . size ( ) ) ; RepeatedArguments < FallbackTensor > operands ( o . values ( ) ) ; RemainingResults results ( results_storage ) ; if ( jit_executable . IsError ( ) ) { ReturnErrors ( results , jit_executable . GetError ( ) , exec_ctx ) ; } else { ExecuteImpl ( * jit_executable , operands , results , exec_ctx , debug ) ; } for ( unsigned i = 0 ; i < r . size ( ) ; ++ i ) llvm :: cast < IndirectAsyncValue > ( * r [ i ] ) . ForwardTo ( std :: move ( results_storage [ i ] ) ) ; } ) ; }
Gets a JitExecutable async value from the cache, and then dispatches it
inline or using and-then continuation depending on the async value state.
Gets a JitExecutable async value from the cache and then dispatches it inline or using and - then continuation depending on the async value state .
// Compile kernel module into the JitExecutable. // If kernel is available execute it inline ... // ... or maybe return errors. // Otherwise execute it when the executable will become available. This // requires careful lifetime extension of all async values passed as operands // to the kernel (and also results that will become available asynchronously). // Allocate indirect async values for all results, we'll forward them to the // actual async values computed by the executable later. // Call executable when it's ready with the original operands. // Allocate storage for compiled executable results. // Reconstruct arguments and results from captured async values. // Forward previously entry indirect results to the actual results.