authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2025-04-19 20:33:03+03:30
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-21 09:49:19+02:00
log13541bc1c0f97c39591c2ba82e9a8c7979ce7b63
tree25c34bac12c22a6a199bf2c81f7715460c76b596
parentf01833e03eea786a05635cfbe142f581e9281b51

Module: ignore `xnack` and `sramecc` features on some gpu models


3 files changed, 56 insertions(+), 0 deletions(-)

src/Compilation.zig+4
...@@ -5989,6 +5989,10 @@ pub fn addCCArgs(...@@ -5989,6 +5989,10 @@ pub fn addCCArgs(
5989 std.mem.startsWith(u8, llvm_name, "hard-float"))5989 std.mem.startsWith(u8, llvm_name, "hard-float"))
5990 continue;5990 continue;
59915991
5992 // Ignore these until we figure out how to handle the concept of omitting features.
5993 // See https://github.com/ziglang/zig/issues/23539
5994 if (target_util.isDynamicAMDGCNFeature(target, feature)) continue;
5995
5992 argv.appendSliceAssumeCapacity(&[_][]const u8{ "-Xclang", "-target-feature", "-Xclang" });5996 argv.appendSliceAssumeCapacity(&[_][]const u8{ "-Xclang", "-target-feature", "-Xclang" });
5993 const plus_or_minus = "-+"[@intFromBool(is_enabled)];5997 const plus_or_minus = "-+"[@intFromBool(is_enabled)];
5994 const arg = try std.fmt.allocPrint(arena, "{c}{s}", .{ plus_or_minus, llvm_name });5998 const arg = try std.fmt.allocPrint(arena, "{c}{s}", .{ plus_or_minus, llvm_name });
src/Package/Module.zig+4
...@@ -335,6 +335,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -335,6 +335,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
335 // Append disabled features after enabled ones, so that their effects aren't overwritten.335 // Append disabled features after enabled ones, so that their effects aren't overwritten.
336 for (target.cpu.arch.allFeaturesList()) |feature| {336 for (target.cpu.arch.allFeaturesList()) |feature| {
337 if (feature.llvm_name) |llvm_name| {337 if (feature.llvm_name) |llvm_name| {
338 // Ignore these until we figure out how to handle the concept of omitting features.
339 // See https://github.com/ziglang/zig/issues/23539
340 if (target_util.isDynamicAMDGCNFeature(target, feature)) continue;
341
338 const is_enabled = target.cpu.features.isEnabled(feature.index);342 const is_enabled = target.cpu.features.isEnabled(feature.index);
339343
340 if (is_enabled) {344 if (is_enabled) {
src/target.zig+48
...@@ -486,6 +486,54 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {...@@ -486,6 +486,54 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {
486 };486 };
487}487}
488488
489pub fn isDynamicAMDGCNFeature(target: std.Target, feature: std.Target.Cpu.Feature) bool {
490 if (target.cpu.arch != .amdgcn) return false;
491
492 const sramecc_only = &[_]*const std.Target.Cpu.Model{
493 &std.Target.amdgcn.cpu.gfx1010,
494 &std.Target.amdgcn.cpu.gfx1011,
495 &std.Target.amdgcn.cpu.gfx1012,
496 &std.Target.amdgcn.cpu.gfx1013,
497 };
498 const xnack_or_sramecc = &[_]*const std.Target.Cpu.Model{
499 &std.Target.amdgcn.cpu.gfx1030,
500 &std.Target.amdgcn.cpu.gfx1031,
501 &std.Target.amdgcn.cpu.gfx1032,
502 &std.Target.amdgcn.cpu.gfx1033,
503 &std.Target.amdgcn.cpu.gfx1034,
504 &std.Target.amdgcn.cpu.gfx1035,
505 &std.Target.amdgcn.cpu.gfx1036,
506 &std.Target.amdgcn.cpu.gfx1100,
507 &std.Target.amdgcn.cpu.gfx1101,
508 &std.Target.amdgcn.cpu.gfx1102,
509 &std.Target.amdgcn.cpu.gfx1103,
510 &std.Target.amdgcn.cpu.gfx1150,
511 &std.Target.amdgcn.cpu.gfx1151,
512 &std.Target.amdgcn.cpu.gfx1152,
513 &std.Target.amdgcn.cpu.gfx1153,
514 &std.Target.amdgcn.cpu.gfx1200,
515 &std.Target.amdgcn.cpu.gfx1201,
516 };
517 const feature_tag: std.Target.amdgcn.Feature = @enumFromInt(feature.index);
518
519 if (feature_tag == .sramecc) {
520 if (std.mem.indexOfScalar(
521 *const std.Target.Cpu.Model,
522 sramecc_only ++ xnack_or_sramecc,
523 target.cpu.model,
524 )) |_| return true;
525 }
526 if (feature_tag == .xnack) {
527 if (std.mem.indexOfScalar(
528 *const std.Target.Cpu.Model,
529 xnack_or_sramecc,
530 target.cpu.model,
531 )) |_| return true;
532 }
533
534 return false;
535}
536
489pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {537pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
490 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it538 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it
491 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc539 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc