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

Vectorized getindex ignores @inbounds #542

Closed
pxl-th opened this issue Jun 23, 2024 · 1 comment · Fixed by #548
Closed

Vectorized getindex ignores @inbounds #542

pxl-th opened this issue Jun 23, 2024 · 1 comment · Fixed by #548

Comments

@pxl-th
Copy link

pxl-th commented Jun 23, 2024

Thus performing device-to-host copy during boundscheck.

julia> x = AMDGPU.rand(Float32, 16);

julia> x[[1, 2, 3, 4]];
[D to H] ROCArray{Bool, 1, AMDGPU.Runtime.Mem.HIPBuffer}: (1,) -> Vector{Bool}: (1,)

julia> @inbounds x[[1, 2, 3, 4]];
[D to H] ROCArray{Bool, 1, AMDGPU.Runtime.Mem.HIPBuffer}: (1,) -> Vector{Bool}: (1,)
@maleadt
Copy link
Member

maleadt commented Jul 5, 2024

Top-level @inbounds doesn't work:

julia> struct Foo end

julia> Base.getindex(::Foo, Is...) = (@boundscheck(error("checking bounds")); 42)

julia> x = Foo()
Foo()

julia> x[1]
ERROR: checking bounds
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] getindex(::Foo, Is::Int64)
   @ Main ./REPL[29]:1
 [3] top-level scope
   @ REPL[31]:1

julia> @inbounds x[1]
ERROR: checking bounds
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] getindex(::Foo, Is::Int64)
   @ Main ./REPL[29]:1
 [3] top-level scope
   @ REPL[32]:1

julia> bar(x) = @inbounds x[1]
bar (generic function with 1 method)

julia> bar(x)
42

There does still seems to be something wrong with the vectorized getindex though.

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

Successfully merging a pull request may close this issue.

2 participants