Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ray-project/ray
Browse files Browse the repository at this point in the history
git pull upstream master
  • Loading branch information
jiaodong committed Jan 22, 2022
2 parents 53f0f0e + 216c4bf commit 2313b22
Show file tree
Hide file tree
Showing 281 changed files with 2,732 additions and 1,114 deletions.
2 changes: 2 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
commands:
- cleanup() { if [ "${BUILDKITE_PULL_REQUEST}" = "false" ]; then ./ci/travis/upload_build_info.sh; fi }; trap cleanup EXIT
- TORCH_VERSION=1.6 ./ci/travis/install-dependencies.sh
- 'git clone https://github.com/wg/wrk.git /tmp/wrk && pushd /tmp/wrk && make -j && sudo cp wrk /usr/local/bin && popd'
- ./dashboard/tests/run_ui_tests.sh
- bazel test --config=ci $(./scripts/bazel_export_options) python/ray/dashboard/...
- bazel test --config=ci $(./scripts/bazel_export_options)
Expand Down Expand Up @@ -342,6 +343,7 @@
commands:
- cleanup() { if [ "${BUILDKITE_PULL_REQUEST}" = "false" ]; then ./ci/travis/upload_build_info.sh; fi }; trap cleanup EXIT
- TORCH_VERSION=1.6 ./ci/travis/install-dependencies.sh
- 'git clone https://github.com/wg/wrk.git /tmp/wrk && pushd /tmp/wrk && make -j && sudo cp wrk /usr/local/bin && popd'
- ./dashboard/tests/run_ui_tests.sh
- bazel test --config=ci $(./scripts/bazel_export_options)
--test_env=RAY_gcs_grpc_based_pubsub=1
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
/doc/source/workflows/ @ericl @iycheng

# RLlib.
/python/ray/rllib/ @sven1977 @gjoliver @avnishn
/rllib/ @sven1977 @gjoliver @avnishn

# ML Docker Dependencies
/python/requirements/ml/requirements_dl.txt @amogkam @sven1977 @richardliaw @matthewdeng
Expand Down
39 changes: 21 additions & 18 deletions bazel/ray_deps_setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def auto_http_archive(
if name == None: # Deduce "com_github_user_project_name" from "https://github.com/user/project-name/..."
name = "_".join(url_parts["netloc"][::-1] + url_path_parts[:2]).replace("-", "_")

# auto appending ray project namespace prefix for 3rd party library reusing.
if build_file == True:
build_file = "@//%s:%s" % ("bazel", "BUILD." + name)
build_file = "@com_github_ray_project_ray//%s:%s" % ("bazel", "BUILD." + name)

if urls == True:
prefer_url_over_mirrors = is_github
Expand Down Expand Up @@ -92,36 +93,38 @@ def ray_deps_setup():
sha256 = "7892a35d979304a404400a101c46ce90e85ec9e2a766a86041bb361f626247f5",
)

# NOTE(lingxuan.zlx): 3rd party dependencies could be accessed, so it suggests
# all of http/git_repository should add prefix for patches defined in ray directory.
auto_http_archive(
name = "com_github_antirez_redis",
build_file = "//bazel:BUILD.redis",
build_file = "@com_github_ray_project_ray//bazel:BUILD.redis",
url = "https://github.com/redis/redis/archive/6.0.10.tar.gz",
sha256 = "900cb82227bac58242c9b7668e7113cd952253b256fe04bbdab1b78979cf255a",
patches = [
"//thirdparty/patches:redis-quiet.patch",
"@com_github_ray_project_ray//thirdparty/patches:redis-quiet.patch",
],
)

auto_http_archive(
name = "com_github_redis_hiredis",
build_file = "//bazel:BUILD.hiredis",
build_file = "@com_github_ray_project_ray//bazel:BUILD.hiredis",
url = "https://github.com/redis/hiredis/archive/392de5d7f97353485df1237872cb682842e8d83f.tar.gz",
sha256 = "2101650d39a8f13293f263e9da242d2c6dee0cda08d343b2939ffe3d95cf3b8b",
patches = [
"//thirdparty/patches:hiredis-windows-msvc.patch",
"@com_github_ray_project_ray//thirdparty/patches:hiredis-windows-msvc.patch",
],
)

auto_http_archive(
name = "com_github_spdlog",
build_file = "//bazel:BUILD.spdlog",
build_file = "@com_github_ray_project_ray//bazel:BUILD.spdlog",
urls = ["https://github.com/gabime/spdlog/archive/v1.7.0.zip"],
sha256 = "c8f1e1103e0b148eb8832275d8e68036f2fdd3975a1199af0e844908c56f6ea5",
)

auto_http_archive(
name = "com_github_tporadowski_redis_bin",
build_file = "//bazel:BUILD.redis",
build_file = "@com_github_ray_project_ray//bazel:BUILD.redis",
strip_prefix = None,
url = "https://github.com/tporadowski/redis/releases/download/v5.0.9/Redis-x64-5.0.9.zip",
sha256 = "b09565b22b50c505a5faa86a7e40b6683afb22f3c17c5e6a5e35fc9b7c03f4c2",
Expand Down Expand Up @@ -154,7 +157,7 @@ def ray_deps_setup():
sha256 = "83bfc1507731a0906e387fc28b7ef5417d591429e51e788417fe9ff025e116b1",
url = "https://boostorg.jfrog.io/artifactory/main/release/1.74.0/source/boost_1_74_0.tar.bz2",
patches = [
"//thirdparty/patches:boost-exception-no_warn_typeid_evaluated.patch",
"@com_github_ray_project_ray//thirdparty/patches:boost-exception-no_warn_typeid_evaluated.patch",
],
)

Expand All @@ -164,7 +167,7 @@ def ray_deps_setup():
url = "https://github.com/nelhage/rules_boost/archive/652b21e35e4eeed5579e696da0facbe8dba52b1f.tar.gz",
sha256 = "c1b8b2adc3b4201683cf94dda7eef3fc0f4f4c0ea5caa3ed3feffe07e1fb5b15",
patches = [
"//thirdparty/patches:rules_boost-windows-linkopts.patch",
"@com_github_ray_project_ray//thirdparty/patches:rules_boost-windows-linkopts.patch",
],
)

Expand Down Expand Up @@ -204,8 +207,8 @@ def ray_deps_setup():
url = "https://github.com/census-instrumentation/opencensus-cpp/archive/b14a5c0dcc2da8a7fc438fab637845c73438b703.zip",
sha256 = "6592e07672e7f7980687f6c1abda81974d8d379e273fea3b54b6c4d855489b9d",
patches = [
"//thirdparty/patches:opencensus-cpp-harvest-interval.patch",
"//thirdparty/patches:opencensus-cpp-shutdown-api.patch",
"@com_github_ray_project_ray//thirdparty/patches:opencensus-cpp-harvest-interval.patch",
"@com_github_ray_project_ray//thirdparty/patches:opencensus-cpp-shutdown-api.patch",
],
)

Expand All @@ -223,10 +226,10 @@ def ray_deps_setup():
url = "https://github.com/jupp0r/prometheus-cpp/archive/60eaa4ea47b16751a8e8740b05fe70914c68a480.tar.gz",
sha256 = "ec825b802487ac18b0d98e2e8b7961487b12562f8f82e424521d0a891d9e1373",
patches = [
"//thirdparty/patches:prometheus-windows-headers.patch",
"@com_github_ray_project_ray//thirdparty/patches:prometheus-windows-headers.patch",
# https://github.com/jupp0r/prometheus-cpp/pull/225
"//thirdparty/patches:prometheus-windows-zlib.patch",
"//thirdparty/patches:prometheus-windows-pollfd.patch",
"@com_github_ray_project_ray//thirdparty/patches:prometheus-windows-zlib.patch",
"@com_github_ray_project_ray//thirdparty/patches:prometheus-windows-pollfd.patch",
],
)

