@@ -79,42 +79,23 @@ class Ray {
79
79
// / \param[in] args The function arguments passed by a value or ObjectRef.
80
80
// / \return TaskCaller.
81
81
template <typename F>
82
- static TaskCaller<boost::callable_traits:: return_type_t <F> > Task (F func);
82
+ static TaskCaller<F > Task (F func);
83
83
84
84
// / Generic version of creating an actor
85
85
// / It is used for creating an actor, such as: ActorCreator<Counter> creator =
86
- // / Ray::Actor(Counter::FactoryCreate, 1).
86
+ // / Ray::Actor(Counter::FactoryCreate<int>).Remote(1);
87
87
template <typename ActorType, typename ... Args>
88
- static ActorCreator<ActorType> Actor (
89
- CreateActorFunc<ActorType, typename FilterArgType<Args>::type...> create_func,
90
- Args... args);
91
-
92
- // / TODO: The bellow specific version of creating an actor will be replaced with generic
93
- // / version later.
94
- #include < ray/api/generated/create_funcs.generated.h>
95
-
96
- #include " api/generated/create_actors.generated.h"
88
+ static ActorCreator<ActorType> Actor (CreateActorFunc<ActorType, Args...> create_func);
97
89
98
90
private:
99
91
static std::once_flag is_inited_;
100
92
101
- template <typename ReturnType, typename FuncType>
102
- static TaskCaller<ReturnType > TaskInternal (FuncType &func);
93
+ template <typename FuncType>
94
+ static TaskCaller<FuncType > TaskInternal (FuncType &func);
103
95
104
- template <typename ActorType, typename FuncType, typename ExecFuncType,
105
- typename ... ArgTypes>
96
+ template <typename ActorType, typename FuncType, typename ExecFuncType>
106
97
static ActorCreator<ActorType> CreateActorInternal (FuncType &func,
107
- ExecFuncType &exec_func,
108
- ArgTypes &... args);
109
-
110
- // / Include the `Call` methods for calling actor methods.
111
- // / Used by ActorHandle to implement .Call()
112
- // / It is called by ActorHandle: Ray::Task(&Counter::Add, counter/*instance of
113
- // / Counter*/, 1);
114
- template <typename ReturnType, typename ActorType, typename ... Args>
115
- static ActorTaskCaller<ReturnType> Task (
116
- ActorFunc<ActorType, ReturnType, typename FilterArgType<Args>::type...> actor_func,
117
- ActorHandle<ActorType> &actor, Args... args);
98
+ ExecFuncType &exec_func);
118
99
};
119
100
120
101
} // namespace api
@@ -170,8 +151,8 @@ inline WaitResult Ray::Wait(const std::vector<ObjectID> &ids, int num_objects,
170
151
return ray::internal::RayRuntime ()->Wait (ids, num_objects, timeout_ms);
171
152
}
172
153
173
- template <typename ReturnType, typename FuncType>
174
- inline TaskCaller<ReturnType > Ray::TaskInternal (FuncType &func) {
154
+ template <typename FuncType>
155
+ inline TaskCaller<FuncType > Ray::TaskInternal (FuncType &func) {
175
156
RemoteFunctionPtrHolder ptr{};
176
157
ptr.function_pointer = reinterpret_cast <uintptr_t >(func);
177
158
if (ray::api::RayConfig::GetInstance ()->use_ray_remote ) {
@@ -182,55 +163,42 @@ inline TaskCaller<ReturnType> Ray::TaskInternal(FuncType &func) {
182
163
}
183
164
ptr.function_name = std::move (function_name);
184
165
}
185
- return TaskCaller<ReturnType >(ray::internal::RayRuntime ().get (), ptr);
166
+ return TaskCaller<FuncType >(ray::internal::RayRuntime ().get (), ptr);
186
167
}
187
168
188
- template <typename ActorType, typename FuncType, typename ExecFuncType,
189
- typename ... ArgTypes>
169
+ template <typename ActorType, typename FuncType, typename ExecFuncType>
190
170
inline ActorCreator<ActorType> Ray::CreateActorInternal (FuncType &create_func,
191
- ExecFuncType &exec_func,
192
- ArgTypes &... args) {
193
- std::vector<std::unique_ptr<::ray::TaskArg>> task_args;
194
- Arguments::WrapArgs (&task_args, args...);
195
- RemoteFunctionPtrHolder ptr;
196
- ptr.function_pointer = reinterpret_cast <uintptr_t >(create_func);
197
- ptr.exec_function_pointer = reinterpret_cast <uintptr_t >(exec_func);
198
- return ActorCreator<ActorType>(ray::internal::RayRuntime ().get (), ptr,
199
- std::move (task_args));
171
+ ExecFuncType &exec_func) {
172
+ RemoteFunctionPtrHolder ptr{};
173
+ if (ray::api::RayConfig::GetInstance ()->use_ray_remote ) {
174
+ auto function_name =
175
+ ray::internal::FunctionManager::Instance ().GetFunctionName (create_func);
176
+ if (function_name.empty ()) {
177
+ throw RayException (
178
+ " Function not found. Please use RAY_REMOTE to register this function." );
179
+ }
180
+
181
+ ptr.function_name = std::move (function_name);
182
+ } else {
183
+ ptr.function_pointer = reinterpret_cast <uintptr_t >(create_func);
184
+ ptr.exec_function_pointer = reinterpret_cast <uintptr_t >(exec_func);
185
+ }
186
+
187
+ return ActorCreator<ActorType>(ray::internal::RayRuntime ().get (), ptr);
200
188
}
201
189
202
190
// / Normal task.
203
191
template <typename F>
204
- TaskCaller<boost::callable_traits::return_type_t <F>> Ray::Task (F func) {
205
- using ReturnType = boost::callable_traits::return_type_t <F>;
206
-
207
- return TaskInternal<ReturnType>(func);
192
+ TaskCaller<F> Ray::Task (F func) {
193
+ return TaskInternal<F>(func);
208
194
}
209
195
210
- // / Generic version of creating an actor.
196
+ // / Creating an actor.
211
197
template <typename ActorType, typename ... Args>
212
- ActorCreator<ActorType> Ray::Actor (
213
- CreateActorFunc<ActorType, typename FilterArgType<Args>::type...> create_func,
214
- Args... args) {
198
+ ActorCreator<ActorType> Ray::Actor (CreateActorFunc<ActorType, Args...> create_func) {
215
199
return CreateActorInternal<ActorType>(
216
200
create_func,
217
- CreateActorExecFunction<ActorType *, typename FilterArgType<Args>::type...>,
218
- args...);
219
- }
220
-
221
- // / TODO: The bellow specific version of creating an actor will be replaced with generic
222
- // / version later.
223
- #include < ray/api/generated/create_actors_impl.generated.h>
224
-
225
- // / Actor task.
226
- template <typename ReturnType, typename ActorType, typename ... Args>
227
- ActorTaskCaller<ReturnType> Ray::Task (
228
- ActorFunc<ActorType, ReturnType, typename FilterArgType<Args>::type...> actor_func,
229
- ActorHandle<ActorType> &actor, Args... args) {
230
- return CallActorInternal<ReturnType, ActorType>(
231
- actor_func,
232
- ActorExecFunction<ReturnType, ActorType, typename FilterArgType<Args>::type...>,
233
- actor, args...);
201
+ CreateActorExecFunction<ActorType *, typename FilterArgType<Args>::type...>);
234
202
}
235
203
236
204
} // namespace api
0 commit comments