🐛 Answer the device's own compiler target, never nil
What the guest sees changes: the device answers targetDeviceArchitecture (MTLDeviceSPI) with an MTLTargetDeviceArchitecture, Metal's own class, of cpuType 0x01005247, subType 0, version 1.0.0 and driverVersion 0x10000. It answered nil, the IOGPU base's answer. Metal's loader ends the process at nil (+[MTLLoader sliceIDForDevice: legacyDriverVersion:airntDriverVersion:]), and MTLAssetUpgraderD, which asks Metal's archive reader about every .metallib of an app it is told of for every device, ended with SIGABRT at each app installed in the guest: 1-2 reports in every walk since pin 70, on Iris and the 3090. Every Mac answers an object (oracle_archtype: AMD 5300M, Intel UHD 630, M3 Max, dgpu-oracle.md Q42), so nil is outside the envelope. The values name each GPU's own compiler target, so the device names its own: CPU_ARCH_ABI64 with its PCI device id, which no Metal slice carries, so no archive holds a slice Metal reads as this device's; one target whatever the host GPU; and one version for both version fields, as the M3 Max and the Intel 630 answer. Where the guest's Metal lacks the class or its setters, nil as before. inherited_tests now checks the answer, and the register's line says why it changed.
This commit is contained in:
1 parent
fffc41b341
commit
e33c569c9c
4 files changed
+153
-2
No files matched your search
@@ -2192,6 +2192,50 @@ mode, and so is one over read-only memory, whose pass completes with the memory
|
||||
M3 Max completes it (Q38). Until 11-14 such a pass ended the process at its making, as a
|
||||
resolve into a texture over a buffer, a shape not measured.
|
||||
|
||||
## Q42: the device's compiler target, and Metal's archive readers
|
||||
|
||||
Probe: `oracle_archtype DEVICE FILE...`, 11-14: the AMD 5300M and the Intel UHD 630 under macOS
|
||||
26.7.1 (25G241), m3-max-30048 and m3-max-30049, and the M3 Max under macOS 27.0.1 (26A434),
|
||||
m3-max-30050. The files: a `.metallib` of AIR (`oracle.metallib`), a dynamic library of AIR
|
||||
(`oracle_bundle_dyn.metallib`), and a binary archive and a dynamic library the device serializes
|
||||
itself.
|
||||
|
||||
| what | AMD 5300M | Intel UHD 630 | M3 Max |
|
||||
|---|---|---|---|
|
||||
| `targetDeviceArchitecture` | an `MTLTargetDeviceArchitecture` (Metal's class, of `NSObject`) | the same | the same |
|
||||
| its `cpuType`, `subType` | 0x1000014, 0x1773 | 0x1000015, 0x950200 | 0x1000013, 0x1a3 |
|
||||
| its `driverVersion`, `versionCombined` | 0x7d4, 0xe0002 | 0x1a0701, 0x1a0701 | 0x30000, 0x30000 |
|
||||
| the archive reader, AIR `.metallib`; AIR dynamic library | 1, 1 | 1, 1 | 1, 1 |
|
||||
| the dynamic library reader, the same files | 0, 1 | 0, 1 | 0, 1 |
|
||||
| the archive reader, the device's own archive; its dynamic library | 2, 1 | 3, 1 | 2, 1 |
|
||||
| the dynamic library reader, the device's own archive; its dynamic library | 0, 2 | 1, 1 | 0, 2 |
|
||||
|
||||
The class has `cpuType`, `subType`, `driverVersion`, `version` (`{MTLTargetDeviceArchVersion=SCC}`)
|
||||
and `versionCombined`, and setters of all but the last. The readers' numbers are the names
|
||||
MTLAssetUpgraderD prints for them: the archive reader's 0 Invalid, 1 Legacy, 2 Compatible,
|
||||
3 Rebuild, 4 NoVendorSlice, and the dynamic library reader's 0 Invalid, 1 AIROnly, 2 Compatible,
|
||||
3 Rebuild, 4 NoVendorSlice.
|
||||
|
||||
Every Mac answers an object, and no Mac answers nil *(class 3)*. Its values are each GPU's own
|
||||
compiler target and versions: an answer that describes the device, which is the device's own and
|
||||
not a pick between the Macs'. What it is read for (read from macOS 27's Metal and MTLAssetUpgraderD):
|
||||
- Metal's loader (`+[MTLLoader sliceIDForDevice:legacyDriverVersion:airntDriverVersion:]`) makes
|
||||
the slice it looks for in a binary archive or a dynamic library of `cpuType` and `subType`, and
|
||||
ends the process where the answer is nil. MTLAssetUpgraderD, told of an app installed, asks
|
||||
Metal's archive and dynamic library readers about each `.metallib` in it, for each device, and
|
||||
queues a rebuild of the file for the device where the archive reader answers 3 or the dynamic
|
||||
library reader 1 or 3.
|
||||
- MPS keeps `cpuType << 32 | subType` and gives it to its NDArray kernels' prefix and postfix
|
||||
queries, and Metal's `_MTLUseAIRNTBinaryArchive` answers YES for a `cpuType` of 0x1000013 to
|
||||
0x1000015 alone, where no setting of Metal's decides it.
|
||||
|
||||
What our stack does: until 11-14 the device left `targetDeviceArchitecture` to the IOGPU base,
|
||||
which answers nil *(class 4)*, and MTLAssetUpgraderD ended with SIGABRT at each app installed in
|
||||
the guest. The device now answers an `MTLTargetDeviceArchitecture` of its own target: `cpuType`
|
||||
0x01005247, `CPU_ARCH_ABI64` with its PCI device id, which no Metal slice carries, `subType` 0, and
|
||||
version 1.0.0 (`versionCombined` 0x10000) with `driverVersion` 0x10000. No Mac's archive holds a
|
||||
slice of it, and the device's own archives are of its own format.
|
||||
|
||||
## Not measured
|
||||
|
||||
- Cross-process lock waits for pending GPU work: rgk-lock's `lock_probe` (x86 matches the M3,
|
||||
|
||||
@@ -765,6 +765,57 @@ RGFX_LOG_UNRECOGNIZED
|
||||
}
|
||||
@end
|
||||
|
||||
namespace {
|
||||
|
||||
// The device's GPU compiler target, which `targetDeviceArchitecture` answers (it says why).
|
||||
constexpr uint32_t kRgfxTargetCpuType = 0x0100'5247;
|
||||
constexpr uint32_t kRgfxTargetSubType = 0;
|
||||
constexpr uint64_t kRgfxTargetDriverVersion = 0x1'0000;
|
||||
|
||||
// Metal's MTLTargetDeviceArchVersion, `{MTLTargetDeviceArchVersion=SCC}` (measured: its setter's
|
||||
// type on macOS 26.7.1 and 27.0.1): a 16-bit and two 8-bit fields, which its versionCombined
|
||||
// answers as field_00 << 16 | field_02 << 8 | field_03 (tests/inherited_tests.mm reads it back).
|
||||
struct RgfxTargetArchVersion {
|
||||
uint16_t field_00;
|
||||
uint8_t field_02;
|
||||
uint8_t field_03;
|
||||
};
|
||||
static_assert(sizeof(RgfxTargetArchVersion) == 4, "MTLTargetDeviceArchVersion is 4 bytes");
|
||||
|
||||
constexpr RgfxTargetArchVersion kRgfxTargetVersion = {1, 0, 0};
|
||||
|
||||
// Whether `cls` has the instance method `sel` of the type encoding `types`.
|
||||
bool rgfxHasMethod(Class cls, SEL sel, const char *types)
|
||||
{
|
||||
Method m = class_getInstanceMethod(cls, sel);
|
||||
return m != nullptr && std::strcmp(method_getTypeEncoding(m), types) == 0;
|
||||
}
|
||||
|
||||
// An MTLTargetDeviceArchitecture naming the device's target; nil where the guest's Metal has no
|
||||
// such class, or its setters are not the ones this sets.
|
||||
id rgfxTargetDeviceArchitecture()
|
||||
{
|
||||
Class cls = objc_getClass("MTLTargetDeviceArchitecture");
|
||||
if (cls == Nil || !rgfxHasMethod(cls, @selector(setCpuType:), "v20@0:8I16") ||
|
||||
!rgfxHasMethod(cls, @selector(setSubType:), "v20@0:8I16") ||
|
||||
!rgfxHasMethod(cls, @selector(setDriverVersion:), "v24@0:8Q16") ||
|
||||
!rgfxHasMethod(cls, @selector(setVersion:), "v20@0:8{MTLTargetDeviceArchVersion=SCC}16")) {
|
||||
os_log_error(rgfxLog(), "RGFX: the guest's Metal has no MTLTargetDeviceArchitecture of the "
|
||||
"setters the device sets; targetDeviceArchitecture answers nil");
|
||||
return nil;
|
||||
}
|
||||
id a = [[cls alloc] init];
|
||||
((void (*)(id, SEL, uint32_t))objc_msgSend)(a, @selector(setCpuType:), kRgfxTargetCpuType);
|
||||
((void (*)(id, SEL, uint32_t))objc_msgSend)(a, @selector(setSubType:), kRgfxTargetSubType);
|
||||
((void (*)(id, SEL, uint64_t))objc_msgSend)(a, @selector(setDriverVersion:),
|
||||
kRgfxTargetDriverVersion);
|
||||
((void (*)(id, SEL, RgfxTargetArchVersion))objc_msgSend)(a, @selector(setVersion:),
|
||||
kRgfxTargetVersion);
|
||||
return a;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@implementation RgfxMetalDevice {
|
||||
RgfxCaps _caps; // host device caps; invalid until the region is read
|
||||
RgfxVideoCaps _videoCaps; // the host's video codecs; none until the region is read
|
||||
@@ -1307,6 +1358,30 @@ RGFX_LOG_UNRECOGNIZED
|
||||
return [[RgfxArchitecture alloc] initWithArchitectureName:@""];
|
||||
}
|
||||
|
||||
// The device's GPU compiler target, MTLDeviceSPI's `targetDeviceArchitecture`: an object of
|
||||
// Metal's own class, MTLTargetDeviceArchitecture, as every Mac's device answers (measured:
|
||||
// tools/oracle/oracle_archtype.m on the AMD 5300M, the Intel 630 and the M3 Max,
|
||||
// docs/graphics-kext/dgpu-oracle.md Q42). nil, which the IOGPU base answered, is outside that:
|
||||
// Metal's loader ends the process at it (+[MTLLoader sliceIDForDevice:legacyDriverVersion:
|
||||
// airntDriverVersion:], read from macOS 27's Metal), and MTLAssetUpgraderD, which asks Metal's
|
||||
// archive reader about every .metallib of an app it is told of for every device, ended with
|
||||
// SIGABRT at each app installed in the guest. Each Mac's answer names its own compiler's
|
||||
// target, so the device's names its own:
|
||||
// - cpuType 0x01005247: CPU_ARCH_ABI64 with the device's PCI device id, 0x5247. No Metal slice
|
||||
// carries it (Apple's GPUs are 0x01000013, AMD's 0x01000014, Intel's 0x01000015, AIR
|
||||
// 0x01000017), so no archive or dynamic library holds a slice Metal reads as this device's:
|
||||
// the device makes its pipelines from AIR on the host, and its archives are of its own format
|
||||
// (RgfxBinaryArchiveFile.hpp).
|
||||
// - subType 0: the device has one target, whatever the host's GPU.
|
||||
// - version 1.0.0, versionCombined 0x10000, and driverVersion 0x10000, the same value, as the M3
|
||||
// Max (0x30000) and the Intel 630 (0x1a0701) answer theirs.
|
||||
// Where the guest's Metal has no such class, nil.
|
||||
- (id)targetDeviceArchitecture
|
||||
{
|
||||
static id answer = rgfxTargetDeviceArchitecture();
|
||||
return answer;
|
||||
}
|
||||
|
||||
- (BOOL)hasUnifiedMemory
|
||||
{
|
||||
return _caps.valid() && _caps.identityFlag(kRgfxIdentityHasUnifiedMemory);
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
// or an argument or return value of another size.
|
||||
// A listed selector this macOS's base classes lack is reported, not failed: the guest's macOS can
|
||||
// differ.
|
||||
// It also checks the x86 device's answer to newResidencySetWithDescriptor:error:: nil, its error
|
||||
// It also checks the device's targetDeviceArchitecture, Metal's MTLTargetDeviceArchitecture naming
|
||||
// the device's own compiler target (checkTargetDeviceArchitecture); the x86 device's answer to
|
||||
// newResidencySetWithDescriptor:error:: nil, its error
|
||||
// out set to nil from an error it held, as the x86 Macs answer (measured: macOS 26.7.1, the AMD
|
||||
// Radeon Pro 5300M and the Intel UHD 630); the refusals Metal answers at a URL before it reads it
|
||||
// (checkUrlRefusals); and that each call Metal's device ends the process at for its argument
|
||||
@@ -23,6 +25,7 @@
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <mach-o/dyld.h>
|
||||
#include <objc/message.h>
|
||||
#include <objc/runtime.h>
|
||||
#include <signal.h>
|
||||
#include <spawn.h>
|
||||
@@ -200,6 +203,34 @@ void checkResidencySetAnswer(Class device)
|
||||
set, error == sentinel ? @"untouched" : error]);
|
||||
}
|
||||
|
||||
// The device's compiler target (src/RgfxMetalDevice.mm says why): an object of Metal's own
|
||||
// MTLTargetDeviceArchitecture, as each Mac's device answers, never the IOGPU base's nil, at which
|
||||
// Metal's loader ends the process; cpuType 0x01005247, subType 0, driverVersion 0x10000, and
|
||||
// versionCombined 0x10000, which Metal works out from the version the device sets (1.0.0). The
|
||||
// member reads no device state, so it is called with the class as `self`.
|
||||
void checkTargetDeviceArchitecture(Class device)
|
||||
{
|
||||
SEL sel = sel_registerName("targetDeviceArchitecture");
|
||||
Method m = class_getInstanceMethod(device, sel), base = class_getInstanceMethod(class_getSuperclass(device), sel);
|
||||
if (m == nullptr || (base != nullptr && method_getImplementation(m) == method_getImplementation(base))) {
|
||||
fail(@"the device does not answer targetDeviceArchitecture itself");
|
||||
return;
|
||||
}
|
||||
id a = ((id(*)(id, SEL))method_getImplementation(m))((id)device, sel);
|
||||
if (a == nil || strcmp(object_getClassName(a), "MTLTargetDeviceArchitecture") != 0) {
|
||||
fail([NSString stringWithFormat:@"targetDeviceArchitecture answers %@, not an MTLTargetDeviceArchitecture", a]);
|
||||
return;
|
||||
}
|
||||
const uint32_t cpuType = ((uint32_t(*)(id, SEL))objc_msgSend)(a, sel_registerName("cpuType"));
|
||||
const uint32_t subType = ((uint32_t(*)(id, SEL))objc_msgSend)(a, sel_registerName("subType"));
|
||||
const uint64_t driver = ((uint64_t(*)(id, SEL))objc_msgSend)(a, sel_registerName("driverVersion"));
|
||||
const uint32_t combined = ((uint32_t(*)(id, SEL))objc_msgSend)(a, sel_registerName("versionCombined"));
|
||||
if (cpuType != 0x01005247 || subType != 0 || driver != 0x10000 || combined != 0x10000)
|
||||
fail([NSString stringWithFormat:@"targetDeviceArchitecture answers cpuType 0x%x subType 0x%x driverVersion "
|
||||
@"0x%llx versionCombined 0x%x (want 0x1005247 0 0x10000 0x10000)",
|
||||
cpuType, subType, (unsigned long long)driver, combined]);
|
||||
}
|
||||
|
||||
// The device's refusals at a URL that Metal answers before it reads the URL: newArchiveWithURL:error:
|
||||
// a device without Metal 4's, and newBinaryLibraryWithOptions:url:error: of no option, "At least one
|
||||
// option must be set.", each at every URL, nil among them (measured: macOS 26.7.1, the AMD Radeon
|
||||
@@ -335,6 +366,7 @@ int main(int argc, char **argv)
|
||||
printf("FAIL: RgfxMetalDevice is not a subclass of IOGPUMetalDevice, of _MTLDevice\n");
|
||||
return 1;
|
||||
}
|
||||
checkTargetDeviceArchitecture(device);
|
||||
checkResidencySetAnswer(device);
|
||||
checkUrlRefusals(device);
|
||||
for (const Death &d : kDeaths)
|
||||
|
||||
@@ -1037,7 +1037,7 @@ supportsYCBCRFormatsXR base %base-spi
|
||||
supportsYCBCRPackedFormats12 base %base-spi
|
||||
supportsYCBCRPackedFormatsPQ base %base-spi
|
||||
supportsYCBCRPackedFormatsXR base %base-spi
|
||||
targetDeviceArchitecture base class 2 (the Macs diverge): the IOGPU base answers nil, the lane's answer. Each Mac answers an MTLTargetDeviceArchitecture naming its GPU compiler's target (measured: cpuType 0x1000013 subType 0x1a3 on the M3 Max, 0x1000014 0x1773 on the AMD 5300M, 0x1000015 0x950200 on the Intel UHD 630), an instruction set the host cannot run; nil names none
|
||||
targetDeviceArchitecture implemented class 4 (outside the envelope) for nil, which the IOGPU base answered and no Mac does: Metal's loader ends the process at nil (+[MTLLoader sliceIDForDevice:legacyDriverVersion:airntDriverVersion:]), and MTLAssetUpgraderD ended at every app installed in the guest. Every Mac answers Metal's MTLTargetDeviceArchitecture naming its own compiler's target (measured, tools/oracle/oracle_archtype.m: cpuType 0x1000013 subType 0x1a3 driverVersion and versionCombined 0x30000 on the M3 Max, 0x1000014 0x1773 0x7d4 0xe0002 on the AMD 5300M, 0x1000015 0x950200 0x1a0701 0x1a0701 on the Intel UHD 630), so the device answers one naming its own: cpuType 0x01005247 (its PCI device id), which no Metal slice carries, subType 0, version 1.0.0 and driverVersion 0x10000
|
||||
targetDeviceInfo base %base-spi
|
||||
tensorSizeAndAlignWithDescriptor: unsupported tensors
|
||||
threadsPerCompilerProcess base %base-spi
|
||||
|
||||
Reference in new issue
Block a user