authorgravatar for gwenzek@users.noreply.github.comGuillaume Wenzek <gwenzek@users.noreply.github.com> 2022-10-04 07:31:36+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-15 10:39:19-07:00
logb425d887375132a915a5cd2baf7958f273732ee1
tree27109965e744c8e63dcb2bf6e8efb2af30309c42
parent577f0aa54b49445d4248cf839346ce3f8632ea39

re-enable nvptx tests


2 files changed, 37 insertions(+), 7 deletions(-)

test/cases.zig+1-2
...@@ -4,6 +4,5 @@ const TestContext = @import("../src/test.zig").TestContext;...@@ -4,6 +4,5 @@ const TestContext = @import("../src/test.zig").TestContext;
4pub fn addCases(ctx: *TestContext) !void {4pub fn addCases(ctx: *TestContext) !void {
5 try @import("compile_errors.zig").addCases(ctx);5 try @import("compile_errors.zig").addCases(ctx);
6 try @import("stage2/cbe.zig").addCases(ctx);6 try @import("stage2/cbe.zig").addCases(ctx);
7 // https://github.com/ziglang/zig/issues/109687 try @import("stage2/nvptx.zig").addCases(ctx);
8 //try @import("stage2/nvptx.zig").addCases(ctx);
9}8}
test/stage2/nvptx.zig+36-5
...@@ -23,11 +23,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -23,11 +23,10 @@ pub fn addCases(ctx: *TestContext) !void {
23 var case = addPtx(ctx, "nvptx: read special registers");23 var case = addPtx(ctx, "nvptx: read special registers");
2424
25 case.compiles(25 case.compiles(
26 \\fn threadIdX() usize {26 \\fn threadIdX() u32 {
27 \\ var tid = asm volatile ("mov.u32 \t$0, %tid.x;"27 \\ return asm ("mov.u32 \t%[r], %tid.x;"
28 \\ : [ret] "=r" (-> u32),28 \\ : [r] "=r" (-> utid),
29 \\ );29 \\ );
30 \\ return @as(usize, tid);
31 \\}30 \\}
32 \\31 \\
33 \\pub export fn special_reg(a: []const i32, out: []i32) callconv(.PtxKernel) void {32 \\pub export fn special_reg(a: []const i32, out: []i32) callconv(.PtxKernel) void {
...@@ -49,6 +48,38 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -49,6 +48,38 @@ pub fn addCases(ctx: *TestContext) !void {
49 \\}48 \\}
50 );49 );
51 }50 }
51
52 {
53 var case = addPtx(ctx, "nvptx: reduce in shared mem");
54 case.compiles(
55 \\fn threadIdX() u32 {
56 \\ return asm ("mov.u32 \t%[r], %tid.x;"
57 \\ : [r] "=r" (-> utid),
58 \\ );
59 \\}
60 \\
61 \\ var _sdata: [1024]f32 addrspace(.shared) = undefined;
62 \\ pub export fn reduceSum(d_x: []const f32, out: *f32) callconv(ptx.Kernel) void {
63 \\ var sdata = @addrSpaceCast(.generic, &_sdata);
64 \\ const tid: u32 = threadIdX();
65 \\ var sum = d_x[tid];
66 \\ sdata[tid] = sum;
67 \\ asm volatile ("bar.sync \t0;");
68 \\ var s: u32 = 512;
69 \\ while (s > 0) : (s = s >> 1) {
70 \\ if (tid < s) {
71 \\ sum += sdata[tid + s];
72 \\ sdata[tid] = sum;
73 \\ }
74 \\ asm volatile ("bar.sync \t0;");
75 \\ }
76 \\
77 \\ if (tid == 0) {
78 \\ out.* = sum;
79 \\ }
80 \\ }
81 );
82 }
52}83}
5384
54const nvptx_target = std.zig.CrossTarget{85const nvptx_target = std.zig.CrossTarget{