2020-09-26 09:13:16 +08:00
|
|
|
//===- acap_dispatch.h ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// This file is licensed under a pytorch-style license
|
|
|
|
// See frontends/pytorch/LICENSE for license information.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// "ATen Capture" dispatcher: Defines facility for capturing programs by
|
|
|
|
// registering dispatch keys to intercept op execution.
|
|
|
|
// References:
|
|
|
|
// http://blog.ezyang.com/2020/09/lets-talk-about-the-pytorch-dispatcher/
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-11-13 14:27:05 +08:00
|
|
|
#ifndef NPCOMP_FRONTENDS_PYTORCH_CSRC_BUILDER_ACAP_DISPATCH_H
|
|
|
|
#define NPCOMP_FRONTENDS_PYTORCH_CSRC_BUILDER_ACAP_DISPATCH_H
|
2020-09-29 09:36:00 +08:00
|
|
|
|
2020-09-26 09:13:16 +08:00
|
|
|
#include <list>
|
|
|
|
#include <memory>
|
|
|
|
|
2020-10-02 09:59:58 +08:00
|
|
|
#include "../pybind.h"
|
|
|
|
|
|
|
|
#include "func_builder.h"
|
2020-09-26 09:13:16 +08:00
|
|
|
|
2020-09-29 09:36:00 +08:00
|
|
|
#include "mlir-c/IR.h"
|
|
|
|
|
2020-09-26 09:13:16 +08:00
|
|
|
#include <ATen/core/dispatch/Dispatcher.h>
|
2020-10-06 14:21:21 +08:00
|
|
|
#include <ATen/core/ivalue.h>
|
2020-09-26 09:13:16 +08:00
|
|
|
#include <c10/core/impl/LocalDispatchKeySet.h>
|
|
|
|
|
|
|
|
namespace torch_mlir {
|
|
|
|
|
|
|
|
/// Main entry point for managing device capture.
|
|
|
|
class AcapController : public std::enable_shared_from_this<AcapController> {
|
|
|
|
public:
|
2020-10-06 14:21:21 +08:00
|
|
|
AcapController(TypeMapper &typeMapper,
|
|
|
|
std::unique_ptr<FuncBuilder> funcBuilder)
|
|
|
|
: typeMapper(typeMapper), funcBuilder(std::move(funcBuilder)) {}
|
2020-09-26 09:13:16 +08:00
|
|
|
|
|
|
|
// Enter and exit the context manager.
|
|
|
|
pybind11::object contextEnter();
|
|
|
|
void contextExit(pybind11::object exc_type, pybind11::object exc_val,
|
|
|
|
pybind11::object exc_tb);
|
|
|
|
|
2020-10-06 14:21:21 +08:00
|
|
|
// Terminates capture and returns tensors from the function.
|
|
|
|
void returns(std::vector<at::Tensor> tensors);
|
|
|
|
|
2020-09-26 09:13:16 +08:00
|
|
|
// Returns the current AcapController (if it has been activated on this
|
2020-10-19 12:32:29 +08:00
|
|
|
// thread. Returns nullptr if none (not active on the current thread).
|
|
|
|
static std::shared_ptr<AcapController> getCurrentThreadAcapController();
|
2020-09-26 09:13:16 +08:00
|
|
|
|
|
|
|
// The fallback boxed kernel that we route captured dispatches through.
|
|
|
|
static void fallbackKernel(const c10::OperatorHandle &opHandle,
|
|
|
|
c10::Stack *stack);
|
|
|
|
|
2020-10-19 12:32:29 +08:00
|
|
|
// Kernel implementation for the boxing-incompatible convolution kernel.
|
|
|
|
static at::Tensor
|
|
|
|
convolutionKernel(const at::Tensor &input, const at::Tensor &weight,
|
|
|
|
const c10::optional<at::Tensor> &bias,
|
|
|
|
const at::IntArrayRef stride, const at::IntArrayRef padding,
|
|
|
|
const at::IntArrayRef dilation, const bool transposed,
|
|
|
|
const at::IntArrayRef output_padding, const int64_t groups);
|
|
|
|
|
2020-10-31 13:52:46 +08:00
|
|
|
// Kernel implementation for the boxing-incompatible convolution kernel.
|
|
|
|
static std::tuple<at::Tensor, at::Tensor, at::Tensor> mklConvolutionBackward(
|
|
|
|
const at::Tensor &input, const at::Tensor &grad_output,
|
|
|
|
const at::Tensor &weight, const at::IntArrayRef padding,
|
|
|
|
const at::IntArrayRef stride, const at::IntArrayRef dilation,
|
|
|
|
const int64_t groups, std::array<bool, 3> output_mask);
|
|
|
|
|
|
|
|
// Implementation for the aten::copy_ kernel.
|
|
|
|
static at::Tensor ©UnderKernel(at::Tensor &self, const at::Tensor &src,
|
|
|
|
bool non_blocking);
|
|
|
|
|
2020-11-13 09:42:19 +08:00
|
|
|
// Backend select kernel for arange factory function.
|
2021-03-19 06:43:45 +08:00
|
|
|
static at::Tensor arangeBackendSelectKernel(
|
|
|
|
const at::Scalar &end, c10::optional<at::ScalarType> dtype,
|
|
|
|
c10::optional<at::Layout> layout, c10::optional<at::Device> device,
|
|
|
|
c10::optional<bool> pin_memory);
|
2020-11-13 09:42:19 +08:00
|
|
|
|
2020-09-26 09:13:16 +08:00
|
|
|
private:
|
Significantly restructure torch/aten import design.
This is a really major and invasive restructuring of the way we get
torch operators (`torch::jit::Operator` / `c10::OperatorHandle`) into
MLIR. Please forgive the challenging review, but due to the sheer
invasiveness, it wasn't really practical do do it in sane smaller
pieces.
This fully replaces everything that was already working on the
TorchScript path (actually, more -- we added tanh support to
TorchToLinalg in order to delete the older code paths). Additionally,
I've kept the lights on for the acap path too, including what little e2e
stuff was working before (for expediency I made a few tiny compromises
along the way that will be easy to undo when we give that path proper
attention).
Overview of the new design:
- The torch operator `somens::someunqualname.someoverloadname` is
imported as `torch.somens.someunqualname.someoverloadname` (skip the
last dotted part if the overload name is empty), OR, if we don't have
such an op registered, it is imported as
`torch.operator "somens.someunqualname.someoverloadname" (...) : ...`.
- The addition of the "overload name" is a critical element here, as
the `(ns,unqual,overload)` triple is unique, which solves a lot of
problems we were having.
- This involves having separate MLIR ops for the `trailing_` and
`.out` variants and all the different overloads. This seemed
necessary, because the set of overloads is so wild and varied and
unstructured. The previous design was leaning into some underlying
structure that just isn't there -- the default situation is
the "random overload that we want to manage on the MLIR side",
rather than that being an exception. E.g. `aten::ne` (not-equal)
has 21 overloads, only 4 of which are c10 dispatcher ops see
[gist](https://gist.github.com/silvasean/190ba918c550c956260e21254e1b8aa1),
and the "out" variant is really called `.Tensor_out` instead of
`.out` as it frequently is for other ops.
- Rationale for all being in `torch` namespace: the set of operators
are so varied and unstructured that "dialect per namespace"
doesn't result in anything resembling the typical MLIR dialect
boundary expectations. We could maybe draw the boundary at
dispatcher ops vs non-dispatcher ops, but that doesn't seem to
really result in very much useful structure at this point in time.
- Note: within the torch operator registry, we effectively have a
mini-basicpy subdialect (already type-resolved), which is reasonably
structured.
- The existing Torch op interfaces are also removed -- now that we
track the overload name, we can losslessly find the original
operator.
- Instead of `ATenRecognizeKernelsPass`, we now have a
`ReduceOpVariantsPass` that keys off certain traits (and perhaps
eventually interfaces) to reduce variants of ops to a smaller set,
ideally operating on immutable tensors and using surrounding ops to
model the mutability/aliasing aspects.
- Note: `torch.ns.unqual.overload` ops allow both immutable and
mutable tensors (unlike the previous hard distinction in the common
case). This is a premonition for a future change that will introduce a
bona fide `!torch.tensor` type that will clean up a bunch of stuff.
- `TorchToLinalg` / `TorchToStd` supercede the existing
"ATen->TCF->TCP->Linalg" path.
- The new `torch_ods_gen.py` supercedes `torch_signature_ods_gen.py`.
It should look somewhat familiar, but the benefit of hindsight has
allowed a lot of simplifications.
The overall trend seems to be to make the `torch` dialect a nice layer
independent of anything else. It feels like as a natural result of
various future changes we will be removing the reliance on basicpy+numpy
dialects and have a nice self-contained type system too that properly
models the TorchScript type system (including proper subtyping,
mutable/immutable tensors, optional dtype, etc.).
Recommended review order:
- Start at some of the new import IR, e.g. in
`frontends/pytorch/test/node_import/prim.py`,
`frontends/pytorch/test/acap_export/test_export_add3.py`, and other
tests.
- `frontends/pytorch/python/torch_mlir_utils/codegen/torch_ods_gen.py`
and associated generated files:
- `include/npcomp/Dialect/Torch/IR/GeneratedAtenOps.td`
- `include/npcomp/Dialect/Torch/IR/GeneratedPrimOps.td`
- Inspect `ReduceOpVariants.cpp` / `reduce-op-variants.mlir` and the new
traits in `include/npcomp/Dialect/Torch/IR/TorchTraits.h`
- Various code changes in the import path in
`frontends/pytorch/csrc/builder`. Probably most interesting is the new
code in `torch_to_mlir_utils.cpp` that has the logic to create the
`torch.operator` ops or `torch.ns.unqual.overload` ops.
This is the [new ResNet IR](https://gist.github.com/silvasean/5407aafb710d07612b7b5b92eabecebe),
just to be able to look at a substantial sample of IR in the new style.
2021-05-05 05:42:50 +08:00
|
|
|
/// Builds an MLIR operation for a Torch operator step by step.
|
|
|
|
class TracedSchemaOpBuilder {
|
2020-10-19 12:32:29 +08:00
|
|
|
public:
|
Significantly restructure torch/aten import design.
This is a really major and invasive restructuring of the way we get
torch operators (`torch::jit::Operator` / `c10::OperatorHandle`) into
MLIR. Please forgive the challenging review, but due to the sheer
invasiveness, it wasn't really practical do do it in sane smaller
pieces.
This fully replaces everything that was already working on the
TorchScript path (actually, more -- we added tanh support to
TorchToLinalg in order to delete the older code paths). Additionally,
I've kept the lights on for the acap path too, including what little e2e
stuff was working before (for expediency I made a few tiny compromises
along the way that will be easy to undo when we give that path proper
attention).
Overview of the new design:
- The torch operator `somens::someunqualname.someoverloadname` is
imported as `torch.somens.someunqualname.someoverloadname` (skip the
last dotted part if the overload name is empty), OR, if we don't have
such an op registered, it is imported as
`torch.operator "somens.someunqualname.someoverloadname" (...) : ...`.
- The addition of the "overload name" is a critical element here, as
the `(ns,unqual,overload)` triple is unique, which solves a lot of
problems we were having.
- This involves having separate MLIR ops for the `trailing_` and
`.out` variants and all the different overloads. This seemed
necessary, because the set of overloads is so wild and varied and
unstructured. The previous design was leaning into some underlying
structure that just isn't there -- the default situation is
the "random overload that we want to manage on the MLIR side",
rather than that being an exception. E.g. `aten::ne` (not-equal)
has 21 overloads, only 4 of which are c10 dispatcher ops see
[gist](https://gist.github.com/silvasean/190ba918c550c956260e21254e1b8aa1),
and the "out" variant is really called `.Tensor_out` instead of
`.out` as it frequently is for other ops.
- Rationale for all being in `torch` namespace: the set of operators
are so varied and unstructured that "dialect per namespace"
doesn't result in anything resembling the typical MLIR dialect
boundary expectations. We could maybe draw the boundary at
dispatcher ops vs non-dispatcher ops, but that doesn't seem to
really result in very much useful structure at this point in time.
- Note: within the torch operator registry, we effectively have a
mini-basicpy subdialect (already type-resolved), which is reasonably
structured.
- The existing Torch op interfaces are also removed -- now that we
track the overload name, we can losslessly find the original
operator.
- Instead of `ATenRecognizeKernelsPass`, we now have a
`ReduceOpVariantsPass` that keys off certain traits (and perhaps
eventually interfaces) to reduce variants of ops to a smaller set,
ideally operating on immutable tensors and using surrounding ops to
model the mutability/aliasing aspects.
- Note: `torch.ns.unqual.overload` ops allow both immutable and
mutable tensors (unlike the previous hard distinction in the common
case). This is a premonition for a future change that will introduce a
bona fide `!torch.tensor` type that will clean up a bunch of stuff.
- `TorchToLinalg` / `TorchToStd` supercede the existing
"ATen->TCF->TCP->Linalg" path.
- The new `torch_ods_gen.py` supercedes `torch_signature_ods_gen.py`.
It should look somewhat familiar, but the benefit of hindsight has
allowed a lot of simplifications.
The overall trend seems to be to make the `torch` dialect a nice layer
independent of anything else. It feels like as a natural result of
various future changes we will be removing the reliance on basicpy+numpy
dialects and have a nice self-contained type system too that properly
models the TorchScript type system (including proper subtyping,
mutable/immutable tensors, optional dtype, etc.).
Recommended review order:
- Start at some of the new import IR, e.g. in
`frontends/pytorch/test/node_import/prim.py`,
`frontends/pytorch/test/acap_export/test_export_add3.py`, and other
tests.
- `frontends/pytorch/python/torch_mlir_utils/codegen/torch_ods_gen.py`
and associated generated files:
- `include/npcomp/Dialect/Torch/IR/GeneratedAtenOps.td`
- `include/npcomp/Dialect/Torch/IR/GeneratedPrimOps.td`
- Inspect `ReduceOpVariants.cpp` / `reduce-op-variants.mlir` and the new
traits in `include/npcomp/Dialect/Torch/IR/TorchTraits.h`
- Various code changes in the import path in
`frontends/pytorch/csrc/builder`. Probably most interesting is the new
code in `torch_to_mlir_utils.cpp` that has the logic to create the
`torch.operator` ops or `torch.ns.unqual.overload` ops.
This is the [new ResNet IR](https://gist.github.com/silvasean/5407aafb710d07612b7b5b92eabecebe),
just to be able to look at a substantial sample of IR in the new style.
2021-05-05 05:42:50 +08:00
|
|
|
TracedSchemaOpBuilder(AcapController &parent, MlirContext context,
|
|
|
|
MlirLocation loc,
|
|
|
|
const c10::OperatorHandle &opHandle);
|
2020-10-19 12:32:29 +08:00
|
|
|
void addOperand(const c10::IValue &value);
|
|
|
|
void addResult(const c10::IValue &result);
|
|
|
|
MlirOperation create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
AcapController &parent;
|
Significantly restructure torch/aten import design.
This is a really major and invasive restructuring of the way we get
torch operators (`torch::jit::Operator` / `c10::OperatorHandle`) into
MLIR. Please forgive the challenging review, but due to the sheer
invasiveness, it wasn't really practical do do it in sane smaller
pieces.
This fully replaces everything that was already working on the
TorchScript path (actually, more -- we added tanh support to
TorchToLinalg in order to delete the older code paths). Additionally,
I've kept the lights on for the acap path too, including what little e2e
stuff was working before (for expediency I made a few tiny compromises
along the way that will be easy to undo when we give that path proper
attention).
Overview of the new design:
- The torch operator `somens::someunqualname.someoverloadname` is
imported as `torch.somens.someunqualname.someoverloadname` (skip the
last dotted part if the overload name is empty), OR, if we don't have
such an op registered, it is imported as
`torch.operator "somens.someunqualname.someoverloadname" (...) : ...`.
- The addition of the "overload name" is a critical element here, as
the `(ns,unqual,overload)` triple is unique, which solves a lot of
problems we were having.
- This involves having separate MLIR ops for the `trailing_` and
`.out` variants and all the different overloads. This seemed
necessary, because the set of overloads is so wild and varied and
unstructured. The previous design was leaning into some underlying
structure that just isn't there -- the default situation is
the "random overload that we want to manage on the MLIR side",
rather than that being an exception. E.g. `aten::ne` (not-equal)
has 21 overloads, only 4 of which are c10 dispatcher ops see
[gist](https://gist.github.com/silvasean/190ba918c550c956260e21254e1b8aa1),
and the "out" variant is really called `.Tensor_out` instead of
`.out` as it frequently is for other ops.
- Rationale for all being in `torch` namespace: the set of operators
are so varied and unstructured that "dialect per namespace"
doesn't result in anything resembling the typical MLIR dialect
boundary expectations. We could maybe draw the boundary at
dispatcher ops vs non-dispatcher ops, but that doesn't seem to
really result in very much useful structure at this point in time.
- Note: within the torch operator registry, we effectively have a
mini-basicpy subdialect (already type-resolved), which is reasonably
structured.
- The existing Torch op interfaces are also removed -- now that we
track the overload name, we can losslessly find the original
operator.
- Instead of `ATenRecognizeKernelsPass`, we now have a
`ReduceOpVariantsPass` that keys off certain traits (and perhaps
eventually interfaces) to reduce variants of ops to a smaller set,
ideally operating on immutable tensors and using surrounding ops to
model the mutability/aliasing aspects.
- Note: `torch.ns.unqual.overload` ops allow both immutable and
mutable tensors (unlike the previous hard distinction in the common
case). This is a premonition for a future change that will introduce a
bona fide `!torch.tensor` type that will clean up a bunch of stuff.
- `TorchToLinalg` / `TorchToStd` supercede the existing
"ATen->TCF->TCP->Linalg" path.
- The new `torch_ods_gen.py` supercedes `torch_signature_ods_gen.py`.
It should look somewhat familiar, but the benefit of hindsight has
allowed a lot of simplifications.
The overall trend seems to be to make the `torch` dialect a nice layer
independent of anything else. It feels like as a natural result of
various future changes we will be removing the reliance on basicpy+numpy
dialects and have a nice self-contained type system too that properly
models the TorchScript type system (including proper subtyping,
mutable/immutable tensors, optional dtype, etc.).
Recommended review order:
- Start at some of the new import IR, e.g. in
`frontends/pytorch/test/node_import/prim.py`,
`frontends/pytorch/test/acap_export/test_export_add3.py`, and other
tests.
- `frontends/pytorch/python/torch_mlir_utils/codegen/torch_ods_gen.py`
and associated generated files:
- `include/npcomp/Dialect/Torch/IR/GeneratedAtenOps.td`
- `include/npcomp/Dialect/Torch/IR/GeneratedPrimOps.td`
- Inspect `ReduceOpVariants.cpp` / `reduce-op-variants.mlir` and the new
traits in `include/npcomp/Dialect/Torch/IR/TorchTraits.h`
- Various code changes in the import path in
`frontends/pytorch/csrc/builder`. Probably most interesting is the new
code in `torch_to_mlir_utils.cpp` that has the logic to create the
`torch.operator` ops or `torch.ns.unqual.overload` ops.
This is the [new ResNet IR](https://gist.github.com/silvasean/5407aafb710d07612b7b5b92eabecebe),
just to be able to look at a substantial sample of IR in the new style.
2021-05-05 05:42:50 +08:00
|
|
|
MlirLocation loc;
|
2020-10-23 14:31:34 +08:00
|
|
|
const c10::OperatorHandle &opHandle;
|
Significantly restructure torch/aten import design.
This is a really major and invasive restructuring of the way we get
torch operators (`torch::jit::Operator` / `c10::OperatorHandle`) into
MLIR. Please forgive the challenging review, but due to the sheer
invasiveness, it wasn't really practical do do it in sane smaller
pieces.
This fully replaces everything that was already working on the
TorchScript path (actually, more -- we added tanh support to
TorchToLinalg in order to delete the older code paths). Additionally,
I've kept the lights on for the acap path too, including what little e2e
stuff was working before (for expediency I made a few tiny compromises
along the way that will be easy to undo when we give that path proper
attention).
Overview of the new design:
- The torch operator `somens::someunqualname.someoverloadname` is
imported as `torch.somens.someunqualname.someoverloadname` (skip the
last dotted part if the overload name is empty), OR, if we don't have
such an op registered, it is imported as
`torch.operator "somens.someunqualname.someoverloadname" (...) : ...`.
- The addition of the "overload name" is a critical element here, as
the `(ns,unqual,overload)` triple is unique, which solves a lot of
problems we were having.
- This involves having separate MLIR ops for the `trailing_` and
`.out` variants and all the different overloads. This seemed
necessary, because the set of overloads is so wild and varied and
unstructured. The previous design was leaning into some underlying
structure that just isn't there -- the default situation is
the "random overload that we want to manage on the MLIR side",
rather than that being an exception. E.g. `aten::ne` (not-equal)
has 21 overloads, only 4 of which are c10 dispatcher ops see
[gist](https://gist.github.com/silvasean/190ba918c550c956260e21254e1b8aa1),
and the "out" variant is really called `.Tensor_out` instead of
`.out` as it frequently is for other ops.
- Rationale for all being in `torch` namespace: the set of operators
are so varied and unstructured that "dialect per namespace"
doesn't result in anything resembling the typical MLIR dialect
boundary expectations. We could maybe draw the boundary at
dispatcher ops vs non-dispatcher ops, but that doesn't seem to
really result in very much useful structure at this point in time.
- Note: within the torch operator registry, we effectively have a
mini-basicpy subdialect (already type-resolved), which is reasonably
structured.
- The existing Torch op interfaces are also removed -- now that we
track the overload name, we can losslessly find the original
operator.
- Instead of `ATenRecognizeKernelsPass`, we now have a
`ReduceOpVariantsPass` that keys off certain traits (and perhaps
eventually interfaces) to reduce variants of ops to a smaller set,
ideally operating on immutable tensors and using surrounding ops to
model the mutability/aliasing aspects.
- Note: `torch.ns.unqual.overload` ops allow both immutable and
mutable tensors (unlike the previous hard distinction in the common
case). This is a premonition for a future change that will introduce a
bona fide `!torch.tensor` type that will clean up a bunch of stuff.
- `TorchToLinalg` / `TorchToStd` supercede the existing
"ATen->TCF->TCP->Linalg" path.
- The new `torch_ods_gen.py` supercedes `torch_signature_ods_gen.py`.
It should look somewhat familiar, but the benefit of hindsight has
allowed a lot of simplifications.
The overall trend seems to be to make the `torch` dialect a nice layer
independent of anything else. It feels like as a natural result of
various future changes we will be removing the reliance on basicpy+numpy
dialects and have a nice self-contained type system too that properly
models the TorchScript type system (including proper subtyping,
mutable/immutable tensors, optional dtype, etc.).
Recommended review order:
- Start at some of the new import IR, e.g. in
`frontends/pytorch/test/node_import/prim.py`,
`frontends/pytorch/test/acap_export/test_export_add3.py`, and other
tests.
- `frontends/pytorch/python/torch_mlir_utils/codegen/torch_ods_gen.py`
and associated generated files:
- `include/npcomp/Dialect/Torch/IR/GeneratedAtenOps.td`
- `include/npcomp/Dialect/Torch/IR/GeneratedPrimOps.td`
- Inspect `ReduceOpVariants.cpp` / `reduce-op-variants.mlir` and the new
traits in `include/npcomp/Dialect/Torch/IR/TorchTraits.h`
- Various code changes in the import path in
`frontends/pytorch/csrc/builder`. Probably most interesting is the new
code in `torch_to_mlir_utils.cpp` that has the logic to create the
`torch.operator` ops or `torch.ns.unqual.overload` ops.
This is the [new ResNet IR](https://gist.github.com/silvasean/5407aafb710d07612b7b5b92eabecebe),
just to be able to look at a substantial sample of IR in the new style.
2021-05-05 05:42:50 +08:00
|
|
|
std::vector<MlirValue> operands;
|
|
|
|
std::vector<MlirType> resultTypes;
|
2020-10-19 12:32:29 +08:00
|
|
|
int resultCount = 0;
|
2020-12-15 00:42:42 +08:00
|
|
|
std::vector<std::pair<size_t, at::Tensor>> resultIndexToTensorMap;
|
2020-10-19 12:32:29 +08:00
|
|
|
};
|
|
|
|
|
2020-10-16 09:28:30 +08:00
|
|
|
MlirLocation getCurrentLocation();
|
2020-10-06 14:21:21 +08:00
|
|
|
void redispatch(const c10::OperatorHandle &opHandle, c10::Stack *stack);
|
|
|
|
void fallbackKernelImpl(const c10::OperatorHandle &opHandle,
|
2020-11-13 09:42:19 +08:00
|
|
|
c10::Stack *stack,
|
|
|
|
std::function<void()> redispatchCallback);
|
2020-10-19 12:32:29 +08:00
|
|
|
MlirValue mapIValueToMlirValue(MlirLocation loc, const c10::IValue &ival);
|
|
|
|
MlirType mapIValueToMlirType(MlirLocation loc, const c10::IValue &ival);
|
2020-10-16 09:28:30 +08:00
|
|
|
/// Imports a tensor by value (as a constant), remembering the association.
|
|
|
|
MlirValue importTensorByValue(at::Tensor tensor);
|
2020-10-06 14:21:21 +08:00
|
|
|
void verifyHasNotReturned();
|
2020-09-26 09:13:16 +08:00
|
|
|
struct Activation {
|
|
|
|
Activation(std::shared_ptr<AcapController> controller)
|
|
|
|
: controller(std::move(controller)) {}
|
|
|
|
std::shared_ptr<AcapController> controller;
|
|
|
|
// The RAII dispatch key guard is not movable, so heap allocate it. This is
|
|
|
|
// a bit outside of its intended design, but since this is thread local as
|
|
|
|
// well, it should be fine.
|
2020-10-19 12:32:29 +08:00
|
|
|
std::unique_ptr<c10::impl::IncludeDispatchKeyGuard> includeGuard;
|
|
|
|
std::unique_ptr<c10::impl::ExcludeDispatchKeyGuard> excludeGuard;
|
2020-09-26 09:13:16 +08:00
|
|
|
};
|
|
|
|
// Gets the thread local stack of active acap controllers.
|
|
|
|
static std::list<Activation> &getThreadLocalActiveStack();
|
2020-09-29 09:36:00 +08:00
|
|
|
|
2020-10-06 14:21:21 +08:00
|
|
|
TypeMapper &typeMapper;
|
2020-10-02 09:59:58 +08:00
|
|
|
std::unique_ptr<FuncBuilder> funcBuilder;
|
2020-10-06 14:21:21 +08:00
|
|
|
bool hasReturned = false;
|
2020-09-26 09:13:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace torch_mlir
|
2020-09-29 09:36:00 +08:00
|
|
|
|
|
|
|
#endif // NPCOMP_FRONTENDS_PYTORCH_CSRC_C10_DISPATCH_ACAP_DISPATCH_H
|