-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from JuliaGPU/tb/compile
Make the compilation example first-class functionality.
- Loading branch information
Showing
7 changed files
with
124 additions
and
106 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
using CUDAdrv, CUDArt | ||
using Base.Test | ||
|
||
using Compat | ||
|
||
dev = CuDevice(0) | ||
ctx = CuContext(dev) | ||
|
||
CUDArt.@compile dev kernel_vadd """ | ||
__global__ void kernel_vadd(const float *a, const float *b, float *c) | ||
{ | ||
int i = blockIdx.x *blockDim.x + threadIdx.x; | ||
c[i] = a[i] + b[i]; | ||
} | ||
""" | ||
|
||
dims = (3,4) | ||
a = round.(rand(Float32, dims) * 100) | ||
b = round.(rand(Float32, dims) * 100) | ||
|
||
d_a = CuArray(a) | ||
d_b = CuArray(b) | ||
d_c = similar(d_a) | ||
|
||
len = prod(dims) | ||
cudacall(kernel_vadd, len, 1, Tuple{Ptr{Cfloat},Ptr{Cfloat},Ptr{Cfloat}}, d_a, d_b, d_c) | ||
c = Array(d_c) | ||
@test a+b ≈ c | ||
|
||
destroy!(ctx) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using CUDArt | ||
import CUDAdrv | ||
using Base.Test | ||
|
||
dev = CUDAdrv.CuDevice(0) | ||
ctx = CUDAdrv.CuContext(dev) | ||
|
||
CUDArt.clean_cache() # for deterministic testing purposes | ||
|
||
|
||
## basic compilation & execution | ||
|
||
let | ||
CUDArt.@compile dev kernel """ | ||
__global__ void kernel() | ||
{ | ||
} | ||
""" | ||
|
||
CUDAdrv.cudacall(kernel, 1, 1, ()) | ||
end | ||
|
||
@test_throws CompileError let | ||
CUDArt.@compile dev kernel """ | ||
__global__ void kernel() | ||
{ | ||
invalid code | ||
} | ||
""" | ||
end | ||
|
||
@test_throws CUDAdrv.CuError let | ||
CUDArt.@compile dev wrongname """ | ||
__global__ void kernel() | ||
{ | ||
} | ||
""" | ||
end | ||
|
||
|
||
## argument passing | ||
|
||
dims = (16, 16) | ||
len = prod(dims) | ||
|
||
CUDArt.@compile dev kernel_copy """ | ||
__global__ void kernel_copy(const float *input, float *output) | ||
{ | ||
int i = blockIdx.x * blockDim.x + threadIdx.x; | ||
output[i] = input[i]; | ||
} | ||
""" | ||
|
||
let | ||
input = round.(rand(Cfloat, dims) * 100) | ||
|
||
input_dev = CUDAdrv.CuArray(input) | ||
output_dev = CUDAdrv.CuArray{Cfloat}(dims) | ||
|
||
CUDAdrv.cudacall(kernel_copy, 1, len, | ||
Tuple{Ptr{Cfloat}, Ptr{Cfloat}}, | ||
input_dev, output_dev) | ||
output = Array(output_dev) | ||
@test input ≈ output | ||
end | ||
|
||
|
||
CUDAdrv.destroy!(ctx) |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
include("gc.jl") | ||
include("test.jl") | ||
include("compile.jl") | ||
include("examples.jl") |