C++ worker API refactoring (#9053)

This commit is contained in:
SongGuyang
2020-06-24 19:33:46 +08:00
committed by GitHub
parent aa231799ed
commit cbf38573bd
19 changed files with 399 additions and 261 deletions
+11 -11
View File
@@ -36,9 +36,9 @@ int main() {
auto getRsult = obj.Get();
/// general function remote callargs passed by value
auto r0 = Ray::Call(Return1);
auto r1 = Ray::Call(Plus1, 1);
auto r2 = Ray::Call(Plus, 1, 2);
auto r0 = Ray::Task(Return1).Remote();
auto r1 = Ray::Task(Plus1, 1).Remote();
auto r2 = Ray::Task(Plus, 1, 2).Remote();
int result0 = *(r0.Get());
int result1 = *(r1.Get());
@@ -48,9 +48,9 @@ int main() {
<< result2 << std::endl;
/// general function remote callargs passed by reference
auto r3 = Ray::Call(Return1);
auto r4 = Ray::Call(Plus1, r3);
auto r5 = Ray::Call(Plus, r4, 1);
auto r3 = Ray::Task(Return1).Remote();
auto r4 = Ray::Task(Plus1, r3).Remote();
auto r5 = Ray::Task(Plus, r4, 1).Remote();
int result3 = *(r3.Get());
int result4 = *(r4.Get());
@@ -60,11 +60,11 @@ int main() {
<< result5 << std::endl;
/// create actor and actor function remote call
RayActor<Counter> actor = Ray::CreateActor(Counter::FactoryCreate);
auto r6 = actor.Call(&Counter::Add, 5);
auto r7 = actor.Call(&Counter::Add, 1);
auto r8 = actor.Call(&Counter::Add, 1);
auto r9 = actor.Call(&Counter::Add, r8);
ActorHandle<Counter> actor = Ray::Actor(Counter::FactoryCreate).Remote();
auto r6 = actor.Task(&Counter::Add, 5).Remote();
auto r7 = actor.Task(&Counter::Add, 1).Remote();
auto r8 = actor.Task(&Counter::Add, 1).Remote();
auto r9 = actor.Task(&Counter::Add, r8).Remote();
int result6 = *(r6.Get());
int result7 = *(r7.Get());
+1 -1
View File
@@ -40,7 +40,7 @@ class ObjectStore {
std::vector<std::shared_ptr<msgpack::sbuffer>> Get(
const std::vector<ObjectID> &ids, int timeout_ms = default_get_timeout_ms);
/// Wait for a list of RayObjects to be locally available,
/// Wait for a list of ObjectRefs to be locally available,
/// until specified number of objects are ready, or specified timeout has passed.
///
/// \param[in] ids The object id array which should be waited.
+17 -17
View File
@@ -44,9 +44,9 @@ TEST(RayApiTest, PutTest) {
TEST(RayApiTest, WaitTest) {
Ray::Init();
auto r0 = Ray::Call(Return1);
auto r1 = Ray::Call(Plus1, 3);
auto r2 = Ray::Call(Plus, 2, 3);
auto r0 = Ray::Task(Return1).Remote();
auto r1 = Ray::Task(Plus1, 3).Remote();
auto r2 = Ray::Task(Plus, 2, 3).Remote();
std::vector<ObjectID> objects = {r0.ID(), r1.ID(), r2.ID()};
WaitResult result = Ray::Wait(objects, 3, 1000);
EXPECT_EQ(result.ready.size(), 3);
@@ -59,9 +59,9 @@ TEST(RayApiTest, WaitTest) {
}
TEST(RayApiTest, CallWithValueTest) {
auto r0 = Ray::Call(Return1);
auto r1 = Ray::Call(Plus1, 3);
auto r2 = Ray::Call(Plus, 2, 3);
auto r0 = Ray::Task(Return1).Remote();
auto r1 = Ray::Task(Plus1, 3).Remote();
auto r2 = Ray::Task(Plus, 2, 3).Remote();
int result0 = *(r0.Get());
int result1 = *(r1.Get());
@@ -73,11 +73,11 @@ TEST(RayApiTest, CallWithValueTest) {
}
TEST(RayApiTest, CallWithObjectTest) {
auto rt0 = Ray::Call(Return1);
auto rt1 = Ray::Call(Plus1, rt0);
auto rt2 = Ray::Call(Plus, rt1, 3);
auto rt3 = Ray::Call(Plus1, 3);
auto rt4 = Ray::Call(Plus, rt2, rt3);
auto rt0 = Ray::Task(Return1).Remote();
auto rt1 = Ray::Task(Plus1, rt0).Remote();
auto rt2 = Ray::Task(Plus, rt1, 3).Remote();
auto rt3 = Ray::Task(Plus1, 3).Remote();
auto rt4 = Ray::Task(Plus, rt2, rt3).Remote();
int return0 = *(rt0.Get());
int return1 = *(rt1.Get());
@@ -94,11 +94,11 @@ TEST(RayApiTest, CallWithObjectTest) {
TEST(RayApiTest, ActorTest) {
Ray::Init();
RayActor<Counter> actor = Ray::CreateActor(Counter::FactoryCreate);
auto rt1 = actor.Call(&Counter::Add, 1);
auto rt2 = actor.Call(&Counter::Add, 2);
auto rt3 = actor.Call(&Counter::Add, 3);
auto rt4 = actor.Call(&Counter::Add, rt3);
ActorHandle<Counter> actor = Ray::Actor(Counter::FactoryCreate).Remote();
auto rt1 = actor.Task(&Counter::Add, 1).Remote();
auto rt2 = actor.Task(&Counter::Add, 2).Remote();
auto rt3 = actor.Task(&Counter::Add, 3).Remote();
auto rt4 = actor.Task(&Counter::Add, rt3).Remote();
int return1 = *(rt1.Get());
int return2 = *(rt2.Get());
@@ -124,7 +124,7 @@ TEST(RayApiTest, CompareWithFuture) {
// Ray API
Ray::Init();
auto f3 = Ray::Call(Plus1, 1);
auto f3 = Ray::Task(Plus1, 1).Remote();
int rt3 = *f3.Get();
EXPECT_EQ(rt1, 2);
+4 -4
View File
@@ -15,10 +15,10 @@ TEST(RaySlowFunctionTest, BaseTest) {
Ray::Init();
auto time1 = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch());
auto r0 = Ray::Call(slow_function, 1);
auto r1 = Ray::Call(slow_function, 2);
auto r2 = Ray::Call(slow_function, 3);
auto r3 = Ray::Call(slow_function, 4);
auto r0 = Ray::Task(slow_function, 1).Remote();
auto r1 = Ray::Task(slow_function, 2).Remote();
auto r2 = Ray::Task(slow_function, 3).Remote();
auto r3 = Ray::Task(slow_function, 4).Remote();
int result0 = *(r0.Get());
int result1 = *(r1.Get());