Skip to content

Commit

Permalink
[Core][C++ Worker]Add error message for unsupported Object Ref parame…
Browse files Browse the repository at this point in the history
…ters in C++ Worker (ray-project#36414)

Signed-off-by: LarryLian <[email protected]>
  • Loading branch information
larrylian committed Jun 21, 2023
1 parent eb6c61c commit 666a452
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cpp/include/ray/api/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ class Arguments {
std::vector<TaskArg> *task_args,
InputArgTypes &&arg) {
if constexpr (is_object_ref_v<OriginArgType>) {
PushReferenceArg(task_args, std::forward<InputArgTypes>(arg));
if (RayRuntimeHolder::Instance().Runtime()->IsLocalMode()) {
PushReferenceArg(task_args, std::forward<InputArgTypes>(arg));
} else {
// After the Object Ref parameter is supported, this exception will be deleted.
throw std::invalid_argument(
"At present, the Ray C++ API does not support the passing of "
"`ray::ObjectRef` parameters. Will support later.");
}
} else if constexpr (is_object_ref_v<InputArgTypes>) {
// core_worker submitting task callback will get the value of an ObjectRef arg, but
// local mode we don't call core_worker submit task, so we need get the value of an
Expand Down
11 changes: 11 additions & 0 deletions cpp/src/ray/test/cluster/cluster_mode_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,17 @@ TEST(RayClusterModeTest, RuntimeEnvJobLevelEnvVarsTest) {
ray::Shutdown();
}

TEST(RayClusterModeTest, UnsupportObjectRefTest) {
ray::RayConfig config;
ray::Init(config, cmd_argc, cmd_argv);
ray::ActorHandle<Counter> actor = ray::Actor(RAY_FUNC(Counter::FactoryCreate)).Remote();
auto int_ref = ray::Put(1);
EXPECT_THROW(actor.Task(&Counter::GetIntByObjectRef).Remote(int_ref),
std::invalid_argument);

ray::Shutdown();
}

int main(int argc, char **argv) {
absl::ParseCommandLine(argc, argv);
cmd_argc = argc;
Expand Down
7 changes: 6 additions & 1 deletion cpp/src/ray/test/cluster/counter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ int Counter::Plus1ForActor(ray::ActorHandle<Counter> actor) {
return *actor.Task(&Counter::Plus1).Remote().Get();
}

int Counter::GetIntByObjectRef(ray::ObjectRef<int> object_ref) {
return *object_ref.Get();
}

RAY_REMOTE(RAY_FUNC(Counter::FactoryCreate),
Counter::FactoryCreateException,
RAY_FUNC(Counter::FactoryCreate, int),
Expand All @@ -124,7 +128,8 @@ RAY_REMOTE(RAY_FUNC(Counter::FactoryCreate),
&Counter::CreateNestedChildActor,
&Counter::GetBytes,
&Counter::echoBytes,
&Counter::echoString);
&Counter::echoString,
&Counter::GetIntByObjectRef);

RAY_REMOTE(ActorConcurrentCall::FactoryCreate, &ActorConcurrentCall::CountDown);

Expand Down
2 changes: 2 additions & 0 deletions cpp/src/ray/test/cluster/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Counter {
return value == NULL ? "" : std::string(value);
}

int GetIntByObjectRef(ray::ObjectRef<int> object_ref);

private:
int count;
bool is_restared = false;
Expand Down

0 comments on commit 666a452

Please sign in to comment.