Skip to content

Commit

Permalink
Merge pull request #168 from JuliaGPU/tb/femtocleaner
Browse files Browse the repository at this point in the history
Run FemtoCleaner.
  • Loading branch information
maleadt authored Oct 13, 2018
2 parents b9a28d6 + a02b1b8 commit c535f37
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 131 deletions.
4 changes: 2 additions & 2 deletions examples/hands_on_opencl/ex06/helper.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Base: error

function error{T}(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T})
function error(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T}) where T
cval = Float32(Pdim * AVAL * BVAL)
errsq = 0f0
for i in 1:Ndim
Expand All @@ -12,7 +12,7 @@ function error{T}(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T})
return errsq
end

function results{T}(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T}, run_time)
function results(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T}, run_time) where T
mflops = 2.0 * Mdim * Ndim * Pdim/(1000000.0* run_time)
println("$run_time seconds at $mflops MFLOPS")
errsq = error(Mdim, Ndim, Pdim, C)
Expand Down
4 changes: 2 additions & 2 deletions examples/hands_on_opencl/ex06/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ h_B = fill(Float32(BVAL), sizeB)
h_C = Vector{Float32}(sizeC)

# %20 improvment using @inbounds
function seq_mat_mul_sdot{T}(Mdim::Int, Ndim::Int, Pdim::Int,
A::Array{T}, B::Array{T}, C::Array{T})
function seq_mat_mul_sdot(Mdim::Int, Ndim::Int, Pdim::Int,
A::Array{T}, B::Array{T}, C::Array{T}) where T
for i in 1:Ndim
for j in 1:Mdim
tmp = zero(Float32)
Expand Down
4 changes: 2 additions & 2 deletions examples/hands_on_opencl/ex07/helper.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Base: error

function error{T}(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T})
function error(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T}) where T
cval = Float32(Pdim * AVAL * BVAL)
errsq = 0f0
for i in 1:Ndim
Expand All @@ -12,7 +12,7 @@ function error{T}(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T})
return errsq
end

function results{T}(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T}, run_time)
function results(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T}, run_time) where T
mflops = 2.0 * Mdim * Ndim * Pdim/(1000000.0* run_time)
println("$run_time seconds at $mflops MFLOPS")
errsq = error(Mdim, Ndim, Pdim, C)
Expand Down
4 changes: 2 additions & 2 deletions examples/hands_on_opencl/ex07/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ h_B = fill(Float32(BVAL), sizeB)
h_C = Vector{Float32}(sizeC)

# %20 improvment using @inbounds
function seq_mat_mul_sdot{T}(Mdim::Int, Ndim::Int, Pdim::Int,
A::Array{T}, B::Array{T}, C::Array{T})
function seq_mat_mul_sdot(Mdim::Int, Ndim::Int, Pdim::Int,
A::Array{T}, B::Array{T}, C::Array{T}) where T
for i in 1:Ndim
for j in 1:Mdim
tmp = zero(Float32)
Expand Down
4 changes: 2 additions & 2 deletions examples/hands_on_opencl/ex08/helper.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function error{T}(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T})
function error(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T}) where T
cval = Float32(Pdim * AVAL * BVAL)
errsq = 0f0
for i in 1:Ndim
Expand All @@ -13,7 +13,7 @@ function error{T}(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T})
return errsq
end

function results{T}(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T}, run_time)
function results(Mdim::Int, Ndim::Int, Pdim::Int, C::Array{T}, run_time) where T
mflops = 2.0 * Mdim * Ndim * Pdim/(1000000.0* run_time)
println("$run_time seconds at $mflops MFLOPS")
errsq = error(Mdim, Ndim, Pdim, C)
Expand Down
4 changes: 2 additions & 2 deletions examples/hands_on_opencl/ex08/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ h_B = fill(Float32(BVAL), sizeB)
h_C = Vector{Float32}(sizeC)

# %20 improvment using @inbounds
function seq_mat_mul_sdot{T}(Mdim::Int, Ndim::Int, Pdim::Int,
A::Array{T}, B::Array{T}, C::Array{T})
function seq_mat_mul_sdot(Mdim::Int, Ndim::Int, Pdim::Int,
A::Array{T}, B::Array{T}, C::Array{T}) where T
for i in 1:Ndim
for j in 1:Mdim
tmp = zero(Float32)
Expand Down
4 changes: 2 additions & 2 deletions src/OpenCL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module cl
abstract type CLObject end

Base.hash(x::CLObject) = hash(pointer(x))
Base.isequal{T <: CLObject}(x :: T, y :: T) = Base.hash(x) == Base.hash(y)
Base.:(==){T <: CLObject}(x :: T, y :: T) = Base.hash(x) == Base.hash(y)
Base.isequal(x :: T, y :: T) where {T <: CLObject} = Base.hash(x) == Base.hash(y)
Base.:(==)(x :: T, y :: T) where {T <: CLObject} = Base.hash(x) == Base.hash(y)

