-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
\\} | ||
); | ||
} | ||
} |