Skip to content

Commit 13541bc

Browse files
alichraghialexrp
authored andcommitted
Module: ignore xnack and sramecc features on some gpu models
1 parent f01833e commit 13541bc

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/Compilation.zig

+4
Original file line numberDiff line numberDiff line change
@@ -5989,6 +5989,10 @@ pub fn addCCArgs(
59895989
std.mem.startsWith(u8, llvm_name, "hard-float"))
59905990
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+
59925996
argv.appendSliceAssumeCapacity(&[_][]const u8{ "-Xclang", "-target-feature", "-Xclang" });
59935997
const plus_or_minus = "-+"[@intFromBool(is_enabled)];
59945998
const arg = try std.fmt.allocPrint(arena, "{c}{s}", .{ plus_or_minus, llvm_name });

src/Package/Module.zig

+4
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
335335
// Append disabled features after enabled ones, so that their effects aren't overwritten.
336336
for (target.cpu.arch.allFeaturesList()) |feature| {
337337
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+
338342
const is_enabled = target.cpu.features.isEnabled(feature.index);
339343

340344
if (is_enabled) {

src/target.zig

+48
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,54 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {
486486
};
487487
}
488488

489+
pub 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+
489537
pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
490538
// LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it
491539
// into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc

0 commit comments

Comments
 (0)