Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sd/v05 #25

Merged
merged 16 commits into from
Apr 3, 2017
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*~
.juliahistory
.juliahistory
deps/deps.jl
deps/downloads
deps/package
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,3 @@ before_install:
tar -xf clBLAS-${CLBLAS}.${PATCH}-Linux-x64.tar.gz;
export LD_LIBRARY_PATH=${HOME}/build/JuliaGPU/CLBLAS.jl/clBLAS-${CLBLAS}.${PATCH}-Linux-x64/lib64:${LD_LIBRARY_PATH};
fi;

script:
- julia -e 'Pkg.init(); Pkg.clone(pwd())'
- julia -e 'Pkg.checkout("OpenCL");'
- julia -e 'using CLBLAS; @assert isdefined(:CLBLAS); @assert typeof(CLBLAS) === Module'
- julia -e 'Pkg.test("CLBLAS")'

# after_success:
# - julia -e 'Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.5-
julia 0.5
OpenCL
BinDeps
41 changes: 41 additions & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using BinDeps
@BinDeps.setup
libnames = ["libCLBLAS", "clBLAS", "libclBLAS"]
libCLBLAS = library_dependency("libCLBLAS", aliases = libnames)
archive = "package"
libpath = "package/bin"
baseurl = "https://github.com/clMathLibraries/clBLAS/releases/download/v2.12/clBLAS-2.12.0-"

# download a pre-compiled binary (built by GLFW)
if is_windows()
if Sys.ARCH == :x86_64
uri = URI(baseurl * "Windows-x64.zip")
provides(
Binaries, uri,
libCLBLAS, unpacked_dir = archive,
installed_libpath = libpath, os = :Windows
)
else
error("Only 64 bits windows supported with automatic build")
end
end

if is_linux()
provides(AptGet, "libclblas-dev", libCLBLAS)
if Sys.ARCH == :x86_64
uri = URI(baseurl * "Linux-x64.tar.gz")
provides(
Binaries, uri,
libCLBLAS, unpacked_dir = archive,
installed_libpath = libpath, os = :Linux
)
end
end
if is_apple()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean @static if is_linux() as it's used above? Although I'm not sure if @static makes any difference in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it shouldn't ;)

error("""
OSX not oficially supported.
Find manual build instructions on: https://github.com/clMathLibraries/clBLAS/wiki/Build
""")
end

@BinDeps.install Dict("libCLBLAS" => "libCLBLAS")
6 changes: 3 additions & 3 deletions examples/AddNumbers.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import OpenCL
const cl = OpenCL
using OpenCL: cl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using OpenCL should be enough


const ARRAY_SIZE = 64
sum = Array(Float32, 2)
data = Array(Float32, ARRAY_SIZE)
sum = Vector{Float32}(2)
data = Vector{Float32}(ARRAY_SIZE)
for i in 1:ARRAY_SIZE
data[i] = i*1.0
end
Expand Down
4 changes: 1 addition & 3 deletions examples/DeviceInfo.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import CLBLAS
import OpenCL

const cl = OpenCL
using OpenCL: cl
const clblas = CLBLAS

for platform in cl.platforms()
Expand Down
97 changes: 48 additions & 49 deletions examples/clblasSasum.jl
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
import CLBLAS
import OpenCL

const clblas = CLBLAS
clblas.setup()

const cl = OpenCL

device, ctx, queue = clblas.get_next_compute_context()

N = unsigned(5)
data = Array(Float32, 5)
data[1] = 1.1
data[2] = 2.22
data[3] = 3.333
data[4] = 4.4444
data[5] = 5.55555

bufX = cl.Buffer(Float32, ctx, (:r, :copy),hostbuf=data)
bufAsum = cl.Buffer(Float32, ctx, :w, length(bufX))
scratchBuff = cl.Buffer(Float32, ctx, :rw, length(bufX))

offx = unsigned(0)
incx = cl.cl_int(1)
ncq = cl.cl_uint(1)
clq = queue.id
newl = cl.cl_uint(0)

event = cl.UserEvent(ctx, retain=true)
ptrEvent = [event.id]

clblas.clblasSasum( N, bufAsum.id, 0, bufX.id, 0, incx, scratchBuff.id,
ncq, [clq], newl, C_NULL, ptrEvent);

cl.api.clWaitForEvents(cl.cl_uint(1), ptrEvent)

result = Array(Float32, length(1))
cl.enqueue_read_buffer(queue, bufAsum, result, unsigned(0), nothing, true)

expected = data[1:end] |> sum
println(result)
println("------------")
println(expected)

try
@assert(isapprox(norm(expected - result[1]), zero(Float32)))
info("success!")
finally
clblas.teardown()
end

const clblas = CLBLAS
clblas.setup()

using OpenCL: cl

device, ctx, queue = clblas.get_next_compute_context()

N = Unsigned(5)
data = Vector{Float32}(5)
data[1] = 1.1
data[2] = 2.22
data[3] = 3.333
data[4] = 4.4444
data[5] = 5.55555

bufX = cl.Buffer(Float32, ctx, (:r, :copy),hostbuf=data)
bufAsum = cl.Buffer(Float32, ctx, :w, length(bufX))
scratchBuff = cl.Buffer(Float32, ctx, :rw, length(bufX))

offx = Unsigned(0)
incx = cl.cl_int(1)
ncq = cl.cl_uint(1)
clq = queue.id
newl = cl.cl_uint(0)

event = cl.UserEvent(ctx, retain=true)
ptrEvent = [event.id]

clblas.clblasSasum( N, bufAsum.id, 0, bufX.id, 0, incx, scratchBuff.id,
ncq, [clq], newl, C_NULL, ptrEvent);

cl.api.clWaitForEvents(cl.cl_uint(1), ptrEvent)

result = Vector{Float32}(length(1))
cl.enqueue_read_buffer(queue, bufAsum, result, Unsigned(0), nothing, true)

expected = data[1:end] |> sum
println(result)
println("------------")
println(expected)

try
@assert(isapprox(norm(expected - result[1]), zero(Float32)))
info("success!")
finally
clblas.teardown()
end
117 changes: 58 additions & 59 deletions examples/clblasSaxpy.jl
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
import CLBLAS
import OpenCL

const clblas = CLBLAS
clblas.setup()

const cl = OpenCL

device, ctx, queue = clblas.get_next_compute_context()

N = unsigned(5)
alpha = cl.cl_float(12)
data = Array(Float32, 5)
data[1] = 1.1
data[2] = 2.22
data[3] = 3.333
data[4] = 4.4444
data[5] = 5.55555

dat = Array(Float32, 5)
dat[1] = 6.1
dat[2] = 7.22
dat[3] = 8.333
dat[4] = 9.4444
dat[5] = 10.55555

bufX = cl.Buffer(Float32, ctx, (:rw, :copy),hostbuf=data)
bufY = cl.Buffer(Float32, ctx, (:rw, :copy),hostbuf=dat)

offx = unsigned(0)
incx = cl.cl_int(1)
incy = cl.cl_int(1)
ncq = cl.cl_uint(1)
clq = queue.id
newl = cl.cl_uint(0)

event = cl.UserEvent(ctx, retain=true)
ptrEvent = [event.id]

clblas.clblasSaxpy( N, alpha, bufX.id, 0, incx, bufY.id, 0, incy,
ncq, [clq], newl, C_NULL, ptrEvent);

cl.api.clWaitForEvents(cl.cl_uint(1), ptrEvent)

result = Array(Float32, length(bufY))
cl.enqueue_read_buffer(queue, bufY, result, unsigned(0), nothing, true)

#Y←αX+Y
expected = alpha * data + dat
println(result)
println("------------")
println(expected)

try
for i in 1:length(result)
@assert(isapprox(norm(expected[i] - result[i]), zero(Float32), atol=0.00001))
end
info("success!")
finally
clblas.teardown()

const clblas = CLBLAS
clblas.setup()

using OpenCL: cl

device, ctx, queue = clblas.get_next_compute_context()

N = unsigned(5)
alpha = cl.cl_float(12)
data = Array(Float32, 5)
data[1] = 1.1
data[2] = 2.22
data[3] = 3.333
data[4] = 4.4444
data[5] = 5.55555

dat = Array(Float32, 5)
dat[1] = 6.1
dat[2] = 7.22
dat[3] = 8.333
dat[4] = 9.4444
dat[5] = 10.55555

bufX = cl.Buffer(Float32, ctx, (:rw, :copy),hostbuf=data)
bufY = cl.Buffer(Float32, ctx, (:rw, :copy),hostbuf=dat)

offx = unsigned(0)
incx = cl.cl_int(1)
incy = cl.cl_int(1)
ncq = cl.cl_uint(1)
clq = queue.id
newl = cl.cl_uint(0)

event = cl.UserEvent(ctx, retain=true)
ptrEvent = [event.id]

clblas.clblasSaxpy( N, alpha, bufX.id, 0, incx, bufY.id, 0, incy,
ncq, [clq], newl, C_NULL, ptrEvent);

cl.api.clWaitForEvents(cl.cl_uint(1), ptrEvent)

result = Array(Float32, length(bufY))
cl.enqueue_read_buffer(queue, bufY, result, unsigned(0), nothing, true)

#Y←αX+Y
expected = alpha * data + dat
println(result)
println("------------")
println(expected)

try
for i in 1:length(result)
@assert(isapprox(norm(expected[i] - result[i]), zero(Float32), atol=0.00001))
end
info("success!")
finally
clblas.teardown()
end
Loading