Caffe2: crash op (#18207)
authorAlexander Sidorov <salex@fb.com>
Fri, 22 Mar 2019 18:49:04 +0000 (11:49 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 22 Mar 2019 18:52:01 +0000 (11:52 -0700)
Summary:
this is handy when testing various core dump related
things. If in the future we want to unit test our future gdb debugger
extensions, we can use this op to generate a core dump for us within a
unit test.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18207

Differential Revision: D14482186

Pulled By: salexspb

fbshipit-source-id: 39a9fffbdd4bd083597f544d1c783a82cf023a89

caffe2/operators/crash_op.cc [new file with mode: 0644]

diff --git a/caffe2/operators/crash_op.cc b/caffe2/operators/crash_op.cc
new file mode 100644 (file)
index 0000000..a7bb9b1
--- /dev/null
@@ -0,0 +1,25 @@
+#if defined(__linux__)
+
+#include "caffe2/core/context.h"
+#include "caffe2/core/operator.h"
+
+namespace caffe2 {
+
+class CrashOp final : public Operator<CPUContext> {
+ public:
+  CrashOp(const OperatorDef& operator_def, Workspace* ws)
+      : Operator<CPUContext>(operator_def, ws) {}
+
+  bool RunOnDevice() override {
+    raise(SIGABRT);
+    return true;
+  }
+};
+
+OPERATOR_SCHEMA(Crash).NumInputs(0).NumOutputs(0).SetDoc(
+    R"DOC(Crashes the program. Use for testing)DOC");
+
+REGISTER_CPU_OPERATOR(Crash, CrashOp);
+
+} // namespace caffe2
+#endif