mirror of
https://github.com/wassname/ray.git
synced 2026-07-11 05:32:40 +08:00
Remove ray.tasks() from API. (#7807)
This commit is contained in:
@@ -36,7 +36,6 @@ from ray.includes.common cimport (
|
||||
from ray.includes.function_descriptor cimport (
|
||||
CFunctionDescriptor,
|
||||
)
|
||||
from ray.includes.task cimport CTaskSpec
|
||||
|
||||
ctypedef unordered_map[c_string, c_vector[pair[int64_t, double]]] \
|
||||
ResourceMappingType
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
from libc.stdint cimport uint8_t, uint64_t
|
||||
from libcpp cimport bool as c_bool
|
||||
from libcpp.memory cimport unique_ptr, shared_ptr
|
||||
from libcpp.string cimport string as c_string
|
||||
from libcpp.unordered_map cimport unordered_map
|
||||
from libcpp.vector cimport vector as c_vector
|
||||
|
||||
from ray.includes.common cimport (
|
||||
CLanguage,
|
||||
ResourceSet,
|
||||
)
|
||||
from ray.includes.unique_ids cimport (
|
||||
CActorID,
|
||||
CJobID,
|
||||
CObjectID,
|
||||
CTaskID,
|
||||
)
|
||||
from ray.includes.function_descriptor cimport (
|
||||
CFunctionDescriptor,
|
||||
)
|
||||
|
||||
cdef extern from "ray/protobuf/common.pb.h" nogil:
|
||||
cdef cppclass RpcTaskSpec "ray::rpc::TaskSpec":
|
||||
void CopyFrom(const RpcTaskSpec &value)
|
||||
|
||||
cdef cppclass RpcTaskExecutionSpec "ray::rpc::TaskExecutionSpec":
|
||||
void CopyFrom(const RpcTaskExecutionSpec &value)
|
||||
void add_dependencies(const c_string &value)
|
||||
|
||||
cdef cppclass RpcTask "ray::rpc::Task":
|
||||
RpcTaskSpec *mutable_task_spec()
|
||||
|
||||
cdef extern from "ray/protobuf/gcs.pb.h" nogil:
|
||||
cdef cppclass TaskTableData "ray::rpc::TaskTableData":
|
||||
RpcTask *mutable_task()
|
||||
const c_string &SerializeAsString()
|
||||
|
||||
|
||||
cdef extern from "ray/common/task/task_spec.h" nogil:
|
||||
cdef cppclass CTaskSpec "ray::TaskSpecification":
|
||||
CTaskSpec(const RpcTaskSpec message)
|
||||
CTaskSpec(const c_string &serialized_binary)
|
||||
const RpcTaskSpec &GetMessage()
|
||||
c_string Serialize() const
|
||||
|
||||
CTaskID TaskId() const
|
||||
CJobID JobId() const
|
||||
CTaskID ParentTaskId() const
|
||||
uint64_t ParentCounter() const
|
||||
CFunctionDescriptor FunctionDescriptor() const
|
||||
c_string FunctionDescriptorString() const
|
||||
uint64_t NumArgs() const
|
||||
uint64_t NumReturns() const
|
||||
c_bool ArgByRef(uint64_t arg_index) const
|
||||
int ArgIdCount(uint64_t arg_index) const
|
||||
CObjectID ArgId(uint64_t arg_index, uint64_t id_index) const
|
||||
CObjectID ReturnIdForPlasma(uint64_t return_index) const
|
||||
const uint8_t *ArgData(uint64_t arg_index) const
|
||||
size_t ArgDataSize(uint64_t arg_index) const
|
||||
const uint8_t *ArgMetadata(uint64_t arg_index) const
|
||||
size_t ArgMetadataSize(uint64_t arg_index) const
|
||||
double GetRequiredResource(const c_string &resource_name) const
|
||||
const ResourceSet GetRequiredResources() const
|
||||
const ResourceSet GetRequiredPlacementResources() const
|
||||
c_bool IsDriverTask() const
|
||||
CLanguage GetLanguage() const
|
||||
c_bool IsNormalTask() const
|
||||
c_bool IsActorCreationTask() const
|
||||
c_bool IsActorTask() const
|
||||
CActorID ActorCreationId() const
|
||||
CObjectID ActorCreationDummyObjectId() const
|
||||
CObjectID PreviousActorTaskDummyObjectId() const
|
||||
uint64_t MaxActorReconstructions() const
|
||||
CActorID ActorId() const
|
||||
uint64_t ActorCounter() const
|
||||
CObjectID ActorDummyObject() const
|
||||
|
||||
|
||||
cdef extern from "ray/common/task/task_execution_spec.h" nogil:
|
||||
cdef cppclass CTaskExecutionSpec "ray::TaskExecutionSpecification":
|
||||
CTaskExecutionSpec(RpcTaskExecutionSpec message)
|
||||
CTaskExecutionSpec(const c_string &serialized_binary)
|
||||
const RpcTaskExecutionSpec &GetMessage()
|
||||
c_vector[CObjectID] ExecutionDependencies()
|
||||
uint64_t NumForwards()
|
||||
|
||||
cdef extern from "ray/common/task/task.h" nogil:
|
||||
cdef cppclass CTask "ray::Task":
|
||||
CTask(CTaskSpec task_spec, CTaskExecutionSpec task_execution_spec)
|
||||
@@ -1,209 +0,0 @@
|
||||
from ray.includes.task cimport (
|
||||
CTask,
|
||||
CTaskExecutionSpec,
|
||||
CTaskSpec,
|
||||
RpcTaskExecutionSpec,
|
||||
TaskTableData,
|
||||
)
|
||||
from ray.ray_constants import RAW_BUFFER_METADATA
|
||||
from ray.utils import decode
|
||||
|
||||
|
||||
cdef class TaskSpec:
|
||||
"""Cython wrapper class of C++ `ray::TaskSpecification`."""
|
||||
cdef:
|
||||
unique_ptr[CTaskSpec] task_spec
|
||||
|
||||
@staticmethod
|
||||
def from_string(const c_string& task_spec_str):
|
||||
"""Convert a string to a Ray task specification Python object.
|
||||
|
||||
Args:
|
||||
task_spec_str: String representation of the task specification.
|
||||
|
||||
Returns:
|
||||
Python task specification object.
|
||||
"""
|
||||
cdef TaskSpec self = TaskSpec.__new__(TaskSpec)
|
||||
self.task_spec.reset(new CTaskSpec(task_spec_str))
|
||||
return self
|
||||
|
||||
def to_string(self):
|
||||
"""Convert a Ray task specification Python object to a string.
|
||||
|
||||
Returns:
|
||||
String representing the task specification.
|
||||
"""
|
||||
return self.task_spec.get().Serialize()
|
||||
|
||||
def is_normal_task(self):
|
||||
"""Whether this task is a normal task."""
|
||||
return self.task_spec.get().IsNormalTask()
|
||||
|
||||
def is_actor_task(self):
|
||||
"""Whether this task is an actor task."""
|
||||
return self.task_spec.get().IsActorTask()
|
||||
|
||||
def is_actor_creation_task(self):
|
||||
"""Whether this task is an actor creation task."""
|
||||
return self.task_spec.get().IsActorCreationTask()
|
||||
|
||||
def job_id(self):
|
||||
"""Return the job ID for this task."""
|
||||
return JobID(self.task_spec.get().JobId().Binary())
|
||||
|
||||
def task_id(self):
|
||||
"""Return the task ID for this task."""
|
||||
return TaskID(self.task_spec.get().TaskId().Binary())
|
||||
|
||||
def parent_task_id(self):
|
||||
"""Return the task ID of the parent task."""
|
||||
return TaskID(self.task_spec.get().ParentTaskId().Binary())
|
||||
|
||||
def parent_counter(self):
|
||||
"""Return the parent counter of this task."""
|
||||
return self.task_spec.get().ParentCounter()
|
||||
|
||||
def function_descriptor(self):
|
||||
"""Return the function descriptor for this task."""
|
||||
return CFunctionDescriptorToPython(
|
||||
self.task_spec.get().FunctionDescriptor())
|
||||
|
||||
def arguments(self):
|
||||
"""Return the arguments for the task."""
|
||||
cdef:
|
||||
int64_t num_args = self.task_spec.get().NumArgs()
|
||||
int32_t lang = <int32_t>self.task_spec.get().GetLanguage()
|
||||
int count
|
||||
arg_list = []
|
||||
|
||||
if lang == <int32_t>LANGUAGE_PYTHON:
|
||||
for i in range(num_args):
|
||||
count = self.task_spec.get().ArgIdCount(i)
|
||||
if count > 0:
|
||||
assert count == 1
|
||||
arg_list.append(
|
||||
ObjectID(self.task_spec.get().ArgId(i, 0).Binary()))
|
||||
else:
|
||||
data = self.task_spec.get().ArgData(i)[
|
||||
:self.task_spec.get().ArgDataSize(i)]
|
||||
metadata = self.task_spec.get().ArgMetadata(i)[
|
||||
:self.task_spec.get().ArgMetadataSize(i)]
|
||||
if metadata == RAW_BUFFER_METADATA:
|
||||
obj = data
|
||||
else:
|
||||
obj = data
|
||||
arg_list.append(obj)
|
||||
elif lang == <int32_t>LANGUAGE_JAVA:
|
||||
arg_list = num_args * ["<java-argument>"]
|
||||
|
||||
return arg_list
|
||||
|
||||
def returns(self):
|
||||
"""Return the object IDs for the return values of the task."""
|
||||
return_id_list = []
|
||||
for i in range(self.task_spec.get().NumReturns()):
|
||||
return_id_list.append(
|
||||
ObjectID(self.task_spec.get().ReturnIdForPlasma(i).Binary()))
|
||||
return return_id_list
|
||||
|
||||
def required_resources(self):
|
||||
"""Return the resource dictionary of the task."""
|
||||
cdef:
|
||||
unordered_map[c_string, double] resource_map = (
|
||||
self.task_spec.get().GetRequiredResources().GetResourceMap())
|
||||
c_string resource_name
|
||||
double resource_value
|
||||
unordered_map[c_string, double].iterator iterator = (
|
||||
resource_map.begin())
|
||||
|
||||
required_resources = {}
|
||||
while iterator != resource_map.end():
|
||||
resource_name = dereference(iterator).first
|
||||
# bytes for Py2, unicode for Py3
|
||||
py_resource_name = decode(resource_name)
|
||||
resource_value = dereference(iterator).second
|
||||
required_resources[py_resource_name] = resource_value
|
||||
postincrement(iterator)
|
||||
return required_resources
|
||||
|
||||
def language(self):
|
||||
"""Return the language of the task."""
|
||||
return Language.from_native(self.task_spec.get().GetLanguage())
|
||||
|
||||
def actor_creation_id(self):
|
||||
"""Return the actor creation ID for the task."""
|
||||
if not self.is_actor_creation_task():
|
||||
return ActorID.nil()
|
||||
return ActorID(self.task_spec.get().ActorCreationId().Binary())
|
||||
|
||||
def actor_creation_dummy_object_id(self):
|
||||
"""Return the actor creation dummy object ID for the task."""
|
||||
if not self.is_actor_task():
|
||||
return ObjectID.nil()
|
||||
return ObjectID(
|
||||
self.task_spec.get().ActorCreationDummyObjectId().Binary())
|
||||
|
||||
def previous_actor_task_dummy_object_id(self):
|
||||
"""Return the object ID of the previously executed actor task."""
|
||||
if not self.is_actor_task():
|
||||
return ObjectID.nil()
|
||||
return ObjectID(
|
||||
self.task_spec.get().PreviousActorTaskDummyObjectId().Binary())
|
||||
|
||||
def actor_id(self):
|
||||
"""Return the actor ID for this task."""
|
||||
if not self.is_actor_task():
|
||||
return ActorID.nil()
|
||||
return ActorID(self.task_spec.get().ActorId().Binary())
|
||||
|
||||
def actor_counter(self):
|
||||
"""Return the actor counter for this task."""
|
||||
if not self.is_actor_task():
|
||||
return 0
|
||||
return self.task_spec.get().ActorCounter()
|
||||
|
||||
|
||||
cdef class TaskExecutionSpec:
|
||||
"""Cython wrapper class of C++ `ray::TaskExecutionSpecification`."""
|
||||
cdef:
|
||||
unique_ptr[CTaskExecutionSpec] c_spec
|
||||
|
||||
def __init__(self):
|
||||
cdef:
|
||||
RpcTaskExecutionSpec message
|
||||
|
||||
self.c_spec.reset(new CTaskExecutionSpec(message))
|
||||
|
||||
@staticmethod
|
||||
def from_string(const c_string& string):
|
||||
"""Convert a string to a Ray `TaskExecutionSpec` Python object.
|
||||
"""
|
||||
cdef TaskExecutionSpec self = TaskExecutionSpec.__new__(
|
||||
TaskExecutionSpec)
|
||||
self.c_spec.reset(new CTaskExecutionSpec(string))
|
||||
return self
|
||||
|
||||
def num_forwards(self):
|
||||
return self.c_spec.get().NumForwards()
|
||||
|
||||
|
||||
cdef class Task:
|
||||
"""Cython wrapper class of C++ `ray::Task`."""
|
||||
cdef:
|
||||
unique_ptr[CTask] c_task
|
||||
|
||||
def __init__(
|
||||
self, TaskSpec task_spec, TaskExecutionSpec task_execution_spec):
|
||||
self.c_task.reset(new CTask(task_spec.task_spec.get()[0],
|
||||
task_execution_spec.c_spec.get()[0]))
|
||||
|
||||
|
||||
def generate_gcs_task_table_data(TaskSpec task_spec):
|
||||
"""Converts a Python `TaskSpec` object to serialized GCS `TaskTableData`.
|
||||
"""
|
||||
cdef:
|
||||
TaskTableData task_table_data
|
||||
task_table_data.mutable_task().mutable_task_spec().CopyFrom(
|
||||
task_spec.task_spec.get().GetMessage())
|
||||
return task_table_data.SerializeAsString()
|
||||
@@ -134,8 +134,9 @@ cdef class ObjectID(BaseID):
|
||||
self.in_core_worker = False
|
||||
|
||||
worker = ray.worker.global_worker
|
||||
# TODO(edoakes): there are dummy object IDs being created in
|
||||
# includes/task.pxi before the core worker is initialized.
|
||||
# TODO(edoakes): We should be able to remove the in_core_worker flag.
|
||||
# But there are still some dummy object IDs being created outside the
|
||||
# context of a core worker.
|
||||
if hasattr(worker, "core_worker"):
|
||||
worker.core_worker.add_object_id_reference(self)
|
||||
self.in_core_worker = True
|
||||
|
||||
Reference in New Issue
Block a user