← Back to Pull requests

an extension that adds a device side abort function #808

Open
pjaaskel opened this pull request with 766 lines diff across 2 files
View on GitHub
pjaaskel pjaaskel commented on Jun 21, 2022 12:11 UTC
Author

With the device side abort extension, a work-item (WI) can return from the kernel execution at any point and cause abnormal unrecoverable termination of the host process.

This extension differs from the cl_arm_controlled_kernel_termination extension in that the abort in the device side is expected to behave like a call to the POSIX abort() in the host side, terminating also the host process immediately.

The extension is meant to easily support POSIX abort()-like functionality on the device side, as well as serve as a basis for CUDA/HIP-style assertions.

An example CPU implementation in PoCL: https://github.com/parmance/pocl/commit/d5e88c700889be4b1296faf4a261810580829d1b

Diff: 766 lines (+766 / -0) across 2 files Reviewer: karolherbst Review duration: 2277071m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.51) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.51 · 766 lines diff across 2 files
0.51
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 5 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
89%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.397
Real PR Conversation Timeline
19 items
Kerilk Kerilk commented on Jul 12, 2022 17:12 UTC
Contributor

Here is the accompanying SPIRV extension:
https://github.com/KhronosGroup/SPIRV-Registry/pull/149

bashbaug bashbaug commented on Sep 22, 2022 00:41 UTC
Contributor

Discussed in the September 20th teleconference:

Use-case: similar to __trap() in CUDA.
There are several similar proposals and it would be nice to consolidate into an EXT extension (this PR).
There is a related SPIR-V extension (linked above) but it has not been implemented (yet).
As-written, the extension will terminate the entire process when a device kernel calls the abort function.
There could be use-cases that aren't as catastrophic. Do we want to support recovery, and if so, how recoverable can we be?
For example, how does calling abort affect other work-items or work-groups that may be executing? How does calling abort affect other commands in the command-queue that may be dependent on the aborted command?

pjaaskel pjaaskel commented on Sep 22, 2022 07:33 UTC
Author

There could be use-cases that aren't as catastrophic. Do we want to support recovery, and if so, how recoverable can we be?

Like I suggested in the call, I think these are two different use cases which could call for separate extensions to not make it too difficult to support only one of them. The primary use case for this simple one is to be part of an assert() implementation: To allow more easy porting (even automated migration) of host functions that have asserts() or abort() calls to device-side executed code.

For example, how does calling abort affect other work-items or work-groups that may be executing? How does calling abort affect other commands in the command-queue that may be dependent on the aborted command?

In this extension, the expected behavior for commands is the same as with any multithreaded program where one thread calls the standard abort(). Other parallel threads (commands) might have proceeded further or not, but the end result is either catching SIGABRT or brutally killing the process along with its threads (in this case also device/GPU threads).

The WI semantics I tried to describe in the last paragraph: https://github.com/KhronosGroup/OpenCL-Docs/pull/808/files#diff-149e893d23663ca01188af6d03a0ebd77bae5776abefe7ec6b063e4bbd88212fR103

bashbaug bashbaug commented on Dec 17, 2024 19:23 UTC
Contributor

Discussed in the December 17th teleconference. Some of this functionality appears to be implemented in Mesa:

https://www.phoronix.com/news/OpenCL-C-Std-Lib-Mesa-25.0
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32529

We should see what it would take to get this across the finish line.

pjaaskel pjaaskel commented on Jul 24, 2025 14:51 UTC
Author

@karolherbst do you have feedback on this from the perspective of Mesa/Rusticl?

karolherbst karolherbst commented on code on Jul 24, 2025 17:28 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.

Unsure to be honest. I think it's a good idea in principle, but it does change certain implementation details. Like if a thread calling abort_platform causes a dead-lock, it might lead to a kernel driver to timeout the GPU job and that alone is undefined behavior, not just "undefined results".

Some implementations might just not be able to terminate the running kernel without undefined behavior. But now this extension actually defines it: it needs to terminate at some point.

I think calling abort_platform in itself causes undefined behavior and runtimes can only guarantee anything that happens afterwards on a best effort basis.

karolherbst karolherbst commented on code on Jul 24, 2025 17:34 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.
+
+The control flow behavior within the work-group of a kernel command with
+a WI that called the device side abort is the same as immediately
+returning from the kernel for the abort-calling WI at the abort call site.
+For possible WIs that do not call abort, the return time is undefined and can
+adhere to the original control flow of the kernel as long as all the WIs
+eventually finish the execution and allow the host runtime to abort the
+process also in a single-threaded/non-interrupting implementation.

The phrasing here is a bit hard to grasp what's actually meant.

Assuming we have control flow that is well defined with all threads participating, but now a single thread calls abort_platform and quits. If that causes an infinite loop an implementation might be able to guarantee that "the return time is undefined and can adhere to the original control flow of the kernel", however, this extension specifies that an implementation is only allowed of doing so "as long as all the WIs eventually finish the execution and allow the host runtime to abort the process", but what if they can't, because the one thread is causing issues?

Is it legal for an implementation to time out the kernel invocation, which might even cause system level problems, like a full GPU reset or even worse, a system reboot, in which case you won't get to see any printf buffer's contents?

pjaaskel pjaaskel commented on code on Jul 25, 2025 07:48 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.

The basis for this extension's semantics are the one of libc's abort() and the __trap() of CUDA. It would be useful to be able to implement both of those with this extension.

I'm not sure what CUDA's "generate an interrupt to the host CPU" should imply, but to me the natural semantics here is to abort the whole (host) process and bring down the GPU resources, similar to killing a threaded CPU-only host application with multiple threads running and one of them calling abort().

pjaaskel pjaaskel commented on code on Jul 25, 2025 07:56 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.
+
+The control flow behavior within the work-group of a kernel command with
+a WI that called the device side abort is the same as immediately
+returning from the kernel for the abort-calling WI at the abort call site.
+For possible WIs that do not call abort, the return time is undefined and can
+adhere to the original control flow of the kernel as long as all the WIs
+eventually finish the execution and allow the host runtime to abort the
+process also in a single-threaded/non-interrupting implementation.

You are right. This paragraph is in a conflict with the ability to abort kernel commands that have deadlocked (partial barrier reach or other reason). I think it could be just removed while fulfilling the goal of being able to implement libc abort and CUDA trap.

karolherbst karolherbst commented on code on Jul 25, 2025 11:50 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.

Right, I'm not concerned about Nvidia being able to reliably implement such a functionality, I'm more concerned about giving too strong guarantees for all the other GPU hardware out there. Nvidia has a BPT instruction which can create a trap signal that is either handled by a GPU queue configured trap handler (used to implement a debugger, e.g. single-stepping) or raised to the OS. So the OS can just handle that signal and deal with it by e.g. forcing a termination of the running workload.

I'm not sure every other GPU vendor has something similar. Maybe it's good enough to make the behavior after abort_platform implementation defined, but urge every implementation to at least try to guarantee the things mandated by this extension?

pjaaskel pjaaskel commented on code on Jul 28, 2025 08:13 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.

I'd rather see well-defined behavior and if the device cannot support it, then it just doesn't advertise support for the extension. My guess is that both AMD and Intel have some sort of features that could be used to implement the "canceling" of the GPU workload when signaled by the device side program (e.g. via a system shared global variable), even in presence of kernel deadlocks.

karolherbst karolherbst commented on code on Jul 28, 2025 09:18 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.

AMD has a pretty aggressive way of dealing with GPU side timeouts, which often lead to full GPU resets impacting other parts of the system, e.g. your desktop session could also just die.

I'm sure Intel will manage, I have my doubts about AMD guaranteeing no abnormal behavior of the system after abort_platform causes dead-locks, invalid memory accesses, etc...

pjaaskel pjaaskel commented on code on Jul 28, 2025 09:33 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.

chipStar implements (or workarounds the lack of) this extension by means of a host-shared variable which a host thread polls and if set to 1 by the device, calls abort(). Do you suggest that even if the process is aborted this way (thus invoking the OS resource cleanup) there is a risk of instability in AMD's case? HIP provides a device reset API. Something like that could be invoked from the host side when device abort is detected for a cleaner ramp-down.

karolherbst karolherbst commented on code on Jul 28, 2025 09:52 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.

From my experience with AMD, hipDeviceReset sounds like its indeed a full device reset, resetting it for _every_ application running on the system :)

karolherbst karolherbst commented on code on Jul 28, 2025 09:54 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.

chipStar implements (or workarounds the lack of) this extension by means of a host-shared variable which a host thread polls and if set to 1 by the device, calls abort(). Do you suggest that even if the process is aborted this way (thus invoking the OS resource cleanup) there is a risk of instability in AMD's case?

Only if the kernel itself is misbehaving as a result. If the kernel just terminates normally, even after one thread quits, there is no danger. The issue simply just starts once it times out, or causes invalid memory accesses, etc....

pjaaskel pjaaskel commented on code on Jul 28, 2025 11:36 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is

The results produced by an aborted kernel command are undefined. Device side abort is

pjaaskel pjaaskel commented on code on Jul 28, 2025 11:41 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.
+
+The control flow behavior within the work-group of a kernel command with
+a WI that called the device side abort is the same as immediately
+returning from the kernel for the abort-calling WI at the abort call site.
+For possible WIs that do not call abort, the return time is undefined and can
+adhere to the original control flow of the kernel as long as all the WIs
+eventually finish the execution and allow the host runtime to abort the
+process also in a single-threaded/non-interrupting implementation.

For possible other WIs that do not call abort can run for an undefined and
adhere to the original control flow of the kernel until the host detects the abort
request and ramps down the execution. Work-items misbehaving (for example
by means of illegal memory accessess) after the abort has been called result in undefined behavior, as normally.

@karolherbst could something along this lines cover your concerns?

karolherbst karolherbst commented on code on Jul 28, 2025 14:55 UTC
Code Review
extensions/cl_ext_device_side_abort.asciidoc:1
@@ -0,0 +1,125 @@
+cl_ext_device_side_abort
+=========================
+
+// This section needs to be after the document title.
+:doctype: book
+:toc2:
+:toc: left
+:encoding: utf-8
+:lang: en
+:blank: pass:[ +]
+:data-uri:
+:icons: font
+include::../config/attribs.txt[]
+:source-highlighter: coderay
+
+== Name Strings
+
++cl_ext_device_side_abort+
+
+== Contact
+
+Pekka Jääskeläinen, Parmance (pekka /at/ parmance /dot/ com)
+
+== Contributors
+
+Pekka Jääskeläinen, Parmance +
+Henry Linjamäki, Parmance +
+Brice Videau, Argonne National Laboratory
+
+== Notice
+
+Copyright (c) 2021-2022 Parmance and Argonne National Laboratory.
+
+== Status
+
+Draft
+
+== Version
+
+Built On: {docdate} +
+Revision: 3
+
+== Dependencies
+
+This extension is written against the OpenCL Specification Version 1.2, Revision 19.
+
+This extension requires OpenCL 1.2.
+
+== Overview
+
+With the device side abort extension, a work-item (WI) can return from the kernel
+execution at any point and cause abnormal unrecoverable termination of the host
+process.
+
+This extension differs from the cl_arm_controlled_kernel_termination extension
+in that the abort in the device side is expected to behave like a call to the
+POSIX abort() in the host side, terminating also the host process immediately.
+
+== New OpenCL C Types and Functions
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+== Modifications to the OpenCL C Specification
+
+=== Add a new Section 6.12.X - "Device-side invoked platform-wide program abort"
+
+A new function: ::
++
+--
+
+[source,c]
+----
+void abort_platform(void);
+----
+
+Stops the kernel execution and causes an abnormal unrecoverable termination of
+the host process, thus causing abortion of execution of the whole program at
+the platform level.
+
+Calling the device side abort also causes the printf buffer to be flushed on the
+host program's standard output before aborting the host process. This allows to
+implement device side assertion functionality by using the OpenCL C printf
+function and this extension.
+
+The host should abort the process at latest when the kernel command that called
+the function has finished execution, which means that all the WIs will
+either call abort_platform() or return from the kernel command otherwise.
+
+The host process is expected to call the standard abort function of the host
+operating system. In POSIX/C99-compliant systems, this must be implemented by
+a call to abort() which implies that the SIGABRT signal is raised and can be
+caught by defining a signal handler. This means that a minimal implementation
+of a device-side abort with a CPU device can simply call the standard abort()
+directly to implement compliant behavior.
+
+The results of an aborted kernel command are undefined. Device side abort is
+guaranteed to stop the kernel command as soon as possible, even in the presence
+of deadlocks or partially reached barriers in the kernel command.
+
+The control flow behavior within the work-group of a kernel command with
+a WI that called the device side abort is the same as immediately
+returning from the kernel for the abort-calling WI at the abort call site.
+For possible WIs that do not call abort, the return time is undefined and can
+adhere to the original control flow of the kernel as long as all the WIs
+eventually finish the execution and allow the host runtime to abort the
+process also in a single-threaded/non-interrupting implementation.

small typo: "Possible other WIs that do not call abort can run for an undefined time ..."

But yeah, I think this covers it pretty well.

Reviewers
Assignees
pjaaskel pjaaskel
Labels
risk: low confidence: 89.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 51.2% (MEDIUM) · Higher = larger blast radius
51.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 89.7% · Lower = rushed or shallow review
89.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 5.3% · Safe to merge
5.3%