mirror of
https://github.com/wassname/ray.git
synced 2026-07-09 17:14:51 +08:00
12fdb3f53a
* Define execution dependencies flatbuffer and add to Redis commands * Convert TaskSpec to TaskExecutionSpec * Add execution dependencies to Python bindings * Submitting actor tasks uses execution dependency API instead of dummy argument * Fix dependency getters and some cleanup for fetching missing dependencies * C++ convention * Make TaskExecutionSpec a C++ class * Convert local scheduler to use TaskExecutionSpec class * Convert some pointers to references * Finish conversion to TaskExecutionSpec class * fix * Fix * Fix memory errors? * Cast flatbuffers GetSize to size_t * Fixes * add more retries in global scheduler unit test * fix linting and cast fbb.GetSize to size_t * Style and doc * Fix linting and simplify from_flatbuf.
78 lines
2.5 KiB
C++
78 lines
2.5 KiB
C++
#ifndef EXAMPLE_TASK_H
|
|
#define EXAMPLE_TASK_H
|
|
|
|
#include "task.h"
|
|
|
|
extern TaskBuilder *g_task_builder;
|
|
|
|
const int64_t arg_value_size = 1000;
|
|
|
|
static inline TaskExecutionSpec example_task_execution_spec_with_args(
|
|
int64_t num_args,
|
|
int64_t num_returns,
|
|
ObjectID arg_ids[]) {
|
|
TaskID parent_task_id = globally_unique_id();
|
|
FunctionID func_id = globally_unique_id();
|
|
TaskSpec_start_construct(g_task_builder, NIL_ID, parent_task_id, 0,
|
|
NIL_ACTOR_ID, NIL_ACTOR_ID, 0, false, func_id,
|
|
num_returns);
|
|
for (int64_t i = 0; i < num_args; ++i) {
|
|
ObjectID arg_id;
|
|
if (arg_ids == NULL) {
|
|
arg_id = globally_unique_id();
|
|
} else {
|
|
arg_id = arg_ids[i];
|
|
}
|
|
TaskSpec_args_add_ref(g_task_builder, &arg_id, 1);
|
|
}
|
|
int64_t task_spec_size;
|
|
TaskSpec *spec = TaskSpec_finish_construct(g_task_builder, &task_spec_size);
|
|
std::vector<ObjectID> execution_dependencies;
|
|
auto execution_spec =
|
|
TaskExecutionSpec(execution_dependencies, spec, task_spec_size);
|
|
TaskSpec_free(spec);
|
|
return execution_spec;
|
|
}
|
|
|
|
static inline TaskExecutionSpec example_task_execution_spec(
|
|
int64_t num_args,
|
|
int64_t num_returns) {
|
|
return example_task_execution_spec_with_args(num_args, num_returns, NULL);
|
|
}
|
|
|
|
static inline Task *example_task_with_args(int64_t num_args,
|
|
int64_t num_returns,
|
|
int task_state,
|
|
ObjectID arg_ids[]) {
|
|
TaskExecutionSpec spec =
|
|
example_task_execution_spec_with_args(num_args, num_returns, arg_ids);
|
|
Task *instance = Task_alloc(spec, task_state, NIL_ID);
|
|
return instance;
|
|
}
|
|
|
|
static inline Task *example_task(int64_t num_args,
|
|
int64_t num_returns,
|
|
int task_state) {
|
|
TaskExecutionSpec spec = example_task_execution_spec(num_args, num_returns);
|
|
Task *instance = Task_alloc(spec, task_state, NIL_ID);
|
|
return instance;
|
|
}
|
|
|
|
static inline bool Task_equals(Task *task1, Task *task2) {
|
|
if (task1->state != task2->state) {
|
|
return false;
|
|
}
|
|
if (!DBClientID_equal(task1->local_scheduler_id, task2->local_scheduler_id)) {
|
|
return false;
|
|
}
|
|
auto execution_spec1 = Task_task_execution_spec(task1);
|
|
auto execution_spec2 = Task_task_execution_spec(task2);
|
|
if (execution_spec1->SpecSize() != execution_spec2->SpecSize()) {
|
|
return false;
|
|
}
|
|
return memcmp(execution_spec1->Spec(), execution_spec2->Spec(),
|
|
execution_spec1->SpecSize()) == 0;
|
|
}
|
|
|
|
#endif /* EXAMPLE_TASK_H */
|