# OpenCL Types
include("types.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const CL_callback = Ptr{Void}
abstract type CL_user_data_tag end
const CL_user_data = Ptr{CL_user_data_tag}

Base.cconvert{T}(::Type{Ptr{CL_user_data_tag}}, obj::T) = Ref{T}(obj)
Base.unsafe_convert{T}(::Type{Ptr{CL_user_data_tag}}, ref::Ref{T}) =
Base.cconvert(::Type{Ptr{CL_user_data_tag}}, obj::T) where {T} = Ref{T}(obj)
Base.unsafe_convert(::Type{Ptr{CL_user_data_tag}}, ref::Ref{T}) where {T} =
Ptr{CL_user_data_tag}(isbits(T) ? pointer_from_objref(ref) : pointer_from_objref(ref[]))

Base.cconvert(::Type{Ptr{CL_user_data_tag}}, ptr::Ptr) = ptr
Expand Down
28 changes: 14 additions & 14 deletions src/array.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

type CLArray{T, N} <: CLObject
mutable struct CLArray{T, N} <: CLObject
ctx::Context
queue::CmdQueue
buffer::Buffer{T}
Expand All @@ -11,22 +11,22 @@ const CLVector{T} = CLArray{T,1}

## constructors

function CLArray{T}(buf::Buffer{T}, queue::CmdQueue, sz::Tuple{Vararg{Int}})
function CLArray(buf::Buffer{T}, queue::CmdQueue, sz::Tuple{Vararg{Int}}) where T
ctx = context(buf)
CLArray(ctx, queue, buf, sz)
end

function CLArray{T,N}(queue::CmdQueue,
flags::Tuple{Vararg{Symbol}},
hostarray::AbstractArray{T,N})
function CLArray(queue::CmdQueue,
flags::Tuple{Vararg{Symbol}},
hostarray::AbstractArray{T,N}) where {T,N}
ctx = context(queue)
buf = Buffer(T, ctx, flags, hostbuf=hostarray)
sz = size(hostarray)
CLArray(ctx, queue, buf, sz)
end

function CLArray{T,N}(queue::CmdQueue, hostarray::AbstractArray{T,N};
flags=(:rw, :copy))
function CLArray(queue::CmdQueue, hostarray::AbstractArray{T,N};
flags=(:rw, :copy)) where {T,N}
CLArray(queue, (:rw, :copy), hostarray)
end

Expand All @@ -37,7 +37,7 @@ function Base.copy(
CLArray(ctx, queue, buffer, size)
end

function Base.deepcopy{T,N}(A::CLArray{T,N})
function Base.deepcopy(A::CLArray{T,N}) where {T,N}
new_buf = Buffer(T, A.ctx, prod(A.size))
copy!(A.queue, new_buf, A.buffer)
return CLArray(A.ctx, A.queue, new_buf, A.size)
Expand All @@ -47,7 +47,7 @@ end
"""
Create in device memory array of type `t` and size `dims` filled by value `x`.
"""
function Base.fill{T}(::Type{T}, q::CmdQueue, x::T, dims...)
function Base.fill(::Type{T}, q::CmdQueue, x::T, dims...) where T
ctx = info(q, :context)
v = opencl_version(ctx)
if v.major == 1 && v.minor >= 2
Expand All @@ -59,9 +59,9 @@ function Base.fill{T}(::Type{T}, q::CmdQueue, x::T, dims...)
return CLArray(buf, q, dims)
end

Base.zeros{T}(::Type{T}, q::CmdQueue, dims...) = fill(T, q, T(0), dims...)
Base.zeros(::Type{T}, q::CmdQueue, dims...) where {T} = fill(T, q, T(0), dims...)
Base.zeros(q::CmdQueue, dims...) = fill(Float64, q, Float64(0), dims...)
Base.ones{T}(::Type{T}, q::CmdQueue, dims...) = fill(T, q, T(1), dims...)
Base.ones(::Type{T}, q::CmdQueue, dims...) where {T} = fill(T, q, T(1), dims...)
Base.ones(q::CmdQueue, dims...) = fill(Float64, q, Float64(1), dims...)


Expand All @@ -71,7 +71,7 @@ buffer(A::CLArray) = A.buffer
Base.pointer(A::CLArray) = A.buffer.id
context(A::CLArray) = context(A.buffer)
queue(A::CLArray) = A.queue
Base.eltype{T, N}(A::CLArray{T, N}) = T
Base.eltype(A::CLArray{T, N}) where {T, N} = T
Base.size(A::CLArray) = A.size
Base.size(A::CLArray, dim::Integer) = A.size[dim]
Base.ndims(A::CLArray) = length(size(A))
Expand All @@ -85,12 +85,12 @@ end

## show

Base.show{T,N}(io::IO, A::CLArray{T,N}) =
Base.show(io::IO, A::CLArray{T,N}) where {T,N} =
print(io, "CLArray{$T,$N}($(buffer(A)),$(size(A)))")

## to_host

function to_host{T,N}(A::CLArray{T,N}; queue=A.queue)
function to_host(A::CLArray{T,N}; queue=A.queue) where {T,N}
hA = Array{T}(size(A))
copy!(queue, hA, buffer(A))
return hA
Expand Down
Loading

0 comments on commit c535f37

Please sign in to comment.