-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a native compiler, using SPIR-V IL. (#222)
- Loading branch information
Showing
44 changed files
with
1,892 additions
and
65 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
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
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 was deleted.
Oops, something went wrong.
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,27 @@ | ||
using OpenCL, pocl_jll, Test | ||
|
||
const source = """ | ||
__kernel void vadd(__global const float *a, | ||
__global const float *b, | ||
__global float *c) { | ||
int i = get_global_id(0); | ||
c[i] = a[i] + b[i]; | ||
}""" | ||
|
||
dims = (2,) | ||
a = round.(rand(Float32, dims) * 100) | ||
b = round.(rand(Float32, dims) * 100) | ||
c = similar(a) | ||
|
||
d_a = CLArray(a) | ||
d_b = CLArray(b) | ||
d_c = CLArray(c) | ||
|
||
prog = cl.Program(; source) |> cl.build! | ||
kern = cl.Kernel(prog, "vadd") | ||
|
||
len = prod(dims) | ||
clcall(kern, Tuple{Ptr{Float32}, Ptr{Float32}, Ptr{Float32}}, | ||
d_a, d_b, d_c; global_size=(len,)) | ||
c = Array(d_c) | ||
@test a+b ≈ c |
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,21 @@ | ||
using OpenCL, pocl_jll, Test | ||
|
||
function vadd(a, b, c) | ||
i = get_global_id() | ||
@inbounds c[i] = a[i] + b[i] | ||
return | ||
end | ||
|
||
dims = (2,) | ||
a = round.(rand(Float32, dims) * 100) | ||
b = round.(rand(Float32, dims) * 100) | ||
c = similar(a) | ||
|
||
d_a = CLArray(a) | ||
d_b = CLArray(b) | ||
d_c = CLArray(c) | ||
|
||
len = prod(dims) | ||
@opencl global_size=len vadd(d_a, d_b, d_c) | ||
c = Array(d_c) | ||
@test a+b ≈ c |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,9 @@ | ||
name = "SPIRVIntrinsics" | ||
uuid = "71d1d633-e7e8-4a92-83a1-de8814b09ba8" | ||
authors = ["Tim Besard <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04" | ||
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0" | ||
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" |
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,25 @@ | ||
module SPIRVIntrinsics | ||
|
||
using LLVM, LLVM.Interop | ||
using Core: LLVMPtr | ||
|
||
import ExprTools | ||
|
||
import SpecialFunctions | ||
|
||
include("pointer.jl") | ||
include("utils.jl") | ||
|
||
# OpenCL intrinsics | ||
# | ||
# we currently don't implement SPIR-V intrinsics directly, but rely on | ||
# the SPIR-V to LLVM translator supporting OpenCL intrinsics | ||
include("work_item.jl") | ||
include("synchronization.jl") | ||
include("memory.jl") | ||
include("printf.jl") | ||
include("math.jl") | ||
include("integer.jl") | ||
include("atomic.jl") | ||
|
||
end |
Oops, something went wrong.