From 1cc999ec4077f7186e09a81028359008a61d787b Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 27 Mar 2018 15:51:17 -0700 Subject: [PATCH] Drop support for older versions of Julia 0.7. --- src/array.jl | 176 ++++++++++++++++++++----------------------- src/base.jl | 11 +-- src/memory.jl | 2 +- src/module/linker.jl | 6 +- test/base.jl | 10 +-- test/util.jl | 2 +- 6 files changed, 91 insertions(+), 116 deletions(-) diff --git a/src/array.jl b/src/array.jl index 58131b7..8aff3de 100644 --- a/src/array.jl +++ b/src/array.jl @@ -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) diff --git a/src/base.jl b/src/base.jl index 223fbb8..b80b7c5 100644 --- a/src/base.jl +++ b/src/base.jl @@ -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 diff --git a/src/memory.jl b/src/memory.jl index dccabf2..2ab0b1a 100644 --- a/src/memory.jl +++ b/src/memory.jl @@ -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")) diff --git a/src/module/linker.jl b/src/module/linker.jl index 429a14d..4a9e51b 100644 --- a/src/module/linker.jl +++ b/src/module/linker.jl @@ -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) diff --git a/test/base.jl b/test/base.jl index 126b2e5..302b043 100644 --- a/test/base.jl +++ b/test/base.jl @@ -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, ()) diff --git a/test/util.jl b/test/util.jl index daf7828..6e7aa84 100644 --- a/test/util.jl +++ b/test/util.jl @@ -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])