Files
ds4/ds4_metal_device.h
T
Giorgio Oppo 0231312820 Metal: extend Qwen M1 Max tuning to M2, M3 and M4
Share the established M1 Max dispatch policy with the M2-M4 families
without changing kernel arithmetic, supported tensor shapes, math-mode
guards or diagnostic overrides.

- Centralize device eligibility with generation-bounded name matching.
  Preserve M1 base/Pro/Ultra and M5/M6 defaults, and retain M3 Ultra's
  dedicated MoE specialization, geometry and prefill tile policy.
- Enable wide Q8 decode row reuse, HC gate/mix reuse, short MTP Q8
  projections and the existing IQ2/Q2/MXFP4 expert paths on M2-M4.
- Extend small HC prefill tiles, large Q8 SSD prefill, sparse IQ2/Q2
  SSD tiles, Q4/MXFP4 K32 tiles, large-batch half staging and Q4 decode
  scratch release under the same existing shape and batch guards.
- Update SSD dispatch probes, cover 47 device-name cases and document
  the supported families and the limits of current hardware evidence.

Validation: build all application targets and run the device-policy,
Qwen kernel, safe-math reuse/projection, MoE specialization and SSD
expert tests (retained and unretained command buffers) on an isolated
HEAD export containing only this commit. Local hardware is M1 Max;
M2/M3/M4 throughput still requires validation on those devices.
2026-10-01 08:04:59 +02:00

32 lines
1.3 KiB
C

#ifndef DS4_METAL_DEVICE_H
#define DS4_METAL_DEVICE_H
#include <string.h>
/* Share the Qwen M1 Max defaults with M2-M4 while keeping other M1 devices
* and newer generations on their existing paths. Bound the generation token
* so names such as M20 do not inherit these defaults. */
static inline int ds4_metal_device_name_uses_qwen_legacy_tuning(const char *name) {
return name && (strcmp(name, "Apple M1 Max") == 0 ||
(strncmp(name, "Apple M", 7) == 0 &&
name[7] >= '2' && name[7] <= '4' &&
(name[8] == '\0' || name[8] == ' ')));
}
/* M3 Ultra already has dedicated MoE defaults; preserve those selections. */
static inline int ds4_metal_device_name_uses_qwen_legacy_moe_tuning(const char *name) {
return ds4_metal_device_name_uses_qwen_legacy_tuning(name) &&
strcmp(name, "Apple M3 Ultra") != 0;
}
/* Share the M5 tuning policy with M6. Keep the generation token bounded so
* untested future names such as M50 and M60 do not inherit these defaults.
* Callers must still check runtime and kernel capabilities where required. */
static inline int ds4_metal_device_name_is_m5_or_m6(const char *name) {
return name && strncmp(name, "Apple M", 7) == 0 &&
(name[7] == '5' || name[7] == '6') &&
(name[8] == '\0' || name[8] == ' ');
}
#endif