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

Return a RayObject from task_executor #97

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions ray_julia_jll/deps/wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void initialize_worker(
bool is_reattempt,
bool is_streaming_generator) {

std::vector<std::shared_ptr<LocalMemoryBuffer>> return_vec;
std::vector<std::shared_ptr<RayObject>> return_vec;
task_executor(ray_function,
&return_vec, // implicity converts to void *
&args, // implicity converts to void *
Expand All @@ -116,8 +116,7 @@ void initialize_worker(

// TODO: support multiple return values
// https://github.com/beacon-biosignals/Ray.jl/issues/54
std::shared_ptr<LocalMemoryBuffer> buffer = return_vec[0];
(*returns)[0].second = std::make_shared<RayObject>(buffer, nullptr, std::vector<rpc::ObjectReference>(), false);
(*returns)[0].second = return_vec[0];
return Status::OK();
};
RAY_LOG(DEBUG) << "ray_julia_jll: Initializing julia worker coreworker";
Expand All @@ -129,9 +128,9 @@ void initialize_worker(
RAY_LOG(DEBUG) << "ray_julia_jll: Task execution loop exited";
}

std::vector<std::shared_ptr<LocalMemoryBuffer>> * cast_to_returns(void *ptr) {
auto buffer_ptr = static_cast<std::vector<std::shared_ptr<LocalMemoryBuffer>> *>(ptr);
return buffer_ptr;
std::vector<std::shared_ptr<RayObject>> *cast_to_returns(void *ptr) {
auto rayobj_ptr = static_cast<std::vector<std::shared_ptr<RayObject>> *>(ptr);
return rayobj_ptr;
}

std::vector<std::shared_ptr<RayObject>> cast_to_task_args(void *ptr) {
Expand Down
2 changes: 1 addition & 1 deletion ray_julia_jll/src/wrappers/any.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function Base.take!(buffer::CxxWrap.CxxWrapCore.SmartPointer{<:Buffer})
end

# Work around this: https://github.com/JuliaInterop/CxxWrap.jl/issues/300
function Base.push!(v::CxxPtr{StdVector{T}}, el::T) where T <: SharedPtr{LocalMemoryBuffer}
function Base.push!(v::CxxPtr{StdVector{T}}, el::T) where T <: SharedPtr{RayObject}
return push!(v, CxxRef(el))
end

Expand Down
13 changes: 11 additions & 2 deletions src/runtime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
application_error, is_retryable_error)
returns = ray_jll.cast_to_returns(returns_ptr)
task_args = ray_jll.cast_to_task_args(task_args_ptr)
worker = ray_jll.GetCoreWorker()

Check warning on line 272 in src/runtime.jl

View check run for this annotation

Codecov / codecov/patch

src/runtime.jl#L272

Added line #L272 was not covered by tests

local result
try
Expand Down Expand Up @@ -321,9 +322,17 @@

# TODO: support multiple return values
# https://github.com/beacon-biosignals/Ray.jl/issues/54
bytes = serialize_to_bytes(result)
bytes = Vector{UInt8}()
serializer = RaySerializer(bytes)
writeheader(serializer)
serialize(serializer, result)

Check warning on line 328 in src/runtime.jl

View check run for this annotation

Codecov / codecov/patch

src/runtime.jl#L325-L328

Added lines #L325 - L328 were not covered by tests

buffer = ray_jll.LocalMemoryBuffer(bytes, sizeof(bytes), true)
push!(returns, buffer)
metadata = ray_jll.NullPtr(ray_jll.Buffer)
inlined_ids = collect(serializer.object_ids)
inlined_refs = ray_jll.GetObjectRefs(worker, StdVector(inlined_ids))
ray_obj = ray_jll.RayObject(buffer, metadata, inlined_refs, false)
push!(returns, ray_obj)

Check warning on line 335 in src/runtime.jl

View check run for this annotation

Codecov / codecov/patch

src/runtime.jl#L331-L335

Added lines #L331 - L335 were not covered by tests

return nothing
end
Expand Down