Skip to content

Commit

Permalink
Wrap some simple pointer attribute queries, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Jan 28, 2020
1 parent aa09aca commit c7bcd13
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,15 @@ function Base.unsafe_convert(::Type{PtrOrCuPtr{T}}, val) where {T}
end
return Base.bitcast(PtrOrCuPtr{T}, ptr)
end

function memory_type(x::CuPtr)
dat = Ref{CUmemorytype}()
cuPointerGetAttribute(dat, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, x)
return dat[]
end

function is_managed(x::CuPtr)
dat = Ref{UInt32}()
cuPointerGetAttribute(dat, CU_POINTER_ATTRIBUTE_IS_MANAGED, x)
return convert(Bool, dat[])
end
14 changes: 14 additions & 0 deletions test/memory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ for srcTy in [Mem.Device, Mem.Host, Mem.Unified],
if isa(src, Mem.Device) || isa(src, Mem.Unified)
Mem.set!(typed_pointer(src, T), zero(T), N)
end
# test the memory-type attribute
if isa(src, Mem.Device)
@test CUDAdrv.memory_type(src.ptr) == CUDAdrv.CU_MEMORYTYPE_DEVICE
@test CUDAdrv.memory_type(typed_pointer(src, T)) == CUDAdrv.CU_MEMORYTYPE_DEVICE
end
# test the is-managed attribute
if isa(src, Mem.Device)
@test !CUDAdrv.is_managed(typed_pointer(src, T))
@test !CUDAdrv.is_managed(src.ptr)
end
if isa(src, Mem.Unified)
@test CUDAdrv.is_managed(typed_pointer(src, T))
@test CUDAdrv.is_managed(src.ptr)
end

Mem.free(src)
Mem.free(dst)
Expand Down

0 comments on commit c7bcd13

Please sign in to comment.