Skip to content

Add spin-loop termination to for AMD GPU hang on MP-ZCH (#5714)#5714

Closed
Ali-Tehrani wants to merge 1 commit intopytorch:mainfrom
Ali-Tehrani:export-D102424864
Closed

Add spin-loop termination to for AMD GPU hang on MP-ZCH (#5714)#5714
Ali-Tehrani wants to merge 1 commit intopytorch:mainfrom
Ali-Tehrani:export-D102424864

Conversation

@Ali-Tehrani
Copy link
Copy Markdown
Contributor

@Ali-Tehrani Ali-Tehrani commented Apr 29, 2026

Summary:

X-link: https://github.com/facebookresearch/FBGEMM/pull/2647

Context

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item. Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864

@meta-cla meta-cla Bot added the cla signed label Apr 29, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 29, 2026

@Ali-Tehrani has exported this pull request. If you are a Meta employee, you can view the originating Diff in D102424864.

@meta-codesync meta-codesync Bot changed the title Add spin-loop termination to for AMD GPU hang on MP-ZCH Add spin-loop termination to for AMD GPU hang on MP-ZCH (#5714) Apr 30, 2026
Ali-Tehrani added a commit to Ali-Tehrani/FBGEMM that referenced this pull request Apr 30, 2026
Summary:

X-link: facebookresearch/FBGEMM#2647

Context
---------

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item.  Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation
------------------

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864
Ali-Tehrani added a commit to Ali-Tehrani/FBGEMM that referenced this pull request Apr 30, 2026
Summary:

X-link: facebookresearch/FBGEMM#2647

Context
---------

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item.  Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation
------------------

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864
@Ali-Tehrani Ali-Tehrani force-pushed the export-D102424864 branch 2 times, most recently from 61630b0 to c7dd6ec Compare May 1, 2026 16:24
Ali-Tehrani added a commit to Ali-Tehrani/FBGEMM that referenced this pull request May 1, 2026
Summary:

X-link: facebookresearch/FBGEMM#2647

Context
---------

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item.  Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation
------------------

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864
Ali-Tehrani added a commit to Ali-Tehrani/FBGEMM that referenced this pull request May 1, 2026
Summary:

X-link: facebookresearch/FBGEMM#2647

Context
---------

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item.  Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation
------------------

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864
@Ali-Tehrani Ali-Tehrani force-pushed the export-D102424864 branch from c7dd6ec to 7126c37 Compare May 1, 2026 16:41
Ali-Tehrani added a commit to Ali-Tehrani/FBGEMM that referenced this pull request May 1, 2026
Summary:

X-link: facebookresearch/FBGEMM#2647

Context
---------

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item.  Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation
------------------

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864
@Ali-Tehrani Ali-Tehrani force-pushed the export-D102424864 branch from 7126c37 to 94bd696 Compare May 1, 2026 20:07
Ali-Tehrani added a commit to Ali-Tehrani/FBGEMM that referenced this pull request May 3, 2026
Summary:

X-link: facebookresearch/FBGEMM#2647

Context
---------

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item.  Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation
------------------

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864
@Ali-Tehrani Ali-Tehrani force-pushed the export-D102424864 branch from 94bd696 to 94e7518 Compare May 3, 2026 00:06
Ali-Tehrani added a commit to Ali-Tehrani/FBGEMM that referenced this pull request May 3, 2026
Summary:

X-link: facebookresearch/FBGEMM#2647

Context
---------

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item.  Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation
------------------

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864
@Ali-Tehrani Ali-Tehrani force-pushed the export-D102424864 branch from 94e7518 to b62ea00 Compare May 3, 2026 16:07
Ali-Tehrani added a commit to Ali-Tehrani/FBGEMM that referenced this pull request May 3, 2026
Summary:

X-link: facebookresearch/FBGEMM#2647

Context
---------

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item.  Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation
------------------

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864
@Ali-Tehrani Ali-Tehrani force-pushed the export-D102424864 branch from b62ea00 to 09e5299 Compare May 3, 2026 16:07
Summary:

X-link: facebookresearch/FBGEMM#2647

Context
---------

Running MPZCH on AMD hardware causes a CPU-to-GPU hang. This was identified to be the ZCH GPU kernel during the spin-wait loop that occurs.

TorchRec creates metadata and sets its default values to -1. This is then provided to the FBGEMM kernel. Note if an identity slot is -1, then its metadata is also -1, and the metadata for that slot is never -1 again when it gets updated.

Suppose thread A writes in slot i, and updates the identity slot with its item.  Suppose thread B was late and is also trying to write in slot i. While the metadata is being updated from thread A, thread B runs a spin-wait loop waiting for the metadata to be updated. This creates many atomic calls just to see if the metadata was updated from thread A.

AMD MI3X handles atomics differently than NVIDIA GPU. Due to this, the latency is incredibly slow, and atomic contention can occur when many threads are reading the atomic value . This ultimately looks like a hang that occurs.

NOTE: this only impacts when identities are first inserted when their metadata is -1, and explains why the hang occurs during the first few batches. WIP to reducing the amount of atomics in ZCH.

Implementation
------------------

Added a spin counter (SC ) to the spin-wait loop in check_evict and check_min. The value is determined through benchmarking

Reviewed By: kaanbaloglu

Differential Revision: D102424864
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented May 5, 2026

This pull request has been merged in 5b950e3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant