Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Drop support for older versions of Julia 0.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Mar 27, 2018
1 parent a29616a commit 1cc999e
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 116 deletions.
176 changes: 82 additions & 94 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,121 +112,109 @@ Base.isequal(a::CuArray, b::CuArray) = a == b

## other

if VERSION >= v"0.7.0-DEV.2797"
Base.print_array(io::IO, a::CuArray) = Base.print_array(io, Array(a))
Base.show_vector(io::IO, a::CuArray; kwargs...) = Base.show_vector(io, Array(a); kwargs...)
else
Base.showarray(io::IO, a::CuArray, repr::Bool = true; kwargs...) =
Base.showarray(io, Array(a), repr; kwargs...)
end
Base.print_array(io::IO, a::CuArray) = Base.print_array(io, Array(a))
Base.show_vector(io::IO, a::CuArray; kwargs...) = Base.show_vector(io, Array(a); kwargs...)


## memory management

const copyfun = VERSION >= v"0.7.0-DEV.3057" ? :(copyto!) : :(copy!)

@eval begin
"""
$copyfun{T}(dst::CuArray{T}, src::Array{T})
Copy an array from a host array `src` to a device array `dst` in place. Both arrays should
have an equal length.
"""
function Base.$copyfun(dst::CuArray{T}, src::Array{T}) where T
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
Mem.upload!(dst.buf, pointer(src), length(src) * sizeof(T))
return dst
end
"""
copyto!{T}(dst::CuArray{T}, src::Array{T})
"""
$copyfun{T}(dst::Array{T}, src::CuArray{T})
Copy an array from a device array `src` to a host array `dst` in place. Both arrays should
have an equal length.
"""
function Base.$copyfun(dst::Array{T}, src::CuArray{T}) where T
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
Mem.download!(pointer(dst), src.buf, length(src) * sizeof(T))
return dst
Copy an array from a host array `src` to a device array `dst` in place. Both arrays should
have an equal length.
"""
function Base.copyto!(dst::CuArray{T}, src::Array{T}) where T
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
Mem.upload!(dst.buf, pointer(src), length(src) * sizeof(T))
return dst
end

"""
$copyfun{T}(dst::CuArray{T}, src::CuArray{T})
Copy an array from a device array `src` to a device array `dst` in place. Both arrays should
have an equal length.
"""
function Base.$copyfun(dst::CuArray{T}, src::CuArray{T}) where T
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
Mem.transfer!(dst.buf, src.buf, length(src) * sizeof(T))
return dst
end
"""
copyto!{T}(dst::Array{T}, src::CuArray{T})
"""
$copyfun{T}(dst::CuArray{T}, src::SubArray{T,N,<:DenseArray,I,true})
Copy an array view from a host array `src` to a device array `dst` in place. Both arrays
should have an equal length, and the view must have a contiguous memory layout.
"""
function Base.$copyfun(dst::CuArray{T}, src::SubArray{T,N,<:DenseArray,I,true}) where {T,N,I}
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
if any(strides(src) .!= strides(parent(src)))
throw(ArgumentError("Transfers from an array view require contiguous memory layout."))
end
Mem.upload!(dst.buf, pointer(src), length(src) * sizeof(T))
return dst
Copy an array from a device array `src` to a host array `dst` in place. Both arrays should
have an equal length.
"""
function Base.copyto!(dst::Array{T}, src::CuArray{T}) where T
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
Mem.download!(pointer(dst), src.buf, length(src) * sizeof(T))
return dst
end

"""
copyto!{T}(dst::CuArray{T}, src::CuArray{T})
function Base.$copyfun(dst::CuArray, src::SubArray)
throw(ArgumentError("Transfers from an array view require a contiguous memory layout."))
Copy an array from a device array `src` to a device array `dst` in place. Both arrays should
have an equal length.
"""
function Base.copyto!(dst::CuArray{T}, src::CuArray{T}) where T
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
Mem.transfer!(dst.buf, src.buf, length(src) * sizeof(T))
return dst
end

"""
copyto!{T}(dst::CuArray{T}, src::SubArray{T,N,<:DenseArray,I,true})
"""
$copyfun{T}(dst::SubArray{T,N,A,I,true}, src::CuArray{T})
Copy an array from a device array `src` to a host array view `dst` in place. Both arrays
should have an equal length, and the view must have a contiguous memory layout.
"""
function Base.$copyfun(dst::SubArray{T,N,<:DenseArray,I,true}, src::CuArray{T}) where {T,N,I}
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
if any(strides(dst) .!= strides(parent(dst)))
throw(ArgumentError("Transfers to an array view require contiguous memory layout."))
end
Mem.download!(pointer(dst), src.buf, length(src) * sizeof(T))
return dst
Copy an array view from a host array `src` to a device array `dst` in place. Both arrays
should have an equal length, and the view must have a contiguous memory layout.
"""
function Base.copyto!(dst::CuArray{T}, src::SubArray{T,N,<:DenseArray,I,true}) where {T,N,I}
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
if any(strides(src) .!= strides(parent(src)))
throw(ArgumentError("Transfers from an array view require contiguous memory layout."))
end
Mem.upload!(dst.buf, pointer(src), length(src) * sizeof(T))
return dst
end

function Base.copyto!(dst::CuArray, src::SubArray)
throw(ArgumentError("Transfers from an array view require a contiguous memory layout."))
end

"""
copyto!{T}(dst::SubArray{T,N,A,I,true}, src::CuArray{T})
function Base.$copyfun(dst::SubArray, src::CuArray)
throw(ArgumentError("Transfers to an array view require a contiguous memory layout."))
Copy an array from a device array `src` to a host array view `dst` in place. Both arrays
should have an equal length, and the view must have a contiguous memory layout.
"""
function Base.copyto!(dst::SubArray{T,N,<:DenseArray,I,true}, src::CuArray{T}) where {T,N,I}
if length(dst) != length(src)
throw(ArgumentError("Inconsistent array length."))
end
if any(strides(dst) .!= strides(parent(dst)))
throw(ArgumentError("Transfers to an array view require contiguous memory layout."))
end
Mem.download!(pointer(dst), src.buf, length(src) * sizeof(T))
return dst
end

function Base.copyto!(dst::SubArray, src::CuArray)
throw(ArgumentError("Transfers to an array view require a contiguous memory layout."))
end


### convenience functions

@eval begin
"""
CuArray{T}(src::Array{T})
"""
CuArray{T}(src::Array{T})
Transfer a host array `src` to device, returning a [`CuArray`](@ref).
"""
CuArray(src::Array{T,N}) where {T,N} = $copyfun(CuArray{T,N}(size(src)), src)
Transfer a host array `src` to device, returning a [`CuArray`](@ref).
"""
CuArray(src::Array{T,N}) where {T,N} = copyto!(CuArray{T,N}(size(src)), src)

"""
Array{T}(src::CuArray{T})
"""
Array{T}(src::CuArray{T})
Transfer a device array `src` to host, returning an `Array`.
"""
Base.Array(src::CuArray{T,N}) where {T,N} = $copyfun(Array{T,N}(undef, size(src)), src)
end
Transfer a device array `src` to host, returning an `Array`.
"""
Base.Array(src::CuArray{T,N}) where {T,N} = copyto!(Array{T,N}(undef, size(src)), src)
11 changes: 2 additions & 9 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,8 @@ end

# ccall wrapper for calling functions in NVIDIA libraries
macro apicall(funspec, argtypes, args...)
fun = if VERSION >= v"0.7.0-DEV.1729"
isa(funspec, QuoteNode) || error("first argument to @apicall should be a symbol")
funspec.value
else
if !isa(funspec, Expr) || funspec.head != :quote
error("first argument to @apicall should be a symbol")
end
funspec.args[1]
end
isa(funspec, QuoteNode) || error("first argument to @apicall should be a symbol")
fun = funspec.value

# resolve the function
global mapping, version_requirements
Expand Down
2 changes: 1 addition & 1 deletion src/memory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ end
## type based

function check_type(::Type{Buffer}, T)
if isa(T, UnionAll) || T.abstract || !(VERSION<=v"0.7.0-DEV.3475" ? T.isleaftype : isconcretetype(T))
if isa(T, UnionAll) || T.abstract || !isconcretetype(T)
throw(ArgumentError("cannot represent abstract or non-leaf object"))
end
Base.datatype_pointerfree(T) || throw(ArgumentError("cannot handle non-ptrfree objects"))
Expand Down
6 changes: 1 addition & 5 deletions src/module/linker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ Base.hash(link::CuLink, h::UInt) = hash(link.handle, h)
Add PTX code to a pending link operation.
"""
function add_data!(link::CuLink, name::String, code::String)
data = if VERSION >= v"0.7.0-DEV.3244"
unsafe_wrap(Vector{UInt8}, code)
else
Vector{UInt8}(code)
end
data = unsafe_wrap(Vector{UInt8}, code)

# there shouldn't be any embedded NULLs
checked_data = Base.unsafe_convert(Cstring, data)
Expand Down
10 changes: 4 additions & 6 deletions test/base.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
@testset "base" begin

@test_throws (VERSION >= v"0.7.0-DEV.1729" ? LoadError : ErrorException) eval(
quote
foo = :bar
CUDAdrv.@apicall(foo, ())
end
)
@test_throws LoadError @eval begin
foo = :bar
CUDAdrv.@apicall(foo, ())
end

@test_throws ErrorException CUDAdrv.@apicall(:cuNonexisting, ())

Expand Down
2 changes: 1 addition & 1 deletion test/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function julia_cmd(cmd)
return `
$(Base.julia_cmd())
--color=$(Base.have_color ? "yes" : "no")
--$(VERSION >= v"0.7.0-DEV.1735" ? "compiled-modules" : "compilecache")=$(Bool(VERSION >= v"0.7.0-DEV.1735" ? Base.JLOptions().use_compiled_modules : Base.JLOptions().use_compilecache) ? "yes" : "no")
--compiled-modules=$(Base.JLOptions().use_compiled_modules != 0 ? "yes" : "no")
--history-file=no
--startup-file=$(Base.JLOptions().startupfile != 2 ? "yes" : "no")
--code-coverage=$(["none", "user", "all"][1+Base.JLOptions().code_coverage])
Expand Down

0 comments on commit 1cc999e

Please sign in to comment.