Expand All @@ -236,10 +239,10 @@ def ray_deps_setup():
url = "https://github.com/grpc/grpc/archive/refs/tags/v1.42.0.tar.gz",
sha256 = "b2f2620c762427bfeeef96a68c1924319f384e877bc0e084487601e4cc6e434c",
patches = [
"//thirdparty/patches:grpc-cython-copts.patch",
"@com_github_ray_project_ray//thirdparty/patches:grpc-cython-copts.patch",
# Delete after upgrading from 1.42.0
"//thirdparty/patches:grpc-default-initialization.patch",
"//thirdparty/patches:grpc-python.patch",
"@com_github_ray_project_ray//thirdparty/patches:grpc-default-initialization.patch",
"@com_github_ray_project_ray//thirdparty/patches:grpc-python.patch",
],
)

Expand Down Expand Up @@ -269,7 +272,7 @@ def ray_deps_setup():
url = "https://github.com/msgpack/msgpack-c/archive/8085ab8721090a447cf98bb802d1406ad7afe420.tar.gz",
sha256 = "83c37c9ad926bbee68d564d9f53c6cbb057c1f755c264043ddd87d89e36d15bb",
patches = [
"//thirdparty/patches:msgpack-windows-iovec.patch",
"@com_github_ray_project_ray//thirdparty/patches:msgpack-windows-iovec.patch",
],
)

