2020-03-27 23:01:08 +08:00
|
|
|
# Bazel build
|
|
|
|
# C/C++ documentation: https://docs.bazel.build/versions/master/be/c-cpp.html
|
|
|
|
|
|
|
|
load("//bazel:ray.bzl", "COPTS")
|
|
|
|
|
2021-06-16 17:45:45 +08:00
|
|
|
cc_binary(
|
|
|
|
name = "libray_api.so",
|
|
|
|
copts = COPTS,
|
2022-07-01 11:51:40 +08:00
|
|
|
linkopts = select({
|
|
|
|
"@bazel_tools//src/conditions:darwin": [
|
2022-07-12 11:00:17 +08:00
|
|
|
#TODO(larry): Hide the symbols when we make it work on mac.
|
2022-07-01 11:51:40 +08:00
|
|
|
],
|
|
|
|
"@bazel_tools//src/conditions:windows": [
|
|
|
|
#TODO(larry): Hide the symbols when we make it work on Windows.
|
|
|
|
],
|
|
|
|
"//conditions:default": [
|
|
|
|
"-Wl,--version-script,$(location :symbols/ray_api_exported_symbols_linux.lds)",
|
|
|
|
],
|
|
|
|
}),
|
2021-06-16 17:45:45 +08:00
|
|
|
linkshared = 1,
|
|
|
|
linkstatic = 1,
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
deps = [
|
|
|
|
":ray_api",
|
2022-07-01 11:51:40 +08:00
|
|
|
":symbols/ray_api_exported_symbols_linux.lds",
|
|
|
|
":symbols/ray_api_exported_symbols_mac.lds",
|
2021-06-16 17:45:45 +08:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2020-03-27 23:01:08 +08:00
|
|
|
cc_library(
|
2020-08-28 13:53:36 +08:00
|
|
|
name = "ray_api",
|
2020-03-27 23:01:08 +08:00
|
|
|
srcs = glob([
|
|
|
|
"src/ray/api.cc",
|
|
|
|
"src/ray/api/*.cc",
|
|
|
|
"src/ray/api/*.h",
|
|
|
|
"src/ray/app/*.cc",
|
|
|
|
"src/ray/app/*.h",
|
|
|
|
"src/ray/runtime/*.cc",
|
|
|
|
"src/ray/runtime/*.h",
|
|
|
|
"src/ray/runtime/**/*.cc",
|
|
|
|
"src/ray/runtime/**/*.h",
|
|
|
|
"src/ray/runtime/task/*.cc",
|
|
|
|
"src/ray/runtime/task/*.h",
|
|
|
|
"src/ray/util/*.cc",
|
|
|
|
"src/ray/util/*.h",
|
|
|
|
"src/ray/*.cc",
|
|
|
|
"src/ray/*.h",
|
|
|
|
]),
|
2020-08-28 13:53:36 +08:00
|
|
|
hdrs = glob([
|
|
|
|
"include/ray/*.h",
|
|
|
|
"include/ray/**/*.h",
|
|
|
|
"include/ray/**/**/*.h",
|
|
|
|
]),
|
2020-03-27 23:01:08 +08:00
|
|
|
copts = COPTS,
|
|
|
|
linkopts = ["-ldl"],
|
2020-09-18 11:08:18 +08:00
|
|
|
linkstatic = True,
|
2020-08-28 13:53:36 +08:00
|
|
|
strip_include_prefix = "include",
|
2020-03-27 23:01:08 +08:00
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
deps = [
|
|
|
|
"//:core_worker_lib",
|
2021-07-08 11:21:12 +08:00
|
|
|
"//:global_state_accessor_lib",
|
2020-03-27 23:01:08 +08:00
|
|
|
"//:ray_common",
|
|
|
|
"//:ray_util",
|
2021-03-01 16:27:03 +08:00
|
|
|
"@boost//:callable_traits",
|
2021-03-27 09:56:40 +08:00
|
|
|
"@boost//:dll",
|
2021-08-13 12:22:37 +08:00
|
|
|
"@com_google_absl//absl/flags:flag",
|
|
|
|
"@com_google_absl//absl/flags:parse",
|
2020-03-27 23:01:08 +08:00
|
|
|
"@msgpack",
|
2022-07-27 18:24:31 +08:00
|
|
|
"@nlohmann_json",
|
2020-03-27 23:01:08 +08:00
|
|
|
],
|
2021-06-16 17:45:45 +08:00
|
|
|
alwayslink = True,
|
2020-03-27 23:01:08 +08:00
|
|
|
)
|
|
|
|
|
2022-06-22 15:11:15 +08:00
|
|
|
cc_library(
|
|
|
|
name = "ray_cpp_lib",
|
|
|
|
srcs = [
|
|
|
|
"libray_api.so",
|
|
|
|
],
|
|
|
|
hdrs = glob([
|
|
|
|
"include/ray/*.h",
|
|
|
|
"include/ray/**/*.h",
|
|
|
|
"include/ray/**/**/*.h",
|
|
|
|
]),
|
|
|
|
strip_include_prefix = "include",
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
)
|
|
|
|
|
2020-03-27 23:01:08 +08:00
|
|
|
cc_binary(
|
2021-02-01 19:24:33 +08:00
|
|
|
name = "default_worker",
|
2020-08-28 13:53:36 +08:00
|
|
|
srcs = glob([
|
2021-02-01 19:24:33 +08:00
|
|
|
"src/ray/worker/default_worker.cc",
|
2020-08-28 13:53:36 +08:00
|
|
|
]),
|
|
|
|
copts = COPTS,
|
2021-02-01 19:24:33 +08:00
|
|
|
linkstatic = True,
|
2022-06-22 15:11:15 +08:00
|
|
|
deps = select({
|
|
|
|
"@bazel_tools//src/conditions:windows": [
|
|
|
|
# TODO(SongGuyang): Change to use dynamic library
|
|
|
|
# "ray_cpp_lib" when we make it work on Windows.
|
|
|
|
"ray_api",
|
|
|
|
],
|
|
|
|
"//conditions:default": [
|
|
|
|
"ray_cpp_lib",
|
|
|
|
"@boost//:callable_traits",
|
|
|
|
"@boost//:optional",
|
|
|
|
"@msgpack",
|
2022-07-27 18:24:31 +08:00
|
|
|
"@nlohmann_json",
|
2022-06-22 15:11:15 +08:00
|
|
|
],
|
|
|
|
}),
|
2020-08-28 13:53:36 +08:00
|
|
|
)
|
|
|
|
|
2021-02-01 19:24:33 +08:00
|
|
|
genrule(
|
|
|
|
name = "ray_cpp_pkg",
|
|
|
|
srcs = [
|
|
|
|
"default_worker",
|
|
|
|
"ray_api",
|
2021-06-16 17:45:45 +08:00
|
|
|
"libray_api.so",
|
2021-02-01 19:24:33 +08:00
|
|
|
],
|
|
|
|
outs = ["ray_cpp_pkg.out"],
|
|
|
|
cmd = """
|
|
|
|
WORK_DIR="$$(pwd)" &&
|
2021-07-08 14:42:26 +08:00
|
|
|
PY_CPP_DIR="$$WORK_DIR/python/ray/cpp" &&
|
|
|
|
rm -rf $$PY_CPP_DIR &&
|
|
|
|
BOOST_DIR="$$PY_CPP_DIR/include/boost/" &&
|
2021-06-21 14:46:48 +08:00
|
|
|
mkdir -p "$$BOOST_DIR" &&
|
2021-07-08 14:42:26 +08:00
|
|
|
mkdir -p "$$PY_CPP_DIR/lib/" &&
|
2021-10-18 16:03:49 +08:00
|
|
|
cp -f $(location default_worker) "$$PY_CPP_DIR/" &&
|
2021-07-08 14:42:26 +08:00
|
|
|
cp -f -r $$WORK_DIR/external/msgpack/include/* "$$PY_CPP_DIR/include" &&
|
2022-07-27 18:24:31 +08:00
|
|
|
cp -f -r $$WORK_DIR/external/nlohmann_json/single_include/* "$$PY_CPP_DIR/include" &&
|
2021-06-21 14:46:48 +08:00
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/archive" "$$BOOST_DIR" &&
|
2021-10-09 18:48:35 -07:00
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/assert" "$$BOOST_DIR" &&
|
2021-06-21 14:46:48 +08:00
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/bind" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/callable_traits" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/concept" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/config" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/container" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/container_hash" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/core" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/detail" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/dll" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/exception" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/filesystem" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/functional" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/io" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/iterator" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/lexical_cast" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/move" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/mpl" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/optional" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/parameter" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/preprocessor" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/system" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/type_traits" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r "$$WORK_DIR/external/boost/boost/utility" "$$BOOST_DIR" &&
|
|
|
|
cp -f -r $$WORK_DIR/external/boost/boost/*.hpp "$$BOOST_DIR" &&
|
2021-07-08 14:42:26 +08:00
|
|
|
cp -f $(locations libray_api.so) "$$PY_CPP_DIR/lib/" &&
|
|
|
|
cp -f -r "$$WORK_DIR/cpp/include/ray" "$$PY_CPP_DIR/include" &&
|
|
|
|
THIRDPARTY_DIR="$$WORK_DIR/cpp/example/thirdparty" &&
|
|
|
|
rm -rf $$THIRDPARTY_DIR &&
|
|
|
|
mkdir $$THIRDPARTY_DIR &&
|
2021-09-10 11:53:05 +08:00
|
|
|
cp -f -r "$$PY_CPP_DIR/include" $$THIRDPARTY_DIR &&
|
|
|
|
cp -f -r "$$PY_CPP_DIR/lib" $$THIRDPARTY_DIR &&
|
2021-07-08 14:42:26 +08:00
|
|
|
cp -f -r "$$WORK_DIR/cpp/example" "$$PY_CPP_DIR" &&
|
2021-02-01 19:24:33 +08:00
|
|
|
echo "$$WORK_DIR" > $@
|
|
|
|
""",
|
|
|
|
local = 1,
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
)
|
|
|
|
|
|
|
|
# test
|
2020-03-27 23:01:08 +08:00
|
|
|
cc_test(
|
|
|
|
name = "api_test",
|
|
|
|
srcs = glob([
|
|
|
|
"src/ray/test/*.cc",
|
|
|
|
]),
|
|
|
|
copts = COPTS,
|
2022-02-10 16:06:38 +08:00
|
|
|
linkstatic = True,
|
2022-02-08 03:33:55 +08:00
|
|
|
tags = ["team:core"],
|
2020-08-28 13:53:36 +08:00
|
|
|
deps = [
|
|
|
|
"ray_api",
|
|
|
|
"@com_google_googletest//:gtest_main",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
cc_test(
|
|
|
|
name = "cluster_mode_test",
|
2022-06-17 11:05:24 +08:00
|
|
|
srcs = glob(
|
|
|
|
[
|
|
|
|
"src/ray/test/cluster/*.cc",
|
|
|
|
"src/ray/test/cluster/*.h",
|
|
|
|
],
|
|
|
|
exclude = [
|
|
|
|
"src/ray/test/cluster/cluster_mode_xlang_test.cc",
|
|
|
|
],
|
|
|
|
),
|
2021-02-01 19:24:33 +08:00
|
|
|
args = [
|
2022-06-17 11:05:24 +08:00
|
|
|
"--ray_code_search_path=$(location plus.so):$(location counter.so):cpp/src/ray/test/cluster",
|
2021-09-23 19:30:53 +08:00
|
|
|
"--ray_head_args '--include-dashboard false'",
|
2021-02-01 19:24:33 +08:00
|
|
|
],
|
2020-08-28 13:53:36 +08:00
|
|
|
copts = COPTS,
|
2021-02-01 19:24:33 +08:00
|
|
|
data = [
|
2021-07-16 13:02:45 +08:00
|
|
|
"counter.so",
|
|
|
|
"plus.so",
|
2021-02-01 19:24:33 +08:00
|
|
|
"ray_cpp_pkg",
|
[C++ Worker][xlang] Support calling python worker (#21390)
C++ API need to call python and java worker, this pr support call python worker. Call python worker is similar with call c++ worker, need to pass PyFunction, PyActorClass and PyActorMethod.
## call python normal task
```python
#test_cross_language_invocation.py
import ray
@ray.remote
def py_return_input(v):
return v
```
c++ api call python function
```c++
auto py_obj1 = ray::Task(ray::PyFunction</*ReturnType*/int>{/*module_name=*/"test_cross_language_invocation",
/*function_name=*/"py_return_input"})
.Remote(42);
EXPECT_EQ(42, *py_obj1.Get());
```
The user need to fill python module name and function name, then pass arguments into the remote.
The user also need to assign the return type and arguments types of the python function, it used to do static safe checking and get result.
## call python actor task
```python
#test_cross_language_invocation.py
@ray.remote
class Counter(object):
def __init__(self, value):
self.value = int(value)
def increase(self, delta):
self.value += int(delta)
return str(self.value)
```
c++ api call python actor function
```c++
// Create python actor
auto py_actor_handle =
ray::Actor(ray::PyActorClass{/*module_name=*/"test_cross_language_invocation", /*class_name=*/"Counter"})
.Remote(1);
EXPECT_TRUE(!py_actor_handle.ID().empty());
// Call python actor task
auto py_actor_ret =
py_actor_handle.Task(ray::PyActorMethod</*ReturnType*/std::string>{/*actor_function_name=*/"increase"}).Remote(1);
EXPECT_EQ("2", *py_actor_ret.Get());
```
The user need to fill python module name and class name when creating python actor.
PyActorMethod only need to fill the function name.
It's also similar with calling c++ actor task, also has compile-time safe checking.
2022-01-21 13:55:30 +08:00
|
|
|
"src/ray/test/cluster/test_cross_language_invocation.py",
|
2022-06-17 11:05:24 +08:00
|
|
|
],
|
|
|
|
linkstatic = True,
|
|
|
|
tags = ["team:core"],
|
|
|
|
deps = [
|
|
|
|
"ray_api",
|
|
|
|
"@com_google_googletest//:gtest_main",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
cc_test(
|
|
|
|
name = "cluster_mode_xlang_test",
|
|
|
|
srcs = glob([
|
|
|
|
"src/ray/test/cluster/cluster_mode_xlang_test.cc",
|
|
|
|
"src/ray/test/cluster/*.h",
|
|
|
|
]),
|
|
|
|
args = [
|
|
|
|
"--ray_code_search_path=$(location //java:libio_ray_ray_test.jar)",
|
|
|
|
"--ray_head_args '--include-dashboard false'",
|
|
|
|
],
|
|
|
|
copts = COPTS,
|
|
|
|
data = [
|
|
|
|
"ray_cpp_pkg",
|
2022-06-14 14:17:14 +08:00
|
|
|
"//java:libio_ray_ray_test.jar",
|
2021-02-01 19:24:33 +08:00
|
|
|
],
|
2020-09-18 11:08:18 +08:00
|
|
|
linkstatic = True,
|
2022-02-08 03:33:55 +08:00
|
|
|
tags = ["team:core"],
|
2020-03-27 23:01:08 +08:00
|
|
|
deps = [
|
|
|
|
"ray_api",
|
|
|
|
"@com_google_googletest//:gtest_main",
|
|
|
|
],
|
|
|
|
)
|
2020-09-18 11:08:18 +08:00
|
|
|
|
2021-02-01 19:24:33 +08:00
|
|
|
cc_binary(
|
2021-07-16 13:02:45 +08:00
|
|
|
name = "plus.so",
|
|
|
|
testonly = True,
|
|
|
|
srcs = [
|
|
|
|
"src/ray/test/cluster/plus.cc",
|
|
|
|
"src/ray/test/cluster/plus.h",
|
|
|
|
],
|
|
|
|
copts = COPTS,
|
|
|
|
linkopts = ["-shared"],
|
|
|
|
linkstatic = True,
|
2022-07-12 17:49:22 +08:00
|
|
|
# NOTE(WangTaoTheTonic): For java x-lang tests. See //java:all_tests
|
|
|
|
# and `CrossLanguageInvocationTest.java`.
|
|
|
|
visibility = ["//java:__subpackages__"],
|
2021-07-16 13:02:45 +08:00
|
|
|
deps = [
|
2022-06-22 15:11:15 +08:00
|
|
|
"ray_cpp_lib",
|
|
|
|
"@boost//:callable_traits",
|
|
|
|
"@boost//:optional",
|
|
|
|
"@msgpack",
|
2022-07-27 18:24:31 +08:00
|
|
|
"@nlohmann_json",
|
2021-07-16 13:02:45 +08:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
cc_binary(
|
|
|
|
name = "counter.so",
|
|
|
|
testonly = True,
|
|
|
|
srcs = [
|
|
|
|
"src/ray/test/cluster/counter.cc",
|
|
|
|
"src/ray/test/cluster/counter.h",
|
|
|
|
],
|
2021-02-01 19:24:33 +08:00
|
|
|
copts = COPTS,
|
2021-05-19 18:03:39 +08:00
|
|
|
linkopts = ["-shared"],
|
2021-02-01 19:24:33 +08:00
|
|
|
linkstatic = True,
|
2022-06-29 14:33:32 +08:00
|
|
|
# NOTE(WangTaoTheTonic): For java x-lang tests. See //java:all_tests
|
|
|
|
# and `CrossLanguageInvocationTest.java`.
|
|
|
|
visibility = ["//java:__subpackages__"],
|
2021-02-01 19:24:33 +08:00
|
|
|
deps = [
|
2022-06-22 15:11:15 +08:00
|
|
|
"ray_cpp_lib",
|
|
|
|
"@boost//:callable_traits",
|
|
|
|
"@boost//:optional",
|
|
|
|
"@msgpack",
|
2022-07-27 18:24:31 +08:00
|
|
|
"@nlohmann_json",
|
2020-09-18 11:08:18 +08:00
|
|
|
],
|
|
|
|
)
|
2021-09-18 16:02:44 +08:00
|
|
|
|
|
|
|
cc_test(
|
|
|
|
name = "simple_kv_store",
|
|
|
|
srcs = glob([
|
|
|
|
"src/ray/test/examples/*.cc",
|
|
|
|
]),
|
2022-06-22 15:11:15 +08:00
|
|
|
args = [
|
|
|
|
"--ray_code_search_path=$(location simple_kv_store.so)",
|
|
|
|
"--ray_head_args '--include-dashboard false'",
|
|
|
|
],
|
|
|
|
copts = COPTS,
|
2021-09-18 16:02:44 +08:00
|
|
|
data = [
|
|
|
|
"simple_kv_store.so",
|
|
|
|
],
|
|
|
|
linkstatic = True,
|
2022-02-08 03:33:55 +08:00
|
|
|
tags = ["team:core"],
|
2021-09-18 16:02:44 +08:00
|
|
|
deps = [
|
2022-06-22 15:11:15 +08:00
|
|
|
"ray_api",
|
2021-09-18 16:02:44 +08:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
cc_binary(
|
|
|
|
name = "simple_kv_store.so",
|
|
|
|
testonly = True,
|
|
|
|
srcs = glob([
|
|
|
|
"src/ray/test/examples/*.cc",
|
|
|
|
]),
|
2022-06-22 15:11:15 +08:00
|
|
|
copts = COPTS,
|
2021-09-18 16:02:44 +08:00
|
|
|
linkopts = ["-shared"],
|
|
|
|
linkstatic = True,
|
|
|
|
deps = [
|
2022-06-22 15:11:15 +08:00
|
|
|
"ray_cpp_lib",
|
|
|
|
"@boost//:callable_traits",
|
|
|
|
"@boost//:optional",
|
|
|
|
"@msgpack",
|
2022-07-27 18:24:31 +08:00
|
|
|
"@nlohmann_json",
|
2021-09-18 16:02:44 +08:00
|
|
|
],
|
|
|
|
)
|
2022-03-11 03:06:14 +08:00
|
|
|
|
|
|
|
load("//bazel:python.bzl", "py_test_module_list")
|
|
|
|
|
|
|
|
py_test_module_list(
|
2022-07-30 00:31:02 +08:00
|
|
|
size = "medium",
|
2022-03-11 03:06:14 +08:00
|
|
|
extra_srcs = [],
|
|
|
|
files = [
|
|
|
|
"test_python_call_cpp.py",
|
|
|
|
],
|
|
|
|
tags = [
|
|
|
|
"exclusive",
|
2022-07-30 00:31:02 +08:00
|
|
|
"medium_size_python_tests",
|
2022-03-11 03:06:14 +08:00
|
|
|
"team:core",
|
|
|
|
],
|
2022-07-19 12:21:19 +08:00
|
|
|
deps = [],
|
2022-03-11 03:06:14 +08:00
|
|
|
)
|