mlir-hlo/lib/Dialect/mhlo/transforms
Wenyi Zhao 23ebbb28d1 PR #50191: [MLIR][DISC] Add RAL (Runtime abstraction layer) Dialect
Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/50191

DISC is a e2e flow, including both compiler side and runtime side. For
runtime side, we have different targeting environments (e.g. tensorflow,
pytorch, or sometimes even a standalone binary). In order to simplify
the design of the compiler side, we design a Runtime Abstraction Layer
(RAL) to sperate the compiler side and runtime side. Thus the compiler
side only need to target RAL itself and it is the responsibility of RAL
to handle the differences between different targeting environments.

One of the most important functions of RAL is to manage stateful
resources. To this end, it provides a context object, and hides all
stateful operations behind this context, thus the compiler side itself
doesn't need to care about the resource initialization. For example, a
kernel must be loaded before it can be launched on GPU. However, the
loading operation should only be taken once during the whole lifetime of
the context in order to achieve the best performance. Based on the
initialization-free interfaces provided by RAL, compiler side can focus
on its core optimization logic and lets the RAL to manage the resource
status.

The context mentioned above is passed as a parameter to the entry
function and all RAL APIs should always use the context as their first
argument. This CR also provides a pass to help to ensure this property.
The pass rewrites the entry function to make sure their first argument
is the context. For entry function, the pass also rewrites its inputs
and outputs. To be concrete, all the original inputs and outputs of the
entry function are received from and sent to RAL through a sequence of
RAL API calls correspondingly. The motivation behind this is to hide the
implementation details of I/Os. This design may also potentially enable
partial execution of the compiled module when some of the inputs are
ready.
Copybara import of the project:

--
c4f20a89aed71181e75bcc5265723b88bde23240 by Wenyi Zhao <reyizero@gmail.com>:

[MLIR][DISC] Add RAL (Runtime abstraction layer) Dialect

DISC is a e2e flow, including both compiler side and runtime side. For
runtime side, we have different targeting environments (e.g. tensorflow,
pytorch, or sometimes even a standalone binary). In order to simplify
the design of the compiler side, we design a Runtime Abstraction Layer
(RAL) to sperate the compiler side and runtime side. Thus the compiler
side only need to target RAL itself and it is the responsibility of RAL
to handle the differences between different targeting environments.

One of the most important functions of RAL is to manage stateful
resources. To this end, it provides a context object, and hides all
stateful operations behind this context, thus the compiler side itself
doesn't need to care about the resource initialization. For example, a
kernel must be loaded before it can be launched on GPU. However, the
loading operation should only be taken once during the whole lifetime of
the context in order to achieve the best performance. Based on the
initialization-free interfaces provided by RAL, compiler side can focus
on its core optimization logic and lets the RAL to manage the resource
status.

The context mentioned above is passed as a parameter to the entry
function and all RAL APIs should always use the context as their first
argument. This CR also provides a pass to help to ensure this property.
The pass rewrites the entry function to make sure their first argument
is the context. For entry function, the pass also rewrites its inputs
and outputs. To be concrete, all the original inputs and outputs of the
entry function are received from and sent to RAL through a sequence of
RAL API calls correspondingly. The motivation behind this is to hide the
implementation details of I/Os. This design may also potentially enable
partial execution of the compiled module when some of the inputs are
ready.

--
1991d4f80ab6087943956e1c0fec4940a22ab08d by Wenyi Zhao <reyizero@gmail.com>:

fix

