diff --git a/ext/StridedViewsAMDGPUExt.jl b/ext/StridedViewsAMDGPUExt.jl index 110ecf8..3d2ba93 100644 --- a/ext/StridedViewsAMDGPUExt.jl +++ b/ext/StridedViewsAMDGPUExt.jl @@ -6,6 +6,8 @@ using AMDGPU: Adapt const ROCStridedView{T, N, A <: ROCArray{T}} = StridedView{T, N, A} +StridedViews._normalizeparent(A::ROCArray, offset::Int) = reshape(A, length(A)), offset + function Base.pointer(x::ROCStridedView{T}) where {T} return Base.unsafe_convert(Ptr{T}, pointer(x.parent, x.offset + 1)) end diff --git a/ext/StridedViewsCUDACoreExt.jl b/ext/StridedViewsCUDACoreExt.jl index 09e89de..d74b1cf 100644 --- a/ext/StridedViewsCUDACoreExt.jl +++ b/ext/StridedViewsCUDACoreExt.jl @@ -6,6 +6,8 @@ using CUDACore: Adapt, CuPtr const CuStridedView{T, N, A <: CuArray{T}} = StridedView{T, N, A} +StridedViews._normalizeparent(A::CuArray, offset::Int) = reshape(A, length(A)), offset + function Base.pointer(x::CuStridedView{T}) where {T} return Base.unsafe_convert(CuPtr{T}, pointer(x.parent, x.offset + 1)) end diff --git a/test/runtests.jl b/test/runtests.jl index c00624a..38c1e0c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -350,12 +350,14 @@ end if CUDACore.functional() @testset "CuArrays with StridedView" begin @testset for T in (Float64, ComplexF64) - A = CUDACore.randn(T, 10, 10, 10, 10) + A = CuArray(randn(T, 10, 10, 10, 10)) @test isstrided(A) B = StridedView(A) @test B isa StridedView + @test parent(B) isa CuArray{T, 1} CUDACore.@allowscalar begin @test B == A + @test parent(B) == reshape(A, :) end end end @@ -368,8 +370,10 @@ if AMDGPU.functional() @test isstrided(A) B = StridedView(A) @test B isa StridedView + @test parent(B) isa ROCArray{T, 1} AMDGPU.@allowscalar begin @test B == A + @test parent(B) == reshape(A, :) end end end