Skip to content

[SYCL][CUDA] Add bfloat16 and marray support to ldg builtin#22732

Open
zjin-lcf wants to merge 2 commits into
intel:syclfrom
zjin-lcf:cuda-ldg-bfloat16-15418
Open

[SYCL][CUDA] Add bfloat16 and marray support to ldg builtin#22732
zjin-lcf wants to merge 2 commits into
intel:syclfrom
zjin-lcf:cuda-ldg-bfloat16-15418

Conversation

@zjin-lcf

Copy link
Copy Markdown
Contributor

Summary

Fixes #15418.

The CUDA read-only-cache ldg builtin previously rejected bfloat16 and marray arguments, producing "no matching function for call to 'ldg'".

  • Add scalar bfloat16 and vec<bfloat16, 2/3/4> support.
  • Add generic marray<E, 2/3/4> support for all supported element types. marray shares the E[N] storage layout, so it delegates to the existing vec<E, N> loads (which read exactly N elements, keeping the padded N=3 case safe) and gets the same ld.global.nc read-only-cache / vectorized codegen.
  • Update the sycl_ext_oneapi_cuda_tex_cache_read extension spec (document bfloat16, marray, and the alignment requirement).
  • Extend sycl/test/check_device_code/cuda/ldg.cpp.

Test plan

  • check_device_code/cuda/ldg.cpp FileCheck passes (verified with an NVPTX-enabled DPC++ build).
  • Verified ldg compiles for marray of bfloat16/half/float/double/int/char.
  • PTX confirms ld.global.nc for bf16; the bit_cast workaround adds no extra instructions.
  • HeCBench addBiasResidualLayerNorm-sycl compiles and runs correctly on an H100 (checksums unchanged); bf16 ldg is up to ~7-8% faster than plain loads.

The CUDA read-only-cache `ldg` builtin previously rejected `bfloat16` and
`marray` arguments, producing "no matching function for call to 'ldg'"
(intel#15418).

Add support for scalar `bfloat16`, `vec<bfloat16, 2/3/4>`, and generic
`marray<E, 2/3/4>` for all supported element types. `marray` shares the
`E[N]` storage layout, so it delegates to the existing `vec<E, N>` loads
(which read exactly N elements, keeping the padded N=3 case safe) and thus
gets the same `ld.global.nc` read-only-cache / vectorized codegen.

Update the extension specification and check_device_code test accordingly.

Fixes intel#15418

Co-authored-by: Cursor <cursoragent@cursor.com>
@zjin-lcf
zjin-lcf requested review from a team as code owners July 22, 2026 23:56
@zjin-lcf
zjin-lcf requested a review from bratpiorka July 22, 2026 23:56
Address code_formatter CI failure on PR intel#22732 by reflowing the
bfloat16 vec branches and the bfloat16 ldg template instantiation
to match clang-format.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BF16 in CUDA builtins.hpp

2 participants