tensorflow/compiler/mlir/tfrt/jit/tf_jitrt_kernels.cc
// Gets a specialized Executable async value from the JitExecutable, and then
// dispatches it inline or using and-then continuation depending on the async
// value state.
Gets a specialized Executable async value from the JitExecutable, and then
dispatches it inline or using and-then continuation depending on the async
value state.
Gets a specialized Executable async value from the JitExecutable and then dispatches it inline or using and - then continuation depending on the async value state .
static void ExecuteImpl(JitExecutable& jit_executable,
                        RepeatedArguments<FallbackTensor> operands,
                        RemainingResults results,
                        const ExecutionContext& exec_ctx, bool debug) {
  llvm::SmallVector<MemrefDesc> memrefs;
  ConvertTensorOperandsToMemrefDesc(operands, &memrefs);
  DebugListener debug_listener;
  JitExecutable::UserData user_data = exec_ctx.request_ctx();
  Expected<AsyncValuePtr<Executable>> executable = jit_executable.GetExecutable(
      memrefs, user_data, debug ? &debug_listener : nullptr);
  if (LLVM_UNLIKELY(!executable))
    return ReturnErrors(results, executable.takeError(), exec_ctx);
  if (LLVM_LIKELY(executable->IsConcrete()))
    return ExecuteImpl(executable->get(), memrefs, operands, results, exec_ctx);
  if (LLVM_UNLIKELY(executable->IsError()))
    return ReturnErrors(results, executable->GetError(), exec_ctx);
  for (unsigned i = 0; i < results.size(); ++i)
    results.AllocateIndirectResultAt(i);
  executable->AndThen([exec_ctx, executable = *executable,
                       memrefs = std::move(memrefs),
                       r = RCArray<AsyncValue>(results.values()),
                       o = RCArray<AsyncValue>(operands.values())] {
    llvm::SmallVector<RCReference<AsyncValue>> results_storage;
    results_storage.resize(r.size());
    RepeatedArguments<FallbackTensor> operands(o.values());
    RemainingResults results(results_storage);
    if (executable.IsError()) {
      ReturnErrors(results, executable.GetError(), exec_ctx);
    } else {
      ExecuteImpl(*executable, memrefs, operands, results, exec_ctx);
    }
    for (unsigned i = 0; i < r.size(); ++i)
      llvm::cast<IndirectAsyncValue>(*r[i]).ForwardTo(
          std::move(results_storage[i]));
  });
}
static void ExecuteImpl ( JitExecutable & jit_executable , RepeatedArguments < FallbackTensor > operands , RemainingResults results , const ExecutionContext & exec_ctx , bool debug ) { llvm :: SmallVector < MemrefDesc > memrefs ; ConvertTensorOperandsToMemrefDesc ( operands , & memrefs ) ; DebugListener debug_listener ; JitExecutable :: UserData user_data = exec_ctx . request_ctx ( ) ; Expected < AsyncValuePtr < Executable > > executable = jit_executable . GetExecutable ( memrefs , user_data , debug ? & debug_listener : nullptr ) ; if ( LLVM_UNLIKELY ( ! executable ) ) return ReturnErrors ( results , executable . takeError ( ) , exec_ctx ) ; if ( LLVM_LIKELY ( executable -> IsConcrete ( ) ) ) return ExecuteImpl ( executable -> get ( ) , memrefs , operands , results , exec_ctx ) ; if ( LLVM_UNLIKELY ( executable -> IsError ( ) ) ) return ReturnErrors ( results , executable -> GetError ( ) , exec_ctx ) ; for ( unsigned i = 0 ; i < results . size ( ) ; ++ i ) results . AllocateIndirectResultAt ( i ) ; executable -> AndThen ( [ exec_ctx , executable = * executable , memrefs = std :: move ( memrefs ) , r = RCArray < AsyncValue > ( results . values ( ) ) , o = RCArray < AsyncValue > ( operands . values ( ) ) ] { llvm :: SmallVector < RCReference < AsyncValue > > results_storage ; results_storage . resize ( r . size ( ) ) ; RepeatedArguments < FallbackTensor > operands ( o . values ( ) ) ; RemainingResults results ( results_storage ) ; if ( executable . IsError ( ) ) { ReturnErrors ( results , executable . GetError ( ) , exec_ctx ) ; } else { ExecuteImpl ( * executable , memrefs , operands , results , exec_ctx ) ; } for ( unsigned i = 0 ; i < r . size ( ) ; ++ i ) llvm :: cast < IndirectAsyncValue > ( * r [ i ] ) . ForwardTo ( std :: move ( results_storage [ i ] ) ) ; } ) ; }
Gets a specialized Executable async value from the JitExecutable, and then
dispatches it inline or using and-then continuation depending on the async
value state.
Gets a specialized Executable async value from the JitExecutable and then dispatches it inline or using and - then continuation depending on the async value state .
// Convert Tensor operands to memref descriptors. // Get an executable that might be specialized to the operands. // Pass request context to the compilation task runner. // If executable 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 the executable results. // Reconstruct arguments and results from captured async values. // Forward previously allocated indirect results to the actual results.