Expand Down
3 changes: 2 additions & 1 deletion cpp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ cc_test(
"src/ray/test/cluster/*.h",
]),
args = [
"--ray_code_search_path=$(location plus.so):$(location counter.so)",
"--ray_code_search_path=$(location plus.so):$(location counter.so):cpp/src/ray/test/cluster",
"--ray_head_args '--include-dashboard false'",
],
copts = COPTS,
data = [
"counter.so",
"plus.so",
"ray_cpp_pkg",
"src/ray/test/cluster/test_cross_language_invocation.py",
],
linkstatic = True,
tags = ["team:serverless"],
Expand Down
45 changes: 25 additions & 20 deletions cpp/include/ray/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ WaitResult<T> Wait(const std::vector<ray::ObjectRef<T>> &objects, int num_object
template <typename F>
ray::internal::TaskCaller<F> Task(F func);

template <typename R>
ray::internal::TaskCaller<PyFunction<R>> Task(PyFunction<R> func);

/// Generic version of creating an actor
/// It is used for creating an actor, such as: ActorCreator<Counter> creator =
/// ray::Actor(Counter::FactoryCreate<int>).Remote(1);
template <typename F>
ray::internal::ActorCreator<F> Actor(F create_func);

ray::internal::ActorCreator<PyActorClass> Actor(PyActorClass func);

/// Get a handle to a named actor in current namespace.
/// Gets a handle to a named actor with the given name. The actor must have been created
/// with name specified.
Expand Down Expand Up @@ -203,36 +208,41 @@ inline WaitResult<T> Wait(const std::vector<ray::ObjectRef<T>> &objects, int num
return WaitResult<T>(std::move(readys), std::move(unreadys));
}

template <typename FuncType>
inline ray::internal::TaskCaller<FuncType> TaskInternal(FuncType &func) {
ray::internal::RemoteFunctionHolder remote_func_holder(func);
return ray::internal::TaskCaller<FuncType>(ray::internal::GetRayRuntime().get(),
std::move(remote_func_holder));
inline ray::internal::ActorCreator<PyActorClass> Actor(PyActorClass func) {
ray::internal::RemoteFunctionHolder remote_func_holder(
func.module_name, func.function_name, func.class_name,
ray::internal::LangType::PYTHON);
return {ray::internal::GetRayRuntime().get(), std::move(remote_func_holder)};
}

template <typename FuncType>
inline ray::internal::ActorCreator<FuncType> CreateActorInternal(FuncType &create_func) {
ray::internal::RemoteFunctionHolder remote_func_holder(create_func);
return ray::internal::ActorCreator<FuncType>(ray::internal::GetRayRuntime().get(),
std::move(remote_func_holder));
template <typename R>
inline ray::internal::TaskCaller<PyFunction<R>> Task(PyFunction<R> func) {
ray::internal::RemoteFunctionHolder remote_func_holder(
func.module_name, func.function_name, "", ray::internal::LangType::PYTHON);
return {ray::internal::GetRayRuntime().get(), std::move(remote_func_holder)};
}

/// Normal task.
template <typename F>
ray::internal::TaskCaller<F> Task(F func) {
inline ray::internal::TaskCaller<F> Task(F func) {
static_assert(!ray::internal::is_python_v<F>, "Must be a cpp function.");
static_assert(!std::is_member_function_pointer_v<F>,
"Incompatible type: member function cannot be called with ray::Task.");
return TaskInternal<F>(func);
ray::internal::RemoteFunctionHolder remote_func_holder(std::move(func));
return ray::internal::TaskCaller<F>(ray::internal::GetRayRuntime().get(),
std::move(remote_func_holder));
}

/// Creating an actor.
template <typename F>
ray::internal::ActorCreator<F> Actor(F create_func) {
return CreateActorInternal<F>(create_func);
inline ray::internal::ActorCreator<F> Actor(F create_func) {
ray::internal::RemoteFunctionHolder remote_func_holder(std::move(create_func));
return ray::internal::ActorCreator<F>(ray::internal::GetRayRuntime().get(),
std::move(remote_func_holder));
}

template <typename T>
inline boost::optional<ActorHandle<T>> GetActorInternal(const std::string &actor_name) {
boost::optional<ActorHandle<T>> GetActor(const std::string &actor_name) {
if (actor_name.empty()) {
return {};
}
Expand All @@ -245,11 +255,6 @@ inline boost::optional<ActorHandle<T>> GetActorInternal(const std::string &actor
return ActorHandle<T>(actor_id);
}

template <typename T>
boost::optional<ActorHandle<T>> GetActor(const std::string &actor_name) {
return GetActorInternal<T>(actor_name);
}

inline PlacementGroup CreatePlacementGroup(
const ray::PlacementGroupCreationOptions &create_options) {
return ray::internal::GetRayRuntime()->CreatePlacementGroup(create_options);
Expand Down
24 changes: 17 additions & 7 deletions cpp/include/ray/api/actor_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ActorCreator {
: runtime_(runtime), remote_function_holder_(std::move(remote_function_holder)) {}

template <typename... Args>
ray::ActorHandle<GetActorType<F>> Remote(Args &&...args);
ray::ActorHandle<GetActorType<F>, is_python_v<F>> Remote(Args &&...args);

ActorCreator &SetName(std::string name) {
create_options_.name = std::move(name);
Expand Down Expand Up @@ -75,15 +75,25 @@ class ActorCreator {
// ---------- implementation ----------
template <typename F>
template <typename... Args>
ActorHandle<GetActorType<F>> ActorCreator<F>::Remote(Args &&...args) {
StaticCheck<F, Args...>();
ActorHandle<GetActorType<F>, is_python_v<F>> ActorCreator<F>::Remote(Args &&...args) {
CheckTaskOptions(create_options_.resources);
using ArgsTuple = RemoveReference_t<boost::callable_traits::args_t<F>>;
Arguments::WrapArgs<ArgsTuple>(&args_, std::make_index_sequence<sizeof...(Args)>{},
std::forward<Args>(args)...);

if constexpr (is_python_v<F>) {
using ArgsTuple = std::tuple<Args...>;
Arguments::WrapArgs<ArgsTuple>(/*cross_lang=*/true, &args_,
std::make_index_sequence<sizeof...(Args)>{},
std::forward<Args>(args)...);
} else {
StaticCheck<F, Args...>();
using ArgsTuple = RemoveReference_t<boost::callable_traits::args_t<F>>;
Arguments::WrapArgs<ArgsTuple>(/*cross_lang=*/false, &args_,
std::make_index_sequence<sizeof...(Args)>{},
std::forward<Args>(args)...);
}

auto returned_actor_id =
runtime_->CreateActor(remote_function_holder_, args_, create_options_);
return ActorHandle<GetActorType<F>>(returned_actor_id);
return ActorHandle<GetActorType<F>, is_python_v<F>>(returned_actor_id);
}
} // namespace internal
} // namespace ray
77 changes: 30 additions & 47 deletions cpp/include/ray/api/actor_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,44 @@ namespace ray {
/// `Call` method.
/// \param ActorType The type of the concrete actor class.
/// Note, the `Call` method is defined in actor_call.generated.h.
template <typename ActorType>
template <typename ActorType, bool IsXlang = false>
class ActorHandle {
public:
ActorHandle();
ActorHandle() = default;

ActorHandle(const std::string &id);
ActorHandle(const std::string &id) { id_ = id; }

/// Get a untyped ID of the actor
const std::string &ID() const;
const std::string &ID() const { return id_; }

/// Include the `Call` methods for calling remote functions.
template <typename F>
ray::internal::ActorTaskCaller<F> Task(F actor_func);

void Kill();
void Kill(bool no_restart);
ray::internal::ActorTaskCaller<F> Task(F actor_func) {
static_assert(!IsXlang && !ray::internal::is_python_v<F>,
"Actor method is not a member function of actor class.");
static_assert(std::is_member_function_pointer_v<F>,
"Actor method is not a member function of actor class.");
using Self = boost::callable_traits::class_of_t<F>;
static_assert(
std::is_same<ActorType, Self>::value || std::is_base_of<Self, ActorType>::value,
"Class types must be same.");
ray::internal::RemoteFunctionHolder remote_func_holder(actor_func);
return ray::internal::ActorTaskCaller<F>(internal::GetRayRuntime().get(), id_,
std::move(remote_func_holder));
}

template <typename R>
ray::internal::ActorTaskCaller<PyActorMethod<R>> Task(PyActorMethod<R> func) {
static_assert(IsXlang, "Actor function type is not match with actor class");
ray::internal::RemoteFunctionHolder remote_func_holder(
"", func.function_name, "", ray::internal::LangType::PYTHON);
return {ray::internal::GetRayRuntime().get(), id_, std::move(remote_func_holder)};
}

void Kill() { ray::internal::GetRayRuntime()->KillActor(id_, true); }
void Kill(bool no_restart) {
ray::internal::GetRayRuntime()->KillActor(id_, no_restart);
}

/// Make ActorHandle serializable
MSGPACK_DEFINE(id_);
Expand All @@ -47,43 +69,4 @@ class ActorHandle {
std::string id_;
};

// ---------- implementation ----------
template <typename ActorType>
ActorHandle<ActorType>::ActorHandle() {}

template <typename ActorType>
ActorHandle<ActorType>::ActorHandle(const std::string &id) {
id_ = id;
}

template <typename ActorType>
const std::string &ActorHandle<ActorType>::ID() const {
return id_;
}

template <typename ActorType>
template <typename F>
ray::internal::ActorTaskCaller<F> ActorHandle<ActorType>::Task(F actor_func) {
static_assert(
std::is_member_function_pointer_v<F>,
"Incompatible type: non-member function cannot be called with Actor::Task.");
using Self = boost::callable_traits::class_of_t<F>;
static_assert(
std::is_same<ActorType, Self>::value || std::is_base_of<Self, ActorType>::value,
"Class types must be same.");
ray::internal::RemoteFunctionHolder remote_func_holder(actor_func);
return ray::internal::ActorTaskCaller<F>(internal::GetRayRuntime().get(), id_,
std::move(remote_func_holder));
}

template <typename ActorType>
void ActorHandle<ActorType>::Kill() {
ray::internal::GetRayRuntime()->KillActor(id_, true);
}

template <typename ActorType>
void ActorHandle<ActorType>::Kill(bool no_restart) {
ray::internal::GetRayRuntime()->KillActor(id_, no_restart);
}

} // namespace ray
Loading

0 comments on commit 2313b22

Please sign in to comment.