Skip to content

Conversation

RD-zhang1234
Copy link

Make sure to read the contributing guidelines before submitting a PR

Summary

Adds support for the LOG operation to the Metal backend for both f32 and f16 tensor types.

Implementation details

  • Added four kernels in ggml-metal.metal:
    • kernel_log_f32
    • kernel_log_f32_4
    • kernel_log_f16
    • kernel_log_f16_4
  • Updated ggml-metal-device.m to allow F16 for the LOG op.
  • Integrated LOG into the unified unary op path (same as SIN and COS).

Validation

Tested on Apple M1 (MTLGPUFamilyApple7)

./build/bin/test-backend-ops -b Metal -o LOG
./build/bin/test-backend-ops perf -b Metal -o LOG
✅ 15978 / 15978 tests passed
✅ f32 / f16 variants all loaded successfully:
	•	kernel_log_f32
	•	kernel_log_f32_4
	•	kernel_log_f16
	•	kernel_log_f16_4
Notes
	•	f16 kernels compute in f32 for better numerical stability, then cast back to half.
	•	Matches CPU backend results for the natural logarithm (log(x)).
	•	Performance parity verified with test-backend-ops perf.

@github-actions github-actions bot added ggml changes relating to the ggml tensor library for machine learning Apple Metal https://en.wikipedia.org/wiki/Metal_(API) labels Oct 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Apple Metal https://en.wikipedia.org/wiki/Metal_(API) ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants