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

Unable to construct StdVector{CxxPtr{TaskArg}} from Vector{CxxRef{TaskArg}} #80

Open
omus opened this issue Sep 5, 2023 · 2 comments
Open
Assignees

Comments

@omus
Copy link
Member

omus commented Sep 5, 2023

julia> using Ray, CxxWrap

julia> Ray.init()

julia> task_args = Ray.serialize_args([1,2,3])
3-element Vector{Any}:
 ray_core_worker_julia_jll.TaskArgByValueAllocated(Ptr{Nothing} @0x0000600000042100)
 ray_core_worker_julia_jll.TaskArgByValueAllocated(Ptr{Nothing} @0x0000600000043be0)
 ray_core_worker_julia_jll.TaskArgByValueAllocated(Ptr{Nothing} @0x0000600000042560)

julia> CxxRef.(convert.(ray_jll.TaskArg, task_args))
3-element Vector{CxxRef{ray_core_worker_julia_jll.TaskArg}}:
 CxxRef{ray_core_worker_julia_jll.TaskArg}(Ptr{ray_core_worker_julia_jll.TaskArg} @0x0000600000051300)
 CxxRef{ray_core_worker_julia_jll.TaskArg}(Ptr{ray_core_worker_julia_jll.TaskArg} @0x000060000004de60)
 CxxRef{ray_core_worker_julia_jll.TaskArg}(Ptr{ray_core_worker_julia_jll.TaskArg} @0x000060000004d0e0)

julia> StdVector{CxxPtr{ray_jll.TaskArg}}(CxxRef.(convert.(ray_jll.TaskArg, task_args)))
ERROR: MethodError: no method matching StdVector{CxxPtr{ray_core_worker_julia_jll.TaskArg}}(::Vector{CxxRef{ray_core_worker_julia_jll.TaskArg}})

Closest candidates are:
  StdVector{CxxPtr{ray_core_worker_julia_jll.TaskArg}}()
   @ ray_core_worker_julia_jll ~/.julia/packages/CxxWrap/aXNBY/src/CxxWrap.jl:624

Stacktrace:
 [1] top-level scope
   @ REPL[15]:1

Originally posted by @omus in #72 (comment)

@omus
Copy link
Member Author

omus commented Oct 26, 2023

Using Ray.jl af34bb3 and CxxWrap 0.14.2 on Julia 1.9.3 I see the following:

julia> using Ray, CxxWrap; using Ray: ray_jll

julia> Ray.init()

julia> task_args = Ray.serialize_args([1,2,3])
3-element Vector{Any}:
 Ray.ray_julia_jll.TaskArgByValueAllocated(Ptr{Nothing} @0x0000600000927e80)
 Ray.ray_julia_jll.TaskArgByValueAllocated(Ptr{Nothing} @0x0000600000927fe0)
 Ray.ray_julia_jll.TaskArgByValueAllocated(Ptr{Nothing} @0x00006000009248e0)

julia> task_arg_refs = CxxRef.(convert.(ray_jll.TaskArg, task_args))
3-element Vector{CxxRef{Ray.ray_julia_jll.TaskArg}}:
 CxxRef{Ray.ray_julia_jll.TaskArg}(Ptr{Ray.ray_julia_jll.TaskArg} @0x0000600000927e80)
 CxxRef{Ray.ray_julia_jll.TaskArg}(Ptr{Ray.ray_julia_jll.TaskArg} @0x0000600000927fe0)
 CxxRef{Ray.ray_julia_jll.TaskArg}(Ptr{Ray.ray_julia_jll.TaskArg} @0x00006000009248e0)

julia> StdVector{CxxPtr{ray_jll.TaskArg}}(task_arg_refs)
ERROR: MethodError: Cannot `convert` an object of type CxxRef{Ray.ray_julia_jll.TaskArg} to an object of type CxxPtr{Ray.ray_julia_jll.TaskArg}

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:64
  CxxPtr{T}(::CxxWrap.CxxWrapCore.CxxBaseRef) where T
   @ CxxWrap ~/.julia/packages/CxxWrap/5IZvn/src/CxxWrap.jl:199

julia> task_arg_ptrs = CxxPtr.(convert.(ray_jll.TaskArg, task_args))
3-element Vector{CxxPtr{Ray.ray_julia_jll.TaskArg}}:
 CxxPtr{Ray.ray_julia_jll.TaskArg}(Ptr{Ray.ray_julia_jll.TaskArg} @0x0000600000927e80)
 CxxPtr{Ray.ray_julia_jll.TaskArg}(Ptr{Ray.ray_julia_jll.TaskArg} @0x0000600000927fe0)
 CxxPtr{Ray.ray_julia_jll.TaskArg}(Ptr{Ray.ray_julia_jll.TaskArg} @0x00006000009248e0)

julia> StdVector{CxxPtr{ray_jll.TaskArg}}(task_arg_ptrs)
ERROR: StackOverflowError:
Stacktrace:
 [1] append(v::CxxWrap.StdLib.StdVectorAllocated{CxxPtr{Ray.ray_julia_jll.TaskArg}}, a::Vector{CxxPtr{Ray.ray_julia_jll.TaskArg}})
   @ CxxWrap.StdLib ~/.julia/packages/CxxWrap/5IZvn/src/StdLib.jl:33
 [2] _append_dispatch(v::CxxWrap.StdLib.StdVectorAllocated{CxxPtr{Ray.ray_julia_jll.TaskArg}}, a::Vector{CxxPtr{Ray.ray_julia_jll.TaskArg}}, #unused#::Type{CxxWrap.CxxWrapCore.IsNormalType})
   @ CxxWrap.StdLib ~/.julia/packages/CxxWrap/5IZvn/src/StdLib.jl:29

julia> StdVector{CxxPtr{ray_jll.TaskArg}}(CxxPtr.(task_args))
ERROR: MethodError: Cannot `convert` an object of type
  CxxPtr{Ray.ray_julia_jll.TaskArgByValue} to an object of type
  CxxPtr{Ray.ray_julia_jll.TaskArg}

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:64
  CxxPtr{T}(::CxxWrap.CxxWrapCore.CxxBaseRef) where T
   @ CxxWrap ~/.julia/packages/CxxWrap/5IZvn/src/CxxWrap.jl:199

julia> task_arg_ptr_vec = StdVector{CxxPtr{ray_jll.TaskArg}}()
0-element CxxWrap.StdLib.StdVectorAllocated{CxxPtr{Ray.ray_julia_jll.TaskArg}}

julia> for task_arg in task_args
           push!(task_arg_ptr_vec, CxxPtr(task_arg))
       end

julia> task_arg_ptr_vec
3-element CxxWrap.StdLib.StdVectorAllocated{CxxPtr{Ray.ray_julia_jll.TaskArg}}:
 CxxPtr{Ray.ray_julia_jll.TaskArg}(Ptr{Ray.ray_julia_jll.TaskArg} @0x0000600000927e80)
 CxxPtr{Ray.ray_julia_jll.TaskArg}(Ptr{Ray.ray_julia_jll.TaskArg} @0x0000600000927fe0)
 CxxPtr{Ray.ray_julia_jll.TaskArg}(Ptr{Ray.ray_julia_jll.TaskArg} @0x00006000009248e0)

Seems like we have a little more work to do with the StdVector constructors

@omus omus changed the title Cannot convert Vector to StdVector Unable to construct StdVector{CxxPtr{TaskArg}} from Vector{CxxRef{TaskArg}} Oct 26, 2023
@omus
Copy link
Member Author

omus commented Oct 26, 2023

Fixing this would allow us to drop this function:

Ray.jl/src/runtime.jl

Lines 212 to 218 in af34bb3

function transform_task_args(task_args)
task_arg_ptrs = StdVector{CxxPtr{ray_jll.TaskArg}}()
for task_arg in task_args
push!(task_arg_ptrs, CxxPtr(task_arg))
end
return task_arg_ptrs
end

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

No branches or pull requests

1 participant