Repository navigation
[ROCm] Fix bfe() bit-field extraction in the quantized CUDA EmbeddingBag kernel (#192571) - #192571
zidongyang wants to merge 1 commit into
Conversation
|
This appears to be a diff that was exported from phabricator, but the PR author does not have sufficient permissions to run CI. @zidongyang, please do step 2 of internal wiki to get write access so you do not need to get CI approvals in the future. If you think this is a mistake, please contact the Pytorch Dev Infra team. |
|
|
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/192571
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 8cb7340 with merge base 4c5b5ab ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@zidongyang has exported this pull request. If you are a Meta employee, you can view the originating Diff in D115065161. |
74fb38d to
c0638d4
Compare
…Bag kernel (pytorch#192571) Summary: `bfe()` in aten/src/ATen/native/quantized/cuda/EmbeddingBag.cu extracts the [pos, pos+len) bit field of a packed word and returns it as a float. It is the inner primitive of `dequantize_intx()`, so every `quantized::embedding_bag_{byte,4bit}_rowwise_offsets` call on a GPU goes through it. The `#ifdef USE_ROCM` branch read: return *reinterpret_cast<float*>((val >> pos) && ((1u << len) - 1u)); which has two defects: - `&&` (logical AND) is used where `&` (bitwise AND) was intended, so the expression collapses to 0 or 1 instead of the requested bit field. - the resulting `bool` is then reinterpreted as a `float*` and dereferenced, i.e. a load from address 0 or 1. This is not a subtle numerical issue: on an AMD GPU the null load aborts the process with Memory access fault by GPU node-2 (Agent handle: 0x...) on address (nil). so quantized embedding-bag lookups could never have run on ROCm. The line has been unchanged since the file was added in July 2021. Use the bitwise AND and convert with `__uint2float_rn`, which yields the same value the CUDA branch computes with the `bfe.u32` PTX instruction. Both branches end in that same conversion, so only the bit-field extraction itself stays under the `#ifdef` and the conversion is shared between them. NVIDIA codegen and the CPU implementations are unchanged. The explanatory comment carried the same `&&` typo and is most likely where the ROCm expression was copied from; it is corrected and hoisted to describe the function as a whole rather than just one branch. Test Plan: New test `test_embedding_bag_rowwise_offsets_cuda` in `test/quantization/core/test_quantized_op.py` runs `quantized::embedding_bag_byte_rowwise_offsets` and `quantized::embedding_bag_4bit_rowwise_offsets` on GPU and asserts the output is finite and agrees with the CPU implementation. Both bit widths are covered because `bfe()` is shared by them through `dequantize_intx()`, with a different `len`. python test/quantization/core/test_quantized_op.py -k test_embedding_bag_rowwise_offsets_cuda Run on an AMD GPU (ROCm): passes. The whole `TestQuantizedEmbeddingOps` class passes as well (7 tests). As a negative control, reverting just this fix makes the new test abort with the GPU memory fault quoted in the summary, so the test does pin the behaviour it claims to. Differential Revision: D115065161
…Bag kernel (pytorch#192571) Summary: `bfe()` in aten/src/ATen/native/quantized/cuda/EmbeddingBag.cu extracts the [pos, pos+len) bit field of a packed word and returns it as a float. It is the inner primitive of `dequantize_intx()`, so every `quantized::embedding_bag_{byte,4bit}_rowwise_offsets` call on a GPU goes through it. The `#ifdef USE_ROCM` branch read: return *reinterpret_cast<float*>((val >> pos) && ((1u << len) - 1u)); which has two defects: - `&&` (logical AND) is used where `&` (bitwise AND) was intended, so the expression collapses to 0 or 1 instead of the requested bit field. - the resulting `bool` is then reinterpreted as a `float*` and dereferenced, i.e. a load from address 0 or 1. This is not a subtle numerical issue: on an AMD GPU the null load aborts the process with Memory access fault by GPU node-2 (Agent handle: 0x...) on address (nil). so quantized embedding-bag lookups could never have run on ROCm. The line has been unchanged since the file was added in July 2021. Use the bitwise AND and convert with `__uint2float_rn`, which yields the same value the CUDA branch computes with the `bfe.u32` PTX instruction. Both branches end in that same conversion, so only the bit-field extraction itself stays under the `#ifdef` and the conversion is shared between them. NVIDIA codegen and the CPU implementations are unchanged. The explanatory comment carried the same `&&` typo and is most likely where the ROCm expression was copied from; it is corrected and hoisted to describe the function as a whole rather than just one branch. Test Plan: New test `test_embedding_bag_rowwise_offsets_cuda` in `test/quantization/core/test_quantized_op.py` runs `quantized::embedding_bag_byte_rowwise_offsets` and `quantized::embedding_bag_4bit_rowwise_offsets` on GPU and asserts the output is finite and agrees with the CPU implementation. Both bit widths are covered because `bfe()` is shared by them through `dequantize_intx()`, with a different `len`. python test/quantization/core/test_quantized_op.py -k test_embedding_bag_rowwise_offsets_cuda Run on an AMD GPU (ROCm): passes. The whole `TestQuantizedEmbeddingOps` class passes as well (7 tests). As a negative control, reverting just this fix makes the new test abort with the GPU memory fault quoted in the summary, so the test does pin the behaviour it claims to. Differential Revision: D115065161
…Bag kernel (pytorch#192571) Summary: Pull Request resolved: pytorch#192571 `bfe()` in aten/src/ATen/native/quantized/cuda/EmbeddingBag.cu extracts the [pos, pos+len) bit field of a packed word and returns it as a float. It is the inner primitive of `dequantize_intx()`, so every `quantized::embedding_bag_{byte,4bit}_rowwise_offsets` call on a GPU goes through it. The `#ifdef USE_ROCM` branch read: return *reinterpret_cast<float*>((val >> pos) && ((1u << len) - 1u)); which has two defects: - `&&` (logical AND) is used where `&` (bitwise AND) was intended, so the expression collapses to 0 or 1 instead of the requested bit field. - the resulting `bool` is then reinterpreted as a `float*` and dereferenced, i.e. a load from address 0 or 1. This is not a subtle numerical issue: on an AMD GPU the null load aborts the process with Memory access fault by GPU node-2 (Agent handle: 0x...) on address (nil). so quantized embedding-bag lookups could never have run on ROCm. The line has been unchanged since the file was added in July 2021. Use the bitwise AND and convert with `__uint2float_rn`, which yields the same value the CUDA branch computes with the `bfe.u32` PTX instruction. Both branches end in that same conversion, so only the bit-field extraction itself stays under the `#ifdef` and the conversion is shared between them. NVIDIA codegen and the CPU implementations are unchanged. The explanatory comment carried the same `&&` typo and is most likely where the ROCm expression was copied from; it is corrected and hoisted to describe the function as a whole rather than just one branch. Test Plan: New test `test_embedding_bag_rowwise_offsets_cuda` in `test/quantization/core/test_quantized_op.py` runs `quantized::embedding_bag_byte_rowwise_offsets` and `quantized::embedding_bag_4bit_rowwise_offsets` on GPU and asserts the output is finite and agrees with the CPU implementation. Both bit widths are covered because `bfe()` is shared by them through `dequantize_intx()`, with a different `len`. python test/quantization/core/test_quantized_op.py -k test_embedding_bag_rowwise_offsets_cuda Run on an AMD GPU (ROCm): passes. The whole `TestQuantizedEmbeddingOps` class passes as well (7 tests). As a negative control, reverting just this fix makes the new test abort with the GPU memory fault quoted in the summary, so the test does pin the behaviour it claims to. Differential Revision: D115065161
c0638d4 to
8cb7340
Compare
…Bag kernel (pytorch#192571) Summary: `bfe()` in aten/src/ATen/native/quantized/cuda/EmbeddingBag.cu extracts the [pos, pos+len) bit field of a packed word and returns it as a float. It is the inner primitive of `dequantize_intx()`, so every `quantized::embedding_bag_{byte,4bit}_rowwise_offsets` call on a GPU goes through it. The `#ifdef USE_ROCM` branch read: return *reinterpret_cast<float*>((val >> pos) && ((1u << len) - 1u)); which has two defects: - `&&` (logical AND) is used where `&` (bitwise AND) was intended, so the expression collapses to 0 or 1 instead of the requested bit field. - the resulting `bool` is then reinterpreted as a `float*` and dereferenced, i.e. a load from address 0 or 1. This is not a subtle numerical issue: on an AMD GPU the null load aborts the process with Memory access fault by GPU node-2 (Agent handle: 0x...) on address (nil). so quantized embedding-bag lookups could never have run on ROCm. The line has been unchanged since the file was added in July 2021. Use the bitwise AND and convert with `__uint2float_rn`, which yields the same value the CUDA branch computes with the `bfe.u32` PTX instruction. Both branches end in that same conversion, so only the bit-field extraction itself stays under the `#ifdef` and the conversion is shared between them. NVIDIA codegen and the CPU implementations are unchanged. The explanatory comment carried the same `&&` typo and is most likely where the ROCm expression was copied from; it is corrected and hoisted to describe the function as a whole rather than just one branch. Test Plan: New test `test_embedding_bag_rowwise_offsets_cuda` in `test/quantization/core/test_quantized_op.py` runs `quantized::embedding_bag_byte_rowwise_offsets` and `quantized::embedding_bag_4bit_rowwise_offsets` on GPU and asserts the output is finite and agrees with the CPU implementation. Both bit widths are covered because `bfe()` is shared by them through `dequantize_intx()`, with a different `len`. python test/quantization/core/test_quantized_op.py -k test_embedding_bag_rowwise_offsets_cuda Run on an AMD GPU (ROCm): passes. The whole `TestQuantizedEmbeddingOps` class passes as well (7 tests). As a negative control, reverting just this fix makes the new test abort with the GPU memory fault quoted in the summary, so the test does pin the behaviour it claims to. Differential Revision: D115065161
…Bag kernel (pytorch#192571) Summary: Pull Request resolved: pytorch#192571 `bfe()` in aten/src/ATen/native/quantized/cuda/EmbeddingBag.cu extracts the [pos, pos+len) bit field of a packed word and returns it as a float. It is the inner primitive of `dequantize_intx()`, so every `quantized::embedding_bag_{byte,4bit}_rowwise_offsets` call on a GPU goes through it. The `#ifdef USE_ROCM` branch read: return *reinterpret_cast<float*>((val >> pos) && ((1u << len) - 1u)); which has two defects: - `&&` (logical AND) is used where `&` (bitwise AND) was intended, so the expression collapses to 0 or 1 instead of the requested bit field. - the resulting `bool` is then reinterpreted as a `float*` and dereferenced, i.e. a load from address 0 or 1. This is not a subtle numerical issue: on an AMD GPU the null load aborts the process with Memory access fault by GPU node-2 (Agent handle: 0x...) on address (nil). so quantized embedding-bag lookups could never have run on ROCm. The line has been unchanged since the file was added in July 2021. Use the bitwise AND and convert with `__uint2float_rn`, which yields the same value the CUDA branch computes with the `bfe.u32` PTX instruction. Both branches end in that same conversion, so only the bit-field extraction itself stays under the `#ifdef` and the conversion is shared between them. NVIDIA codegen and the CPU implementations are unchanged. The explanatory comment carried the same `&&` typo and is most likely where the ROCm expression was copied from; it is corrected and hoisted to describe the function as a whole rather than just one branch. Test Plan: New test `test_embedding_bag_rowwise_offsets_cuda` in `test/quantization/core/test_quantized_op.py` runs `quantized::embedding_bag_byte_rowwise_offsets` and `quantized::embedding_bag_4bit_rowwise_offsets` on GPU and asserts the output is finite and agrees with the CPU implementation. Both bit widths are covered because `bfe()` is shared by them through `dequantize_intx()`, with a different `len`. python test/quantization/core/test_quantized_op.py -k test_embedding_bag_rowwise_offsets_cuda Run on an AMD GPU (ROCm): passes. The whole `TestQuantizedEmbeddingOps` class passes as well (7 tests). As a negative control, reverting just this fix makes the new test abort with the GPU memory fault quoted in the summary, so the test does pin the behaviour it claims to. Differential Revision: D115065161
|
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…Bag kernel (pytorch#192571) (pytorch#192571) Summary: `bfe()` in aten/src/ATen/native/quantized/cuda/EmbeddingBag.cu extracts the [pos, pos+len) bit field of a packed word and returns it as a float. It is the inner primitive of `dequantize_intx()`, so every `quantized::embedding_bag_{byte,4bit}_rowwise_offsets` call on a GPU goes through it. The `#ifdef USE_ROCM` branch read: return *reinterpret_cast<float*>((val >> pos) && ((1u << len) - 1u)); which has two defects: - `&&` (logical AND) is used where `&` (bitwise AND) was intended, so the expression collapses to 0 or 1 instead of the requested bit field. - the resulting `bool` is then reinterpreted as a `float*` and dereferenced, i.e. a load from address 0 or 1. This is not a subtle numerical issue: on an AMD GPU the null load aborts the process with Memory access fault by GPU node-2 (Agent handle: 0x...) on address (nil). so quantized embedding-bag lookups could never have run on ROCm. The line has been unchanged since the file was added in July 2021. Use the bitwise AND and convert with `__uint2float_rn`, which yields the same value the CUDA branch computes with the `bfe.u32` PTX instruction. Both branches end in that same conversion, so only the bit-field extraction itself stays under the `#ifdef` and the conversion is shared between them. NVIDIA codegen and the CPU implementations are unchanged. The explanatory comment carried the same `&&` typo and is most likely where the ROCm expression was copied from; it is corrected and hoisted to describe the function as a whole rather than just one branch. Test Plan: New test `test_embedding_bag_rowwise_offsets_cuda` in `test/quantization/core/test_quantized_op.py` runs `quantized::embedding_bag_byte_rowwise_offsets` and `quantized::embedding_bag_4bit_rowwise_offsets` on GPU and asserts the output is finite and agrees with the CPU implementation. Both bit widths are covered because `bfe()` is shared by them through `dequantize_intx()`, with a different `len`. python test/quantization/core/test_quantized_op.py -k test_embedding_bag_rowwise_offsets_cuda Run on an AMD GPU (ROCm): passes. The whole `TestQuantizedEmbeddingOps` class passes as well (7 tests). As a negative control, reverting just this fix makes the new test abort with the GPU memory fault quoted in the summary, so the test does pin the behaviour it claims to. Differential Revision: D115065161 Pull Request resolved: pytorch#192571 Approved by: https://github.com/Skylion007, https://github.com/vadimkantorov
Summary:
bfe()in aten/src/ATen/native/quantized/cuda/EmbeddingBag.cu extracts the[pos, pos+len) bit field of a packed word and returns it as a float. It is the
inner primitive of
dequantize_intx(), so everyquantized::embedding_bag_{byte,4bit}_rowwise_offsetscall on a GPU goesthrough it.
The
#ifdef USE_ROCMbranch read:which has two defects:
&&(logical AND) is used where&(bitwise AND) was intended, so theexpression collapses to 0 or 1 instead of the requested bit field.
boolis then reinterpreted as afloat*and dereferenced,i.e. a load from address 0 or 1.
This is not a subtle numerical issue: on an AMD GPU the null load aborts the
process with
so quantized embedding-bag lookups could never have run on ROCm. The line has
been unchanged since the file was added in July 2021.
Use the bitwise AND and convert with
__uint2float_rn, which yields the samevalue the CUDA branch computes with the
bfe.u32PTX instruction. Both branchesend in that same conversion, so only the bit-field extraction itself stays under
the
#ifdefand the conversion is shared between them. NVIDIA codegen and theCPU implementations are unchanged.
The explanatory comment carried the same
&&typo and is most likely where theROCm expression was copied from; it is corrected and hoisted to describe the
function as a whole rather than just one branch.
Test Plan:
New test
test_embedding_bag_rowwise_offsets_cudaintest/quantization/core/test_quantized_op.pyrunsquantized::embedding_bag_byte_rowwise_offsetsandquantized::embedding_bag_4bit_rowwise_offsetson GPU and asserts the output isfinite and agrees with the CPU implementation. Both bit widths are covered
because
bfe()is shared by them throughdequantize_intx(), with a differentlen.Run on an AMD GPU (ROCm): passes. The whole
TestQuantizedEmbeddingOpsclasspasses as well (7 tests).
As a negative control, reverting just this fix makes the new test abort with the
GPU memory fault quoted in the summary, so the test does pin the behaviour it
claims to.
Differential Revision: D115065161
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang