Python api of placement group (#9243)

This commit is contained in:
Alisa
2020-07-28 05:57:05 +08:00
committed by GitHub
parent b51ab2af66
commit 51e12ee97c
20 changed files with 362 additions and 23 deletions
+20 -1
View File
@@ -5,6 +5,7 @@ from libcpp.string cimport string as c_string
from libc.stdint cimport uint8_t, int32_t, uint64_t, int64_t
from libcpp.unordered_map cimport unordered_map
from libcpp.vector cimport vector as c_vector
from libcpp.pair cimport pair as c_pair
from ray.includes.unique_ids cimport (
CActorID,
@@ -12,6 +13,7 @@ from ray.includes.unique_ids cimport (
CWorkerID,
CObjectID,
CTaskID,
CPlacementGroupID,
)
from ray.includes.function_descriptor cimport (
CFunctionDescriptor,
@@ -142,6 +144,8 @@ cdef extern from "src/ray/protobuf/common.pb.h" nogil:
pass
cdef cppclass CTaskType "ray::TaskType":
pass
cdef cppclass CPlacementStrategy "ray::PlacementStrategy":
pass
cdef cppclass CAddress "ray::rpc::Address":
CAddress()
const c_string &SerializeAsString()
@@ -164,6 +168,11 @@ cdef extern from "src/ray/protobuf/common.pb.h" nogil:
cdef CTaskType TASK_TYPE_ACTOR_CREATION_TASK "ray::TaskType::ACTOR_CREATION_TASK" # noqa: E501
cdef CTaskType TASK_TYPE_ACTOR_TASK "ray::TaskType::ACTOR_TASK"
cdef extern from "src/ray/protobuf/common.pb.h" nogil:
cdef CPlacementStrategy PLACEMENT_STRATEGY_PACK \
"ray::PlacementStrategy::PACK"
cdef CPlacementStrategy PLACEMENT_STRATEGY_SPREAD \
"ray::PlacementStrategy::SPREAD"
cdef extern from "ray/common/task/scheduling_resources.h" nogil:
cdef cppclass ResourceSet "ray::ResourceSet":
@@ -239,7 +248,17 @@ cdef extern from "ray/core_worker/common.h" nogil:
const unordered_map[c_string, double] &resources,
const unordered_map[c_string, double] &placement_resources,
const c_vector[c_string] &dynamic_worker_options,
c_bool is_detached, c_string &name, c_bool is_asyncio)
c_bool is_detached, c_string &name, c_bool is_asyncio,
c_pair[CPlacementGroupID, int64_t] placement_options)
cdef cppclass CPlacementGroupCreationOptions \
"ray::PlacementGroupCreationOptions":
CPlacementGroupCreationOptions()
CPlacementGroupCreationOptions(
const c_string &name,
CPlacementStrategy strategy,
const c_vector[unordered_map[c_string, double]] &bundles
)
cdef extern from "ray/gcs/gcs_client.h" nogil:
cdef cppclass CGcsClientOptions "ray::gcs::GcsClientOptions":
+8
View File
@@ -17,11 +17,13 @@ from ray.includes.unique_ids cimport (
CJobID,
CTaskID,
CObjectID,
CPlacementGroupID,
)
from ray.includes.common cimport (
CAddress,
CActorCreationOptions,
CBuffer,
CPlacementGroupCreationOptions,
CRayFunction,
CRayObject,
CRayStatus,
@@ -91,6 +93,9 @@ cdef extern from "ray/core_worker/core_worker.h" nogil:
const c_vector[unique_ptr[CTaskArg]] &args,
const CActorCreationOptions &options,
const c_string &extension_data, CActorID *actor_id)
CRayStatus CreatePlacementGroup(
const CPlacementGroupCreationOptions &options,
CPlacementGroupID *placement_group_id)
void SubmitActorTask(
const CActorID &actor_id, const CRayFunction &function,
const c_vector[unique_ptr[CTaskArg]] &args,
@@ -225,9 +230,12 @@ cdef extern from "ray/core_worker/core_worker.h" nogil:
void Initialize(const CCoreWorkerOptions &options)
# Only call this in CoreWorker.__cinit__,
# use CoreWorker.core_worker to access C++ CoreWorker.
@staticmethod
CCoreWorker &GetCoreWorker()
@staticmethod
void Shutdown()
@staticmethod
void RunTaskExecutionLoop()
+15
View File
@@ -158,3 +158,18 @@ cdef extern from "ray/common/id.h" namespace "ray" nogil:
@staticmethod
CWorkerID FromBinary(const c_string &binary)
cdef cppclass CPlacementGroupID "ray::PlacementGroupID" \
(CBaseID[CPlacementGroupID]):
@staticmethod
CPlacementGroupID FromBinary(const c_string &binary)
@staticmethod
const CActorID Nil()
@staticmethod
size_t Size()
@staticmethod
CPlacementGroupID FromRandom()
+40 -1
View File
@@ -19,7 +19,8 @@ from ray.includes.unique_ids cimport (
CObjectID,
CTaskID,
CUniqueID,
CWorkerID
CWorkerID,
CPlacementGroupID
)
import ray
@@ -331,6 +332,43 @@ cdef class ActorClassID(UniqueID):
# This type alias is for backward compatibility.
ObjectID = ObjectRef
cdef class PlacementGroupID(BaseID):
cdef CPlacementGroupID data
def __init__(self, id):
check_id(id, CPlacementGroupID.Size())
self.data = CPlacementGroupID.FromBinary(<c_string>id)
cdef CPlacementGroupID native(self):
return <CPlacementGroupID>self.data
@classmethod
def from_random(cls):
return cls(CPlacementGroupID.FromRandom().Binary())
@classmethod
def nil(cls):
return cls(CPlacementGroupID.Nil().Binary())
@classmethod
def size(cls):
return CPlacementGroupID.Size()
def binary(self):
return self.data.Binary()
def hex(self):
return decode(self.data.Hex())
def size(self):
return CPlacementGroupID.Size()
def is_nil(self):
return self.data.IsNil()
cdef size_t hash(self):
return self.data.Hash()
_ID_TYPES = [
ActorCheckpointID,
ActorClassID,
@@ -342,4 +380,5 @@ _ID_TYPES = [
ObjectID,
TaskID,
UniqueID,
PlacementGroupID,
]