aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorgwenzek <gwenzek@users.noreply.github.com>2022-02-21 20:05:27 +0100
committerGitHub <noreply@github.com>2022-02-21 14:05:27 -0500
commit628e9e6d040979bd0a2cba05e854014dee5a7d55 (patch)
treeb2d86569b54d792808b608402cc9d1ea8ec7d161 /test
parentd8da9a01fcfebf14a9f262cabf36f1c0767d2e2b (diff)
downloadzig-628e9e6d040979bd0a2cba05e854014dee5a7d55.tar.gz
zig-628e9e6d040979bd0a2cba05e854014dee5a7d55.zip
enable Gpu address spaces (#10884)
Diffstat (limited to 'test')
-rw-r--r--test/cases.zig1
-rw-r--r--test/stage2/nvptx.zig57
2 files changed, 58 insertions, 0 deletions
diff --git a/test/cases.zig b/test/cases.zig
index 20dece3c7d..a65baeeef6 100644
--- a/test/cases.zig
+++ b/test/cases.zig
@@ -16,4 +16,5 @@ pub fn addCases(ctx: *TestContext) !void {
try @import("stage2/riscv64.zig").addCases(ctx);
try @import("stage2/plan9.zig").addCases(ctx);
try @import("stage2/x86_64.zig").addCases(ctx);
+ try @import("stage2/nvptx.zig").addCases(ctx);
}
diff --git a/test/stage2/nvptx.zig b/test/stage2/nvptx.zig
new file mode 100644
index 0000000000..95ca79d448
--- /dev/null
+++ b/test/stage2/nvptx.zig
@@ -0,0 +1,57 @@
+const std = @import("std");
+const TestContext = @import("../../src/test.zig").TestContext;
+
+const nvptx = std.zig.CrossTarget{
+ .cpu_arch = .nvptx64,
+ .os_tag = .cuda,
+};
+
+pub fn addCases(ctx: *TestContext) !void {
+ {
+ var case = ctx.exeUsingLlvmBackend("simple addition and subtraction", nvptx);
+
+ case.compiles(
+ \\fn add(a: i32, b: i32) i32 {
+ \\ return a + b;
+ \\}
+ \\
+ \\pub export fn main(a: i32, out: *i32) callconv(.PtxKernel) void {
+ \\ const x = add(a, 7);
+ \\ var y = add(2, 0);
+ \\ y -= x;
+ \\ out.* = y;
+ \\}
+ );
+ }
+
+ {
+ var case = ctx.exeUsingLlvmBackend("read special registers", nvptx);
+
+ case.compiles(
+ \\fn tid() usize {
+ \\ var tid = asm volatile ("mov.u32 \t$0, %tid.x;"
+ \\ : [ret] "=r" (-> u32),
+ \\ );
+ \\ return @as(usize, tid);
+ \\}
+ \\
+ \\pub export fn main(a: []const i32, out: []i32) callconv(.PtxKernel) void {
+ \\ const i = tid();
+ \\ out[i] = a[i] + 7;
+ \\}
+ );
+ }
+
+ {
+ var case = ctx.exeUsingLlvmBackend("address spaces", nvptx);
+
+ case.compiles(
+ \\var x: u32 addrspace(.global) = 0;
+ \\
+ \\pub export fn increment(out: *i32) callconv(.PtxKernel) void {
+ \\ x += 1;
+ \\ out.* = x;
+ \\}
+ );
+ }
+}