PiperOrigin-RevId: 379317586
2021-06-14 11:27:43 -07:00
..
CMakeLists.txt PR #50191: [MLIR][DISC] Add RAL (Runtime abstraction layer) Dialect 2021-06-14 11:27:43 -07:00
broadcast_propagation.cc [MLIR][HLO] Extend broadcast propagation pass to enable more fusion 2021-06-09 03:03:37 -07:00
chlo_legalize_to_hlo.cc Fix Cosh approximation for F16. 2021-06-10 06:16:44 -07:00
chlo_legalize_to_hlo_pass.cc Separate CHLO transforms for expanding compositions and lowering broadcasts. 2021-05-18 13:33:59 -07:00
chlo_legalize_to_hlo_patterns.td Fix Cosh approximation for F16. 2021-06-10 06:16:44 -07:00
hlo_legalize_to_lhlo.cc PR #50211: [MLIR][DISC] Bufferize RealDynamicSliceOp and ReduceOp 2021-06-11 16:33:15 -07:00
legalize_control_flow.cc Allow variadic operands/result in MHLO while 2021-06-11 13:08:28 -07:00
legalize_gather_to_torch_index_select.cc Integrate LLVM at llvm/llvm-project@b24436ac96 2021-03-23 12:20:17 -07:00
legalize_tensor_load_op.cc PR #49598: [MLIR][DISC] legalize tensor_load inserted during hlo-to-lhlo conversion 2021-06-01 16:27:56 -07:00
legalize_to_linalg.cc [MHLO:linalg] Be more aggressive about turning mhlo.const into std.constant 2021-06-07 11:58:23 -07:00
legalize_to_standard.cc Integrate LLVM at llvm/llvm-project@b24436ac96 2021-03-23 12:20:17 -07:00
legalize_to_standard_patterns.td Lowering for mhlo.ceil to std.ceil 2020-08-12 16:15:35 -07:00
legalize_trigonometric_to_approximation.cc Fix tanh lowering for NaN input. 2021-03-24 06:34:36 -07:00
lhlo_fuse_linalg.cc Update lhlo to use the new structured op interface. 2021-06-07 03:11:03 -07:00
lhlo_legalize_to_affine.cc PR #47315: [MLIR] Add concatenateOp lowering from lmhlo to Affine. 2021-04-14 11:06:38 -07:00
lhlo_legalize_to_gpu.cc [MLIR][NFC] Rename ReduceOp operands() => inputs(). 2021-04-14 12:08:23 -07:00
lhlo_legalize_to_parallel_loops.cc [MLIR][NFC] Rename ReduceOp operands() => inputs(). 2021-04-14 12:08:23 -07:00
lower_complex.cc Integrate LLVM at llvm/llvm-project@b24436ac96 2021-03-23 12:20:17 -07:00
lower_complex_patterns.td Generate Equal and NotEqual kernels for complex types. 2021-04-15 00:35:52 -07:00
lower_general_dot.cc Integrate LLVM at llvm/llvm-project@b24436ac96 2021-03-23 12:20:17 -07:00
materialize_broadcasts.cc More cleanup in mlir-hlo to prepare for the standalone build 2020-08-03 19:28:00 -07:00
materialize_broadcasts_pass.cc Integrate LLVM at llvm/llvm-project@b24436ac96 2021-03-23 12:20:17 -07:00
mhlo_control_flow_to_scf.cc Allow variadic operands/result in MHLO while 2021-06-11 13:08:28 -07:00
mhlo_fusion.cc Integrate LLVM at llvm/llvm-project@37e1458128 2021-04-22 22:57:08 -07:00
optimize_mhlo.cc More cleanup in mlir-hlo to prepare for the standalone build 2020-08-03 19:28:00 -07:00
optimize_mhlo_pass.cc Integrate LLVM at llvm/llvm-project@b24436ac96 2021-03-23 12:20:17 -07:00
ral_inject_execution_context.cc PR #50191: [MLIR][DISC] Add RAL (Runtime abstraction layer) Dialect 2021-06-14 11:27:43 -07:00
rank_specialization.cc [MLIR][HLO] Find shape equivalences and use them for better rank specialization 2021-06-11 04:00:26 -07:00
sink_constants_to_control_flow.cc Enable fallback legalization for MaxPoolGradGrad and MaxPool3DGradGrad ops 2020-11-13 13:49:05 -08:00
test_infer_shaped_type_pass.cc [mlir][hlo] Avoid dyn_cast_or_null when called with getDefiningOp result (NFC) 2021-05-27 00:20:42 -07:00
transform_unranked_hlo.cc Replace !any_of with none_of 2021-05-04 01:55:36 -07:00
unfuse_batch_norm.cc Integrate LLVM at llvm/llvm-project@678241795c 2021-03-16 13:33:00 -07:00
unfuse_batch_norm_pass.cc mlir-hlo-opt: set preloadDialectsInContext to false. 2021-03-30 01:07:14 -07:00