Skip to content

Commit

Permalink
Convert task_spec to flatbuffers (#255)
Browse files Browse the repository at this point in the history
* convert Ray to C++

* convert task_spec to flatbuffers

* fix

* it compiles

* latest

* tests are passing

* task2 -> task

* fix

* fix

* fix

* fix

* fix

* linting

* fix valgrind

* upgrade flatbuffers

* use debug mode for valgrind

* fix naming and comments

* downgrade flatbuffers

* fix linting

* reintroduce TaskSpec_free

* rename TaskSpec -> TaskInfo

* refactoring

* linting
  • Loading branch information
pcmoritz authored and robertnishihara committed Mar 5, 2017
1 parent 65a8659 commit 0b8d279
Show file tree
Hide file tree
Showing 36 changed files with 1,052 additions and 929 deletions.
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ bash "$ROOT_DIR/src/numbuf/thirdparty/build_thirdparty.sh"

# Now build everything.
pushd "$ROOT_DIR/python/ray/core"
cmake -DCMAKE_BUILD_TYPE=Release ../../..
if [ "$VALGRIND" = "1" ]
then
cmake -DCMAKE_BUILD_TYPE=Debug ../../..
else
cmake -DCMAKE_BUILD_TYPE=Release ../../..
fi
make clean
make
popd
19 changes: 19 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

include_directories(thirdparty/ae)

# Compile flatbuffers

set(COMMON_FBS_SRC "${CMAKE_CURRENT_LIST_DIR}/format/common.fbs")
set(OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/format/)

add_custom_target(gen_common_fbs ALL)

add_custom_command(
TARGET gen_common_fbs
COMMAND ${FLATBUFFERS_COMPILER} -c -o ${OUTPUT_DIR} ${COMMON_FBS_SRC}
DEPENDS ${FBS_DEPENDS}
COMMENT "Running flatc compiler on ${COMMON_FBS_SRC}"
VERBATIM)

add_dependencies(gen_common_fbs flatbuffers_ep)

add_custom_target(
hiredis
COMMAND make
Expand All @@ -18,6 +34,7 @@ add_custom_target(
add_library(common STATIC
event_loop.cc
common.cc
common_protocol.cc
task.cc
io.cc
net.cc
Expand All @@ -32,6 +49,8 @@ add_library(common STATIC
thirdparty/ae/ae.c
thirdparty/sha256.c)

add_dependencies(common gen_common_fbs)

target_link_libraries(common "${CMAKE_CURRENT_LIST_DIR}/thirdparty/hiredis/libhiredis.a")

function(define_test test_name library)
Expand Down
6 changes: 6 additions & 0 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
#endif

#include "utarray.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "sha256.h"
#ifdef __cplusplus
}
#endif

/** Definitions for Ray logging levels. */
#define RAY_COMMON_DEBUG 0
Expand Down
26 changes: 26 additions & 0 deletions src/common/common_protocol.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "common_protocol.h"

flatbuffers::Offset<flatbuffers::String> to_flatbuf(
flatbuffers::FlatBufferBuilder &fbb,
ObjectID object_id) {
return fbb.CreateString((char *) &object_id.id[0], sizeof(object_id.id));
}

ObjectID from_flatbuf(const flatbuffers::String *string) {
ObjectID object_id;
CHECK(string->size() == sizeof(object_id.id));
memcpy(&object_id.id[0], string->data(), sizeof(object_id.id));
return object_id;
}

flatbuffers::Offset<
flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>>
to_flatbuf(flatbuffers::FlatBufferBuilder &fbb,
ObjectID object_ids[],
int64_t num_objects) {
std::vector<flatbuffers::Offset<flatbuffers::String>> results;
for (size_t i = 0; i < num_objects; i++) {
results.push_back(to_flatbuf(fbb, object_ids[i]));
}
return fbb.CreateVector(results);
}
41 changes: 41 additions & 0 deletions src/common/common_protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef COMMON_PROTOCOL_H
#define COMMON_PROTOCOL_H

#include "format/common_generated.h"

#include "common.h"

/**
* Convert an object ID to a flatbuffer string.
*
* @param fbb Reference to the flatbuffer builder.
* @param object_id The object ID to be converted.
* @return The flatbuffer string contining the object ID.
*/
flatbuffers::Offset<flatbuffers::String> to_flatbuf(
flatbuffers::FlatBufferBuilder &fbb,
ObjectID object_id);

/**
* Convert a flatbuffer string to an object ID.
*
* @param string The flatbuffer string.
* @return The object ID.
*/
ObjectID from_flatbuf(const flatbuffers::String *string);

/**
* Convert an array of object IDs to a flatbuffer vector of strings.
*
* @param fbb Reference to the flatbuffer builder.
* @param object_ids Array of object IDs.
* @param num_objects Number of elements in the array.
* @return Flatbuffer vector of strings.
*/
flatbuffers::Offset<
flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>>
to_flatbuf(flatbuffers::FlatBufferBuilder &fbb,
ObjectID object_ids[],
int64_t num_objects);

#endif
52 changes: 52 additions & 0 deletions src/common/format/common.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

// Indices into resource vectors.
// A resource vector maps a resource index to the number
// of units of that resource required.

// The total length of the resource vector is ResourceIndex_MAX.
enum ResourceIndex:int {
// A central processing unit.
CPU = 0,
// A graphics processing unit.
GPU = 1,
// A dummy entry to make ResourceIndex_MAX equal to the length of
// a resource vector.
DUMMY = 2
}

table Arg {
// Object ID for pass-by-reference arguments.
object_id: string;
// Data for pass-by-value arguments.
data: string;
}

table TaskInfo {
// ID of the driver that created this task.
driver_id: string;
// Task ID of the task.
task_id: string;
// Task ID of the parent task.
parent_task_id: string;
// A count of the number of tasks submitted by the parent task before this one.
parent_counter: int;
// Actor ID of the task. This is the actor that this task is executed on
// or NIL_ACTOR_ID if the task is just a normal task.
actor_id: string;
// Number of tasks that have been submitted to this actor so far.
actor_counter: int;
// Function ID of the task.
function_id: string;
// Task arguments.
args: [Arg];
// Object IDs of return values.
returns: [string];
// The required_resources vector indicates the quantities of the different
// resources required by this task. The index in this vector corresponds to
// the resource type defined in the ResourceIndex enum. For example,
// required_resources[0] is the number of CPUs required, and
// required_resources[1] is the number of GPUs required.
required_resources: [double];
}

root_type TaskInfo;
Loading

0 comments on commit 0b8d279

Please sign in to comment.