#pragma once
#include <ATen/core/dispatch/Dispatcher.h>
-#include "caffe2/core/operator.h"
+#include <ATen/core/ivalue.h>
#include <c10/util/ArrayRef.h>
+#include <c10/util/C++17.h>
#include <c10/util/Metaprogramming.h>
-#include <ATen/core/ivalue.h>
+#include "caffe2/core/operator.h"
namespace caffe2 {
template <class Context>
inline std::function<
std::unique_ptr<OperatorBase>(const OperatorDef&, Workspace*)>
-createC10OperatorWrapper(const c10::OperatorHandle& op_handle) {
- return [op_handle](const OperatorDef& op_def, Workspace* ws) {
+createC10OperatorWrapper(const char* op_name, const char* overload_name) {
+ return [op_name, overload_name](const OperatorDef& op_def, Workspace* ws) {
+ auto op_handle =
+ c10::Dispatcher::singleton().findSchema(op_name, overload_name);
+ AT_ASSERTM(
+ op_handle.has_value(),
+ "Tried to register c10 operator ",
+ op_name,
+ ".",
+ overload_name,
+ " with caffe2, but didn't find the c10 operator.");
return c10::guts::make_unique<C10OperatorWrapper<Context>>(
- op_handle, op_def, ws);
+ *op_handle, op_def, ws);
};
}
#ifndef C10_MOBILE
// TODO Currently we only register the CPU variant. This is going to be fixed
// once the tensor detemplatization lands.
-#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(OperatorHandle, Name) \
- REGISTER_CPU_OPERATOR_CREATOR( \
- Name, detail::createC10OperatorWrapper<CPUContext>(OperatorHandle))
-#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CUDA(OperatorHandle, Name) \
- REGISTER_CUDA_OPERATOR_CREATOR( \
- Name, detail::createC10OperatorWrapper<CUDAContext>(OperatorHandle))
-#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_HIP(OperatorHandle, Name) \
- REGISTER_HIP_OPERATOR_CREATOR( \
- Name, detail::createC10OperatorWrapper<HIPContext>(OperatorHandle))
+#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU( \
+ OperatorName, Name) \
+ REGISTER_CPU_OPERATOR_CREATOR( \
+ Name, \
+ ::caffe2::detail::createC10OperatorWrapper<CPUContext>( \
+ OperatorName, ""))
+#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CUDA( \
+ OperatorName, Name) \
+ REGISTER_CUDA_OPERATOR_CREATOR( \
+ Name, \
+ ::caffe2::detail::createC10OperatorWrapper<CUDAContext>( \
+ OperatorName, ""))
+#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_HIP( \
+ OperatorName, Name) \
+ REGISTER_HIP_OPERATOR_CREATOR( \
+ Name, \
+ ::caffe2::detail::createC10OperatorWrapper<HIPContext>( \
+ OperatorName, ""))
#else
-#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(OperatorHandle, Name)
-#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CUDA(OperatorHandle, Name)
-#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_HIP(OperatorHandle, Name)
+#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU( \
+ OperatorName, Name)
+#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CUDA( \
+ OperatorName, Name)
+#define REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_HIP( \
+ OperatorName, Name)
#endif
} // namespace caffe2
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::Add(),
+ "_c10_experimental::Add",
C10Add_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::AveragedLoss(),
+ "_c10_experimental::AveragedLoss",
C10AveragedLoss_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::BatchGather(),
+ "_c10_experimental::BatchGather",
C10BatchGather_DontUseThisOpYet)
}
}
namespace caffe2 {
-
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::BatchMatmul(),
+ "_c10_experimental::BatchMatmul",
C10BatchMatMul_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::Cast(),
+ "_c10_experimental::Cast",
C10Cast_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::Concat(),
+ "_c10_experimental::Concat",
C10Concat_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::EnforceFinite(),
+ "_c10_experimental::EnforceFinite",
C10EnforceFinite_DontUseThisOpYet)
}
}
namespace caffe2 {
-
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::ExpandDims(),
+ "_c10_experimental::ExpandDims",
C10ExpandDims_DontUseThisOpYet)
}
}
namespace caffe2 {
-
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::FullyConnected(),
+ "_c10_experimental::FullyConnected",
C10FC_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::ConstantFill(),
+ "_c10_experimental::ConstantFill",
C10ConstantFill_DontUseThisOpYet)
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::UniformFill(),
+ "_c10_experimental::UniformFill",
C10UniformFill_DontUseThisOpYet)
-
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::GivenTensorFill(),
+ "_c10_experimental::GivenTensorFill",
C10GivenTensorFill_DontUseThisOpYet)
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::GivenTensorIntFill(),
+ "_c10_experimental::GivenTensorIntFill",
C10GivenTensorIntFill_DontUseThisOpYet)
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::GivenTensorInt64Fill(),
+ "_c10_experimental::GivenTensorInt64Fill",
C10GivenTensorInt64Fill_DontUseThisOpYet)
} // namespace caffe2
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::Flatten(),
+ "_c10_experimental::Flatten",
C10Flatten_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::Mul(),
+ "_c10_experimental::Mul",
C10Mul_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::Relu(),
+ "_c10_experimental::Relu",
C10Relu_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::Sigmoid(),
+ "_c10_experimental::Sigmoid",
C10Sigmoid_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::SigmoidCrossEntropyWithLogits(),
+ "_c10_experimental::SigmoidCrossEntropyWithLogits",
C10SigmoidCrossEntropyWithLogits_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::SparseLengthsSum(),
+ "_c10_experimental::SparseLengthsSum",
C10SparseLengthsSum_DontUseThisOpYet)
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- ops::StopGradient(),
+ "_c10_experimental::StopGradient",
C10StopGradient_DontUseThisOpYet)
}
#include "caffe2/operators/layer_norm_op.h"
-#include <ATen/core/dispatch/KernelRegistration.h>
-#include <ATen/core/dispatch/OpSchemaRegistration.h>
#include <c10/core/Tensor.h>
#include "caffe2/core/operator_c10wrapper.h"
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CPU(
- _c10_ops::LayerNorm(),
+ "_caffe2::LayerNorm",
C10LayerNorm_DontUseThisOpYet);
}
namespace caffe2 {
REGISTER_C10_OPERATOR_FOR_CAFFE2_DISPATCH_CUDA(
- _c10_ops::LayerNorm(),
+ "_caffe2::LayerNorm",
C10LayerNorm_DontUseThisOpYet);
}
#include <array>
#include <vector>
-#include <ATen/core/dispatch/OpSchemaRegistration.h>
-
#include "caffe2/core/context.h"
#include "caffe2/core/operator.h"
#include "caffe2/core/types.h"