Skip to content

Add GPU support for Apple Silicon (M1/M2/M3/M4) #20

@hadv

Description

@hadv

Summary

The current GPU miner uses OpenCL, which is deprecated on macOS and has limited/no support on Apple Silicon Macs. To properly support M1/M2/M3/M4 chips, we need to implement a Metal-based GPU miner.

Current State

  • gpu_darwin.go uses OpenCL 1.2 via -framework OpenCL
  • Works well on Intel Macs with discrete AMD GPUs (e.g., Radeon Pro 555X, 560X, 5500M)
  • On Apple Silicon, OpenCL either:
    • Doesn't detect the GPU at all
    • Runs through an emulation layer with poor performance

Proposed Solution

Implement a Metal-based GPU miner for Apple Silicon:

  1. Create gpu_darwin_metal.go with Metal compute shaders
  2. Port the Keccak256 kernel (kernel/keccak256.cl) to Metal Shading Language (MSL)
  3. Use build tags to select between OpenCL (Intel Macs) and Metal (Apple Silicon)
  4. Alternatively, use Metal for all macOS builds since it works on both Intel and Apple Silicon

Technical Considerations

  • Metal uses MSL (Metal Shading Language) instead of OpenCL C
  • Need to use cgo with -framework Metal -framework Foundation
  • Consider using go-metal or direct cgo bindings
  • Metal provides better performance on Apple hardware than OpenCL

Benefits

  • Native GPU acceleration on M1/M2/M3/M4 Macs
  • Better performance than OpenCL even on Intel Macs
  • Future-proof as Apple continues to deprecate OpenCL

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions