Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repeat does not work with KnetArray #635

Open
johnberg1 opened this issue Nov 27, 2020 · 2 comments
Open

repeat does not work with KnetArray #635

johnberg1 opened this issue Nov 27, 2020 · 2 comments

Comments

@johnberg1
Copy link

I was using repeat() function to replicate a Float64 array and the following code seems to be working:
a = randn(256, 5)
repeat(a,16,16)

but when I cast the array to a KnetArray type and try again,
a = KnetArray{}(randn(256, 5))
repeat(a,16,16)

I encounter the following error:

MethodError: no method matching repeat(::KnetArray{Float64,2}, ::Int64, ::Int64) Closest candidates are: repeat(!Matched::Union{GPUArrays.AbstractGPUArray{T,2}, GPUArrays.AbstractGPUArray{T,1}} where T, ::Int64, ::Int64) at C:\Users\canbe\.julia\packages\GPUArrays\Ck0bk\src\host\base.jl:3 repeat(!Matched::Union{AbstractArray{T,2}, AbstractArray{T,1}} where T, ::Integer, ::Integer) at abstractarraymath.jl:275 repeat(!Matched::AbstractArray, ::Integer...) at abstractarraymath.jl:273 ...

It looks like repeat() does not support KnetArray type. I'm using Julia Version 1.5.2 and Knet v1.4.3

@denizyuret
Copy link
Owner

As a temporary workaround until I fix this, I would recommend:

KnetArray(repeat(CuArray(a),16,16)))

Or use CuArray as your array type, might be a bit slower but supports more operations.

@Alexander-Barth
Copy link
Contributor

Alexander-Barth commented May 5, 2022

Apparently, CUDA (as of 3.9.0) does not have such kernel either:

using CUDA; repeat(cu(ones(2,2)),1,1,3)
┌ Warning: Performing scalar indexing on task Task (runnable) @0x00007f7d738a0010.
│ Invocation of getindex resulted in scalar indexing of a GPU array.
│ This is typically caused by calling an iterating implementation of a method.
│ Such implementations *do not* execute on the GPU, but very slowly on the CPU,
│ and therefore are only permitted from the REPL for prototyping purposes.
│ If you did intend to index this array, annotate the caller with @allowscalar.

My workaround is to use an array of indices:

KnetArray(ones(2,2))[:,:,ones(Int,3)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants