mirror of
https://github.com/wassname/ray.git
synced 2026-07-19 11:27:32 +08:00
Define common data structures with protobuf. (#5121)
This commit is contained in:
+24
-26
@@ -24,8 +24,8 @@ from ray.includes.common cimport (
|
||||
)
|
||||
from ray.includes.libraylet cimport (
|
||||
CRayletClient,
|
||||
GCSProfileEventT,
|
||||
GCSProfileTableDataT,
|
||||
GCSProfileEvent,
|
||||
GCSProfileTableData,
|
||||
ResourceMappingType,
|
||||
WaitResultPair,
|
||||
)
|
||||
@@ -34,7 +34,7 @@ from ray.includes.unique_ids cimport (
|
||||
CObjectID,
|
||||
CClientID,
|
||||
)
|
||||
from ray.includes.task cimport CTaskSpecification
|
||||
from ray.includes.task cimport CTaskSpec
|
||||
from ray.includes.ray_config cimport RayConfig
|
||||
from ray.utils import decode
|
||||
|
||||
@@ -232,18 +232,22 @@ cdef class RayletClient:
|
||||
def disconnect(self):
|
||||
check_status(self.client.get().Disconnect())
|
||||
|
||||
def submit_task(self, Task task_spec):
|
||||
def submit_task(self, TaskSpec task_spec, execution_dependencies):
|
||||
cdef:
|
||||
CObjectID c_id
|
||||
c_vector[CObjectID] c_dependencies
|
||||
for dep in execution_dependencies:
|
||||
c_dependencies.push_back((<ObjectID>dep).native())
|
||||
check_status(self.client.get().SubmitTask(
|
||||
task_spec.execution_dependencies.get()[0],
|
||||
task_spec.task_spec.get()[0]))
|
||||
c_dependencies, task_spec.task_spec.get()[0]))
|
||||
|
||||
def get_task(self):
|
||||
cdef:
|
||||
unique_ptr[CTaskSpecification] task_spec
|
||||
unique_ptr[CTaskSpec] task_spec
|
||||
|
||||
with nogil:
|
||||
check_status(self.client.get().GetTask(&task_spec))
|
||||
return Task.make(task_spec)
|
||||
return TaskSpec.make(task_spec)
|
||||
|
||||
def task_done(self):
|
||||
check_status(self.client.get().TaskDone())
|
||||
@@ -303,19 +307,19 @@ cdef class RayletClient:
|
||||
def push_profile_events(self, component_type, UniqueID component_id,
|
||||
node_ip_address, profile_data):
|
||||
cdef:
|
||||
GCSProfileTableDataT profile_info
|
||||
GCSProfileEventT *profile_event
|
||||
GCSProfileTableData profile_info
|
||||
GCSProfileEvent *profile_event
|
||||
c_string event_type
|
||||
|
||||
if len(profile_data) == 0:
|
||||
return # Short circuit if there are no profile events.
|
||||
|
||||
profile_info.component_type = component_type.encode("ascii")
|
||||
profile_info.component_id = component_id.binary()
|
||||
profile_info.node_ip_address = node_ip_address.encode("ascii")
|
||||
profile_info.set_component_type(component_type.encode("ascii"))
|
||||
profile_info.set_component_id(component_id.binary())
|
||||
profile_info.set_node_ip_address(node_ip_address.encode("ascii"))
|
||||
|
||||
for py_profile_event in profile_data:
|
||||
profile_event = new GCSProfileEventT()
|
||||
profile_event = profile_info.add_profile_events()
|
||||
if not isinstance(py_profile_event, dict):
|
||||
raise TypeError(
|
||||
"Incorrect type for a profile event. Expected dict "
|
||||
@@ -325,28 +329,22 @@ cdef class RayletClient:
|
||||
# that will cause segfaults in the node manager.
|
||||
for key_string, event_data in py_profile_event.items():
|
||||
if key_string == "event_type":
|
||||
profile_event.event_type = event_data.encode("ascii")
|
||||
if profile_event.event_type.length() == 0:
|
||||
if len(event_data) == 0:
|
||||
raise ValueError(
|
||||
"'event_type' should not be a null string.")
|
||||
profile_event.set_event_type(event_data.encode("ascii"))
|
||||
elif key_string == "start_time":
|
||||
profile_event.start_time = float(event_data)
|
||||
profile_event.set_start_time(float(event_data))
|
||||
elif key_string == "end_time":
|
||||
profile_event.end_time = float(event_data)
|
||||
profile_event.set_end_time(float(event_data))
|
||||
elif key_string == "extra_data":
|
||||
profile_event.extra_data = event_data.encode("ascii")
|
||||
if profile_event.extra_data.length() == 0:
|
||||
if len(event_data) == 0:
|
||||
raise ValueError(
|
||||
"'extra_data' should not be a null string.")
|
||||
profile_event.set_extra_data(event_data.encode("ascii"))
|
||||
else:
|
||||
raise ValueError(
|
||||
"Unknown profile event key '%s'" % key_string)
|
||||
# Note that profile_info.profile_events is a vector of unique
|
||||
# pointers, so profile_event will be deallocated when profile_info
|
||||
# goes out of scope. "emplace_back" of vector has not been
|
||||
# supported by Cython
|
||||
profile_info.profile_events.push_back(
|
||||
unique_ptr[GCSProfileEventT](profile_event))
|
||||
|
||||
check_status(self.client.get().PushProfileEvents(profile_info))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user