Skip to content

opencl: add ABS op#25115

Open
Gezahegne wants to merge 6 commits into
ggml-org:masterfrom
Gezahegne:opencl-abs
Open

opencl: add ABS op#25115
Gezahegne wants to merge 6 commits into
ggml-org:masterfrom
Gezahegne:opencl-abs

Conversation

@Gezahegne

@Gezahegne Gezahegne commented Jun 29, 2026

Copy link
Copy Markdown

Overview

Adds support for the ABS unary operation (y = |x|) to the OpenCL backend.
This implements it for F32 and F16, contiguous and non-contiguous tensors.
The implementation mirrors the existing EXPM1 op (same element-wise unary
structure); only the per-element math differs (exp(x) - 1fabs(x)).

Additional information

Changes

  • ggml/src/ggml-opencl/kernels/abs.cl (new): 6 kernels —
    kernel_abs_f32, kernel_abs_f32_4, kernel_abs_f32_nc,
    kernel_abs_f16, kernel_abs_f16_4, kernel_abs_f16_nc.
  • ggml/src/ggml-opencl/CMakeLists.txt: register abs in GGML_OPENCL_KERNELS.
  • ggml/src/ggml-opencl/ggml-opencl.cpp:
    • declare the 6 cl_kernel kernel_abs_* handles in the backend context,
    • load them in a new // abs program block,
    • add the ggml_cl_abs() dispatch function (contiguous fast path with _4
      vectorization when nelements % 4 == 0, otherwise scalar; _nc for
      non-contiguous inputs),
    • route GGML_UNARY_OP_ABS to ggml_cl_abs,
    • return true for GGML_UNARY_OP_ABS (F32/F16) in supports_op.
  • docs/ops.md: regenerated — OpenCL ABS cell flips ❌ → ✅.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure:
    YES — used Claude Code to help implement the ABS OpenCL kernels and dispatch by mirroring the existing EXPM1 op, and regenerate docs/ops.md. Reviewed and verified on Intel Arc 140V hardware.

@Gezahegne Gezahegne requested a review from a team as a code owner June 29, 2026 02:12
@github-actions github-actions Bot added documentation Improvements or additions to documentation ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend labels Jun 29, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

Hi @Gezahegne, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • AI-generated content: This project does not accept PRs, descriptions or commit messages that are fully or predominantly AI-generated. If you have used AI to assist you in writing code, please make sure to disclose that explicitly.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@arthw

arthw commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Could you remove the string "SYCL" in the description?
We use it as key word to filter the PR/issue for different backends.

Thank you!

@max-krasnyansky

Copy link
Copy Markdown
Member

Please remove changes in .gitignore and extra txt files.
Also looks like you need to rebase with latest master.

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

Labels

documentation Improvements or additions to documentation ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants